LALInspiral 5.0.3.1-eeff03c
InspiralInjectionParams.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Bernd Machenschalk, Stephen Fairhurst, Alexander Dietz
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 * \file InspiralInjectionParams.c
21 * \ingroup InspiralInjectionParams
22 * \author D. Brown, J. Creighton, S. Fairhurst, G. Jones, E. Messaritaki
23 *
24 * \brief Functions for generating random distributions of inspiral parameters
25 * for injection purposes
26 *
27 */
28
29#include <math.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <lal/LALStdlib.h>
33#include <lal/LALStdio.h>
34#include <lal/LIGOMetadataTables.h>
35#include <lal/LIGOMetadataInspiralUtils.h>
36#include <lal/Date.h>
37#include <lal/SkyCoordinates.h>
38#include <lal/GeneratePPNInspiral.h>
39#include <lal/DetectorSite.h>
40#include <lal/DetResponse.h>
41#include <lal/TimeDelay.h>
42#include <lal/InspiralInjectionParams.h>
43#include <lal/VectorOps.h>
44
45/**
46 * Generates the geocent_end_time for an inspiral injection, based on the
47 * given startTime and timeWindow
48 */
50 SimInspiralTable *inj, /**< injection for which time will be set */
51 RandomParams *randParams,/**< random parameter details*/
52 LIGOTimeGPS startTime, /**< the first time that the injection could be */
53 REAL4 timeWindow /**< the time window within which inj must occur*/
54 )
55{
56 REAL8 timeOffset;
57 timeOffset = (REAL8) timeWindow * XLALUniformDeviate( randParams );
58 inj->geocent_end_time = *XLALGPSAdd( &startTime, timeOffset );
60 &(inj->geocent_end_time) );
61
62 return ( inj );
63}
64
65/**
66 * Generates the distance for an inspiral injection, based on the requested
67 * distribution and max/min distances
68 */
70 SimInspiralTable *inj, /**< injection for which distance will be set */
71 RandomParams *randParams, /**< random parameter details*/
72 LoudnessDistribution dDist,/**< requested distance distribution */
73 REAL4 distMin, /**< minimum distance (Mpc) */
74 REAL4 distMax /**< maximum distance (Mpc) */
75 )
76{
77 if ( dDist == uniformDistance )
78 {
79 /* uniform distribution in distance */
80 inj->distance = distMin +
81 (distMax - distMin) * XLALUniformDeviate( randParams );
82 }
83 else if ( dDist == uniformLogDistance )
84 {
85 /* uniform distribution in log(distance) */
86 REAL4 lmin = log10(distMin);
87 REAL4 lmax = log10(distMax);
88 REAL4 deltaL = lmax - lmin;
89 REAL4 exponent;
90 exponent = lmin + deltaL * XLALUniformDeviate( randParams );
91 inj->distance = pow(10.0,(REAL4) exponent);
92 }
93 else if ( dDist == uniformVolume )
94 {
95 /* uniform volume distribution */
96 REAL4 d3min = distMin * distMin * distMin;
97 REAL4 d3max = distMax * distMax * distMax;
98 REAL4 deltad3 = d3max - d3min ;
99 REAL4 d3;
100 d3 = d3min + deltad3 * XLALUniformDeviate( randParams );
101 inj->distance = cbrt( d3 );
102 }
103 else if ( dDist == uniformDistanceSquared )
104 {
105 /* uniform distance^2 distribution */
106 REAL4 d2min = distMin * distMin ;
107 REAL4 d2max = distMax * distMax ;
108 REAL4 deltad2 = d2max - d2min ;
109 REAL4 d2;
110 d2 = d2min + deltad2 * XLALUniformDeviate( randParams );
111 inj->distance = sqrt( d2 );
112 }
113
114 return ( inj );
115}
116
117
118/**
119 * Generates a random sky location (right ascension=longitude,
120 * delta=latitude) for an inspiral injection
121 */
123 SimInspiralTable *inj, /**< injection for which sky location will be set*/
124 RandomParams *randParams/**< random parameter details*/
125 )
126{
127 inj->latitude = asin( 2.0 * XLALUniformDeviate( randParams ) - 1.0 ) ;
128 inj->longitude = LAL_TWOPI * XLALUniformDeviate( randParams ) ;
129
130 return ( inj );
131}
132
133/**
134 * Generates a location within the Milky Way
135 * for an inspiral injection
136 */
138 REAL8 *rightAscension, /**< right ascension of the milky-way source */
139 REAL8 *declination, /**< declination of the milky-way source */
140 REAL8 *distance, /**< distance to the milky-way source */
141 RandomParams *randParams/**< random parameter details*/
142 )
143{
144 static LALStatus status;
145 SkyPosition galacticPos, equatorialPos;
146 const REAL8 h_scale = 1.5; /* scales in kpc */
147 const REAL8 r_scale = 4.0;
148 const REAL8 r_sun = 8.5;
149 REAL8 r, z, phi, rho2, dist;
150 REAL4 u;
151
152 /* draw the radial position in the galactic plane */
153 r = r_scale * sqrt( -2 * log( XLALUniformDeviate(randParams) ) );
154
155 /* draw the height */
156 u = XLALUniformDeviate(randParams);
157 if ( u > 0.5)
158 {
159 z = -h_scale * log( 2 * ( 1 - u ) );
160 }
161 else
162 {
163 z = h_scale * log( 2 * u );
164 }
165 phi = LAL_TWOPI * XLALUniformDeviate(randParams);
166
167 /* calculate the distace from the sun */
168 rho2 = r_sun * r_sun + r * r - 2 * r_sun * r * cos( phi );
169 dist = sqrt( z * z + rho2 );
170
171 /* convert galactic coordinates into equatorial coordinates */
172 galacticPos.longitude = atan2( r * sin( phi ), r_sun - r * cos( phi ) );
173 galacticPos.latitude = asin( z / dist );
174 galacticPos.system = COORDINATESYSTEM_GALACTIC;
175
176 /* convert the coordinates */
177 LALGalacticToEquatorial( &status, &equatorialPos, &galacticPos);
178
179 *declination = equatorialPos.latitude;
180 *rightAscension = equatorialPos.longitude;
181 *distance = dist/1000.0; /* convert to Mpc */
182}
183
184/**
185 * Generates a random orientation (polarization, inclination, coa_phase)
186 * for an inspiral injection. If inclinationPeak is non-zero, then peak the
187 * inclination around o with width inclinationPeak
188 */
190 SimInspiralTable *inj, /**< injection for which orientation will be set*/
191 RandomParams *randParams,/**< random parameter details*/
192 InclDistribution iDist, /**< requested inclination distribution */
193 REAL4 inclinationPeak /**< width of the peak of the inclination */
194 )
195{
196 if ( iDist == uniformInclDist )
197 {
198 inj->inclination = acos( 2.0 * XLALUniformDeviate( randParams )
199 - 1.0 );
200 }
201 else if ( iDist == gaussianInclDist )
202 {
203 inj->inclination = inclinationPeak * XLALNormalDeviate( randParams );
204 }
205
206 inj->polarization = LAL_TWOPI * XLALUniformDeviate( randParams ) ;
207 inj->coa_phase = LAL_TWOPI * XLALUniformDeviate( randParams ) ;
208
209 return ( inj );
210}
211
212/** Places component masses on a square grid for an inspiral injection. */
214 SimInspiralTable *inj, /**< injection for which masses will be set*/
215 REAL4 mass1Min, /**< minimum mass for first component */
216 REAL4 mass2Min, /**< minimum mass for second component */
217 REAL4 minTotalMass, /**< minimum total mass of binary */
218 REAL4 maxTotalMass, /**< maximum total mass of binary */
219 REAL4 mass1Delta, /**< m1 grid spacing */
220 REAL4 mass2Delta, /**< m2 grid spacing */
221 INT4 mass1Pnt, /**< number of grid points along m1 */
222 INT4 mass2Pnt, /**< number of grid points along m2 */
223 INT4 injNum, /**< injection number */
224 INT4 *count /**< unsuccessful injection counter */
225 )
226{
227 INT4 nIndex, nCycles;
228 REAL4 mTotal = maxTotalMass +1;
229
230 while ( mTotal < minTotalMass || mTotal > maxTotalMass )
231 {
232 nIndex = injNum + *count;
233 nCycles = (int) ( ceil( ((float) nIndex) / mass1Pnt ));
234 inj->mass1 = mass1Min + mass1Delta * (nIndex % mass1Pnt );
235 inj->mass2 = mass2Min + mass2Delta * (nCycles % mass2Pnt );
236 mTotal = inj->mass1 + inj->mass2 ;
237 if ( mTotal < minTotalMass || mTotal > maxTotalMass ) (*count)++;
238 }
239
240 inj->eta = inj->mass1 * inj->mass2 / ( mTotal * mTotal );
241 inj->mchirp = mTotal * pow(inj->eta, 0.6);
242
243 return ( inj );
244}
245
246/** Set masses to fixed values for an inspiral injection. */
248 SimInspiralTable *inj, /**< injection for which masses will be set*/
249 REAL4 mass1Fix, /**< fixed mass of first component */
250 REAL4 mass2Fix /**< fixed mass of second component */
251 )
252{
253 REAL4 mTotal;
254
255 inj->mass1 = mass1Fix;
256 inj->mass2 = mass2Fix;
257 mTotal = inj->mass1 + inj->mass2 ;
258 inj->eta = inj->mass1 * inj->mass2 / ( mTotal * mTotal );
259 inj->mchirp = mTotal * pow(inj->eta, 0.6);
260
261 return ( inj );
262}
263
264/** Generates random masses for an inspiral injection. */
266 SimInspiralTable *inj, /**< injection for which masses will be set*/
267 RandomParams *randParams,/**< random parameter details*/
268 MassDistribution mDist, /**< the mass distribution to use */
269 REAL4 mass1Min, /**< minimum mass for first component */
270 REAL4 mass1Max, /**< maximum mass for first component */
271 REAL4 mass2Min, /**< minimum mass for second component */
272 REAL4 mass2Max, /**< maximum mass for second component */
273 REAL4 minTotalMass, /**< minimum total mass of binaty */
274 REAL4 maxTotalMass /**< maximum total mass of binary */
275 )
276{
277 REAL4 mTotal = maxTotalMass +1;
278
279 while ( mTotal < minTotalMass || mTotal > maxTotalMass )
280 {
281
282 if ( mDist == uniformComponentMass )
283 {
284 /* uniformly distributed mass1 and uniformly distributed mass2 */
285 inj->mass1 = mass1Min + XLALUniformDeviate( randParams ) *
286 (mass1Max - mass1Min);
287 inj->mass2 = mass2Min + XLALUniformDeviate( randParams ) *
288 (mass2Max - mass2Min);
289 mTotal = inj->mass1 + inj->mass2 ;
290 }
291 else if ( mDist == logComponentMass )
292 {
293 /* distributed logarithmically in mass1 and mass2 */
294 inj->mass1 = exp( log(mass1Min) + XLALUniformDeviate( randParams ) *
295 (log(mass1Max) - log(mass1Min) ) );
296 inj->mass2 = exp( log(mass2Min) + XLALUniformDeviate( randParams ) *
297 (log(mass2Max) - log(mass2Min) ) );
298 mTotal = inj->mass1 + inj->mass2;
299 }
300 else if ( mDist == uniformTotalMass )
301 {
302 /*uniformly distributed total mass */
303 REAL4 minMass= mass1Min + mass2Min;
304 REAL4 maxMass= mass1Max + mass2Max;
305 mTotal = minMass + XLALUniformDeviate( randParams ) * (maxMass - minMass);
306 inj->mass2 = -1.0;
307 while( inj->mass2 > mass2Max || inj->mass2 <= mass2Min )
308 {
309 inj->mass1 = mass1Min +
310 XLALUniformDeviate( randParams ) * (mass1Max - mass1Min);
311 inj->mass2 = mTotal - inj->mass1;
312 }
313 }
314 }
315
316 inj->eta = inj->mass1 * inj->mass2 / ( mTotal * mTotal );
317 inj->mchirp = mTotal * pow(inj->eta, 0.6);
318
319 return ( inj );
320}
321
322/**
323 * Generates masses for an inspiral injection. Masses are Gaussian distributed
324 * with the requested mean and standard deviation.
325 */
327 SimInspiralTable *inj, /**< injection for which masses will be set*/
328 RandomParams *randParams,/**< random parameter details*/
329 REAL4 mass1Min, /**< minimum mass for first component */
330 REAL4 mass1Max, /**< maximum mass for first component */
331 REAL4 mass1Mean, /**< mean value for mass1 */
332 REAL4 mass1Std, /**< standard deviation of mass1 */
333 REAL4 mass2Min, /**< minimum mass for second component */
334 REAL4 mass2Max, /**< maximum mass for second component */
335 REAL4 mass2Mean, /**< mean value of mass2 */
336 REAL4 mass2Std /**< standard deviation of mass2 */
337 )
338{
339 REAL4 m1, m2, mtotal;
340
341 m1 = -1.0;
342 while ( (m1-mass1Max)*(m1-mass1Min) > 0 )
343 {
344 m1 = mass1Mean + mass1Std * XLALNormalDeviate( randParams );
345 }
346 m2 = -1.0;
347 while ( (m2-mass2Max)*(m2-mass2Min) > 0 )
348 {
349 m2 = mass2Mean + mass2Std * XLALNormalDeviate( randParams );
350 }
351
352 mtotal = m1 + m2;
353 inj->mass1 = m1;
354 inj->mass2 = m2;
355 inj->eta = inj->mass1 * inj->mass2 / ( mtotal * mtotal );
356 inj->mchirp = mtotal * pow(inj->eta, 0.6);
357
358 return ( inj );
359}
360
361/**
362 * Generates masses for an inspiral injection. Total mass and mass ratio
363 * are uniformly distributed
364 */
366 SimInspiralTable *inj, /**< injection for which masses will be set */
367 RandomParams *randParams,/**< random parameter details */
368 MassDistribution mDist, /**< the mass distribution to use */
369 REAL4 minTotalMass, /**< minimum total mass of binary */
370 REAL4 maxTotalMass, /**< maximum total mass of binary */
371 REAL4 minMassRatio, /**< minimum mass ratio */
372 REAL4 maxMassRatio /**< maximum mass ratio */
373 )
374{
375 REAL4 mtotal = -1.0;
376 REAL4 ratio = -1.0;
377
378 /* generate uniformly distributed total mass and mass ratio */
379 if ( mDist==uniformTotalMassRatio)
380 {
381 mtotal = minTotalMass + (XLALUniformDeviate(randParams) * (maxTotalMass - minTotalMass));
382 ratio = minMassRatio + (XLALUniformDeviate(randParams) * (maxMassRatio - minMassRatio));
383 }
384 else if ( mDist==logMassUniformTotalMassRatio)
385 {
386 mtotal = exp( log(minTotalMass) + XLALUniformDeviate(randParams) *
387 ( log(maxTotalMass) - log(minTotalMass) ) );
388 ratio = minMassRatio + (XLALUniformDeviate(randParams) * (maxMassRatio - minMassRatio));
389 }
390 else
391 {
392 /* unsupported distribution type */
394 }
395 inj->mass1 = (ratio * mtotal) / (ratio + 1);
396 inj->mass2 = mtotal / (ratio + 1);
397 inj->eta = inj->mass1 * inj->mass2 / ( mtotal * mtotal );
398 inj->mchirp = mtotal * pow(inj->eta, 0.6);
399
400 return ( inj );
401}
402
403/**
404 * Generates masses for an inspiral injection. Total mass and mass fraction
405 * m1 / M are uniformly distributed
406 */
408 SimInspiralTable *inj, /**< injection for which masses will be set */
409 RandomParams *randParams,/**< random parameter details */
410 MassDistribution mDist, /**< the mass distribution to use */
411 REAL4 minTotalMass, /**< minimum total mass of binary */
412 REAL4 maxTotalMass, /**< maximum total mass of binary */
413 REAL4 minMassRatio, /**< minimum mass ratio */
414 REAL4 maxMassRatio /**< maximum mass ratio */
415 )
416{
417 REAL4 mtotal = -1.0;
418 REAL4 fraction = -1.0;
419 REAL4 minfraction = -1.0;
420 REAL4 maxfraction = -1.0;
421
422 if ( mDist==uniformTotalMassFraction)
423 {
424 mtotal = minTotalMass + (XLALUniformDeviate(randParams) * (maxTotalMass - minTotalMass));
425 minfraction = 1 / (1 + 1 / minMassRatio);
426 maxfraction = 1 / (1 + 1 / maxMassRatio);
427 fraction = minfraction + (XLALUniformDeviate(randParams) * (maxfraction - minfraction));
428 }
429 else
430 {
431 /* unsupported distribution type */
433 }
434 inj->mass1 = fraction * mtotal;
435 inj->mass2 = mtotal - inj->mass1;
436 inj->eta = inj->mass1 * inj->mass2 / ( mtotal * mtotal );
437 inj->mchirp = mtotal * pow(inj->eta, 0.6);
438
439 return ( inj );
440}
441
442/**
443 * Generates spins for an inspiral injection.
444 * Spin magnitudes lie between the specified max and min values.
445 *
446 * The parameter alignInj controls whether spins are aligned with the orbital
447 * angular momentum according to two separate coordinate conventions (along z-axis
448 * as for IMRPhenom, or in x-z plane as for SpinTaylor).
449 *
450 * For single-spin-like systems as treated in the 'PTF' paper (Pan, Buonanno, Chen and
451 * Vallisneri, gr-qc/03100034) the component of spin1 along the direction of orbital
452 * angular momentum (where m1>m2) is specified by the kappa1 bounds.
453 *
454 * Otherwise, orientations for spin1 and spin2 are random.
455 */
457 SimInspiralTable *inj, /**< injection for which spins will be set*/
458 RandomParams *randParams,/**< random parameter details*/
459 REAL4 spin1Min, /**< minimum magnitude of spin1 */
460 REAL4 spin1Max, /**< maximum magnitude of spin1 */
461 REAL4 spin2Min, /**< minimum magnitude of spin2 */
462 REAL4 spin2Max, /**< maximum magnitude of spin2 */
463 REAL4 kappa1Min, /**< minimum value of spin1 . L_N */
464 REAL4 kappa1Max, /**< maximum value of spin1 . L_N */
465 REAL4 abskappa1Min, /**< minimum absolute value of spin1 . L_N */
466 REAL4 abskappa1Max, /**< maximum absolute value of spin1 . L_N */
467 AlignmentType alignInj, /**< choice of convention for aligned spins */
468 SpinDistribution distribution, /**< the spin magnitude distribution to use */
469 REAL4 spin1Mean, /**< mean value for |spin1| gaussian */
470 REAL4 spin1Std, /**< standard deviation for |spin1| */
471 REAL4 spin2Mean, /**< mean value for |spin2| gaussian */
472 REAL4 spin2Std /**< standard deviation for |spin2| */
473 )
474{
475 REAL4 spin1Mag;
476 REAL4 spin2Mag;
477 REAL4 r1;
478 REAL4 r2;
479 REAL4 phi1;
480 REAL4 phi2;
481 REAL4 kappa;
482 REAL4 sintheta;
483 REAL4 zmin;
484 REAL4 zmax;
485 REAL4 inc;
486 REAL4 cosinc;
487 REAL4 sininc;
488 REAL4 sgn;
489
490 inc = inj->inclination;
491 cosinc = cos( inc );
492 sininc = sin( inc );
493 kappa = -2.0;
494
495 /* spin1Mag */
496 switch (distribution)
497 {
498 case uniformSpinDist: spin1Mag = spin1Min + XLALUniformDeviate( randParams ) *(spin1Max - spin1Min);
499 break;
500 case gaussianSpinDist:
501 do spin1Mag = spin1Mean + spin1Std*XLALNormalDeviate(randParams);
502 while ( spin1Mag > spin1Max || spin1Mag < spin1Min );
503 break;
504 default: {
505 fprintf( stderr,"Spin magnitude distribution not known.\n" );
507 }
508
509 }
510
511 /* Check if initial spin orientation is specified by user */
512 if ( (kappa1Min > -1.0) || (kappa1Max < 1.0) )
513 {
514 kappa = kappa1Min + XLALUniformDeviate( randParams ) *
515 ( kappa1Max - kappa1Min );
516 }
517 else if ( (abskappa1Min > 0.0) || (abskappa1Max < 1.0) )
518 {
519 kappa = abskappa1Min + XLALUniformDeviate( randParams ) *
520 ( abskappa1Max - abskappa1Min );
521 sgn = XLALUniformDeviate( randParams ) - 0.5;
522 sgn = (sgn > 0.0) ? 1.0 : -1.0;
523 kappa = kappa * sgn;
524 }
525
526 /* spin1z */
527 if (kappa > -2.0)
528 {
529 sintheta = sqrt( 1 - kappa * kappa );
530 zmin = spin1Mag * ( cosinc * kappa - sininc * sintheta );
531 zmax = spin1Mag * ( cosinc * kappa + sininc * sintheta );
532 inj->spin1z = zmin + XLALUniformDeviate( randParams ) * (zmax - zmin);
533 }
534 else if (alignInj==inxzPlane)
535 {
536 inj->spin1z = spin1Mag * cosinc;
537 }
538 else if (alignInj==alongzAxis)
539 {
540 /* z-component of aligned spin equal to the spin magnitude and
541 random in sign */
542 sgn = XLALUniformDeviate( randParams ) - 0.5;
543 sgn = (sgn > 0.0) ? 1.0 : -1.0;
544 inj->spin1z = spin1Mag * sgn;
545 }
546 else
547 {
548 inj->spin1z = (XLALUniformDeviate( randParams ) - 0.5) * 2 * (spin1Mag);
549 }
550
551 /* spin1x and spin1y */
552 if (kappa > -2.0 && inc!=0) {
553 inj->spin1x = (kappa * spin1Mag - inj->spin1z * cosinc) / sininc ;
554 inj->spin1y = pow( ((spin1Mag * spin1Mag) - (inj->spin1z * inj->spin1z) -
555 (inj->spin1x * inj->spin1x)) , 0.5);
556 }
557 else if (alignInj==inxzPlane)
558 {
559 inj->spin1x = spin1Mag * sininc;
560 /* randomize sign of S_1.L_N while keeping spin along L_N */
561 sgn = XLALUniformDeviate( randParams ) - 0.5;
562 sgn = (sgn > 0.0) ? 1.0 : -1.0;
563 inj->spin1x = inj->spin1x * sgn;
564 inj->spin1z = inj->spin1z * sgn;
565 inj->spin1y = 0.0;
566 }
567 else if (alignInj==alongzAxis)
568 {
569 inj->spin1x = 0.0;
570 inj->spin1y = 0.0;
571 }
572 else
573 {
574 /* phi1 */
575 r1 = pow( ((spin1Mag * spin1Mag) - (inj->spin1z * inj->spin1z)) , 0.5);
576 phi1 = XLALUniformDeviate( randParams ) * LAL_TWOPI;
577 /* spin1x and spin1y */
578 inj->spin1x = r1 * cos(phi1);
579 inj->spin1y = r1 * sin(phi1);
580 }
581
582 /* spin2Mag */
583 switch (distribution)
584 {
585 case uniformSpinDist: spin2Mag = spin2Min + XLALUniformDeviate( randParams ) *(spin2Max - spin2Min);
586 break;
587 case gaussianSpinDist:
588 do spin2Mag = spin2Mean + spin2Std*XLALNormalDeviate(randParams);
589 while ( spin2Mag > spin2Max || spin2Mag < spin2Min );
590 break;
591 default: {
592 fprintf( stderr,"Spin magnitude distribution not known.\n" );
594 }
595
596 }
597
598 /* aligned case */
599 if (alignInj==inxzPlane)
600 {
601 sgn = XLALUniformDeviate( randParams ) - 0.5;
602 sgn = (sgn > 0.0) ? 1.0 : -1.0;
603 inj->spin2z = spin2Mag * cosinc * sgn;
604 inj->spin2x = spin2Mag * sininc * sgn;
605 inj->spin2y = 0.0;
606 }
607 else if (alignInj==alongzAxis)
608 {
609 inj->spin2x = 0.0;
610 inj->spin2y = 0.0;
611 sgn = XLALUniformDeviate( randParams ) - 0.5;
612 sgn = (sgn > 0.0) ? 1.0 : -1.0;
613 inj->spin2z = spin2Mag * sgn;
614 }
615 else
616 {
617 /* spin2z */
618 inj->spin2z = (XLALUniformDeviate( randParams ) - 0.5) * 2 * (spin2Mag);
619 r2 = pow( ((spin2Mag * spin2Mag) - (inj->spin2z * inj->spin2z)) ,
620 0.5);
621
622 /* phi2 */
623 phi2 = XLALUniformDeviate( randParams ) * LAL_TWOPI;
624
625 /* spin2x and spin2y */
626 inj->spin2x = r2 * cos(phi2);
627 inj->spin2y = r2 * sin(phi2);
628 }
629
630 return ( inj );
631}
632
633
634/** Generates random masses for an inspiral injection. */
636 SimInspiralTable *inj, /**< injection for which masses will be set*/
637 RandomParams *randParams,/**< random parameter details*/
638 REAL4 minTotalMass, /**< minimum total mass of binary */
639 REAL4 maxTotalMass, /**< maximum total mass of binary */
640 SimInspiralTable *nrInjParams /**< parameters of NR injection*/
641 )
642{
643 REAL4 mtotal;
644
645 mtotal = minTotalMass + XLALUniformDeviate( randParams ) * \
646 (maxTotalMass - minTotalMass);
647 inj->eta = nrInjParams->eta;
648 inj->mchirp = mtotal * pow(inj->eta, 3.0/5.0);
649
650 /* set mass1 and mass2 */
651 inj->mass1 = (mtotal / 2.0) * (1 + pow( (1 - 4 * inj->eta), 0.5) );
652 inj->mass2 = (mtotal / 2.0) * (1 - pow( (1 - 4 * inj->eta), 0.5) );
653
654 /* copy over the spin parameters */
655 inj->spin1x = nrInjParams->spin1x;
656 inj->spin1y = nrInjParams->spin1y;
657 inj->spin1z = nrInjParams->spin1z;
658 inj->spin2x = nrInjParams->spin2x;
659 inj->spin2y = nrInjParams->spin2y;
660 inj->spin2z = nrInjParams->spin2z;
661
662 /* copy over the numrel information */
663 inj->numrel_mode_min = nrInjParams->numrel_mode_min;
664 inj->numrel_mode_max = nrInjParams->numrel_mode_max;
665 snprintf(inj->numrel_data, LIGOMETA_STRING_MAX, "%s",
666 nrInjParams->numrel_data);
667
668 return ( inj );
669}
670
671/** Set end time and effective distance of an injection for a detector */
673 SimInspiralTable *inj, /**< the injection details */
674 const LALDetector *detector, /**< the detector of interest */
675 LIGOTimeGPS *endTime, /**< the end time to populate */
676 REAL4 *effDist /**< the effective distance to populate */
677 )
678{
679 REAL8 tDelay, fplus, fcross;
680 REAL4 splus, scross, cosiota;
681
682 /* calculate the detector end time */
683 tDelay = XLALTimeDelayFromEarthCenter( detector->location, inj->longitude,
684 inj->latitude, &(inj->geocent_end_time) );
685 *endTime = inj->geocent_end_time;
686 *endTime = *XLALGPSAdd( endTime, tDelay );
687
688 /* initialize distance with real distance and compute splus and scross */
689 *effDist = 2.0 * inj->distance;
690 cosiota = cos( inj->inclination );
691 splus = -( 1.0 + cosiota * cosiota );
692 scross = -2.0 * cosiota;
693
694 /* calculate the detector response */
695 XLALComputeDetAMResponse(&fplus, &fcross, (const REAL4(*)[3])detector->response, inj->longitude,
696 inj->latitude, inj->polarization, inj->end_time_gmst);
697
698 /* compute the effective distance */
699 *effDist /= sqrt(
700 splus*splus*fplus*fplus + scross*scross*fcross*fcross );
701
702 return ( inj );
703}
704
705/**
706 * Set the end time and effective distance for all detectors for this
707 * injection
708 */
710 SimInspiralTable *inj /**< the injection */
711 )
712{
714 REAL4 *eff_dist;
716
717 /* LIGO Hanford observatory*/
719 end_time = &(inj->h_end_time);
720 eff_dist = &(inj->eff_dist_h);
721 inj = XLALInspiralSiteTimeAndDist(inj, &detector, end_time, eff_dist);
722
723 /* LIGO Livingston observatory*/
725 end_time = &(inj->l_end_time);
726 eff_dist = &(inj->eff_dist_l);
727 inj = XLALInspiralSiteTimeAndDist(inj, &detector, end_time, eff_dist);
728
729 /* GEO observatory*/
731 end_time = &(inj->g_end_time);
732 eff_dist = &(inj->eff_dist_g);
733 inj = XLALInspiralSiteTimeAndDist(inj, &detector, end_time, eff_dist);
734
735 /* TAMA observatory*/
737 end_time = &(inj->t_end_time);
738 eff_dist = &(inj->eff_dist_t);
739 inj = XLALInspiralSiteTimeAndDist(inj, &detector, end_time, eff_dist);
740
741 /* Virgo observatory*/
743 end_time = &(inj->v_end_time);
744 eff_dist = &(inj->eff_dist_v);
745 inj = XLALInspiralSiteTimeAndDist(inj, &detector, end_time, eff_dist);
746
747 return ( inj );
748}
749
750/**
751 * Populate a frequency series with the actuation response. Here, we just use
752 * the pendulum part of the actuation function
753 */
755 COMPLEX8FrequencySeries *resp, /* the frequency series to be populated */
756 REAL4 ETMcal,/* the ETM calibration */
757 REAL4 pendF, /* the pendulum frequency */
758 REAL4 pendQ /* the pendulum Q */
759 )
760{
761 UINT4 k;
762 REAL4 fNorm = 0;
763 COMPLEX8Vector *num = NULL;
764 COMPLEX8Vector *denom = NULL;
765
766 num = XLALCreateCOMPLEX8Vector( resp->data->length );
767 denom = XLALCreateCOMPLEX8Vector( resp->data->length );
768
769 /* the response function is
770 *
771 * ETMcal * pendF^2
772 * R(f) = ---------------------------------------
773 * pendF^2 - freq^2 - i freq (pendF/pendQ)
774 */
775
776 for ( k = 0; k < resp->data->length; k++ )
777 {
778 fNorm = k * resp->deltaF / pendF;
779 denom->data[k] = crectf( ( 1 - fNorm * fNorm ), - fNorm / pendQ );
780 num->data[k] = crectf( -1.0 * ETMcal, 0.0 );
781 }
782
783 XLALCCVectorDivide( resp->data, num, denom);
786 return( resp );
787}
LALDetectorIndexLLODIFF
LALDetectorIndexGEO600DIFF
LALDetectorIndexTAMA300DIFF
LALDetectorIndexVIRGODIFF
LALDetectorIndexLHODIFF
#define LIGOMETA_STRING_MAX
static INT8 end_time(const SnglInspiralTable *x)
#define fprintf
const char * detector
const double u
const double r2
const double rho2
void LALGalacticToEquatorial(LALStatus *stat, SkyPosition *output, SkyPosition *input)
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)
void XLALRandomInspiralMilkywayLocation(REAL8 *rightAscension, REAL8 *declination, REAL8 *distance, RandomParams *randParams)
Generates a location within the Milky Way for an inspiral injection.
SpinDistribution
enum containing the different ways in which the spin magnitudes of injections can be distributed
SimInspiralTable * XLALFixedInspiralMasses(SimInspiralTable *inj, REAL4 mass1Fix, REAL4 mass2Fix)
Set masses to fixed values for an inspiral injection.
SimInspiralTable * XLALRandomInspiralSkyLocation(SimInspiralTable *inj, RandomParams *randParams)
Generates a random sky location (right ascension=longitude, delta=latitude) for an inspiral injection...
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)
Generates spins for an inspiral injection.
LoudnessDistribution
enum containing the different ways in which the loudness of injections can be distributed
MassDistribution
enum containing the different ways in which the masses of injections can be distributed
SimInspiralTable * XLALRandomInspiralDistance(SimInspiralTable *inj, RandomParams *randParams, LoudnessDistribution dDist, REAL4 distMin, REAL4 distMax)
Generates the distance for an inspiral injection, based on the requested distribution and max/min dis...
SimInspiralTable * XLALGaussianInspiralMasses(SimInspiralTable *inj, RandomParams *randParams, REAL4 mass1Min, REAL4 mass1Max, REAL4 mass1Mean, REAL4 mass1Std, REAL4 mass2Min, REAL4 mass2Max, REAL4 mass2Mean, REAL4 mass2Std)
Generates masses for an inspiral injection.
SimInspiralTable * XLALRandomInspiralTime(SimInspiralTable *inj, RandomParams *randParams, LIGOTimeGPS startTime, REAL4 timeWindow)
Generates the geocent_end_time for an inspiral injection, based on the given startTime and timeWindow...
COMPLEX8FrequencySeries * generateActuation(COMPLEX8FrequencySeries *resp, REAL4 ETMcal, REAL4 pendF, REAL4 pendQ)
Populate a frequency series with the actuation response.
SimInspiralTable * XLALRandomInspiralTotalMassFraction(SimInspiralTable *inj, RandomParams *randParams, MassDistribution mDist, REAL4 minTotalMass, REAL4 maxTotalMass, REAL4 minMassRatio, REAL4 maxMassRatio)
Generates masses for an inspiral injection.
InclDistribution
enum containing the different ways in which the inclinations of injections can be distributed
AlignmentType
enum for two distinct ways a spin-aligned injection is realized depending on the waveform family
SimInspiralTable * XLALm1m2SquareGridInspiralMasses(SimInspiralTable *inj, REAL4 mass1Min, REAL4 mass2Min, REAL4 minTotalMass, REAL4 maxTotalMass, REAL4 mass1Delta, REAL4 mass2Delta, INT4 mass1Pnt, INT4 mass2Pnt, INT4 injNum, INT4 *count)
Places component masses on a square grid for an inspiral injection.
SimInspiralTable * XLALInspiralSiteTimeAndDist(SimInspiralTable *inj, const LALDetector *detector, LIGOTimeGPS *endTime, REAL4 *effDist)
Set end time and effective distance of an injection for a detector.
SimInspiralTable * XLALRandomNRInjectTotalMass(SimInspiralTable *inj, RandomParams *randParams, REAL4 minTotalMass, REAL4 maxTotalMass, SimInspiralTable *nrInjParams)
Generates random masses for an inspiral injection.
SimInspiralTable * XLALPopulateSimInspiralSiteInfo(SimInspiralTable *inj)
Set the end time and effective distance for all detectors for this injection.
SimInspiralTable * XLALRandomInspiralMasses(SimInspiralTable *inj, RandomParams *randParams, MassDistribution mDist, REAL4 mass1Min, REAL4 mass1Max, REAL4 mass2Min, REAL4 mass2Max, REAL4 minTotalMass, REAL4 maxTotalMass)
Generates random masses for an inspiral injection.
SimInspiralTable * XLALRandomInspiralOrientation(SimInspiralTable *inj, RandomParams *randParams, InclDistribution iDist, REAL4 inclinationPeak)
Generates a random orientation (polarization, inclination, coa_phase) for an inspiral injection.
SimInspiralTable * XLALRandomInspiralTotalMassRatio(SimInspiralTable *inj, RandomParams *randParams, MassDistribution mDist, REAL4 minTotalMass, REAL4 maxTotalMass, REAL4 minMassRatio, REAL4 maxMassRatio)
Generates masses for an inspiral injection.
@ gaussianSpinDist
@ uniformLogDistance
@ uniformDistance
@ uniformDistanceSquared
@ logComponentMass
@ uniformTotalMass
@ uniformTotalMassRatio
@ uniformTotalMassFraction
@ uniformComponentMass
@ logMassUniformTotalMassRatio
@ gaussianInclDist
#define LAL_TWOPI
double REAL8
#define crectf(re, im)
uint32_t UINT4
int32_t INT4
float REAL4
REAL4 XLALNormalDeviate(RandomParams *params)
static const INT4 r
REAL4 XLALUniformDeviate(RandomParams *params)
COORDINATESYSTEM_GALACTIC
REAL8 XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
COMPLEX8Vector * XLALCreateCOMPLEX8Vector(UINT4 length)
void XLALDestroyCOMPLEX8Vector(COMPLEX8Vector *vector)
COMPLEX8Vector * XLALCCVectorDivide(COMPLEX8Vector *out, const COMPLEX8Vector *in1, const COMPLEX8Vector *in2)
#define XLAL_ERROR_NULL(...)
XLAL_EDOM
XLAL_EINVAL
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
COMPLEX8Sequence * data
COMPLEX8 * data
LIGOTimeGPS l_end_time
LIGOTimeGPS geocent_end_time
LIGOTimeGPS v_end_time
LIGOTimeGPS t_end_time
LIGOTimeGPS g_end_time
LIGOTimeGPS h_end_time
CHAR numrel_data[LIGOMETA_STRING_MAX]
REAL8 longitude
REAL8 latitude
CoordinateSystem system