/** * Very simple test: pick random skyposition, compute a_i, b_i using * once LALComputeAM() and once LALGetAMCoeffs(), and look at the errors * sum_i (a_i - a_i')^2 */ int main(int argc, char *argv[]) { LALStatus XLAL_INIT_DECL(status); LIGOTimeGPS startTime = {714180733, 0}; REAL8 duration = 180000; /* 50 hours */ REAL8 Tsft = 1800; /* assume 30min SFTs */ LIGOTimeGPSVector *timestamps = NULL; DetectorStateSeries *detStates = NULL; SkyPosition XLAL_INIT_DECL(skypos); EphemerisData XLAL_INIT_DECL(edat); BarycenterInput XLAL_INIT_DECL(baryinput); LALDetector *det = NULL; AMCoeffs XLAL_INIT_DECL(AMold); AMCoeffs XLAL_INIT_DECL(AMnew); REAL8 alpha, delta; AMCoeffsParams XLAL_INIT_DECL(amParams); EarthState earth; UINT4 i; REAL8 maxerr_a, maxerr_b, averr_a, averr_b; REAL8 tolerance = 1e-2; /* be generous: allow 1% error */ struct tms buf; const CHAR *sites[] = {"H1", "L1", "V2", "G1", "T1" }; UINT4 pickedSite; char earthEphem[] = TEST_DATA_DIR "earth00-19-DE405.dat.gz"; char sunEphem[] = TEST_DATA_DIR "sun00-19-DE405.dat.gz"; if ( argc == 2 && !strcmp(argv[1], "-v1") ) /* init random-generator */ srand ( times(&buf) ); /* ----- init ephemeris ----- */ edat.ephiles.earthEphemeris = earthEphem; edat.ephiles.sunEphemeris = sunEphem; SUB ( LALInitBarycenter(&status, &edat), &status); /* ----- get timestamps ----- */ SUB ( LALMakeTimestamps ( &status, ×tamps, startTime, duration, Tsft ), &status ); /* ----- allocate memory for AM-coeffs ----- */ AMold.a = XLALCreateREAL4Vector ( timestamps->length ); AMold.b = XLALCreateREAL4Vector ( timestamps->length ); AMnew.a = XLALCreateREAL4Vector ( timestamps->length ); AMnew.b = XLALCreateREAL4Vector ( timestamps->length ); /* ----- pick detector-site at random ----- */ pickedSite = floor( 5 * (1.0 * rand() / (RAND_MAX + 1.0) ) ); /* int in [0,5) */ if ( ( det = XLALGetSiteInfo ( sites[pickedSite] )) == NULL ) { XLALPrintError ("\nCall to XLALGetSiteInfo() has failed for site = '%s'... \n\n", sites[pickedSite]); return GETAMCOEFFSTEST_ESUB; } /* ----- pick skyposition at random ----- */ alpha = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) ); /* uniform in [0, 2pi) */ delta = LAL_PI_2 - acos ( 1 - 2.0 * rand()/RAND_MAX ); /* sin(delta) uniform in [-1,1] */ /* ===== compute AM-coeffs the 'old way': ===== */ baryinput.site.location[0] = det->location[0]/LAL_C_SI; baryinput.site.location[1] = det->location[1]/LAL_C_SI; baryinput.site.location[2] = det->location[2]/LAL_C_SI; baryinput.alpha = alpha; baryinput.delta = delta; baryinput.dInv = 0.e0; /* amParams structure to compute a(t) and b(t) */ amParams.das = (LALDetAndSource *)LALMalloc(sizeof(LALDetAndSource)); amParams.das->pSource = (LALSource *)LALMalloc(sizeof(LALSource)); amParams.baryinput = &baryinput; amParams.earth = &earth; amParams.edat = &edat; amParams.das->pDetector = det; amParams.das->pSource->equatorialCoords.longitude = alpha; amParams.das->pSource->equatorialCoords.latitude = delta; amParams.das->pSource->orientation = 0.0; amParams.das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL; amParams.polAngle = 0; SUB (LALComputeAM ( &status, &AMold, timestamps->data, &amParams), &status); /* ===== compute AM-coeffs the 'new way' using LALGetAMCoeffs() */ /* ----- get detector-state series ----- */ SUB ( LALGetDetectorStates (&status, &detStates, timestamps, det, &edat, 0 ), &status ); skypos.system = COORDINATESYSTEM_EQUATORIAL; skypos.longitude = alpha; skypos.latitude = delta; SUB ( LALGetAMCoeffs ( &status, &AMnew, detStates, skypos ), &status ); /* ===== analyse relative error ===== */ maxerr_a = maxerr_b = averr_a = averr_b = 0; for ( i=0; i < timestamps->length; i ++ ) { REAL8 thisErr; thisErr = sqrt( SQ ( AMold.a->data[i] - AMnew.a->data[i] ) / AMold.A ); averr_a += thisErr; maxerr_a = MYMAX( thisErr, maxerr_a ); thisErr = sqrt( SQ ( AMold.b->data[i] - AMnew.b->data[i] ) / AMold.B ); averr_b += thisErr; maxerr_b = MYMAX( thisErr, maxerr_b ); } averr_a /= timestamps->length; averr_b /= timestamps->length; if ( lalDebugLevel ) { printf ("Parameters: IFO = %s, skypos = [%g, %g]\n", sites[pickedSite], alpha, delta ); printf ("Maximal relative errors: maxerr(a) = %g %%, maxerr(b) = %g %% \n", 100.0 * maxerr_a, 100.0 * maxerr_b); printf ("Average relative errors: averr(a) = %g %%, averr(b) = %g %% \n", 100.0 * averr_a, 100.0 * averr_b ); } else printf ("%d %g %g %g %g %g %g \n", pickedSite, alpha, delta, averr_a, averr_b, maxerr_a, maxerr_b); if ( (averr_a > tolerance) || (averr_b > tolerance) || (maxerr_a > tolerance) ||(maxerr_b > tolerance)) { XLALPrintError ("Maximal error-tolerance of %g %% was exceeded!\n", 100.0 * tolerance ); return 1; } /* ----- free memory ----- */ XLALDestroyTimestampVector ( timestamps ); XLALDestroyREAL4Vector ( AMold.a ); XLALDestroyREAL4Vector ( AMold.b ); XLALDestroyREAL4Vector ( AMnew.a ); XLALDestroyREAL4Vector ( AMnew.b ); LALFree ( det ); XLALDestroyDetectorStateSeries ( detStates ); LALFree ( amParams.das->pSource ); LALFree ( amParams.das ); LALFree(edat.ephemE); LALFree(edat.ephemS); LALCheckMemoryLeaks(); return 0; /* OK */ } /* main() */
/** * Very simple test: pick random skyposition, compute a_i, b_i using * once LALComputeAM() and once LALNewGetAMCoeffs(), and look at the errors * sum_i (a_i - a_i')^2 */ int main(int argc, char *argv[]) { LALStatus XLAL_INIT_DECL(status); int opt; /* Command-line option. */ LIGOTimeGPS startTime = {714180733, 0}; REAL8 duration = 180000; /* 50 hours */ REAL8 Tsft = 1800; /* assume 30min SFTs */ LIGOTimeGPSVector *timestamps = NULL; DetectorStateSeries *detStates = NULL; SkyPosition XLAL_INIT_DECL(skypos); EphemerisData XLAL_INIT_DECL(edat); BarycenterInput XLAL_INIT_DECL(baryinput); LALDetector *det = NULL; AMCoeffs XLAL_INIT_DECL(AMold); AMCoeffs XLAL_INIT_DECL(AMnew1); AMCoeffs XLAL_INIT_DECL(AMnew2); REAL8 alpha, delta; AMCoeffsParams XLAL_INIT_DECL(amParams); EarthState earth; UINT4 i; REAL8 maxerr01, maxerr02, maxerr12, averr01, averr02, averr12; REAL8 tolerance = 1e-2; /* be generous: allow 1% error */ struct tms buf; const CHAR *sites[] = {"H1", "L1", "V2", "G1", "T1" }; REAL8 sinzeta; /* zeta = IFO opening angle */ UINT4 pickedSite; BOOLEAN ignoreErrors = 0; /* Don't fail if tolerance exceeded */ UINT4 numChecks = 1; /* Number of times to check */ char earthEphem[] = TEST_DATA_DIR "earth00-19-DE405.dat.gz"; char sunEphem[] = TEST_DATA_DIR "sun00-19-DE405.dat.gz"; /* ----- old testing code to use 9 degree earth rotations ----- */ /* startTime.gpsSeconds = 714275242; duration = 86164; Tsft = 2154.1; */ while ((opt = LALgetopt( argc, argv, "n:qv:" )) != -1) { switch (opt) { case 'v': /* set lalDebugLevel */ break; case 'q': /* don't fail if tolerance exceeded */ ignoreErrors = 1; break; case 'n': /* number of times to check */ numChecks = atoi( LALoptarg ); break; } } /* init random-generator */ srand ( times(&buf) ); /* ----- init ephemeris ----- */ edat.ephiles.earthEphemeris = earthEphem; edat.ephiles.sunEphemeris = sunEphem; SUB ( LALInitBarycenter(&status, &edat), &status); /* ----- get timestamps ----- */ SUB ( LALMakeTimestamps ( &status, ×tamps, startTime, duration, Tsft ), &status ); /* ----- allocate memory for AM-coeffs ----- */ AMold.a = XLALCreateREAL4Vector ( timestamps->length ); AMold.b = XLALCreateREAL4Vector ( timestamps->length ); AMnew1.a = XLALCreateREAL4Vector ( timestamps->length ); AMnew1.b = XLALCreateREAL4Vector ( timestamps->length ); AMnew2.a = XLALCreateREAL4Vector ( timestamps->length ); AMnew2.b = XLALCreateREAL4Vector ( timestamps->length ); while ( numChecks-- ) { /* ----- pick detector-site at random ----- */ pickedSite = floor( 5 * (1.0 * rand() / (RAND_MAX + 1.0) ) ); /* int in [0,5) */ /* NOTE: contrary to ComputeAM() and LALGetAMCoffs(), the new function LALNewGetAMCoeffs() * computes 'a * sinzeta' and 'b * sinzeta': for the comparison we therefore need to correct * for GEO's opening-angle of 94.33degrees [JKS98]: */ if ( ! strcmp ( sites[pickedSite], "G1" ) ) sinzeta = 0.997146; else sinzeta = 1; if ( ( det = XLALGetSiteInfo ( sites[pickedSite] )) == NULL ) { XLALPrintError ("\nCall to XLALGetSiteInfo() has failed for site = '%s'... \n\n", sites[pickedSite]); return NEWGETAMCOEFFSTEST_ESUB; } /* ----- pick skyposition at random ----- */ alpha = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) ); /* uniform in [0, 2pi) */ delta = LAL_PI_2 - acos ( 1 - 2.0 * rand()/RAND_MAX ); /* sin(delta) uniform in [-1,1] */ /* ----- old testing code to put source overhead ----- */ /* alpha = det->frDetector.vertexLongitudeRadians; delta = det->frDetector.vertexLatitudeRadians; */ /* ===== compute AM-coeffs the 'old way': ===== */ baryinput.site.location[0] = det->location[0]/LAL_C_SI; baryinput.site.location[1] = det->location[1]/LAL_C_SI; baryinput.site.location[2] = det->location[2]/LAL_C_SI; baryinput.alpha = alpha; baryinput.delta = delta; baryinput.dInv = 0.e0; /* amParams structure to compute a(t) and b(t) */ amParams.das = (LALDetAndSource *)LALMalloc(sizeof(LALDetAndSource)); amParams.das->pSource = (LALSource *)LALMalloc(sizeof(LALSource)); amParams.baryinput = &baryinput; amParams.earth = &earth; amParams.edat = &edat; amParams.das->pDetector = det; amParams.das->pSource->equatorialCoords.longitude = alpha; amParams.das->pSource->equatorialCoords.latitude = delta; amParams.das->pSource->orientation = 0.0; amParams.das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL; amParams.polAngle = 0; SUB (LALComputeAM ( &status, &AMold, timestamps->data, &amParams), &status); /* ===== compute AM-coeffs the 'new way' using LALNewGetAMCoeffs() */ /* ----- get detector-state series ----- */ SUB ( LALGetDetectorStates (&status, &detStates, timestamps, det, &edat, 0 ), &status ); skypos.system = COORDINATESYSTEM_EQUATORIAL; skypos.longitude = alpha; skypos.latitude = delta; /* the 'new' and the 'newer' way ... */ SUB ( LALGetAMCoeffs ( &status, &AMnew1, detStates, skypos ), &status ); /* 'new1' */ SUB ( LALNewGetAMCoeffs ( &status, &AMnew2, detStates, skypos ), &status ); /* 'new2' */ /* ===== analyse relative errors ===== */ maxerr01 = maxerr02 = maxerr12 = 0; /* errors between 0='old', 1='new1', 2='new2' */ averr01 = averr02 = averr12 = 0; for ( i=0; i < timestamps->length; i ++ ) { /* printf("GPS time: %d s %d ns; GMST in radians: %f\n", detStates->data[i].tGPS.gpsSeconds, detStates->data[i].tGPS.gpsNanoSeconds, fmod(detStates->data[i].earthState.gmstRad,LAL_TWOPI)); printf("Old AM coeffs: a=%f, b=%f\nNew AM coeffs: a=%f, b=%f\nNEWER AM coeffs: a=%f b=%f", AMold.a->data[i], AMold.b->data[i], AMnew.a->data[i], AMnew.b->data[i], AMnewer.a->data[i], AMnewer.b->data[i]); */ REAL8 thisErr; /* compare 0-1 */ thisErr = sqrt( SQ ( AMold.a->data[i] - AMnew1.a->data[i] ) / AMold.A ); averr01 += thisErr; maxerr01 = MYMAX( thisErr, maxerr01 ); thisErr = sqrt( SQ ( AMold.b->data[i] - AMnew1.b->data[i] ) / AMold.B ); averr01 += thisErr; maxerr01 = MYMAX( thisErr, maxerr01 ); /* compare 0-2 */ thisErr = sqrt( SQ ( AMold.a->data[i] - AMnew2.a->data[i]/sinzeta ) / AMold.A ); averr02 += thisErr; maxerr02 = MYMAX( thisErr, maxerr02 ); thisErr = sqrt( SQ ( AMold.b->data[i] - AMnew2.b->data[i]/sinzeta ) / AMold.B ); averr02 += thisErr; maxerr02 = MYMAX( thisErr, maxerr02 ); /* compare 1-2 */ thisErr = sqrt( SQ ( AMnew1.a->data[i] - AMnew2.a->data[i]/sinzeta ) / AMold.A ); averr12 += thisErr; maxerr12 = MYMAX( thisErr, maxerr12 ); thisErr = sqrt( SQ ( AMnew1.b->data[i] - AMnew2.b->data[i]/sinzeta ) / AMold.B ); averr12 += thisErr; maxerr12 = MYMAX( thisErr, maxerr12 ); } averr01 /= 2.0 * timestamps->length; averr02 /= 2.0 * timestamps->length; averr12 /= 2.0 * timestamps->length; if ( lalDebugLevel ) { printf ("Parameters: IFO = %s, skypos = [%g, %g]\n", sites[pickedSite], alpha, delta ); printf ("Maximal relative errors: maxerr(0-1) = %g %%, maxerr(0-2) = %g %% maxerr(1-2) = %g %%\n", 100.0 * maxerr01, 100.0 * maxerr02, 100.0 * maxerr12 ); printf ("Average relative errors: averr(0-1) = %g %%, averr(0-2) = %g %% averr(1-2) = %g %%\n", 100.0 * averr01, 100.0 * averr02, 100.0 * averr12 ); } else printf ("%d %g %g \t %g %g %g \t %g %g %g\n", pickedSite, alpha, delta, averr01, averr02, averr12, maxerr01, maxerr02, maxerr12); if ( (averr01 > tolerance) || (averr02 > tolerance) || (averr12 > tolerance) || (maxerr01 > tolerance) ||(maxerr02 > tolerance) || (maxerr12 > tolerance) ) { XLALPrintError ("Maximal error-tolerance of %g %% was exceeded!\n", 100.0 * tolerance ); if (!ignoreErrors) return 1; } if ( lalDebugLevel ) printf("%d checks left\n", numChecks); /* ---- Clean up things that were created in this loop ---- */ XLALDestroyDetectorStateSeries ( detStates ); detStates = NULL; LALFree ( det ); LALFree ( amParams.das->pSource ); LALFree ( amParams.das ); } /* ----- free memory ----- */ XLALDestroyTimestampVector ( timestamps ); XLALDestroyREAL4Vector ( AMold.a ); XLALDestroyREAL4Vector ( AMold.b ); XLALDestroyREAL4Vector ( AMnew1.a ); XLALDestroyREAL4Vector ( AMnew1.b ); XLALDestroyREAL4Vector ( AMnew2.a ); XLALDestroyREAL4Vector ( AMnew2.b ); LALFree(edat.ephemE); LALFree(edat.ephemS); LALCheckMemoryLeaks(); return 0; /* OK */ } /* main() */
/** * Handle user-input and check its validity. * Load ephemeris and calculate AM-coefficients (stored globally) */ void Initialize (LALStatus *status, struct CommandLineArgsTag *CLA) { EphemerisData *edat=NULL; /* Stores earth/sun ephemeris data for barycentering */ BarycenterInput baryinput; /* Stores detector location and other barycentering data */ EarthState earth; AMCoeffsParams *amParams; LIGOTimeGPS *midTS=NULL; /* Time stamps for amplitude modulation coefficients */ LALDetector *Detector; /* Our detector*/ INT4 k; INITSTATUS(status); ATTATCHSTATUSPTR (status); if ( LALUserVarWasSet ( &(CLA->nTsft) ) ) CLA->duration = 1.0 * CLA->nTsft * CLA->Tsft; /* read or generate SFT timestamps */ if ( LALUserVarWasSet(&(CLA->timestamps)) ) { TRY ( LALReadTimestampsFile (status->statusPtr, ×tamps, CLA->timestamps ), status ); if ( (CLA->nTsft > 0) && ( (UINT4)CLA->nTsft < timestamps->length ) ) /* truncate if required */ timestamps->length = CLA->nTsft; CLA->nTsft = timestamps->length; } /* if have_timestamps */ else { LIGOTimeGPS tStart; tStart.gpsSeconds = CLA->gpsStart; tStart.gpsNanoSeconds = 0; TRY ( LALMakeTimestamps(status->statusPtr, ×tamps, tStart, CLA->duration, CLA->Tsft ), status ); CLA->nTsft = timestamps->length; } /* no timestamps */ /*---------- initialize detector ---------- */ { BOOLEAN have_IFO = LALUserVarWasSet ( &CLA->IFO ); BOOLEAN have_detector = LALUserVarWasSet ( &CLA->detector ); CHAR *IFO; if ( !have_IFO && !have_detector ) { fprintf (stderr, "\nNeed to specify the detector (--IFO) !\n\n"); ABORT (status, SEMIANALYTIC_EINPUT, SEMIANALYTIC_MSGEINPUT); } if ( have_IFO ) IFO = CLA->IFO; else IFO = CLA->detector; if ( ( Detector = XLALGetSiteInfo ( IFO ) ) == NULL ) { ABORT (status, SEMIANALYTIC_EINPUT, SEMIANALYTIC_MSGEINPUT); } } /* ---------- load ephemeris-files ---------- */ { edat = XLALInitBarycenter( CLA->ephemEarth, CLA->ephemSun ); if ( !edat ) { XLALPrintError("XLALInitBarycenter failed: could not load Earth ephemeris '%s' and Sun ephemeris '%s'\n", CLA->ephemEarth, CLA->ephemSun); ABORT (status, SEMIANALYTIC_EINPUT, SEMIANALYTIC_MSGEINPUT); } } /* ephemeris-reading */ /* ---------- calculate AM-coefficients ---------- */ /* prepare call to barycentering routing */ baryinput.site.location[0] = Detector->location[0]/LAL_C_SI; baryinput.site.location[1] = Detector->location[1]/LAL_C_SI; baryinput.site.location[2] = Detector->location[2]/LAL_C_SI; baryinput.alpha = CLA->Alpha; baryinput.delta = CLA->Delta; baryinput.dInv = 0.e0; /* amParams structure to compute a(t) and b(t) */ /* Allocate space for amParams stucture */ /* Here, amParams->das is the Detector and Source info */ amParams = (AMCoeffsParams *)LALMalloc(sizeof(AMCoeffsParams)); amParams->das = (LALDetAndSource *)LALMalloc(sizeof(LALDetAndSource)); amParams->das->pSource = (LALSource *)LALMalloc(sizeof(LALSource)); /* Fill up AMCoeffsParams structure */ amParams->baryinput = &baryinput; amParams->earth = &earth; amParams->edat = edat; amParams->das->pDetector = Detector; amParams->das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL; amParams->das->pSource->equatorialCoords.longitude = CLA->Alpha; amParams->das->pSource->equatorialCoords.latitude = CLA->Delta; amParams->das->pSource->orientation = 0.0; amParams->polAngle = amParams->das->pSource->orientation ; /* These two have to be the same!!!!!!!!!*/ /* Allocate space for AMCoeffs */ amc.a = NULL; amc.b = NULL; TRY ( LALSCreateVector(status->statusPtr, &(amc.a), (UINT4) CLA->nTsft), status); TRY ( LALSCreateVector(status->statusPtr, &(amc.b), (UINT4) CLA->nTsft), status); /* Mid point of each SFT */ midTS = (LIGOTimeGPS *)LALCalloc(CLA->nTsft,sizeof(LIGOTimeGPS)); for(k=0; k < CLA->nTsft; k++) { /* FIXME: loss of precision; consider midTS[k] = timestamps->data[k]; XLALGPSAdd(&midTS[k], 0.5*CLA->Tsft); */ REAL8 teemp=0.0; teemp = XLALGPSGetREAL8(&(timestamps->data[k])); teemp += 0.5*CLA->Tsft; XLALGPSSetREAL8(&(midTS[k]), teemp); } TRY ( LALComputeAM(status->statusPtr, &amc, midTS, amParams), status); /* Free memory */ TRY ( LALDestroyTimestampVector (status->statusPtr, ×tamps), status ); LALFree(midTS); LALFree(Detector); XLALDestroyEphemerisData(edat); LALFree(amParams->das->pSource); LALFree(amParams->das); LALFree(amParams); DETATCHSTATUSPTR (status); RETURN(status); } /* ParseUserInput() */