LALApps 10.1.0.1-eeff03c
FindChirpIMRSimulation.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Duncan Brown, Eirini Messaritaki, Gareth Jones, Jolien Creighton, Patrick Brady, Reinhard Prix, Anand Sengupta, Stephen Fairhurst, Craig Robinson , Thomas Cokelaer
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: FindChirpIMRSimulation.c
23 *
24 * Author: L. M. Goggin
25 *
26 *-----------------------------------------------------------------------
27 */
28/** \cond LALINSPIRAL */
29
30#include <lal/Units.h>
31#include <lal/Date.h>
32#include <lal/AVFactories.h>
33#include <lal/VectorOps.h>
34#include <lal/SeqFactories.h>
35#include <lal/DetectorSite.h>
36#include <lal/GenerateInspiral.h>
37#include <lal/GeneratePPNInspiral.h>
38#include <lal/SimulateCoherentGW.h>
39#include <Inject.h>
41#include <lal/LIGOLwXML.h>
42#include <lal/LIGOMetadataTables.h>
43#include <lal/LIGOMetadataInspiralUtils.h>
44#include <lal/LALInspiralBank.h>
45#include <lal/FindChirp.h>
46#include <lal/LALStdlib.h>
47#include <lal/LALInspiralBank.h>
48#include <lal/GenerateInspiral.h>
49#include <lal/GenerateInspRing.h>
50#include <lal/TimeSeries.h>
51
52
53/**
54 * \brief Provides an interface between code build from \ref lalinspiral_findchirp and
55 * various simulation packages for injecting chirps into data.
56 * \author Brown, D. A. and Creighton, T. D
57 *
58 * Injects the signals described
59 * in the linked list of \c SimInspiralTable structures \c events
60 * into the data \c chan. The response function \c resp should
61 * contain the response function to use when injecting the signals into the data.
62 */
63void
66 REAL4TimeSeries *chan,
67 SimInspiralTable *events,
68 SimRingdownTable *ringdownevents,
70 INT4 injectSignalType
71 )
72
73{
74 UINT4 k;
76 SimInspiralTable *thisEvent = NULL;
77 SimRingdownTable *thisRingdownEvent = NULL;
78 PPNParamStruc ppnParams;
79 CoherentGW waveform, *wfm;
80 INT8 waveformStartTime;
81 REAL4TimeSeries signalvec;
82 COMPLEX8Vector *unity = NULL;
83 CHAR warnMsg[512];
84#if 0
85 UINT4 n;
86 UINT4 i;
87#endif
88
91
92 ASSERT( chan, status,
93 FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL );
94 ASSERT( chan->data, status,
95 FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL );
96 ASSERT( chan->data->data, status,
97 FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL );
98
99 ASSERT( events, status,
100 FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL );
101
102 ASSERT( resp, status,
103 FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL );
104 ASSERT( resp->data, status,
105 FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL );
106 ASSERT( resp->data->data, status,
107 FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL );
108
109
110 /*
111 *
112 * set up structures and parameters needed
113 *
114 */
115
116 /* fixed waveform injection parameters */
117 memset( &ppnParams, 0, sizeof(PPNParamStruc) );
118 ppnParams.deltaT = chan->deltaT;
119 ppnParams.lengthIn = 0;
120 ppnParams.ppn = NULL;
121
122
123 /*
124 *
125 * compute the transfer function from the given response function
126 *
127 */
128
129
130 /* allocate memory and copy the parameters describing the freq series */
131 memset( &detector, 0, sizeof( DetectorResponse ) );
132 detector.transfer = (COMPLEX8FrequencySeries *)
134 if ( ! detector.transfer )
135 {
136 ABORT( status, FINDCHIRPH_EALOC, FINDCHIRPH_MSGEALOC );
137 }
138 memcpy( &(detector.transfer->epoch), &(resp->epoch),
139 sizeof(LIGOTimeGPS) );
140 detector.transfer->f0 = resp->f0;
141 detector.transfer->deltaF = resp->deltaF;
142
143 detector.site = (LALDetector *) LALMalloc( sizeof(LALDetector) );
144 /* set the detector site */
145 switch ( chan->name[0] )
146 {
147 case 'H':
149 LALWarning( status, "computing waveform for Hanford." );
150 break;
151 case 'L':
153 LALWarning( status, "computing waveform for Livingston." );
154 break;
155 case 'G':
157 LALWarning( status, "computing waveform for GEO600." );
158 break;
159 case 'T':
161 LALWarning( status, "computing waveform for TAMA300." );
162 break;
163 case 'V':
165 LALWarning( status, "computing waveform for Virgo." );
166 break;
167 default:
168 LALFree( detector.site );
169 detector.site = NULL;
170 LALWarning( status, "Unknown detector site, computing plus mode "
171 "waveform with no time delay" );
172 break;
173 }
174
175 /* set up units for the transfer function */
176 if (XLALUnitDivide( &(detector.transfer->sampleUnits),
177 &lalADCCountUnit, &lalStrainUnit ) == NULL) {
179 }
180
181 /* invert the response function to get the transfer function */
182 LALCCreateVector( status->statusPtr, &( detector.transfer->data ),
183 resp->data->length );
185
186 LALCCreateVector( status->statusPtr, &unity, resp->data->length );
188 for ( k = 0; k < resp->data->length; ++k )
189 {
190 unity->data[k] = 1.0;
191 }
192
193 LALCCVectorDivide( status->statusPtr, detector.transfer->data, unity,
194 resp->data );
196
199
200 thisRingdownEvent = ringdownevents;
201
202 /*
203 *
204 * loop over the signals and inject them into the time series
205 *
206 */
207
208
209 for ( thisEvent = events; thisEvent; thisEvent = thisEvent->next)
210 {
211 /*
212 *
213 * generate waveform and inject it into the data
214 *
215 */
216
217
218 /* clear the waveform structure */
219 memset( &waveform, 0, sizeof(CoherentGW) );
220
221 LALGenerateInspiral(status->statusPtr, &waveform, thisEvent, &ppnParams);
223
224 /* add the ringdown */
225 wfm = XLALGenerateInspRing( &waveform, thisEvent, thisRingdownEvent,
226 injectSignalType );
227
228 if ( !wfm )
229 {
230 fprintf( stderr, "Failed to generate the waveform \n" );
231 if (xlalErrno == XLAL_EFAILED)
232 {
233 fprintf( stderr, "Too much merger\n");
236 return;
237 }
238 else exit ( 1 );
239 }
240
241
242 waveform = *wfm;
243
244 LALInfo( status, ppnParams.termDescription );
245
246 if ( thisEvent->geocent_end_time.gpsSeconds )
247 {
248 /* get the gps start time of the signal to inject */
249 waveformStartTime = XLALGPSToINT8NS( &(thisEvent->geocent_end_time) );
250 waveformStartTime -= (INT8) ( 1000000000.0 * ppnParams.tc );
251 }
252 else
253 {
254 LALInfo( status, "Waveform start time is zero: injecting waveform "
255 "into center of data segment" );
256
257 /* center the waveform in the data segment */
258 waveformStartTime = XLALGPSToINT8NS( &(chan->epoch) );
259
260 waveformStartTime += (INT8) ( 1000000000.0 *
261 ((REAL8) (chan->data->length - ppnParams.length) / 2.0) * chan->deltaT
262 );
263 }
264
265 snprintf( warnMsg, XLAL_NUM_ELEM(warnMsg),
266 "Injected waveform timing:\n"
267 "thisEvent->geocent_end_time.gpsSeconds = %d\n"
268 "thisEvent->geocent_end_time.gpsNanoSeconds = %d\n"
269 "ppnParams.tc = %e\n"
270 "waveformStartTime = %" LAL_INT8_FORMAT "\n",
271 thisEvent->geocent_end_time.gpsSeconds,
273 ppnParams.tc,
274 waveformStartTime );
275 LALInfo( status, warnMsg );
276
277 /* clear the signal structure */
278 memset( &signalvec, 0, sizeof(REAL4TimeSeries) );
279
280 /* set the start times for injection */
281 XLALINT8NSToGPS( &(waveform.a->epoch), waveformStartTime );
282 memcpy( &(waveform.f->epoch), &(waveform.a->epoch),
283 sizeof(LIGOTimeGPS) );
284 memcpy( &(waveform.phi->epoch), &(waveform.a->epoch),
285 sizeof(LIGOTimeGPS) );
286
287 /* set the start time of the signal vector to the start time of the chan */
288 signalvec.epoch = chan->epoch;
289
290 /* set the parameters for the signal time series */
291 signalvec.deltaT = chan->deltaT;
292 if ( ( signalvec.f0 = chan->f0 ) != 0 )
293 {
294 ABORT( status, FINDCHIRPH_EHETR, FINDCHIRPH_MSGEHETR );
295 }
296 signalvec.sampleUnits = lalADCCountUnit;
297
298 /* simulate the detectors response to the inspiral */
299 LALSCreateVector( status->statusPtr, &(signalvec.data), chan->data->length );
301
303 &signalvec, &waveform, &detector );
305
306/* *****************************************************************************/
307#if 0
308 FILE *fp;
309 char fname[512];
310 UINT4 jj, kplus, kcross;
311 snprintf( fname, XLAL_NUM_ELEM(fname),
312 "waveform-%d-%d-%s.txt",
313 thisEvent->geocent_end_time.gpsSeconds,
315 thisEvent->waveform );
316 fp = fopen( fname, "w" );
317 for( jj = 0, kplus = 0, kcross = 1; jj < waveform.phi->data->length;
318 ++jj, kplus += 2, kcross +=2 )
319 {
320 fprintf(fp, "%d %e %e %le %e\n", jj,
321 waveform.a->data->data[kplus],
322 waveform.a->data->data[kcross],
323 waveform.phi->data->data[jj],
324 waveform.f->data->data[jj]);
325 }
326 fclose( fp );
327#endif
328
329/* ********************************************************************************/
330#if 0
331 FILE *fp;
332 char fname[512];
333 UINT4 jj;
334 snprintf( fname, XLAL_NUM_ELEM(fname),
335 "waveform-%d-%d-%s.txt",
336 thisEvent->geocent_end_time.gpsSeconds,
338 thisEvent->waveform );
339 fp = fopen( fname, "w" );
340 for( jj = 0; jj < signalvec.data->length; ++jj )
341 {
342 fprintf(fp, "%d %e %e \n", jj, signalvec.data->data[jj]);
343 }
344 fclose( fp );
345#endif
346
347/* ********************************************************************************/
348
349
350 /* inject the signal into the data channel */
351 LALSSInjectTimeSeries( status->statusPtr, chan, &signalvec );
353
354 /* allocate and go to next SimRingdownTable */
355 if( thisEvent->next )
356 thisRingdownEvent = thisRingdownEvent->next = (SimRingdownTable *)
357 calloc( 1, sizeof(SimRingdownTable) );
358 else
359 thisRingdownEvent->next = NULL;
360
361 /* destroy the signal */
362 LALSDestroyVector( status->statusPtr, &(signalvec.data) );
364
367
370
371 LALDDestroyVector( status->statusPtr, &(waveform.phi->data) );
373
374 if ( waveform.shift )
375 {
376 LALSDestroyVector( status->statusPtr, &(waveform.shift->data) );
378 }
379
380 LALFree( waveform.a );
381 LALFree( waveform.f );
382 LALFree( waveform.phi );
383 if ( waveform.shift )
384 {
385 LALFree( waveform.shift );
386 }
387
388 }
389
390 LALCDestroyVector( status->statusPtr, &( detector.transfer->data ) );
392
393 if ( detector.site ) LALFree( detector.site );
394 LALFree( detector.transfer );
395
397 RETURN( status );
398}
399
400/** \endcond */
LALDetectorIndexLLODIFF
LALDetectorIndexGEO600DIFF
LALDetectorIndexTAMA300DIFF
LALDetectorIndexVIRGODIFF
LALDetectorIndexLHODIFF
void LALFindChirpInjectIMR(LALStatus *status, REAL4TimeSeries *chan, SimInspiralTable *events, SimRingdownTable *ringdownevents, COMPLEX8FrequencySeries *resp, INT4 injectSignalType)
Provides an interface between code build from FindChirp Package and various simulation packages for i...
int k
#define LALCalloc(m, n)
#define LALMalloc(n)
#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)
void LALSimulateCoherentGW(LALStatus *status, REAL4TimeSeries *output, CoherentGW *input, DetectorResponse *detector)
#define fprintf
const char * detector
void LALSDestroyVectorSequence(LALStatus *status, REAL4VectorSequence **vectorSequence)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
#define FINDCHIRPH_EALOC
#define FINDCHIRPH_ENULL
#define FINDCHIRPH_EHETR
CoherentGW * XLALGenerateInspRing(CoherentGW *waveform, SimInspiralTable *thisEvent, SimRingdownTable *thisRingEvent, int injectSignalType)
void LALGenerateInspiral(LALStatus *status, CoherentGW *waveform, SimInspiralTable *params, PPNParamStruc *ppnParamsInputOutput)
void LALSSInjectTimeSeries(LALStatus *, REAL4TimeSeries *output, REAL4TimeSeries *signalvec)
#define XLAL_NUM_ELEM(x)
double REAL8
int64_t INT8
char CHAR
uint32_t UINT4
int32_t INT4
int LALWarning(LALStatus *status, const char *warning)
int LALInfo(LALStatus *status, const char *info)
#define LAL_INT8_FORMAT
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
const LALUnit lalStrainUnit
const LALUnit lalADCCountUnit
LALUnit * XLALUnitDivide(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
void LALCCreateVector(LALStatus *, COMPLEX8Vector **, UINT4)
void LALCDestroyVector(LALStatus *, COMPLEX8Vector **)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
void LALCCVectorDivide(LALStatus *status, COMPLEX8Vector *out, const COMPLEX8Vector *in1, const COMPLEX8Vector *in2)
#define xlalErrno
XLAL_SUCCESS
XLAL_EFAILED
LIGOTimeGPS * XLALINT8NSToGPS(LIGOTimeGPS *epoch, INT8 ns)
INT8 XLALGPSToINT8NS(const LIGOTimeGPS *epoch)
static LALStatus status
Definition: inspinj.c:552
int i
Definition: inspinj.c:596
waveform
CHAR fname[256]
Definition: spininj.c:211
COMPLEX8Sequence * data
COMPLEX8 * data
struct tagLALStatus * statusPtr
INT4 gpsNanoSeconds
REAL4Vector * ppn
const CHAR * termDescription
CHAR name[LALNameLength]
REAL4Sequence * data
LALUnit sampleUnits
LIGOTimeGPS epoch
REAL4 * data
LIGOTimeGPS geocent_end_time
struct tagSimInspiralTable * next
CHAR waveform[LIGOMETA_WAVEFORM_MAX]
struct tagSimRingdownTable * next
FILE * fp