LALInspiral 5.0.3.1-eeff03c
GetInspiralParams.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Duncan Brown, Jolien Creighton, Teviet Creighton, John Whelan
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 <math.h>
21#include <lal/LALStdlib.h>
22#include <lal/LALConstants.h>
23#include <lal/GeneratePPNInspiral.h>
24#include <lal/SkyCoordinates.h>
25
26#define LAL_DGALCORE_SI (2.62e20) /* Galactic core distance (metres) */
27
28/**
29 * \author Creighton, T. D.
30 *
31 * \brief Computes the input parameters for a PPN inspiral.
32 *
33 * ### Description ###
34 *
35 * This function takes a Galactic location and pair of masses from
36 * <tt>*input</tt> and uses them to set the \c PPNParamStruc fields
37 * <tt>output->position</tt>, <tt>output->mTot</tt>, <tt>output->eta</tt>, and
38 * <tt>output->d</tt>. The fields <tt>output->psi</tt>, <tt>output->inc</tt>,
39 * and <tt>output->phi</tt> are set randomly to reflect a uniform
40 * distribution in solid angle (that is, cosine of inclination is uniform
41 * between \f$-1\f$ and 1, other angles are uniform between 0 and \f$2\pi\f$).
42 * The routine uses the random sequence specified by <tt>*params</tt> when
43 * given, but if <tt>*params</tt>=\c NULL a new sequence is started
44 * internally using the current execution time as a seed. The field
45 * <tt>input->geocentEndTime</tt> is ignored by this routine.
46 *
47 * The other \c PPNParamStruc input fields are not touched by this
48 * routine, and must be specified externally before generating a waveform
49 * with this structure.
50 *
51 * ### Algorithm ###
52 *
53 * Galactocentric Galactic axial coordinates \f$\rho\f$, \f$z\f$, and \f$l_G\f$ are
54 * transformed to geocentric Galactic Cartesian coordinates:
55 * \f{eqnarray}{
56 * x_e & = & R_e + \rho\cos l_G \;,\\
57 * y_e & = & \rho\sin l_G \;,\\
58 * z_e & = & z \;,
59 * \f}
60 * where
61 * \f[
62 * R_e \approx 8.5\,\mathrm{kpc}
63 * \f]
64 * is the distance to the Galactic core (this constant will probably
65 * migrate into \ref LALConstants.h eventually). These are converted
66 * to geocentric Galactic spherical coordinates:
67 * \f{eqnarray}{
68 * d & = & \sqrt{x_e^2 + y_e^2 + z_e^2} \;,\\
69 * b & = & \arcsin\left(\frac{z_e}{d_e}\right) \;,\\
70 * l & = & \arctan\!2(y_e,x_e) \;.
71 * \f}
72 * In the calculation of \f$d\f$ we factor out the leading order term from
73 * the square root to avoid inadvertent overflow, and check for underflow
74 * in case the location lies on top of the Earth. The angular
75 * coordinates are then transformed to equatorial celestial coordinates
76 * \f$\alpha\f$ and \f$\delta\f$ using the routines in \ref SkyCoordinates.h.
77 *
78 */
79void
81 PPNParamStruc *output,
84{
85 REAL4 x, y, z; /* geocentric Galactic Cartesian coordinates */
86 REAL4 max, d; /* maximum of x, y, and z, and normalized distance */
87 REAL4 psi, phi, inc; /* polarization, phase, and inclination angles */
88 REAL4 mTot; /* total binary mass */
89 SkyPosition direction; /* direction to the source */
90 RandomParams *localParams = NULL; /* local random parameters pointer */
91
92 INITSTATUS(stat);
93 ATTATCHSTATUSPTR( stat );
94
95 /* Make sure parameter structures exist. */
97 GENERATEPPNINSPIRALH_MSGENUL );
99 GENERATEPPNINSPIRALH_MSGENUL );
100
101 /* Compute total mass. */
102 mTot = input->m1 + input->m2;
103 if ( mTot == 0.0 ) {
105 GENERATEPPNINSPIRALH_MSGEMBAD );
106 }
107
108 /* Compute Galactic geocentric Cartesian coordinates. */
109 x = LAL_DGALCORE_SI + input->rho*1e3*LAL_PC_SI*cos( input->lGal );
110 y = input->rho*1e3*LAL_PC_SI*sin( input->lGal );
111 z = input->z*1e3*LAL_PC_SI;
112
113 /* Compute Galactic geocentric spherical coordinates. */
114 max = fabs( x );
115 if ( fabs( y ) > max )
116 max = fabs( y );
117 if ( fabs( z ) > max )
118 max = fabs( z );
119 if ( max == 0.0 ) {
121 GENERATEPPNINSPIRALH_MSGEDBAD );
122 }
123 x /= max;
124 y /= max;
125 z /= max;
126 d = sqrt( x*x + y*y + z*z );
127 direction.latitude = asin( z/d );
128 direction.longitude = atan2( y, x );
130
131 /* Compute equatorial coordinates. */
132 TRY( LALGalacticToEquatorial( stat->statusPtr, &direction,
133 &direction ), stat );
134 output->position = direction;
135 output->d = max*d;
136
137 /* If we haven't been given a random sequence, generate one. */
138 if ( params )
139 localParams = params;
140 else {
141 TRY( LALCreateRandomParams( stat->statusPtr, &localParams, 0 ),
142 stat );
143 }
144
145 /* Compute random inclination and polarization angle. */
146 LALUniformDeviate( stat->statusPtr, &psi, localParams );
147 if ( params )
148 CHECKSTATUSPTR( stat );
149 else
150 BEGINFAIL( stat )
151 TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
152 stat );
153 ENDFAIL( stat );
154 LALUniformDeviate( stat->statusPtr, &phi, localParams );
155 if ( params )
156 CHECKSTATUSPTR( stat );
157 else
158 BEGINFAIL( stat )
159 TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
160 stat );
161 ENDFAIL( stat );
162 LALUniformDeviate( stat->statusPtr, &inc, localParams );
163 if ( params )
164 CHECKSTATUSPTR( stat );
165 else
166 BEGINFAIL( stat )
167 TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
168 stat );
169 ENDFAIL( stat );
170 output->psi = LAL_TWOPI*psi;
171 output->phi = LAL_TWOPI*phi;
172 inc = 2.0*inc - 1.0;
173 output->inc = acos( inc );
174
175 /* Set output masses. */
176 output->mTot = mTot;
177 output->eta = (input->m1/mTot)*(input->m2/mTot);
178
179 /* Clean up and exit. */
180 if ( !params ) {
181 TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
182 stat );
183 }
184 DETATCHSTATUSPTR( stat );
185 RETURN( stat );
186}
#define LAL_DGALCORE_SI
#define ABORT(statusptr, code, mesg)
#define CHECKSTATUSPTR(statusptr)
#define ENDFAIL(statusptr)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define BEGINFAIL(statusptr)
void LALGalacticToEquatorial(LALStatus *stat, SkyPosition *output, SkyPosition *input)
#define GENERATEPPNINSPIRALH_EDBAD
Bad distance.
#define GENERATEPPNINSPIRALH_EMBAD
Bad masses.
#define GENERATEPPNINSPIRALH_ENUL
Unexpected null pointer in arguments.
void LALGetInspiralParams(LALStatus *stat, PPNParamStruc *output, GalacticInspiralParamStruc *input, RandomParams *params)
Computes the input parameters for a PPN inspiral.
#define LAL_TWOPI
#define LAL_PC_SI
float REAL4
void LALCreateRandomParams(LALStatus *status, RandomParams **params, INT4 seed)
void LALUniformDeviate(LALStatus *status, REAL4 *deviate, RandomParams *params)
void LALDestroyRandomParams(LALStatus *status, RandomParams **params)
COORDINATESYSTEM_GALACTIC
list y
x
This structure stores the position and mass parameters of a galactic inspiral event.
REAL4 lGal
The Galactocentric Galactic longitude of the system (ie the Galactic longitude of the direction from ...
REAL4 z
The distance of the system from the Galactic plane, in kpc.
REAL4 rho
The distance of the binary system from the Galactic axis, in kpc.
REAL4 m2
The masses of the binary components, in solar masses.
struct tagLALStatus * statusPtr
This structure stores the parameters for constructing a restricted post-Newtonian waveform.
REAL8 longitude
REAL8 latitude
CoordinateSystem system
char output[FILENAME_MAX]