Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALInferenceReadData.c
Go to the documentation of this file.
1/*
2 * LALInferenceReadData.c: Bayesian Followup functions
3 *
4 * Copyright (C) 2009,2012 Ilya Mandel, Vivien Raymond, Christian
5 * Roever, Marc van der Sluys, John Veitch, Salvatore Vitale, and
6 * Will M. Farr
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with with program; see the file COPYING. If not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * MA 02110-1301 USA
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <errno.h>
28#include <unistd.h>
29
30#include <lal/LALStdio.h>
31#include <lal/LALStdlib.h>
32
33#include <lal/LALInspiral.h>
34#include <lal/LALCache.h>
35#include <lal/LALFrStream.h>
36#include <lal/TimeFreqFFT.h>
37#include <lal/LALDetectors.h>
38#include <lal/AVFactories.h>
39#include <lal/ResampleTimeSeries.h>
40#include <lal/Sequence.h>
41#include <lal/TimeSeries.h>
42#include <lal/FrequencySeries.h>
43#include <lal/Units.h>
44#include <lal/Date.h>
45#include <lal/StringInput.h>
46#include <lal/VectorOps.h>
47#include <lal/Random.h>
48#include <lal/LALNoiseModels.h>
49#include <lal/XLALError.h>
50#include <lal/GenerateInspiral.h>
51#include <lal/LIGOLwXMLRead.h>
52
53#include <lal/SeqFactories.h>
54#include <lal/DetectorSite.h>
55#include <lal/GenerateInspiral.h>
56#include <lal/GeneratePPNInspiral.h>
57#include <lal/SimulateCoherentGW.h>
58#include <lal/LIGOMetadataTables.h>
59#include <lal/LIGOMetadataUtils.h>
60#include <lal/LIGOMetadataInspiralUtils.h>
61#include <lal/LIGOMetadataRingdownUtils.h>
62#include <lal/LALInspiralBank.h>
63#include <lal/FindChirp.h>
64#include <lal/LALInspiralBank.h>
65#include <lal/GenerateInspiral.h>
66#include <lal/NRWaveInject.h>
67#include <lal/GenerateInspRing.h>
68#include <math.h>
69#include <lal/LALInspiral.h>
70#include <lal/LALSimulation.h>
71#include <lal/LIGOLwXMLRead.h>
72
73#include <lal/LALInference.h>
74#include <lal/LALInferenceReadData.h>
75#include <lal/LALInferenceLikelihood.h>
76#include <lal/LALInferenceTemplate.h>
77#include <lal/LALInferenceInit.h>
78#include <lal/LALSimNoise.h>
80/* LIB deps */
81#include <lal/LALInferenceBurstRoutines.h>
82
83struct fvec {
86};
87
88#define LALINFERENCE_DEFAULT_FLOW "20.0"
89
90static void LALInferenceSetGPSTrigtime(LIGOTimeGPS *GPStrig, ProcessParamsTable *commandLine);
91struct fvec *interpFromFile(char *filename, REAL8 squareinput);
92
93struct fvec *interpFromFile(char *filename, REAL8 squareinput){
94 UINT4 fileLength=0;
95 UINT4 i=0;
96 UINT4 minLength=100; /* size of initial file buffer, and also size of increment */
97 FILE *interpfile=NULL;
98 struct fvec *interp=NULL;
99 interp=XLALCalloc(minLength,sizeof(struct fvec)); /* Initialise array */
100 if(!interp) {printf("Unable to allocate memory buffer for reading interpolation file\n");}
101 fileLength=minLength;
102 REAL8 f=0.0,x=0.0;
103 interpfile = fopen(filename,"r");
104 if (interpfile==NULL){
105 printf("Unable to open file %s\n",filename);
106 exit(1);
107 }
108 while(2==fscanf(interpfile," %lf %lf ", &f, &x )){
109 interp[i].f=f;
110 if (squareinput) {
111 interp[i].x=x*x;
112 }
113 else {
114 interp[i].x=x;
115 }
116 i++;
117 if(i>fileLength-1){ /* Grow the array */
118 interp=XLALRealloc(interp,(fileLength+minLength)*sizeof(struct fvec));
119 fileLength+=minLength;
120 }
121 }
122 interp[i].f=0.0; interp[i].x=0.0;
123 fileLength=i+1;
124 interp=XLALRealloc(interp,fileLength*sizeof(struct fvec)); /* Resize array */
125 fclose(interpfile);
126 printf("Read %i records from %s\n",fileLength-1,filename);
127 if(fileLength-1 <1)
128 {
129 XLALPrintError("Error: read no records from %s\n",filename);
130 exit(1);
131 }
132 return interp;
133}
134
135REAL8 interpolate(struct fvec *fvec, REAL8 f);
137 int i=0;
138 REAL8 a=0.0; /* fractional distance between bins */
139 if(f<fvec[1].f) return(INFINITY); /* Frequency below minimum */
140 while((i==0) || (fvec[i].f<f && (fvec[i].x!=0.0 ))){i++;}; //&& fvec[i].f!=0.0)){i++;};
141 if (fvec[i].f==0.0 && fvec[i].x==0.0) /* Frequency above maximum */
142 {
143 return (INFINITY);
144 }
145 a=(fvec[i].f-f)/(fvec[i].f-fvec[i-1].f);
146 return (fvec[i-1].x*a + fvec[i].x*(1.0-a));
147}
148
149void InjectFD(LALInferenceIFOData *IFOdata, SimInspiralTable *inj_table, ProcessParamsTable *commandLine);
151
152typedef void (NoiseFunc)(LALStatus *statusPtr,REAL8 *psd,REAL8 f);
153void MetaNoiseFunc(LALStatus *status, REAL8 *psd, REAL8 f, struct fvec *interp, NoiseFunc *noisefunc);
154
155void MetaNoiseFunc(LALStatus *status, REAL8 *psd, REAL8 f, struct fvec *interp, NoiseFunc *noisefunc){
156 if(interp==NULL&&noisefunc==NULL){
157 printf("ERROR: Trying to calculate PSD with NULL inputs\n");
158 exit(1);
159 }
160 if(interp!=NULL && noisefunc!=NULL){
161 printf("ERROR: You have specified both an interpolation vector and a function to calculate the PSD\n");
162 exit(1);
163 }
164 if(noisefunc!=NULL){
165 noisefunc(status,psd,f);
166 return;
167 }
168 if(interp!=NULL){ /* Use linear interpolation of the interp vector */
169 *psd=interpolate(interp,f);
170 return;
171 }
172}
173
174
175static const LALUnit strainPerCount={0,{0,0,0,0,0,1,-1},{0,0,0,0,0,0,0}};
176
177static REAL8TimeSeries *readTseries(LALCache *cache, CHAR *channel, LIGOTimeGPS start, REAL8 length);
178static void makeWhiteData(LALInferenceIFOData *IFOdata);
179static void PrintSNRsToFile(LALInferenceIFOData *IFOdata , char SNRpath[] );
180
181
182static LALCache *GlobFramesPWD( char *ifo);
183static LALCache *GlobFramesPWD(char *ifo)
184{
185 LALCache *frGlobCache = NULL;
186
187 /* create a frame cache by globbing all *.gwf files in the pwd */
188 /* FIXME: This should really open all the files and see if the desired channel is in there */
189 char globPattern[8];
190 sprintf(globPattern,"%c-*.gwf",ifo[0]);
191 frGlobCache = XLALCacheGlob(NULL,globPattern);
192
193 /* check we globbed at least one frame file */
194 if ( ! frGlobCache->length )
195 {
196 fprintf( stderr, "error: no frame file files found\n");
197 exit( 1 );
198 }
199 CHAR ifoRegExPattern[6];
200 LALCache *frInCache=NULL;
201 /* sieve out the requested data type */
202 snprintf( ifoRegExPattern,
203 XLAL_NUM_ELEM(ifoRegExPattern), ".*%c.*",
204 ifo[0] );
205 fprintf(stderr,"GlobFramesPWD : Found unseived src files:\n");
206 for(UINT4 i=0;i<frGlobCache->length;i++)
207 fprintf(stderr,"(%s,%s,%s)\n",frGlobCache->list[i].src,frGlobCache->list[i].dsc,frGlobCache->list[i].url);
208 frInCache = XLALCacheDuplicate(frGlobCache);
209 XLALCacheSieve(frInCache, 0, 0, ifoRegExPattern, NULL, NULL);
210 if ( ! frGlobCache->length )
211 {
212 fprintf( stderr, "error: no frame file files found after sieving\n");
213 exit( 1 );
214 }
215 else
216 {
217 fprintf(stderr,"GlobFramesPWD : Sieved frames with pattern %s. Found src files:\n",ifoRegExPattern);
218 for(UINT4 i=0;i<frInCache->length;i++)
219 fprintf(stderr,"(%s,%s,%s)\n",frInCache->list[i].src,frInCache->list[i].dsc,frInCache->list[i].url);
220 }
221
222 return(frGlobCache);
223}
224
225static REAL8TimeSeries *readTseries(LALCache *cache, CHAR *channel, LIGOTimeGPS start, REAL8 length)
226{
227 /* This function attempts to read the data from the given cache file. If it failes to open the data
228 * it waits for a period and tries again, up to 5 times. This is an attempt to get around overloading
229 * of file servers when many jobs are run at the time same */
231 UINT4 max_tries=7,tries=0,delay=5;
232 memset(&status,0,sizeof(status));
233 LALFrStream *stream = NULL;
234 REAL8TimeSeries *out = NULL;
235 if(cache==NULL) fprintf(stderr,"readTseries ERROR: Received NULL pointer for channel %s\n",channel);
236 for (tries=0,delay=5;tries<max_tries;tries++,delay*=2) {
237 stream = XLALFrStreamCacheOpen( cache );
238 if(stream) break;
239 sleep(delay);
240 }
241 if(stream==NULL) {fprintf(stderr,"readTseries ERROR: Unable to open stream from frame cache file\n"); exit(-1);}
242
243 for (tries=0,delay=5;tries<max_tries;tries++,delay*=2) {
244 out = XLALFrStreamInputREAL8TimeSeries( stream, channel, &start, length , 0 );
245 if(out) break;
246 sleep(delay);
247 }
248 if(out==NULL) fprintf(stderr,"readTseries ERROR: unable to read channel %s at times %i - %f\nCheck the specified data duration is not too long\n",channel,start.gpsSeconds,start.gpsSeconds+length);
249 XLALFrStreamClose(stream);
250 return out;
251}
252
253/**
254 * Parse the command line looking for options of the kind --ifo H1 --H1-channel H1:LDAS_STRAIN --H1-cache H1.cache --H1-flow 20.0 --H1-fhigh 4096.0 --H1-timeslide 100.0 --H1-asd asd_ascii.txt --H1-psd psd_ascii.txt ...
255 * It is necessary to use this method instead of the old method for the pipeline to work in DAX mode. Warning: do not mix options between
256 * the old and new style.
257 */
258static INT4 getDataOptionsByDetectors(ProcessParamsTable *commandLine, char ***ifos, char ***caches, char ***channels, char ***flows , char ***fhighs, char ***timeslides, char ***asds, char ***psds, UINT4 *N)
259{
260 /* Check that the input has no lists with [ifo,ifo] */
261 ProcessParamsTable *this=commandLine;
262 UINT4 i=0;
263 *caches=*ifos=*channels=*flows=*fhighs=*timeslides=*asds=*psds=NULL;
264 *N=0;
265 char tmp[128];
266 if(!this) {fprintf(stderr,"No command line arguments given!\n"); exit(1);}
267 /* Construct a list of IFOs */
268 for(this=commandLine;this;this=this->next)
269 {
270 if(!strcmp(this->param,"--ifo"))
271 {
272 (*N)++;
273 *ifos=XLALRealloc(*ifos,*N*sizeof(char *));
274 (*ifos)[*N-1]=XLALStringDuplicate(this->value);
275 }
276 }
277 *caches=XLALCalloc(*N,sizeof(char *));
278 *channels=XLALCalloc(*N,sizeof(char *));
279 *flows=XLALCalloc(*N,sizeof(REAL8));
280 *fhighs=XLALCalloc(*N,sizeof(REAL8));
281 *timeslides=XLALCalloc(*N,sizeof(REAL8));
282 *asds=XLALCalloc(*N,sizeof(char *));
283 *psds=XLALCalloc(*N,sizeof(char *));
284
285 int globFrames=!!LALInferenceGetProcParamVal(commandLine,"--glob-frame-data");
286
287 /* For each IFO, fetch the other options if available */
288 for(i=0;i<*N;i++)
289 {
290 /* Cache */
291 if(!globFrames){
292 sprintf(tmp,"--%s-cache",(*ifos)[i]);
293 this=LALInferenceGetProcParamVal(commandLine,tmp);
294 if(!this){fprintf(stderr,"ERROR: Must specify a cache file for %s with --%s-cache\n",(*ifos)[i],(*ifos)[i]); exit(1);}
295 (*caches)[i]=XLALStringDuplicate(this->value);
296 }
297
298 /* Channel */
299 sprintf(tmp,"--%s-channel",(*ifos)[i]);
300 this=LALInferenceGetProcParamVal(commandLine,tmp);
301 (*channels)[i]=XLALStringDuplicate(this?this->value:"Unknown channel");
302
303 /* flow */
304 sprintf(tmp,"--%s-flow",(*ifos)[i]);
305 this=LALInferenceGetProcParamVal(commandLine,tmp);
306 (*flows)[i]=XLALStringDuplicate(this?this->value:LALINFERENCE_DEFAULT_FLOW);
307
308 /* fhigh */
309 sprintf(tmp,"--%s-fhigh",(*ifos)[i]);
310 this=LALInferenceGetProcParamVal(commandLine,tmp);
311 (*fhighs)[i]=this?XLALStringDuplicate(this->value):NULL;
312
313 /* timeslides */
314 sprintf(tmp,"--%s-timeslide",(*ifos)[i]);
315 this=LALInferenceGetProcParamVal(commandLine,tmp);
316 (*timeslides)[i]=XLALStringDuplicate(this?this->value:"0.0");
317
318 /* ASD */
319 sprintf(tmp,"--%s-asd",(*ifos)[i]);
320 this=LALInferenceGetProcParamVal(commandLine,tmp);
321 (*asds)[i]=this?XLALStringDuplicate(this->value):NULL;
322
323 /* PSD */
324 sprintf(tmp,"--%s-psd",(*ifos)[i]);
325 this=LALInferenceGetProcParamVal(commandLine,tmp);
326 (*psds)[i]=this?XLALStringDuplicate(this->value):NULL;
327 }
328 return(1);
329}
330
331/**
332 * Parse the command line looking for options of the kind ---IFO-name value
333 * Unlike the function above, this one does not have a preset list of names to lookup, but instead uses the option "name"
334 * It is necessary to use this method instead of the old method for the pipeline to work in DAX mode. Warning: do not mix options between
335 * the old and new style.
336 * Return 0 if the number of options --IFO-name doesn't much the number of ifos, 1 otherwise. Fills in the pointer out with the values that were found.
337 */
338static INT4 getNamedDataOptionsByDetectors(ProcessParamsTable *commandLine, char ***ifos, char ***out, const char *name, UINT4 *N)
339{
340 /* Check that the input has no lists with [ifo,ifo] */
341 ProcessParamsTable *this=commandLine;
342 UINT4 i=0;
343 *out=*ifos=NULL;
344 *N=0;
345 char tmp[128];
346 if(!this) {fprintf(stderr,"No command line arguments given!\n"); exit(1);}
347 /* Construct a list of IFOs */
348 for(this=commandLine;this;this=this->next)
349 {
350 if(!strcmp(this->param,"--ifo"))
351 {
352 (*N)++;
353 *ifos=XLALRealloc(*ifos,*N*sizeof(char *));
354 (*ifos)[*N-1]=XLALStringDuplicate(this->value);
355 }
356 }
357 *out=XLALCalloc(*N,sizeof(char *));
358
359 UINT4 found=0;
360 /* For each IFO, fetch the other options if available */
361 for(i=0;i<*N;i++)
362 {
363 /* Channel */
364 sprintf(tmp,"--%s-%s",(*ifos)[i],name);
365 this=LALInferenceGetProcParamVal(commandLine,tmp);
366 (*out)[i]=this?XLALStringDuplicate(this->value):NULL;
367 if (this) found++;
368
369 }
370 if (found==*N)
371 return(1);
372 else
373 return 0;
374}
375
377
379 memset(&status,0,sizeof(status));
380 UINT4 Nifo=0,i,j;
381 LALInferenceIFOData *thisData=IFOdata;
382 UINT4 q=0;
383 UINT4 event=0;
384 ProcessParamsTable *procparam=NULL,*ppt=NULL;
385 SimInspiralTable *injTable=NULL;
386 //ProcessParamsTable *pptdatadump=NULL;
387 LIGOTimeGPS GPStrig;
388 while(thisData){
389 thisData=thisData->next;
390 Nifo++;
391 }
392
393 procparam=LALInferenceGetProcParamVal(commandLine,"--inj");
394 if(procparam){
395 injTable = XLALSimInspiralTableFromLIGOLw(procparam->value);
396 if(!injTable){
397 fprintf(stderr,"Unable to open injection file(LALInferenceReadData) %s\n",procparam->value);
398 exit(1);
399 }
400 procparam=LALInferenceGetProcParamVal(commandLine,"--event");
401 if(procparam) {
402 event=atoi(procparam->value);
403 while(q<event) {q++; injTable=injTable->next;}
404 }
405 else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id")))
406 {
407 while(injTable)
408 {
409 if(injTable->simulation_id == atol(procparam->value)) break;
410 else injTable=injTable->next;
411 }
412 if(!injTable){
413 fprintf(stderr,"Error, cannot find simulation id %s in injection file\n",procparam->value);
414 exit(1);
415 }
416 }
417 }
418
419 if(LALInferenceGetProcParamVal(commandLine,"--trigtime")){
420 procparam=LALInferenceGetProcParamVal(commandLine,"--trigtime");
421 XLALStrToGPS(&GPStrig,procparam->value,NULL);
422 }
423 else{
424 if(injTable) memcpy(&GPStrig,&(injTable->geocent_end_time),sizeof(GPStrig));
425 else {
426 fprintf(stderr,"+++ Error: No trigger time specifed and no injection given \n");
427 exit(1);
428 }
429 }
430
431 if (LALInferenceGetProcParamVal(commandLine, "--data-dump")) {
432 //pptdatadump=LALInferenceGetProcParamVal(commandLine,"--data-dump");
433 const UINT4 nameLength=FILENAME_MAX+50;
434 char filename[nameLength];
435 FILE *out;
436
437 for (i=0;i<Nifo;i++) {
438
439 ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
440 if(ppt) {
441 if((int)nameLength<=snprintf(filename, nameLength, "%s%s-timeDataWithInjection.dat", ppt->value, IFOdata[i].name))
442 XLAL_ERROR_VOID(XLAL_EINVAL, "Output filename too long!");
443 }
444 //else if(strcmp(pptdatadump->value,"")) {
445 // snprintf(filename, nameLength, "%s/%s-timeDataWithInjection.dat", pptdatadump->value, IFOdata[i].name);
446 //}
447 else
448 snprintf(filename, nameLength, "%.3f_%s-timeDataWithInjection.dat", GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
449 out = fopen(filename, "w");
450 if(!out){
451 fprintf(stderr,"Unable to open the path %s for writing time data with injection files\n",filename);
452 exit(1);
453 }
454 for (j = 0; j < IFOdata[i].timeData->data->length; j++) {
455 REAL8 t = XLALGPSGetREAL8(&(IFOdata[i].timeData->epoch)) +
456 j * IFOdata[i].timeData->deltaT;
457 REAL8 d = IFOdata[i].timeData->data->data[j];
458
459 fprintf(out, "%.6f %g\n", t, d);
460 }
461 fclose(out);
462
463 ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
464 if(ppt) {
465 snprintf(filename, nameLength, "%s%s-freqDataWithInjection.dat", ppt->value, IFOdata[i].name) ;
466 }
467 //else if(strcmp(pptdatadump->value,"")) {
468 // snprintf(filename, nameLength, "%s/%s-freqDataWithInjection.dat", pptdatadump->value, IFOdata[i].name);
469 //}
470 else
471 snprintf(filename, nameLength, "%.3f_%s-freqDataWithInjection.dat", GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
472 out = fopen(filename, "w");
473 if(!out){
474 fprintf(stderr,"Unable to open the path %s for writing freq data with injection files\n",filename);
475 exit(1);
476 }
477 for (j = 0; j < IFOdata[i].freqData->data->length; j++) {
478 REAL8 f = IFOdata[i].freqData->deltaF * j;
479 REAL8 dre = creal(IFOdata[i].freqData->data->data[j]);
480 REAL8 dim = cimag(IFOdata[i].freqData->data->data[j]);
481
482 fprintf(out, "%10.10g %10.10g %10.10g\n", f, dre, dim);
483 }
484 fclose(out);
485
486 }
487
488 }
489
490}
491
492#define USAGE "\
493 ----------------------------------------------\n\
494 --- Data Parameters --------------------------\n\
495 ----------------------------------------------\n\
496 Options for reading/generating data. User should specify which interferometers\n\
497 to use and their data source using the following options. The data source\n\
498 can be either a LFS cache file (generated by gw_data_find) with channel name\n\
499 (e.g. --H1-cache H1.cache --H1-channel H1:DCS-CALIB-STRAIN_C02 )\n\
500 or internally-generated gaussian noise with a given detector PSD model\n\
501 (e.g. --H1-cache LALSimAdLIGO --dataseed 1234)\n\
502 or by searching for frame files in the local directory\n\
503 (e.g. --glob-frame-data --H1-channel H1:DCS-CALIB-STRAIN_C02)\n\
504 \n\
505 Additional noise curves for simulated data can be specified by providing\n\
506 their PSD or ASD as a text file. See detailed options below.\n\
507 \n\
508 --ifo IFO1 [--ifo IFO2 ...] IFOs can be H1,L1,V1\n\
509 --IFO1-cache cache1 Cache files \n\
510 [--IFO2-cache2 cache2 ...] lal PSDs: LAL{Ad}LIGO, LALVirgo\n\
511 lalsimuation PSDs: LALSim{Ad}LIGO, LALSim{Ad}Virgo\n\
512 interpolate from file: interp:asd_file.txt\n\
513 --psdstart GPStime GPS start time of PSD estimation data\n\
514 --psdlength length Length of PSD estimation data in seconds\n\
515 --seglen length Length of segments for PSD estimation and analysis in seconds\n\
516 (--glob-frame-data) Will search for frame files containing data in the PWD.\n\
517 Filenames must begin with the IFO's 1-letter code, e.g. H-*.gwf\n\
518 (--dont-dump-extras) If given, won't save PSD and SNR files\n\
519 (--dump-geocenter-pols) If given, print out the TD/FD h_plus and h_cross polarisations\n\
520 (--trigtime GPStime) GPS time of the trigger to analyse\n\
521 (optional when using --margtime or --margtimephi)\n\
522 (--segment-start) GPS time of the start of the segment\n\
523 (optional with --trigtime,\n\
524 default: seglen-2 s before --trigtime)\n\
525 (--srate rate) Downsample data to rate in Hz (4096.0,)\n\
526 (--padding PAD [sec] Override default 0.4 seconds padding\n\
527 (--injectionsrate rate) Downsample injection signal to rate in Hz (--srate)\n\
528 (--IFO1-flow freq1 Specify lower frequency cutoff for overlap integral (20.0)\n\
529 [--IFO2-flow freq2 ...])\n\
530 (--IFO1-fhigh freq1 Specify higher frequency cutoff for overlap integral (Nyquist\n\
531 [--IFO2-fhigh freq2 ...]) freq 0.5*srate)\n\
532 (--IFO1-channel chan1 Specify channel names when reading cache files\n\
533 [--IFO2-channel chan2 ...])\n\
534 (--IFO1-asd asd1-ascii.txt Read in ASD from ascii file. This is not equivalent \n\
535 [--IFO2-asd asd2-ascii.txt ...]) to using --IFO1-cache interp:asd_file.txt since the former\n\
536 won't use the ascii ASD to generate fake noise. \n\
537 (--IFO1-psd psd1-ascii.txt Read in PSD from ascii file. This is not equivalent \n\
538 [--IFO2-psd psd2-ascii.txt ...]) to using --IFO1-cache interp:asd_file.txt since the former\n\
539 won't use the ascii PSD to generate fake noise. \n\
540 (--dataseed number) Specify random seed to use when generating data\n\
541 (--lalinspiralinjection) Enables injections via the LALInspiral package\n\
542 (--inj-fref) Reference frequency of parameters in injection XML (default 100Hz)\n\
543 (--inj-lambda1) value of lambda1 to be injected, LALSimulation only (0)\n\
544 (--inj-lambda2) value of lambda2 to be injected, LALSimulation only (0)\n\
545 (--inj-lambdaT value of lambdaT to be injected (0)\n\
546 (--inj-dlambdaT value of dlambdaT to be injected (0)\n\
547 (--inj-logp1) value of logp1 to be injected\n\
548 (--inj-gamma1) value of gamma1 to be injected\n\
549 (--inj-gamma2) value of gamma2 to be injected\n\
550 (--inj-gamma3) value of gamma3 to be injected\n\
551 (--inj-SDgamma0) value of SDgamma0 to be injected (0)\n\
552 (--inj-SDgamma1) value of SDgamma1 to be injected (0)\n\
553 (--inj-SDgamma2) value of SDgamma2 to be injected (0)\n\
554 (--inj-SDgamma3) value of SDgamma3 to be injected (0)\n\
555 (--inj-spinOrder PNorder) Specify twice the injection PN order (e.g. 5 <==> 2.5PN)\n\
556 of spin effects effects to use, only for LALSimulation\n\
557 (default: -1 <==> Use all spin effects).\n\
558 (--inj-tidalOrder PNorder) Specify twice the injection PN order (e.g. 10 <==> 5PN)\n\
559 of tidal effects to use, only for LALSimulation\n\
560 (default: -1 <==> Use all tidal effects).\n\
561 (--inj-spin-frame FRAME Specify injection spin frame: choice of total-j, orbital-l, view.\n\
562 (Default = OrbitalL).\n\
563 (--inj-numreldata FileName) Location of NR data file for the injection of NR waveforms (with NR_hdf5 in injection XML file).\n\
564 (--0noise) Sets the noise realisation to be identically zero\n\
565 (for the fake caches above only)\n\
566 \n"
567
569/* Read in the data and store it in a LALInferenceIFOData structure */
570{
572 INT4 dataseed=0;
573 memset(&status,0,sizeof(status));
574 ProcessParamsTable *procparam=NULL,*ppt=NULL;
575 //ProcessParamsTable *pptdatadump=NULL;
576 LALInferenceIFOData *headIFO=NULL,*IFOdata=NULL;
577 REAL8 SampleRate=4096.0,SegmentLength=0;
578 if(LALInferenceGetProcParamVal(commandLine,"--srate")) SampleRate=atof(LALInferenceGetProcParamVal(commandLine,"--srate")->value);
579 REAL8 defaultFLow = atof(LALINFERENCE_DEFAULT_FLOW);
580 int nSegs=0;
581 size_t seglen=0;
582 REAL8TimeSeries *PSDtimeSeries=NULL;
583 REAL8 padding=0.4;//Default was 1.0 second. However for The Event the Common Inputs specify a Tukey parameter of 0.1, so 0.4 second of padding for 8 seconds of data.
584 UINT4 Ncache=0,Nifo=0,Nchannel=0,NfLow=0,NfHigh=0;
585 UINT4 i,j;
586 //int FakeFlag=0; - set but not used
587 char strainname[]="LSC-STRAIN";
588 //typedef void (NoiseFunc)(LALStatus *statusPtr,REAL8 *psd,REAL8 f);
589 NoiseFunc *PSD=NULL;
590 REAL8 scalefactor=1;
591 RandomParams *datarandparam;
592 int globFrames=0; // 0 = no, 1 = will search for frames in PWD
593 char **channels=NULL;
594 char **caches=NULL;
595 char **asds=NULL;
596 char **psds=NULL;
597 char **IFOnames=NULL;
598 char **fLows=NULL,**fHighs=NULL;
599 char **timeslides=NULL;
600 UINT4 Ntimeslides=0;
601 LIGOTimeGPS GPSstart,GPStrig,segStart;
602 REAL8 PSDdatalength=0;
603 REAL8 AIGOang=0.0; //orientation angle for the proposed Australian detector.
604 procparam=LALInferenceGetProcParamVal(commandLine,"--aigoang");
605 if(!procparam) procparam=LALInferenceGetProcParamVal(commandLine,"--AIGOang");
606 if(procparam)
607 AIGOang=atof(procparam->value)*LAL_PI/180.0;
608
609 struct fvec *interp;
610 int interpFlag=0;
611 REAL8 asdFlag=0;
612
613 if(LALInferenceGetProcParamVal(commandLine,"--glob-frame-data")) globFrames=1;
614
615 /* Check if the new style command line arguments are used */
616 INT4 dataOpts=getDataOptionsByDetectors(commandLine, &IFOnames, &caches, &channels, &fLows, &fHighs, &timeslides, &asds, &psds, &Nifo);
617 /* Check for options if not given in the new style */
618 if(!dataOpts){
619 if(!(globFrames||LALInferenceGetProcParamVal(commandLine,"--cache"))||!(LALInferenceGetProcParamVal(commandLine,"--IFO")||LALInferenceGetProcParamVal(commandLine,"--ifo")))
620 {fprintf(stderr,USAGE); return(NULL);}
621 if(LALInferenceGetProcParamVal(commandLine,"--channel")){
622 LALInferenceParseCharacterOptionString(LALInferenceGetProcParamVal(commandLine,"--channel")->value,&channels,&Nchannel);
623 }
624 LALInferenceParseCharacterOptionString(LALInferenceGetProcParamVal(commandLine,"--cache")->value,&caches,&Ncache);
625 ppt=LALInferenceGetProcParamVal(commandLine,"--ifo");
627
628 ppt=LALInferenceGetProcParamVal(commandLine,"--flow");
629 if(!ppt) ppt=LALInferenceGetProcParamVal(commandLine,"--fLow");
630 if(ppt){
632 }
633 ppt=LALInferenceGetProcParamVal(commandLine,"--fhigh");
634 if(!ppt) ppt=LALInferenceGetProcParamVal(commandLine,"--fHigh");
635 if(ppt){
637 }
638
639 if((ppt=LALInferenceGetProcParamVal(commandLine,"--timeslide"))) LALInferenceParseCharacterOptionString(ppt->value,&timeslides,&Ntimeslides);
640 if(Nifo!=Ncache) {fprintf(stderr,"ERROR: Must specify equal number of IFOs and Cache files\n"); exit(1);}
641 if(Nchannel!=0 && Nchannel!=Nifo) {fprintf(stderr,"ERROR: Please specify a channel for all caches, or omit to use the defaults\n"); exit(1);}
642 }
643 else
644 {
645 NfHigh=Ntimeslides=Ncache=Nchannel=NfLow=Nifo;
646
647 }
648 /* Check for remaining required options */
649 if(!LALInferenceGetProcParamVal(commandLine,"--seglen"))
650 {fprintf(stderr,USAGE); return(NULL);}
651
652 if(LALInferenceGetProcParamVal(commandLine,"--dataseed")){
653 procparam=LALInferenceGetProcParamVal(commandLine,"--dataseed");
654 dataseed=atoi(procparam->value);
655 }
656
657 IFOdata=headIFO=XLALCalloc(sizeof(LALInferenceIFOData),Nifo);
658 if(!IFOdata) XLAL_ERROR_NULL(XLAL_ENOMEM);
659
660 procparam=LALInferenceGetProcParamVal(commandLine,"--psdstart");
661 if (procparam) {
662 XLALStrToGPS(&GPSstart,procparam->value,NULL);
663 if(status.statusCode) REPORTSTATUS(&status);
664 } else
665 XLALINT8NSToGPS(&GPSstart, 0);
666
667 /*Set trigtime in GPStrig using either inj file or --trigtime*/
668 LALInferenceSetGPSTrigtime(&GPStrig,commandLine);
669
670 if(status.statusCode) REPORTSTATUS(&status);
671
672 SegmentLength=atof(LALInferenceGetProcParamVal(commandLine,"--seglen")->value);
673 seglen=(size_t)(SegmentLength*SampleRate);
674
675 ppt=LALInferenceGetProcParamVal(commandLine,"--psdlength");
676 if(ppt) {
677 PSDdatalength=atof(ppt->value);
678 nSegs=(int)floor(PSDdatalength/SegmentLength);
679 }
680
681 CHAR df_argument_name[262];
682 REAL8 dof;
683
684 for(i=0;i<Nifo;i++) {
685 IFOdata[i].fLow=fLows?atof(fLows[i]):defaultFLow;
686 if(fHighs) IFOdata[i].fHigh=fHighs[i]?atof(fHighs[i]):(SampleRate/2.0-(1.0/SegmentLength));
687 else IFOdata[i].fHigh=(SampleRate/2.0-(1.0/SegmentLength));
688 strncpy(IFOdata[i].name, IFOnames[i], DETNAMELEN-1);
689 IFOdata[i].name[DETNAMELEN-1] = 0;
690
691 dof=4.0 / M_PI * nSegs; /* Degrees of freedom parameter */
692 sprintf(df_argument_name,"--dof-%s",IFOdata[i].name);
693 if((ppt=LALInferenceGetProcParamVal(commandLine,df_argument_name)))
694 dof=atof(ppt->value);
695
696 IFOdata[i].STDOF = dof;
697 XLALPrintInfo("Detector %s will run with %g DOF if Student's T likelihood used.\n",
698 IFOdata[i].name, IFOdata[i].STDOF);
699 }
700
701 /* Only allocate this array if there weren't channels read in from the command line */
702 if(!dataOpts && !Nchannel) channels=XLALCalloc(Nifo,sizeof(char *));
703 for(i=0;i<Nifo;i++) {
704 if(!dataOpts && !Nchannel) channels[i]=XLALMalloc(VARNAME_MAX);
705 IFOdata[i].detector=XLALCalloc(1,sizeof(LALDetector));
706
707 if(!strcmp(IFOnames[i],"H1")) {
709 if(!Nchannel) sprintf((channels[i]),"H1:%s",strainname); continue;}
710 if(!strcmp(IFOnames[i],"H2")) {
712 if(!Nchannel) sprintf((channels[i]),"H2:%s",strainname); continue;}
713 if(!strcmp(IFOnames[i],"LLO")||!strcmp(IFOnames[i],"L1")) {
715 if(!Nchannel) sprintf((channels[i]),"L1:%s",strainname); continue;}
716 if(!strcmp(IFOnames[i],"V1")||!strcmp(IFOnames[i],"VIRGO")) {
718 if(!Nchannel) sprintf((channels[i]),"V1:h_16384Hz"); continue;}
719 if(!strcmp(IFOnames[i],"GEO")||!strcmp(IFOnames[i],"G1")) {
721 if(!Nchannel) sprintf((channels[i]),"G1:DER_DATA_H"); continue;}
722
723 if(!strcmp(IFOnames[i],"E1")){
725 if(!Nchannel) sprintf((channels[i]),"E1:STRAIN"); continue;}
726 if(!strcmp(IFOnames[i],"E2")){
728 if(!Nchannel) sprintf((channels[i]),"E2:STRAIN"); continue;}
729 if(!strcmp(IFOnames[i],"E3")){
731 if(!Nchannel) sprintf((channels[i]),"E3:STRAIN"); continue;}
732 if(!strcmp(IFOnames[i],"K1")){
734 if(!Nchannel) sprintf((channels[i]),"K1:STRAIN"); continue;}
735 if(!strcmp(IFOnames[i],"I1")){
737 if(!Nchannel) sprintf((channels[i]),"I1:STRAIN"); continue;}
738 if(!strcmp(IFOnames[i],"A1")||!strcmp(IFOnames[i],"LIGOSouth")){
739 /* Construct a detector at AIGO with 4k arms */
740 LALFrDetector LIGOSouthFr;
741 sprintf(LIGOSouthFr.name,"LIGO-South");
742 sprintf(LIGOSouthFr.prefix,"A1");
743 /* Location of the AIGO detector vertex is */
744 /* 31d21'27.56" S, 115d42'50.34"E */
745 LIGOSouthFr.vertexLatitudeRadians = - (31. + 21./60. + 27.56/3600.)*LAL_PI/180.0;
746 LIGOSouthFr.vertexLongitudeRadians = (115. + 42./60. + 50.34/3600.)*LAL_PI/180.0;
747 LIGOSouthFr.vertexElevation=0.0;
748 LIGOSouthFr.xArmAltitudeRadians=0.0;
749 LIGOSouthFr.xArmAzimuthRadians=AIGOang+LAL_PI/2.;
750 LIGOSouthFr.yArmAltitudeRadians=0.0;
751 LIGOSouthFr.yArmAzimuthRadians=AIGOang;
752 LIGOSouthFr.xArmMidpoint=2000.;
753 LIGOSouthFr.yArmMidpoint=2000.;
754 IFOdata[i].detector=XLALMalloc(sizeof(LALDetector));
755 memset(IFOdata[i].detector,0,sizeof(LALDetector));
757 printf("Created LIGO South detector, location: %lf, %lf, %lf\n",IFOdata[i].detector->location[0],IFOdata[i].detector->location[1],IFOdata[i].detector->location[2]);
758 printf("Detector tensor:\n");
759 for(int jdx=0;jdx<3;jdx++){
760 for(j=0;j<3;j++) printf("%f ",IFOdata[i].detector->response[jdx][j]);
761 printf("\n");
762 }
763 continue;
764 }
765 fprintf(stderr,"Unknown interferometer %s. Valid codes: H1 H2 L1 V1 GEO A1 K1 I1 E1 E2 E3 HM1 HM2 EM1 EM2\n",IFOnames[i]); exit(-1);
766 }
767
768 /* Set up FFT structures and window */
769 for (i=0;i<Nifo;i++){
770 /* Create FFT plans (flag 1 to measure performance) */
771 IFOdata[i].timeToFreqFFTPlan = XLALCreateForwardREAL8FFTPlan((UINT4) seglen, 1 );
772 if(!IFOdata[i].timeToFreqFFTPlan) XLAL_ERROR_NULL(XLAL_ENOMEM);
773 IFOdata[i].freqToTimeFFTPlan = XLALCreateReverseREAL8FFTPlan((UINT4) seglen, 1 );
774 if(!IFOdata[i].freqToTimeFFTPlan) XLAL_ERROR_NULL(XLAL_ENOMEM);
775 IFOdata[i].margFFTPlan = XLALCreateReverseREAL8FFTPlan((UINT4) seglen, 1);
776 if(!IFOdata[i].margFFTPlan) XLAL_ERROR_NULL(XLAL_ENOMEM);
777 /* Setup windows */
778 ppt=LALInferenceGetProcParamVal(commandLine,"--padding");
779 if (ppt){
780 padding=atof(ppt->value);
781 fprintf(stdout,"Using %lf seconds of padding for IFO %s \n",padding, IFOdata[i].name);
782 }
783 if ((REAL8)2.0*padding*SampleRate/(REAL8)seglen <0.0 ||(REAL8)2.0*padding*SampleRate/(REAL8)seglen >1 ){
784 fprintf(stderr,"Padding is negative or 2*padding is bigger than the whole segment. Consider reducing it using --padding or increase --seglen. Exiting\n");
785 exit(1);
786 }
787 IFOdata[i].padding=padding;
788 IFOdata[i].window=XLALCreateTukeyREAL8Window(seglen,(REAL8)2.0*padding*SampleRate/(REAL8)seglen);
789 if(!IFOdata[i].window) XLAL_ERROR_NULL(XLAL_EFUNC);
790 }
791
792 if(!(ppt=LALInferenceGetProcParamVal(commandLine,"--segment-start")))
793 {
794 /* Trigger time = 2 seconds before end of segment (was 1 second, but Common Inputs for The Events are -6 +2*/
795 memcpy(&segStart,&GPStrig,sizeof(LIGOTimeGPS));
796 REAL8 offset=SegmentLength-2.;
797 /* If we are using a burst approximant, put at the center */
798 if ((ppt=LALInferenceGetProcParamVal(commandLine,"--approx"))){
799 if (XLALCheckBurstApproximantFromString(ppt->value)) offset=SegmentLength/2.;
800 }
801 XLALGPSAdd(&segStart,-offset);
802 }
803 else
804 {
805 /* Segment starts at given time */
806 REAL8 segstartR8 = atof(ppt->value);
807 XLALGPSSetREAL8(&segStart,segstartR8);
808 }
809
810
811 /* Read the PSD data */
812 for(i=0;i<Nifo;i++) {
813 memcpy(&(IFOdata[i].epoch),&segStart,sizeof(LIGOTimeGPS));
814 /* Check to see if an interpolation file is specified */
815 interpFlag=0;
816 interp=NULL;
817 if( (globFrames)?0:strstr(caches[i],"interp:")==caches[i]){
818 /* Extract the file name */
819 char *interpfilename=&(caches[i][7]);
820 printf("Looking for ASD interpolation file %s\n",interpfilename);
821 interpFlag=1;
822 asdFlag=1;
823 interp=interpFromFile(interpfilename, asdFlag);
824 }
825 /* Check if fake data is requested */
826 if( (globFrames)?0:(interpFlag || (!(strcmp(caches[i],"LALLIGO") && strcmp(caches[i],"LALVirgo") && strcmp(caches[i],"LALGEO") && strcmp(caches[i],"LALEGO") && strcmp(caches[i],"LALSimLIGO") && strcmp(caches[i],"LALSimAdLIGO") && strcmp(caches[i],"LALSimVirgo") && strcmp(caches[i],"LALSimAdVirgo") && strcmp(caches[i],"LALAdLIGO")))))
827 {
828 if (!LALInferenceGetProcParamVal(commandLine,"--dataseed")){
829 fprintf(stderr,"Error: You need to specify a dataseed when generating data with --dataseed <number>.\n\
830 (--dataseed 0 uses a non-reproducible number from the system clock, and no parallel run is then possible.)\n" );
831 exit(-1);
832 }
833 /* Offset the seed in a way that depends uniquely on the IFO name */
834 int ifo_salt=0;
835 ifo_salt+=(int)IFOnames[i][0]+(int)IFOnames[i][1];
836 datarandparam=XLALCreateRandomParams(dataseed?dataseed+(int)ifo_salt:dataseed);
837 if(!datarandparam) XLAL_ERROR_NULL(XLAL_EFUNC);
838 IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)
839 XLALCreateREAL8FrequencySeries("spectrum",&GPSstart,0.0,
840 (REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
841 if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
842
843 int LALSimPsd=0;
844 /* Selection of the noise curve */
845 if(!strcmp(caches[i],"LALLIGO")) {PSD = &LALLIGOIPsd; scalefactor=9E-46;}
846 if(!strcmp(caches[i],"LALVirgo")) {PSD = &LALVIRGOPsd; scalefactor=1.0;}
847 if(!strcmp(caches[i],"LALGEO")) {PSD = &LALGEOPsd; scalefactor=1E-46;}
848 if(!strcmp(caches[i],"LALEGO")) {PSD = &LALEGOPsd; scalefactor=1.0;}
849 if(!strcmp(caches[i],"LALAdLIGO")) {PSD = &LALAdvLIGOPsd; scalefactor = 1E-49;}
850 if(!strcmp(caches[i],"LALSimLIGO")) {XLALSimNoisePSD(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow,XLALSimNoisePSDiLIGOSRD ) ; LALSimPsd=1;}
851 if(!strcmp(caches[i],"LALSimVirgo")) {XLALSimNoisePSD(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow,XLALSimNoisePSDVirgo ); LALSimPsd=1;}
852 if(!strcmp(caches[i],"LALSimAdLIGO")) {XLALSimNoisePSDaLIGODesignSensitivityT1800044(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow) ;LALSimPsd=1;}
853 if(!strcmp(caches[i],"LALSimAdVirgo")) {XLALSimNoisePSD(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow,XLALSimNoisePSDAdvVirgo) ;LALSimPsd=1;}
854 if(interpFlag) {PSD=NULL; scalefactor=1.0;}
855 if(PSD==NULL && !(interpFlag|| LALSimPsd)) {fprintf(stderr,"Error: unknown simulated PSD: %s\n",caches[i]); exit(-1);}
856
857 if(LALSimPsd==0){
858 for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
859 {
860 MetaNoiseFunc(&status,&(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]),j*IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,interp,PSD);
861 IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]*=scalefactor;
862 }
863 }
864
865 IFOdata[i].freqData = (COMPLEX16FrequencySeries *)XLALCreateCOMPLEX16FrequencySeries("stilde",&segStart,0.0,IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,&lalDimensionlessUnit,seglen/2 +1);
866 if(!IFOdata[i].freqData) XLAL_ERROR_NULL(XLAL_EFUNC);
867
868 /* Create the fake data */
869 int j_Lo = (int) IFOdata[i].fLow/IFOdata[i].freqData->deltaF;
870 if(LALInferenceGetProcParamVal(commandLine,"--0noise")){
871 for(j=j_Lo;j<IFOdata[i].freqData->data->length;j++){
872 IFOdata[i].freqData->data->data[j] = 0.0;
873 }
874 } else {
875 for(j=j_Lo;j<IFOdata[i].freqData->data->length;j++){
876 IFOdata[i].freqData->data->data[j] = crect(
877 XLALNormalDeviate(datarandparam)*(0.5*sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]/IFOdata[i].freqData->deltaF)),
878 XLALNormalDeviate(datarandparam)*(0.5*sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]/IFOdata[i].freqData->deltaF))
879 );
880 }
881 }
882 IFOdata[i].freqData->data->data[0] = 0;
883 const char timename[]="timeData";
884 IFOdata[i].timeData=(REAL8TimeSeries *)XLALCreateREAL8TimeSeries(timename,&segStart,0.0,(REAL8)1.0/SampleRate,&lalDimensionlessUnit,(size_t)seglen);
885 if(!IFOdata[i].timeData) XLAL_ERROR_NULL(XLAL_EFUNC);
886 XLALREAL8FreqTimeFFT(IFOdata[i].timeData,IFOdata[i].freqData,IFOdata[i].freqToTimeFFTPlan);
887 if(*XLALGetErrnoPtr()) printf("XLErr: %s\n",XLALErrorString(*XLALGetErrnoPtr()));
888 XLALDestroyRandomParams(datarandparam);
889 }
890 else{ /* Not using fake data, load the data from a cache file */
891
892 LALCache *cache=NULL;
893 if(!globFrames)
894 {
895 cache = XLALCacheImport( caches[i] );
896 int err;
897 err = *XLALGetErrnoPtr();
898 if(cache==NULL) {fprintf(stderr,"ERROR: Unable to import cache file \"%s\",\n XLALError: \"%s\".\n",caches[i], XLALErrorString(err)); exit(-1);}
899 }
900 else
901 {
902 printf("Looking for frames for %s in PWD\n",IFOnames[i]);
903 cache= GlobFramesPWD(IFOnames[i]);
904
905 }
906 if(!cache) {fprintf(stderr,"ERROR: Cannot find any frame data!\n"); exit(1);}
907 if ((!((psds[i])==NULL)) && (!((asds[i])==NULL))) {fprintf(stderr,"ERROR: Cannot provide both ASD and PSD file from command line!\n"); exit(1);}
908 if (!((asds)==NULL || (asds[i])==NULL)){
909 interp=NULL;
910 asdFlag=1;
911 char *interpfilename=&(asds[i][0]);
912 fprintf(stderr,"Reading ASD for %s using %s\n",IFOnames[i],interpfilename);
913 printf("Looking for ASD file %s for PSD interpolation\n",interpfilename);
914 interp=interpFromFile(interpfilename, asdFlag);
915 IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)
916 XLALCreateREAL8FrequencySeries("spectrum",&GPSstart,0.0,
917 (REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
918 if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
919 for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
920 {
921 MetaNoiseFunc(&status,&(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]),j*IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,interp,NULL);
922 //fprintf(stdout,"%lf\n",IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
923 }
924 }else if(!((psds)==NULL || (psds[i])==NULL)){
925 interp=NULL;
926 asdFlag=0;
927 char *interpfilename=&(psds[i][0]);
928 fprintf(stderr,"Reading PSD for %s using %s\n",IFOnames[i],interpfilename);
929 printf("Looking for PSD file %s for PSD interpolation\n",interpfilename);
930 interp=interpFromFile(interpfilename, asdFlag);
931 IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)
932 XLALCreateREAL8FrequencySeries("spectrum",&GPSstart,0.0,
933 (REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
934 if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
935 for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
936 {
937 MetaNoiseFunc(&status,&(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]),j*IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,interp,NULL);
938 //fprintf(stdout,"%lf\n",IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
939 }
940 }else{
941 /* Make sure required PSD arguments were provided */
942 if(!LALInferenceGetProcParamVal(commandLine,"--psdstart") ||
943 !LALInferenceGetProcParamVal(commandLine,"--psdlength"))
944 {fprintf(stderr,USAGE); return(NULL);}
945
946 fprintf(stderr,"Estimating PSD for %s using %i segments of %i samples (%lfs)\n",IFOnames[i],nSegs,(int)seglen,SegmentLength);
947 LIGOTimeGPS trueGPSstart=GPSstart;
948 if(Ntimeslides) {
949 REAL4 deltaT=-atof(timeslides[i]);
950 XLALGPSAdd(&GPSstart, deltaT);
951 fprintf(stderr,"Slid PSD estimation of %s by %f s from %10.10lf to %10.10lf\n",IFOnames[i],deltaT,trueGPSstart.gpsSeconds+1e-9*trueGPSstart.gpsNanoSeconds,GPSstart.gpsSeconds+1e-9*GPSstart.gpsNanoSeconds);
952 }
953 PSDtimeSeries=readTseries(cache,channels[i],GPSstart,PSDdatalength);
954 GPSstart=trueGPSstart;
955 if(!PSDtimeSeries) {XLALPrintError("Error reading PSD data for %s\n",IFOnames[i]); exit(1);}
956 XLALResampleREAL8TimeSeries(PSDtimeSeries,1.0/SampleRate);
957 PSDtimeSeries=(REAL8TimeSeries *)XLALShrinkREAL8TimeSeries(PSDtimeSeries,(size_t) 0, (size_t) seglen*nSegs);
958 if(!PSDtimeSeries) {
959 fprintf(stderr,"ERROR while estimating PSD for %s\n",IFOnames[i]);
961 }
962 IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)XLALCreateREAL8FrequencySeries("spectrum",&PSDtimeSeries->epoch,0.0,(REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
963 if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
964 if (LALInferenceGetProcParamVal(commandLine, "--PSDwelch"))
965 XLALREAL8AverageSpectrumWelch(IFOdata[i].oneSidedNoisePowerSpectrum ,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan);
966 else
967 XLALREAL8AverageSpectrumMedian(IFOdata[i].oneSidedNoisePowerSpectrum ,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan);
968
969 if(LALInferenceGetProcParamVal(commandLine, "--binFit")) {
970
971 LIGOTimeGPS GPStime=segStart;
972
973 const UINT4 nameLength=256;
974 char filename[nameLength];
975
976 snprintf(filename, nameLength, "%s-BinFitLines.dat", IFOdata[i].name);
977
978 printf("Running PSD bin fitting... ");
979 LALInferenceAverageSpectrumBinFit(IFOdata[i].oneSidedNoisePowerSpectrum ,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,filename,GPStime);
980 printf("completed!\n");
981 }
982
983 if (LALInferenceGetProcParamVal(commandLine, "--chisquaredlines")){
984
985 double deltaF = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF;
986 int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
987
988 REAL8 *pvalues;
989 pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
990
991 printf("Running chi-squared tests... ");
992 LALInferenceRemoveLinesChiSquared(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues);
993 printf("completed!\n");
994
995 const UINT4 nameLength=256;
996 char filename[nameLength];
997 FILE *out;
998
999 double lines_width;
1000 ppt = LALInferenceGetProcParamVal(commandLine, "--chisquaredlinesWidth");
1001 if(ppt) lines_width = atof(ppt->value);
1002 else lines_width = deltaF;
1003
1004 double lines_threshold;
1005 ppt = LALInferenceGetProcParamVal(commandLine, "--chisquaredlinesThreshold");
1006 if(ppt) lines_threshold = atof(ppt->value);
1007 else lines_threshold = 2*pow(10.0,-14.0);
1008
1009 printf("Using chi squared threshold of %g\n",lines_threshold);
1010
1011 snprintf(filename, nameLength, "%s-ChiSquaredLines.dat", IFOdata[i].name);
1012 out = fopen(filename, "w");
1013 for (int k = 0; k < lengthF; ++k ) {
1014 if (pvalues[k] < lines_threshold) {
1015 fprintf(out,"%g %g\n",((double) k) * deltaF,lines_width);
1016 }
1017 }
1018 fclose(out);
1019
1020 snprintf(filename, nameLength, "%s-ChiSquaredLines-pvalues.dat", IFOdata[i].name);
1021 out = fopen(filename, "w");
1022 for (int k = 0; k < lengthF; ++k ) {
1023 fprintf(out,"%g %g\n",((double) k) * deltaF,pvalues[k]);
1024 }
1025 fclose(out);
1026
1027 }
1028
1029 if (LALInferenceGetProcParamVal(commandLine, "--KSlines")){
1030
1031 double deltaF = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF;
1032 int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
1033
1034 REAL8 *pvalues;
1035 pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
1036
1037 printf("Running KS tests... ");
1038 LALInferenceRemoveLinesKS(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues);
1039 printf("completed!\n");
1040
1041 const UINT4 nameLength=256;
1042 char filename[nameLength];
1043 FILE *out;
1044
1045 double lines_width;
1046 ppt = LALInferenceGetProcParamVal(commandLine, "--KSlinesWidth");
1047 if(ppt) lines_width = atof(ppt->value);
1048 else lines_width = deltaF;
1049
1050 double lines_threshold;
1051 ppt = LALInferenceGetProcParamVal(commandLine, "--KSlinesThreshold");
1052 if(ppt) lines_threshold = atof(ppt->value);
1053 else lines_threshold = 0.134558;
1054
1055 printf("Using KS threshold of %g\n",lines_threshold);
1056
1057 snprintf(filename, nameLength, "%s-KSLines.dat", IFOdata[i].name);
1058 out = fopen(filename, "w");
1059 for (int k = 0; k < lengthF; ++k ) {
1060 if (pvalues[k] < lines_threshold) {
1061 fprintf(out,"%g %g\n",((double) k) * deltaF,lines_width);
1062 }
1063 }
1064 fclose(out);
1065
1066 snprintf(filename, nameLength, "%s-KSLines-pvalues.dat", IFOdata[i].name);
1067 out = fopen(filename, "w");
1068 for (int k = 0; k < lengthF; ++k ) {
1069 fprintf(out,"%g %g\n",((double) k) * deltaF,pvalues[k]);
1070 }
1071 fclose(out);
1072
1073 }
1074
1075 if (LALInferenceGetProcParamVal(commandLine, "--powerlawlines")){
1076
1077 double deltaF = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF;
1078 int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
1079
1080 REAL8 *pvalues;
1081 pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
1082
1083 printf("Running power law tests... ");
1084 LALInferenceRemoveLinesPowerLaw(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues);
1085 printf("completed!\n");
1086
1087 const UINT4 nameLength=256;
1088 char filename[nameLength];
1089 FILE *out;
1090
1091 double lines_width;
1092 ppt = LALInferenceGetProcParamVal(commandLine, "--powerlawlinesWidth");
1093 if(ppt) lines_width = atof(ppt->value);
1094 else lines_width = deltaF;
1095
1096 double lines_threshold;
1097 ppt = LALInferenceGetProcParamVal(commandLine, "--powerlawlinesThreshold");
1098 if(ppt) lines_threshold = atof(ppt->value);
1099 else lines_threshold = 0.7197370;
1100
1101 printf("Using power law threshold of %g\n",lines_threshold);
1102
1103 snprintf(filename, nameLength, "%s-PowerLawLines.dat", IFOdata[i].name);
1104 out = fopen(filename, "w");
1105 for (int k = 0; k < lengthF; ++k ) {
1106 if (pvalues[k] < lines_threshold) {
1107 fprintf(out,"%g %g\n",((double) k) * deltaF,lines_width);
1108 }
1109 }
1110 fclose(out);
1111
1112 snprintf(filename, nameLength, "%s-PowerLawLines-pvalues.dat", IFOdata[i].name);
1113 out = fopen(filename, "w");
1114 for (int k = 0; k < lengthF; ++k ) {
1115 fprintf(out,"%g %g\n",((double) k) * deltaF,pvalues[k]);
1116 }
1117 fclose(out);
1118
1119 }
1120
1121 if (LALInferenceGetProcParamVal(commandLine, "--xcorrbands")){
1122
1123 int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
1124
1125 REAL8 *pvalues;
1126 pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
1127
1128 const UINT4 nameLength=256;
1129 char filename[nameLength];
1130 FILE *out;
1131
1132 snprintf(filename, nameLength, "%s-XCorrVals.dat", IFOdata[i].name);
1133
1134 printf("Running xcorr tests... ");
1135 LALInferenceXCorrBands(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues,filename);
1136 printf("completed!\n");
1137
1138 snprintf(filename, nameLength, "%s-XCorrBands.dat", IFOdata[i].name);
1139 out = fopen(filename, "w");
1140 fprintf(out,"%g %g\n",10.0,75.0);
1141 fprintf(out,"%g %g\n",16.0,40.0);
1142 fprintf(out,"%g %g\n",40.0,330.0);
1143 fclose(out);
1144
1145 }
1146
1147 XLALDestroyREAL8TimeSeries(PSDtimeSeries);
1148 }
1149
1150 /* Read the data segment */
1151 LIGOTimeGPS truesegstart=segStart;
1152 if(Ntimeslides) {
1153 REAL4 deltaT=-atof(timeslides[i]);
1154 XLALGPSAdd(&segStart, deltaT);
1155 fprintf(stderr,"Slid %s by %f s from %10.10lf to %10.10lf\n",IFOnames[i],deltaT,truesegstart.gpsSeconds+1e-9*truesegstart.gpsNanoSeconds,segStart.gpsSeconds+1e-9*segStart.gpsNanoSeconds);
1156 }
1157 IFOdata[i].timeData=readTseries(cache,channels[i],segStart,SegmentLength);
1158 segStart=truesegstart;
1159 if(Ntimeslides) IFOdata[i].timeData->epoch=truesegstart;
1160
1161 if(!IFOdata[i].timeData) {
1162 XLALPrintError("Error reading segment data for %s at %i\n",IFOnames[i],segStart.gpsSeconds);
1164 }
1165 XLALResampleREAL8TimeSeries(IFOdata[i].timeData,1.0/SampleRate);
1166 if(!IFOdata[i].timeData) {XLALPrintError("Error reading segment data for %s\n",IFOnames[i]); XLAL_ERROR_NULL(XLAL_EFUNC);}
1167 IFOdata[i].freqData=(COMPLEX16FrequencySeries *)XLALCreateCOMPLEX16FrequencySeries("freqData",&(IFOdata[i].timeData->epoch),0.0,1.0/SegmentLength,&lalDimensionlessUnit,seglen/2+1);
1168 if(!IFOdata[i].freqData) XLAL_ERROR_NULL(XLAL_EFUNC);
1169 IFOdata[i].windowedTimeData=(REAL8TimeSeries *)XLALCreateREAL8TimeSeries("windowed time data",&(IFOdata[i].timeData->epoch),0.0,1.0/SampleRate,&lalDimensionlessUnit,seglen);
1170 if(!IFOdata[i].windowedTimeData) XLAL_ERROR_NULL(XLAL_EFUNC);
1171 XLALDDVectorMultiply(IFOdata[i].windowedTimeData->data,IFOdata[i].timeData->data,IFOdata[i].window->data);
1172 XLALREAL8TimeFreqFFT(IFOdata[i].freqData,IFOdata[i].windowedTimeData,IFOdata[i].timeToFreqFFTPlan);
1173
1174 for(j=0;j<IFOdata[i].freqData->data->length;j++){
1175 IFOdata[i].freqData->data->data[j] /= sqrt(IFOdata[i].window->sumofsquares / IFOdata[i].window->data->length);
1176 IFOdata[i].windowedTimeData->data->data[j] /= sqrt(IFOdata[i].window->sumofsquares / IFOdata[i].window->data->length);
1177 }
1178
1179 XLALDestroyCache(cache); // Clean up cache
1180 } /* End of data reading process */
1181
1182 makeWhiteData(&(IFOdata[i]));
1183
1184 /* Store ASD of noise spectrum to whiten glitch model */
1185 IFOdata[i].noiseASD=(REAL8FrequencySeries *)XLALCreateREAL8FrequencySeries("asd",&GPSstart,0.0,(REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
1186 for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
1187 IFOdata[i].noiseASD->data->data[j]=sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
1188 /* Save to file the PSDs so that they can be used in the PP pages */
1189 const UINT4 nameLength=FILENAME_MAX+100;
1190 char filename[nameLength];
1191 FILE *out;
1192 ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
1193 if (!ppt){
1194 ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1195 if(ppt) {
1196 snprintf(filename, nameLength, "%s%s-PSD.dat", ppt->value, IFOdata[i].name);
1197 }
1198 else
1199 snprintf(filename, nameLength, "%.3f_%s-PSD.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1200
1201 out = fopen(filename, "w");
1202 if(!out){
1203 fprintf(stderr,"Unable to open the path %s for writing PSD files\n",filename);
1204 exit(1);
1205 }
1206 for (j = 0; j < IFOdata[i].oneSidedNoisePowerSpectrum->data->length; j++) {
1207 REAL8 f = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF*j;
1208 REAL8 psd = IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j];
1209
1210 fprintf(out, "%10.10g %10.10g\n", f, psd);
1211 }
1212 fclose(out);
1213 }
1214 if (LALInferenceGetProcParamVal(commandLine, "--data-dump")) {
1215 //pptdatadump=LALInferenceGetProcParamVal(commandLine,"--data-dump");
1216
1217 ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1218
1219 if(ppt) {
1220 snprintf(filename, nameLength, "%s%s-timeData.dat", ppt->value, IFOdata[i].name);
1221 }
1222 //else if(strcmp(pptdatadump->value,"")) {
1223 // snprintf(filename, nameLength, "%s/%s-timeData.dat", pptdatadump->value, IFOdata[i].name);
1224 //}
1225 else
1226 snprintf(filename, nameLength, "%.3f_%s-timeData.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1227 out = fopen(filename, "w");
1228 if(!out){
1229 fprintf(stderr,"Unable to open the path %s for writing time data files\n",filename);
1230 exit(1);
1231 }
1232 for (j = 0; j < IFOdata[i].timeData->data->length; j++) {
1233 REAL8 t = XLALGPSGetREAL8(&(IFOdata[i].timeData->epoch)) +
1234 j * IFOdata[i].timeData->deltaT;
1235 REAL8 d = IFOdata[i].timeData->data->data[j];
1236
1237 fprintf(out, "%.6f %g\n", t, d);
1238 }
1239 fclose(out);
1240
1241 ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1242 if(ppt) {
1243 snprintf(filename, nameLength, "%s%s-freqData.dat", ppt->value, IFOdata[i].name);
1244 }
1245 //else if(strcmp(pptdatadump->value,"")) {
1246 // snprintf(filename, nameLength, "%s/%s-freqData.dat", pptdatadump->value, IFOdata[i].name);
1247 //}
1248 else
1249 snprintf(filename, nameLength, "%.3f_%s-freqData.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1250 out = fopen(filename, "w");
1251 if(!out){
1252 fprintf(stderr,"Unable to open the path %s for writing freq data files\n",filename);
1253 exit(1);
1254 }
1255 for (j = 0; j < IFOdata[i].freqData->data->length; j++) {
1256 REAL8 f = IFOdata[i].freqData->deltaF * j;
1257 REAL8 dre = creal(IFOdata[i].freqData->data->data[j]);
1258 REAL8 dim = cimag(IFOdata[i].freqData->data->data[j]);
1259
1260 fprintf(out, "%10.10g %10.10g %10.10g\n", f, dre, dim);
1261 }
1262 fclose(out);
1263
1264 ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1265 if(ppt) {
1266 snprintf(filename, nameLength, "%s%s-ASD.dat", ppt->value, IFOdata[i].name);
1267 }
1268 else
1269 snprintf(filename, nameLength, "%.3f_%s-ASD.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1270 out = fopen(filename, "w");
1271 if(!out){
1272 fprintf(stderr,"Unable to open the path %s for writing freq ASD files\n",filename);
1273 exit(1);
1274 }
1275 for (j = 0; j < IFOdata[i].oneSidedNoisePowerSpectrum->data->length; j++) {
1276 REAL8 f = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF*j;
1277 REAL8 asd = sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
1278
1279 fprintf(out, "%10.10g %10.10g\n", f, asd);
1280 }
1281 fclose(out);
1282
1283 }
1284 }
1285
1286 for (i=0;i<Nifo;i++) IFOdata[i].SNR=0.0; //SNR of the injection ONLY IF INJECTION. Set to 0.0 by default.
1287
1288 for (i=0;i<Nifo-1;i++) IFOdata[i].next=&(IFOdata[i+1]);
1289
1290 for(i=0;i<Nifo;i++) {
1291 if(channels) if(channels[i]) XLALFree(channels[i]);
1292 if(caches) if(caches[i]) XLALFree(caches[i]);
1293 if(IFOnames) if(IFOnames[i]) XLALFree(IFOnames[i]);
1294 if(fLows) if(fLows[i]) XLALFree(fLows[i]);
1295 if(fHighs) if(fHighs[i]) XLALFree(fHighs[i]);
1296 }
1297 if(channels) XLALFree(channels);
1298 if(caches) XLALFree(caches);
1299 if(IFOnames) XLALFree(IFOnames);
1300 if(fLows) XLALFree(fLows);
1301 if(fHighs) XLALFree(fHighs);
1302
1303 if (LALInferenceGetProcParamVal(commandLine, "--roqtime_steps")){
1304
1305 LALInferenceSetupROQdata(IFOdata, commandLine);
1306 fprintf(stderr, "done LALInferenceSetupROQdata\n");
1307
1308 }
1309
1310
1311 return headIFO;
1312}
1313
1314static void makeWhiteData(LALInferenceIFOData *IFOdata) {
1315 REAL8 deltaF = IFOdata->freqData->deltaF;
1316 REAL8 deltaT = IFOdata->timeData->deltaT;
1317
1318 IFOdata->whiteFreqData =
1319 XLALCreateCOMPLEX16FrequencySeries("whitened frequency data",
1320 &(IFOdata->freqData->epoch),
1321 0.0,
1322 deltaF,
1324 IFOdata->freqData->data->length);
1326 IFOdata->whiteTimeData =
1327 XLALCreateREAL8TimeSeries("whitened time data",
1328 &(IFOdata->timeData->epoch),
1329 0.0,
1330 deltaT,
1332 IFOdata->timeData->data->length);
1334
1335 REAL8 iLow = IFOdata->fLow / deltaF;
1336 REAL8 iHighDefaultCut = 0.95 * IFOdata->freqData->data->length;
1337 REAL8 iHighFromFHigh = IFOdata->fHigh / deltaF;
1338 REAL8 iHigh = (iHighDefaultCut < iHighFromFHigh ? iHighDefaultCut : iHighFromFHigh);
1339 REAL8 windowSquareSum = 0.0;
1340
1341 UINT4 i;
1342
1343 for (i = 0; i < IFOdata->freqData->data->length; i++) {
1344 IFOdata->whiteFreqData->data->data[i] = IFOdata->freqData->data->data[i] / IFOdata->oneSidedNoisePowerSpectrum->data->data[i];
1345
1346 if (i == 0) {
1347 /* Cut off the average trend in the data. */
1348 IFOdata->whiteFreqData->data->data[i] = 0.0;
1349 }
1350 if (i <= iLow) {
1351 /* Need to taper to implement the fLow cutoff. Tukey window
1352 that starts at zero, and reaches 100% at fLow. */
1353 REAL8 weight = 0.5*(1.0 + cos(M_PI*(i-iLow)/iLow)); /* Starts at -Pi, runs to zero at iLow. */
1354
1355 IFOdata->whiteFreqData->data->data[i] *= weight;
1356
1357 windowSquareSum += weight*weight;
1358 } else if (i >= iHigh) {
1359 /* Also taper at high freq end, Tukey window that starts at 100%
1360 at fHigh, then drops to zero at Nyquist. Except that we
1361 always taper at least 5% of the data at high freq to avoid a
1362 sharp edge in freq space there. */
1363 REAL8 NWind = IFOdata->whiteFreqData->data->length - iHigh;
1364 REAL8 weight = 0.5*(1.0 + cos(M_PI*(i-iHigh)/NWind)); /* Starts at 0, runs to Pi at i = length */
1365
1366 IFOdata->whiteFreqData->data->data[i] *= weight;
1367
1368 windowSquareSum += weight*weight;
1369 } else {
1370 windowSquareSum += 1.0;
1371 }
1372 }
1373
1374 REAL8 norm = sqrt(IFOdata->whiteFreqData->data->length / windowSquareSum);
1375 for (i = 0; i < IFOdata->whiteFreqData->data->length; i++) {
1376 IFOdata->whiteFreqData->data->data[i] *= norm;
1377 }
1378
1380}
1381
1383{
1385 memset(&status,0,sizeof(status));
1386 SimInspiralTable *injTable=NULL;
1387 SimInspiralTable *injEvent=NULL;
1388 UINT4 event=0;
1389 UINT4 i=0,j=0;
1390 REAL8 responseScale=1.0;
1391 LIGOTimeGPS injstart;
1392 REAL8 SNR=0,NetworkSNR=0;
1393 DetectorResponse det;
1394 memset(&injstart,0,sizeof(LIGOTimeGPS));
1395 COMPLEX16FrequencySeries *injF=NULL;
1396 FILE *rawWaveform=NULL;
1397 ProcessParamsTable *ppt=NULL;
1398 REAL8 bufferLength = 2048.0; /* Default length of buffer for injections (seconds) */
1399 UINT4 bufferN=0;
1400 LIGOTimeGPS bufferStart;
1401
1402 LALInferenceIFOData *thisData=IFOdata->next;
1403 REAL8 minFlow=IFOdata->fLow;
1404 REAL8 MindeltaT=IFOdata->timeData->deltaT;
1405 REAL8 InjSampleRate=1.0/MindeltaT;
1406 REAL4TimeSeries *injectionBuffer=NULL;
1407 REAL8 padding=0.4; //default, set in LALInferenceReadData()
1408 char SNRpath[FILENAME_MAX+50]="";
1409 int flipped_masses=0;
1410
1411 while(thisData){
1412 minFlow = minFlow>thisData->fLow ? thisData->fLow : minFlow;
1413 MindeltaT = MindeltaT>thisData->timeData->deltaT ? thisData->timeData->deltaT : MindeltaT;
1414 thisData = thisData->next;
1415 }
1416 thisData=IFOdata;
1417
1418 if(!LALInferenceGetProcParamVal(commandLine,"--inj")) {fprintf(stdout,"No injection file specified, not injecting\n"); return;}
1419 if(LALInferenceGetProcParamVal(commandLine,"--event")){
1420 event= atoi(LALInferenceGetProcParamVal(commandLine,"--event")->value);
1421 fprintf(stdout,"Injecting event %d\n",event);
1422 }
1423
1424 ppt = LALInferenceGetProcParamVal(commandLine,"--outfile");
1425 if (ppt)
1426 sprintf(SNRpath, "%s_snr.txt", ppt->value);
1427 else
1428 sprintf(SNRpath, "snr.txt");
1429
1430 injTable=XLALSimInspiralTableFromLIGOLw(LALInferenceGetProcParamVal(commandLine,"--inj")->value);
1431 if(!injTable){
1432 fprintf(stderr,"Error reading event %d from %s\n",event,LALInferenceGetProcParamVal(commandLine,"--inj")->value);
1433 exit(1);
1434 }
1435 while(i<event) {i++; injTable = injTable->next;} /* Select event */
1436 injEvent = injTable;
1437 injEvent->next = NULL;
1438 Approximant injapprox;
1439 injapprox = XLALGetApproximantFromString(injTable->waveform);
1440 if( (int) injapprox == XLAL_FAILURE)
1441 ABORTXLAL(&status);
1442 printf("Injecting approximant %i: %s\n", injapprox, injTable->waveform);
1444
1445 /* Check for frequency domain injection. All aproximants supported by XLALSimInspiralImplementedFDApproximants will work.
1446 * CAVEAT: FD spinning approximants will refer the spin to the lower frequency as given in the xml table. Templates instead will refer it to the lower cutoff of the likelihood integral. This means *different* values of spin will be recovered if one doesn't pay attention! */
1448 {
1449 InjectFD(IFOdata, injTable, commandLine);
1450 LALInferencePrintDataWithInjection(IFOdata,commandLine);
1451 return;
1452 }
1453 flipped_masses = enforce_m1_larger_m2(injEvent);
1454 /* Begin loop over interferometers */
1455 while(thisData){
1456 Approximant approximant; /* Get approximant value */
1458 if( (int) approximant == XLAL_FAILURE)
1459 ABORTXLAL(&status);
1460
1461 InjSampleRate=1.0/thisData->timeData->deltaT;
1462 if(LALInferenceGetProcParamVal(commandLine,"--injectionsrate")) InjSampleRate=atof(LALInferenceGetProcParamVal(commandLine,"--injectionsrate")->value);
1463 if(approximant == NumRelNinja2 && InjSampleRate != 16384) {
1464 fprintf(stderr, "WARNING: NINJA2 injections only work with 16384 Hz sampling rates. Generating injection in %s at this rate, then downsample to the run's sampling rate.\n", thisData->name);
1465 InjSampleRate = 16384;
1466 }
1467
1468 memset(&det,0,sizeof(det));
1469 det.site=thisData->detector;
1471 0.0,
1472 thisData->freqData->deltaF,
1474 thisData->freqData->data->length);
1475
1476 for(i=0;i<resp->data->length;i++) {resp->data->data[i] = 1.0;}
1477 /* Originally created for injecting into DARM-ERR, so transfer function was needed.
1478 But since we are injecting into h(t), the transfer function from h(t) to h(t) is 1.*/
1479
1480 /* We need a long buffer to inject into so that FindChirpInjectSignals() works properly
1481 for low mass systems. Use 100 seconds here */
1482 bufferN = (UINT4) (bufferLength*InjSampleRate);// /thisData->timeData->deltaT);
1483 memcpy(&bufferStart,&thisData->timeData->epoch,sizeof(LIGOTimeGPS));
1484 XLALGPSAdd(&bufferStart,(REAL8) thisData->timeData->data->length * thisData->timeData->deltaT);
1485 XLALGPSAdd(&bufferStart,-bufferLength);
1487 &bufferStart, 0.0, 1.0/InjSampleRate,//thisData->timeData->deltaT,
1488 &lalADCCountUnit, bufferN);
1490 &thisData->timeData->epoch,
1491 0.0,
1492 thisData->timeData->deltaT,
1493 //&lalDimensionlessUnit,
1495 thisData->timeData->data->length);
1496 if(!inj8Wave) XLAL_ERROR_VOID(XLAL_EFUNC);
1497 /* This marks the sample in which the real segment starts, within the buffer */
1498 for(i=0;i<injectionBuffer->data->length;i++) injectionBuffer->data->data[i]=0.0;
1499 for(i=0;i<inj8Wave->data->length;i++) inj8Wave->data->data[i]=0.0;
1500 INT4 realStartSample=(INT4)((thisData->timeData->epoch.gpsSeconds - injectionBuffer->epoch.gpsSeconds)/thisData->timeData->deltaT);
1501 realStartSample+=(INT4)((thisData->timeData->epoch.gpsNanoSeconds - injectionBuffer->epoch.gpsNanoSeconds)*1e-9/thisData->timeData->deltaT);
1502
1503 if(LALInferenceGetProcParamVal(commandLine,"--lalinspiralinjection")){
1504 if ( approximant == NumRelNinja2) {
1505 XLALSimInjectNinjaSignals(injectionBuffer, thisData->name, 1./responseScale, injEvent);
1506 } else {
1507 /* Use this custom version for extra sites - not currently maintained */
1508 /* Normal find chirp simulation cannot handle the extra sites */
1509 LALFindChirpInjectSignals (&status,injectionBuffer,injEvent,resp);
1510 }
1511 printf("Using LALInspiral for injection\n");
1512 XLALResampleREAL4TimeSeries(injectionBuffer,thisData->timeData->deltaT); //downsample to analysis sampling rate.
1513 if(status.statusCode) REPORTSTATUS(&status);
1515
1516 if ( approximant != NumRelNinja2 ) {
1517 /* Checking the lenght of the injection waveform with respect of thisData->timeData->data->length */
1519 PPNParamStruc ppnParams;
1520 memset( &waveform, 0, sizeof(CoherentGW) );
1521 memset( &ppnParams, 0, sizeof(PPNParamStruc) );
1522 ppnParams.deltaT = 1.0/InjSampleRate;//thisData->timeData->deltaT;
1523 ppnParams.lengthIn = 0;
1524 ppnParams.ppn = NULL;
1525 unsigned lengthTest = 0;
1526
1527 LALGenerateInspiral(&status, &waveform, injEvent, &ppnParams ); //Recompute the waveform just to get access to ppnParams.tc and waveform.h->data->length or waveform.phi->data->length
1528 if(status.statusCode) REPORTSTATUS(&status);
1529
1530 if(waveform.h){
1531 lengthTest = waveform.h->data->length*(thisData->timeData->deltaT*InjSampleRate);
1532 }
1533 if(waveform.phi){
1535 lengthTest = waveform.phi->data->length;
1536 }
1537
1538
1539 if(lengthTest>thisData->timeData->data->length-(UINT4)ceil((2.0*padding+2.0)/thisData->timeData->deltaT)){
1540 fprintf(stderr, "WARNING: waveform length = %u is longer than thisData->timeData->data->length = %d minus the window width = %d and the 2.0 seconds after tc (total of %d points available).\n", lengthTest, thisData->timeData->data->length, (INT4)ceil((2.0*padding)/thisData->timeData->deltaT) , thisData->timeData->data->length-(INT4)ceil((2.0*padding+2.0)/thisData->timeData->deltaT));
1541 fprintf(stderr, "The waveform injected is %f seconds long. Consider increasing the %f seconds segment length (--seglen) to be greater than %f. (in %s, line %d)\n",ppnParams.tc , thisData->timeData->data->length * thisData->timeData->deltaT, ppnParams.tc + 2.0*padding + 2.0, __FILE__, __LINE__);
1542 }
1543 if(ppnParams.tc>bufferLength){
1544 fprintf(stderr, "ERROR: The waveform injected is %f seconds long and the buffer for FindChirpInjectSignal is %f seconds long. The end of the waveform will be cut ! (in %s, line %d)\n",ppnParams.tc , bufferLength, __FILE__, __LINE__);
1545 exit(1);
1546 }
1547 }
1548
1549 /* Now we cut the injection buffer down to match the time domain wave size */
1550 injectionBuffer=(REAL4TimeSeries *)XLALCutREAL4TimeSeries(injectionBuffer,realStartSample,thisData->timeData->data->length);
1551 if (!injectionBuffer) XLAL_ERROR_VOID(XLAL_EFUNC);
1552 if(status.statusCode) REPORTSTATUS(&status);
1553 for(i=0;i<injectionBuffer->data->length;i++) inj8Wave->data->data[i]=(REAL8)injectionBuffer->data->data[i];
1554 }else{
1555 printf("Using LALSimulation for injection\n");
1556 REAL8TimeSeries *hplus=NULL; /**< +-polarization waveform */
1557 REAL8TimeSeries *hcross=NULL; /**< x-polarization waveform */
1558 REAL8TimeSeries *signalvecREAL8=NULL;
1559 LALPNOrder order; /* Order of the model */
1560 INT4 amporder=0; /* Amplitude order of the model */
1561
1562 order = XLALGetOrderFromString(injEvent->waveform);
1563 if ( (int) order == XLAL_FAILURE)
1564 ABORTXLAL(&status);
1565 amporder = injEvent->amp_order;
1566 //if(amporder<0) amporder=0;
1567 /* FIXME - tidal lambda's and interactionFlag are just set to command line values here.
1568 * They should be added to injEvent and set to appropriate values
1569 */
1570
1571 // Inject (lambda1,lambda2)
1572 REAL8 lambda1 = 0.;
1573 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1574 lambda1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")->value);
1575 }
1576 REAL8 lambda2 = 0.;
1577 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1578 lambda2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")->value);
1579 }
1580 if(flipped_masses)
1581 {
1582 /* Having previously flipped the masses so m1>m2, also flip lambdas */
1583 REAL8 lambda_tmp = lambda1;
1584 lambda1 = lambda2;
1585 lambda2 = lambda_tmp;
1586 fprintf(stdout,"Flipping lambdas since masses are flipped\n");
1587 }
1588 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1589 fprintf(stdout,"Injection lambda1 set to %f\n",lambda1);
1590 }
1591 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1592 fprintf(stdout,"Injection lambda1 set to %f\n",lambda1);
1593 }
1594
1595 // Inject (lambdaT,dLambdaT)
1596 REAL8 lambdaT = 0.;
1597 REAL8 dLambdaT = 0.;
1598 REAL8 m1=injEvent->mass1;
1599 REAL8 m2=injEvent->mass2;
1600 REAL8 Mt=m1+m2;
1601 REAL8 eta=m1*m2/(Mt*Mt);
1602 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")&&LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")) {
1603 lambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")->value);
1604 dLambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")->value);
1606 fprintf(stdout,"Injection lambdaT set to %f\n",lambdaT);
1607 fprintf(stdout,"Injection dLambdaT set to %f\n",dLambdaT);
1608 fprintf(stdout,"lambda1 set to %f\n",lambda1);
1609 fprintf(stdout,"lambda2 set to %f\n",lambda2);
1610 }
1611
1612 // Inject 4-piece polytrope eos
1613 REAL8 logp1=0.0;
1614 REAL8 gamma1=0.0;
1615 REAL8 gamma2=0.0;
1616 REAL8 gamma3=0.0;
1617 if(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")){
1618 logp1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")->value);
1619 gamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")->value);
1620 gamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")->value);
1621 gamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")->value);
1622 // Find lambda1,2(m1,2|eos)
1623 LALInferenceLogp1GammasMasses2Lambdas(logp1, gamma1, gamma2, gamma3, m1, m2, &lambda1, &lambda2);
1624 fprintf(stdout,"Injection logp1 set to %f\n",logp1);
1625 fprintf(stdout,"Injection gamma1 set to %f\n",gamma1);
1626 fprintf(stdout,"Injection gamma2 set to %f\n",gamma2);
1627 fprintf(stdout,"Injection gamma3 set to %f\n",gamma3);
1628 fprintf(stdout,"lambda1 set to %f\n",lambda1);
1629 fprintf(stdout,"lambda2 set to %f\n",lambda2);
1630
1631 /*
1632 For when tagSimInspiralTable is updated
1633 to include EOS params
1634
1635 injEvent->logp1= logp1;
1636 injEvent->gamma1= gamma1;
1637 injEvent->gamma2= gamma2;
1638 injEvent->gamma3= gamma3;
1639 */
1640 }
1641
1642 // Inject 4-coef. spectral eos
1643 REAL8 SDgamma0=0.0;
1644 REAL8 SDgamma1=0.0;
1645 REAL8 SDgamma2=0.0;
1646 REAL8 SDgamma3=0.0;
1647 if(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")){
1648 SDgamma0= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0")->value);
1649 SDgamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1")->value);
1650 SDgamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2")->value);
1651 SDgamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")->value);
1652 REAL8 gamma[]={SDgamma0,SDgamma1,SDgamma2,SDgamma3};
1654 fprintf(stdout,"Injection SDgamma0 set to %lf\n",SDgamma0);
1655 fprintf(stdout,"Injection SDgamma1 set to %lf\n",SDgamma1);
1656 fprintf(stdout,"Injection SDgamma2 set to %lf\n",SDgamma2);
1657 fprintf(stdout,"Injection SDgamma3 set to %lf\n",SDgamma3);
1658 fprintf(stdout,"lambda1 set to %f\n",lambda1);
1659 fprintf(stdout,"lambda2 set to %f\n",lambda2);
1660 }
1661
1662
1663 REAL8 fref = 100.;
1664 if(LALInferenceGetProcParamVal(commandLine,"--inj-fref")) {
1665 fref = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-fref")->value);
1666 }
1667
1668 LALDict *LALpars=XLALCreateDict();
1669
1670 /* Inject deviation from GR */
1671 /* Inspiral Coefficients */
1672 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")){
1673 REAL8 dchi_minus2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")->value);
1675
1676 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")){
1677 REAL8 dchi_minus1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")->value);
1679
1680 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")){
1681 REAL8 dchi0 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")->value);
1683 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")){
1684 REAL8 dchi1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")->value);
1686 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")){
1687 REAL8 dchi2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")->value);
1689 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")){
1690 REAL8 dchi3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")->value);
1692 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")){
1693 REAL8 dchi4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")->value);
1695 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5")){
1696 REAL8 dchi5 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")->value);
1698 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")){
1699 REAL8 dchi5l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")->value);
1701 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")){
1702 REAL8 dchi6 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")->value);
1704 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")){
1705 REAL8 dchi6l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")->value);
1707 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")){
1708 REAL8 dchi7 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")->value);
1710
1711 /* PhenomD Intermediate */
1712 if (LALInferenceGetProcParamVal(commandLine,"--inj-dbeta1")){
1713 REAL8 nongr_dbeta1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dbeta1")->value);
1714 XLALSimInspiralWaveformParamsInsertNonGRDBeta1(LALpars, nongr_dbeta1);}
1715 if (LALInferenceGetProcParamVal(commandLine,"--inj-dbeta2")){
1716 REAL8 nongr_dbeta2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dbeta2")->value);
1717 XLALSimInspiralWaveformParamsInsertNonGRDBeta2(LALpars, nongr_dbeta2);}
1718 if (LALInferenceGetProcParamVal(commandLine,"--inj-dbeta3")){
1719 REAL8 nongr_dbeta3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dbeta3")->value);
1720 XLALSimInspiralWaveformParamsInsertNonGRDBeta3(LALpars, nongr_dbeta3);}
1721
1722 /* PhenomX Intermediate */
1723 if (LALInferenceGetProcParamVal(commandLine,"--inj-db1")){
1724 REAL8 nongr_db1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db1")->value);
1726 if (LALInferenceGetProcParamVal(commandLine,"--inj-db2")){
1727 REAL8 nongr_db2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db2")->value);
1729 if (LALInferenceGetProcParamVal(commandLine,"--inj-db3")){
1730 REAL8 nongr_db3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db3")->value);
1732 if (LALInferenceGetProcParamVal(commandLine,"--inj-db4")){
1733 REAL8 nongr_db4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db4")->value);
1735
1736 /* PhenomD Merger-Ringdown */
1737 if (LALInferenceGetProcParamVal(commandLine,"--inj-dalpha1")){
1738 REAL8 nongr_dalpha1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dalpha1")->value);
1739 XLALSimInspiralWaveformParamsInsertNonGRDAlpha1(LALpars, nongr_dalpha1);}
1740 if (LALInferenceGetProcParamVal(commandLine,"--inj-dalpha2")){
1741 REAL8 nongr_dalpha2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dalpha2")->value);
1742 XLALSimInspiralWaveformParamsInsertNonGRDAlpha2(LALpars, nongr_dalpha2);}
1743 if (LALInferenceGetProcParamVal(commandLine,"--inj-dalpha3")){
1744 REAL8 nongr_dalpha3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dalpha3")->value);
1745 XLALSimInspiralWaveformParamsInsertNonGRDAlpha3(LALpars, nongr_dalpha3);}
1746
1747 /* PhenomX Merger-Ringdown */
1748 if (LALInferenceGetProcParamVal(commandLine,"--inj-dc1")){
1749 REAL8 nongr_dc1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc1")->value);
1751 if (LALInferenceGetProcParamVal(commandLine,"--inj-dc2")){
1752 REAL8 nongr_dc2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc2")->value);
1754 if (LALInferenceGetProcParamVal(commandLine,"--inj-dc4")){
1755 REAL8 nongr_dc4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc4")->value);
1757 if (LALInferenceGetProcParamVal(commandLine,"--inj-dcl")){
1758 REAL8 nongr_dcl = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dcl")->value);
1760
1761
1762 /* Set the spin-frame convention */
1763
1765 if(LALInferenceGetProcParamVal(commandLine,"--inj-spinOrder")) {
1766 spinO = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-spinOrder")->value);
1768 }
1770 if(LALInferenceGetProcParamVal(commandLine,"--inj-tidalOrder")) {
1771 tideO = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-tidalOrder")->value);
1773 }
1774
1776 if((ppt=LALInferenceGetProcParamVal(commandLine,"--inj-spin-frame"))) {
1778 }
1779 XLALSimInspiralWaveformParamsInsertFrameAxis(LALpars,(int) frameAxis);
1780
1781 if((ppt=LALInferenceGetProcParamVal(commandLine,"--inj-numreldata"))) {
1783 fprintf(stdout,"Injection will use %s.\n",ppt->value);
1784 }
1785 else if (strlen(injEvent->numrel_data) > 0) {
1787 }
1788
1789 /* Print a line with information about approximant, amporder, phaseorder, tide order and spin order */
1790 fprintf(stdout,"Injection will run using Approximant %i (%s), phase order %i, amp order %i, spin order %i, tidal order %i, in the time domain with a reference frequency of %f.\n",approximant,XLALSimInspiralGetStringFromApproximant(approximant),order,amporder,(int) spinO, (int) tideO, (float) fref);
1791
1792 /* ChooseWaveform starts the (2,2) mode of the waveform at the given minimum frequency. We want the highest order contribution to start at the f_lower of the injection file */
1794 printf("Injecting with f_min = %f.\n", f_min);
1795
1800
1801 XLALSimInspiralChooseTDWaveform(&hplus, &hcross, injEvent->mass1*LAL_MSUN_SI, injEvent->mass2*LAL_MSUN_SI,
1802 injEvent->spin1x, injEvent->spin1y, injEvent->spin1z,
1803 injEvent->spin2x, injEvent->spin2y, injEvent->spin2z,
1804 injEvent->distance*LAL_PC_SI * 1.0e6, injEvent->inclination,
1805 injEvent->coa_phase, 0., 0., 0.,
1806 1.0/InjSampleRate, f_min, fref,
1807 LALpars, approximant);
1808 XLALDestroyDict(LALpars);
1809
1810 if(!hplus || !hcross) {
1811 fprintf(stderr,"Error: XLALSimInspiralChooseWaveform() failed to produce waveform.\n");
1812 exit(-1);
1813 }
1815 XLALResampleREAL8TimeSeries(hcross,thisData->timeData->deltaT);
1816 /* XLALSimInspiralChooseTDWaveform always ends the waveform at t=0 */
1817 /* So we can adjust the epoch so that the end time is as desired */
1818 XLALGPSAddGPS(&(hplus->epoch), &(injEvent->geocent_end_time));
1819 XLALGPSAddGPS(&(hcross->epoch), &(injEvent->geocent_end_time));
1820
1821 if((ppt=LALInferenceGetProcParamVal(commandLine,"--dump-geocenter-pols"))) {
1822
1823 fprintf(stdout,"Dump injected TimeDomain h_plus and h_cross at geocenter (for IFO %s)\n", thisData->name);
1824
1825 char filename[320];
1826 sprintf(filename,"%s_TD_geocenter_pols.dat",thisData->name);
1827
1828 FILE* file=fopen(filename, "w");
1829 if(!file){
1830 fprintf(stderr,"Unable to open the path %s for writing injected TimeDomain h_plus and h_cross at geocenter\n",filename);
1831 exit(1);
1832 }
1833
1834 for(j=0; j<hplus->data->length; j++){
1835 fprintf(file, "%.6f %g %g \n", XLALGPSGetREAL8(&hplus->epoch) + hplus->deltaT*j, hplus->data->data[j], hcross->data->data[j]);
1836 }
1837 fclose(file);
1838 }
1839
1840 signalvecREAL8=XLALSimDetectorStrainREAL8TimeSeries(hplus, hcross, injEvent->longitude, injEvent->latitude, injEvent->polarization, det.site);
1841 if (!signalvecREAL8) XLAL_ERROR_VOID(XLAL_EFUNC);
1842
1843 for(i=0;i<signalvecREAL8->data->length;i++){
1844 if(isnan(signalvecREAL8->data->data[i])) signalvecREAL8->data->data[i]=0.0;
1845 }
1846
1847 if(signalvecREAL8->data->length > thisData->timeData->data->length-(UINT4)ceil((2.0*padding+2.0)/thisData->timeData->deltaT)){
1848 fprintf(stderr, "WARNING: waveform length = %u is longer than thisData->timeData->data->length = %d minus the window width = %d and the 2.0 seconds after tc (total of %d points available).\n", signalvecREAL8->data->length, thisData->timeData->data->length, (INT4)ceil((2.0*padding)/thisData->timeData->deltaT) , thisData->timeData->data->length-(INT4)ceil((2.0*padding+2.0)/thisData->timeData->deltaT));
1849 fprintf(stderr, "The waveform injected is %f seconds long. Consider increasing the %f seconds segment length (--seglen) to be greater than %f. (in %s, line %d)\n",signalvecREAL8->data->length * thisData->timeData->deltaT , thisData->timeData->data->length * thisData->timeData->deltaT, signalvecREAL8->data->length * thisData->timeData->deltaT + 2.0*padding + 2.0, __FILE__, __LINE__);
1850 }
1851
1852 XLALSimAddInjectionREAL8TimeSeries(inj8Wave, signalvecREAL8, NULL);
1853
1854 if ( hplus ) XLALDestroyREAL8TimeSeries(hplus);
1855 if ( hcross ) XLALDestroyREAL8TimeSeries(hcross);
1856
1857 }
1858 XLALDestroyREAL4TimeSeries(injectionBuffer);
1860 &thisData->timeData->epoch,
1861 0.0,
1862 thisData->freqData->deltaF,
1864 thisData->freqData->data->length);
1865 if(!injF) {
1866 XLALPrintError("Unable to allocate memory for injection buffer\n");
1868 }
1869 /* Window the data */
1870 REAL4 WinNorm = sqrt(thisData->window->sumofsquares/thisData->window->data->length);
1871 for(j=0;j<inj8Wave->data->length;j++) inj8Wave->data->data[j]*=thisData->window->data->data[j]; /* /WinNorm; */ /* Window normalisation applied only in freq domain */
1872 XLALREAL8TimeFreqFFT(injF,inj8Wave,thisData->timeToFreqFFTPlan);
1873 if(thisData->oneSidedNoisePowerSpectrum){
1874 for(SNR=0.0,j=thisData->fLow/injF->deltaF;j<thisData->fHigh/injF->deltaF;j++){
1875 SNR += pow(creal(injF->data->data[j]), 2.0)/thisData->oneSidedNoisePowerSpectrum->data->data[j];
1876 SNR += pow(cimag(injF->data->data[j]), 2.0)/thisData->oneSidedNoisePowerSpectrum->data->data[j];
1877 }
1878 SNR*=4.0*injF->deltaF;
1879 }
1880 thisData->SNR=sqrt(SNR);
1881 NetworkSNR+=SNR;
1882
1883 /* Actually inject the waveform */
1884 for(j=0;j<inj8Wave->data->length;j++) thisData->timeData->data->data[j]+=inj8Wave->data->data[j];
1885 fprintf(stdout,"Injected SNR in detector %s = %g\n",thisData->name,thisData->SNR);
1886 char filename[320];
1887 sprintf(filename,"%s_timeInjection.dat",thisData->name);
1888 FILE* file=fopen(filename, "w");
1889 for(j=0;j<inj8Wave->data->length;j++){
1890 fprintf(file, "%.6f\t%lg\n", XLALGPSGetREAL8(&thisData->timeData->epoch) + thisData->timeData->deltaT*j, inj8Wave->data->data[j]);
1891 }
1892 fclose(file);
1893 sprintf(filename,"%s_freqInjection.dat",thisData->name);
1894 file=fopen(filename, "w");
1895 for(j=0;j<injF->data->length;j++){
1896 thisData->freqData->data->data[j] += injF->data->data[j] / WinNorm;
1897 fprintf(file, "%lg %lg \t %lg\n", thisData->freqData->deltaF*j, creal(injF->data->data[j]), cimag(injF->data->data[j]));
1898 }
1899 fclose(file);
1900
1903 thisData=thisData->next;
1904 }
1905 ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
1906 if (!ppt){
1907 PrintSNRsToFile(IFOdata , SNRpath);
1908 }
1909 NetworkSNR=sqrt(NetworkSNR);
1910 fprintf(stdout,"Network SNR of event %d = %g\n",event,NetworkSNR);
1911
1912 /* Output waveform raw h-plus mode */
1913 if( (ppt=LALInferenceGetProcParamVal(commandLine,"--rawwaveform")) )
1914 {
1915 rawWaveform=fopen(ppt->value,"w");
1916 bufferN = (UINT4) (bufferLength/IFOdata->timeData->deltaT);
1917 memcpy(&bufferStart,&IFOdata->timeData->epoch,sizeof(LIGOTimeGPS));
1918 XLALGPSAdd(&bufferStart,(REAL8) IFOdata->timeData->data->length * IFOdata->timeData->deltaT);
1919 XLALGPSAdd(&bufferStart,-bufferLength);
1921 if(!resp) XLAL_ERROR_VOID(XLAL_EFUNC);
1922 injectionBuffer=(REAL4TimeSeries *)XLALCreateREAL4TimeSeries("None",&bufferStart, 0.0, IFOdata->timeData->deltaT,&lalADCCountUnit, bufferN);
1923 if(!injectionBuffer) XLAL_ERROR_VOID(XLAL_EFUNC);
1924 /* This marks the sample in which the real segment starts, within the buffer */
1925 INT4 realStartSample=(INT4)((IFOdata->timeData->epoch.gpsSeconds - injectionBuffer->epoch.gpsSeconds)/IFOdata->timeData->deltaT);
1926 realStartSample+=(INT4)((IFOdata->timeData->epoch.gpsNanoSeconds - injectionBuffer->epoch.gpsNanoSeconds)*1e-9/IFOdata->timeData->deltaT);
1927 LALFindChirpInjectSignals(&status,injectionBuffer,injEvent,resp);
1928 if(status.statusCode) REPORTSTATUS(&status);
1930 injectionBuffer=(REAL4TimeSeries *)XLALCutREAL4TimeSeries(injectionBuffer,realStartSample,IFOdata->timeData->data->length);
1931 for(j=0;j<injectionBuffer->data->length;j++) fprintf(rawWaveform,"%.6f\t%g\n", XLALGPSGetREAL8(&IFOdata->timeData->epoch) + IFOdata->timeData->deltaT*j, injectionBuffer->data->data[j]);
1932 fclose(rawWaveform);
1933 XLALDestroyREAL4TimeSeries(injectionBuffer);
1934 }
1935
1936 LALInferencePrintDataWithInjection(IFOdata,commandLine);
1937
1938 return;
1939}
1940
1941
1942void InjectFD(LALInferenceIFOData *IFOdata, SimInspiralTable *inj_table, ProcessParamsTable *commandLine)
1943///*-------------- Inject in Frequency domain -----------------*/
1944{
1945 /* Inject a gravitational wave into the data in the frequency domain */
1947 memset(&status,0,sizeof(LALStatus));
1948 INT4 errnum;
1949 char SNRpath[FILENAME_MAX+50];
1950 ProcessParamsTable *ppt=NULL;
1951 int flipped_masses=0;
1952 LALInferenceIFOData *dataPtr;
1953
1954 ppt = LALInferenceGetProcParamVal(commandLine,"--outfile");
1955 if (ppt)
1956 sprintf(SNRpath, "%s_snr.txt", ppt->value);
1957 else
1958 sprintf(SNRpath, "snr.txt");
1959
1961 if( (int) approximant == XLAL_FAILURE)
1962 ABORTXLAL(&status);
1963
1964 LALPNOrder phase_order = XLALGetOrderFromString(inj_table->waveform);
1965 if ( (int) phase_order == XLAL_FAILURE)
1966 ABORTXLAL(&status);
1967
1968 LALPNOrder amp_order = (LALPNOrder) inj_table->amp_order;
1969
1970 flipped_masses = enforce_m1_larger_m2(inj_table);
1971
1972 REAL8 injtime=0.0;
1973 injtime=(REAL8) inj_table->geocent_end_time.gpsSeconds + (REAL8) inj_table->geocent_end_time.gpsNanoSeconds*1.0e-9;
1974
1975 // Inject (lambda1,lambda2)
1976 REAL8 lambda1 = 0.;
1977 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1978 lambda1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")->value);
1979 }
1980 REAL8 lambda2 = 0.;
1981 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1982 lambda2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")->value);
1983 }
1984 if(flipped_masses) /* If flipped masses, also flip lambda */
1985 {
1986 REAL8 lambda_tmp=lambda1;
1988 lambda2=lambda_tmp;
1989 fprintf(stdout,"Flipping lambdas since masses are flipped\n");
1990 }
1991 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1992 fprintf(stdout,"Injection lambda1 set to %f\n",lambda1);
1993 }
1994 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1995 fprintf(stdout,"Injection lambda2 set to %f\n",lambda2);
1996 }
1997
1998
1999 // Inject (lambdaT,dLambdaT)
2000 REAL8 lambdaT = 0.;
2001 REAL8 dLambdaT = 0.;
2002 if(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")&&LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")) {
2003 lambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")->value);
2004 dLambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")->value);
2005 // Find lambda1,2(LambdaT,dLambdaT,eta)
2006 LALInferenceLambdaTsEta2Lambdas(lambdaT, dLambdaT, inj_table->eta, &lambda1, &lambda2);
2007 fprintf(stdout,"Injection lambdaT set to %f\n",lambdaT);
2008 fprintf(stdout,"Injection dLambdaT set to %f\n",dLambdaT);
2009 fprintf(stdout,"lambda1 set to %f\n",lambda1);
2010 fprintf(stdout,"lambda2 set to %f\n",lambda2);
2011 }
2012
2013 // Inject 4-piece polytrope eos
2014 REAL8 logp1=0.0;
2015 REAL8 gamma1=0.0;
2016 REAL8 gamma2=0.0;
2017 REAL8 gamma3=0.0;
2018 if(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")){
2019 logp1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")->value);
2020 gamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")->value);
2021 gamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")->value);
2022 gamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")->value);
2023 // Find lambda1,2(m1,2|eos)
2024 LALInferenceLogp1GammasMasses2Lambdas(logp1, gamma1, gamma2, gamma3, inj_table->mass1, inj_table->mass2, &lambda1, &lambda2);
2025 fprintf(stdout,"Injection logp1 set to %f\n",logp1);
2026 fprintf(stdout,"Injection gamma1 set to %f\n",gamma1);
2027 fprintf(stdout,"Injection gamma2 set to %f\n",gamma2);
2028 fprintf(stdout,"Injection gamma3 set to %f\n",gamma3);
2029 fprintf(stdout,"lambda1 set to %f\n",lambda1);
2030 fprintf(stdout,"lambda2 set to %f\n",lambda2);
2031
2032 /*
2033 For when tagSimInspiralTable is updated
2034 to include EOS params
2035
2036 injEvent->logp1= logp1;
2037 injEvent->gamma1= gamma1;
2038 injEvent->gamma2= gamma2;
2039 injEvent->gamma3= gamma3;
2040 */
2041 }
2042
2043 // Inject 4-coef. spectral eos
2044 REAL8 SDgamma0=0.0;
2045 REAL8 SDgamma1=0.0;
2046 REAL8 SDgamma2=0.0;
2047 REAL8 SDgamma3=0.0;
2048 if(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")){
2049 SDgamma0= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0")->value);
2050 SDgamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1")->value);
2051 SDgamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2")->value);
2052 SDgamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")->value);
2053 REAL8 gamma[]={SDgamma0,SDgamma1,SDgamma2,SDgamma3};
2055 fprintf(stdout,"Injection SDgamma0 set to %lf\n",SDgamma0);
2056 fprintf(stdout,"Injection SDgamma1 set to %lf\n",SDgamma1);
2057 fprintf(stdout,"Injection SDgamma2 set to %lf\n",SDgamma2);
2058 fprintf(stdout,"Injection SDgamma3 set to %lf\n",SDgamma3);
2059 fprintf(stdout,"lambda1 set to %f\n",lambda1);
2060 fprintf(stdout,"lambda2 set to %f\n",lambda2);
2061 }
2062
2063
2064 /* FIXME: One also need to code the same manipulations done to f_max in LALInferenceTemplateXLALSimInspiralChooseWaveform line 856 circa*/
2065
2066 /* Set up LAL dictionary */
2067 LALDict* LALpars=XLALCreateDict();
2068
2069 // Inject deviation from GR
2070 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")){
2071 REAL8 dchi_minus2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")->value);
2073
2074 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")){
2075 REAL8 dchi_minus1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")->value);
2077
2078 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")){
2079 REAL8 dchi0 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")->value);
2081
2082 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")){
2083 REAL8 dchi1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")->value);
2085
2086 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")){
2087 REAL8 dchi2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")->value);
2089
2090 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")){
2091 REAL8 dchi3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")->value);
2093
2094 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")){
2095 REAL8 dchi4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")->value);
2097
2098 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5")){
2099 REAL8 dchi5 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5")->value);
2101
2102 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")){
2103 REAL8 dchi5l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")->value);
2105
2106 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")){
2107 REAL8 dchi6 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")->value);
2109
2110 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")){
2111 REAL8 dchi6l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")->value);
2113
2114 if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")){
2115 REAL8 dchi7 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")->value);
2117
2118 if (LALInferenceGetProcParamVal(commandLine,"--inj-db1")){
2119 REAL8 nongr_db1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db1")->value);
2121
2122 if (LALInferenceGetProcParamVal(commandLine,"--inj-db2")){
2123 REAL8 nongr_db2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db2")->value);
2125
2126 if (LALInferenceGetProcParamVal(commandLine,"--inj-db3")){
2127 REAL8 nongr_db3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db3")->value);
2129
2130 if (LALInferenceGetProcParamVal(commandLine,"--inj-db4")){
2131 REAL8 nongr_db4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db4")->value);
2133
2134 if (LALInferenceGetProcParamVal(commandLine,"--inj-dc1")){
2135 REAL8 nongr_dc1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc1")->value);
2137
2138 if (LALInferenceGetProcParamVal(commandLine,"--inj-dc2")){
2139 REAL8 nongr_dc2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc2")->value);
2141
2142 if (LALInferenceGetProcParamVal(commandLine,"--inj-dc4")){
2143 REAL8 nongr_dc4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc4")->value);
2145
2146 if (LALInferenceGetProcParamVal(commandLine,"--inj-dcl")){
2147 REAL8 nongr_dcl = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dcl")->value);
2149
2150
2151 /* Set the spin-frame convention */
2152 ppt = LALInferenceGetProcParamVal(commandLine,"--inj-spin-frame");
2153 if(ppt) {
2154 if (!strcmp(ppt->value, "view"))
2156 else if (!strcmp(ppt->value, "orbital-l"))
2158 else if (!strcmp(ppt->value, "total-j"))
2160 }
2161
2163 if(LALInferenceGetProcParamVal(commandLine, "--inj-spinOrder")) {
2164 spinO = atoi(LALInferenceGetProcParamVal(commandLine, "--inj-spinOrder")->value);
2166 }
2167
2169 if(LALInferenceGetProcParamVal(commandLine, "--inj-tidalOrder")) {
2170 tideO = atoi(LALInferenceGetProcParamVal(commandLine, "--inj-tidalOrder")->value);
2172 }
2173
2174 REAL8 deltaT = IFOdata->timeData->deltaT;
2175 REAL8 deltaF = IFOdata->freqData->deltaF;
2176
2177 REAL8 f_min = XLALSimInspiralfLow2fStart(inj_table->f_lower, amp_order, approximant);
2178 REAL8 f_max = 0.0;
2179
2180 REAL8 fref = 100.;
2181 if(LALInferenceGetProcParamVal(commandLine,"--inj-fref")) {
2182 fref = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-fref")->value);
2183 }
2184
2185 if (approximant == TaylorF2)
2186 f_max = 0.0; /* this will stop at ISCO */
2187 else{
2188 /* get the max f_max as done in Template. Has to do this since I cannot access LALInferenceModel here*/
2189 dataPtr=IFOdata;
2190 while(dataPtr){
2191 if(dataPtr->fHigh>f_max) f_max=dataPtr->fHigh;
2192 dataPtr=dataPtr->next;
2193 }
2194 }
2195 /* Print a line with information about approximant, amp_order, phaseorder, tide order and spin order */
2196 fprintf(stdout,"\n\n---\t\t ---\n");
2197 fprintf(stdout,"Injection will run using Approximant %i (%s), phase order %i, amp order %i, spin order %i, tidal order %i, in the frequency domain.\n",approximant,XLALSimInspiralGetStringFromApproximant(approximant),phase_order,amp_order,(int) spinO,(int) tideO);
2198 fprintf(stdout,"---\t\t ---\n\n");
2199
2200 COMPLEX16FrequencySeries *hptilde=NULL, *hctilde=NULL;
2201
2206
2207 XLALSimInspiralChooseFDWaveform(&hptilde, &hctilde, inj_table->mass1*LAL_MSUN_SI, inj_table->mass2*LAL_MSUN_SI,
2208 inj_table->spin1x, inj_table->spin1y, inj_table->spin1z,
2209 inj_table->spin2x, inj_table->spin2y, inj_table->spin2z,
2210 inj_table->distance*LAL_PC_SI * 1.0e6, inj_table->inclination,
2211 inj_table->coa_phase, 0., 0., 0., deltaF, f_min, f_max, fref,
2212 LALpars, approximant);
2213 XLALDestroyDict(LALpars);
2214
2215 /* Fail if injection waveform generation was not successful */
2216 errnum = *XLALGetErrnoPtr();
2217 if (errnum != XLAL_SUCCESS) {
2218 XLALPrintError(" ERROR in InjectFD(): error encountered when injecting waveform. errnum=%d\n",errnum);
2219 exit(1);
2220 }
2221
2222 if((ppt=LALInferenceGetProcParamVal(commandLine,"--dump-geocenter-pols"))) {
2223 fprintf(stdout,"Dump injected FreqDomain h_plus and h_cross at geocenter (for IFO %s)\n", IFOdata->name);
2224 char filename[320];
2225 sprintf(filename,"%s_FD_geocenter_pols.dat",IFOdata->name);
2226 FILE* file=fopen(filename, "w");
2227 if(!file){
2228 fprintf(stderr,"Unable to open the path %s for writing injected FreqDomain h_plus and h_cross\n",filename);
2229 exit(1);
2230 }
2231 UINT4 j;
2232 for(j=0; j<hptilde->data->length; j++){
2233 fprintf(file, "%10.10g %10.10g %10.10g %10.10g %10.10g\n", deltaF*j,
2234 creal(hptilde->data->data[j]), cimag(hptilde->data->data[j]),
2235 creal(hctilde->data->data[j]), cimag(hctilde->data->data[j]));
2236 }
2237 fclose(file);
2238 }
2239
2240 REAL8 Fplus, Fcross;
2241 REAL8 plainTemplateReal, plainTemplateImag;
2242 REAL8 templateReal, templateImag;
2243 LIGOTimeGPS GPSlal;
2244 REAL8 gmst;
2245 REAL8 chisquared;
2246 REAL8 timedelay; /* time delay b/w iterferometer & geocenter w.r.t. sky location */
2247 REAL8 timeshift; /* time shift (not necessarily same as above) */
2248 REAL8 twopit, re, im, dre, dim, newRe, newIm;
2249 UINT4 i, lower, upper;
2250
2251 REAL8 temp=0.0;
2252 REAL8 NetSNR=0.0;
2253
2254 /* figure out GMST: */
2255 XLALGPSSetREAL8(&GPSlal, injtime);
2256 gmst=XLALGreenwichMeanSiderealTime(&GPSlal);
2257
2258 /* loop over data (different interferometers): */
2259 dataPtr = IFOdata;
2260
2261 while (dataPtr != NULL) {
2262 /*-- WF to inject is now in hptilde and hctilde. --*/
2263 /* determine beam pattern response (Fplus and Fcross) for given Ifo: */
2264 XLALComputeDetAMResponse(&Fplus, &Fcross,
2265 (const REAL4(*)[3])dataPtr->detector->response,
2266 inj_table->longitude, inj_table->latitude,
2267 inj_table->polarization, gmst);
2268
2269 /* signal arrival time (relative to geocenter); */
2270 timedelay = XLALTimeDelayFromEarthCenter(dataPtr->detector->location,
2271 inj_table->longitude, inj_table->latitude,
2272 &GPSlal);
2273
2274 /* (negative timedelay means signal arrives earlier at Ifo than at geocenter, etc.) */
2275 /* amount by which to time-shift template (not necessarily same as above "timedelay"): */
2276 REAL8 instant = dataPtr->timeData->epoch.gpsSeconds + 1e-9*dataPtr->timeData->epoch.gpsNanoSeconds;
2277
2278 timeshift = (injtime - instant) + timedelay;
2279 twopit = LAL_TWOPI * (timeshift);
2280
2281 dataPtr->fPlus = Fplus;
2282 dataPtr->fCross = Fcross;
2283 dataPtr->timeshift = timeshift;
2284
2285 char InjFileName[320];
2286 sprintf(InjFileName,"injection_%s.dat",dataPtr->name);
2287 FILE *outInj=fopen(InjFileName,"w");
2288
2289 /* determine frequency range & loop over frequency bins: */
2290 lower = (UINT4)ceil(dataPtr->fLow / deltaF);
2291 upper = (UINT4)floor(dataPtr->fHigh / deltaF);
2292 chisquared = 0.0;
2293
2294 re = cos(twopit * deltaF * lower);
2295 im = -sin(twopit * deltaF * lower);
2296
2297 /* When analysing TD data, FD templates need to be amplified by the window power loss factor */
2298 double windowFactor;
2299 windowFactor=sqrt(dataPtr->window->data->length/dataPtr->window->sumofsquares);
2300
2301 for (i=lower; i<=upper; ++i){
2302 /* derive template (involving location/orientation parameters) from given plus/cross waveforms: */
2303 if (i < hptilde->data->length) {
2304 plainTemplateReal = Fplus * creal(hptilde->data->data[i])
2305 + Fcross * creal(hctilde->data->data[i]);
2306 plainTemplateImag = Fplus * cimag(hptilde->data->data[i])
2307 + Fcross * cimag(hctilde->data->data[i]);
2308 } else {
2309 plainTemplateReal = 0.0;
2310 plainTemplateImag = 0.0;
2311 }
2312
2313 /* do time-shifting... */
2314 /* (also un-do 1/deltaT scaling): */
2315 /* real & imag parts of exp(-2*pi*i*f*deltaT): */
2316 templateReal = (plainTemplateReal*re - plainTemplateImag*im);
2317 templateImag = (plainTemplateReal*im + plainTemplateImag*re);
2318
2319 /* apply windowing factor */
2320 templateReal *= ((REAL8) windowFactor);
2321 templateImag *= ((REAL8) windowFactor);
2322
2323 /* Incremental values, using cos(theta) - 1 = -2*sin(theta/2)^2 */
2324 dim = -sin(twopit*deltaF);
2325 dre = -2.0*sin(0.5*twopit*deltaF)*sin(0.5*twopit*deltaF);
2326 newRe = re + re*dre - im * dim;
2327 newIm = im + re*dim + im*dre;
2328 re = newRe;
2329 im = newIm;
2330
2331 fprintf(outInj,"%lf %e %e %e\n",i*deltaF ,templateReal,templateImag,1.0/dataPtr->oneSidedNoisePowerSpectrum->data->data[i]);
2332 dataPtr->freqData->data->data[i] += crect( templateReal, templateImag );
2333
2334 temp = ((2.0/( deltaT*(double) dataPtr->timeData->data->length) * (templateReal*templateReal+templateImag*templateImag)) / dataPtr->oneSidedNoisePowerSpectrum->data->data[i]);
2335 chisquared += temp;
2336 }
2337 printf("injected SNR %.1f in IFO %s\n",sqrt(2.0*chisquared),dataPtr->name);
2338 NetSNR+=2.0*chisquared;
2339 dataPtr->SNR=sqrt(2.0*chisquared);
2340 dataPtr = dataPtr->next;
2341
2342 fclose(outInj);
2343 }
2344 printf("injected Network SNR %.1f \n",sqrt(NetSNR));
2345 ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
2346 if (!ppt){
2347 PrintSNRsToFile(IFOdata , SNRpath);
2348 }
2351}
2352
2353static void PrintSNRsToFile(LALInferenceIFOData *IFOdata , char SNRpath[] ){
2354 REAL8 NetSNR=0.0;
2355 LALInferenceIFOData *thisData=IFOdata;
2356 int nIFO=0;
2357
2358 while(thisData){
2359 thisData=thisData->next;
2360 nIFO++;
2361 }
2362 FILE * snrout = fopen(SNRpath,"w");
2363 if(!snrout){
2364 fprintf(stderr,"Unable to open the path %s for writing SNR files\n",SNRpath);
2365 fprintf(stderr,"Error code %i: %s\n",errno,strerror(errno));
2366 exit(errno);
2367 }
2368 thisData=IFOdata;
2369 while(thisData){
2370 fprintf(snrout,"%s:\t %4.2f\n",thisData->name,thisData->SNR);
2371 nIFO++;
2372 NetSNR+=(thisData->SNR*thisData->SNR);
2373 thisData=thisData->next;
2374 }
2375 if (nIFO>1){
2376 fprintf(snrout,"Network:\t");
2377 fprintf(snrout,"%4.2f\n",sqrt(NetSNR));
2378 }
2379 fclose(snrout);
2380}
2381
2382/**
2383* Fill the variables passed in vars with the parameters of the injection passed in event
2384* will over-write and destroy any existing parameters. Param vary type will be fixed
2385*/
2387{
2388 //UINT4 spinCheck=0;
2389 if(!vars) {
2390 XLALPrintError("Encountered NULL variables pointer");
2392 }
2393 enforce_m1_larger_m2(theEventTable);
2394 REAL8 q = theEventTable->mass2 / theEventTable->mass1;
2395 if (q > 1.0) q = 1.0/q;
2396
2397 REAL8 psi = theEventTable->polarization;
2398 if (psi>=M_PI) psi -= M_PI;
2399
2400 REAL8 injGPSTime = XLALGPSGetREAL8(&(theEventTable->geocent_end_time));
2401
2402 REAL8 dist = theEventTable->distance;
2403 //REAL8 cosinclination = cos(theEventTable->inclination);
2404 REAL8 phase = theEventTable->coa_phase;
2405 REAL8 dec = theEventTable->latitude;
2406 REAL8 ra = theEventTable->longitude;
2407
2408 Approximant injapprox = XLALGetApproximantFromString(theEventTable->waveform);
2409 LALPNOrder order = XLALGetOrderFromString(theEventTable->waveform);
2410
2411 REAL8 m1=theEventTable->mass1;
2412 REAL8 m2=theEventTable->mass2;
2413 REAL8 chirpmass = theEventTable->mchirp;
2414
2417 if (LALInferenceCheckVariable(vars,"distance"))
2419 else if (LALInferenceCheckVariable(vars,"logdistance")){
2420 REAL8 logdistance=log(dist);
2421 LALInferenceAddVariable(vars, "logdistance", &logdistance, LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_FIXED);
2422 }
2425
2426 /* Those will work even if the user is working with the detector-frame variables because SKY_FRAME is set
2427 to zero while calculating the injected logL in LALInferencePrintInjectionSample */
2431
2432
2433 LALInferenceAddVariable(vars, "LAL_APPROXIMANT", &injapprox, LALINFERENCE_UINT4_t, LALINFERENCE_PARAM_FIXED);
2435 LALInferenceAddVariable(vars, "LAL_AMPORDER", &(theEventTable->amp_order), LALINFERENCE_INT4_t, LALINFERENCE_PARAM_FIXED);
2436
2437 REAL8 thetaJN,phiJL,theta1,theta2,phi12,chi1,chi2;
2438 /* Convert cartesian spin coordinates to system-frame variables*/
2439
2440 /* This fref is --inj-fref, which has been set previously by LALInferencePrintInjectionSample
2441 I don't call it inj_fref since LALInferenceTemplate looks for fref, and that is what will be called to calculate
2442 the logL at injval
2443 */
2444 REAL8 fref=100.0;
2445 if (LALInferenceCheckVariable(vars,"f_ref"))
2446 fref= *(REAL8*) LALInferenceGetVariable(vars,"f_ref");
2447
2448 XLALSimInspiralTransformPrecessingWvf2PE(&thetaJN,&phiJL,&theta1,&theta2,&phi12,&chi1,&chi2,theEventTable->inclination,theEventTable->spin1x,theEventTable->spin1y,theEventTable->spin1z, theEventTable->spin2x, theEventTable->spin2y, theEventTable->spin2z,m1,m2,fref,phase);
2449
2450 if (LALInferenceCheckVariable(vars,"a_spin1"))
2452 if (LALInferenceCheckVariable(vars,"a_spin2"))
2454 if (LALInferenceCheckVariable(vars,"tilt_spin1"))
2456 if (LALInferenceCheckVariable(vars,"tilt_spin2"))
2458 if (LALInferenceCheckVariable(vars,"phi_jl"))
2460 if (LALInferenceCheckVariable(vars,"phi12"))
2462 REAL8 costhetajn=cos(thetaJN);
2463 LALInferenceAddVariable(vars, "costheta_jn", &costhetajn, LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_FIXED);
2464
2465}
2466
2468 int errnum=0;
2469 char *fname=NULL;
2470 char defaultname[]="injection_params.dat";
2471 FILE *outfile=NULL;
2472
2473 /* check if the --inj argument has been passed */
2475 if (!ppt)
2476 return(NULL);
2477
2478 SimInspiralTable *injTable=NULL, *theEventTable=NULL;
2480 if (LALInferenceGetProcParamVal(runState->commandLine, "--roqtime_steps")){
2481 LALInferenceSetupROQmodel(model, runState->commandLine);
2482 fprintf(stderr, "done LALInferenceSetupROQmodel\n");
2483 } else {
2484 model->roq_flag=0;
2485 }
2487 LALInferenceCopyVariables(model->params, injparams);
2488
2490
2491 ppt = LALInferenceGetProcParamVal(runState->commandLine, "--outfile");
2492 if (ppt) {
2493 fname = XLALCalloc((strlen(ppt->value)+255)*sizeof(char),1);
2494 sprintf(fname,"%s.injection",ppt->value);
2495 }
2496 else
2497 fname = defaultname;
2498
2499 ppt = LALInferenceGetProcParamVal(runState->commandLine, "--event");
2500 if (ppt) {
2501 UINT4 event = atoi(ppt->value);
2502 UINT4 i;
2503 theEventTable = injTable;
2504 for (i = 0; i < event; i++) {
2505 theEventTable = theEventTable->next;
2506 }
2507 theEventTable->next = NULL;
2508 } else {
2509 theEventTable=injTable;
2510 theEventTable->next = NULL;
2511 }
2512
2513 LALPNOrder *order = LALInferenceGetVariable(injparams, "LAL_PNORDER");
2514 Approximant *approx = LALInferenceGetVariable(injparams, "LAL_APPROXIMANT");
2515
2516 if (!(approx && order)){
2517 fprintf(stdout,"Unable to print injection sample: No approximant/PN order set\n");
2518 return(NULL);
2519 }
2520
2521 REAL8 fref = 100.;
2522 if(LALInferenceGetProcParamVal(runState->commandLine,"--inj-fref")) {
2523 fref = atoi(LALInferenceGetProcParamVal(runState->commandLine,"--inj-fref")->value);
2524 }
2526
2527 UINT4 azero=0;
2528 LALInferenceAddVariable(injparams,"SKY_FRAME",(void *)&azero,LALINFERENCE_REAL8_t,LALINFERENCE_PARAM_OUTPUT);
2529 /* remove eventual SKY FRAME vars since they will contain garbage*/
2530 if (LALInferenceCheckVariable(injparams,"t0"))
2531 LALInferenceRemoveVariable(injparams,"t0");
2532 if (LALInferenceCheckVariable(injparams,"cosalpha"))
2533 LALInferenceRemoveVariable(injparams,"cosalpha");
2534 if (LALInferenceCheckVariable(injparams,"azimuth"))
2535 LALInferenceRemoveVariable(injparams,"azimuth");
2536
2537 /* Fill named variables */
2538 LALInferenceInjectionToVariables(theEventTable, injparams);
2539
2540 REAL8 injPrior = runState->prior(runState, injparams, model);
2542 REAL8 injL=0.;
2543 if ( (int) *approx == XLALGetApproximantFromString(theEventTable->waveform)){
2544 XLAL_TRY(injL = runState->likelihood(injparams, runState->data, model), errnum);
2545 if(errnum){
2546 fprintf(stderr,"ERROR: Cannot print injection sample. Received error code %s\n",XLALErrorString(errnum));
2547 }
2548 }
2550 REAL8 logZnoise=LALInferenceNullLogLikelihood(runState->data);
2551 REAL8 tmp2=injL-logZnoise;
2552 LALInferenceAddVariable(injparams,"deltalogL",(void *)&tmp2,LALINFERENCE_REAL8_t,LALINFERENCE_PARAM_OUTPUT);
2553
2554 LALInferenceIFOData *data=runState->data;
2555 while(data) {
2556 char tmpName[320];
2557 REAL8 tmp=model->loglikelihood - data->nullloglikelihood;
2558 sprintf(tmpName,"deltalogl%s",data->name);
2560 data=data->next;
2561 }
2562
2563 /* Save to file */
2564 outfile=fopen(fname,"w");
2565 if(!outfile) {fprintf(stderr,"ERROR: Unable to open file %s for injection saving\n",fname); exit(1);}
2568 fprintf(outfile,"\n");
2569 LALInferencePrintSample(outfile, injparams);
2570
2571 fclose(outfile);
2572 //LALInferenceClearVariables(injparams);
2573 return(injparams);
2574}
2575
2577 /* Template generator assumes m1>=m2 thus we must enfore the same convention while injecting, otherwise spin2 will be assigned to mass1
2578 * We also shift the phase by pi to be sure the same WF in injected
2579 * Returns: 1 if masses were flipped
2580 */
2581 REAL8 m1,m2,tmp;
2582 m1=injEvent->mass1;
2583 m2=injEvent->mass2;
2584
2585 if (m1>=m2) return(0);
2586 else{
2587 fprintf(stdout, "Injtable has m1<m2. Flipping masses and spins in injection. Shifting phase by pi. \n");
2588 tmp=m1;
2589 injEvent->mass1=injEvent->mass2;
2590 injEvent->mass2=tmp;
2591 tmp=injEvent->spin1x;
2592 injEvent->spin1x=injEvent->spin2x;
2593 injEvent->spin2x=tmp;
2594 tmp=injEvent->spin1y;
2595 injEvent->spin1y=injEvent->spin2y;
2596 injEvent->spin2y=tmp;
2597 tmp=injEvent->spin1z;
2598 injEvent->spin1z=injEvent->spin2z;
2599 injEvent->spin2z=tmp;
2600 injEvent->coa_phase=injEvent->coa_phase+LAL_PI;
2601 return(1);
2602 }
2603}
2604
2606
2608 memset(&status,0,sizeof(status));
2609 UINT4 q=0;
2610 UINT4 event=0;
2611 ProcessParamsTable *procparam=NULL,*ppt=NULL;
2612 SimInspiralTable *injTable=NULL;
2613 FILE *tempfp;
2614 unsigned int n_basis_linear=0, n_basis_quadratic=0, n_samples=0, time_steps=0;
2615 int errsave;
2616
2617 LIGOTimeGPS GPStrig;
2618 REAL8 endtime=0.0;
2619
2620 model->roq = XLALMalloc(sizeof(LALInferenceROQModel));
2621 model->roq_flag = 1;
2622 procparam=LALInferenceGetProcParamVal(commandLine,"--inj");
2623 if(procparam){
2624 injTable = XLALSimInspiralTableFromLIGOLw(procparam->value);
2625 if(!injTable){
2626 fprintf(stderr,"Unable to open injection file(LALInferenceReadData) %s\n",procparam->value);
2627 exit(1);
2628 }
2629 procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2630 if(procparam) {
2631 event=atoi(procparam->value);
2632 while(q<event) {q++; injTable=injTable->next;}
2633 }
2634 else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id")))
2635 {
2636 while(injTable)
2637 {
2638 if(injTable->simulation_id == atol(procparam->value)) break;
2639 else injTable=injTable->next;
2640 }
2641 if(!injTable){
2642 fprintf(stderr,"Error, cannot find simulation id %s in injection file\n",procparam->value);
2643 exit(1);
2644 }
2645 }
2646 }
2647
2648 if(LALInferenceGetProcParamVal(commandLine,"--trigtime")){
2649 procparam=LALInferenceGetProcParamVal(commandLine,"--trigtime");
2650 XLALStrToGPS(&GPStrig,procparam->value,NULL);
2651 }
2652 else{
2653 if(injTable) memcpy(&GPStrig,&(injTable->geocent_end_time),sizeof(GPStrig));
2654 else {
2655 fprintf(stderr,">>> Error: No trigger time specifed and no injection given \n");
2656 exit(1);
2657 }
2658 }
2659
2660 endtime=XLALGPSGetREAL8(&GPStrig);
2661
2662 if(LALInferenceGetProcParamVal(commandLine,"--roqtime_steps")){
2663 ppt=LALInferenceGetProcParamVal(commandLine,"--roqtime_steps");
2664 tempfp = fopen (ppt->value,"r");
2665 if (tempfp == NULL){
2666 errsave = errno;
2667 fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2668 fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2669 exit(errsave);
2670 }
2671 fscanf(tempfp, "%u", &time_steps);
2672 fscanf(tempfp, "%u", &n_basis_linear);
2673 fscanf(tempfp, "%u", &n_basis_quadratic);
2674 fscanf(tempfp, "%u", &n_samples);
2675 fclose(tempfp);
2676 fprintf(stderr, "loaded --roqtime_steps\n");
2677 }
2678
2679
2680 model->roq->frequencyNodesLinear = XLALCreateREAL8Sequence(n_basis_linear);
2681 model->roq->frequencyNodesQuadratic = XLALCreateREAL8Sequence(n_basis_quadratic);
2682
2683 model->roq->trigtime = endtime;
2684
2685 model->roq->frequencyNodesLinear = XLALCreateREAL8Sequence(n_basis_linear);
2686 model->roq->frequencyNodesQuadratic = XLALCreateREAL8Sequence(n_basis_quadratic);
2687 model->roq->calFactorLinear = XLALCreateCOMPLEX16Sequence(model->roq->frequencyNodesLinear->length);
2688 model->roq->calFactorQuadratic = XLALCreateCOMPLEX16Sequence(model->roq->frequencyNodesQuadratic->length);
2689
2690 if(LALInferenceGetProcParamVal(commandLine,"--roqnodesLinear")){
2691 ppt=LALInferenceGetProcParamVal(commandLine,"--roqnodesLinear");
2692
2693 model->roq->nodesFileLinear = fopen(ppt->value, "rb");
2694 if (!(model->roq->nodesFileLinear)) {
2695 errsave = errno;
2696 fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2697 fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2698 exit(errsave);
2699 } // check file exists
2700 fprintf(stderr, "read model->roq->frequencyNodesLinear");
2701
2702 for(unsigned int linsize = 0; linsize < n_basis_linear; linsize++){
2703 fread(&(model->roq->frequencyNodesLinear->data[linsize]), sizeof(REAL8), 1, model->roq->nodesFileLinear);
2704 }
2705 fclose(model->roq->nodesFileLinear);
2706 model->roq->nodesFileLinear = NULL;
2707 fprintf(stderr, "loaded --roqnodesLinear\n");
2708 }
2709
2710 if(LALInferenceGetProcParamVal(commandLine,"--roqnodesQuadratic")){
2711 ppt=LALInferenceGetProcParamVal(commandLine,"--roqnodesQuadratic");
2712 model->roq->nodesFileQuadratic = fopen(ppt->value, "rb");
2713 if (!(model->roq->nodesFileQuadratic)) {
2714 errsave = errno;
2715 fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2716 fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2717 exit(errsave);
2718 } // check file exists
2719
2720 for(unsigned int quadsize = 0; quadsize < n_basis_quadratic; quadsize++){
2721 fread(&(model->roq->frequencyNodesQuadratic->data[quadsize]), sizeof(REAL8), 1, model->roq->nodesFileQuadratic);
2722 }
2723 fclose(model->roq->nodesFileQuadratic);
2724 model->roq->nodesFileQuadratic = NULL;
2725 fprintf(stderr, "loaded --roqnodesQuadratic\n");
2726
2727
2728
2729 }
2730}
2731
2734 memset(&status,0,sizeof(status));
2735 LALInferenceIFOData *thisData=IFOdata;
2736 UINT4 q=0;
2737 UINT4 event=0;
2738 ProcessParamsTable *procparam=NULL,*ppt=NULL;
2739 SimInspiralTable *injTable=NULL;
2740 unsigned int n_basis_linear, n_basis_quadratic, n_samples, time_steps;
2741 float dt=0.1;
2742 //REAL8 timeMin=0.0,timeMax=0.0;
2743 FILE *tempfp;
2744 char tmp[320];
2745 int errsave;
2746
2747 procparam=LALInferenceGetProcParamVal(commandLine,"--inj");
2748 if(procparam) {
2749 injTable = XLALSimInspiralTableFromLIGOLw(procparam->value);
2750 if (!injTable) {
2751 fprintf(stderr,"Unable to open injection file(LALInferenceReadData) %s\n",procparam->value);
2752 exit(1);
2753 }
2754 procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2755 if (procparam) {
2756 event=atoi(procparam->value);
2757 while(q<event) {
2758 q++;
2759 injTable=injTable->next;
2760 }
2761 } else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id"))) {
2762 while (injTable) {
2763 if (injTable->simulation_id == atol(procparam->value)) {
2764 break;
2765 } else {
2766 injTable=injTable->next;
2767 }
2768 }
2769 if (!injTable) {
2770 fprintf(stderr, "Error, cannot find simulation id %s in injection file\n", procparam->value);
2771 exit(1);
2772 }
2773 }
2774 }
2775
2776 ppt=LALInferenceGetProcParamVal(commandLine,"--dt");
2777 if(ppt){
2778 dt=atof(ppt->value);
2779 }
2780
2781 if (LALInferenceGetProcParamVal(commandLine,"--roqtime_steps")) {
2782 ppt = LALInferenceGetProcParamVal(commandLine,"--roqtime_steps");
2783 tempfp = fopen (ppt->value,"r");
2784 if (tempfp == NULL){
2785 errsave = errno;
2786 fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2787 fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2788 exit(errsave);
2789 }
2790 fscanf(tempfp, "%u", &time_steps);
2791 fscanf(tempfp, "%u", &n_basis_linear);
2792 fscanf(tempfp, "%u", &n_basis_quadratic);
2793 fscanf(tempfp, "%u", &n_samples);
2794 fclose(tempfp);
2795 fprintf(stderr, "loaded --roqtime_steps\n");
2796 }
2797
2798
2799 thisData=IFOdata;
2800 while (thisData) {
2801 thisData->roq = XLALMalloc(sizeof(LALInferenceROQData));
2802
2803 thisData->roq->weights_linear = XLALMalloc(n_basis_linear*sizeof(LALInferenceROQSplineWeights));
2804
2805 sprintf(tmp, "--%s-roqweightsLinear", thisData->name);
2806 ppt = LALInferenceGetProcParamVal(commandLine,tmp);
2807
2808 thisData->roq->weightsFileLinear = fopen(ppt->value, "rb");
2809 if (thisData->roq->weightsFileLinear == NULL){
2810 errsave = errno;
2811 fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2812 fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2813 exit(errsave);
2814 }
2815 thisData->roq->weightsLinear = (double complex*)malloc(n_basis_linear*time_steps*(sizeof(double complex)));
2816
2817 //0.045 comes from the diameter of the earth in light seconds: the maximum time-delay between earth-based observatories
2818 thisData->roq->time_weights_width = 2*dt + 2*0.045;
2819 thisData->roq->time_step_size = thisData->roq->time_weights_width/time_steps;
2820 thisData->roq->n_time_steps = time_steps;
2821
2822
2823 fprintf(stderr, "basis_size = %d\n", n_basis_linear);
2824 fprintf(stderr, "time steps = %d\n", time_steps);
2825
2826 double *tmp_real_weight = malloc(time_steps*(sizeof(double)));
2827 double *tmp_imag_weight = malloc(time_steps*(sizeof(double)));
2828
2829 double *tmp_tcs = malloc(time_steps*(sizeof(double)));
2830
2831 sprintf(tmp, "--roq-times");
2832 ppt = LALInferenceGetProcParamVal(commandLine,tmp);
2833
2834 FILE *tcFile = fopen(ppt->value, "rb");
2835 if (tcFile == NULL) {
2836 errsave = errno;
2837 fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2838 fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2839 exit(errsave);
2840 }
2841
2842 for(unsigned int gg=0;gg < time_steps; gg++){
2843 fread(&(tmp_tcs[gg]), sizeof(double), 1, tcFile);
2844 }
2845
2846 for(unsigned int ii=0; ii<n_basis_linear;ii++){
2847 for(unsigned int jj=0; jj<time_steps;jj++){
2848 fread(&(thisData->roq->weightsLinear[ii*time_steps + jj]), sizeof(double complex), 1, thisData->roq->weightsFileLinear);
2849 tmp_real_weight[jj] = creal(thisData->roq->weightsLinear[ii*time_steps + jj]);
2850 tmp_imag_weight[jj] = cimag(thisData->roq->weightsLinear[ii*time_steps + jj]);
2851 }
2852 //gsl_interp_accel is not thread-safe, and each OpenMP thread will need its
2853 //own gsl_interp_accel object.
2854 thisData->roq->weights_linear[ii].acc_real_weight_linear = NULL;
2855 thisData->roq->weights_linear[ii].acc_imag_weight_linear = NULL;
2856
2857 thisData->roq->weights_linear[ii].spline_real_weight_linear = gsl_spline_alloc (gsl_interp_cspline, time_steps);
2858 gsl_spline_init(thisData->roq->weights_linear[ii].spline_real_weight_linear, tmp_tcs, tmp_real_weight, time_steps);
2859
2860 thisData->roq->weights_linear[ii].spline_imag_weight_linear = gsl_spline_alloc (gsl_interp_cspline, time_steps);
2861 gsl_spline_init(thisData->roq->weights_linear[ii].spline_imag_weight_linear, tmp_tcs, tmp_imag_weight, time_steps);
2862 }
2863 fclose(thisData->roq->weightsFileLinear);
2864 thisData->roq->weightsFileLinear = NULL;
2865 fclose(tcFile);
2866
2867 sprintf(tmp, "--%s-roqweightsQuadratic", thisData->name);
2868 ppt = LALInferenceGetProcParamVal(commandLine,tmp);
2869 thisData->roq->weightsQuadratic = (double*)malloc(n_basis_quadratic*sizeof(double));
2870 thisData->roq->weightsFileQuadratic = fopen(ppt->value, "rb");
2871 if (thisData->roq->weightsFileQuadratic == NULL){
2872 errsave = errno;
2873 fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2874 fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2875 exit(errsave);
2876 }
2877 for(unsigned int ii=0; ii<n_basis_quadratic;ii++){
2878 fread(&(thisData->roq->weightsQuadratic[ii]), sizeof(double), 1, thisData->roq->weightsFileQuadratic);
2879 }
2880 fclose(thisData->roq->weightsFileQuadratic);
2881 thisData->roq->weightsFileQuadratic = NULL;
2882 fprintf(stderr, "loaded %s ROQ weights\n", thisData->name);
2883 thisData = thisData->next;
2884 }
2885}
2886
2888
2889 ProcessParamsTable *procparam;
2890 SimInspiralTable *inspiralTable=NULL;
2891 SimBurst *burstTable=NULL;
2892 UINT4 event=0;
2893 UINT4 q=0;
2895 memset(&status,0,sizeof(LALStatus));
2896
2897 /* First check if trigtime has been given as an option */
2898 if(LALInferenceGetProcParamVal(commandLine,"--trigtime")){
2899 procparam=LALInferenceGetProcParamVal(commandLine,"--trigtime");
2900 XLALStrToGPS(GPStrig,procparam->value,NULL);
2901 fprintf(stdout,"Set trigtime to %.10f\n",GPStrig->gpsSeconds+1.0e-9 * GPStrig->gpsNanoSeconds);
2902 return;
2903
2904 }
2905 else{
2906 /* If not check if we have an injtable passed with --inj */
2907
2908 if(LALInferenceGetProcParamVal(commandLine,"--injXML"))
2909 {
2910 XLALPrintError("ERROR: --injXML option is deprecated. Use --inj and update your scripts\n");
2911 exit(1);
2912 }
2913 if((procparam=LALInferenceGetProcParamVal(commandLine,"--inj"))){
2914 fprintf(stdout,"Checking if the xml table is an inspiral table... \n");
2915 /* Check if it is a SimInspiralTable */
2916 inspiralTable = XLALSimInspiralTableFromLIGOLw(procparam->value);
2917
2918 if (inspiralTable){
2919 procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2920 if(procparam) {
2921 event=atoi(procparam->value);
2922 while(q<event) {q++; inspiralTable=inspiralTable->next;}
2923 }
2924 else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id")))
2925 {
2926 while(inspiralTable)
2927 {
2928 if(inspiralTable->simulation_id == atol(procparam->value)) break;
2929 else inspiralTable=inspiralTable->next;
2930 }
2931 if(!inspiralTable){
2932 fprintf(stderr,"Error, cannot find simulation id %s in injection file\n",procparam->value);
2933 exit(1);
2934 }
2935 }
2936 else
2937 fprintf(stdout,"You did not provide an event number with the injtable. Using event 0 which may not be what you want!!!!!\n");
2938 memcpy(GPStrig,&(inspiralTable->geocent_end_time),sizeof(LIGOTimeGPS));
2939 printf("Set inspiral injtime %.10f\n",inspiralTable->geocent_end_time.gpsSeconds+1.0e-9* inspiralTable->geocent_end_time.gpsNanoSeconds);
2940 return;
2941 }
2942 }
2943 else if((procparam=LALInferenceGetProcParamVal(commandLine,"--binj"))){
2944 /* Check if it is a SimBurst table */
2945 fprintf(stdout,"Checking if the xml table is a burst table... \n");
2946 burstTable=XLALSimBurstTableFromLIGOLw(procparam->value);
2947 if(burstTable){
2948 procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2949 if(procparam) {
2950 event=atoi(procparam->value);
2951 while(q<event) {q++; burstTable=burstTable->next;}
2952 }
2953 else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id")))
2954 {
2955 fprintf(stderr,"Error, SimBurst tables do not currently support event_id tags \n");
2956 exit(1);
2957 }
2958 else
2959 fprintf(stdout,"You did not provide an event number with the injtable. Using event 0 which may not be what you want!!!!!\n");
2960 memcpy(GPStrig,&(burstTable->time_geocent_gps),sizeof(LIGOTimeGPS));
2961 fprintf(stdout,"Set trigtime from burstable to %.10f\n",GPStrig->gpsSeconds+1.0e-9 * GPStrig->gpsNanoSeconds);
2962 return;
2963 }
2964 }
2965 else if(!LALInferenceGetProcParamVal(commandLine,"--segment-start")){
2966 XLALPrintError("Error: No trigger time specifed and no injection given \n");
2967 //XLAL_ERROR_NULL(XLAL_EINVAL);
2968 exit(1);
2969 }
2970
2971 }
2972}
2973
2975
2976 /* Read time domain WF present in an mdc frame file, FFT it and inject into the frequency domain stream */
2977
2978 char mdcname[]="GW";
2979 char **mdc_caches=NULL;
2980 char **mdc_channels=NULL;
2981 ProcessParamsTable * ppt=commandLine;
2982
2983 UINT4 nIFO=0;
2984 int i=0;
2985 UINT4 j=0;
2986 LALInferenceIFOData *data=IFOdata;
2987 REAL8 prefactor =1.0;
2988 ppt=LALInferenceGetProcParamVal(commandLine,"--mdc-prefactor");
2989 if (ppt){
2990
2991 prefactor=atof(ppt->value);
2992 fprintf(stdout,"Using prefactor=%f to scale the MDC injection\n",prefactor);
2993 }
2994
2995 ppt=LALInferenceGetProcParamVal(commandLine,"--inj");
2996 if (ppt){
2997
2998 fprintf(stderr,"You cannot use both injfile (--inj) and MDCs (--inject_from_mdc) Exiting... \n");
2999 exit(1);
3000
3001 }
3002 ppt=LALInferenceGetProcParamVal(commandLine,"--binj");
3003 if (ppt){
3004
3005 fprintf(stderr,"You cannot use both injfile (--binj) and MDCs (--inject_from_mdc) Exiting... \n");
3006 exit(1);
3007
3008 }
3009
3010 REAL8 tmp=0.0;
3011 REAL8 net_snr=0.0;
3012 while (data) {nIFO++; data=data->next;}
3013 UINT4 Nmdc=0,Nchannel=0;
3014
3015 char mdc_caches_name[] = "injcache";
3016 char mdc_channels_name[] = "injchannel";
3017 char **IFOnames=NULL;
3018 INT4 rlceops= getNamedDataOptionsByDetectors(commandLine, &IFOnames,&mdc_caches ,mdc_caches_name, &Nmdc);
3019 if (!rlceops){
3020 fprintf(stderr,"Must provide a --IFO-injcache option for each IFO if --inject_from_mdc is given\n");
3021 exit(1);
3022 }
3023
3024 rlceops= getNamedDataOptionsByDetectors(commandLine, &IFOnames,&mdc_channels ,mdc_channels_name, &Nchannel);
3025 if (!rlceops){
3026 fprintf(stdout,"WARNING: You did not provide the name(s) of channel(s) to use with the injection mdc. Using the default which may not be what you want!\n");
3027 mdc_channels= malloc((nIFO+1)*sizeof(char*));
3028 data=IFOdata;
3029 i=0;
3030 while (data){
3031 mdc_channels[i] = malloc(512*sizeof(char));
3032 if(!strcmp(data->name,"H1")) {
3033 sprintf(mdc_channels[i],"H1:%s-H",mdcname);}
3034 else if(!strcmp(data->name,"L1")) {
3035 sprintf(mdc_channels[i],"L1:%s-H",mdcname); }
3036 else if(!strcmp(data->name,"V1")) {
3037 sprintf(mdc_channels[i],"V1:%s-16K",mdcname);}
3038 data=data->next;
3039 i++;
3040
3041 }
3042 }
3043
3044 LIGOTimeGPS epoch=IFOdata->timeData->epoch;
3045 REAL8 deltaT=IFOdata->timeData->deltaT ;
3046 int seglen=IFOdata->timeData->data->length;
3047 REAL8 SampleRate=4096.0,SegmentLength=0.0;
3048 if(LALInferenceGetProcParamVal(commandLine,"--srate")) SampleRate=atof(LALInferenceGetProcParamVal(commandLine,"--srate")->value);
3049 SegmentLength=(REAL8) seglen/SampleRate;
3050
3051 REAL8TimeSeries * timeData=NULL;
3054
3055 if(!injF) {
3056 XLALPrintError("Unable to allocate memory for injection buffer\n");
3058 }
3059
3060 REAL4 WinNorm = sqrt(IFOdata->window->sumofsquares/IFOdata->window->data->length);
3061
3062 data=IFOdata;
3063 i=0;
3064 UINT4 lower = (UINT4)ceil(data->fLow / injF->deltaF);
3065 UINT4 upper = (UINT4)floor(data->fHigh /injF-> deltaF);
3066 //FIXME CHECK WNORM
3067 /* Inject into FD data stream and calculate optimal SNR */
3068 while(data){
3069 tmp=0.0;
3070 LALCache *mdc_cache=NULL;
3071 mdc_cache = XLALCacheImport(mdc_caches[i] );
3072
3073 /* Read MDC frame */
3074 timeData=readTseries(mdc_cache,mdc_channels[i],epoch,SegmentLength);
3075 /* downsample */
3076 XLALResampleREAL8TimeSeries(timeData,1.0/SampleRate);
3077 /* window timeData and store it in windTimeData */
3078 XLALDDVectorMultiply(windTimeData->data,timeData->data,IFOdata->window->data);
3079
3080 /*for(j=0;j< timeData->data->length;j++)
3081 fprintf(out,"%lf %10.10e %10.10e %10.10e \n",epoch.gpsSeconds + j*deltaT,data->timeData->data->data[j],data->timeData->data->data[j]+timeData->data->data[j],timeData->data->data[j]);
3082 fclose(out);
3083 */
3084
3085 /* set the whole seq to 0 */
3086 for(j=0;j<injF->data->length;j++) injF->data->data[j]=0.0;
3087
3088 /* FFT */
3089 XLALREAL8TimeFreqFFT(injF,windTimeData,IFOdata->timeToFreqFFTPlan);
3090
3091
3092 for(j=lower;j<upper;j++){
3093 windTimeData->data->data[j] /= sqrt(data->window->sumofsquares / data->window->data->length);
3094 /* Add data in freq stream */
3095 data->freqData->data->data[j]+=crect(prefactor *creal(injF->data->data[j])/WinNorm,prefactor *cimag(injF->data->data[j])/WinNorm);
3096 tmp+= prefactor*prefactor*(creal(injF ->data->data[j])*creal(injF ->data->data[j])+cimag(injF ->data->data[j])*cimag(injF ->data->data[j]))/data->oneSidedNoisePowerSpectrum->data->data[j];
3097 }
3098
3099 tmp*=2.*injF->deltaF;
3100 printf("Injected SNR %.3f in IFO %s from MDC \n",sqrt(2*tmp),data->name);
3101 data->SNR=sqrt(2*tmp);
3102 net_snr+=2*tmp;
3103 i++;
3104 data=data->next;
3105 }
3106 printf("Injected network SNR %.3f from MDC\n",sqrt(net_snr));
3107
3108 char SNRpath[FILENAME_MAX+100];
3109 ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
3110 if(!ppt){
3111 fprintf(stderr,"Must specify --outfile <filename.dat>\n");
3112 exit(1);
3113 }
3114 char *outfile=ppt->value;
3115 snprintf(SNRpath,sizeof(SNRpath),"%s_snr.txt",outfile);
3116 ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
3117 if (!ppt){
3118 PrintSNRsToFile(IFOdata , SNRpath);
3119 }
3120 return ;
3121
3122}
int XLALStrToGPS(LIGOTimeGPS *t, const char *nptr, char **endptr)
LALDetectorIndexE1DIFF
LALDetectorIndexE2DIFF
LALDetectorIndexE3DIFF
LALDetectorIndexLLODIFF
LALDetectorIndexGEO600DIFF
LALDetectorIndexKAGRADIFF
LALDetectorIndexVIRGODIFF
LALDetectorIndexLHODIFF
LALDetectorIndexLIODIFF
void LALFindChirpInjectSignals(LALStatus *status, REAL4TimeSeries *chan, SimInspiralTable *events, COMPLEX8FrequencySeries *resp)
void XLALDestroyDict(LALDict *dict)
LALDict * XLALCreateDict(void)
void REPORTSTATUS(LALStatus *status)
int XLALCheckBurstApproximantFromString(const CHAR *inString)
LALInferenceModel * LALInferenceInitCBCModel(LALInferenceRunState *state)
Initialise state variables needed for LALInferenceNest or LALInferenceMCMC to run on a CBC signal.
static REAL8 norm(const REAL8 x[3])
void InjectFD(LALInferenceIFOData *IFOdata, SimInspiralTable *inj_table, ProcessParamsTable *commandLine)
-----------— Inject in Frequency domain --------------—‍/
static void makeWhiteData(LALInferenceIFOData *IFOdata)
static INT4 getNamedDataOptionsByDetectors(ProcessParamsTable *commandLine, char ***ifos, char ***out, const char *name, UINT4 *N)
Parse the command line looking for options of the kind —IFO-name value Unlike the function above,...
void LALInferenceInjectInspiralSignal(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
void MetaNoiseFunc(LALStatus *status, REAL8 *psd, REAL8 f, struct fvec *interp, NoiseFunc *noisefunc)
struct fvec * interpFromFile(char *filename, REAL8 squareinput)
void() NoiseFunc(LALStatus *statusPtr, REAL8 *psd, REAL8 f)
#define USAGE
#define LALINFERENCE_DEFAULT_FLOW
int enforce_m1_larger_m2(SimInspiralTable *injEvent)
static const LALUnit strainPerCount
static void LALInferencePrintDataWithInjection(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
static INT4 getDataOptionsByDetectors(ProcessParamsTable *commandLine, char ***ifos, char ***caches, char ***channels, char ***flows, char ***fhighs, char ***timeslides, char ***asds, char ***psds, UINT4 *N)
Parse the command line looking for options of the kind –ifo H1 –H1-channel H1:LDAS_STRAIN –H1-cache H...
static void PrintSNRsToFile(LALInferenceIFOData *IFOdata, char SNRpath[])
static LALCache * GlobFramesPWD(char *ifo)
static REAL8TimeSeries * readTseries(LALCache *cache, CHAR *channel, LIGOTimeGPS start, REAL8 length)
static void LALInferenceSetGPSTrigtime(LIGOTimeGPS *GPStrig, ProcessParamsTable *commandLine)
REAL8 interpolate(struct fvec *fvec, REAL8 f)
ProcessParamsTable * ppt
int j
int k
void XLALSimInjectNinjaSignals(REAL4TimeSeries *chan, const char *ifo, REAL8 dynRange, SimInspiralTable *events)
int XLALGetOrderFromString(const char *waveform)
int XLALGetApproximantFromString(const char *waveform)
REAL8 XLALSimInspiralfLow2fStart(REAL8 fLow, INT4 ampOrder, INT4 approximant)
int XLALSimInspiralImplementedFDApproximants(Approximant approximant)
int XLALSimInspiralGetFrameAxisFromString(const char *waveform)
const char * XLALSimInspiralGetStringFromApproximant(Approximant approximant)
#define gamma
int XLALSimInspiralWaveformParamsInsertNonGRDC1(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi4(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDB4(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChiMinus2(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertPNPhaseOrder(LALDict *params, INT4 value)
int XLALSimInspiralWaveformParamsInsertNumRelData(LALDict *params, const char *value)
int XLALSimInspiralWaveformParamsInsertNonGRDB2(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDBeta1(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDBeta2(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChiMinus1(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi5L(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi1(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertTidalLambda1(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi5(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi7(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertFrameAxis(LALDict *params, INT4 value)
int XLALSimInspiralWaveformParamsInsertNonGRDBeta3(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi2(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi3(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertPNSpinOrder(LALDict *params, INT4 value)
int XLALSimInspiralWaveformParamsInsertTidalLambda2(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertPNAmplitudeOrder(LALDict *params, INT4 value)
int XLALSimInspiralWaveformParamsInsertNonGRDC2(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertPNTidalOrder(LALDict *params, INT4 value)
int XLALSimInspiralWaveformParamsInsertNonGRDB3(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDCL(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDAlpha1(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi6(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDC4(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi6L(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDAlpha3(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDChi0(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDB1(LALDict *params, REAL8 value)
int XLALSimInspiralWaveformParamsInsertNonGRDAlpha2(LALDict *params, REAL8 value)
#define ABORTXLAL(sp)
SimInspiralTable * XLALSimInspiralTableFromLIGOLw(const char *fileName)
SimBurst * XLALSimBurstTableFromLIGOLw(const char *filename)
#define fscanf
#define fprintf
const char *const name
double e
const char * detector
sigmaKerr data[0]
LALDetector * XLALCreateDetector(LALDetector *detector, const LALFrDetector *frDetector, LALDetectorType type)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
void XLALComputeDetAMResponse(double *fplus, double *fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const double gmst)
COMPLEX16FrequencySeries * XLALCreateCOMPLEX16FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
REAL8FrequencySeries * XLALCreateREAL8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCOMPLEX8FrequencySeries(COMPLEX8FrequencySeries *series)
COMPLEX8FrequencySeries * XLALCreateCOMPLEX8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCOMPLEX16FrequencySeries(COMPLEX16FrequencySeries *series)
void LALGenerateInspiral(LALStatus *status, CoherentGW *waveform, SimInspiralTable *params, PPNParamStruc *ppnParamsInputOutput)
void XLALDestroyCache(LALCache *cache)
LALCache * XLALCacheGlob(const char *dirstr, const char *fnptrn)
LALCache * XLALCacheImport(const char *fname)
LALCache * XLALCacheDuplicate(const LALCache *cache)
int XLALCacheSieve(LALCache *cache, INT4 t0, INT4 t1, const char *srcregex, const char *dscregex, const char *urlregex)
#define LAL_MSUN_SI
#define LAL_PI
#define LAL_TWOPI
#define LAL_PC_SI
#define crect(re, im)
#define XLAL_NUM_ELEM(x)
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
LALDETECTORTYPE_IFODIFF
int XLALFrStreamClose(LALFrStream *stream)
LALFrStream * XLALFrStreamCacheOpen(LALCache *cache)
REAL8TimeSeries * XLALFrStreamInputREAL8TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, double duration, size_t lengthlimit)
#define VARNAME_MAX
Definition: LALInference.h:50
void LALInferencePrintSample(FILE *fp, LALInferenceVariables *sample)
Output the sample to file *fp, in ASCII format.
Definition: LALInference.c:923
int LALInferenceFprintParameterHeaders(FILE *out, LALInferenceVariables *params)
Print the parameter names to a file as a tab-separated ASCII line.
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
Add a variable named name to vars with initial value referenced by value.
Definition: LALInference.c:395
void LALInferenceLogp1GammasMasses2Lambdas(REAL8 logp1, REAL8 gamma1, REAL8 gamma2, REAL8 gamma3, REAL8 mass1, REAL8 mass2, REAL8 *lambda1, REAL8 *lambda2)
Calculate lambda1,2(m1,2|eos(logp1,gamma1,gamma2,gamma3))
void LALInferenceRemoveVariable(LALInferenceVariables *vars, const char *name)
Remove name from vars Frees the memory for the name structure and its contents.
Definition: LALInference.c:450
void LALInferenceLambdaTsEta2Lambdas(REAL8 lambdaT, REAL8 dLambdaT, REAL8 eta, REAL8 *lambda1, REAL8 *lambda2)
Convert from lambdaT, dLambdaT, and eta to lambda1 and lambda2.
void LALInferenceCopyVariables(LALInferenceVariables *origin, LALInferenceVariables *target)
Deep copy the variables from one to another LALInferenceVariables structure.
Definition: LALInference.c:558
void * LALInferenceGetVariable(const LALInferenceVariables *vars, const char *name)
Return a pointer to the memory the variable vars is stored in specified by name User must cast this p...
Definition: LALInference.c:238
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void LALInferenceSDGammasMasses2Lambdas(REAL8 gamma[], REAL8 mass1, REAL8 mass2, REAL8 *lambda1, REAL8 *lambda2, int size)
Convert from spectral parameters to lambda1, lambda2.
void LALInferenceParseCharacterOptionString(char *input, char **strings[], UINT4 *n)
parses a character string (passed as one of the options) and decomposes it into individual parameter ...
#define DETNAMELEN
Definition: LALInference.h:617
void LALInferenceSortVariablesByName(LALInferenceVariables *vars)
Sorts the variable structure by name.
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars returns 1(==true) or 0.
Definition: LALInference.c:525
@ LALINFERENCE_PARAM_OUTPUT
A parameter that never changes, functions should respect this.
Definition: LALInference.h:131
@ LALINFERENCE_PARAM_FIXED
A parameter that is cyclic, such as an angle between 0 and 2pi.
Definition: LALInference.h:130
@ LALINFERENCE_REAL8_t
Definition: LALInference.h:109
@ LALINFERENCE_INT4_t
Definition: LALInference.h:105
@ LALINFERENCE_UINT4_t
Definition: LALInference.h:107
REAL8 LALInferenceNullLogLikelihood(LALInferenceIFOData *data)
Identical to LALInferenceFreqDomainNullLogLikelihood, but returns the likelihood of a null template.
void LALInferenceInjectionToVariables(SimInspiralTable *theEventTable, LALInferenceVariables *vars)
Fill the variables passed in vars with the parameters of the injection passed in event will over-writ...
void LALInferenceSetupROQmodel(LALInferenceModel *model, ProcessParamsTable *commandLine)
void LALInferenceSetupROQdata(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
void LALInferenceInjectFromMDC(ProcessParamsTable *commandLine, LALInferenceIFOData *IFOdata)
LALInferenceVariables * LALInferencePrintInjectionSample(LALInferenceRunState *runState)
Function to output a sample with logL values etc for the injection, if one is made.
LALInferenceIFOData * LALInferenceReadData(ProcessParamsTable *commandLine)
Read IFO data according to command line arguments.
int LALInferenceRemoveLinesChiSquared(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan, REAL8 *pvalues)
Determine non-Gaussian frequency bins using a chi-squared test.
int LALInferenceXCorrBands(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan, REAL8 *pvalues, char *filename)
Determine correlated frequency bands using cross correlation.
int LALInferenceRemoveLinesPowerLaw(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan, REAL8 *pvalues)
Determine large amplitude frequency bins using power law fit.
int LALInferenceAverageSpectrumBinFit(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan, char *filename, LIGOTimeGPS GPStime)
Calculate PSD by fitting bins to lines.
int LALInferenceRemoveLinesKS(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan, REAL8 *pvalues)
Determine non-Gaussian frequency bins using a K-S test.
void * XLALMalloc(size_t n)
void * XLALCalloc(size_t m, size_t n)
void * XLALRealloc(void *p, size_t n)
void XLALFree(void *p)
void LALAdvLIGOPsd(LALStatus UNUSED *status, REAL8 *psd, REAL8 f)
void LALGEOPsd(LALStatus UNUSED *status, REAL8 *psd, REAL8 f)
void LALEGOPsd(LALStatus UNUSED *status, REAL8 *psd, REAL8 f)
void LALLIGOIPsd(LALStatus UNUSED *status, REAL8 *psd, REAL8 f)
void LALVIRGOPsd(LALStatus *status, REAL8 *shf, REAL8 x)
int XLALSimInspiralChooseFDWaveform(COMPLEX16FrequencySeries **hptilde, COMPLEX16FrequencySeries **hctilde, const REAL8 m1, const REAL8 m2, const REAL8 S1x, const REAL8 S1y, const REAL8 S1z, const REAL8 S2x, const REAL8 S2y, const REAL8 S2z, const REAL8 distance, const REAL8 inclination, const REAL8 phiRef, const REAL8 longAscNodes, const REAL8 eccentricity, const REAL8 UNUSED meanPerAno, const REAL8 deltaF, const REAL8 f_min, const REAL8 f_max, REAL8 f_ref, LALDict *params, const Approximant approximant)
int XLALSimInspiralChooseTDWaveform(REAL8TimeSeries **hplus, REAL8TimeSeries **hcross, const REAL8 m1, const REAL8 m2, const REAL8 S1x, const REAL8 S1y, const REAL8 S1z, const REAL8 S2x, const REAL8 S2y, const REAL8 S2z, const REAL8 distance, const REAL8 inclination, const REAL8 phiRef, const REAL8 longAscNodes, const REAL8 eccentricity, const REAL8 UNUSED meanPerAno, const REAL8 deltaT, const REAL8 f_min, REAL8 f_ref, LALDict *params, const Approximant approximant)
#define LAL_SIM_INSPIRAL_FRAME_AXIS_DEFAULT
LALSimInspiralSpinOrder
LALSimInspiralFrameAxis
LALSimInspiralTidalOrder
Approximant
LALPNOrder
LAL_SIM_INSPIRAL_SPIN_ORDER_ALL
LAL_SIM_INSPIRAL_FRAME_AXIS_VIEW
LAL_SIM_INSPIRAL_FRAME_AXIS_TOTAL_J
LAL_SIM_INSPIRAL_FRAME_AXIS_ORBITAL_L
LAL_SIM_INSPIRAL_TIDAL_ORDER_ALL
TaylorF2
NumRelNinja2
int XLALSimNoisePSDaLIGODesignSensitivityT1800044(REAL8FrequencySeries *psd, double flow)
int XLALSimNoisePSD(REAL8FrequencySeries *psd, double flow, double(*psdfunc)(double))
double XLALSimNoisePSDAdvVirgo(double f)
double XLALSimNoisePSDiLIGOSRD(double f)
double XLALSimNoisePSDVirgo(double f)
REAL8TimeSeries * XLALSimDetectorStrainREAL8TimeSeries(const REAL8TimeSeries *hplus, const REAL8TimeSeries *hcross, REAL8 right_ascension, REAL8 declination, REAL8 psi, const LALDetector *detector)
int XLALSimAddInjectionREAL8TimeSeries(REAL8TimeSeries *target, REAL8TimeSeries *h, const COMPLEX16FrequencySeries *response)
char char * XLALStringDuplicate(const char *s)
REAL4 XLALNormalDeviate(RandomParams *params)
static const INT4 q
RandomParams * XLALCreateRandomParams(INT4 seed)
void XLALDestroyRandomParams(RandomParams *params)
static const INT4 a
REAL8FFTPlan * XLALCreateReverseREAL8FFTPlan(UINT4 size, int measurelvl)
REAL8FFTPlan * XLALCreateForwardREAL8FFTPlan(UINT4 size, int measurelvl)
int XLALResampleREAL4TimeSeries(REAL4TimeSeries *series, REAL8 dt)
int XLALResampleREAL8TimeSeries(REAL8TimeSeries *series, REAL8 dt)
COMPLEX16Sequence * XLALCreateCOMPLEX16Sequence(size_t length)
REAL8Sequence * XLALCreateREAL8Sequence(size_t length)
REAL8 XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
int XLALREAL8AverageSpectrumWelch(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan)
int XLALREAL8AverageSpectrumMedian(REAL8FrequencySeries *spectrum, const REAL8TimeSeries *tseries, UINT4 seglen, UINT4 stride, const REAL8Window *window, const REAL8FFTPlan *plan)
int XLALREAL8TimeFreqFFT(COMPLEX16FrequencySeries *freq, const REAL8TimeSeries *tser, const REAL8FFTPlan *plan)
int XLALREAL8FreqTimeFFT(REAL8TimeSeries *tser, const COMPLEX16FrequencySeries *freq, const REAL8FFTPlan *plan)
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
REAL8TimeSeries * XLALShrinkREAL8TimeSeries(REAL8TimeSeries *series, size_t first, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
REAL4TimeSeries * XLALCutREAL4TimeSeries(const REAL4TimeSeries *series, size_t first, size_t length)
const LALUnit lalStrainUnit
const LALUnit lalADCCountUnit
const LALUnit lalDimensionlessUnit
REAL8Vector * XLALDDVectorMultiply(REAL8Vector *out, const REAL8Vector *in1, const REAL8Vector *in2)
REAL8Window * XLALCreateTukeyREAL8Window(UINT4 length, REAL8 beta)
#define XLAL_ERROR_VOID(...)
const char * XLALErrorString(int errnum)
#define XLAL_ERROR_NULL(...)
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_TRY(statement, errnum)
int * XLALGetErrnoPtr(void)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EINVAL
XLAL_FAILURE
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
LIGOTimeGPS * XLALGPSAddGPS(LIGOTimeGPS *epoch, const LIGOTimeGPS *dt)
LIGOTimeGPS * XLALINT8NSToGPS(LIGOTimeGPS *epoch, INT8 ns)
int XLALSimInspiralTransformPrecessingWvf2PE(REAL8 *thetaJN, REAL8 *phiJL, REAL8 *theta1, REAL8 *theta2, REAL8 *phi12, REAL8 *chi1, REAL8 *chi2, const REAL8 incl, const REAL8 S1x, const REAL8 S1y, const REAL8 S1z, const REAL8 S2x, const REAL8 S2y, const REAL8 S2z, const REAL8 m1, const REAL8 m2, const REAL8 fRef, const REAL8 phiRef)
start
double fref
LALCache * cache
char * channel
COMPLEX16Sequence * data
COMPLEX16 * data
COMPLEX8Sequence * data
COMPLEX8 * data
LALDetector * site
CHAR * src
CHAR * dsc
CHAR * url
UINT4 length
LALCacheEntry * list
REAL4 response[3][3]
REAL8 location[3]
LALFrDetector frDetector
REAL8 vertexLongitudeRadians
REAL8 vertexLatitudeRadians
REAL4 xArmMidpoint
REAL4 vertexElevation
REAL4 xArmAzimuthRadians
REAL4 yArmMidpoint
CHAR prefix[3]
REAL4 yArmAltitudeRadians
REAL4 yArmAzimuthRadians
REAL4 xArmAltitudeRadians
CHAR name[LALNameLength]
Structure to contain IFO data.
Definition: LALInference.h:625
REAL8TimeSeries * timeData
Detector name.
Definition: LALInference.h:627
LALDetector * detector
integration limits for overlap integral in F-domain
Definition: LALInference.h:651
REAL8FrequencySeries * oneSidedNoisePowerSpectrum
Definition: LALInference.h:643
REAL8 timeshift
Detector responses.
Definition: LALInference.h:638
REAL8FFTPlan * timeToFreqFFTPlan
Padding for the above window.
Definition: LALInference.h:648
struct tagLALInferenceROQData * roq
counts how many time the template has been calculated
Definition: LALInference.h:657
REAL8Window * window
(one-sided Noise Power Spectrum)^{-1/2}
Definition: LALInference.h:646
char name[DETNAMELEN]
Definition: LALInference.h:626
COMPLEX16FrequencySeries * freqData
What is this?
Definition: LALInference.h:639
COMPLEX16FrequencySeries * whiteFreqData
Buffer for frequency domain data.
Definition: LALInference.h:640
REAL8 SNR
The epoch of this observation (the time of the first sample)
Definition: LALInference.h:653
struct tagLALInferenceIFOData * next
ROQ data.
Definition: LALInference.h:659
LIGOTimeGPS epoch
LALDetector structure for where this data came from.
Definition: LALInference.h:652
REAL8FFTPlan * freqToTimeFFTPlan
Definition: LALInference.h:648
REAL8 fLow
FFT plan needed for time/time-and-phase marginalisation.
Definition: LALInference.h:650
REAL8TimeSeries * whiteTimeData
A time series from the detector.
Definition: LALInference.h:628
Structure to constain a model and its parameters.
Definition: LALInference.h:436
REAL8 loglikelihood
Prior value at params
Definition: LALInference.h:443
int roq_flag
ROQ data.
Definition: LALInference.h:464
LALInferenceVariables * params
Definition: LALInference.h:437
struct tagLALInferenceROQModel * roq
The padding of the above window.
Definition: LALInference.h:463
Structure containing inference run state This includes pointers to the function types required to run...
Definition: LALInference.h:592
ProcessParamsTable * commandLine
Definition: LALInference.h:593
struct tagLALInferenceIFOData * data
Log sample, i.e.
Definition: LALInference.h:601
LALInferencePriorFunction prior
The algorithm's single iteration function.
Definition: LALInference.h:597
LALInferenceLikelihoodFunction likelihood
MultiNest prior for the parameters.
Definition: LALInference.h:599
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
Definition: LALInference.h:170
INT4 gpsNanoSeconds
REAL4Vector * ppn
CHAR value[LIGOMETA_VALUE_MAX]
REAL4Sequence * data
LIGOTimeGPS epoch
REAL4 * data
REAL8Sequence * data
REAL8Sequence * data
LIGOTimeGPS epoch
REAL8 * data
REAL8Sequence * data
REAL8 sumofsquares
struct tagSimBurst * next
LIGOTimeGPS time_geocent_gps
LIGOTimeGPS geocent_end_time
struct tagSimInspiralTable * next
CHAR waveform[LIGOMETA_WAVEFORM_MAX]
CHAR numrel_data[LIGOMETA_STRING_MAX]
enum @1 epoch
double f_min
double f_max
char * outfile