Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
blindinj.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Patrick Brady, Stephen Fairhurst
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/*-----------------------------------------------------------------------
21 *
22 * File Name: blindinj.c
23 *
24 * Author: Fairhurst, S
25 *
26 *
27 *-----------------------------------------------------------------------
28 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <config.h>
33
34#include <math.h>
35#include <ctype.h>
36#include <string.h>
37#include <time.h>
38#include <lal/LALStdio.h>
39#include <lal/LALgetopt.h>
40#include <lal/LALStdlib.h>
41#include <lal/LALConstants.h>
42#include <lal/LIGOLwXML.h>
43#include <lal/LIGOMetadataTables.h>
44#include <lal/LIGOMetadataUtils.h>
45#include <lal/LIGOMetadataInspiralUtils.h>
46#include <lal/LIGOMetadataRingdownUtils.h>
47#include <lal/Units.h>
48#include <lal/Date.h>
49#include <lal/InspiralInjectionParams.h>
50#include <lal/GenerateInspiral.h>
51#include <lal/GenerateInspRing.h>
52#include <lal/FindChirp.h>
53#include <lal/RingUtils.h>
54#include <lal/LALNoiseModels.h>
55#include <lal/RealFFT.h>
56#include <lal/FrequencySeries.h>
57#include <lal/TimeSeries.h>
58#include <lal/TimeFreqFFT.h>
59#include <lal/VectorOps.h>
60#include <LALAppsVCSInfo.h>
61
62#define CVS_ID_STRING "$Id$"
63#define CVS_NAME_STRING "$Name$"
64#define CVS_REVISION "$Revision$"
65#define CVS_SOURCE "$Source$"
66#define CVS_DATE "$Date$"
67#define PROGRAM_NAME "blindinj"
68
69#define USAGE \
70 "lalapps_blindinj [options]\n"\
71"\nDefaults are shown in brackets\n\n" \
72" --help display this message\n"\
73" --version print version information and exit\n"\
74" --verbose be verbose\n"\
75" --gps-start-time TIME start time of injection\n"\
76" --injection-type TYPE type of injection, must be one of \n"\
77" (strain, etmx, etmy)\n"\
78" --seed SEED seed random number generator with SEED (1)\n"\
79"\n"
80
81/* global definitions */
82
83typedef enum
84{
92
93typedef struct actuationparameters {
102
104 const char *name,
105 const char *type,
106 const char *fmt, ... );
107
108static void destroyCoherentGW( CoherentGW *waveform );
109
112 SimInspiralTable *inspInj,
113 SimRingdownTable *ringdownevents,
114 ResponseFunction responseType,
115 InterferometerNumber ifoNumber,
116 LIGOTimeGPS epoch);
117
118extern int vrbflg;
119
120/* Actuation function parameters */
122REAL8 dynRange = 1.0/3.0e-23;/* dynamic range rescaling */
123INT4 duration = 100.0; /* length of output data stream */
124INT4 sampleRate = 16384; /* sample rate of output channel */
125
126/* default values of various things */
127REAL4 fLower = 30; /* start frequency of injection */
128REAL4 mergerLength = 10; /* length in ms of the merger */
129REAL8 longestSignal = 95.0;/* length of 1.0 - 1.0 from 30 Hz */
130REAL8 timeWindow = 4; /* injection can be delayed by up to this
131 number of seconds */
132UINT4 numInjections = 0; /* number of injections we have generated */
134REAL4 minNSMass = 1.0; /* minimum NS component mass */
135REAL4 maxNSMass = 2.0; /* maximum NS component mass */
136REAL4 minBHMass = 2.0; /* minimum BH component mass */
137REAL4 maxBHMass = 30.0; /* maximum BH component mass */
138REAL4 minTotalMass = 0.0; /* minimum total mass */
139REAL4 maxTotalMass = 35.0; /* maximum total mass */
140
141REAL4 minNSSpin = 0.0; /* minimum NS component spin */
142REAL4 maxNSSpin = 0.2; /* maximum NS component spin */
143REAL4 minBHSpin = 0.0; /* minimum BH component spin */
144REAL4 maxBHSpin = 1.0; /* maximum BH component spin */
145
146REAL4 BNSfrac = 0.35; /* fraction of injections which are BNS */
147REAL4 BBHfrac = 0.35; /* fraction of injections which are BBH */
148/* 1 - BNSfrac - BBHfrac are NS-BH inj */
149
150REAL4 bnsSnrMean = 9.0; /* mean single ifo snr of bns injection */
151REAL4 bnsSnrStd = 0.5; /* std of single ifo snr of bns injection */
152REAL4 snrMean = 12.0; /* mean single ifo snr of injection */
153REAL4 snrStd = 1.0; /* std of single ifo snr of injection */
154/* snrs assume detectors at design */
155REAL4Vector *normalDev; /* vector to store normally distributed vars*/
156
157/* functions */
158
160 const char *name,
161 const char *type,
162 const char *fmt, ... )
163{
165 va_list ap;
166 pp = calloc( 1, sizeof( *pp ) );
167
168 if ( ! pp )
169 {
170 perror( "next_process_param" );
171 exit( 1 );
172 }
173 strncpy( pp->program, PROGRAM_NAME, LIGOMETA_PROGRAM_MAX );
174 if ( ! strcmp( name, "userTag" ) || ! strcmp( name, "user-tag" ) )
175 snprintf( pp->param, LIGOMETA_PARAM_MAX, "-userTag" );
176 else
177 snprintf( pp->param, LIGOMETA_PARAM_MAX, "--%s", name );
178 strncpy( pp->type, type, LIGOMETA_TYPE_MAX - 1 );
179 va_start( ap, fmt );
180 vsnprintf( pp->value, LIGOMETA_VALUE_MAX, fmt, ap );
181 va_end( ap );
182
183 return pp;
184}
185
186static void destroyCoherentGW( CoherentGW *waveform )
187{
188 if ( waveform->h )
189 {
191 LALFree( waveform->a );
192 }
193 if ( waveform->a )
194 {
196 LALFree( waveform->a );
197 }
198 if ( waveform->phi )
199 {
200 XLALDestroyREAL8Vector( waveform->phi->data );
201 LALFree( waveform->phi );
202 }
203 if ( waveform->f )
204 {
206 LALFree( waveform->f );
207 }
208 if ( waveform->shift )
209 {
210 XLALDestroyREAL4Vector( waveform->shift->data );
211 LALFree( waveform->shift );
212 }
213
214 return;
215}
216
219 SimInspiralTable *inspInj,
220 SimRingdownTable *ringdownevents,
221 ResponseFunction responseType,
222 InterferometerNumber ifoNumber,
223 LIGOTimeGPS epoch)
224{
225 REAL4TimeSeries *chan;
227 COMPLEX8Vector *unity;
230 PPNParamStruc ppnParams;
231 SimRingdownTable *thisRingdownEvent = NULL;
232
233 INT8 waveformStartTime;
235 CoherentGW waveform, *wfm;
236 ActuationParameters actData = actuationParams[ifoNumber];
237 UINT4 i,k;
238 int injectSignalType = LALRINGDOWN_IMR_INJECT;
239 const LALUnit strainPerCount = {0,{0,0,0,0,0,1,-1},{0,0,0,0,0,0,0}};
240 FILE *fp = NULL;
241 char fileName[FILENAME_MAX];
242
243 /* set up the channel to which we add the injection */
244 XLALReturnIFO( ifo, ifoNumber );
245 snprintf( name, LALNameLength, "%s:INJECT", ifo );
248 if ( ! chan )
249 {
250 exit( 1 );
251 }
252
253 memset( chan->data->data, 0, chan->data->length * sizeof(REAL4) );
254
255 thisRingdownEvent = ringdownevents;
256
257 /*
258 *
259 * Generate the Waveforms
260 *
261 */
262
263 /* fixed waveform injection parameters */
264 memset( &ppnParams, 0, sizeof(PPNParamStruc) );
265 ppnParams.deltaT = chan->deltaT;
266 ppnParams.lengthIn = 0;
267 ppnParams.ppn = NULL;
268
269 memset( &waveform, 0, sizeof(CoherentGW) );
270
271 LAL_CALL( LALGenerateInspiral(status, &waveform, inspInj, &ppnParams),
272 status);
273
274 /* add the ringdown */
275 wfm = XLALGenerateInspRing( &waveform, inspInj, thisRingdownEvent,
276 injectSignalType );
277
278 if ( !wfm )
279 {
280 fprintf( stderr, "Failed to generate the waveform \n" );
281 if (xlalErrno == XLAL_EFAILED)
282 {
283 fprintf( stderr, "Too much merger\n");
286 return ( NULL );
287 }
288 else exit ( 1 );
289 }
290
291 waveform = *wfm;
292
293 /* write out the waveform */
294 if ( ifoNumber == LAL_IFO_H1 && vrbflg )
295 {
296 fprintf( stdout,
297 "Writing out A+, Ax, f, phi, shift for waveform "
298 "to file named INSPIRAL_WAVEFORM.dat\n");
299 snprintf( fileName, FILENAME_MAX, "INSPIRAL_WAVEFORM.dat");
300 fp = fopen(fileName, "w");
301 for ( i = 0; i < waveform.phi->data->length; i++ )
302 {
303 if ( waveform.shift ) fprintf( fp, "%e\t %e\t %f\t %f\t %f\n",
304 waveform.a->data->data[2*i],
305 waveform.a->data->data[2*i+1], waveform.f->data->data[i],
306 waveform.phi->data->data[i] , waveform.shift->data->data[i] );
307
308 else fprintf( fp, "%e\t %e\t %f\t %f\n",
309 waveform.a->data->data[2*i],
310 waveform.a->data->data[2*i+1], waveform.f->data->data[i],
311 waveform.phi->data->data[i] );
312 }
313 fclose( fp );
314 }
315
316 /*
317 *
318 * set up the response function
319 *
320 */
321
322 resp = XLALCreateCOMPLEX8FrequencySeries( chan->name, &(chan->epoch), 0,
323 1.0 / ( duration ), &strainPerCount, ( sampleRate * duration / 2 + 1 ) );
324
325 switch ( responseType )
326 {
327 case noResponse:
328 fprintf( stderr, "Must specify the response function\n" );
329 exit( 1 );
330 break;
331
332 case unityResponse:
333 /* set the response function to unity */
334 for ( k = 0; k < resp->data->length; ++k )
335 {
336 resp->data->data[k] = crectf( (REAL4) (1.0 /dynRange), 0.0 );
337 }
338 break;
339
340 case LIGOdesign:
341 /* set the response function to LIGO design */
342 for ( k = 0; k < resp->data->length; ++k )
343 {
344 REAL8 sim_psd_freq = (REAL8) k * resp->deltaF;
345 REAL8 sim_psd_value;
346 LALLIGOIPsd( NULL, &sim_psd_value, sim_psd_freq );
347 resp->data->data[k] = crectf( (REAL4) pow( sim_psd_value, 0.5 ) / dynRange, 0.0 );
348 }
349 break;
350
351 case actuationX:
352 /* actuation units are m/count so we must divide by arm length */
353 resp = generateActuation( resp, actData.ETMXcal / actData.length,
354 actData.pendFX, actData.pendQX);
355 break;
356
357 case actuationY:
358 /* actuation units are m/count so we must divide by arm length */
359 resp = generateActuation( resp, actData.ETMYcal / actData.length,
360 actData.pendFY, actData.pendQY);
361 break;
362 }
363
364 /*
365 *
366 * set up the detector structure
367 *
368 */
369
370 /* allocate memory and copy the parameters describing the freq series */
371 memset( &detector, 0, sizeof( DetectorResponse ) );
372 detector.site = (LALDetector *) LALMalloc( sizeof(LALDetector) );
373 XLALReturnDetector( detector.site, ifoNumber );
375 &(chan->epoch), 0, 1.0 / ( duration ), &strainPerCount,
376 ( sampleRate * duration / 2 + 1 ) );
377
378 XLALUnitInvert( &(detector.transfer->sampleUnits), &(resp->sampleUnits) );
379
380 /* invert the response function to get the transfer function */
381 unity = XLALCreateCOMPLEX8Vector( resp->data->length );
382 for ( k = 0; k < unity->length; ++k )
383 {
384 unity->data[k] = 1.0;
385 }
386
387 XLALCCVectorDivide( detector.transfer->data, unity, resp->data );
389
390 /* set the injection time */
391 waveformStartTime = XLALGPSToINT8NS( &(inspInj->geocent_end_time));
392 waveformStartTime -= (INT8) ( 1000000000.0 * ppnParams.tc );
393
394 XLALINT8NSToGPS( &(waveform.a->epoch), waveformStartTime );
395 memcpy(&(waveform.f->epoch), &(waveform.a->epoch),
396 sizeof(LIGOTimeGPS) );
397 memcpy(&(waveform.phi->epoch), &(waveform.a->epoch),
398 sizeof(LIGOTimeGPS) );
399
400 /* perform the injection */
402 status);
403
406 if ( detector.site ) LALFree( detector.site );
407
409 return( chan );
410}
411
412/*
413 *
414 * MAIN CODE
415 *
416 */
417
418int main( int argc, char *argv[] )
419{
421 LIGOTimeGPS gpsStartTime = {0, 0};
422 LIGOTimeGPS earliestEndTime = {0, 0};
423 ResponseFunction injectionResponse = noResponse;
424
425 /* program variables */
426 RandomParams *randParams = NULL;
427 REAL4 massPar = 0;
430 REAL4 desiredSnr = 0;
431 REAL4 snrsqAt1Mpc = 0;
432 REAL4TimeSeries *chan = NULL;
433 REAL4FFTPlan *pfwd;
435
436 /* waveform */
438
439 /* xml output data */
440 CHAR fname[FILENAME_MAX];
441 ProcessTable *proctable;
442 ProcessParamsTable *procparams;
443 SimInspiralTable *inspInjections;
444 SimRingdownTable *ringInjections;
445 ProcessParamsTable *this_proc_param;
446 SimInspiralTable *inj = NULL;
447 SimRingdownTable *ringList = NULL;
449 FILE *fp = NULL;
450
451 /* LALgetopt arguments */
452 struct LALoption long_options[] =
453 {
454 {"help", no_argument, 0, 'h'},
455 {"verbose", no_argument, &vrbflg, 1 },
456 {"version", no_argument, 0, 'V'},
457 {"gps-start-time", required_argument, 0, 'a'},
458 {"injection-type", required_argument, 0, 't'},
459 {"seed", required_argument, 0, 's'},
460 {0, 0, 0, 0}
461 };
462 int c;
463
464
465 /*taken from Calibration CVS file:
466 * calibration/frequencydomain/runs/S5/H1/model/V3/H1DARMparams_849677446.m */
474
475 /*taken from Calibration CVS file:
476 * calibration/frequencydomain/runs/S5/H2/model/V3/H2DARMparams_849678155.m */
484
485 /*taken from Calibration CVS file:
486 * calibration/frequencydomain/runs/S5/L1/model/V3/L1DARMparams_841930071.m */
494
495 /* set up inital debugging values */
497
498
499 /* create the process and process params tables */
500 proctable = (ProcessTable *)
501 calloc( 1, sizeof(ProcessTable) );
502 XLALGPSTimeNow(&(proctable->start_time));
505 snprintf( proctable->comment, LIGOMETA_COMMENT_MAX, " " );
506 this_proc_param = procparams = (ProcessParamsTable *)
507 calloc( 1, sizeof(ProcessParamsTable) );
508
509 /* clear the waveform field */
510 memset( waveform, 0, LIGOMETA_WAVEFORM_MAX * sizeof(CHAR) );
511 snprintf( waveform, LIGOMETA_WAVEFORM_MAX, "SpinTaylorthreePN");
512
513 /*
514 *
515 * parse command line arguments
516 *
517 */
518
519
520 while ( 1 )
521 {
522 /* LALgetopt_long stores long option here */
523 int option_index = 0;
524 long int gpsinput;
525
526 c = LALgetopt_long_only( argc, argv, "a:hs:t:V", long_options, &option_index );
527
528 /* detect the end of the options */
529 if ( c == - 1 )
530 {
531 break;
532 }
533
534 switch ( c )
535 {
536 case 0:
537 /* if this option set a flag, do nothing else now */
538 if ( long_options[option_index].flag != 0 )
539 {
540 break;
541 }
542 else
543 {
544 fprintf( stderr, "error parsing option %s with argument %s\n",
545 long_options[option_index].name, LALoptarg );
546 exit( 1 );
547 }
548 break;
549
550 case 'a':
551 gpsinput = atol( LALoptarg );
552 if ( gpsinput < 441417609 )
553 {
554 fprintf( stderr, "invalid argument to --%s:\n"
555 "GPS start time is prior to "
556 "Jan 01, 1994 00:00:00 UTC:\n"
557 "(%ld specified)\n",
558 long_options[option_index].name, gpsinput );
559 exit( 1 );
560 }
561 gpsStartTime.gpsSeconds = gpsinput;
562
563 this_proc_param = this_proc_param->next =
564 next_process_param( long_options[option_index].name, "int",
565 "%ld", gpsinput );
566 break;
567
568 case 's':
569 randSeed = atoi( LALoptarg );
570 this_proc_param = this_proc_param->next =
571 next_process_param( long_options[option_index].name, "int",
572 "%d", randSeed );
573 break;
574
575 case 't':
576 /* set the injection type */
577 if ( ! strcmp( "strain", LALoptarg ) )
578 {
579 injectionResponse = unityResponse;
580 }
581 else if ( ! strcmp( "etmx", LALoptarg ) )
582 {
583 injectionResponse = actuationX;
584 }
585 else if ( ! strcmp( "etmy", LALoptarg ) )
586 {
587 injectionResponse = actuationY;
588 }
589 else
590 {
591 fprintf( stderr, "invalid argument to --%s:\n"
592 "unknown injection type specified: "
593 "%s (must be strain, etmx or etmy)\n",
594 long_options[option_index].name, LALoptarg );
595 exit( 1 );
596 }
597 next_process_param( long_options[option_index].name, "string", "%s",
598 LALoptarg );
599 break;
600
601 case 'V':
602 /* print version information and exit */
603 fprintf( stdout, "blind hardware injection generation routine\n"
604 "Stephen Fairhurst\n");
605 XLALOutputVCSInfo(stderr, lalAppsVCSInfoList, 0, "%% ");
606 exit( 0 );
607 break;
608
609 case 'h':
610 case '?':
611 fprintf( stderr, USAGE );
612 exit( 0 );
613 break;
614
615 default:
616 fprintf( stderr, "unknown error while parsing options\n" );
617 fprintf( stderr, USAGE );
618 exit( 1 );
619 }
620 }
621
622 if ( LALoptind < argc )
623 {
624 fprintf( stderr, "extraneous command line arguments:\n" );
625 while ( LALoptind < argc )
626 {
627 fprintf ( stderr, "%s\n", argv[LALoptind++] );
628 }
629 exit( 1 );
630 }
631
632 /* check the input arguments */
633 if ( injectionResponse == noResponse )
634 {
635 fprintf( stderr, "Must specify the --injection-type\n" );
636 exit( 1 );
637 }
638
639 if ( gpsStartTime.gpsSeconds <= 0 )
640 {
641 fprintf( stderr, "Must specify the --gps-start-time\n" );
642 exit( 1 );
643 }
644
645 /*
646 *
647 * initialization
648 *
649 */
650
651
652 /* initialize the random number generator */
654
655
656 /*
657 *
658 * create a random injection
659 *
660 */
661
662 /* create the sim_inspiral table */
663 inspInjections = inj = (SimInspiralTable *)
664 LALCalloc( 1, sizeof(SimInspiralTable) );
665
666 ringInjections = ringList = (SimRingdownTable *)
667 LALCalloc( 1, sizeof(SimRingdownTable) );
668
669
670 /* set the geocentric end time of the injection */
671 earliestEndTime = gpsStartTime;
672 earliestEndTime = *XLALGPSAdd( &earliestEndTime, longestSignal );
673 inj = XLALRandomInspiralTime( inj, randParams, earliestEndTime,
674 timeWindow );
675
676 /* set the distance of the injection to 1 Mpc */
677 inj->distance = 1.0;
678
679 /* set the masses */
680 massPar = XLALUniformDeviate( randParams );
681
682 if ( vrbflg) fprintf( stdout,
683 "Random variable to determine inj type = %f\n",
684 massPar);
685
686 while ( numInjections == 0 )
687 {
688
691
692 if ( massPar < BNSfrac )
693 {
694 if ( vrbflg ) fprintf( stdout, "Generating a BNS injection\n" );
695 inj = XLALRandomInspiralMasses( inj, randParams, mDist,
698 maxNSSpin, minNSSpin, maxNSSpin, -1.0, 1.0, 0.0, 0.1, 0, uniformSpinDist, 0.0, 0.0, 0.0, 0.0);
699 desiredSnr = bnsSnrMean + bnsSnrStd * normalDev->data[0];
700 }
701 else if ( massPar < (BNSfrac + BBHfrac) )
702 {
703 if ( vrbflg ) fprintf( stdout, "Generating a BBH injection\n" );
704 inj = XLALRandomInspiralMasses( inj, randParams, mDist,
707 maxBHSpin, minBHSpin, maxBHSpin , -1.0, 1.0, 0.0, 0.1, 0, uniformSpinDist, 0.0, 0.0, 0.0, 0.0);
708 desiredSnr = snrMean + snrStd * normalDev->data[0];
709 }
710 else
711 {
712 if ( vrbflg ) fprintf( stdout, "Generating an NS - BH injection\n" );
713 inj = XLALRandomInspiralMasses( inj, randParams, mDist,
716 maxNSSpin, minBHSpin, maxBHSpin , -1.0, 1.0, 0.0, 0.1, 0, uniformSpinDist, 0.0, 0.0, 0.0, 0.0);
717 desiredSnr = snrMean + snrStd * normalDev->data[0];
718 }
720
721
722 /* set the sky location */
725 inj = XLALRandomInspiralOrientation( inj, randParams, iDist, 0);
726
727 /* set the source and waveform fields */
728 snprintf( inj->source, LIGOMETA_SOURCE_MAX, "???" );
729 memcpy( inj->waveform, waveform, LIGOMETA_WAVEFORM_MAX * sizeof(CHAR));
730
731 /* populate the site specific information */
733
734 /* finally populate the flower */
735 inj->f_lower = fLower;
736
737
738 /*
739 *
740 * perform the injection
741 *
742 */
743
744 if ( vrbflg ) fprintf( stdout, "Injection details\n"
745 "mass 1 = %.2f;\t spin 1 = (%.2f, %.2f, %.2f)\n"
746 "mass 2 = %.2f;\t spin 2 = (%.2f, %.2f, %.2f)\n"
747 "Hanford effective distance = %.2f Mpc\n"
748 "Livingston effective distance = %.2f Mpc\n",
749 inj->mass1, inj->spin1x, inj->spin1y, inj->spin1z,
750 inj->mass2, inj->spin2x, inj->spin2y, inj->spin2z,
751 inj->eff_dist_h,
752 inj->eff_dist_l );
753
754 for ( ifoNumber = 0; ifoNumber < LAL_NUM_IFO; ifoNumber++ )
755 {
756 if ( ifoNumber == LAL_IFO_H1 || ifoNumber == LAL_IFO_L1 )
757 {
758 ResponseFunction responseType = unityResponse;
759 REAL4 thisSnrsq = 0;
760 UINT4 k;
761
762 chan = injectWaveform( &status, inj, ringList, responseType, ifoNumber,
764
765 if ( ! chan )
766 {
767 if ( vrbflg ) fprintf( stdout,
768 "Unable to generate a realistic merger for this inspiral\n"
769 "Trying again with different parameters\n" );
770 break;
771 }
772 else if ( ifoNumber == LAL_IFO_H1 ) numInjections++;
773
774
775 /*
776 *
777 * calculate the snr for the injection
778 *
779 */
780
781 /* fft the output */
782 pfwd = XLALCreateForwardREAL4FFTPlan( chan->data->length, 0 );
784 &(chan->epoch), 0, 1.0/chan->deltaT, &lalDimensionlessUnit,
785 chan->data->length/2 + 1 );
786 XLALREAL4TimeFreqFFT( fftData, chan, pfwd );
788
789 /* compute the SNR for initial LIGO at design */
790 thisSnrsq = 0;
791 for ( k = 0; k < fftData->data->length; k++ )
792 {
793 REAL8 freq;
794 REAL8 sim_psd_value;
795 freq = fftData->deltaF * k;
796 LALLIGOIPsd( NULL, &sim_psd_value, freq );
797 thisSnrsq += crealf(fftData->data->data[k]) * crealf(fftData->data->data[k]) /
798 sim_psd_value;
799 thisSnrsq += cimagf(fftData->data->data[k]) * cimagf(fftData->data->data[k]) /
800 sim_psd_value;
801 }
802 thisSnrsq *= 4*fftData->deltaF;
804
805 if ( ifoNumber == LAL_IFO_H1 )
806 {
807 /* add in H2, assuming half the snr */
808 snrsqAt1Mpc += 5.0/4.0 * thisSnrsq;
809 }
810 else
811 {
812 snrsqAt1Mpc += thisSnrsq;
813 }
814 if ( vrbflg )
815 {
817 XLALReturnIFO( ifo, ifoNumber );
818 fprintf(stdout,
819 "For %s, the SNR at distance of 1 Mpc is %.2f\n", ifo,
820 pow(thisSnrsq, 0.5));
821 }
823 }
824 }
825
826 if ( numInjections )
827 {
828 /* scale the distance so the combined snr is equal to desired value */
829 desiredSnr *= 1.5;
830 inj->distance = 1.0 * pow( snrsqAt1Mpc, 0.5 ) / desiredSnr;
832 if ( vrbflg ) fprintf( stdout,
833 "Rescaling the distance to %.2f to give a combined snr of %.2f\n",
834 inj->distance, desiredSnr);
835
836 /*
837 *
838 * compute the waveforms for injection
839 *
840 */
841
842 for ( ifoNumber = 0; ifoNumber < LAL_NUM_IFO; ifoNumber++ )
843 {
844 if ( ifoNumber == LAL_IFO_H1 || ifoNumber == LAL_IFO_H2 ||
845 ifoNumber == LAL_IFO_L1 )
846 {
847 UINT4 k;
850
851 XLALReturnIFO( ifo, ifoNumber );
852
853 if ( injectionResponse == unityResponse )
854 {
855 snprintf( type, LIGOMETA_COMMENT_MAX, "STRAIN");
856 if ( vrbflg ) fprintf( stdout,
857 "Generating h(t) injection for %s\n", ifo );
858 }
859 if ( injectionResponse == actuationX )
860 {
861 snprintf( type, LIGOMETA_COMMENT_MAX, "ETMX");
862 if ( vrbflg ) fprintf( stdout,
863 "Generating ETMX hardware injection for %s\n", ifo );
864 }
865 if ( injectionResponse == actuationY )
866 {
867 snprintf( type, LIGOMETA_COMMENT_MAX, "ETMY");
868 if (vrbflg ) fprintf( stdout,
869 "Generating ETMY hardware injection for %s\n", ifo );
870 }
871
872 chan = injectWaveform( &status, inj, ringList, injectionResponse,
873 ifoNumber, gpsStartTime);
874
875 snprintf( fname, FILENAME_MAX,
876 "%s-HARDWARE-INJECTION_%d_%s-%d-%d.txt",
878 if ( vrbflg ) fprintf( stdout, "Writing waveform to %s\n", fname);
879
880 fp = fopen( fname, "w" );
881 for ( k = 0; k < chan->data->length; k++ )
882 {
883 if ( injectionResponse == unityResponse )
884 {
885 /* we have to fix the dynamic range scaling */
886 fprintf( fp, "%e\n", chan->data->data[k] / dynRange );
887 }
888 else
889 {
890 fprintf( fp, "%e\n", chan->data->data[k] );
891 }
892 }
893
894 fclose( fp );
895
897 }
898 }
899 }
900 }
901
902 /*
903 *
904 * write output to LIGO_LW XML file
905 *
906 */
907
908 /* create the output file name */
909 snprintf( fname, sizeof(fname), "HL-INJECTIONS_%d-%d-%d.xml",
911
912 if ( vrbflg ) fprintf( stdout, "Writing the injection details to %s\n",
913 fname);
914
915 /* open the xml file */
917
918 /* write the process table */
919 snprintf( proctable->ifos, LIGOMETA_IFOS_MAX, "H1H2L1" );
920 XLALGPSTimeNow(&(proctable->end_time));
922 free( proctable );
923
924 /* free the unused process param entry */
925 this_proc_param = procparams;
926 procparams = procparams->next;
927 free( this_proc_param );
928
929 /* write the process params table */
930 if ( procparams )
931 {
933 while( procparams )
934 {
935 this_proc_param = procparams;
936 procparams = this_proc_param->next;
937 free( this_proc_param );
938 }
939 }
940
941 /* write the sim_inspiral table */
942 XLALSimInspiralAssignIDs ( inspInjections, 0, 0 );
943 if ( inspInjections )
944 XLALWriteLIGOLwXMLSimInspiralTable( xmlfp, inspInjections );
945 XLALDestroySimInspiralTable( inspInjections );
946
947
948 /* write the sim_ringdown table */
949 if ( ringInjections )
950 XLALWriteLIGOLwXMLSimRingdownTable( xmlfp, ringInjections );
951 XLALDestroySimRingdownTable( ringInjections );
952
953
954 /* close the injection file */
956
957 /* destroy random parameters */
959
960 /* check for memory leaks and exit */
962 return 0;
963}
const LALVCSInfoList lalAppsVCSInfoList
NULL-terminated list of VCS and build information for LALApps and its dependencies
const LALVCSInfo lalAppsVCSIdentInfo
Identable VCS and build information for LALApps.
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
#define LAL_CALL(function, statusptr)
int k
void LALCheckMemoryLeaks(void)
#define LALCalloc(m, n)
#define LALMalloc(n)
#define LALFree(p)
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
int LALoptind
char * LALoptarg
#define no_argument
#define required_argument
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLProcessTable(LIGOLwXMLStream *, const ProcessTable *)
int XLALWriteLIGOLwXMLProcessParamsTable(LIGOLwXMLStream *, const ProcessParamsTable *)
int XLALWriteLIGOLwXMLSimRingdownTable(LIGOLwXMLStream *xml, const SimRingdownTable *sim_ringdown)
int XLALWriteLIGOLwXMLSimInspiralTable(LIGOLwXMLStream *, const SimInspiralTable *)
LALRINGDOWN_IMR_INJECT
#define LIGOMETA_IFOS_MAX
#define LIGOMETA_COMMENT_MAX
#define LIGOMETA_TYPE_MAX
#define LIGOMETA_WAVEFORM_MAX
#define LIGOMETA_PROGRAM_MAX
#define LIGOMETA_SOURCE_MAX
#define LIGOMETA_VALUE_MAX
#define LIGOMETA_PARAM_MAX
#define LIGOMETA_IFO_MAX
InterferometerNumber
LAL_UNKNOWN_IFO
LAL_NUM_IFO
LAL_IFO_H1
LAL_IFO_H2
LAL_IFO_L1
void XLALReturnDetector(LALDetector *det, InterferometerNumber IFONumber)
void XLALReturnIFO(char *ifo, InterferometerNumber IFONumber)
void XLALDestroySimInspiralTable(SimInspiralTable *head)
int XLALPopulateProcessTable(ProcessTable *ptable, const char *program_name, const char *cvs_revision, const char *cvs_source, const char *cvs_date, long process_id)
long XLALSimInspiralAssignIDs(SimInspiralTable *head, long process_id, long simulation_id)
void XLALDestroySimRingdownTable(SimRingdownTable *head)
void LALSimulateCoherentGW(LALStatus *status, REAL4TimeSeries *output, CoherentGW *input, DetectorResponse *detector)
#define fprintf
int main(int argc, char *argv[])
Definition: blindinj.c:418
static REAL4TimeSeries * injectWaveform(LALStatus *status, SimInspiralTable *inspInj, SimRingdownTable *ringdownevents, ResponseFunction responseType, InterferometerNumber ifoNumber, LIGOTimeGPS epoch)
Definition: blindinj.c:217
REAL8 longestSignal
Definition: blindinj.c:129
REAL4 fLower
Definition: blindinj.c:127
#define PROGRAM_NAME
Definition: blindinj.c:67
INT4 randSeed
Definition: blindinj.c:133
REAL8 dynRange
Definition: blindinj.c:122
REAL4 maxNSSpin
Definition: blindinj.c:142
REAL4 minNSMass
Definition: blindinj.c:134
REAL4 minNSSpin
Definition: blindinj.c:141
#define USAGE
Definition: blindinj.c:69
UINT4 numInjections
Definition: blindinj.c:132
REAL4 BBHfrac
Definition: blindinj.c:147
REAL4Vector * normalDev
Definition: blindinj.c:155
INT4 sampleRate
Definition: blindinj.c:124
INT4 duration
Definition: blindinj.c:123
REAL4 BNSfrac
Definition: blindinj.c:146
REAL4 maxBHSpin
Definition: blindinj.c:144
ActuationParameters actuationParams[LAL_NUM_IFO]
Definition: blindinj.c:121
REAL4 minBHSpin
Definition: blindinj.c:143
REAL4 snrStd
Definition: blindinj.c:153
int vrbflg
defined in lal/lib/std/LALError.c
REAL4 mergerLength
Definition: blindinj.c:128
REAL8 timeWindow
Definition: blindinj.c:130
REAL4 maxTotalMass
Definition: blindinj.c:139
static void destroyCoherentGW(CoherentGW *waveform)
Definition: blindinj.c:186
REAL4 snrMean
Definition: blindinj.c:152
REAL4 bnsSnrMean
Definition: blindinj.c:150
ResponseFunction
Definition: blindinj.c:84
@ actuationX
Definition: blindinj.c:88
@ unityResponse
Definition: blindinj.c:86
@ noResponse
Definition: blindinj.c:85
@ actuationY
Definition: blindinj.c:89
@ LIGOdesign
Definition: blindinj.c:87
REAL4 bnsSnrStd
Definition: blindinj.c:151
static ProcessParamsTable * next_process_param(const char *name, const char *type, const char *fmt,...)
Definition: blindinj.c:159
REAL4 minBHMass
Definition: blindinj.c:136
REAL4 maxNSMass
Definition: blindinj.c:135
REAL4 minTotalMass
Definition: blindinj.c:138
REAL4 maxBHMass
Definition: blindinj.c:137
const char * detector
const double pp
static LALUnit strainPerCount
Definition: getresp.c:41
void XLALDestroyREAL4VectorSequence(REAL4VectorSequence *vecseq)
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
void XLALDestroyCOMPLEX8FrequencySeries(COMPLEX8FrequencySeries *series)
COMPLEX8FrequencySeries * XLALCreateCOMPLEX8FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
CoherentGW * XLALGenerateInspRing(CoherentGW *waveform, SimInspiralTable *thisEvent, SimRingdownTable *thisRingEvent, int injectSignalType)
void LALGenerateInspiral(LALStatus *status, CoherentGW *waveform, SimInspiralTable *params, PPNParamStruc *ppnParamsInputOutput)
SimInspiralTable * XLALRandomInspiralSkyLocation(SimInspiralTable *inj, RandomParams *randParams)
SimInspiralTable * XLALRandomInspiralSpins(SimInspiralTable *inj, RandomParams *randParams, REAL4 spin1Min, REAL4 spin1Max, REAL4 spin2Min, REAL4 spin2Max, REAL4 kappa1Min, REAL4 kappa1Max, REAL4 abskappa1Min, REAL4 abskappa1Max, AlignmentType alignInj, SpinDistribution distribution, REAL4 spin1Mean, REAL4 spin1Std, REAL4 spin2Mean, REAL4 spin2Std)
MassDistribution
SimInspiralTable * XLALRandomInspiralTime(SimInspiralTable *inj, RandomParams *randParams, LIGOTimeGPS startTime, REAL4 timeWindow)
COMPLEX8FrequencySeries * generateActuation(COMPLEX8FrequencySeries *resp, REAL4 ETMcal, REAL4 pendF, REAL4 pendQ)
InclDistribution
SimInspiralTable * XLALPopulateSimInspiralSiteInfo(SimInspiralTable *inj)
SimInspiralTable * XLALRandomInspiralMasses(SimInspiralTable *inj, RandomParams *randParams, MassDistribution mDistr, REAL4 mass1Min, REAL4 mass1Max, REAL4 mass2Min, REAL4 mass2Max, REAL4 minTotalMass, REAL4 maxTotalMass)
SimInspiralTable * XLALRandomInspiralOrientation(SimInspiralTable *inj, RandomParams *randParams, InclDistribution iDist, REAL4 inclinationPeak)
uniformSpinDist
logComponentMass
uniformInclDist
double REAL8
#define XLAL_INIT_DECL(var,...)
int64_t INT8
#define crectf(re, im)
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
LALNameLength
void LALLIGOIPsd(LALStatus UNUSED *status, REAL8 *psd, REAL8 f)
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
RandomParams * XLALCreateRandomParams(INT4 seed)
REAL4 XLALUniformDeviate(RandomParams *params)
void XLALDestroyRandomParams(RandomParams *params)
int XLALNormalDeviates(REAL4Vector *deviates, RandomParams *params)
REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan(UINT4 size, int measurelvl)
void XLALDestroyREAL4FFTPlan(REAL4FFTPlan *plan)
int XLALREAL4TimeFreqFFT(COMPLEX8FrequencySeries *freq, const REAL4TimeSeries *tser, const REAL4FFTPlan *plan)
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
const LALUnit lalADCCountUnit
const LALUnit lalDimensionlessUnit
LALUnit * XLALUnitInvert(LALUnit *output, const LALUnit *input)
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
void XLALDestroyVector(REAL4Vector *vector)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
COMPLEX8Vector * XLALCreateCOMPLEX8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
void XLALDestroyCOMPLEX8Vector(COMPLEX8Vector *vector)
COMPLEX8Vector * XLALCCVectorDivide(COMPLEX8Vector *out, const COMPLEX8Vector *in1, const COMPLEX8Vector *in2)
#define xlalErrno
XLAL_SUCCESS
XLAL_EFAILED
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
LIGOTimeGPS * XLALINT8NSToGPS(LIGOTimeGPS *epoch, INT8 ns)
INT8 XLALGPSToINT8NS(const LIGOTimeGPS *epoch)
char * ifo
Definition: gwf2xml.c:57
LIGOTimeGPS gpsStartTime
Definition: inspfrinj.c:314
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
static LALStatus status
Definition: inspinj.c:552
int i
Definition: inspinj.c:596
type
waveform
fmt
c
float freq
float atol
RandomParams * randParams
Definition: spininj.c:212
LIGOLwXMLStream * xmlfp
Definition: spininj.c:210
CHAR fname[256]
Definition: spininj.c:211
COMPLEX8Sequence * data
COMPLEX8 * data
const char *const vcsDate
const char *const vcsStatus
const char *const vcsId
int * flag
REAL4Vector * ppn
struct tagProcessParamsTable * next
LIGOTimeGPS start_time
CHAR ifos[LIGOMETA_IFOS_MAX]
LIGOTimeGPS end_time
CHAR comment[LIGOMETA_COMMENT_MAX]
CHAR name[LALNameLength]
REAL4Sequence * data
LIGOTimeGPS epoch
REAL4 * data
LIGOTimeGPS geocent_end_time
CHAR source[LIGOMETA_SOURCE_MAX]
CHAR waveform[LIGOMETA_WAVEFORM_MAX]
FILE * fp
enum @1 epoch