LALApps 10.1.0.1-eeff03c
injsgnl.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Duncan Brown, Jolien Creighton, Lisa M. Goggin, Patrick Brady
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#include "config.h"
21
22#include <math.h>
23#include <string.h>
24
25#include <lal/Date.h>
26#include <lal/LALStdlib.h>
27#include <lal/LALStdio.h>
28#include <lal/AVFactories.h>
29#include <GenerateRing.h>
31#include <lal/GenerateInspiral.h>
32#include <lal/LIGOLwXML.h>
33#include <lal/LIGOLwXMLRead.h>
34#include <lal/LIGOMetadataRingdownUtils.h>
35#include <lal/LIGOMetadataUtils.h>
36#include <lal/Units.h>
37#include <lal/FindChirp.h>
38#include <lal/LALSimInspiral.h>
39#include <lal/LALInspiral.h>
40
41#include <LALAppsVCSInfo.h>
42#include "injsgnl.h"
43#include "getresp.h"
44#include "errutil.h"
45
46/* maximum length of filename */
47#define FILENAME_LENGTH 255
48
50 SimRingdownTable **sim,
52)
53{
54 LIGOTimeGPS stopgps = series->epoch;
55 XLALGPSAdd(&stopgps, series->data->length * series->deltaT);
56
57 while(*sim)
58 {
59 if(XLALGPSDiff(&(*sim)->geocent_start_time, &series->epoch) < 0 || XLALGPSDiff(&(*sim)->geocent_start_time, &stopgps) > 0)
60 {
61 /* free this sim, point the variable that contained its address at
62 * the next one in the list */
63 SimRingdownTable *next = (*sim)->next;
65 *sim = next;
66 }
67 else
68 {
69 /* keep this sim, advance to the next address in the list */
70 sim = &(*sim)->next;
71 }
72 }
73}
74
75
76/* routine to inject a signal with parameters read from a LIGOLw-format file */
79 int injectSignalType,
80 const char *injectFile,
81 const char *calCacheFile,
82 REAL4 responseScale,
83 const char *channel_name
84 )
85{
86 /* note: duration is only used for response, and can be relatively coarse */
87 const REAL8 duration = 16; /* determines deltaF=1/dataDuration Hz*/
89 COMPLEX8FrequencySeries *response = NULL;
90 SimInspiralTable *injectList = NULL;
91 SimInspiralTable *thisInject;
92 SimRingdownTable *ringList = NULL;
93 char injFile[FILENAME_LENGTH + 1];
95 INT4 startSec;
96 INT4 stopSec;
97 int strainData;
98 char ifoName[3];
99 char name[LALNameLength];
101 INT4 calType=0;
102
103 /* xml output data */
104 CHAR fname[FILENAME_MAX];
106 Approximant injApproximant;
107
108 /* copy injectFile to injFile (to get rid of const qual) */
109 strncpy( injFile, injectFile, sizeof( injFile ) - 1 );
110 if(snprintf( name, sizeof( name ), "%s_INJ", series->name ) >= (int) sizeof( name )) abort();
111 strncpy( ifoName, series->name, 2 );
112 ifoName[2] = 0;
113
114 /* get list of injections for this data epoch */
115 verbose( "reading simulated-ring tables from file %s\n", injFile );
116 startSec = series->epoch.gpsSeconds;
117 stopSec = startSec + ceil( 1e-9 * series->epoch.gpsNanoSeconds
118 + series->deltaT * series->data->length );
119
120/* call the approprate LAL injection routine */
121 switch ( injectSignalType )
122 {
124 ringList = XLALSimRingdownTableFromLIGOLw( injFile );
126 break;
128 injectList = XLALSimInspiralTableFromLIGOLw( injFile );
129 break;
130 default:
131 error( "unrecognized injection signal type\n" );
132 }
133
134 /* perform the injections */
135 /* get a representative response function */
136 epoch.gpsSeconds = startSec;
137 epoch.gpsNanoSeconds = 0;
138 verbose( "getting response function for GPS time %d.%09d\n",
139 epoch.gpsSeconds, epoch.gpsNanoSeconds );
140
141 /* determine if this is strain data */
142 strainData = !XLALUnitCompare( &series->sampleUnits, &lalStrainUnit );
143
144 /* determine sample rate of data (needed for response) */
145 sampleRate = 1.0/series->deltaT;
146
147 /* this gets an impulse response if we have strain data */
148 response = get_response( calCacheFile, ifoName, &epoch, duration,
149 sampleRate, responseScale, strainData, channel_name );
150
151 /* units must be counts for inject; reset below if they were strain */
152 series->sampleUnits = lalADCCountUnit;
153
154 /* inject the signals */
155 verbose( "injecting signal(s) into time series\n" );
156
157 switch ( injectSignalType )
158 {
160 LAL_CALL( LALRingInjectSignals(&status, series, ringList, response, calType),
161 &status );
162 break;
164 ringList = (SimRingdownTable *) XLALCalloc( 1, sizeof(SimRingdownTable) );
165 LAL_CALL( LALFindChirpInjectIMR( &status, series, injectList, ringList,
166 response, injectSignalType ), &status );
167 break;
169 // Check if these are NINJA injections
170 injApproximant = XLALGetApproximantFromString(injectList->waveform);
171 if ( (int) injApproximant == XLAL_FAILURE)
172 {
173 fprintf( stderr, "could not parse approximant from sim_inspiral.waveform\n" );
174 exit( 1 );
175 }
176 if (injApproximant == NumRelNinja2)
177 {
178 XLALSimInjectNinjaSignals(series,ifoName,1./responseScale,injectList);
179 }
180 else
181 {
182 LAL_CALL( LALFindChirpInjectSignals( &status, series, injectList, response ), &status );
183 }
184 break;
185 default:
186 error( "unrecognized injection signal type\n" );
187 }
188
189 /* correct the name */
190 strncpy( series->name, name, sizeof( series->name ) );
191
192 /* reset units if necessary */
193 if ( strainData )
194 series->sampleUnits = lalStrainUnit;
195
196 switch ( injectSignalType )
197 {
199 /* write output to LIGO_LW XML file */
200 /* create the output file name */
201 snprintf( fname, sizeof(fname), "HL-INJECTIONS_0-%d-%d.xml",
202 startSec, stopSec - startSec );
203 fprintf( stdout, "Writing the injection details to %s\n", fname);
204
205 /* open the xml file */
207
208 /* write the sim_ringdown table */
209 if ( ringList )
211
212 /* close the injection file */
214
215 /* free memory */
216
217 }
218
219 while ( injectList )
220 {
221 thisInject = injectList;
222 injectList = injectList->next;
223 LALFree( thisInject );
224 }
225
226 /* free memory */
227 XLALDestroySimRingdownTable( ringList );
228
229 XLALDestroyCOMPLEX8Vector( response->data );
230 LALFree( response );
231
232 return 0;
233}
void LALFindChirpInjectSignals(LALStatus *status, REAL4TimeSeries *chan, SimInspiralTable *events, COMPLEX8FrequencySeries *resp)
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...
#define LAL_CALL(function, statusptr)
void XLALSimInjectNinjaSignals(REAL4TimeSeries *chan, const char *ifo, REAL8 dynRange, SimInspiralTable *events)
#define LALFree(p)
int XLALGetApproximantFromString(const char *waveform)
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLSimRingdownTable(LIGOLwXMLStream *xml, const SimRingdownTable *sim_ringdown)
SimRingdownTable * XLALSimRingdownTableFromLIGOLw(const char *fileName)
SimInspiralTable * XLALSimInspiralTableFromLIGOLw(const char *fileName)
LALRINGDOWN_IMR_INJECT
LALRINGDOWN_PHENOM_INJECT
LALRINGDOWN_RING_INJECT
LALRINGDOWN_EOBNR_INJECT
LALRINGDOWN_IMR_RING_INJECT
void XLALDestroySimRingdownTable(SimRingdownTable *head)
SimRingdownTable * XLALDestroySimRingdownTableRow(SimRingdownTable *row)
#define fprintf
double e
INT4 sampleRate
Definition: blindinj.c:124
INT4 duration
Definition: blindinj.c:123
int verbose
Definition: chirplen.c:77
int error(const char *fmt,...)
Definition: errutil.c:37
COMPLEX8FrequencySeries * get_response(const char *cacheName, const char *ifoName, LIGOTimeGPS *epoch, REAL8 dataDuration, REAL8 dataSampleRate, REAL4 responseScale, int strainData, const char *channel_name)
Definition: getresp.c:45
void LALRingInjectSignals(LALStatus *stat, REAL4TimeSeries *series, SimRingdownTable *injections, COMPLEX8FrequencySeries *resp, INT4 calType)
Definition: GenerateRing.c:219
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
int32_t INT4
float REAL4
LALNameLength
void * XLALCalloc(size_t m, size_t n)
Approximant
NumRelNinja2
int XLALUnitCompare(const LALUnit *unit1, const LALUnit *unit2)
const LALUnit lalStrainUnit
const LALUnit lalADCCountUnit
void XLALDestroyCOMPLEX8Vector(COMPLEX8Vector *vector)
XLAL_FAILURE
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
static void clip_sim_ringdown_to_series(SimRingdownTable **sim, REAL4TimeSeries *series)
Definition: injsgnl.c:49
#define FILENAME_LENGTH
Definition: injsgnl.c:47
int ring_inject_signal(REAL4TimeSeries *series, int injectSignalType, const char *injectFile, const char *calCacheFile, REAL4 responseScale, const char *channel_name)
Definition: injsgnl.c:77
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
static LALStatus status
Definition: inspinj.c:552
LIGOLwXMLStream * xmlfp
Definition: spininj.c:210
CHAR fname[256]
Definition: spininj.c:211
COMPLEX8Sequence * data
struct tagSimInspiralTable * next
CHAR waveform[LIGOMETA_WAVEFORM_MAX]
struct tagSimRingdownTable * next
Definition: series.h:36
char * name
Definition: series.h:37
float * data
Definition: series.h:46
enum @1 epoch