00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <math.h>
00029 #include <sys/times.h>
00030
00031 #include <lal/ComputeFstat.h>
00032 #include <lal/LALBarycenter.h>
00033 #include <lal/LALInitBarycenter.h>
00034 #include <lal/AVFactories.h>
00035
00036 NRCSID (GETAMCOEFFSTEST, "$Id: GetAMCoeffsTest.c,v 1.5 2006/10/27 15:18:20 reinhard Exp $");
00037
00038
00039
00040 #define GETAMCOEFFSTEST_ENORM 0
00041 #define GETAMCOEFFSTEST_ESUB 1
00042
00043 #define GETAMCOEFFSTEST_MSGENORM "Normal exit"
00044 #define GETAMCOEFFSTEST_MSGESUB "Subroutine failed"
00045
00046
00047
00048 #define RELERROR(x, y) fabs( 2.0 * ((x) - (y)) / ( (x) + (y) ) )
00049 #define SQ(x) ( (x) * (x) )
00050 #define MYMAX(a,b) ( (a) > (b) ? (a) : (b) )
00051
00052
00053
00054
00055
00056 #define ERROR( code, msg, statement ) \
00057 do { \
00058 if ( lalDebugLevel & LALERROR ) \
00059 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
00060 " %s %s\n", (code), *argv, __FILE__, \
00061 __LINE__, GETAMCOEFFSTEST, statement ? statement : \
00062 "", (msg) ); \
00063 } while (0)
00064
00065 #define INFO( statement ) \
00066 do { \
00067 if ( lalDebugLevel & LALINFO ) \
00068 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
00069 " %s\n", *argv, __FILE__, __LINE__, \
00070 GETAMCOEFFSTEST, (statement) ); \
00071 } while (0)
00072
00073 #define SUB( func, statusptr ) \
00074 do { \
00075 if ( (func), (statusptr)->statusCode ) { \
00076 ERROR( GETAMCOEFFSTEST_ESUB, GETAMCOEFFSTEST_MSGESUB, \
00077 "Function call \"" #func "\" failed:" ); \
00078 return GETAMCOEFFSTEST_ESUB; \
00079 } \
00080 } while (0)
00081
00082
00083 static const LALStatus empty_status;
00084 static const AMCoeffsParams empty_AMCoeffsParams;
00085 static const AMCoeffs empty_AMCoeffs;
00086
00087 extern int lalDebugLevel;
00088
00089
00090
00091
00092
00093 int main(int argc, char *argv[])
00094 {
00095 LALStatus status = empty_status;
00096
00097 LIGOTimeGPS startTime = {714180733, 0};
00098 REAL8 duration = 180000;
00099 REAL8 Tsft = 1800;
00100 LIGOTimeGPSVector *timestamps = NULL;
00101 DetectorStateSeries *detStates = NULL;
00102 SkyPosition skypos = empty_SkyPosition;
00103 EphemerisData edat = empty_EphemerisData;
00104 BarycenterInput baryinput = empty_BarycenterInput;
00105 LALDetector *det = NULL;
00106 AMCoeffs AMold = empty_AMCoeffs, AMnew = empty_AMCoeffs;
00107 REAL8 alpha, delta;
00108 AMCoeffsParams amParams = empty_AMCoeffsParams;
00109 EarthState earth;
00110 UINT4 i;
00111 REAL8 maxerr_a, maxerr_b, averr_a, averr_b;
00112 REAL8 tolerance = 1e-2;
00113 struct tms buf;
00114
00115 const CHAR *sites[] = {"H1", "L1", "V2", "G1", "T1" };
00116 UINT4 pickedSite;
00117 char earthEphem[] = "earth00-04.dat";
00118 char sunEphem[] = "sun00-04.dat";
00119
00120 lalDebugLevel = 0;
00121 if ( argc == 2 && !strcmp(argv[1], "-v1") )
00122 lalDebugLevel = 1;
00123
00124
00125
00126 srand ( times(&buf) );
00127
00128
00129 edat.ephiles.earthEphemeris = earthEphem;
00130 edat.ephiles.sunEphemeris = sunEphem;
00131 edat.leap = 0;
00132 SUB ( LALInitBarycenter(&status, &edat), &status);
00133
00134
00135 SUB ( LALMakeTimestamps ( &status, ×tamps, startTime, duration, Tsft ), &status );
00136
00137
00138 AMold.a = XLALCreateREAL4Vector ( timestamps->length );
00139 AMold.b = XLALCreateREAL4Vector ( timestamps->length );
00140 AMnew.a = XLALCreateREAL4Vector ( timestamps->length );
00141 AMnew.b = XLALCreateREAL4Vector ( timestamps->length );
00142
00143
00144 pickedSite = floor( 5 * (1.0 * rand() / (RAND_MAX + 1.0) ) );
00145 if ( ( det = XLALGetSiteInfo ( sites[pickedSite] )) == NULL )
00146 {
00147 LALPrintError ("\nCall to XLALGetSiteInfo() has failed for site = '%s'... \n\n",
00148 sites[pickedSite]);
00149 return GETAMCOEFFSTEST_ESUB;
00150 }
00151
00152
00153 alpha = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) );
00154 delta = LAL_PI_2 - acos ( 1 - 2.0 * rand()/RAND_MAX );
00155
00156
00157 baryinput.site.location[0] = det->location[0]/LAL_C_SI;
00158 baryinput.site.location[1] = det->location[1]/LAL_C_SI;
00159 baryinput.site.location[2] = det->location[2]/LAL_C_SI;
00160 baryinput.alpha = alpha;
00161 baryinput.delta = delta;
00162 baryinput.dInv = 0.e0;
00163
00164
00165 amParams.das = (LALDetAndSource *)LALMalloc(sizeof(LALDetAndSource));
00166 amParams.das->pSource = (LALSource *)LALMalloc(sizeof(LALSource));
00167 amParams.baryinput = &baryinput;
00168 amParams.earth = &earth;
00169 amParams.edat = &edat;
00170 amParams.das->pDetector = det;
00171 amParams.das->pSource->equatorialCoords.longitude = alpha;
00172 amParams.das->pSource->equatorialCoords.latitude = delta;
00173 amParams.das->pSource->orientation = 0.0;
00174 amParams.das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL;
00175 amParams.polAngle = 0;
00176 amParams.leapAcc = LALLEAPSEC_STRICT;
00177
00178 SUB (LALComputeAM ( &status, &AMold, timestamps->data, &amParams), &status);
00179
00180
00181
00182
00183 SUB ( LALGetDetectorStates (&status, &detStates, timestamps, det, &edat, 0 ), &status );
00184
00185 skypos.system = COORDINATESYSTEM_EQUATORIAL;
00186 skypos.longitude = alpha;
00187 skypos.latitude = delta;
00188
00189 SUB ( LALGetAMCoeffs ( &status, &AMnew, detStates, skypos ), &status );
00190
00191
00192
00193 maxerr_a = maxerr_b = averr_a = averr_b = 0;
00194 for ( i=0; i < timestamps->length; i ++ )
00195 {
00196 REAL8 thisErr;
00197 thisErr = sqrt( SQ ( AMold.a->data[i] - AMnew.a->data[i] ) / AMold.A );
00198 averr_a += thisErr;
00199 maxerr_a = MYMAX( thisErr, maxerr_a );
00200 thisErr = sqrt( SQ ( AMold.b->data[i] - AMnew.b->data[i] ) / AMold.B );
00201 averr_b += thisErr;
00202 maxerr_b = MYMAX( thisErr, maxerr_b );
00203 }
00204 averr_a /= timestamps->length;
00205 averr_b /= timestamps->length;
00206
00207 if ( lalDebugLevel )
00208 {
00209 printf ("Parameters: IFO = %s, skypos = [%g, %g]\n", sites[pickedSite], alpha, delta );
00210 printf ("Maximal relative errors: maxerr(a) = %g %%, maxerr(b) = %g %% \n",
00211 100.0 * maxerr_a, 100.0 * maxerr_b);
00212 printf ("Average relative errors: averr(a) = %g %%, averr(b) = %g %% \n",
00213 100.0 * averr_a, 100.0 * averr_b );
00214 }
00215 else
00216 printf ("%d %g %g %g %g %g %g \n", pickedSite, alpha, delta, averr_a, averr_b, maxerr_a, maxerr_b);
00217
00218 if ( (averr_a > tolerance) || (averr_b > tolerance) || (maxerr_a > tolerance) ||(maxerr_b > tolerance))
00219 {
00220 LALPrintError ("Maximal error-tolerance of %g %% was exceeded!\n", 100.0 * tolerance );
00221 return 1;
00222 }
00223
00224
00225 XLALDestroyTimestampVector ( timestamps );
00226 XLALDestroyREAL4Vector ( AMold.a );
00227 XLALDestroyREAL4Vector ( AMold.b );
00228 XLALDestroyREAL4Vector ( AMnew.a );
00229 XLALDestroyREAL4Vector ( AMnew.b );
00230 LALFree ( det );
00231 XLALDestroyDetectorStateSeries ( detStates );
00232 LALFree ( amParams.das->pSource );
00233 LALFree ( amParams.das );
00234
00235 LALFree(edat.ephemE);
00236 LALFree(edat.ephemS);
00237
00238
00239 LALCheckMemoryLeaks();
00240
00241 return 0;
00242
00243 }
00244
00245