GetInspiralParams.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Duncan Brown, Jolien Creighton, Teviet Creighton, John Whelan
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /**************************** <lalVerbatim file="GetInspiralParamsCV">
00021 Author: Creighton, T. D.
00022 $Id: GetInspiralParams.c,v 1.11 2007/06/08 14:41:47 bema Exp $
00023 **************************************************** </lalVerbatim> */
00024 
00025 /********************************************************** <lalLaTeX>
00026 
00027 \providecommand{\lessim}{\stackrel{<}{\scriptstyle\sim}}
00028 
00029 \subsection{Module \texttt{GetInspiralParams.c}}
00030 \label{ss:GetInspiralParams.c}
00031 
00032 Computes the input parameters for a PPN inspiral.
00033 
00034 \subsubsection*{Prototypes}
00035 \vspace{0.1in}
00036 \input{GetInspiralParamsCP}
00037 \idx{LALGetInspiralParams()}
00038 
00039 \subsubsection*{Description}
00040 
00041 This function takes a Galactic location and pair of masses from
00042 \verb@*input@ and uses them to set the \verb@PPNParamStruc@ fields
00043 \verb@output->position@, \verb@output->mTot@, \verb@output->eta@, and
00044 \verb@output->d@.  The fields \verb@output->psi@, \verb@output->inc@,
00045 and \verb@output->phi@ are set randomly to reflect a uniform
00046 distribution in solid angle (that is, cosine of inclination is uniform
00047 between $-1$ and 1, other angles are uniform between 0 and $2\pi$).
00048 The routine uses the random sequence specified by \verb@*params@ when
00049 given, but if \verb@*params@=\verb@NULL@ a new sequence is started
00050 internally using the current execution time as a seed. The field
00051 \verb@input->geocentEndTime@ is ignored by this routine.
00052 
00053 The other \verb@PPNParamStruc@ input fields are not touched by this
00054 routine, and must be specified externally before generating a waveform
00055 with this structure.
00056 
00057 \subsubsection*{Algorithm}
00058 
00059 Galactocentric Galactic axial coordinates $\rho$, $z$, and $l_G$ are
00060 transformed to geocentric Galactic Cartesian coordinates:
00061 \begin{eqnarray}
00062 x_e & = & R_e + \rho\cos l_G \;,\nonumber\\
00063 y_e & = & \rho\sin l_G \;,\nonumber\\
00064 z_e & = & z \;,
00065 \end{eqnarray}
00066 where
00067 $$
00068 R_e \approx 8.5\,\mathrm{kpc}
00069 $$
00070 is the distance to the Galactic core (this constant will probably
00071 migrate into \verb@LALConstants.h@ eventually).  These are converted
00072 to geocentric Galactic spherical coordinates:
00073 \begin{eqnarray}
00074 d & = & \sqrt{x_e^2 + y_e^2 + z_e^2} \;,\nonumber\\
00075 b & = & \arcsin\left(\frac{z_e}{d_e}\right) \;,\nonumber\\
00076 l & = & \arctan\!2(y_e,x_e) \;.
00077 \end{eqnarray}
00078 In the calculation of $d$ we factor out the leading order term from
00079 the square root to avoid inadvertent overflow, and check for underflow
00080 in case the location lies on top of the Earth.  The angular
00081 coordinates are then transformed to equatorial celestial coordinates
00082 $\alpha$ and $\delta$ using the routines in \verb@SkyCoordinates.h@.
00083 
00084 \subsubsection*{Uses}
00085 \begin{verbatim}
00086 LALGalacticToEquatorial()       LALUniformDeviate()
00087 LALCreateRandomParams()         LALDestroyRandomParams()
00088 \end{verbatim}
00089 
00090 \subsubsection*{Notes}
00091 
00092 \vfill{\footnotesize\input{GetInspiralParamsCV}}
00093 
00094 ******************************************************* </lalLaTeX> */
00095 
00096 #include <math.h>
00097 #include <lal/LALStdlib.h>
00098 #include <lal/LALConstants.h>
00099 #include <lal/GeneratePPNInspiral.h>
00100 #include <lal/SkyCoordinates.h>
00101 
00102 NRCSID( GETINSPIRALPARAMSC, "$Id: GetInspiralParams.c,v 1.11 2007/06/08 14:41:47 bema Exp $" );
00103 
00104 #define LAL_DGALCORE_SI (2.62e20) /* Galactic core distance (metres) */
00105 
00106 /* <lalVerbatim file="GetInspiralParamsCP"> */
00107 void
00108 LALGetInspiralParams( LALStatus                  *stat,
00109                       PPNParamStruc              *output,
00110                       GalacticInspiralParamStruc *input,
00111                       RandomParams               *params )
00112 { /* </lalVerbatim> */
00113   REAL4 x, y, z;  /* geocentric Galactic Cartesian coordinates */
00114   REAL4 max, d;   /* maximum of x, y, and z, and normalized distance */
00115   REAL4 psi, phi, inc; /* polarization, phase, and inclination angles */
00116   REAL4 mTot;          /* total binary mass */
00117   SkyPosition direction; /* direction to the source */
00118   RandomParams *localParams = NULL; /* local random parameters pointer */
00119 
00120   INITSTATUS( stat, "LALGetInspiralParams", GETINSPIRALPARAMSC );
00121   ATTATCHSTATUSPTR( stat );
00122 
00123   /* Make sure parameter structures exist. */
00124   ASSERT( output, stat, GENERATEPPNINSPIRALH_ENUL,
00125           GENERATEPPNINSPIRALH_MSGENUL );
00126   ASSERT( input, stat, GENERATEPPNINSPIRALH_ENUL,
00127           GENERATEPPNINSPIRALH_MSGENUL );
00128 
00129   /* Compute total mass. */
00130   mTot = input->m1 + input->m2;
00131   if ( mTot == 0.0 ) {
00132     ABORT( stat, GENERATEPPNINSPIRALH_EMBAD,
00133            GENERATEPPNINSPIRALH_MSGEMBAD );
00134   }
00135 
00136   /* Compute Galactic geocentric Cartesian coordinates. */
00137   x = LAL_DGALCORE_SI + input->rho*1e3*LAL_PC_SI*cos( input->lGal );
00138   y = input->rho*1e3*LAL_PC_SI*sin( input->lGal );
00139   z = input->z*1e3*LAL_PC_SI;
00140 
00141   /* Compute Galactic geocentric spherical coordinates. */
00142   max = fabs( x );
00143   if ( fabs( y ) > max )
00144     max = fabs( y );
00145   if ( fabs( z ) > max )
00146     max = fabs( z );
00147   if ( max == 0.0 ) {
00148     ABORT( stat, GENERATEPPNINSPIRALH_EDBAD,
00149            GENERATEPPNINSPIRALH_MSGEDBAD );
00150   }
00151   x /= max;
00152   y /= max;
00153   z /= max;
00154   d = sqrt( x*x + y*y + z*z );
00155   direction.latitude = asin( z/d );
00156   direction.longitude = atan2( y, x );
00157   direction.system = COORDINATESYSTEM_GALACTIC;
00158 
00159   /* Compute equatorial coordinates. */
00160   TRY( LALGalacticToEquatorial( stat->statusPtr, &direction,
00161                                 &direction ), stat );
00162   output->position = direction;
00163   output->d = max*d;
00164 
00165   /* If we haven't been given a random sequence, generate one. */
00166   if ( params )
00167     localParams = params;
00168   else {
00169     TRY( LALCreateRandomParams( stat->statusPtr, &localParams, 0 ),
00170          stat );
00171   }
00172 
00173   /* Compute random inclination and polarization angle. */
00174   LALUniformDeviate( stat->statusPtr, &psi, localParams );
00175   if ( params )
00176     CHECKSTATUSPTR( stat );
00177   else
00178     BEGINFAIL( stat )
00179       TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
00180            stat );
00181       ENDFAIL( stat );
00182   LALUniformDeviate( stat->statusPtr, &phi, localParams );
00183   if ( params )
00184     CHECKSTATUSPTR( stat );
00185   else
00186     BEGINFAIL( stat )
00187       TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
00188            stat );
00189     ENDFAIL( stat );
00190   LALUniformDeviate( stat->statusPtr, &inc, localParams );
00191   if ( params )
00192     CHECKSTATUSPTR( stat );
00193   else
00194     BEGINFAIL( stat )
00195       TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
00196            stat );
00197     ENDFAIL( stat );
00198   output->psi = LAL_TWOPI*psi;
00199   output->phi = LAL_TWOPI*phi;
00200   inc = 2.0*inc - 1.0;
00201   output->inc = acos( inc );
00202 
00203   /* Set output masses. */
00204   output->mTot = mTot;
00205   output->eta = (input->m1/mTot)*(input->m2/mTot);
00206 
00207   /* Clean up and exit. */
00208   if ( !params ) {
00209     TRY( LALDestroyRandomParams( stat->statusPtr, &localParams ),
00210          stat );
00211   }
00212   DETATCHSTATUSPTR( stat );
00213   RETURN( stat );
00214 }

Generated on Sun Sep 7 03:06:46 2008 for LAL by  doxygen 1.5.2