Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInspiral 5.0.3.1-ea7c608
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALInspiralNinjaInject.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Patrick Brady, Drew Keppel
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: LALSimNinjaInject.c
23 *
24 * Author: Pekowsky, L., Harry, I., Keppel, D.
25 *
26 *
27 *-----------------------------------------------------------------------
28*/
29
30
31#include <config.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <fcntl.h>
38#include <regex.h>
39#include <time.h>
40#include <math.h>
41
42#include <lal/LALConstants.h>
43#include <lal/LALgetopt.h>
44#include <lal/Units.h>
45#include <lal/TimeSeries.h>
46#include <lal/LALFrStream.h>
47#include <lal/LALSimulation.h>
48#include <lal/NRWaveInject.h>
49#include <lal/LALInspiral.h>
50#include <lal/LALFrameIO.h>
51
53 CHAR *name,
54 LALFrStream *stream
55);
56
58 REAL8TimeSeries **seriesPlus,
59 REAL8TimeSeries **seriesCross,
60 SimInspiralTable *thisinj
61);
62
64 const char *ifo,
66);
67
69{
70#if 0
71 FrTOCts *ts;
72 ts = stream->file->toc->adc;
73 while ( ts && strcmp( channel, ts->name ) )
74 ts = ts->next;
75 if ( ! ts )
76 {
77 /* scan sim data channels */
78 ts = stream->file->toc->sim;
79 while ( ts && strcmp( channel, ts->name ) )
80 ts = ts->next;
81 }
82 if ( ! ts )
83 {
84 /* scan proc data channels */
85 ts = stream->file->toc->proc;
86 while ( ts && strcmp( channel, ts->name ) )
87 ts = ts->next;
88 }
89 if ( ! ts )
90 return 0;
91 return 1;
92#else
93 if ((int)XLALFrStreamGetVectorLength(channel, stream) < 0)
94 return 0;
95 return 1;
96#endif
97}
98
99int
101 REAL8TimeSeries **seriesPlus, /**< [out] h+, hx data */
102 REAL8TimeSeries **seriesCross, /**< [out] h+, hx data */
103 SimInspiralTable *thisinj /**< [in] injection data */
104 )
105{
106 INT4 modeL, modeM, modeLlo, modeLhi;
107 INT4 len, lenPlus, lenCross, k;
108 CHAR *channel_name_plus;
109 CHAR *channel_name_cross;
110 LALFrStream *frStream = NULL;
111 LALCache frCache;
113 REAL8TimeSeries *modePlus=NULL;
114 REAL8TimeSeries *modeCross=NULL;
115 REAL8 massMpc, timeStep;
116
117 modeLlo = thisinj->numrel_mode_min;
118 modeLhi = thisinj->numrel_mode_max;
119
120 /* create a frame cache and open the frame stream */
121 frCache.length = 1;
122 frCache.list = LALCalloc(1, sizeof(frCache.list[0]));
123 frCache.list[0].url = thisinj->numrel_data;
124 frStream = XLALFrStreamCacheOpen( &frCache );
125
126 /* the total mass of the binary in Mpc */
127 massMpc = (thisinj->mass1 + thisinj->mass2) * LAL_MRSUN_SI / ( LAL_PC_SI * 1.0e6);
128
129 /* Time step in dimensionful units */
130 timeStep = (thisinj->mass1 + thisinj->mass2) * LAL_MTSUN_SI;
131
132 /* start time of waveform -- set it to something */
133 epoch.gpsSeconds = thisinj->geocent_end_time.gpsSeconds;
134 epoch.gpsNanoSeconds = thisinj->geocent_end_time.gpsNanoSeconds;
135
136 /* loop over l values */
137 for ( modeL = modeLlo; modeL <= modeLhi; modeL++ ) {
138
139 /* loop over m values */
140 for ( modeM = -modeL; modeM <= modeL; modeM++ ) {
141 /* read numrel waveform */
142 /* first the plus polarization */
143 channel_name_plus = XLALGetNinjaChannelName("plus", modeL, modeM);
144 /*get number of data points */
145 if (XLALCheckFrameHasChannel(channel_name_plus, frStream ) )
146 {
147 lenPlus = XLALFrStreamGetVectorLength ( channel_name_plus, frStream );
148 }
149 else
150 {
151 lenPlus = -1;
152 }
153
154 /* now the cross polarization */
155 channel_name_cross = XLALGetNinjaChannelName("cross", modeL, modeM);
156 /*get number of data points */
157 if (XLALCheckFrameHasChannel(channel_name_cross, frStream ) )
158 {
159 lenCross = XLALFrStreamGetVectorLength ( channel_name_cross, frStream );
160 }
161 else
162 {
163 lenCross = -1;
164 }
165
166 /* skip on to next mode if mode doesn't exist */
167 if ( (lenPlus <= 0) || (lenCross <= 0) || (lenPlus != lenCross) ) {
169 LALFree(channel_name_plus);
170 LALFree(channel_name_cross);
171 continue;
172 }
173
174 /* note: lenPlus and lenCross must be equal if we got this far*/
175 len = lenPlus;
176
177 /* allocate and read the plus/cross time series */
178 modePlus = XLALCreateREAL8TimeSeries ( channel_name_plus, &epoch, 0, 0, &lalDimensionlessUnit, len);
179 memset(modePlus->data->data, 0, modePlus->data->length*sizeof(REAL8));
180 XLALFrStreamGetREAL8TimeSeries ( modePlus, frStream );
181 XLALFrStreamRewind( frStream );
182 LALFree(channel_name_plus);
183
184 modeCross = XLALCreateREAL8TimeSeries ( channel_name_cross, &epoch, 0, 0, &lalDimensionlessUnit, len);
185 memset(modeCross->data->data, 0, modeCross->data->length*sizeof(REAL8));
186 XLALFrStreamGetREAL8TimeSeries ( modeCross, frStream );
187 XLALFrStreamRewind( frStream );
188 LALFree(channel_name_cross);
189
190 /* scale and add */
191 if (*seriesPlus == NULL) {
192 *seriesPlus = XLALCreateREAL8TimeSeries ( "hplus", &epoch, 0, 0, &lalDimensionlessUnit, len);
193 memset((*seriesPlus)->data->data, 0, (*seriesPlus)->data->length*sizeof(REAL8));
194 (*seriesPlus)->deltaT = modePlus->deltaT;
195 }
196
197 if (*seriesCross == NULL) {
198 *seriesCross = XLALCreateREAL8TimeSeries ( "hcross", &epoch, 0, 0, &lalDimensionlessUnit, len);
199 memset((*seriesCross)->data->data, 0, (*seriesCross)->data->length*sizeof(REAL8));
200 (*seriesCross)->deltaT = modeCross->deltaT;
201 }
202
203 XLALOrientNRWaveTimeSeriesREAL8( modePlus, modeCross, modeL, modeM, thisinj->inclination, thisinj->coa_phase );
204
205 for (k = 0; k < len; k++) {
206 (*seriesPlus)->data->data[k] += massMpc * modePlus->data->data[k];
207 (*seriesCross)->data->data[k] += massMpc * modeCross->data->data[k];
208 }
209
210 /* we are done with seriesPlus and Cross for this iteration */
212 XLALDestroyREAL8TimeSeries (modeCross);
213 } /* end loop over modeM values */
214 } /* end loop over modeL values */
215 (*seriesPlus)->deltaT *= timeStep;
216 (*seriesCross)->deltaT *= timeStep;
217 XLALFrStreamClose( frStream );
218 LALFree(frCache.list);
219
220 return XLAL_SUCCESS;
221}
222
223int
225 REAL8TimeSeries **hplus, /**< +-polarization waveform */
226 REAL8TimeSeries **hcross, /**< x-polarization waveform */
227 SimInspiralTable *thisRow, /**< row from the sim_inspiral table containing waveform parameters */
228 REAL8 deltaT /**< time step */
229 )
230{
231 REAL8TimeSeries *plus = NULL;
232 REAL8TimeSeries *cross = NULL;
233 INT4 sampleRate = (INT4) 1./deltaT;
234
235 /* Add the modes together */
236 XLALAddNumRelStrainModesREAL8(&plus, &cross, thisRow);
237 /* Place at distance */
238 for (UINT4 j = 0; j < plus->data->length; j++)
239 {
240 plus->data->data[j] /= thisRow->distance;
241 cross->data->data[j] /= thisRow->distance;
242 }
243
246
247 /* Interpolate to desired sample rate */
248 *hplus = XLALInterpolateNRWaveREAL8(plus, sampleRate);
249 *hcross = XLALInterpolateNRWaveREAL8(cross, sampleRate);
250 if (*hplus == NULL || *hcross == NULL)
252
253 /* We want the end time to be the time of largest amplitude */
254 REAL8 offset = 0;
255 XLALFindNRCoalescencePlusCrossREAL8(&offset, *hplus, *hcross);
256 XLALGPSAdd( &((*hplus)->epoch), -offset);
257 XLALGPSAdd( &((*hcross)->epoch), -offset);
258
261
262 return XLAL_SUCCESS;
263}
264
267{
268 REAL8TimeSeries *hplus = NULL;
269 REAL8TimeSeries *hcross = NULL;
270 REAL8TimeSeries *strain = NULL;
271
272 REAL8 deltaT = 1./16384.;
273 LALDetector det;
274
275 /* look up detector */
276 memcpy( &det, XLALDetectorPrefixToLALDetector( ifo ), sizeof(LALDetector) );
277
278 /* generate plus and cross polarizations */
279 XLALNRInjectionFromSimInspiral(&hplus, &hcross, inj, deltaT);
280
281 /* Use Jolien's method to place on the sky */
282 strain = XLALSimDetectorStrainREAL8TimeSeries(hplus, hcross,
283 inj->longitude, inj->latitude, inj->polarization, &det);
284
287
288 return strain;
289}
290
292 REAL4TimeSeries* chan,
293 const char *ifo,
294 REAL8 dynRange,
295 SimInspiralTable* events
296)
297{
298 /* New REAL8, NINJA-2 code */
299 UINT4 j;
300 SimInspiralTable *thisInj = NULL;
301
302 REAL8TimeSeries *tempStrain = NULL;
303 REAL8TimeSeries *tempChan = NULL;
304
305 /* Make a REAL8 version of the channel data */
306 /* so we can call Jolien's new inject function */
307 tempChan = XLALCreateREAL8TimeSeries(
308 chan->name,
309 &(chan->epoch),
310 chan->f0,
311 chan->deltaT,
312 &(chan->sampleUnits),
313 chan->data->length);
314 for ( j = 0 ; j < tempChan->data->length ; ++j )
315 {
316 tempChan->data->data[j] = (REAL8) ( chan->data->data[j] );
317 }
318
319 /* loop over injections */
320 for ( thisInj = events; thisInj; thisInj = thisInj->next )
321 {
322 tempStrain = XLALNRInjectionStrain(ifo, thisInj);
323 for ( j = 0 ; j < tempStrain->data->length ; ++j )
324 {
325 tempStrain->data->data[j] *= dynRange;
326 }
327
328 XLALSimAddInjectionREAL8TimeSeries( tempChan, tempStrain, NULL);
329 XLALDestroyREAL8TimeSeries(tempStrain);
330 } /* loop over injections */
331
332 /* Back to REAL4 */
333 for ( j = 0 ; j < tempChan->data->length ; ++j )
334 {
335 chan->data->data[j] = (REAL4) ( tempChan->data->data[j] );
336 }
337
339}
int XLALAddNumRelStrainModesREAL8(REAL8TimeSeries **seriesPlus, REAL8TimeSeries **seriesCross, SimInspiralTable *thisinj)
int XLALNRInjectionFromSimInspiral(REAL8TimeSeries **hplus, REAL8TimeSeries **hcross, SimInspiralTable *thisRow, REAL8 deltaT)
int XLALCheckFrameHasChannel(CHAR *name, LALFrStream *stream)
void XLALSimInjectNinjaSignals(REAL4TimeSeries *chan, const char *ifo, REAL8 dynRange, SimInspiralTable *events)
REAL8TimeSeries * XLALNRInjectionStrain(const char *ifo, SimInspiralTable *inj)
#define LALCalloc(m, n)
#define LALFree(p)
#define LAL_MTSUN_SI
#define LAL_PC_SI
#define LAL_MRSUN_SI
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
int XLALFrStreamClose(LALFrStream *stream)
LALFrStream * XLALFrStreamCacheOpen(LALCache *cache)
int XLALFrStreamRewind(LALFrStream *stream)
int XLALFrStreamGetREAL8TimeSeries(REAL8TimeSeries *series, LALFrStream *stream)
int XLALFrStreamGetVectorLength(const char *chname, LALFrStream *stream)
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 XLALFindNRCoalescencePlusCrossREAL8(REAL8 *tc, const REAL8TimeSeries *plus, const REAL8TimeSeries *cross)
Definition: NRWaveInject.c:500
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
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
REAL8TimeSeries * XLALInterpolateNRWaveREAL8(REAL8TimeSeries *in, INT4 sampleRate)
Function for interpolating time series to a given sampling rate.
Definition: NRWaveInject.c:367
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
const LALUnit lalDimensionlessUnit
#define XLAL_ERROR(...)
int XLALClearErrno(void)
XLAL_SUCCESS
XLAL_EFUNC
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
ts
char * channel
CHAR * url
UINT4 length
LALCacheEntry * list
LALFrFile * file
INT4 gpsNanoSeconds
CHAR name[LALNameLength]
REAL4Sequence * data
LALUnit sampleUnits
LIGOTimeGPS epoch
REAL4 * data
REAL8Sequence * data
LALUnit sampleUnits
REAL8 * data
LIGOTimeGPS geocent_end_time
struct tagSimInspiralTable * next
CHAR numrel_data[LIGOMETA_STRING_MAX]
enum @1 epoch
double deltaT