LALInspiral 5.0.3.1-eeff03c
NRWaveInject.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006 S.Fairhurst, B. Krishnan, L.Santamaria
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20#include <lal/LALStdio.h>
21#include <lal/FileIO.h>
22#include <lal/NRWaveIO.h>
23#include <lal/LIGOMetadataTables.h>
24#include <lal/LIGOMetadataInspiralUtils.h>
25#include <lal/Date.h>
26#include <lal/Units.h>
27#include <lal/LALConstants.h>
28#include <lal/NRWaveInject.h>
29#include <lal/Random.h>
30#include <lal/LALSimulation.h>
31#include <lal/LALSimInspiral.h>
32#include <lal/LALDetectors.h>
33#include <lal/DetResponse.h>
34#include <lal/TimeDelay.h>
35#include <lal/SkyCoordinates.h>
36#include <lal/TimeSeries.h>
37#include <lal/FrequencySeries.h>
38#include <lal/TimeFreqFFT.h>
39#include <lal/Window.h>
40#include <lal/SphericalHarmonics.h>
41
42#include <gsl/gsl_heapsort.h>
43
44#ifdef __GNUC__
45#define UNUSED __attribute__ ((unused))
46#else
47#define UNUSED
48#endif
49
50int compare_abs_float(const void *a, const void *b);
51int compare_abs_double(const void *a, const void *b);
52
53/**
54 * Takes a strain of h+ and hx data and stores it in a temporal
55 * strain in order to perform the sum over l and m modes
56 */
59 REAL4TimeVectorSeries *tempstrain, /**< storing variable */
60 REAL4TimeVectorSeries *strain /**< variable to add */)
61{
62 UINT4 vecLength, length, k;
63
64 vecLength = strain->data->vectorLength;
65 length = strain->data->length;
66
67 for ( k = 0; k < vecLength*length; k++)
68 {
69 tempstrain->data->data[k] += strain->data->data[k];
70 }
71 return( tempstrain );
72}
73
74/* REAL8 version */
77 REAL8TimeVectorSeries *tempstrain, /**< storing variable */
78 REAL8TimeVectorSeries *strain /**< variable to add */)
79{
80 UINT4 vecLength, length, k;
81
82 vecLength = strain->data->vectorLength;
83 length = strain->data->length;
84
85 for ( k = 0; k < vecLength*length; k++)
86 {
87 tempstrain->data->data[k] += strain->data->data[k];
88 }
89 return( tempstrain );
90}
91
92
93/**
94 * Takes a (sky averaged) numerical relativity waveform and returns the
95 * waveform appropriate for given coalescence phase and inclination angles
96 */
97/* REAL4TimeVectorSeries */
98INT4
100 REAL4TimeVectorSeries *strain, /**< sky average h+, hx data */
101 UINT4 modeL, /**< L */
102 INT4 modeM, /**< M */
103 REAL4 inclination, /**< binary inclination */
104 REAL4 coa_phase /**< binary coalescence phase*/)
105{
106 COMPLEX16 MultSphHarm;
107 REAL4 tmp1, tmp2;
108 UINT4 vecLength, k;
109
110 vecLength = strain->data->vectorLength;
111
112 /* Calculating the (2,2) Spherical Harmonic */
113 /* need some error checking */
114 XLALSphHarm( &MultSphHarm, modeL, modeM, inclination, coa_phase );
115
116 /* Filling the data vector with the data multiplied by the Harmonic */
117 for ( k = 0; k < vecLength; k++)
118 {
119 tmp1 = strain->data->data[k];
120 tmp2 = strain->data->data[vecLength + k];
121
122 strain->data->data[k] =
123 (tmp1 * creal(MultSphHarm)) +
124 (tmp2 * cimag(MultSphHarm));
125
126 strain->data->data[vecLength + k] =
127 (tmp2 * creal(MultSphHarm)) -
128 (tmp1 * cimag(MultSphHarm));
129 }
130
131 return 0;
132 /* return( strain ); */
133}
134
135/**
136 * Takes a (sky averaged) numerical relativity waveform and returns the
137 * waveform appropriate for given coalescence phase and inclination angles
138 */
139void
141 REAL8TimeSeries *plus, /**< NEEDS DOCUMENTATION */
142 REAL8TimeSeries *cross, /**< NEEDS DOCUMENTATION */
143 UINT4 modeL, /**< L */
144 INT4 modeM, /**< M */
145 REAL4 inclination, /**< binary inclination */
146 REAL4 coa_phase /**< binary coalescence phase*/)
147{
148 COMPLEX16 MultSphHarm;
149 REAL4 tmp1, tmp2;
150 UINT4 vecLength, k;
151
152 vecLength = plus->data->length;
153
154 /* Calculating the (2,2) Spherical Harmonic */
155 /* need some error checking */
156 XLALSphHarm( &MultSphHarm, modeL, modeM, inclination, coa_phase );
157
158 /* Filling the data vector with the data multiplied by the Harmonic */
159 for ( k = 0; k < vecLength; k++)
160 {
161 tmp1 = plus->data->data[k];
162 tmp2 = cross->data->data[k];
163
164 plus->data->data[k] =
165 (tmp1 * creal(MultSphHarm)) +
166 (tmp2 * cimag(MultSphHarm));
167
168 cross->data->data[k] =
169 (tmp2 * creal(MultSphHarm)) -
170 (tmp1 * cimag(MultSphHarm));
171 }
172
173 return;
174}
175
176
177/**
178 * Takes a (sky averaged) numerical relativity waveform and returns the
179 * waveform appropriate for given coalescence phase and inclination angles
180 */
183 REAL8TimeVectorSeries *strain, /**< sky average h+, hx data */
184 UINT4 modeL, /**< L */
185 INT4 modeM, /**< M */
186 REAL4 inclination, /**< binary inclination */
187 REAL4 coa_phase /**< binary coalescence phase*/)
188{
189 COMPLEX16 MultSphHarm;
190 REAL4 tmp1, tmp2;
191 UINT4 vecLength, k;
192
193 vecLength = strain->data->vectorLength;
194
195 /* Calculating the (2,2) Spherical Harmonic */
196 /* need some error checking */
197 XLALSphHarm( &MultSphHarm, modeL, modeM, inclination, coa_phase );
198
199 /* Filling the data vector with the data multiplied by the Harmonic */
200 for ( k = 0; k < vecLength; k++)
201 {
202 tmp1 = strain->data->data[k];
203 tmp2 = strain->data->data[vecLength + k];
204
205 strain->data->data[k] =
206 (tmp1 * creal(MultSphHarm)) +
207 (tmp2 * cimag(MultSphHarm));
208
209 strain->data->data[vecLength + k] =
210 (tmp2 * creal(MultSphHarm)) -
211 (tmp1 * cimag(MultSphHarm));
212 }
213 return( strain );
214}
215
216
218XLALCalculateNRStrain( REAL4TimeVectorSeries *strain, /**< h+, hx time series data*/
219 SimInspiralTable *inj, /**< injection details */
220 const CHAR *ifo, /**< interferometer */
221 INT4 sampleRate /**< sample rate of time series */)
222{
223 LALDetector det;
224 double fplus;
225 double fcross;
226 double tDelay;
227 REAL4TimeSeries *htData = NULL;
228 UINT4 vecLength, k;
229
230 /* get the detector information */
231 memcpy( &det, XLALDetectorPrefixToLALDetector( ifo ), sizeof(LALDetector) );
232
233 /* compute detector response */
234 XLALComputeDetAMResponse(&fplus, &fcross, (const REAL4(*)[3])det.response, inj->longitude,
235 inj->latitude, inj->polarization, inj->end_time_gmst);
236
237 /* calculate the time delay */
239 inj->latitude, &(inj->geocent_end_time) );
240
241 /* create htData */
242 htData = LALCalloc(1, sizeof(*htData));
243 if (!htData)
244 {
246 }
247 vecLength = strain->data->vectorLength;
248 htData->data = XLALCreateREAL4Vector( vecLength );
249 if ( ! htData->data )
250 {
251 LALFree( htData );
253 }
254
255 /* store the htData */
256
257 /* add timedelay to inj->geocent_end_time */
258 {
259 REAL8 tEnd;
261 tEnd += tDelay;
262 XLALGPSSetREAL8(&(htData->epoch), tEnd );
263 }
264 /* Using XLALGPSAdd is bad because that changes the GPS time! */
265 /* htData->epoch = *XLALGPSAdd( &(inj->geocent_end_time), tDelay ); */
266
267 htData->deltaT = strain->deltaT;
269
270 for ( k = 0; k < vecLength; ++k )
271 {
272 htData->data->data[k] = (fplus * strain->data->data[k] +
273 fcross * strain->data->data[vecLength + k]) / inj->distance;
274 }
275
276 /*interpolate to given sample rate */
277 htData = XLALInterpolateNRWave( htData, sampleRate);
278
279 return( htData );
280}
281
282
283
284/**
285 * Function for interpolating time series to a given sampling rate.
286 * Input vector is destroyed and a new vector is allocated.
287 */
289XLALInterpolateNRWave( REAL4TimeSeries *in, /**< input strain time series */
290 INT4 sampleRate /**< sample rate of time series */)
291{
292
293 REAL4TimeSeries *ret=NULL;
294 REAL8 deltaTin, deltaTout, r, y_1, y_2;
295 REAL8 tObs; /* duration of signal */
296 UINT4 k, lo, numPoints;
297
298 deltaTin = in->deltaT;
299 tObs = deltaTin * in->data->length;
300
301 /* length of output vector */
302 numPoints = (UINT4) (sampleRate * tObs);
303
304 /* allocate memory */
305 ret = LALCalloc(1, sizeof(*ret));
306 if (!ret)
307 {
309 }
310
311 ret->data = XLALCreateREAL4Vector( numPoints );
312 if (! ret->data)
313 {
315 }
316
317 ret->deltaT = 1./sampleRate;
318 deltaTout = ret->deltaT;
319
320 /* copy stuff from in which should be the same */
321 ret->epoch = in->epoch;
322 ret->f0 = in->f0;
323 ret->sampleUnits = in->sampleUnits;
324 strcpy(ret->name, in->name);
325
326 /* go over points of output vector and interpolate linearly
327 using closest points of input */
328 for (k = 0; k < numPoints; k++) {
329
330 lo = (UINT4)( k*deltaTout / deltaTin);
331
332 /* y_1 and y_2 are the input values at x1 and x2 */
333 /* here we need to make sure that we don't exceed
334 bounds of input vector */
335 if ( lo < in->data->length - 1) {
336 y_1 = in->data->data[lo];
337 y_2 = in->data->data[lo+1];
338
339 /* we want to calculate y_2*r + y_1*(1-r) where
340 r = (x-x1)/(x2-x1) */
341 r = k*deltaTout / deltaTin - lo;
342
343 ret->data->data[k] = y_2 * r + y_1 * (1 - r);
344 }
345 /* Copy the end point if we are exactly at it */
346 else if(lo==in->data->length-1){
347 ret->data->data[k]=in->data->data[lo];
348 }
349 else {
350 ret->data->data[k] = 0.0;
351 }
352 }
353
354 /* destroy input vector */
356 LALFree(in);
357
358 return ret;
359}
360
361
362/**
363 * Function for interpolating time series to a given sampling rate.
364 * Input vector is destroyed and a new vector is allocated.
365 */
367XLALInterpolateNRWaveREAL8( REAL8TimeSeries *in, /**< input strain time series */
368 INT4 sampleRate /**< sample rate of time series */)
369{
370
371 REAL8TimeSeries *ret=NULL;
372 REAL8 deltaTin, deltaTout, r, y_1, y_2;
373 REAL8 tObs; /* duration of signal */
374 UINT4 k, lo, numPoints;
375
376 deltaTin = in->deltaT;
377 tObs = deltaTin * in->data->length;
378
379 /* length of output vector */
380 numPoints = (UINT4) (sampleRate * tObs);
381
382 /* allocate memory */
383 ret = LALCalloc(1, sizeof(*ret));
384 if (!ret)
385 {
387 }
388
389 ret->data = XLALCreateREAL8Vector( numPoints );
390 if (! ret->data)
391 {
393 }
394
395 ret->deltaT = 1./sampleRate;
396 deltaTout = ret->deltaT;
397
398 /* copy stuff from in which should be the same */
399 ret->epoch = in->epoch;
400 ret->f0 = in->f0;
401 ret->sampleUnits = in->sampleUnits;
402 strcpy(ret->name, in->name);
403
404 /* go over points of output vector and interpolate linearly
405 using closest points of input */
406 for (k = 0; k < numPoints; k++) {
407
408 lo = (UINT4)( k*deltaTout / deltaTin);
409
410 /* y_1 and y_2 are the input values at x1 and x2 */
411 /* here we need to make sure that we don't exceed
412 bounds of input vector */
413 if ( lo < in->data->length - 1) {
414 y_1 = in->data->data[lo];
415 y_2 = in->data->data[lo+1];
416
417 /* we want to calculate y_2*r + y_1*(1-r) where
418 r = (x-x1)/(x2-x1) */
419 r = k*deltaTout / deltaTin - lo;
420
421 ret->data->data[k] = y_2 * r + y_1 * (1 - r);
422 } /* Copy the end point if we are exactly at it */
423 else if(lo==in->data->length-1){
424 ret->data->data[k]=in->data->data[lo];
425 }
426 else {
427 ret->data->data[k] = 0.0;
428 }
429 }
430
431 /* destroy input vector */
432 return ret;
433}
434
435int compare_abs_float(const void *a, const void *b){
436
437 const REAL4 *af, *bf;
438
439 af = (const REAL4 *)a;
440 bf = (const REAL4 *)b;
441
442 if ( fabs(*af) > fabs(*bf))
443 return 1;
444 else if ( fabs(*af) < fabs(*bf))
445 return -1;
446 else
447 return 0;
448}
449
450
451int compare_abs_double(const void *a, const void *b){
452
453 const REAL8 *af, *bf;
454
455 af = (const REAL8 *)a;
456 bf = (const REAL8 *)b;
457
458 if ( fabs(*af) > fabs(*bf))
459 return 1;
460 else if ( fabs(*af) < fabs(*bf))
461 return -1;
462 else
463 return 0;
464}
465
466
467/** Function for calculating the coalescence time (defined to be the peak) of a NR wave */
468 INT4
469XLALFindNRCoalescenceTime(REAL8 *tc, /**< FIXME: !TO BE DOCUMENTED! */
470 const REAL4TimeVectorSeries *in /**< input strain time series */)
471{
472
473 size_t *ind=NULL;
474 size_t len;
475 REAL4 *sumSquare=NULL;
476 UINT4 k;
477
478 len = in->data->vectorLength;
479 ind = LALCalloc(1,len*sizeof(*ind));
480
481 sumSquare = LALCalloc(1, len*sizeof(*sumSquare));
482
483 for (k=0; k < len; k++) {
484 sumSquare[k] = in->data->data[k]*in->data->data[k] +
485 in->data->data[k + len]*in->data->data[k + len];
486 }
487
488 gsl_heapsort_index( ind, sumSquare, len, sizeof(REAL4), compare_abs_float);
489
490 *tc = ind[len-1] * in->deltaT;
491
492 LALFree(ind);
493 LALFree(sumSquare);
494
495 return 0;
496}
497
498
499 INT4
500XLALFindNRCoalescencePlusCrossREAL8(REAL8 *tc, /**< FIXME: !TO BE DOCUMENTED! */
501 const REAL8TimeSeries *plus, /**< input strain plus time series */
502 const REAL8TimeSeries *cross /**< input strain cross time series */)
503{
504
505 size_t *ind=NULL;
506 size_t len;
507 REAL8 *sumSquare=NULL;
508 UINT4 k;
509
510 len = plus->data->length;
511 ind = LALCalloc(1,len*sizeof(*ind));
512
513 sumSquare = LALCalloc(1, len*sizeof(*sumSquare));
514
515 for (k=0; k < len; k++) {
516 sumSquare[k] = plus->data->data[k]*plus->data->data[k] +
517 cross->data->data[k]*cross->data->data[k];
518 }
519
520 gsl_heapsort_index( ind, sumSquare, len, sizeof(REAL8), compare_abs_double);
521
522 *tc = ind[len-1] * plus->deltaT;
523
524 LALFree(ind);
525 LALFree(sumSquare);
526
527 return 0;
528}
529
530
531/**
532 * Function for calculating the coalescence time (defined to be the
533 * peak) of a NR wave
534 * This uses the peak of h(t)
535 */
536 INT4
537XLALFindNRCoalescenceTimeFromhoft(REAL8 *tc, /**< FIXME: !TO BE DOCUMENTED! */
538 const REAL4TimeSeries *in /**< input strain time series */)
539{
540
541 size_t *ind=NULL;
542 size_t len;
543
544 len = in->data->length;
545 ind = LALCalloc(1,len*sizeof(*ind));
546
547 /* gsl_heapsort_index( ind, in->data->data, len, sizeof(REAL4), compare_abs_float); */
548
549 *tc = ind[len-1] * in->deltaT;
550
551 LALFree(ind);
552
553 return 0;
554}
555
556
557/** Function for calculating the coalescence time (defined to be the peak) of a NR wave */
558 INT4
559XLALFindNRCoalescenceTimeREAL8(REAL8 *tc, /**< FIXME: !TO BE DOCUMENTED! */
560 const REAL8TimeSeries *in /**< input strain time series */)
561{
562
563 size_t *ind=NULL;
564 size_t len;
565
566 len = in->data->length;
567 ind = LALCalloc(len, sizeof(*ind));
568
569 gsl_heapsort_index( ind, in->data->data, len, sizeof(REAL8), compare_abs_double);
570
571 *tc = ind[len-1] * in->deltaT;
572
573 LALFree(ind);
574
575 return 0;
576}
577
578
579
580/**
581 * For given inspiral parameters, find nearest waveform in
582 * catalog of numerical relativity waveforms. At the moment, only
583 * the mass ratio is considered.
584 */
585 INT4
586XLALFindNRFile( NRWaveMetaData *out, /**< output wave data */
587 NRWaveCatalog *nrCatalog, /**< input NR wave catalog */
588 const SimInspiralTable *inj, /**< injection details */
589 INT4 modeL, /**< mode index l*/
590 INT4 modeM /**< mode index m*/)
591{
592
593 REAL8 massRatioIn, massRatio, diff, newDiff;
594 UINT4 k, best=0;
595
596 /* check arguments are sensible */
597 if ( !out ) {
598 LALPrintError ("\nOutput pointer is NULL !\n\n");
600 }
601
602 if ( !nrCatalog ) {
603 LALPrintError ("\n NR Catalog pointer is NULL !\n\n");
605 }
606
607 if ( !inj ) {
608 LALPrintError ("\n SimInspiralTable pointer is NULL !\n\n");
610 }
611
612 /* we want to check for the highest mass before calculating the mass ratio */
613 if (inj->mass2 > inj->mass1) {
614 massRatioIn = inj->mass2/inj->mass1;
615 }
616 else {
617 massRatioIn = inj->mass1/inj->mass2;
618 }
619
620 /* massRatio = nrCatalog->data[0].massRatio; */
621
622 /* diff = fabs(massRatio - massRatioIn); */
623
624 /* look over catalog and fimd waveform closest in mass ratio */
625 /* initialize diff */
626 diff = -1;
627 for (k = 0; k < nrCatalog->length; k++) {
628 /* look for waveforms with correct mode values */
629 if ((modeL == nrCatalog->data[k].mode[0]) && (modeM == nrCatalog->data[k].mode[1])) {
630
631 massRatio = nrCatalog->data[k].massRatio;
632 newDiff = fabs(massRatio - massRatioIn);
633
634 if ( (diff < 0) || (diff > newDiff)) {
635 diff = newDiff;
636 best = k;
637 }
638 } /* if (modeL == ...) */
639 } /* loop over waveform catalog */
640
641 /* error checking if waveforms with input mode values were not found */
642 if ( diff < 0) {
643 LALPrintError ("\n Input mode numbers not found !\n\n");
645 }
646
647 /* copy best match to output */
648 memcpy(out, nrCatalog->data + best, sizeof(NRWaveMetaData));
649
650 return 0;
651
652}
653
654
656 REAL4TimeSeries *injData,
657 REAL4TimeVectorSeries *strain,
658 SimInspiralTable *thisInj,
659 CHAR *ifo,
660 REAL8 dynRange)
661{
662
663 REAL8 sampleRate;
664 REAL4TimeSeries *htData = NULL;
665 UINT4 k;
666 REAL8 offset;
668
671
672 /* sampleRate = 1.0/strain->deltaT; */
673 /* use the sample rate required for the output time series */
674 sampleRate = 1.0/injData->deltaT;
675
676 /*compute strain for given sky location*/
677 htData = XLALCalculateNRStrain( strain, thisInj, ifo, sampleRate );
678 if ( !htData )
679 {
680 ABORTXLAL( status );
681 }
682
683 /* multiply the input data by dynRange */
684 for ( k = 0 ; k < htData->data->length ; ++k )
685 {
686 htData->data->data[k] *= dynRange;
687 }
688
689 XLALFindNRCoalescenceTime( &offset, strain);
690
691 XLALGPSAdd( &(htData->epoch), -offset);
692
693
694 /* Taper the signal if required */
695 if ( strcmp( thisInj->taper, "TAPER_NONE" ) )
696 {
697
698 if ( ! strcmp( "TAPER_START", thisInj->taper ) )
699 {
701 }
702 else if ( ! strcmp( "TAPER_END", thisInj->taper ) )
703 {
705 }
706 else if ( ! strcmp( "TAPER_STARTEND", thisInj->taper ) )
707 {
709 }
710 else
711 {
712 XLALPrintError( "Unsupported tapering type specified: %s\n", thisInj->taper );
713 XLALDestroyREAL4Vector ( htData->data);
714 LALFree(htData);
715 ABORT( status, NRWAVEINJECT_EVAL, NRWAVEINJECT_MSGEVAL );
716 }
717 if ( XLALSimInspiralREAL4WaveTaper( htData->data, taper ) == XLAL_FAILURE )
718 {
720 XLALDestroyREAL4Vector ( htData->data);
721 LALFree(htData);
722 ABORTXLAL( status );
723 }
724 }
725
726 /* Band-passing probably not as important for NR-type waveforms */
727 /* TODO: Implement if required at a later date */
728 if ( thisInj->bandpass )
729 {
730 XLALPrintError( "Band-passing not yet implemented for InjectStrainGW.\n" );
731 XLALDestroyREAL4Vector ( htData->data);
732 LALFree(htData);
733 ABORTXLAL( status );
734 }
735
736 /* Cast to REAL8 for injection */
737 REAL8TimeSeries *injData8=XLALCreateREAL8TimeSeries("temporary", &(injData->epoch), injData->f0, injData->deltaT, &(injData->sampleUnits), injData->data->length);
738 if(!injData8) XLAL_ERROR_VOID(XLAL_ENOMEM,"Unable to allocate injection buffer\n");
739 REAL8TimeSeries *htData8=XLALCreateREAL8TimeSeries("signal, temp", &(htData->epoch), htData->f0, htData->deltaT, &(htData->sampleUnits), htData->data->length);
740 if(!htData8) XLAL_ERROR_VOID(XLAL_ENOMEM,"Unable to allocate signal buffer\n");
741
742 for(UINT4 i=0;i<htData->data->length;i++) htData8->data->data[i]=(REAL8)htData->data->data[i];
743 for(UINT4 i=0;i<injData->data->length;i++) injData8->data->data[i]=(REAL8)injData->data->data[i];
744
745 /* inject the htData into injection time stream */
746 int retcode = XLALSimAddInjectionREAL8TimeSeries(injData8, htData8, NULL);
747 if(retcode!=XLAL_SUCCESS)
748 {
752 LALFree(htData);
754 }
755
756 for(UINT4 i=0;i<injData8->data->length;i++) injData->data->data[i]=(REAL4)injData8->data->data[i];
757
760
761
762 /* set channel name */
763 snprintf( injData->name, sizeof(injData->name),
764 "%s:STRAIN", ifo );
765
766 XLALDestroyREAL4Vector ( htData->data);
767 LALFree(htData);
768
770 RETURN(status);
771
772}
773
774
775/** REAL8 version of above but using Jolien's new functions */
777 REAL8TimeSeries *injData,
778 REAL8TimeVectorSeries *strain,
779 SimInspiralTable *thisInj,
780 CHAR *ifo,
781 REAL8 UNUSED dynRange)
782{
783
784 REAL8TimeSeries *htData = NULL;
785 REAL8TimeSeries *hplus = NULL;
786 REAL8TimeSeries *hcross = NULL;
787 UINT4 k, len;
788 REAL8 offset;
789 LALDetector det;
790
793
794 /* get the detector information */
795 memcpy( &det, XLALDetectorPrefixToLALDetector( ifo ), sizeof(LALDetector) );
796
797 /* Band-passing and tapering not yet implemented for REAL8 data */
798 if ( strcmp( thisInj->taper, "TAPER_NONE" ) || thisInj->bandpass )
799 {
800 XLALPrintError( "Tapering/band-passing of REAL8 injection currently unsupported\n" );
801 ABORT( status, NRWAVEINJECT_EVAL, NRWAVEINJECT_MSGEVAL );
802 }
803
804 /* use the sample rate required for the output time series */
805 len = strain->data->vectorLength;
806
807 hplus = XLALCreateREAL8TimeSeries ( strain->name, &strain->epoch, strain->f0,
808 strain->deltaT, &strain->sampleUnits, len);
809 hcross = XLALCreateREAL8TimeSeries ( strain->name, &strain->epoch, strain->f0,
810 strain->deltaT, &strain->sampleUnits, len);
811
812 for ( k = 0; k < len; k++) {
813 hplus->data->data[k] = strain->data->data[k];
814 hplus->data->data[k] = strain->data->data[k + len];
815 }
816
817 htData = XLALSimDetectorStrainREAL8TimeSeries( hplus, hcross, thisInj->longitude,
818 thisInj->latitude, thisInj->polarization,
819 &det);
820
821 XLALFindNRCoalescenceTimeREAL8( &offset, htData);
822 XLALGPSAdd( &(htData->epoch), -offset);
823
824 int retcode=XLALSimAddInjectionREAL8TimeSeries( injData, htData, NULL);
825 XLAL_CHECK_VOID(retcode==XLAL_SUCCESS, XLAL_EFUNC, "Unable to add injection to data\n");
826
827 /* set channel name */
828 snprintf( injData->name, sizeof(injData->name),
829 "%s:STRAIN", ifo );
830
834
836 RETURN(status);
837
838}
839
840
841/**
842 * construct the channel name corresponding to a particular mode
843 * and polarization in frame file containing nr data
844 */
845CHAR* XLALGetNinjaChannelName(const CHAR *polarisation, UINT4 l, INT4 m)
846{
847 /* variables */
848 CHAR sign;
849 CHAR *channel=NULL;
850
851 if ( !((strncmp(polarisation, "plus", 4) == 0) || (strncmp(polarisation, "cross", 5) == 0))) {
853 }
854
855 /* allocate memory for channel */
857
858 /* get sign of m */
859 if (m < 0)
860 /* negative */
861 sign = 'n';
862 else
863 /* positive */
864 sign = 'p';
865
866 /* set channel name */
867 snprintf(channel, LIGOMETA_CHANNEL_MAX, "h%s_l%d_m%c%d", polarisation, l, sign, abs(m));
868
869 /* return channel name */
870 return channel;
871}
872
873
874/**
875 * Function for parsing numrel group name and converting it into a enum element.
876 * This needs to be robust enough to be able to handle the information as submitted
877 * by the groups. Is there a cleaner way to do this?
878 * add or modify the group names as required
879 */
881{
882
884
885 if ( !name ) {
886 return ret;
887 }
888
889 if ( strstr( name, "Caltech") || strstr( name, "CIT") )
890 ret = NINJA_GROUP_CIT;
891 else if ( strstr( name, "AEI") || strstr(name, "Potsdam") )
892 ret = NINJA_GROUP_AEI;
893 else if ( strstr( name, "Jena") )
894 ret = NINJA_GROUP_JENA;
895 else if ( strstr( name, "Pretorius") || strstr( name, "Princeton"))
897 else if ( strstr( name, "Cornell") )
899 else if ( strstr( name, "PSU") || strstr(name, "Penn State") )
900 ret = NINJA_GROUP_PSU;
901 else if ( strstr( name, "LSU") )
902 ret = NINJA_GROUP_LSU;
903 else if ( strstr( name, "RIT") || strstr( name, "Rochester") )
904 ret = NINJA_GROUP_RIT;
905 else if ( strstr( name, "FAU") || strstr( name, "Florida Atlantic") )
906 ret = NINJA_GROUP_FAU;
907 else if ( strstr( name, "UTB") )
908 ret = NINJA_GROUP_UTB;
909 else if ( strstr( name, "UIUC") || strstr(name, "Urbana Champaign") )
910 ret = NINJA_GROUP_UIUC;
911
912 return ret;
913}
#define LALCalloc(m, n)
#define LALFree(p)
#define tEnd
#define ABORT(statusptr, code, mesg)
#define ATTATCHSTATUSPTR(statusptr)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define ABORTXLAL(sp)
#define LIGOMETA_CHANNEL_MAX
int compare_abs_float(const void *a, const void *b)
Definition: NRWaveInject.c:435
int compare_abs_double(const void *a, const void *b)
Definition: NRWaveInject.c:451
void LALInjectStrainGWREAL8(LALStatus *status, REAL8TimeSeries *injData, REAL8TimeVectorSeries *strain, SimInspiralTable *thisInj, CHAR *ifo, REAL8 UNUSED dynRange)
REAL8 version of above but using Jolien's new functions.
Definition: NRWaveInject.c:776
REAL8 tmp1
const char *const name
int l
double i
sigmaKerr data[0]
void XLALComputeDetAMResponse(double *fplus, double *fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const double gmst)
double complex COMPLEX16
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
int LALPrintError(const char *fmt,...)
LALSimInspiralApplyTaper
LAL_SIM_INSPIRAL_TAPER_START
LAL_SIM_INSPIRAL_TAPER_STARTEND
LAL_SIM_INSPIRAL_TAPER_END
LAL_SIM_INSPIRAL_TAPER_NONE
int XLALSimInspiralREAL4WaveTaper(REAL4Vector *signalvec, LALSimInspiralApplyTaper bookends)
const LALDetector * XLALDetectorPrefixToLALDetector(const char *string)
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)
INT4 XLALFindNRFile(NRWaveMetaData *out, NRWaveCatalog *nrCatalog, const SimInspiralTable *inj, INT4 modeL, INT4 modeM)
For given inspiral parameters, find nearest waveform in catalog of numerical relativity waveforms.
Definition: NRWaveInject.c:586
REAL4TimeSeries * XLALCalculateNRStrain(REAL4TimeVectorSeries *strain, SimInspiralTable *inj, const CHAR *ifo, INT4 sampleRate)
Definition: NRWaveInject.c:218
INT4 XLALOrientNRWave(REAL4TimeVectorSeries *strain, UINT4 modeL, INT4 modeM, REAL4 inclination, REAL4 coa_phase)
Takes a (sky averaged) numerical relativity waveform and returns the waveform appropriate for given c...
Definition: NRWaveInject.c:99
REAL8TimeVectorSeries * XLALOrientNRWaveREAL8(REAL8TimeVectorSeries *strain, UINT4 modeL, INT4 modeM, REAL4 inclination, REAL4 coa_phase)
Takes a (sky averaged) numerical relativity waveform and returns the waveform appropriate for given c...
Definition: NRWaveInject.c:182
NumRelGroup
enum for list of numrel groups
Definition: NRWaveInject.h:76
INT4 XLALFindNRCoalescencePlusCrossREAL8(REAL8 *tc, const REAL8TimeSeries *plus, const REAL8TimeSeries *cross)
Definition: NRWaveInject.c:500
INT4 XLALFindNRCoalescenceTimeFromhoft(REAL8 *tc, const REAL4TimeSeries *in)
Function for calculating the coalescence time (defined to be the peak) of a NR wave This uses the pea...
Definition: NRWaveInject.c:537
INT4 XLALFindNRCoalescenceTimeREAL8(REAL8 *tc, const REAL8TimeSeries *in)
Function for calculating the coalescence time (defined to be the peak) of a NR wave.
Definition: NRWaveInject.c:559
CHAR * XLALGetNinjaChannelName(const CHAR *polarisation, UINT4 l, INT4 m)
construct the channel name corresponding to a particular mode and polarization in frame file containi...
Definition: NRWaveInject.c:845
#define NRWAVEINJECT_EVAL
Invalid value.
Definition: NRWaveInject.h:59
REAL4TimeVectorSeries * XLALSumStrain(REAL4TimeVectorSeries *tempstrain, REAL4TimeVectorSeries *strain)
Takes a strain of h+ and hx data and stores it in a temporal strain in order to perform the sum over ...
Definition: NRWaveInject.c:58
void XLALOrientNRWaveTimeSeriesREAL8(REAL8TimeSeries *plus, REAL8TimeSeries *cross, UINT4 modeL, INT4 modeM, REAL4 inclination, REAL4 coa_phase)
Takes a (sky averaged) numerical relativity waveform and returns the waveform appropriate for given c...
Definition: NRWaveInject.c:140
void LALInjectStrainGW(LALStatus *status, REAL4TimeSeries *injData, REAL4TimeVectorSeries *strain, SimInspiralTable *thisInj, CHAR *ifo, REAL8 dynRange)
Definition: NRWaveInject.c:655
REAL8TimeVectorSeries * XLALSumStrainREAL8(REAL8TimeVectorSeries *tempstrain, REAL8TimeVectorSeries *strain)
Definition: NRWaveInject.c:76
INT4 XLALFindNRCoalescenceTime(REAL8 *tc, const REAL4TimeVectorSeries *in)
Function for calculating the coalescence time (defined to be the peak) of a NR wave.
Definition: NRWaveInject.c:469
REAL8TimeSeries * XLALInterpolateNRWaveREAL8(REAL8TimeSeries *in, INT4 sampleRate)
Function for interpolating time series to a given sampling rate.
Definition: NRWaveInject.c:367
REAL4TimeSeries * XLALInterpolateNRWave(REAL4TimeSeries *in, INT4 sampleRate)
Function for interpolating time series to a given sampling rate.
Definition: NRWaveInject.c:289
NumRelGroup XLALParseNumRelGroupName(CHAR *name)
Function for parsing numrel group name and converting it into a enum element.
Definition: NRWaveInject.c:880
@ NINJA_GROUP_UTB
Definition: NRWaveInject.h:85
@ NINJA_GROUP_AEI
Definition: NRWaveInject.h:77
@ NINJA_GROUP_RIT
Definition: NRWaveInject.h:81
@ NINJA_GROUP_LAST
Definition: NRWaveInject.h:88
@ NINJA_GROUP_PRINCETON
Definition: NRWaveInject.h:87
@ NINJA_GROUP_PSU
Definition: NRWaveInject.h:83
@ NINJA_GROUP_CIT
Definition: NRWaveInject.h:78
@ NINJA_GROUP_UIUC
Definition: NRWaveInject.h:86
@ NINJA_GROUP_FAU
Definition: NRWaveInject.h:84
@ NINJA_GROUP_JENA
Definition: NRWaveInject.h:80
@ NINJA_GROUP_LSU
Definition: NRWaveInject.h:79
@ NINJA_GROUP_CORNELL
Definition: NRWaveInject.h:82
static const INT4 r
static const INT4 m
static const INT4 a
INT4 XLALSphHarm(COMPLEX16 *out, UINT4 L, INT4 M, REAL4 theta, REAL4 phi)
REAL8 XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
const LALUnit lalADCCountUnit
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
#define XLAL_ERROR_VOID(...)
#define XLAL_ERROR_NULL(...)
#define XLAL_ERROR(...)
#define XLAL_CHECK_VOID(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int XLALClearErrno(void)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EINVAL
XLAL_FAILURE
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
char * channel
REAL4 response[3][3]
REAL8 location[3]
List of numrel waveform metadata.
Definition: NRWaveIO.h:98
NRWaveMetaData * data
List of waveforms.
Definition: NRWaveIO.h:100
UINT4 length
Number of waveforms.
Definition: NRWaveIO.h:99
Struct containing metadata information about a single numerical relativity waveform.
Definition: NRWaveIO.h:84
INT4 mode[2]
l and m values
Definition: NRWaveIO.h:88
REAL8 massRatio
Mass ratio m1/m2 where we assume m1 >= m2.
Definition: NRWaveIO.h:85
CHAR name[LALNameLength]
REAL4Sequence * data
LALUnit sampleUnits
LIGOTimeGPS epoch
REAL4VectorSequence * data
REAL4 * data
REAL8Sequence * data
LALUnit sampleUnits
LIGOTimeGPS epoch
CHAR name[LALNameLength]
REAL8VectorSequence * data
CHAR name[LALNameLength]
REAL8 * data
LIGOTimeGPS geocent_end_time
CHAR taper[LIGOMETA_INSPIRALTAPER_MAX]