Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
FindChirpTDTemplate.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Stas Babak, Duncan Brown, Jolien Creighton, Craig Robinson
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/*-----------------------------------------------------------------------
21 *
22 * File Name: FindChirpTDTemplate.c
23 *
24 * Author: Brown D. A., and Creighton, J. D. E.
25 *
26 */
27
28/**
29 * \author Brown, D. A., and Creighton, J. D. E.
30 * \file
31 * \ingroup FindChirpTD_h
32 *
33 * \brief Provides functions to create time domain inspiral templates in a
34 * form that can be used by the <tt>FindChirpFilter()</tt> function.
35 *
36 * ### Prototypes ###
37 *
38 * The function <tt>LALFindChirpTDTemplate()</tt> creates a time domain template
39 * template using the inspiral package.
40 *
41 * ### Algorithm ###
42 *
43 * Blah.
44 *
45 * ### Uses ###
46 *
47 * \code
48 * LALCalloc()
49 * LALFree()
50 * LALCreateVector()
51 * LALDestroyVector()
52 * \endcode
53 *
54 * ### Notes ###
55 *
56 */
57
58#include <math.h>
59#include <lal/LALStdlib.h>
60#include <lal/AVFactories.h>
61#include <lal/SeqFactories.h>
62#include <lal/LALInspiral.h>
63#include <lal/FindChirp.h>
64#include "FindChirpDatatypes.h"
65#include "FindChirpTD.h"
66
67void
70 FindChirpTemplate *fcTmplt,
71 InspiralTemplate *tmplt,
73 )
74
75{
76 UINT4 j;
77 UINT4 shift;
78 UINT4 waveLength;
80 REAL4 *xfac;
84 const REAL4 cannonDist = 1.0; /* Mpc */
85 /*CHAR infomsg[512];*/
86 PPNParamStruc ppnParams;
88
89 REAL4Vector *tmpxfac = NULL; /* Used for band-passing */
90
91
94
95
96 /*
97 *
98 * check that the arguments are reasonable
99 *
100 */
101
102
103 /* check that the output structures exist */
104 ASSERT( fcTmplt, status,
105 FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
106 ASSERT( fcTmplt->data, status,
107 FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
108 ASSERT( fcTmplt->data->data, status,
109 FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
110
111 /* check that the parameter structure exists */
113 FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
114 ASSERT( params->xfacVec, status,
115 FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
116 ASSERT( params->xfacVec->data, status,
117 FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
118
119 /* check we have an fft plan for the template */
120 ASSERT( params->fwdPlan, status,
121 FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
122
123 /* check that the timestep is positive */
124 ASSERT( params->deltaT > 0, status,
125 FINDCHIRPTDH_EDELT, FINDCHIRPTDH_MSGEDELT );
126
127 /* check that the input exists */
128 ASSERT( tmplt, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL );
129
130 /* store deltaT and zero out the time domain waveform vector */
131 deltaT = params->deltaT;
132 sampleRate = 1.0 / deltaT;
133 xfac = params->xfacVec->data;
134 numPoints = params->xfacVec->length;
135 memset( xfac, 0, numPoints * sizeof(REAL4) );
136
137 ASSERT( numPoints == (2 * (fcTmplt->data->length - 1)), status,
138 FINDCHIRPTDH_EMISM, FINDCHIRPTDH_MSGEMISM );
139
140
141 /* choose the time domain template */
142 if ( params->approximant == GeneratePPN )
143 {
144
145
146 /*
147 *
148 * generate the waveform using LALGeneratePPNInspiral() from inject
149 *
150 */
151
152
153
154 /* input parameters */
155 memset( &ppnParams, 0, sizeof(PPNParamStruc) );
156 ppnParams.deltaT = deltaT;
157 ppnParams.mTot = tmplt->mass1 + tmplt->mass2;
158 ppnParams.eta = tmplt->mass1 * tmplt->mass2 /
159 ( ppnParams.mTot * ppnParams.mTot );
160 ppnParams.d = 1.0;
161 ppnParams.fStartIn = params->fLow;
162 ppnParams.fStopIn = -1.0 /
163 (6.0 * sqrt(6.0) * LAL_PI * ppnParams.mTot * LAL_MTSUN_SI);
164
165 /* generate waveform amplitude and phase */
166 memset( &waveform, 0, sizeof(CoherentGW) );
169
170 /* print termination information and check sampling */
171 LALInfo( status, ppnParams.termDescription );
172 if ( ppnParams.dfdt > 2.0 )
173 {
174 ABORT( status, FINDCHIRPTDH_ESMPL, FINDCHIRPTDH_MSGESMPL );
175 }
176 if ( waveform.a->data->length > numPoints )
177 {
178 ABORT( status, FINDCHIRPTDH_ELONG, FINDCHIRPTDH_MSGELONG );
179 }
180
181 /* compute h(t) */
182 for ( j = 0; j < waveform.a->data->length; ++j )
183 {
184 xfac[j] =
185 waveform.a->data->data[2*j] * cos( waveform.phi->data->data[j] );
186 }
187
188 /* free the memory allocated by LALGeneratePPNInspiral() */
191
194
195 LALDDestroyVector( status->statusPtr, &(waveform.phi->data) );
197
198 LALFree( waveform.a );
199 LALFree( waveform.f );
200 LALFree( waveform.phi );
201
202 /* waveform parameters needed for findchirp filter */
203 tmplt->approximant = params->approximant;
204 tmplt->tC = ppnParams.tc;
205 tmplt->fFinal = ppnParams.fStop;
206
207 fcTmplt->tmpltNorm = params->dynRange / ( cannonDist * 1.0e6 * LAL_PC_SI );
208 fcTmplt->tmpltNorm *= fcTmplt->tmpltNorm;
209 }
210 else
211 {
212
213
214 /*
215 *
216 * generate the waveform by calling LALInspiralWave() from inspiral
217 *
218 */
219
220
221 /* set up additional template parameters */
222 deltaF = 1.0 / ((REAL8) numPoints * deltaT);
223 tmplt->ieta = 1;
224 tmplt->approximant = params->approximant;
225 tmplt->order = params->order;
226 tmplt->massChoice = m1Andm2;
227 tmplt->tSampling = sampleRate;
228 tmplt->fLower = params->fLow;
229 tmplt->fCutoff = sampleRate / 2.0 - deltaF;
230 /* get the template norm right */
231 if ( params->approximant==EOBNR )
232 {
233 /* lalinspiral EOBNR code produces correct norm when
234 fed unit signalAmplitude and non-physical distance */
235 tmplt->signalAmplitude = 1.0;
236 tmplt->distance = -1.0;
237 }
238 else if ( params->approximant==EOBNRv2 )
239 {
240 /* this formula sets the ampl0 variable to 1.0
241 * within the lalsimulation EOBNRv2 waveform engine
242 * which again produces a correct template norm */
243 tmplt->distance = tmplt->totalMass*LAL_MRSUN_SI;
244 }
245 else if ( params->approximant==IMRPhenomD )
246 {
247 /* 1Mpc standard distance - not clear if this produces correct norm */
248 tmplt->distance = 1.0;
249 }
250 else if ( (params->approximant==IMRPhenomB) || (params->approximant==IMRPhenomC) )
251 {
252 XLALPrintError("**** LALFindChirpTDTemplate ERROR ****\n");
253 XLALPrintError("Old IMRPhenom approximant requested! Please switch to IMRPhenomD.\n");
254 XLALPrintError("If an approximant that precedes IMRPhenomD MUST be used, then\n");
255 XLALPrintError("comment out lines 251-257 in lalinspiral/lib/FindChirpTDTemplate.c,\n");
256 XLALPrintError("recompile, and rerun.\n");
257 XLALPrintError("**************************************\n");
259 /* 1Mpc standard distance - not clear if this produces correct norm */
260 tmplt->distance = 1.0;
261 tmplt->spin1[2] = 2 * tmplt->chi/(1. + sqrt(1.-4.*tmplt->eta));
262 }
263 else
264 {
265 tmplt->distance = -1.0;
266 }
267
268 /* compute the tau parameters from the input template */
271
272 /* determine the length of the chirp in sample points */
273 /* This call implicitely checks that a valid approximant+order combination
274 was fed in, because LALInspiralWaveLength calls XLALInspiralChooseModel
275 which is what ultimately limits the available choices. */
276 LALInspiralWaveLength( status->statusPtr, &waveLength, *tmplt );
278
279 if ( waveLength > numPoints )
280 {
281 ABORT( status, FINDCHIRPTDH_ELONG, FINDCHIRPTDH_MSGELONG );
282 }
283
284 /* generate the chirp in the time domain */
285 LALInspiralWave( status->statusPtr, params->xfacVec, tmplt );
287
288
289 /* template dependent normalization */
290 fcTmplt->tmpltNorm = 2 * tmplt->mu;
291 fcTmplt->tmpltNorm *= 2 * LAL_MRSUN_SI / ( cannonDist * 1.0e6 * LAL_PC_SI );
292 fcTmplt->tmpltNorm *= params->dynRange;
293 fcTmplt->tmpltNorm *= fcTmplt->tmpltNorm;
294 }
295
296
297 /* Taper the waveform if required */
298 if ( params->taperTmplt != LAL_SIM_INSPIRAL_TAPER_NONE )
299 {
300 if ( XLALSimInspiralREAL4WaveTaper( params->xfacVec, params->taperTmplt )
301 == XLAL_FAILURE )
302 {
303 ABORTXLAL( status );
304 }
305 }
306
307 /* Find the end of the chirp */
308 j = numPoints - 1;
309 while ( xfac[j] == 0 )
310 {
311 /* search for the end of the chirp but don't fall off the array */
312 if ( --j == 0 )
313 {
314 ABORT( status, FINDCHIRPTDH_EEMTY, FINDCHIRPTDH_MSGEEMTY );
315 }
316 }
317 ++j;
318
319 /* Band pass the template if required */
320 if ( params->bandPassTmplt )
321 {
322 REAL4Vector bpVector; /*Used to save time */
323
324 /* We want to shift the template to the middle of the vector so */
325 /* that band-passing will work properly */
326 shift = ( numPoints - j ) / 2;
327 memmove( xfac + shift, xfac, j * sizeof( *xfac ) );
328 memset( xfac, 0, shift * sizeof( *xfac ) );
329 memset( xfac + ( numPoints + j ) / 2, 0,
330 ( numPoints - ( numPoints + j ) / 2 ) * sizeof( *xfac ) );
331
332
333 /* Select an appropriate part of the vector to band pass. */
334 /* band passing the whole thing takes a lot of time */
335 if ( j > 2 * sampleRate && 2 * j <= numPoints )
336 {
337 bpVector.length = 2 * j;
338 bpVector.data = params->xfacVec->data + numPoints / 2 - j;
339 }
340 else if ( j <= 2 * sampleRate && j + 2 * sampleRate <= numPoints )
341 {
342 bpVector.length = j + 2 * sampleRate;
343 bpVector.data = params->xfacVec->data
344 + ( numPoints - j ) / 2 - (INT4)sampleRate;
345 }
346 else
347 {
348 bpVector.length = params->xfacVec->length;
349 bpVector.data = params->xfacVec->data;
350 }
351
352 if ( XLALBandPassInspiralTemplate( &bpVector, 0.95 * tmplt->fLower,
353 1.02 * tmplt->fFinal, sampleRate ) == XLAL_FAILURE )
354 {
355 ABORTXLAL( status );
356 }
357
358 /* Now we need to do the shift to the end. */
359 /* Use a temporary vector to avoid mishaps */
360 if ( ( tmpxfac = XLALCreateREAL4Vector( numPoints ) ) == NULL )
361 {
362 ABORTXLAL( status );
363 }
364
365 if ( params->approximant == EOBNR || params->approximant == EOBNRv2
366 || params->approximant == IMRPhenomB || params->approximant == IMRPhenomC )
367 {
368 /* We need to do something slightly different for EOBNR */
369 UINT4 endIndx = (UINT4) (tmplt->tC * sampleRate);
370
371 memcpy( tmpxfac->data, xfac + ( numPoints - j ) / 2 + endIndx,
372 ( numPoints - ( numPoints - j ) / 2 - endIndx ) * sizeof( *xfac ) );
373
374 memcpy( tmpxfac->data + numPoints - ( numPoints - j ) / 2 - endIndx,
375 xfac, ( ( numPoints - j ) / 2 + endIndx ) * sizeof( *xfac ) );
376 }
377 else
378 {
379 memcpy( tmpxfac->data, xfac + ( numPoints + j ) / 2,
380 ( numPoints - ( numPoints + j ) / 2 ) * sizeof( *xfac ) );
381
382 memcpy( tmpxfac->data + numPoints - ( numPoints + j ) / 2,
383 xfac, ( numPoints + j ) / 2 * sizeof( *xfac ) );
384 }
385
386 memcpy( xfac, tmpxfac->data, numPoints * sizeof( *xfac ) );
387
388 XLALDestroyREAL4Vector( tmpxfac );
389 tmpxfac = NULL;
390 }
391 else if ( params->approximant == EOBNR || params->approximant == EOBNRv2
392 || params->approximant == IMRPhenomB || params->approximant == IMRPhenomC )
393 {
394 /* For EOBNR we shift so that tC is at the end of the vector */
395 if ( ( tmpxfac = XLALCreateREAL4Vector( numPoints ) ) == NULL )
396 {
397 ABORTXLAL( status );
398 }
399
400 /* Set the coalescence index depending on tC */
401 j = (UINT4) (tmplt->tC * sampleRate);
402 memcpy( tmpxfac->data + numPoints - j, xfac, j * sizeof( *xfac ) );
403 memcpy( tmpxfac->data, xfac + j, ( numPoints - j ) * sizeof( *xfac ) );
404 memcpy( xfac, tmpxfac->data, numPoints * sizeof( *xfac ) );
405 XLALDestroyREAL4Vector( tmpxfac );
406 tmpxfac = NULL;
407 }
408 else
409 {
410 /* No need for so much shifting around if not band passing */
411 /* shift chirp to end of vector so it is the correct place for the filter */
412 memmove( xfac + numPoints - j, xfac, j * sizeof( *xfac ) );
413 memset( xfac, 0, ( numPoints - j ) * sizeof( *xfac ) );
414 }
415
416 /*
417 *
418 * create the frequency domain findchirp template
419 *
420 */
421
422 /* fft chirp */
423 if ( XLALREAL4ForwardFFT( fcTmplt->data, params->xfacVec,
424 params->fwdPlan ) == XLAL_FAILURE )
425 {
426 ABORTXLAL( status );
427 }
428
429 /* copy the template parameters to the findchirp template structure */
430 memcpy( &(fcTmplt->tmplt), tmplt, sizeof(InspiralTemplate) );
431
432 /* normal exit */
434 RETURN( status );
435}
int XLALBandPassInspiralTemplate(REAL4Sequence *sequence, REAL4 fLow, REAL4 fHigh, REAL4 fSampling)
#define FINDCHIRPTDH_EDELT
Definition: FindChirpTD.h:54
#define FINDCHIRPTDH_ESMPL
Definition: FindChirpTD.h:62
#define FINDCHIRPTDH_EMISM
Definition: FindChirpTD.h:53
#define FINDCHIRPTDH_ELONG
Definition: FindChirpTD.h:60
#define FINDCHIRPTDH_EEMTY
Definition: FindChirpTD.h:61
#define FINDCHIRPTDH_ENULL
Definition: FindChirpTD.h:48
void LALFindChirpTDTemplate(LALStatus *status, FindChirpTemplate *fcTmplt, InspiralTemplate *tmplt, FindChirpTmpltParams *params)
int j
void LALInspiralWaveLength(LALStatus *status, UINT4 *n, InspiralTemplate params)
void LALInspiralParameterCalc(LALStatus *status, InspiralTemplate *params)
void LALInspiralWave(LALStatus *status, REAL4Vector *signalvec, InspiralTemplate *params)
#define LALFree(p)
#define ABORT(statusptr, code, mesg)
#define CHECKSTATUSPTR(statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define ABORTXLAL(sp)
INT4 sampleRate
Definition: blindinj.c:124
void LALSDestroyVectorSequence(LALStatus *status, REAL4VectorSequence **vectorSequence)
void LALGeneratePPNInspiral(LALStatus *, CoherentGW *output, PPNParamStruc *params)
#define LAL_PI
#define LAL_MTSUN_SI
#define LAL_PC_SI
#define LAL_MRSUN_SI
double REAL8
uint32_t UINT4
int32_t INT4
float REAL4
int LALInfo(LALStatus *status, const char *info)
m1Andm2
LAL_SIM_INSPIRAL_TAPER_NONE
GeneratePPN
IMRPhenomC
EOBNRv2
IMRPhenomD
EOBNR
IMRPhenomB
int XLALSimInspiralREAL4WaveTaper(REAL4Vector *signalvec, LALSimInspiralApplyTaper bookends)
int XLALREAL4ForwardFFT(COMPLEX8Vector *output, const REAL4Vector *input, const REAL4FFTPlan *plan)
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
#define XLAL_ERROR_VOID(...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_EFUNC
XLAL_FAILURE
static LALStatus status
Definition: inspinj.c:552
waveform
int deltaF
COMPLEX8 * data
This structure contains a frequency domain template used as input to the FindChirpFilter() routine.
COMPLEX8Vector * data
Vector of length containing the frequency template data ; For a template generated in the frequency ...
InspiralTemplate tmplt
The template parameters of this FindChirpTemplate; In addition to the mass parameters the following f...
REAL4 tmpltNorm
The template dependent normalisation constant ; For the stationary phase template FindChirpSP this is...
This structure contains the parameters for generation of templates by the various template generation...
Approximant approximant
LALPNOrder order
InputMasses massChoice
struct tagLALStatus * statusPtr
const CHAR * termDescription
REAL4 * data
INT4 numPoints
Definition: tmpltbank.c:399
double deltaT