LALInference  4.1.6.1-89842e6
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 
83 struct fvec {
86 };
87 
88 #define LALINFERENCE_DEFAULT_FLOW "20.0"
89 
90 static void LALInferenceSetGPSTrigtime(LIGOTimeGPS *GPStrig, ProcessParamsTable *commandLine);
91 struct fvec *interpFromFile(char *filename, REAL8 squareinput);
92 
93 struct 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 
135 REAL8 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 
149 void InjectFD(LALInferenceIFOData *IFOdata, SimInspiralTable *inj_table, ProcessParamsTable *commandLine);
151 
152 typedef void (NoiseFunc)(LALStatus *statusPtr,REAL8 *psd,REAL8 f);
153 void MetaNoiseFunc(LALStatus *status, REAL8 *psd, REAL8 f, struct fvec *interp, NoiseFunc *noisefunc);
154 
155 void 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 
175 static const LALUnit strainPerCount={0,{0,0,0,0,0,1,-1},{0,0,0,0,0,0,0}};
176 
177 static REAL8TimeSeries *readTseries(LALCache *cache, CHAR *channel, LIGOTimeGPS start, REAL8 length);
178 static void makeWhiteData(LALInferenceIFOData *IFOdata);
179 static void PrintSNRsToFile(LALInferenceIFOData *IFOdata , char SNRpath[] );
180 
181 
182 static LALCache *GlobFramesPWD( char *ifo);
183 static 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 
225 static 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  */
258 static 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  */
338 static 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);
689 
690  dof=4.0 / M_PI * nSegs; /* Degrees of freedom parameter */
691  sprintf(df_argument_name,"--dof-%s",IFOdata[i].name);
692  if((ppt=LALInferenceGetProcParamVal(commandLine,df_argument_name)))
693  dof=atof(ppt->value);
694 
695  IFOdata[i].STDOF = dof;
696  XLALPrintInfo("Detector %s will run with %g DOF if Student's T likelihood used.\n",
697  IFOdata[i].name, IFOdata[i].STDOF);
698  }
699 
700  /* Only allocate this array if there weren't channels read in from the command line */
701  if(!dataOpts && !Nchannel) channels=XLALCalloc(Nifo,sizeof(char *));
702  for(i=0;i<Nifo;i++) {
703  if(!dataOpts && !Nchannel) channels[i]=XLALMalloc(VARNAME_MAX);
704  IFOdata[i].detector=XLALCalloc(1,sizeof(LALDetector));
705 
706  if(!strcmp(IFOnames[i],"H1")) {
708  if(!Nchannel) sprintf((channels[i]),"H1:%s",strainname); continue;}
709  if(!strcmp(IFOnames[i],"H2")) {
711  if(!Nchannel) sprintf((channels[i]),"H2:%s",strainname); continue;}
712  if(!strcmp(IFOnames[i],"LLO")||!strcmp(IFOnames[i],"L1")) {
714  if(!Nchannel) sprintf((channels[i]),"L1:%s",strainname); continue;}
715  if(!strcmp(IFOnames[i],"V1")||!strcmp(IFOnames[i],"VIRGO")) {
717  if(!Nchannel) sprintf((channels[i]),"V1:h_16384Hz"); continue;}
718  if(!strcmp(IFOnames[i],"GEO")||!strcmp(IFOnames[i],"G1")) {
720  if(!Nchannel) sprintf((channels[i]),"G1:DER_DATA_H"); continue;}
721 
722  if(!strcmp(IFOnames[i],"E1")){
724  if(!Nchannel) sprintf((channels[i]),"E1:STRAIN"); continue;}
725  if(!strcmp(IFOnames[i],"E2")){
727  if(!Nchannel) sprintf((channels[i]),"E2:STRAIN"); continue;}
728  if(!strcmp(IFOnames[i],"E3")){
730  if(!Nchannel) sprintf((channels[i]),"E3:STRAIN"); continue;}
731  if(!strcmp(IFOnames[i],"K1")){
733  if(!Nchannel) sprintf((channels[i]),"K1:STRAIN"); continue;}
734  if(!strcmp(IFOnames[i],"I1")){
736  if(!Nchannel) sprintf((channels[i]),"I1:STRAIN"); continue;}
737  if(!strcmp(IFOnames[i],"A1")||!strcmp(IFOnames[i],"LIGOSouth")){
738  /* Construct a detector at AIGO with 4k arms */
739  LALFrDetector LIGOSouthFr;
740  sprintf(LIGOSouthFr.name,"LIGO-South");
741  sprintf(LIGOSouthFr.prefix,"A1");
742  /* Location of the AIGO detector vertex is */
743  /* 31d21'27.56" S, 115d42'50.34"E */
744  LIGOSouthFr.vertexLatitudeRadians = - (31. + 21./60. + 27.56/3600.)*LAL_PI/180.0;
745  LIGOSouthFr.vertexLongitudeRadians = (115. + 42./60. + 50.34/3600.)*LAL_PI/180.0;
746  LIGOSouthFr.vertexElevation=0.0;
747  LIGOSouthFr.xArmAltitudeRadians=0.0;
748  LIGOSouthFr.xArmAzimuthRadians=AIGOang+LAL_PI/2.;
749  LIGOSouthFr.yArmAltitudeRadians=0.0;
750  LIGOSouthFr.yArmAzimuthRadians=AIGOang;
751  LIGOSouthFr.xArmMidpoint=2000.;
752  LIGOSouthFr.yArmMidpoint=2000.;
753  IFOdata[i].detector=XLALMalloc(sizeof(LALDetector));
754  memset(IFOdata[i].detector,0,sizeof(LALDetector));
755  XLALCreateDetector(IFOdata[i].detector,&LIGOSouthFr,LALDETECTORTYPE_IFODIFF);
756  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]);
757  printf("Detector tensor:\n");
758  for(int jdx=0;jdx<3;jdx++){
759  for(j=0;j<3;j++) printf("%f ",IFOdata[i].detector->response[jdx][j]);
760  printf("\n");
761  }
762  continue;
763  }
764  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);
765  }
766 
767  /* Set up FFT structures and window */
768  for (i=0;i<Nifo;i++){
769  /* Create FFT plans (flag 1 to measure performance) */
770  IFOdata[i].timeToFreqFFTPlan = XLALCreateForwardREAL8FFTPlan((UINT4) seglen, 1 );
771  if(!IFOdata[i].timeToFreqFFTPlan) XLAL_ERROR_NULL(XLAL_ENOMEM);
772  IFOdata[i].freqToTimeFFTPlan = XLALCreateReverseREAL8FFTPlan((UINT4) seglen, 1 );
773  if(!IFOdata[i].freqToTimeFFTPlan) XLAL_ERROR_NULL(XLAL_ENOMEM);
774  IFOdata[i].margFFTPlan = XLALCreateReverseREAL8FFTPlan((UINT4) seglen, 1);
775  if(!IFOdata[i].margFFTPlan) XLAL_ERROR_NULL(XLAL_ENOMEM);
776  /* Setup windows */
777  ppt=LALInferenceGetProcParamVal(commandLine,"--padding");
778  if (ppt){
779  padding=atof(ppt->value);
780  fprintf(stdout,"Using %lf seconds of padding for IFO %s \n",padding, IFOdata[i].name);
781  }
782  if ((REAL8)2.0*padding*SampleRate/(REAL8)seglen <0.0 ||(REAL8)2.0*padding*SampleRate/(REAL8)seglen >1 ){
783  fprintf(stderr,"Padding is negative or 2*padding is bigger than the whole segment. Consider reducing it using --padding or increase --seglen. Exiting\n");
784  exit(1);
785  }
786  IFOdata[i].padding=padding;
787  IFOdata[i].window=XLALCreateTukeyREAL8Window(seglen,(REAL8)2.0*padding*SampleRate/(REAL8)seglen);
788  if(!IFOdata[i].window) XLAL_ERROR_NULL(XLAL_EFUNC);
789  }
790 
791  if(!(ppt=LALInferenceGetProcParamVal(commandLine,"--segment-start")))
792  {
793  /* Trigger time = 2 seconds before end of segment (was 1 second, but Common Inputs for The Events are -6 +2*/
794  memcpy(&segStart,&GPStrig,sizeof(LIGOTimeGPS));
795  REAL8 offset=SegmentLength-2.;
796  /* If we are using a burst approximant, put at the center */
797  if ((ppt=LALInferenceGetProcParamVal(commandLine,"--approx"))){
798  if (XLALCheckBurstApproximantFromString(ppt->value)) offset=SegmentLength/2.;
799  }
800  XLALGPSAdd(&segStart,-offset);
801  }
802  else
803  {
804  /* Segment starts at given time */
805  REAL8 segstartR8 = atof(ppt->value);
806  XLALGPSSetREAL8(&segStart,segstartR8);
807  }
808 
809 
810  /* Read the PSD data */
811  for(i=0;i<Nifo;i++) {
812  memcpy(&(IFOdata[i].epoch),&segStart,sizeof(LIGOTimeGPS));
813  /* Check to see if an interpolation file is specified */
814  interpFlag=0;
815  interp=NULL;
816  if( (globFrames)?0:strstr(caches[i],"interp:")==caches[i]){
817  /* Extract the file name */
818  char *interpfilename=&(caches[i][7]);
819  printf("Looking for ASD interpolation file %s\n",interpfilename);
820  interpFlag=1;
821  asdFlag=1;
822  interp=interpFromFile(interpfilename, asdFlag);
823  }
824  /* Check if fake data is requested */
825  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")))))
826  {
827  if (!LALInferenceGetProcParamVal(commandLine,"--dataseed")){
828  fprintf(stderr,"Error: You need to specify a dataseed when generating data with --dataseed <number>.\n\
829  (--dataseed 0 uses a non-reproducible number from the system clock, and no parallel run is then possible.)\n" );
830  exit(-1);
831  }
832  /* Offset the seed in a way that depends uniquely on the IFO name */
833  int ifo_salt=0;
834  ifo_salt+=(int)IFOnames[i][0]+(int)IFOnames[i][1];
835  datarandparam=XLALCreateRandomParams(dataseed?dataseed+(int)ifo_salt:dataseed);
836  if(!datarandparam) XLAL_ERROR_NULL(XLAL_EFUNC);
837  IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)
838  XLALCreateREAL8FrequencySeries("spectrum",&GPSstart,0.0,
839  (REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
840  if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
841 
842  int LALSimPsd=0;
843  /* Selection of the noise curve */
844  if(!strcmp(caches[i],"LALLIGO")) {PSD = &LALLIGOIPsd; scalefactor=9E-46;}
845  if(!strcmp(caches[i],"LALVirgo")) {PSD = &LALVIRGOPsd; scalefactor=1.0;}
846  if(!strcmp(caches[i],"LALGEO")) {PSD = &LALGEOPsd; scalefactor=1E-46;}
847  if(!strcmp(caches[i],"LALEGO")) {PSD = &LALEGOPsd; scalefactor=1.0;}
848  if(!strcmp(caches[i],"LALAdLIGO")) {PSD = &LALAdvLIGOPsd; scalefactor = 1E-49;}
849  if(!strcmp(caches[i],"LALSimLIGO")) {XLALSimNoisePSD(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow,XLALSimNoisePSDiLIGOSRD ) ; LALSimPsd=1;}
850  if(!strcmp(caches[i],"LALSimVirgo")) {XLALSimNoisePSD(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow,XLALSimNoisePSDVirgo ); LALSimPsd=1;}
851  if(!strcmp(caches[i],"LALSimAdLIGO")) {XLALSimNoisePSDaLIGODesignSensitivityT1800044(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow) ;LALSimPsd=1;}
852  if(!strcmp(caches[i],"LALSimAdVirgo")) {XLALSimNoisePSD(IFOdata[i].oneSidedNoisePowerSpectrum,IFOdata[i].fLow,XLALSimNoisePSDAdvVirgo) ;LALSimPsd=1;}
853  if(interpFlag) {PSD=NULL; scalefactor=1.0;}
854  if(PSD==NULL && !(interpFlag|| LALSimPsd)) {fprintf(stderr,"Error: unknown simulated PSD: %s\n",caches[i]); exit(-1);}
855 
856  if(LALSimPsd==0){
857  for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
858  {
859  MetaNoiseFunc(&status,&(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]),j*IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,interp,PSD);
860  IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]*=scalefactor;
861  }
862  }
863 
864  IFOdata[i].freqData = (COMPLEX16FrequencySeries *)XLALCreateCOMPLEX16FrequencySeries("stilde",&segStart,0.0,IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,&lalDimensionlessUnit,seglen/2 +1);
865  if(!IFOdata[i].freqData) XLAL_ERROR_NULL(XLAL_EFUNC);
866 
867  /* Create the fake data */
868  int j_Lo = (int) IFOdata[i].fLow/IFOdata[i].freqData->deltaF;
869  if(LALInferenceGetProcParamVal(commandLine,"--0noise")){
870  for(j=j_Lo;j<IFOdata[i].freqData->data->length;j++){
871  IFOdata[i].freqData->data->data[j] = 0.0;
872  }
873  } else {
874  for(j=j_Lo;j<IFOdata[i].freqData->data->length;j++){
875  IFOdata[i].freqData->data->data[j] = crect(
876  XLALNormalDeviate(datarandparam)*(0.5*sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]/IFOdata[i].freqData->deltaF)),
877  XLALNormalDeviate(datarandparam)*(0.5*sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]/IFOdata[i].freqData->deltaF))
878  );
879  }
880  }
881  IFOdata[i].freqData->data->data[0] = 0;
882  const char timename[]="timeData";
883  IFOdata[i].timeData=(REAL8TimeSeries *)XLALCreateREAL8TimeSeries(timename,&segStart,0.0,(REAL8)1.0/SampleRate,&lalDimensionlessUnit,(size_t)seglen);
884  if(!IFOdata[i].timeData) XLAL_ERROR_NULL(XLAL_EFUNC);
885  XLALREAL8FreqTimeFFT(IFOdata[i].timeData,IFOdata[i].freqData,IFOdata[i].freqToTimeFFTPlan);
886  if(*XLALGetErrnoPtr()) printf("XLErr: %s\n",XLALErrorString(*XLALGetErrnoPtr()));
887  XLALDestroyRandomParams(datarandparam);
888  }
889  else{ /* Not using fake data, load the data from a cache file */
890 
891  LALCache *cache=NULL;
892  if(!globFrames)
893  {
894  cache = XLALCacheImport( caches[i] );
895  int err;
896  err = *XLALGetErrnoPtr();
897  if(cache==NULL) {fprintf(stderr,"ERROR: Unable to import cache file \"%s\",\n XLALError: \"%s\".\n",caches[i], XLALErrorString(err)); exit(-1);}
898  }
899  else
900  {
901  printf("Looking for frames for %s in PWD\n",IFOnames[i]);
902  cache= GlobFramesPWD(IFOnames[i]);
903 
904  }
905  if(!cache) {fprintf(stderr,"ERROR: Cannot find any frame data!\n"); exit(1);}
906  if ((!((psds[i])==NULL)) && (!((asds[i])==NULL))) {fprintf(stderr,"ERROR: Cannot provide both ASD and PSD file from command line!\n"); exit(1);}
907  if (!((asds)==NULL || (asds[i])==NULL)){
908  interp=NULL;
909  asdFlag=1;
910  char *interpfilename=&(asds[i][0]);
911  fprintf(stderr,"Reading ASD for %s using %s\n",IFOnames[i],interpfilename);
912  printf("Looking for ASD file %s for PSD interpolation\n",interpfilename);
913  interp=interpFromFile(interpfilename, asdFlag);
914  IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)
915  XLALCreateREAL8FrequencySeries("spectrum",&GPSstart,0.0,
916  (REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
917  if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
918  for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
919  {
920  MetaNoiseFunc(&status,&(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]),j*IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,interp,NULL);
921  //fprintf(stdout,"%lf\n",IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
922  }
923  }else if(!((psds)==NULL || (psds[i])==NULL)){
924  interp=NULL;
925  asdFlag=0;
926  char *interpfilename=&(psds[i][0]);
927  fprintf(stderr,"Reading PSD for %s using %s\n",IFOnames[i],interpfilename);
928  printf("Looking for PSD file %s for PSD interpolation\n",interpfilename);
929  interp=interpFromFile(interpfilename, asdFlag);
930  IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)
931  XLALCreateREAL8FrequencySeries("spectrum",&GPSstart,0.0,
932  (REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
933  if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
934  for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
935  {
936  MetaNoiseFunc(&status,&(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]),j*IFOdata[i].oneSidedNoisePowerSpectrum->deltaF,interp,NULL);
937  //fprintf(stdout,"%lf\n",IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
938  }
939  }else{
940  /* Make sure required PSD arguments were provided */
941  if(!LALInferenceGetProcParamVal(commandLine,"--psdstart") ||
942  !LALInferenceGetProcParamVal(commandLine,"--psdlength"))
943  {fprintf(stderr,USAGE); return(NULL);}
944 
945  fprintf(stderr,"Estimating PSD for %s using %i segments of %i samples (%lfs)\n",IFOnames[i],nSegs,(int)seglen,SegmentLength);
946  LIGOTimeGPS trueGPSstart=GPSstart;
947  if(Ntimeslides) {
948  REAL4 deltaT=-atof(timeslides[i]);
949  XLALGPSAdd(&GPSstart, deltaT);
950  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);
951  }
952  PSDtimeSeries=readTseries(cache,channels[i],GPSstart,PSDdatalength);
953  GPSstart=trueGPSstart;
954  if(!PSDtimeSeries) {XLALPrintError("Error reading PSD data for %s\n",IFOnames[i]); exit(1);}
955  XLALResampleREAL8TimeSeries(PSDtimeSeries,1.0/SampleRate);
956  PSDtimeSeries=(REAL8TimeSeries *)XLALShrinkREAL8TimeSeries(PSDtimeSeries,(size_t) 0, (size_t) seglen*nSegs);
957  if(!PSDtimeSeries) {
958  fprintf(stderr,"ERROR while estimating PSD for %s\n",IFOnames[i]);
960  }
961  IFOdata[i].oneSidedNoisePowerSpectrum=(REAL8FrequencySeries *)XLALCreateREAL8FrequencySeries("spectrum",&PSDtimeSeries->epoch,0.0,(REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
962  if(!IFOdata[i].oneSidedNoisePowerSpectrum) XLAL_ERROR_NULL(XLAL_EFUNC);
963  if (LALInferenceGetProcParamVal(commandLine, "--PSDwelch"))
964  XLALREAL8AverageSpectrumWelch(IFOdata[i].oneSidedNoisePowerSpectrum ,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan);
965  else
966  XLALREAL8AverageSpectrumMedian(IFOdata[i].oneSidedNoisePowerSpectrum ,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan);
967 
968  if(LALInferenceGetProcParamVal(commandLine, "--binFit")) {
969 
970  LIGOTimeGPS GPStime=segStart;
971 
972  const UINT4 nameLength=256;
973  char filename[nameLength];
974 
975  snprintf(filename, nameLength, "%s-BinFitLines.dat", IFOdata[i].name);
976 
977  printf("Running PSD bin fitting... ");
978  LALInferenceAverageSpectrumBinFit(IFOdata[i].oneSidedNoisePowerSpectrum ,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,filename,GPStime);
979  printf("completed!\n");
980  }
981 
982  if (LALInferenceGetProcParamVal(commandLine, "--chisquaredlines")){
983 
984  double deltaF = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF;
985  int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
986 
987  REAL8 *pvalues;
988  pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
989 
990  printf("Running chi-squared tests... ");
991  LALInferenceRemoveLinesChiSquared(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues);
992  printf("completed!\n");
993 
994  const UINT4 nameLength=256;
995  char filename[nameLength];
996  FILE *out;
997 
998  double lines_width;
999  ppt = LALInferenceGetProcParamVal(commandLine, "--chisquaredlinesWidth");
1000  if(ppt) lines_width = atof(ppt->value);
1001  else lines_width = deltaF;
1002 
1003  double lines_threshold;
1004  ppt = LALInferenceGetProcParamVal(commandLine, "--chisquaredlinesThreshold");
1005  if(ppt) lines_threshold = atof(ppt->value);
1006  else lines_threshold = 2*pow(10.0,-14.0);
1007 
1008  printf("Using chi squared threshold of %g\n",lines_threshold);
1009 
1010  snprintf(filename, nameLength, "%s-ChiSquaredLines.dat", IFOdata[i].name);
1011  out = fopen(filename, "w");
1012  for (int k = 0; k < lengthF; ++k ) {
1013  if (pvalues[k] < lines_threshold) {
1014  fprintf(out,"%g %g\n",((double) k) * deltaF,lines_width);
1015  }
1016  }
1017  fclose(out);
1018 
1019  snprintf(filename, nameLength, "%s-ChiSquaredLines-pvalues.dat", IFOdata[i].name);
1020  out = fopen(filename, "w");
1021  for (int k = 0; k < lengthF; ++k ) {
1022  fprintf(out,"%g %g\n",((double) k) * deltaF,pvalues[k]);
1023  }
1024  fclose(out);
1025 
1026  }
1027 
1028  if (LALInferenceGetProcParamVal(commandLine, "--KSlines")){
1029 
1030  double deltaF = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF;
1031  int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
1032 
1033  REAL8 *pvalues;
1034  pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
1035 
1036  printf("Running KS tests... ");
1037  LALInferenceRemoveLinesKS(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues);
1038  printf("completed!\n");
1039 
1040  const UINT4 nameLength=256;
1041  char filename[nameLength];
1042  FILE *out;
1043 
1044  double lines_width;
1045  ppt = LALInferenceGetProcParamVal(commandLine, "--KSlinesWidth");
1046  if(ppt) lines_width = atof(ppt->value);
1047  else lines_width = deltaF;
1048 
1049  double lines_threshold;
1050  ppt = LALInferenceGetProcParamVal(commandLine, "--KSlinesThreshold");
1051  if(ppt) lines_threshold = atof(ppt->value);
1052  else lines_threshold = 0.134558;
1053 
1054  printf("Using KS threshold of %g\n",lines_threshold);
1055 
1056  snprintf(filename, nameLength, "%s-KSLines.dat", IFOdata[i].name);
1057  out = fopen(filename, "w");
1058  for (int k = 0; k < lengthF; ++k ) {
1059  if (pvalues[k] < lines_threshold) {
1060  fprintf(out,"%g %g\n",((double) k) * deltaF,lines_width);
1061  }
1062  }
1063  fclose(out);
1064 
1065  snprintf(filename, nameLength, "%s-KSLines-pvalues.dat", IFOdata[i].name);
1066  out = fopen(filename, "w");
1067  for (int k = 0; k < lengthF; ++k ) {
1068  fprintf(out,"%g %g\n",((double) k) * deltaF,pvalues[k]);
1069  }
1070  fclose(out);
1071 
1072  }
1073 
1074  if (LALInferenceGetProcParamVal(commandLine, "--powerlawlines")){
1075 
1076  double deltaF = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF;
1077  int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
1078 
1079  REAL8 *pvalues;
1080  pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
1081 
1082  printf("Running power law tests... ");
1083  LALInferenceRemoveLinesPowerLaw(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues);
1084  printf("completed!\n");
1085 
1086  const UINT4 nameLength=256;
1087  char filename[nameLength];
1088  FILE *out;
1089 
1090  double lines_width;
1091  ppt = LALInferenceGetProcParamVal(commandLine, "--powerlawlinesWidth");
1092  if(ppt) lines_width = atof(ppt->value);
1093  else lines_width = deltaF;
1094 
1095  double lines_threshold;
1096  ppt = LALInferenceGetProcParamVal(commandLine, "--powerlawlinesThreshold");
1097  if(ppt) lines_threshold = atof(ppt->value);
1098  else lines_threshold = 0.7197370;
1099 
1100  printf("Using power law threshold of %g\n",lines_threshold);
1101 
1102  snprintf(filename, nameLength, "%s-PowerLawLines.dat", IFOdata[i].name);
1103  out = fopen(filename, "w");
1104  for (int k = 0; k < lengthF; ++k ) {
1105  if (pvalues[k] < lines_threshold) {
1106  fprintf(out,"%g %g\n",((double) k) * deltaF,lines_width);
1107  }
1108  }
1109  fclose(out);
1110 
1111  snprintf(filename, nameLength, "%s-PowerLawLines-pvalues.dat", IFOdata[i].name);
1112  out = fopen(filename, "w");
1113  for (int k = 0; k < lengthF; ++k ) {
1114  fprintf(out,"%g %g\n",((double) k) * deltaF,pvalues[k]);
1115  }
1116  fclose(out);
1117 
1118  }
1119 
1120  if (LALInferenceGetProcParamVal(commandLine, "--xcorrbands")){
1121 
1122  int lengthF = IFOdata[i].oneSidedNoisePowerSpectrum->data->length;
1123 
1124  REAL8 *pvalues;
1125  pvalues = XLALMalloc( lengthF * sizeof( *pvalues ) );
1126 
1127  const UINT4 nameLength=256;
1128  char filename[nameLength];
1129  FILE *out;
1130 
1131  snprintf(filename, nameLength, "%s-XCorrVals.dat", IFOdata[i].name);
1132 
1133  printf("Running xcorr tests... ");
1134  LALInferenceXCorrBands(IFOdata[i].oneSidedNoisePowerSpectrum,PSDtimeSeries, seglen, (UINT4)seglen, IFOdata[i].window, IFOdata[i].timeToFreqFFTPlan,pvalues,filename);
1135  printf("completed!\n");
1136 
1137  snprintf(filename, nameLength, "%s-XCorrBands.dat", IFOdata[i].name);
1138  out = fopen(filename, "w");
1139  fprintf(out,"%g %g\n",10.0,75.0);
1140  fprintf(out,"%g %g\n",16.0,40.0);
1141  fprintf(out,"%g %g\n",40.0,330.0);
1142  fclose(out);
1143 
1144  }
1145 
1146  XLALDestroyREAL8TimeSeries(PSDtimeSeries);
1147  }
1148 
1149  /* Read the data segment */
1150  LIGOTimeGPS truesegstart=segStart;
1151  if(Ntimeslides) {
1152  REAL4 deltaT=-atof(timeslides[i]);
1153  XLALGPSAdd(&segStart, deltaT);
1154  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);
1155  }
1156  IFOdata[i].timeData=readTseries(cache,channels[i],segStart,SegmentLength);
1157  segStart=truesegstart;
1158  if(Ntimeslides) IFOdata[i].timeData->epoch=truesegstart;
1159 
1160  if(!IFOdata[i].timeData) {
1161  XLALPrintError("Error reading segment data for %s at %i\n",IFOnames[i],segStart.gpsSeconds);
1163  }
1164  XLALResampleREAL8TimeSeries(IFOdata[i].timeData,1.0/SampleRate);
1165  if(!IFOdata[i].timeData) {XLALPrintError("Error reading segment data for %s\n",IFOnames[i]); XLAL_ERROR_NULL(XLAL_EFUNC);}
1166  IFOdata[i].freqData=(COMPLEX16FrequencySeries *)XLALCreateCOMPLEX16FrequencySeries("freqData",&(IFOdata[i].timeData->epoch),0.0,1.0/SegmentLength,&lalDimensionlessUnit,seglen/2+1);
1167  if(!IFOdata[i].freqData) XLAL_ERROR_NULL(XLAL_EFUNC);
1168  IFOdata[i].windowedTimeData=(REAL8TimeSeries *)XLALCreateREAL8TimeSeries("windowed time data",&(IFOdata[i].timeData->epoch),0.0,1.0/SampleRate,&lalDimensionlessUnit,seglen);
1169  if(!IFOdata[i].windowedTimeData) XLAL_ERROR_NULL(XLAL_EFUNC);
1170  XLALDDVectorMultiply(IFOdata[i].windowedTimeData->data,IFOdata[i].timeData->data,IFOdata[i].window->data);
1171  XLALREAL8TimeFreqFFT(IFOdata[i].freqData,IFOdata[i].windowedTimeData,IFOdata[i].timeToFreqFFTPlan);
1172 
1173  for(j=0;j<IFOdata[i].freqData->data->length;j++){
1174  IFOdata[i].freqData->data->data[j] /= sqrt(IFOdata[i].window->sumofsquares / IFOdata[i].window->data->length);
1175  IFOdata[i].windowedTimeData->data->data[j] /= sqrt(IFOdata[i].window->sumofsquares / IFOdata[i].window->data->length);
1176  }
1177 
1178  XLALDestroyCache(cache); // Clean up cache
1179  } /* End of data reading process */
1180 
1181  makeWhiteData(&(IFOdata[i]));
1182 
1183  /* Store ASD of noise spectrum to whiten glitch model */
1184  IFOdata[i].noiseASD=(REAL8FrequencySeries *)XLALCreateREAL8FrequencySeries("asd",&GPSstart,0.0,(REAL8)(SampleRate)/seglen,&lalDimensionlessUnit,seglen/2 +1);
1185  for(j=0;j<IFOdata[i].oneSidedNoisePowerSpectrum->data->length;j++)
1186  IFOdata[i].noiseASD->data->data[j]=sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
1187  /* Save to file the PSDs so that they can be used in the PP pages */
1188  const UINT4 nameLength=FILENAME_MAX+100;
1189  char filename[nameLength];
1190  FILE *out;
1191  ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
1192  if (!ppt){
1193  ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1194  if(ppt) {
1195  snprintf(filename, nameLength, "%s%s-PSD.dat", ppt->value, IFOdata[i].name);
1196  }
1197  else
1198  snprintf(filename, nameLength, "%.3f_%s-PSD.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1199 
1200  out = fopen(filename, "w");
1201  if(!out){
1202  fprintf(stderr,"Unable to open the path %s for writing PSD files\n",filename);
1203  exit(1);
1204  }
1205  for (j = 0; j < IFOdata[i].oneSidedNoisePowerSpectrum->data->length; j++) {
1206  REAL8 f = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF*j;
1207  REAL8 psd = IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j];
1208 
1209  fprintf(out, "%10.10g %10.10g\n", f, psd);
1210  }
1211  fclose(out);
1212  }
1213  if (LALInferenceGetProcParamVal(commandLine, "--data-dump")) {
1214  //pptdatadump=LALInferenceGetProcParamVal(commandLine,"--data-dump");
1215 
1216  ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1217 
1218  if(ppt) {
1219  snprintf(filename, nameLength, "%s%s-timeData.dat", ppt->value, IFOdata[i].name);
1220  }
1221  //else if(strcmp(pptdatadump->value,"")) {
1222  // snprintf(filename, nameLength, "%s/%s-timeData.dat", pptdatadump->value, IFOdata[i].name);
1223  //}
1224  else
1225  snprintf(filename, nameLength, "%.3f_%s-timeData.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1226  out = fopen(filename, "w");
1227  if(!out){
1228  fprintf(stderr,"Unable to open the path %s for writing time data files\n",filename);
1229  exit(1);
1230  }
1231  for (j = 0; j < IFOdata[i].timeData->data->length; j++) {
1232  REAL8 t = XLALGPSGetREAL8(&(IFOdata[i].timeData->epoch)) +
1233  j * IFOdata[i].timeData->deltaT;
1234  REAL8 d = IFOdata[i].timeData->data->data[j];
1235 
1236  fprintf(out, "%.6f %g\n", t, d);
1237  }
1238  fclose(out);
1239 
1240  ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1241  if(ppt) {
1242  snprintf(filename, nameLength, "%s%s-freqData.dat", ppt->value, IFOdata[i].name);
1243  }
1244  //else if(strcmp(pptdatadump->value,"")) {
1245  // snprintf(filename, nameLength, "%s/%s-freqData.dat", pptdatadump->value, IFOdata[i].name);
1246  //}
1247  else
1248  snprintf(filename, nameLength, "%.3f_%s-freqData.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1249  out = fopen(filename, "w");
1250  if(!out){
1251  fprintf(stderr,"Unable to open the path %s for writing freq data files\n",filename);
1252  exit(1);
1253  }
1254  for (j = 0; j < IFOdata[i].freqData->data->length; j++) {
1255  REAL8 f = IFOdata[i].freqData->deltaF * j;
1256  REAL8 dre = creal(IFOdata[i].freqData->data->data[j]);
1257  REAL8 dim = cimag(IFOdata[i].freqData->data->data[j]);
1258 
1259  fprintf(out, "%10.10g %10.10g %10.10g\n", f, dre, dim);
1260  }
1261  fclose(out);
1262 
1263  ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
1264  if(ppt) {
1265  snprintf(filename, nameLength, "%s%s-ASD.dat", ppt->value, IFOdata[i].name);
1266  }
1267  else
1268  snprintf(filename, nameLength, "%.3f_%s-ASD.dat",GPStrig.gpsSeconds+1e-9*GPStrig.gpsNanoSeconds, IFOdata[i].name);
1269  out = fopen(filename, "w");
1270  if(!out){
1271  fprintf(stderr,"Unable to open the path %s for writing freq ASD files\n",filename);
1272  exit(1);
1273  }
1274  for (j = 0; j < IFOdata[i].oneSidedNoisePowerSpectrum->data->length; j++) {
1275  REAL8 f = IFOdata[i].oneSidedNoisePowerSpectrum->deltaF*j;
1276  REAL8 asd = sqrt(IFOdata[i].oneSidedNoisePowerSpectrum->data->data[j]);
1277 
1278  fprintf(out, "%10.10g %10.10g\n", f, asd);
1279  }
1280  fclose(out);
1281 
1282  }
1283  }
1284 
1285  for (i=0;i<Nifo;i++) IFOdata[i].SNR=0.0; //SNR of the injection ONLY IF INJECTION. Set to 0.0 by default.
1286 
1287  for (i=0;i<Nifo-1;i++) IFOdata[i].next=&(IFOdata[i+1]);
1288 
1289  for(i=0;i<Nifo;i++) {
1290  if(channels) if(channels[i]) XLALFree(channels[i]);
1291  if(caches) if(caches[i]) XLALFree(caches[i]);
1292  if(IFOnames) if(IFOnames[i]) XLALFree(IFOnames[i]);
1293  if(fLows) if(fLows[i]) XLALFree(fLows[i]);
1294  if(fHighs) if(fHighs[i]) XLALFree(fHighs[i]);
1295  }
1296  if(channels) XLALFree(channels);
1297  if(caches) XLALFree(caches);
1298  if(IFOnames) XLALFree(IFOnames);
1299  if(fLows) XLALFree(fLows);
1300  if(fHighs) XLALFree(fHighs);
1301 
1302  if (LALInferenceGetProcParamVal(commandLine, "--roqtime_steps")){
1303 
1304  LALInferenceSetupROQdata(IFOdata, commandLine);
1305  fprintf(stderr, "done LALInferenceSetupROQdata\n");
1306 
1307  }
1308 
1309 
1310  return headIFO;
1311 }
1312 
1313 static void makeWhiteData(LALInferenceIFOData *IFOdata) {
1314  REAL8 deltaF = IFOdata->freqData->deltaF;
1315  REAL8 deltaT = IFOdata->timeData->deltaT;
1316 
1317  IFOdata->whiteFreqData =
1318  XLALCreateCOMPLEX16FrequencySeries("whitened frequency data",
1319  &(IFOdata->freqData->epoch),
1320  0.0,
1321  deltaF,
1323  IFOdata->freqData->data->length);
1324  if(!IFOdata->whiteFreqData) XLAL_ERROR_VOID(XLAL_EFUNC);
1325  IFOdata->whiteTimeData =
1326  XLALCreateREAL8TimeSeries("whitened time data",
1327  &(IFOdata->timeData->epoch),
1328  0.0,
1329  deltaT,
1331  IFOdata->timeData->data->length);
1332  if(!IFOdata->whiteTimeData) XLAL_ERROR_VOID(XLAL_EFUNC);
1333 
1334  REAL8 iLow = IFOdata->fLow / deltaF;
1335  REAL8 iHighDefaultCut = 0.95 * IFOdata->freqData->data->length;
1336  REAL8 iHighFromFHigh = IFOdata->fHigh / deltaF;
1337  REAL8 iHigh = (iHighDefaultCut < iHighFromFHigh ? iHighDefaultCut : iHighFromFHigh);
1338  REAL8 windowSquareSum = 0.0;
1339 
1340  UINT4 i;
1341 
1342  for (i = 0; i < IFOdata->freqData->data->length; i++) {
1343  IFOdata->whiteFreqData->data->data[i] = IFOdata->freqData->data->data[i] / IFOdata->oneSidedNoisePowerSpectrum->data->data[i];
1344 
1345  if (i == 0) {
1346  /* Cut off the average trend in the data. */
1347  IFOdata->whiteFreqData->data->data[i] = 0.0;
1348  }
1349  if (i <= iLow) {
1350  /* Need to taper to implement the fLow cutoff. Tukey window
1351  that starts at zero, and reaches 100% at fLow. */
1352  REAL8 weight = 0.5*(1.0 + cos(M_PI*(i-iLow)/iLow)); /* Starts at -Pi, runs to zero at iLow. */
1353 
1354  IFOdata->whiteFreqData->data->data[i] *= weight;
1355 
1356  windowSquareSum += weight*weight;
1357  } else if (i >= iHigh) {
1358  /* Also taper at high freq end, Tukey window that starts at 100%
1359  at fHigh, then drops to zero at Nyquist. Except that we
1360  always taper at least 5% of the data at high freq to avoid a
1361  sharp edge in freq space there. */
1362  REAL8 NWind = IFOdata->whiteFreqData->data->length - iHigh;
1363  REAL8 weight = 0.5*(1.0 + cos(M_PI*(i-iHigh)/NWind)); /* Starts at 0, runs to Pi at i = length */
1364 
1365  IFOdata->whiteFreqData->data->data[i] *= weight;
1366 
1367  windowSquareSum += weight*weight;
1368  } else {
1369  windowSquareSum += 1.0;
1370  }
1371  }
1372 
1373  REAL8 norm = sqrt(IFOdata->whiteFreqData->data->length / windowSquareSum);
1374  for (i = 0; i < IFOdata->whiteFreqData->data->length; i++) {
1375  IFOdata->whiteFreqData->data->data[i] *= norm;
1376  }
1377 
1378  XLALREAL8FreqTimeFFT(IFOdata->whiteTimeData, IFOdata->whiteFreqData, IFOdata->freqToTimeFFTPlan);
1379 }
1380 
1382 {
1383  LALStatus status;
1384  memset(&status,0,sizeof(status));
1385  SimInspiralTable *injTable=NULL;
1386  SimInspiralTable *injEvent=NULL;
1387  UINT4 event=0;
1388  UINT4 i=0,j=0;
1389  REAL8 responseScale=1.0;
1390  LIGOTimeGPS injstart;
1391  REAL8 SNR=0,NetworkSNR=0;
1392  DetectorResponse det;
1393  memset(&injstart,0,sizeof(LIGOTimeGPS));
1394  COMPLEX16FrequencySeries *injF=NULL;
1395  FILE *rawWaveform=NULL;
1396  ProcessParamsTable *ppt=NULL;
1397  REAL8 bufferLength = 2048.0; /* Default length of buffer for injections (seconds) */
1398  UINT4 bufferN=0;
1399  LIGOTimeGPS bufferStart;
1400 
1401  LALInferenceIFOData *thisData=IFOdata->next;
1402  REAL8 minFlow=IFOdata->fLow;
1403  REAL8 MindeltaT=IFOdata->timeData->deltaT;
1404  REAL8 InjSampleRate=1.0/MindeltaT;
1405  REAL4TimeSeries *injectionBuffer=NULL;
1406  REAL8 padding=0.4; //default, set in LALInferenceReadData()
1407  char SNRpath[FILENAME_MAX+50]="";
1408  int flipped_masses=0;
1409 
1410  while(thisData){
1411  minFlow = minFlow>thisData->fLow ? thisData->fLow : minFlow;
1412  MindeltaT = MindeltaT>thisData->timeData->deltaT ? thisData->timeData->deltaT : MindeltaT;
1413  thisData = thisData->next;
1414  }
1415  thisData=IFOdata;
1416 
1417  if(!LALInferenceGetProcParamVal(commandLine,"--inj")) {fprintf(stdout,"No injection file specified, not injecting\n"); return;}
1418  if(LALInferenceGetProcParamVal(commandLine,"--event")){
1419  event= atoi(LALInferenceGetProcParamVal(commandLine,"--event")->value);
1420  fprintf(stdout,"Injecting event %d\n",event);
1421  }
1422 
1423  ppt = LALInferenceGetProcParamVal(commandLine,"--outfile");
1424  if (ppt)
1425  sprintf(SNRpath, "%s_snr.txt", ppt->value);
1426  else
1427  sprintf(SNRpath, "snr.txt");
1428 
1429  injTable=XLALSimInspiralTableFromLIGOLw(LALInferenceGetProcParamVal(commandLine,"--inj")->value);
1430  if(!injTable){
1431  fprintf(stderr,"Error reading event %d from %s\n",event,LALInferenceGetProcParamVal(commandLine,"--inj")->value);
1432  exit(1);
1433  }
1434  while(i<event) {i++; injTable = injTable->next;} /* Select event */
1435  injEvent = injTable;
1436  injEvent->next = NULL;
1437  Approximant injapprox;
1438  injapprox = XLALGetApproximantFromString(injTable->waveform);
1439  if( (int) injapprox == XLAL_FAILURE)
1440  ABORTXLAL(&status);
1441  printf("Injecting approximant %i: %s\n", injapprox, injTable->waveform);
1442  REPORTSTATUS(&status);
1443 
1444  /* Check for frequency domain injection. All aproximants supported by XLALSimInspiralImplementedFDApproximants will work.
1445  * 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! */
1447  {
1448  InjectFD(IFOdata, injTable, commandLine);
1449  LALInferencePrintDataWithInjection(IFOdata,commandLine);
1450  return;
1451  }
1452  flipped_masses = enforce_m1_larger_m2(injEvent);
1453  /* Begin loop over interferometers */
1454  while(thisData){
1455  Approximant approximant; /* Get approximant value */
1457  if( (int) approximant == XLAL_FAILURE)
1458  ABORTXLAL(&status);
1459 
1460  InjSampleRate=1.0/thisData->timeData->deltaT;
1461  if(LALInferenceGetProcParamVal(commandLine,"--injectionsrate")) InjSampleRate=atof(LALInferenceGetProcParamVal(commandLine,"--injectionsrate")->value);
1462  if(approximant == NumRelNinja2 && InjSampleRate != 16384) {
1463  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);
1464  InjSampleRate = 16384;
1465  }
1466 
1467  memset(&det,0,sizeof(det));
1468  det.site=thisData->detector;
1470  0.0,
1471  thisData->freqData->deltaF,
1472  &strainPerCount,
1473  thisData->freqData->data->length);
1474 
1475  for(i=0;i<resp->data->length;i++) {resp->data->data[i] = 1.0;}
1476  /* Originally created for injecting into DARM-ERR, so transfer function was needed.
1477  But since we are injecting into h(t), the transfer function from h(t) to h(t) is 1.*/
1478 
1479  /* We need a long buffer to inject into so that FindChirpInjectSignals() works properly
1480  for low mass systems. Use 100 seconds here */
1481  bufferN = (UINT4) (bufferLength*InjSampleRate);// /thisData->timeData->deltaT);
1482  memcpy(&bufferStart,&thisData->timeData->epoch,sizeof(LIGOTimeGPS));
1483  XLALGPSAdd(&bufferStart,(REAL8) thisData->timeData->data->length * thisData->timeData->deltaT);
1484  XLALGPSAdd(&bufferStart,-bufferLength);
1485  injectionBuffer=(REAL4TimeSeries *)XLALCreateREAL4TimeSeries(thisData->detector->frDetector.prefix,
1486  &bufferStart, 0.0, 1.0/InjSampleRate,//thisData->timeData->deltaT,
1487  &lalADCCountUnit, bufferN);
1488  REAL8TimeSeries *inj8Wave=(REAL8TimeSeries *)XLALCreateREAL8TimeSeries("injection8",
1489  &thisData->timeData->epoch,
1490  0.0,
1491  thisData->timeData->deltaT,
1492  //&lalDimensionlessUnit,
1493  &lalStrainUnit,
1494  thisData->timeData->data->length);
1495  if(!inj8Wave) XLAL_ERROR_VOID(XLAL_EFUNC);
1496  /* This marks the sample in which the real segment starts, within the buffer */
1497  for(i=0;i<injectionBuffer->data->length;i++) injectionBuffer->data->data[i]=0.0;
1498  for(i=0;i<inj8Wave->data->length;i++) inj8Wave->data->data[i]=0.0;
1499  INT4 realStartSample=(INT4)((thisData->timeData->epoch.gpsSeconds - injectionBuffer->epoch.gpsSeconds)/thisData->timeData->deltaT);
1500  realStartSample+=(INT4)((thisData->timeData->epoch.gpsNanoSeconds - injectionBuffer->epoch.gpsNanoSeconds)*1e-9/thisData->timeData->deltaT);
1501 
1502  if(LALInferenceGetProcParamVal(commandLine,"--lalinspiralinjection")){
1503  if ( approximant == NumRelNinja2) {
1504  XLALSimInjectNinjaSignals(injectionBuffer, thisData->name, 1./responseScale, injEvent);
1505  } else {
1506  /* Use this custom version for extra sites - not currently maintained */
1507  /* Normal find chirp simulation cannot handle the extra sites */
1508  LALFindChirpInjectSignals (&status,injectionBuffer,injEvent,resp);
1509  }
1510  printf("Using LALInspiral for injection\n");
1511  XLALResampleREAL4TimeSeries(injectionBuffer,thisData->timeData->deltaT); //downsample to analysis sampling rate.
1512  if(status.statusCode) REPORTSTATUS(&status);
1514 
1515  if ( approximant != NumRelNinja2 ) {
1516  /* Checking the lenght of the injection waveform with respect of thisData->timeData->data->length */
1518  PPNParamStruc ppnParams;
1519  memset( &waveform, 0, sizeof(CoherentGW) );
1520  memset( &ppnParams, 0, sizeof(PPNParamStruc) );
1521  ppnParams.deltaT = 1.0/InjSampleRate;//thisData->timeData->deltaT;
1522  ppnParams.lengthIn = 0;
1523  ppnParams.ppn = NULL;
1524  unsigned lengthTest = 0;
1525 
1526  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
1527  if(status.statusCode) REPORTSTATUS(&status);
1528 
1529  if(waveform.h){
1530  lengthTest = waveform.h->data->length*(thisData->timeData->deltaT*InjSampleRate);
1531  }
1532  if(waveform.phi){
1534  lengthTest = waveform.phi->data->length;
1535  }
1536 
1537 
1538  if(lengthTest>thisData->timeData->data->length-(UINT4)ceil((2.0*padding+2.0)/thisData->timeData->deltaT)){
1539  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));
1540  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__);
1541  }
1542  if(ppnParams.tc>bufferLength){
1543  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__);
1544  exit(1);
1545  }
1546  }
1547 
1548  /* Now we cut the injection buffer down to match the time domain wave size */
1549  injectionBuffer=(REAL4TimeSeries *)XLALCutREAL4TimeSeries(injectionBuffer,realStartSample,thisData->timeData->data->length);
1550  if (!injectionBuffer) XLAL_ERROR_VOID(XLAL_EFUNC);
1551  if(status.statusCode) REPORTSTATUS(&status);
1552  for(i=0;i<injectionBuffer->data->length;i++) inj8Wave->data->data[i]=(REAL8)injectionBuffer->data->data[i];
1553  }else{
1554  printf("Using LALSimulation for injection\n");
1555  REAL8TimeSeries *hplus=NULL; /**< +-polarization waveform */
1556  REAL8TimeSeries *hcross=NULL; /**< x-polarization waveform */
1557  REAL8TimeSeries *signalvecREAL8=NULL;
1558  LALPNOrder order; /* Order of the model */
1559  INT4 amporder=0; /* Amplitude order of the model */
1560 
1561  order = XLALGetOrderFromString(injEvent->waveform);
1562  if ( (int) order == XLAL_FAILURE)
1563  ABORTXLAL(&status);
1564  amporder = injEvent->amp_order;
1565  //if(amporder<0) amporder=0;
1566  /* FIXME - tidal lambda's and interactionFlag are just set to command line values here.
1567  * They should be added to injEvent and set to appropriate values
1568  */
1569 
1570  // Inject (lambda1,lambda2)
1571  REAL8 lambda1 = 0.;
1572  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1573  lambda1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")->value);
1574  }
1575  REAL8 lambda2 = 0.;
1576  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1577  lambda2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")->value);
1578  }
1579  if(flipped_masses)
1580  {
1581  /* Having previously flipped the masses so m1>m2, also flip lambdas */
1582  REAL8 lambda_tmp = lambda1;
1583  lambda1 = lambda2;
1584  lambda2 = lambda_tmp;
1585  fprintf(stdout,"Flipping lambdas since masses are flipped\n");
1586  }
1587  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1588  fprintf(stdout,"Injection lambda1 set to %f\n",lambda1);
1589  }
1590  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1591  fprintf(stdout,"Injection lambda1 set to %f\n",lambda1);
1592  }
1593 
1594  // Inject (lambdaT,dLambdaT)
1595  REAL8 lambdaT = 0.;
1596  REAL8 dLambdaT = 0.;
1597  REAL8 m1=injEvent->mass1;
1598  REAL8 m2=injEvent->mass2;
1599  REAL8 Mt=m1+m2;
1600  REAL8 eta=m1*m2/(Mt*Mt);
1601  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")&&LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")) {
1602  lambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")->value);
1603  dLambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")->value);
1604  LALInferenceLambdaTsEta2Lambdas(lambdaT,dLambdaT,eta,&lambda1,&lambda2);
1605  fprintf(stdout,"Injection lambdaT set to %f\n",lambdaT);
1606  fprintf(stdout,"Injection dLambdaT set to %f\n",dLambdaT);
1607  fprintf(stdout,"lambda1 set to %f\n",lambda1);
1608  fprintf(stdout,"lambda2 set to %f\n",lambda2);
1609  }
1610 
1611  // Inject 4-piece polytrope eos
1612  REAL8 logp1=0.0;
1613  REAL8 gamma1=0.0;
1614  REAL8 gamma2=0.0;
1615  REAL8 gamma3=0.0;
1616  if(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")){
1617  logp1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")->value);
1618  gamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")->value);
1619  gamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")->value);
1620  gamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")->value);
1621  // Find lambda1,2(m1,2|eos)
1622  LALInferenceLogp1GammasMasses2Lambdas(logp1, gamma1, gamma2, gamma3, m1, m2, &lambda1, &lambda2);
1623  fprintf(stdout,"Injection logp1 set to %f\n",logp1);
1624  fprintf(stdout,"Injection gamma1 set to %f\n",gamma1);
1625  fprintf(stdout,"Injection gamma2 set to %f\n",gamma2);
1626  fprintf(stdout,"Injection gamma3 set to %f\n",gamma3);
1627  fprintf(stdout,"lambda1 set to %f\n",lambda1);
1628  fprintf(stdout,"lambda2 set to %f\n",lambda2);
1629 
1630  /*
1631  For when tagSimInspiralTable is updated
1632  to include EOS params
1633 
1634  injEvent->logp1= logp1;
1635  injEvent->gamma1= gamma1;
1636  injEvent->gamma2= gamma2;
1637  injEvent->gamma3= gamma3;
1638  */
1639  }
1640 
1641  // Inject 4-coef. spectral eos
1642  REAL8 SDgamma0=0.0;
1643  REAL8 SDgamma1=0.0;
1644  REAL8 SDgamma2=0.0;
1645  REAL8 SDgamma3=0.0;
1646  if(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")){
1647  SDgamma0= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0")->value);
1648  SDgamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1")->value);
1649  SDgamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2")->value);
1650  SDgamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")->value);
1651  REAL8 gamma[]={SDgamma0,SDgamma1,SDgamma2,SDgamma3};
1653  fprintf(stdout,"Injection SDgamma0 set to %lf\n",SDgamma0);
1654  fprintf(stdout,"Injection SDgamma1 set to %lf\n",SDgamma1);
1655  fprintf(stdout,"Injection SDgamma2 set to %lf\n",SDgamma2);
1656  fprintf(stdout,"Injection SDgamma3 set to %lf\n",SDgamma3);
1657  fprintf(stdout,"lambda1 set to %f\n",lambda1);
1658  fprintf(stdout,"lambda2 set to %f\n",lambda2);
1659  }
1660 
1661 
1662  REAL8 fref = 100.;
1663  if(LALInferenceGetProcParamVal(commandLine,"--inj-fref")) {
1664  fref = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-fref")->value);
1665  }
1666 
1667  LALDict *LALpars=XLALCreateDict();
1668 
1669  /* Inject deviation from GR */
1670  /* Inspiral Coefficients */
1671  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")){
1672  REAL8 dchi_minus2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")->value);
1674 
1675  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")){
1676  REAL8 dchi_minus1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")->value);
1678 
1679  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")){
1680  REAL8 dchi0 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")->value);
1682  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")){
1683  REAL8 dchi1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")->value);
1685  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")){
1686  REAL8 dchi2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")->value);
1688  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")){
1689  REAL8 dchi3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")->value);
1691  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")){
1692  REAL8 dchi4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")->value);
1694  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5")){
1695  REAL8 dchi5 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")->value);
1697  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")){
1698  REAL8 dchi5l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")->value);
1700  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")){
1701  REAL8 dchi6 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")->value);
1703  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")){
1704  REAL8 dchi6l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")->value);
1706  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")){
1707  REAL8 dchi7 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")->value);
1709 
1710  /* PhenomD Intermediate */
1711  if (LALInferenceGetProcParamVal(commandLine,"--inj-dbeta1")){
1712  REAL8 nongr_dbeta1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dbeta1")->value);
1713  XLALSimInspiralWaveformParamsInsertNonGRDBeta1(LALpars, nongr_dbeta1);}
1714  if (LALInferenceGetProcParamVal(commandLine,"--inj-dbeta2")){
1715  REAL8 nongr_dbeta2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dbeta2")->value);
1716  XLALSimInspiralWaveformParamsInsertNonGRDBeta2(LALpars, nongr_dbeta2);}
1717  if (LALInferenceGetProcParamVal(commandLine,"--inj-dbeta3")){
1718  REAL8 nongr_dbeta3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dbeta3")->value);
1719  XLALSimInspiralWaveformParamsInsertNonGRDBeta3(LALpars, nongr_dbeta3);}
1720 
1721  /* PhenomX Intermediate */
1722  if (LALInferenceGetProcParamVal(commandLine,"--inj-db1")){
1723  REAL8 nongr_db1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db1")->value);
1724  XLALSimInspiralWaveformParamsInsertNonGRDB1(LALpars, nongr_db1);}
1725  if (LALInferenceGetProcParamVal(commandLine,"--inj-db2")){
1726  REAL8 nongr_db2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db2")->value);
1727  XLALSimInspiralWaveformParamsInsertNonGRDB2(LALpars, nongr_db2);}
1728  if (LALInferenceGetProcParamVal(commandLine,"--inj-db3")){
1729  REAL8 nongr_db3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db3")->value);
1730  XLALSimInspiralWaveformParamsInsertNonGRDB3(LALpars, nongr_db3);}
1731  if (LALInferenceGetProcParamVal(commandLine,"--inj-db4")){
1732  REAL8 nongr_db4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db4")->value);
1733  XLALSimInspiralWaveformParamsInsertNonGRDB4(LALpars, nongr_db4);}
1734 
1735  /* PhenomD Merger-Ringdown */
1736  if (LALInferenceGetProcParamVal(commandLine,"--inj-dalpha1")){
1737  REAL8 nongr_dalpha1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dalpha1")->value);
1738  XLALSimInspiralWaveformParamsInsertNonGRDAlpha1(LALpars, nongr_dalpha1);}
1739  if (LALInferenceGetProcParamVal(commandLine,"--inj-dalpha2")){
1740  REAL8 nongr_dalpha2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dalpha2")->value);
1741  XLALSimInspiralWaveformParamsInsertNonGRDAlpha2(LALpars, nongr_dalpha2);}
1742  if (LALInferenceGetProcParamVal(commandLine,"--inj-dalpha3")){
1743  REAL8 nongr_dalpha3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dalpha3")->value);
1744  XLALSimInspiralWaveformParamsInsertNonGRDAlpha3(LALpars, nongr_dalpha3);}
1745 
1746  /* PhenomX Merger-Ringdown */
1747  if (LALInferenceGetProcParamVal(commandLine,"--inj-dc1")){
1748  REAL8 nongr_dc1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc1")->value);
1749  XLALSimInspiralWaveformParamsInsertNonGRDC1(LALpars, nongr_dc1);}
1750  if (LALInferenceGetProcParamVal(commandLine,"--inj-dc2")){
1751  REAL8 nongr_dc2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc2")->value);
1752  XLALSimInspiralWaveformParamsInsertNonGRDC2(LALpars, nongr_dc2);}
1753  if (LALInferenceGetProcParamVal(commandLine,"--inj-dc4")){
1754  REAL8 nongr_dc4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc4")->value);
1755  XLALSimInspiralWaveformParamsInsertNonGRDC4(LALpars, nongr_dc4);}
1756  if (LALInferenceGetProcParamVal(commandLine,"--inj-dcl")){
1757  REAL8 nongr_dcl = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dcl")->value);
1758  XLALSimInspiralWaveformParamsInsertNonGRDCL(LALpars, nongr_dcl);}
1759 
1760 
1761  /* Set the spin-frame convention */
1762 
1764  if(LALInferenceGetProcParamVal(commandLine,"--inj-spinOrder")) {
1765  spinO = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-spinOrder")->value);
1767  }
1769  if(LALInferenceGetProcParamVal(commandLine,"--inj-tidalOrder")) {
1770  tideO = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-tidalOrder")->value);
1772  }
1773 
1775  if((ppt=LALInferenceGetProcParamVal(commandLine,"--inj-spin-frame"))) {
1777  }
1778  XLALSimInspiralWaveformParamsInsertFrameAxis(LALpars,(int) frameAxis);
1779 
1780  if((ppt=LALInferenceGetProcParamVal(commandLine,"--inj-numreldata"))) {
1782  fprintf(stdout,"Injection will use %s.\n",ppt->value);
1783  }
1784  else if (strlen(injEvent->numrel_data) > 0) {
1786  }
1787 
1788  /* Print a line with information about approximant, amporder, phaseorder, tide order and spin order */
1789  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);
1790 
1791  /* 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 */
1793  printf("Injecting with f_min = %f.\n", f_min);
1794 
1799 
1800  XLALSimInspiralChooseTDWaveform(&hplus, &hcross, injEvent->mass1*LAL_MSUN_SI, injEvent->mass2*LAL_MSUN_SI,
1801  injEvent->spin1x, injEvent->spin1y, injEvent->spin1z,
1802  injEvent->spin2x, injEvent->spin2y, injEvent->spin2z,
1803  injEvent->distance*LAL_PC_SI * 1.0e6, injEvent->inclination,
1804  injEvent->coa_phase, 0., 0., 0.,
1805  1.0/InjSampleRate, f_min, fref,
1806  LALpars, approximant);
1807  XLALDestroyDict(LALpars);
1808 
1809  if(!hplus || !hcross) {
1810  fprintf(stderr,"Error: XLALSimInspiralChooseWaveform() failed to produce waveform.\n");
1811  exit(-1);
1812  }
1813  XLALResampleREAL8TimeSeries(hplus,thisData->timeData->deltaT);
1814  XLALResampleREAL8TimeSeries(hcross,thisData->timeData->deltaT);
1815  /* XLALSimInspiralChooseTDWaveform always ends the waveform at t=0 */
1816  /* So we can adjust the epoch so that the end time is as desired */
1817  XLALGPSAddGPS(&(hplus->epoch), &(injEvent->geocent_end_time));
1818  XLALGPSAddGPS(&(hcross->epoch), &(injEvent->geocent_end_time));
1819 
1820  if((ppt=LALInferenceGetProcParamVal(commandLine,"--dump-geocenter-pols"))) {
1821 
1822  fprintf(stdout,"Dump injected TimeDomain h_plus and h_cross at geocenter (for IFO %s)\n", thisData->name);
1823 
1824  char filename[320];
1825  sprintf(filename,"%s_TD_geocenter_pols.dat",thisData->name);
1826 
1827  FILE* file=fopen(filename, "w");
1828  if(!file){
1829  fprintf(stderr,"Unable to open the path %s for writing injected TimeDomain h_plus and h_cross at geocenter\n",filename);
1830  exit(1);
1831  }
1832 
1833  for(j=0; j<hplus->data->length; j++){
1834  fprintf(file, "%.6f %g %g \n", XLALGPSGetREAL8(&hplus->epoch) + hplus->deltaT*j, hplus->data->data[j], hcross->data->data[j]);
1835  }
1836  fclose(file);
1837  }
1838 
1839  signalvecREAL8=XLALSimDetectorStrainREAL8TimeSeries(hplus, hcross, injEvent->longitude, injEvent->latitude, injEvent->polarization, det.site);
1840  if (!signalvecREAL8) XLAL_ERROR_VOID(XLAL_EFUNC);
1841 
1842  for(i=0;i<signalvecREAL8->data->length;i++){
1843  if(isnan(signalvecREAL8->data->data[i])) signalvecREAL8->data->data[i]=0.0;
1844  }
1845 
1846  if(signalvecREAL8->data->length > thisData->timeData->data->length-(UINT4)ceil((2.0*padding+2.0)/thisData->timeData->deltaT)){
1847  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));
1848  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__);
1849  }
1850 
1851  XLALSimAddInjectionREAL8TimeSeries(inj8Wave, signalvecREAL8, NULL);
1852 
1853  if ( hplus ) XLALDestroyREAL8TimeSeries(hplus);
1854  if ( hcross ) XLALDestroyREAL8TimeSeries(hcross);
1855 
1856  }
1857  XLALDestroyREAL4TimeSeries(injectionBuffer);
1859  &thisData->timeData->epoch,
1860  0.0,
1861  thisData->freqData->deltaF,
1863  thisData->freqData->data->length);
1864  if(!injF) {
1865  XLALPrintError("Unable to allocate memory for injection buffer\n");
1867  }
1868  /* Window the data */
1869  REAL4 WinNorm = sqrt(thisData->window->sumofsquares/thisData->window->data->length);
1870  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 */
1871  XLALREAL8TimeFreqFFT(injF,inj8Wave,thisData->timeToFreqFFTPlan);
1872  if(thisData->oneSidedNoisePowerSpectrum){
1873  for(SNR=0.0,j=thisData->fLow/injF->deltaF;j<thisData->fHigh/injF->deltaF;j++){
1874  SNR += pow(creal(injF->data->data[j]), 2.0)/thisData->oneSidedNoisePowerSpectrum->data->data[j];
1875  SNR += pow(cimag(injF->data->data[j]), 2.0)/thisData->oneSidedNoisePowerSpectrum->data->data[j];
1876  }
1877  SNR*=4.0*injF->deltaF;
1878  }
1879  thisData->SNR=sqrt(SNR);
1880  NetworkSNR+=SNR;
1881 
1882  /* Actually inject the waveform */
1883  for(j=0;j<inj8Wave->data->length;j++) thisData->timeData->data->data[j]+=inj8Wave->data->data[j];
1884  fprintf(stdout,"Injected SNR in detector %s = %g\n",thisData->name,thisData->SNR);
1885  char filename[320];
1886  sprintf(filename,"%s_timeInjection.dat",thisData->name);
1887  FILE* file=fopen(filename, "w");
1888  for(j=0;j<inj8Wave->data->length;j++){
1889  fprintf(file, "%.6f\t%lg\n", XLALGPSGetREAL8(&thisData->timeData->epoch) + thisData->timeData->deltaT*j, inj8Wave->data->data[j]);
1890  }
1891  fclose(file);
1892  sprintf(filename,"%s_freqInjection.dat",thisData->name);
1893  file=fopen(filename, "w");
1894  for(j=0;j<injF->data->length;j++){
1895  thisData->freqData->data->data[j] += injF->data->data[j] / WinNorm;
1896  fprintf(file, "%lg %lg \t %lg\n", thisData->freqData->deltaF*j, creal(injF->data->data[j]), cimag(injF->data->data[j]));
1897  }
1898  fclose(file);
1899 
1900  XLALDestroyREAL8TimeSeries(inj8Wave);
1902  thisData=thisData->next;
1903  }
1904  ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
1905  if (!ppt){
1906  PrintSNRsToFile(IFOdata , SNRpath);
1907  }
1908  NetworkSNR=sqrt(NetworkSNR);
1909  fprintf(stdout,"Network SNR of event %d = %g\n",event,NetworkSNR);
1910 
1911  /* Output waveform raw h-plus mode */
1912  if( (ppt=LALInferenceGetProcParamVal(commandLine,"--rawwaveform")) )
1913  {
1914  rawWaveform=fopen(ppt->value,"w");
1915  bufferN = (UINT4) (bufferLength/IFOdata->timeData->deltaT);
1916  memcpy(&bufferStart,&IFOdata->timeData->epoch,sizeof(LIGOTimeGPS));
1917  XLALGPSAdd(&bufferStart,(REAL8) IFOdata->timeData->data->length * IFOdata->timeData->deltaT);
1918  XLALGPSAdd(&bufferStart,-bufferLength);
1920  if(!resp) XLAL_ERROR_VOID(XLAL_EFUNC);
1921  injectionBuffer=(REAL4TimeSeries *)XLALCreateREAL4TimeSeries("None",&bufferStart, 0.0, IFOdata->timeData->deltaT,&lalADCCountUnit, bufferN);
1922  if(!injectionBuffer) XLAL_ERROR_VOID(XLAL_EFUNC);
1923  /* This marks the sample in which the real segment starts, within the buffer */
1924  INT4 realStartSample=(INT4)((IFOdata->timeData->epoch.gpsSeconds - injectionBuffer->epoch.gpsSeconds)/IFOdata->timeData->deltaT);
1925  realStartSample+=(INT4)((IFOdata->timeData->epoch.gpsNanoSeconds - injectionBuffer->epoch.gpsNanoSeconds)*1e-9/IFOdata->timeData->deltaT);
1926  LALFindChirpInjectSignals(&status,injectionBuffer,injEvent,resp);
1927  if(status.statusCode) REPORTSTATUS(&status);
1929  injectionBuffer=(REAL4TimeSeries *)XLALCutREAL4TimeSeries(injectionBuffer,realStartSample,IFOdata->timeData->data->length);
1930  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]);
1931  fclose(rawWaveform);
1932  XLALDestroyREAL4TimeSeries(injectionBuffer);
1933  }
1934 
1935  LALInferencePrintDataWithInjection(IFOdata,commandLine);
1936 
1937  return;
1938 }
1939 
1940 
1941 void InjectFD(LALInferenceIFOData *IFOdata, SimInspiralTable *inj_table, ProcessParamsTable *commandLine)
1942 ///*-------------- Inject in Frequency domain -----------------*/
1943 {
1944  /* Inject a gravitational wave into the data in the frequency domain */
1945  LALStatus status;
1946  memset(&status,0,sizeof(LALStatus));
1947  INT4 errnum;
1948  char SNRpath[FILENAME_MAX+50];
1949  ProcessParamsTable *ppt=NULL;
1950  int flipped_masses=0;
1951  LALInferenceIFOData *dataPtr;
1952 
1953  ppt = LALInferenceGetProcParamVal(commandLine,"--outfile");
1954  if (ppt)
1955  sprintf(SNRpath, "%s_snr.txt", ppt->value);
1956  else
1957  sprintf(SNRpath, "snr.txt");
1958 
1960  if( (int) approximant == XLAL_FAILURE)
1961  ABORTXLAL(&status);
1962 
1963  LALPNOrder phase_order = XLALGetOrderFromString(inj_table->waveform);
1964  if ( (int) phase_order == XLAL_FAILURE)
1965  ABORTXLAL(&status);
1966 
1967  LALPNOrder amp_order = (LALPNOrder) inj_table->amp_order;
1968 
1969  flipped_masses = enforce_m1_larger_m2(inj_table);
1970 
1971  REAL8 injtime=0.0;
1972  injtime=(REAL8) inj_table->geocent_end_time.gpsSeconds + (REAL8) inj_table->geocent_end_time.gpsNanoSeconds*1.0e-9;
1973 
1974  // Inject (lambda1,lambda2)
1975  REAL8 lambda1 = 0.;
1976  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1977  lambda1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")->value);
1978  }
1979  REAL8 lambda2 = 0.;
1980  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1981  lambda2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")->value);
1982  }
1983  if(flipped_masses) /* If flipped masses, also flip lambda */
1984  {
1985  REAL8 lambda_tmp=lambda1;
1986  lambda1=lambda2;
1987  lambda2=lambda_tmp;
1988  fprintf(stdout,"Flipping lambdas since masses are flipped\n");
1989  }
1990  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda1")) {
1991  fprintf(stdout,"Injection lambda1 set to %f\n",lambda1);
1992  }
1993  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambda2")) {
1994  fprintf(stdout,"Injection lambda2 set to %f\n",lambda2);
1995  }
1996 
1997 
1998  // Inject (lambdaT,dLambdaT)
1999  REAL8 lambdaT = 0.;
2000  REAL8 dLambdaT = 0.;
2001  if(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")&&LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")) {
2002  lambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-lambdaT")->value);
2003  dLambdaT= atof(LALInferenceGetProcParamVal(commandLine,"--inj-dLambdaT")->value);
2004  // Find lambda1,2(LambdaT,dLambdaT,eta)
2005  LALInferenceLambdaTsEta2Lambdas(lambdaT, dLambdaT, inj_table->eta, &lambda1, &lambda2);
2006  fprintf(stdout,"Injection lambdaT set to %f\n",lambdaT);
2007  fprintf(stdout,"Injection dLambdaT set to %f\n",dLambdaT);
2008  fprintf(stdout,"lambda1 set to %f\n",lambda1);
2009  fprintf(stdout,"lambda2 set to %f\n",lambda2);
2010  }
2011 
2012  // Inject 4-piece polytrope eos
2013  REAL8 logp1=0.0;
2014  REAL8 gamma1=0.0;
2015  REAL8 gamma2=0.0;
2016  REAL8 gamma3=0.0;
2017  if(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")&&LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")){
2018  logp1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-logp1")->value);
2019  gamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma1")->value);
2020  gamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma2")->value);
2021  gamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-gamma3")->value);
2022  // Find lambda1,2(m1,2|eos)
2023  LALInferenceLogp1GammasMasses2Lambdas(logp1, gamma1, gamma2, gamma3, inj_table->mass1, inj_table->mass2, &lambda1, &lambda2);
2024  fprintf(stdout,"Injection logp1 set to %f\n",logp1);
2025  fprintf(stdout,"Injection gamma1 set to %f\n",gamma1);
2026  fprintf(stdout,"Injection gamma2 set to %f\n",gamma2);
2027  fprintf(stdout,"Injection gamma3 set to %f\n",gamma3);
2028  fprintf(stdout,"lambda1 set to %f\n",lambda1);
2029  fprintf(stdout,"lambda2 set to %f\n",lambda2);
2030 
2031  /*
2032  For when tagSimInspiralTable is updated
2033  to include EOS params
2034 
2035  injEvent->logp1= logp1;
2036  injEvent->gamma1= gamma1;
2037  injEvent->gamma2= gamma2;
2038  injEvent->gamma3= gamma3;
2039  */
2040  }
2041 
2042  // Inject 4-coef. spectral eos
2043  REAL8 SDgamma0=0.0;
2044  REAL8 SDgamma1=0.0;
2045  REAL8 SDgamma2=0.0;
2046  REAL8 SDgamma3=0.0;
2047  if(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")){
2048  SDgamma0= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0")->value);
2049  SDgamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1")->value);
2050  SDgamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2")->value);
2051  SDgamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")->value);
2052  REAL8 gamma[]={SDgamma0,SDgamma1,SDgamma2,SDgamma3};
2054  fprintf(stdout,"Injection SDgamma0 set to %lf\n",SDgamma0);
2055  fprintf(stdout,"Injection SDgamma1 set to %lf\n",SDgamma1);
2056  fprintf(stdout,"Injection SDgamma2 set to %lf\n",SDgamma2);
2057  fprintf(stdout,"Injection SDgamma3 set to %lf\n",SDgamma3);
2058  fprintf(stdout,"lambda1 set to %f\n",lambda1);
2059  fprintf(stdout,"lambda2 set to %f\n",lambda2);
2060  }
2061 
2062 
2063  /* FIXME: One also need to code the same manipulations done to f_max in LALInferenceTemplateXLALSimInspiralChooseWaveform line 856 circa*/
2064 
2065  /* Set up LAL dictionary */
2066  LALDict* LALpars=XLALCreateDict();
2067 
2068  // Inject deviation from GR
2069  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")){
2070  REAL8 dchi_minus2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus2")->value);
2072 
2073  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")){
2074  REAL8 dchi_minus1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchiMinus1")->value);
2076 
2077  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")){
2078  REAL8 dchi0 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi0")->value);
2080 
2081  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")){
2082  REAL8 dchi1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi1")->value);
2084 
2085  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")){
2086  REAL8 dchi2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi2")->value);
2088 
2089  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")){
2090  REAL8 dchi3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi3")->value);
2092 
2093  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")){
2094  REAL8 dchi4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi4")->value);
2096 
2097  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5")){
2098  REAL8 dchi5 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5")->value);
2100 
2101  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")){
2102  REAL8 dchi5l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi5l")->value);
2104 
2105  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")){
2106  REAL8 dchi6 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6")->value);
2108 
2109  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")){
2110  REAL8 dchi6l = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi6l")->value);
2112 
2113  if (LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")){
2114  REAL8 dchi7 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dchi7")->value);
2116 
2117  if (LALInferenceGetProcParamVal(commandLine,"--inj-db1")){
2118  REAL8 nongr_db1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db1")->value);
2119  XLALSimInspiralWaveformParamsInsertNonGRDB1(LALpars, nongr_db1);}
2120 
2121  if (LALInferenceGetProcParamVal(commandLine,"--inj-db2")){
2122  REAL8 nongr_db2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db2")->value);
2123  XLALSimInspiralWaveformParamsInsertNonGRDB2(LALpars, nongr_db2);}
2124 
2125  if (LALInferenceGetProcParamVal(commandLine,"--inj-db3")){
2126  REAL8 nongr_db3 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db3")->value);
2127  XLALSimInspiralWaveformParamsInsertNonGRDB3(LALpars, nongr_db3);}
2128 
2129  if (LALInferenceGetProcParamVal(commandLine,"--inj-db4")){
2130  REAL8 nongr_db4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-db4")->value);
2131  XLALSimInspiralWaveformParamsInsertNonGRDB4(LALpars, nongr_db4);}
2132 
2133  if (LALInferenceGetProcParamVal(commandLine,"--inj-dc1")){
2134  REAL8 nongr_dc1 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc1")->value);
2135  XLALSimInspiralWaveformParamsInsertNonGRDC1(LALpars, nongr_dc1);}
2136 
2137  if (LALInferenceGetProcParamVal(commandLine,"--inj-dc2")){
2138  REAL8 nongr_dc2 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc2")->value);
2139  XLALSimInspiralWaveformParamsInsertNonGRDC2(LALpars, nongr_dc2);}
2140 
2141  if (LALInferenceGetProcParamVal(commandLine,"--inj-dc4")){
2142  REAL8 nongr_dc4 = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dc4")->value);
2143  XLALSimInspiralWaveformParamsInsertNonGRDC4(LALpars, nongr_dc4);}
2144 
2145  if (LALInferenceGetProcParamVal(commandLine,"--inj-dcl")){
2146  REAL8 nongr_dcl = atof(LALInferenceGetProcParamVal(commandLine,"--inj-dcl")->value);
2147  XLALSimInspiralWaveformParamsInsertNonGRDCL(LALpars, nongr_dcl);}
2148 
2149 
2150  /* Set the spin-frame convention */
2151  ppt = LALInferenceGetProcParamVal(commandLine,"--inj-spin-frame");
2152  if(ppt) {
2153  if (!strcmp(ppt->value, "view"))
2155  else if (!strcmp(ppt->value, "orbital-l"))
2157  else if (!strcmp(ppt->value, "total-j"))
2159  }
2160 
2162  if(LALInferenceGetProcParamVal(commandLine, "--inj-spinOrder")) {
2163  spinO = atoi(LALInferenceGetProcParamVal(commandLine, "--inj-spinOrder")->value);
2165  }
2166 
2168  if(LALInferenceGetProcParamVal(commandLine, "--inj-tidalOrder")) {
2169  tideO = atoi(LALInferenceGetProcParamVal(commandLine, "--inj-tidalOrder")->value);
2171  }
2172 
2173  REAL8 deltaT = IFOdata->timeData->deltaT;
2174  REAL8 deltaF = IFOdata->freqData->deltaF;
2175 
2176  REAL8 f_min = XLALSimInspiralfLow2fStart(inj_table->f_lower, amp_order, approximant);
2177  REAL8 f_max = 0.0;
2178 
2179  REAL8 fref = 100.;
2180  if(LALInferenceGetProcParamVal(commandLine,"--inj-fref")) {
2181  fref = atoi(LALInferenceGetProcParamVal(commandLine,"--inj-fref")->value);
2182  }
2183 
2184  if (approximant == TaylorF2)
2185  f_max = 0.0; /* this will stop at ISCO */
2186  else{
2187  /* get the max f_max as done in Template. Has to do this since I cannot access LALInferenceModel here*/
2188  dataPtr=IFOdata;
2189  while(dataPtr){
2190  if(dataPtr->fHigh>f_max) f_max=dataPtr->fHigh;
2191  dataPtr=dataPtr->next;
2192  }
2193  }
2194  /* Print a line with information about approximant, amp_order, phaseorder, tide order and spin order */
2195  fprintf(stdout,"\n\n---\t\t ---\n");
2196  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);
2197  fprintf(stdout,"---\t\t ---\n\n");
2198 
2199  COMPLEX16FrequencySeries *hptilde=NULL, *hctilde=NULL;
2200 
2205 
2206  XLALSimInspiralChooseFDWaveform(&hptilde, &hctilde, inj_table->mass1*LAL_MSUN_SI, inj_table->mass2*LAL_MSUN_SI,
2207  inj_table->spin1x, inj_table->spin1y, inj_table->spin1z,
2208  inj_table->spin2x, inj_table->spin2y, inj_table->spin2z,
2209  inj_table->distance*LAL_PC_SI * 1.0e6, inj_table->inclination,
2210  inj_table->coa_phase, 0., 0., 0., deltaF, f_min, f_max, fref,
2211  LALpars, approximant);
2212  XLALDestroyDict(LALpars);
2213 
2214  /* Fail if injection waveform generation was not successful */
2215  errnum = *XLALGetErrnoPtr();
2216  if (errnum != XLAL_SUCCESS) {
2217  XLALPrintError(" ERROR in InjectFD(): error encountered when injecting waveform. errnum=%d\n",errnum);
2218  exit(1);
2219  }
2220 
2221  if((ppt=LALInferenceGetProcParamVal(commandLine,"--dump-geocenter-pols"))) {
2222  fprintf(stdout,"Dump injected FreqDomain h_plus and h_cross at geocenter (for IFO %s)\n", IFOdata->name);
2223  char filename[320];
2224  sprintf(filename,"%s_FD_geocenter_pols.dat",IFOdata->name);
2225  FILE* file=fopen(filename, "w");
2226  if(!file){
2227  fprintf(stderr,"Unable to open the path %s for writing injected FreqDomain h_plus and h_cross\n",filename);
2228  exit(1);
2229  }
2230  UINT4 j;
2231  for(j=0; j<hptilde->data->length; j++){
2232  fprintf(file, "%10.10g %10.10g %10.10g %10.10g %10.10g\n", deltaF*j,
2233  creal(hptilde->data->data[j]), cimag(hptilde->data->data[j]),
2234  creal(hctilde->data->data[j]), cimag(hctilde->data->data[j]));
2235  }
2236  fclose(file);
2237  }
2238 
2239  REAL8 Fplus, Fcross;
2240  REAL8 plainTemplateReal, plainTemplateImag;
2241  REAL8 templateReal, templateImag;
2242  LIGOTimeGPS GPSlal;
2243  REAL8 gmst;
2244  REAL8 chisquared;
2245  REAL8 timedelay; /* time delay b/w iterferometer & geocenter w.r.t. sky location */
2246  REAL8 timeshift; /* time shift (not necessarily same as above) */
2247  REAL8 twopit, re, im, dre, dim, newRe, newIm;
2248  UINT4 i, lower, upper;
2249 
2250  REAL8 temp=0.0;
2251  REAL8 NetSNR=0.0;
2252 
2253  /* figure out GMST: */
2254  XLALGPSSetREAL8(&GPSlal, injtime);
2255  gmst=XLALGreenwichMeanSiderealTime(&GPSlal);
2256 
2257  /* loop over data (different interferometers): */
2258  dataPtr = IFOdata;
2259 
2260  while (dataPtr != NULL) {
2261  /*-- WF to inject is now in hptilde and hctilde. --*/
2262  /* determine beam pattern response (Fplus and Fcross) for given Ifo: */
2263  XLALComputeDetAMResponse(&Fplus, &Fcross,
2264  (const REAL4(*)[3])dataPtr->detector->response,
2265  inj_table->longitude, inj_table->latitude,
2266  inj_table->polarization, gmst);
2267 
2268  /* signal arrival time (relative to geocenter); */
2269  timedelay = XLALTimeDelayFromEarthCenter(dataPtr->detector->location,
2270  inj_table->longitude, inj_table->latitude,
2271  &GPSlal);
2272 
2273  /* (negative timedelay means signal arrives earlier at Ifo than at geocenter, etc.) */
2274  /* amount by which to time-shift template (not necessarily same as above "timedelay"): */
2275  REAL8 instant = dataPtr->timeData->epoch.gpsSeconds + 1e-9*dataPtr->timeData->epoch.gpsNanoSeconds;
2276 
2277  timeshift = (injtime - instant) + timedelay;
2278  twopit = LAL_TWOPI * (timeshift);
2279 
2280  dataPtr->fPlus = Fplus;
2281  dataPtr->fCross = Fcross;
2282  dataPtr->timeshift = timeshift;
2283 
2284  char InjFileName[320];
2285  sprintf(InjFileName,"injection_%s.dat",dataPtr->name);
2286  FILE *outInj=fopen(InjFileName,"w");
2287 
2288  /* determine frequency range & loop over frequency bins: */
2289  lower = (UINT4)ceil(dataPtr->fLow / deltaF);
2290  upper = (UINT4)floor(dataPtr->fHigh / deltaF);
2291  chisquared = 0.0;
2292 
2293  re = cos(twopit * deltaF * lower);
2294  im = -sin(twopit * deltaF * lower);
2295 
2296  /* When analysing TD data, FD templates need to be amplified by the window power loss factor */
2297  double windowFactor;
2298  windowFactor=sqrt(dataPtr->window->data->length/dataPtr->window->sumofsquares);
2299 
2300  for (i=lower; i<=upper; ++i){
2301  /* derive template (involving location/orientation parameters) from given plus/cross waveforms: */
2302  if (i < hptilde->data->length) {
2303  plainTemplateReal = Fplus * creal(hptilde->data->data[i])
2304  + Fcross * creal(hctilde->data->data[i]);
2305  plainTemplateImag = Fplus * cimag(hptilde->data->data[i])
2306  + Fcross * cimag(hctilde->data->data[i]);
2307  } else {
2308  plainTemplateReal = 0.0;
2309  plainTemplateImag = 0.0;
2310  }
2311 
2312  /* do time-shifting... */
2313  /* (also un-do 1/deltaT scaling): */
2314  /* real & imag parts of exp(-2*pi*i*f*deltaT): */
2315  templateReal = (plainTemplateReal*re - plainTemplateImag*im);
2316  templateImag = (plainTemplateReal*im + plainTemplateImag*re);
2317 
2318  /* apply windowing factor */
2319  templateReal *= ((REAL8) windowFactor);
2320  templateImag *= ((REAL8) windowFactor);
2321 
2322  /* Incremental values, using cos(theta) - 1 = -2*sin(theta/2)^2 */
2323  dim = -sin(twopit*deltaF);
2324  dre = -2.0*sin(0.5*twopit*deltaF)*sin(0.5*twopit*deltaF);
2325  newRe = re + re*dre - im * dim;
2326  newIm = im + re*dim + im*dre;
2327  re = newRe;
2328  im = newIm;
2329 
2330  fprintf(outInj,"%lf %e %e %e\n",i*deltaF ,templateReal,templateImag,1.0/dataPtr->oneSidedNoisePowerSpectrum->data->data[i]);
2331  dataPtr->freqData->data->data[i] += crect( templateReal, templateImag );
2332 
2333  temp = ((2.0/( deltaT*(double) dataPtr->timeData->data->length) * (templateReal*templateReal+templateImag*templateImag)) / dataPtr->oneSidedNoisePowerSpectrum->data->data[i]);
2334  chisquared += temp;
2335  }
2336  printf("injected SNR %.1f in IFO %s\n",sqrt(2.0*chisquared),dataPtr->name);
2337  NetSNR+=2.0*chisquared;
2338  dataPtr->SNR=sqrt(2.0*chisquared);
2339  dataPtr = dataPtr->next;
2340 
2341  fclose(outInj);
2342  }
2343  printf("injected Network SNR %.1f \n",sqrt(NetSNR));
2344  ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
2345  if (!ppt){
2346  PrintSNRsToFile(IFOdata , SNRpath);
2347  }
2350 }
2351 
2352 static void PrintSNRsToFile(LALInferenceIFOData *IFOdata , char SNRpath[] ){
2353  REAL8 NetSNR=0.0;
2354  LALInferenceIFOData *thisData=IFOdata;
2355  int nIFO=0;
2356 
2357  while(thisData){
2358  thisData=thisData->next;
2359  nIFO++;
2360  }
2361  FILE * snrout = fopen(SNRpath,"w");
2362  if(!snrout){
2363  fprintf(stderr,"Unable to open the path %s for writing SNR files\n",SNRpath);
2364  fprintf(stderr,"Error code %i: %s\n",errno,strerror(errno));
2365  exit(errno);
2366  }
2367  thisData=IFOdata;
2368  while(thisData){
2369  fprintf(snrout,"%s:\t %4.2f\n",thisData->name,thisData->SNR);
2370  nIFO++;
2371  NetSNR+=(thisData->SNR*thisData->SNR);
2372  thisData=thisData->next;
2373  }
2374  if (nIFO>1){
2375  fprintf(snrout,"Network:\t");
2376  fprintf(snrout,"%4.2f\n",sqrt(NetSNR));
2377  }
2378  fclose(snrout);
2379 }
2380 
2381 /**
2382 * Fill the variables passed in vars with the parameters of the injection passed in event
2383 * will over-write and destroy any existing parameters. Param vary type will be fixed
2384 */
2386 {
2387  //UINT4 spinCheck=0;
2388  if(!vars) {
2389  XLALPrintError("Encountered NULL variables pointer");
2391  }
2392  enforce_m1_larger_m2(theEventTable);
2393  REAL8 q = theEventTable->mass2 / theEventTable->mass1;
2394  if (q > 1.0) q = 1.0/q;
2395 
2396  REAL8 psi = theEventTable->polarization;
2397  if (psi>=M_PI) psi -= M_PI;
2398 
2399  REAL8 injGPSTime = XLALGPSGetREAL8(&(theEventTable->geocent_end_time));
2400 
2401  REAL8 dist = theEventTable->distance;
2402  //REAL8 cosinclination = cos(theEventTable->inclination);
2403  REAL8 phase = theEventTable->coa_phase;
2404  REAL8 dec = theEventTable->latitude;
2405  REAL8 ra = theEventTable->longitude;
2406 
2407  Approximant injapprox = XLALGetApproximantFromString(theEventTable->waveform);
2408  LALPNOrder order = XLALGetOrderFromString(theEventTable->waveform);
2409 
2410  REAL8 m1=theEventTable->mass1;
2411  REAL8 m2=theEventTable->mass2;
2412  REAL8 chirpmass = theEventTable->mchirp;
2413 
2416  if (LALInferenceCheckVariable(vars,"distance"))
2418  else if (LALInferenceCheckVariable(vars,"logdistance")){
2419  REAL8 logdistance=log(dist);
2420  LALInferenceAddVariable(vars, "logdistance", &logdistance, LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_FIXED);
2421  }
2424 
2425  /* Those will work even if the user is working with the detector-frame variables because SKY_FRAME is set
2426  to zero while calculating the injected logL in LALInferencePrintInjectionSample */
2430 
2431 
2432  LALInferenceAddVariable(vars, "LAL_APPROXIMANT", &injapprox, LALINFERENCE_UINT4_t, LALINFERENCE_PARAM_FIXED);
2434  LALInferenceAddVariable(vars, "LAL_AMPORDER", &(theEventTable->amp_order), LALINFERENCE_INT4_t, LALINFERENCE_PARAM_FIXED);
2435 
2436  REAL8 thetaJN,phiJL,theta1,theta2,phi12,chi1,chi2;
2437  /* Convert cartesian spin coordinates to system-frame variables*/
2438 
2439  /* This fref is --inj-fref, which has been set previously by LALInferencePrintInjectionSample
2440  I don't call it inj_fref since LALInferenceTemplate looks for fref, and that is what will be called to calculate
2441  the logL at injval
2442  */
2443  REAL8 fref=100.0;
2444  if (LALInferenceCheckVariable(vars,"f_ref"))
2445  fref= *(REAL8*) LALInferenceGetVariable(vars,"f_ref");
2446 
2447  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);
2448 
2449  if (LALInferenceCheckVariable(vars,"a_spin1"))
2451  if (LALInferenceCheckVariable(vars,"a_spin2"))
2453  if (LALInferenceCheckVariable(vars,"tilt_spin1"))
2455  if (LALInferenceCheckVariable(vars,"tilt_spin2"))
2457  if (LALInferenceCheckVariable(vars,"phi_jl"))
2459  if (LALInferenceCheckVariable(vars,"phi12"))
2461  REAL8 costhetajn=cos(thetaJN);
2462  LALInferenceAddVariable(vars, "costheta_jn", &costhetajn, LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_FIXED);
2463 
2464 }
2465 
2467  int errnum=0;
2468  char *fname=NULL;
2469  char defaultname[]="injection_params.dat";
2470  FILE *outfile=NULL;
2471 
2472  /* check if the --inj argument has been passed */
2474  if (!ppt)
2475  return(NULL);
2476 
2477  SimInspiralTable *injTable=NULL, *theEventTable=NULL;
2478  LALInferenceModel *model = LALInferenceInitCBCModel(runState);
2479  if (LALInferenceGetProcParamVal(runState->commandLine, "--roqtime_steps")){
2480  LALInferenceSetupROQmodel(model, runState->commandLine);
2481  fprintf(stderr, "done LALInferenceSetupROQmodel\n");
2482  } else {
2483  model->roq_flag=0;
2484  }
2485  LALInferenceVariables *injparams = XLALCalloc(1, sizeof(LALInferenceVariables));
2486  LALInferenceCopyVariables(model->params, injparams);
2487 
2489 
2490  ppt = LALInferenceGetProcParamVal(runState->commandLine, "--outfile");
2491  if (ppt) {
2492  fname = XLALCalloc((strlen(ppt->value)+255)*sizeof(char),1);
2493  sprintf(fname,"%s.injection",ppt->value);
2494  }
2495  else
2496  fname = defaultname;
2497 
2498  ppt = LALInferenceGetProcParamVal(runState->commandLine, "--event");
2499  if (ppt) {
2500  UINT4 event = atoi(ppt->value);
2501  UINT4 i;
2502  theEventTable = injTable;
2503  for (i = 0; i < event; i++) {
2504  theEventTable = theEventTable->next;
2505  }
2506  theEventTable->next = NULL;
2507  } else {
2508  theEventTable=injTable;
2509  theEventTable->next = NULL;
2510  }
2511 
2512  LALPNOrder *order = LALInferenceGetVariable(injparams, "LAL_PNORDER");
2513  Approximant *approx = LALInferenceGetVariable(injparams, "LAL_APPROXIMANT");
2514 
2515  if (!(approx && order)){
2516  fprintf(stdout,"Unable to print injection sample: No approximant/PN order set\n");
2517  return(NULL);
2518  }
2519 
2520  REAL8 fref = 100.;
2521  if(LALInferenceGetProcParamVal(runState->commandLine,"--inj-fref")) {
2522  fref = atoi(LALInferenceGetProcParamVal(runState->commandLine,"--inj-fref")->value);
2523  }
2525 
2526  UINT4 azero=0;
2527  LALInferenceAddVariable(injparams,"SKY_FRAME",(void *)&azero,LALINFERENCE_REAL8_t,LALINFERENCE_PARAM_OUTPUT);
2528  /* remove eventual SKY FRAME vars since they will contain garbage*/
2529  if (LALInferenceCheckVariable(injparams,"t0"))
2530  LALInferenceRemoveVariable(injparams,"t0");
2531  if (LALInferenceCheckVariable(injparams,"cosalpha"))
2532  LALInferenceRemoveVariable(injparams,"cosalpha");
2533  if (LALInferenceCheckVariable(injparams,"azimuth"))
2534  LALInferenceRemoveVariable(injparams,"azimuth");
2535 
2536  /* Fill named variables */
2537  LALInferenceInjectionToVariables(theEventTable, injparams);
2538 
2539  REAL8 injPrior = runState->prior(runState, injparams, model);
2540  LALInferenceAddVariable(injparams, "logPrior", &injPrior, LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_OUTPUT);
2541  REAL8 injL=0.;
2542  if ( (int) *approx == XLALGetApproximantFromString(theEventTable->waveform)){
2543  XLAL_TRY(injL = runState->likelihood(injparams, runState->data, model), errnum);
2544  if(errnum){
2545  fprintf(stderr,"ERROR: Cannot print injection sample. Received error code %s\n",XLALErrorString(errnum));
2546  }
2547  }
2548  LALInferenceAddVariable(injparams, "logL", (void *)&injL,LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_OUTPUT);
2549  REAL8 logZnoise=LALInferenceNullLogLikelihood(runState->data);
2550  REAL8 tmp2=injL-logZnoise;
2551  LALInferenceAddVariable(injparams,"deltalogL",(void *)&tmp2,LALINFERENCE_REAL8_t,LALINFERENCE_PARAM_OUTPUT);
2552 
2553  LALInferenceIFOData *data=runState->data;
2554  while(data) {
2555  char tmpName[320];
2556  REAL8 tmp=model->loglikelihood - data->nullloglikelihood;
2557  sprintf(tmpName,"deltalogl%s",data->name);
2559  data=data->next;
2560  }
2561 
2562  /* Save to file */
2563  outfile=fopen(fname,"w");
2564  if(!outfile) {fprintf(stderr,"ERROR: Unable to open file %s for injection saving\n",fname); exit(1);}
2567  fprintf(outfile,"\n");
2568  LALInferencePrintSample(outfile, injparams);
2569 
2570  fclose(outfile);
2571  //LALInferenceClearVariables(injparams);
2572  return(injparams);
2573 }
2574 
2576  /* Template generator assumes m1>=m2 thus we must enfore the same convention while injecting, otherwise spin2 will be assigned to mass1
2577  * We also shift the phase by pi to be sure the same WF in injected
2578  * Returns: 1 if masses were flipped
2579  */
2580  REAL8 m1,m2,tmp;
2581  m1=injEvent->mass1;
2582  m2=injEvent->mass2;
2583 
2584  if (m1>=m2) return(0);
2585  else{
2586  fprintf(stdout, "Injtable has m1<m2. Flipping masses and spins in injection. Shifting phase by pi. \n");
2587  tmp=m1;
2588  injEvent->mass1=injEvent->mass2;
2589  injEvent->mass2=tmp;
2590  tmp=injEvent->spin1x;
2591  injEvent->spin1x=injEvent->spin2x;
2592  injEvent->spin2x=tmp;
2593  tmp=injEvent->spin1y;
2594  injEvent->spin1y=injEvent->spin2y;
2595  injEvent->spin2y=tmp;
2596  tmp=injEvent->spin1z;
2597  injEvent->spin1z=injEvent->spin2z;
2598  injEvent->spin2z=tmp;
2599  injEvent->coa_phase=injEvent->coa_phase+LAL_PI;
2600  return(1);
2601  }
2602 }
2603 
2605 
2606  LALStatus status;
2607  memset(&status,0,sizeof(status));
2608  UINT4 q=0;
2609  UINT4 event=0;
2610  ProcessParamsTable *procparam=NULL,*ppt=NULL;
2611  SimInspiralTable *injTable=NULL;
2612  FILE *tempfp;
2613  unsigned int n_basis_linear=0, n_basis_quadratic=0, n_samples=0, time_steps=0;
2614  int errsave;
2615 
2616  LIGOTimeGPS GPStrig;
2617  REAL8 endtime=0.0;
2618 
2619  model->roq = XLALMalloc(sizeof(LALInferenceROQModel));
2620  model->roq_flag = 1;
2621  procparam=LALInferenceGetProcParamVal(commandLine,"--inj");
2622  if(procparam){
2623  injTable = XLALSimInspiralTableFromLIGOLw(procparam->value);
2624  if(!injTable){
2625  fprintf(stderr,"Unable to open injection file(LALInferenceReadData) %s\n",procparam->value);
2626  exit(1);
2627  }
2628  procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2629  if(procparam) {
2630  event=atoi(procparam->value);
2631  while(q<event) {q++; injTable=injTable->next;}
2632  }
2633  else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id")))
2634  {
2635  while(injTable)
2636  {
2637  if(injTable->simulation_id == atol(procparam->value)) break;
2638  else injTable=injTable->next;
2639  }
2640  if(!injTable){
2641  fprintf(stderr,"Error, cannot find simulation id %s in injection file\n",procparam->value);
2642  exit(1);
2643  }
2644  }
2645  }
2646 
2647  if(LALInferenceGetProcParamVal(commandLine,"--trigtime")){
2648  procparam=LALInferenceGetProcParamVal(commandLine,"--trigtime");
2649  XLALStrToGPS(&GPStrig,procparam->value,NULL);
2650  }
2651  else{
2652  if(injTable) memcpy(&GPStrig,&(injTable->geocent_end_time),sizeof(GPStrig));
2653  else {
2654  fprintf(stderr,">>> Error: No trigger time specifed and no injection given \n");
2655  exit(1);
2656  }
2657  }
2658 
2659  endtime=XLALGPSGetREAL8(&GPStrig);
2660 
2661  if(LALInferenceGetProcParamVal(commandLine,"--roqtime_steps")){
2662  ppt=LALInferenceGetProcParamVal(commandLine,"--roqtime_steps");
2663  tempfp = fopen (ppt->value,"r");
2664  if (tempfp == NULL){
2665  errsave = errno;
2666  fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2667  fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2668  exit(errsave);
2669  }
2670  fscanf(tempfp, "%u", &time_steps);
2671  fscanf(tempfp, "%u", &n_basis_linear);
2672  fscanf(tempfp, "%u", &n_basis_quadratic);
2673  fscanf(tempfp, "%u", &n_samples);
2674  fclose(tempfp);
2675  fprintf(stderr, "loaded --roqtime_steps\n");
2676  }
2677 
2678 
2679  model->roq->frequencyNodesLinear = XLALCreateREAL8Sequence(n_basis_linear);
2680  model->roq->frequencyNodesQuadratic = XLALCreateREAL8Sequence(n_basis_quadratic);
2681 
2682  model->roq->trigtime = endtime;
2683 
2684  model->roq->frequencyNodesLinear = XLALCreateREAL8Sequence(n_basis_linear);
2685  model->roq->frequencyNodesQuadratic = XLALCreateREAL8Sequence(n_basis_quadratic);
2686  model->roq->calFactorLinear = XLALCreateCOMPLEX16Sequence(model->roq->frequencyNodesLinear->length);
2687  model->roq->calFactorQuadratic = XLALCreateCOMPLEX16Sequence(model->roq->frequencyNodesQuadratic->length);
2688 
2689  if(LALInferenceGetProcParamVal(commandLine,"--roqnodesLinear")){
2690  ppt=LALInferenceGetProcParamVal(commandLine,"--roqnodesLinear");
2691 
2692  model->roq->nodesFileLinear = fopen(ppt->value, "rb");
2693  if (!(model->roq->nodesFileLinear)) {
2694  errsave = errno;
2695  fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2696  fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2697  exit(errsave);
2698  } // check file exists
2699  fprintf(stderr, "read model->roq->frequencyNodesLinear");
2700 
2701  for(unsigned int linsize = 0; linsize < n_basis_linear; linsize++){
2702  fread(&(model->roq->frequencyNodesLinear->data[linsize]), sizeof(REAL8), 1, model->roq->nodesFileLinear);
2703  }
2704  fclose(model->roq->nodesFileLinear);
2705  model->roq->nodesFileLinear = NULL;
2706  fprintf(stderr, "loaded --roqnodesLinear\n");
2707  }
2708 
2709  if(LALInferenceGetProcParamVal(commandLine,"--roqnodesQuadratic")){
2710  ppt=LALInferenceGetProcParamVal(commandLine,"--roqnodesQuadratic");
2711  model->roq->nodesFileQuadratic = fopen(ppt->value, "rb");
2712  if (!(model->roq->nodesFileQuadratic)) {
2713  errsave = errno;
2714  fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2715  fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2716  exit(errsave);
2717  } // check file exists
2718 
2719  for(unsigned int quadsize = 0; quadsize < n_basis_quadratic; quadsize++){
2720  fread(&(model->roq->frequencyNodesQuadratic->data[quadsize]), sizeof(REAL8), 1, model->roq->nodesFileQuadratic);
2721  }
2722  fclose(model->roq->nodesFileQuadratic);
2723  model->roq->nodesFileQuadratic = NULL;
2724  fprintf(stderr, "loaded --roqnodesQuadratic\n");
2725 
2726 
2727 
2728  }
2729 }
2730 
2732  LALStatus status;
2733  memset(&status,0,sizeof(status));
2734  LALInferenceIFOData *thisData=IFOdata;
2735  UINT4 q=0;
2736  UINT4 event=0;
2737  ProcessParamsTable *procparam=NULL,*ppt=NULL;
2738  SimInspiralTable *injTable=NULL;
2739  unsigned int n_basis_linear, n_basis_quadratic, n_samples, time_steps;
2740  float dt=0.1;
2741  //REAL8 timeMin=0.0,timeMax=0.0;
2742  FILE *tempfp;
2743  char tmp[320];
2744  int errsave;
2745 
2746  procparam=LALInferenceGetProcParamVal(commandLine,"--inj");
2747  if(procparam) {
2748  injTable = XLALSimInspiralTableFromLIGOLw(procparam->value);
2749  if (!injTable) {
2750  fprintf(stderr,"Unable to open injection file(LALInferenceReadData) %s\n",procparam->value);
2751  exit(1);
2752  }
2753  procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2754  if (procparam) {
2755  event=atoi(procparam->value);
2756  while(q<event) {
2757  q++;
2758  injTable=injTable->next;
2759  }
2760  } else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id"))) {
2761  while (injTable) {
2762  if (injTable->simulation_id == atol(procparam->value)) {
2763  break;
2764  } else {
2765  injTable=injTable->next;
2766  }
2767  }
2768  if (!injTable) {
2769  fprintf(stderr, "Error, cannot find simulation id %s in injection file\n", procparam->value);
2770  exit(1);
2771  }
2772  }
2773  }
2774 
2775  ppt=LALInferenceGetProcParamVal(commandLine,"--dt");
2776  if(ppt){
2777  dt=atof(ppt->value);
2778  }
2779 
2780  if (LALInferenceGetProcParamVal(commandLine,"--roqtime_steps")) {
2781  ppt = LALInferenceGetProcParamVal(commandLine,"--roqtime_steps");
2782  tempfp = fopen (ppt->value,"r");
2783  if (tempfp == NULL){
2784  errsave = errno;
2785  fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2786  fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2787  exit(errsave);
2788  }
2789  fscanf(tempfp, "%u", &time_steps);
2790  fscanf(tempfp, "%u", &n_basis_linear);
2791  fscanf(tempfp, "%u", &n_basis_quadratic);
2792  fscanf(tempfp, "%u", &n_samples);
2793  fclose(tempfp);
2794  fprintf(stderr, "loaded --roqtime_steps\n");
2795  }
2796 
2797 
2798  thisData=IFOdata;
2799  while (thisData) {
2800  thisData->roq = XLALMalloc(sizeof(LALInferenceROQData));
2801 
2802  thisData->roq->weights_linear = XLALMalloc(n_basis_linear*sizeof(LALInferenceROQSplineWeights));
2803 
2804  sprintf(tmp, "--%s-roqweightsLinear", thisData->name);
2805  ppt = LALInferenceGetProcParamVal(commandLine,tmp);
2806 
2807  thisData->roq->weightsFileLinear = fopen(ppt->value, "rb");
2808  if (thisData->roq->weightsFileLinear == NULL){
2809  errsave = errno;
2810  fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2811  fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2812  exit(errsave);
2813  }
2814  thisData->roq->weightsLinear = (double complex*)malloc(n_basis_linear*time_steps*(sizeof(double complex)));
2815 
2816  //0.045 comes from the diameter of the earth in light seconds: the maximum time-delay between earth-based observatories
2817  thisData->roq->time_weights_width = 2*dt + 2*0.045;
2818  thisData->roq->time_step_size = thisData->roq->time_weights_width/time_steps;
2819  thisData->roq->n_time_steps = time_steps;
2820 
2821 
2822  fprintf(stderr, "basis_size = %d\n", n_basis_linear);
2823  fprintf(stderr, "time steps = %d\n", time_steps);
2824 
2825  double *tmp_real_weight = malloc(time_steps*(sizeof(double)));
2826  double *tmp_imag_weight = malloc(time_steps*(sizeof(double)));
2827 
2828  double *tmp_tcs = malloc(time_steps*(sizeof(double)));
2829 
2830  sprintf(tmp, "--roq-times");
2831  ppt = LALInferenceGetProcParamVal(commandLine,tmp);
2832 
2833  FILE *tcFile = fopen(ppt->value, "rb");
2834  if (tcFile == NULL) {
2835  errsave = errno;
2836  fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2837  fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2838  exit(errsave);
2839  }
2840 
2841  for(unsigned int gg=0;gg < time_steps; gg++){
2842  fread(&(tmp_tcs[gg]), sizeof(double), 1, tcFile);
2843  }
2844 
2845  for(unsigned int ii=0; ii<n_basis_linear;ii++){
2846  for(unsigned int jj=0; jj<time_steps;jj++){
2847  fread(&(thisData->roq->weightsLinear[ii*time_steps + jj]), sizeof(double complex), 1, thisData->roq->weightsFileLinear);
2848  tmp_real_weight[jj] = creal(thisData->roq->weightsLinear[ii*time_steps + jj]);
2849  tmp_imag_weight[jj] = cimag(thisData->roq->weightsLinear[ii*time_steps + jj]);
2850  }
2851  //gsl_interp_accel is not thread-safe, and each OpenMP thread will need its
2852  //own gsl_interp_accel object.
2853  thisData->roq->weights_linear[ii].acc_real_weight_linear = NULL;
2854  thisData->roq->weights_linear[ii].acc_imag_weight_linear = NULL;
2855 
2856  thisData->roq->weights_linear[ii].spline_real_weight_linear = gsl_spline_alloc (gsl_interp_cspline, time_steps);
2857  gsl_spline_init(thisData->roq->weights_linear[ii].spline_real_weight_linear, tmp_tcs, tmp_real_weight, time_steps);
2858 
2859  thisData->roq->weights_linear[ii].spline_imag_weight_linear = gsl_spline_alloc (gsl_interp_cspline, time_steps);
2860  gsl_spline_init(thisData->roq->weights_linear[ii].spline_imag_weight_linear, tmp_tcs, tmp_imag_weight, time_steps);
2861  }
2862  fclose(thisData->roq->weightsFileLinear);
2863  thisData->roq->weightsFileLinear = NULL;
2864  fclose(tcFile);
2865 
2866  sprintf(tmp, "--%s-roqweightsQuadratic", thisData->name);
2867  ppt = LALInferenceGetProcParamVal(commandLine,tmp);
2868  thisData->roq->weightsQuadratic = (double*)malloc(n_basis_quadratic*sizeof(double));
2869  thisData->roq->weightsFileQuadratic = fopen(ppt->value, "rb");
2870  if (thisData->roq->weightsFileQuadratic == NULL){
2871  errsave = errno;
2872  fprintf(stderr, "Error: cannot find file %s \n", ppt->value);
2873  fprintf(stderr, "Error code %i: %s\n", errsave, strerror(errsave));
2874  exit(errsave);
2875  }
2876  for(unsigned int ii=0; ii<n_basis_quadratic;ii++){
2877  fread(&(thisData->roq->weightsQuadratic[ii]), sizeof(double), 1, thisData->roq->weightsFileQuadratic);
2878  }
2879  fclose(thisData->roq->weightsFileQuadratic);
2880  thisData->roq->weightsFileQuadratic = NULL;
2881  fprintf(stderr, "loaded %s ROQ weights\n", thisData->name);
2882  thisData = thisData->next;
2883  }
2884 }
2885 
2886 static void LALInferenceSetGPSTrigtime(LIGOTimeGPS *GPStrig, ProcessParamsTable *commandLine){
2887 
2888  ProcessParamsTable *procparam;
2889  SimInspiralTable *inspiralTable=NULL;
2890  SimBurst *burstTable=NULL;
2891  UINT4 event=0;
2892  UINT4 q=0;
2893  LALStatus status;
2894  memset(&status,0,sizeof(LALStatus));
2895 
2896  /* First check if trigtime has been given as an option */
2897  if(LALInferenceGetProcParamVal(commandLine,"--trigtime")){
2898  procparam=LALInferenceGetProcParamVal(commandLine,"--trigtime");
2899  XLALStrToGPS(GPStrig,procparam->value,NULL);
2900  fprintf(stdout,"Set trigtime to %.10f\n",GPStrig->gpsSeconds+1.0e-9 * GPStrig->gpsNanoSeconds);
2901  return;
2902 
2903  }
2904  else{
2905  /* If not check if we have an injtable passed with --inj */
2906 
2907  if(LALInferenceGetProcParamVal(commandLine,"--injXML"))
2908  {
2909  XLALPrintError("ERROR: --injXML option is deprecated. Use --inj and update your scripts\n");
2910  exit(1);
2911  }
2912  if((procparam=LALInferenceGetProcParamVal(commandLine,"--inj"))){
2913  fprintf(stdout,"Checking if the xml table is an inspiral table... \n");
2914  /* Check if it is a SimInspiralTable */
2915  inspiralTable = XLALSimInspiralTableFromLIGOLw(procparam->value);
2916 
2917  if (inspiralTable){
2918  procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2919  if(procparam) {
2920  event=atoi(procparam->value);
2921  while(q<event) {q++; inspiralTable=inspiralTable->next;}
2922  }
2923  else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id")))
2924  {
2925  while(inspiralTable)
2926  {
2927  if(inspiralTable->simulation_id == atol(procparam->value)) break;
2928  else inspiralTable=inspiralTable->next;
2929  }
2930  if(!inspiralTable){
2931  fprintf(stderr,"Error, cannot find simulation id %s in injection file\n",procparam->value);
2932  exit(1);
2933  }
2934  }
2935  else
2936  fprintf(stdout,"You did not provide an event number with the injtable. Using event 0 which may not be what you want!!!!!\n");
2937  memcpy(GPStrig,&(inspiralTable->geocent_end_time),sizeof(LIGOTimeGPS));
2938  printf("Set inspiral injtime %.10f\n",inspiralTable->geocent_end_time.gpsSeconds+1.0e-9* inspiralTable->geocent_end_time.gpsNanoSeconds);
2939  return;
2940  }
2941  }
2942  else if((procparam=LALInferenceGetProcParamVal(commandLine,"--binj"))){
2943  /* Check if it is a SimBurst table */
2944  fprintf(stdout,"Checking if the xml table is a burst table... \n");
2945  burstTable=XLALSimBurstTableFromLIGOLw(procparam->value);
2946  if(burstTable){
2947  procparam=LALInferenceGetProcParamVal(commandLine,"--event");
2948  if(procparam) {
2949  event=atoi(procparam->value);
2950  while(q<event) {q++; burstTable=burstTable->next;}
2951  }
2952  else if ((procparam=LALInferenceGetProcParamVal(commandLine,"--event-id")))
2953  {
2954  fprintf(stderr,"Error, SimBurst tables do not currently support event_id tags \n");
2955  exit(1);
2956  }
2957  else
2958  fprintf(stdout,"You did not provide an event number with the injtable. Using event 0 which may not be what you want!!!!!\n");
2959  memcpy(GPStrig,&(burstTable->time_geocent_gps),sizeof(LIGOTimeGPS));
2960  fprintf(stdout,"Set trigtime from burstable to %.10f\n",GPStrig->gpsSeconds+1.0e-9 * GPStrig->gpsNanoSeconds);
2961  return;
2962  }
2963  }
2964  else if(!LALInferenceGetProcParamVal(commandLine,"--segment-start")){
2965  XLALPrintError("Error: No trigger time specifed and no injection given \n");
2966  //XLAL_ERROR_NULL(XLAL_EINVAL);
2967  exit(1);
2968  }
2969 
2970  }
2971 }
2972 
2974 
2975  /* Read time domain WF present in an mdc frame file, FFT it and inject into the frequency domain stream */
2976 
2977  char mdcname[]="GW";
2978  char **mdc_caches=NULL;
2979  char **mdc_channels=NULL;
2980  ProcessParamsTable * ppt=commandLine;
2981 
2982  UINT4 nIFO=0;
2983  int i=0;
2984  UINT4 j=0;
2985  LALInferenceIFOData *data=IFOdata;
2986  REAL8 prefactor =1.0;
2987  ppt=LALInferenceGetProcParamVal(commandLine,"--mdc-prefactor");
2988  if (ppt){
2989 
2990  prefactor=atof(ppt->value);
2991  fprintf(stdout,"Using prefactor=%f to scale the MDC injection\n",prefactor);
2992  }
2993 
2994  ppt=LALInferenceGetProcParamVal(commandLine,"--inj");
2995  if (ppt){
2996 
2997  fprintf(stderr,"You cannot use both injfile (--inj) and MDCs (--inject_from_mdc) Exiting... \n");
2998  exit(1);
2999 
3000  }
3001  ppt=LALInferenceGetProcParamVal(commandLine,"--binj");
3002  if (ppt){
3003 
3004  fprintf(stderr,"You cannot use both injfile (--binj) and MDCs (--inject_from_mdc) Exiting... \n");
3005  exit(1);
3006 
3007  }
3008 
3009  REAL8 tmp=0.0;
3010  REAL8 net_snr=0.0;
3011  while (data) {nIFO++; data=data->next;}
3012  UINT4 Nmdc=0,Nchannel=0;
3013 
3014  char mdc_caches_name[] = "injcache";
3015  char mdc_channels_name[] = "injchannel";
3016  char **IFOnames=NULL;
3017  INT4 rlceops= getNamedDataOptionsByDetectors(commandLine, &IFOnames,&mdc_caches ,mdc_caches_name, &Nmdc);
3018  if (!rlceops){
3019  fprintf(stderr,"Must provide a --IFO-injcache option for each IFO if --inject_from_mdc is given\n");
3020  exit(1);
3021  }
3022 
3023  rlceops= getNamedDataOptionsByDetectors(commandLine, &IFOnames,&mdc_channels ,mdc_channels_name, &Nchannel);
3024  if (!rlceops){
3025  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");
3026  mdc_channels= malloc((nIFO+1)*sizeof(char*));
3027  data=IFOdata;
3028  i=0;
3029  while (data){
3030  mdc_channels[i] = malloc(512*sizeof(char));
3031  if(!strcmp(data->name,"H1")) {
3032  sprintf(mdc_channels[i],"H1:%s-H",mdcname);}
3033  else if(!strcmp(data->name,"L1")) {
3034  sprintf(mdc_channels[i],"L1:%s-H",mdcname); }
3035  else if(!strcmp(data->name,"V1")) {
3036  sprintf(mdc_channels[i],"V1:%s-16K",mdcname);}
3037  data=data->next;
3038  i++;
3039 
3040  }
3041  }
3042 
3043  LIGOTimeGPS epoch=IFOdata->timeData->epoch;
3044  REAL8 deltaT=IFOdata->timeData->deltaT ;
3045  int seglen=IFOdata->timeData->data->length;
3046  REAL8 SampleRate=4096.0,SegmentLength=0.0;
3047  if(LALInferenceGetProcParamVal(commandLine,"--srate")) SampleRate=atof(LALInferenceGetProcParamVal(commandLine,"--srate")->value);
3048  SegmentLength=(REAL8) seglen/SampleRate;
3049 
3050  REAL8TimeSeries * timeData=NULL;
3051  REAL8TimeSeries * windTimeData=(REAL8TimeSeries *)XLALCreateREAL8TimeSeries("WindMDCdata",&epoch,0.0,deltaT,&lalDimensionlessUnit,(size_t)seglen);
3053 
3054  if(!injF) {
3055  XLALPrintError("Unable to allocate memory for injection buffer\n");
3057  }
3058 
3059  REAL4 WinNorm = sqrt(IFOdata->window->sumofsquares/IFOdata->window->data->length);
3060 
3061  data=IFOdata;
3062  i=0;
3063  UINT4 lower = (UINT4)ceil(data->fLow / injF->deltaF);
3064  UINT4 upper = (UINT4)floor(data->fHigh /injF-> deltaF);
3065  //FIXME CHECK WNORM
3066  /* Inject into FD data stream and calculate optimal SNR */
3067  while(data){
3068  tmp=0.0;
3069  LALCache *mdc_cache=NULL;
3070  mdc_cache = XLALCacheImport(mdc_caches[i] );
3071 
3072  /* Read MDC frame */
3073  timeData=readTseries(mdc_cache,mdc_channels[i],epoch,SegmentLength);
3074  /* downsample */
3075  XLALResampleREAL8TimeSeries(timeData,1.0/SampleRate);
3076  /* window timeData and store it in windTimeData */
3077  XLALDDVectorMultiply(windTimeData->data,timeData->data,IFOdata->window->data);
3078 
3079  /*for(j=0;j< timeData->data->length;j++)
3080  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]);
3081  fclose(out);
3082  */
3083 
3084  /* set the whole seq to 0 */
3085  for(j=0;j<injF->data->length;j++) injF->data->data[j]=0.0;
3086 
3087  /* FFT */
3088  XLALREAL8TimeFreqFFT(injF,windTimeData,IFOdata->timeToFreqFFTPlan);
3089 
3090 
3091  for(j=lower;j<upper;j++){
3092  windTimeData->data->data[j] /= sqrt(data->window->sumofsquares / data->window->data->length);
3093  /* Add data in freq stream */
3094  data->freqData->data->data[j]+=crect(prefactor *creal(injF->data->data[j])/WinNorm,prefactor *cimag(injF->data->data[j])/WinNorm);
3095  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];
3096  }
3097 
3098  tmp*=2.*injF->deltaF;
3099  printf("Injected SNR %.3f in IFO %s from MDC \n",sqrt(2*tmp),data->name);
3100  data->SNR=sqrt(2*tmp);
3101  net_snr+=2*tmp;
3102  i++;
3103  data=data->next;
3104  }
3105  printf("Injected network SNR %.3f from MDC\n",sqrt(net_snr));
3106 
3107  char SNRpath[FILENAME_MAX+100];
3108  ppt=LALInferenceGetProcParamVal(commandLine,"--outfile");
3109  if(!ppt){
3110  fprintf(stderr,"Must specify --outfile <filename.dat>\n");
3111  exit(1);
3112  }
3113  char *outfile=ppt->value;
3114  snprintf(SNRpath,sizeof(SNRpath),"%s_snr.txt",outfile);
3115  ppt=LALInferenceGetProcParamVal(commandLine,"--dont-dump-extras");
3116  if (!ppt){
3117  PrintSNRsToFile(IFOdata , SNRpath);
3118  }
3119  return ;
3120 
3121 }
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)
const char * XLALSimInspiralGetStringFromApproximant(Approximant approximant)
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)
#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)
SimBurst * XLALSimBurstTableFromLIGOLw(const char *filename)
SimInspiralTable * XLALSimInspiralTableFromLIGOLw(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)
REAL8FrequencySeries * XLALCreateREAL8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
COMPLEX8FrequencySeries * XLALCreateCOMPLEX8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
COMPLEX16FrequencySeries * XLALCreateCOMPLEX16FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCOMPLEX8FrequencySeries(COMPLEX8FrequencySeries *series)
void XLALDestroyCOMPLEX16FrequencySeries(COMPLEX16FrequencySeries *series)
void LALGenerateInspiral(LALStatus *status, CoherentGW *waveform, SimInspiralTable *params, PPNParamStruc *ppnParamsInputOutput)
LALCache * XLALCacheImport(const char *fname)
void XLALDestroyCache(LALCache *cache)
LALCache * XLALCacheGlob(const char *dirstr, const char *fnptrn)
int XLALCacheSieve(LALCache *cache, INT4 t0, INT4 t1, const char *srcregex, const char *dscregex, const char *urlregex)
LALCache * XLALCacheDuplicate(const LALCache *cache)
#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 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.
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
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
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...
LALInferenceVariables * LALInferencePrintInjectionSample(LALInferenceRunState *runState)
Function to output a sample with logL values etc for the injection, if one is made.
void LALInferenceSetupROQmodel(LALInferenceModel *model, ProcessParamsTable *commandLine)
void LALInferenceSetupROQdata(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
void LALInferenceInjectFromMDC(ProcessParamsTable *commandLine, LALInferenceIFOData *IFOdata)
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 * XLALCalloc(size_t m, size_t n)
void * XLALMalloc(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)
REAL8Sequence * XLALCreateREAL8Sequence(size_t length)
COMPLEX16Sequence * XLALCreateCOMPLEX16Sequence(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)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
REAL8TimeSeries * XLALShrinkREAL8TimeSeries(REAL8TimeSeries *series, size_t first, size_t length)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
REAL4TimeSeries * XLALCutREAL4TimeSeries(const REAL4TimeSeries *series, size_t first, size_t length)
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, 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(...)
#define XLAL_ERROR_NULL(...)
int * XLALGetErrnoPtr(void)
const char * XLALErrorString(int errnum)
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_TRY(statement, errnum)
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 * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
LIGOTimeGPS * XLALGPSAddGPS(LIGOTimeGPS *epoch, const LIGOTimeGPS *dt)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
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