static void destroyCoherentGW( CoherentGW *waveform ) { if ( waveform->h ) { XLALDestroyREAL4VectorSequence( waveform->h->data ); LALFree( waveform->a ); } if ( waveform->a ) { XLALDestroyREAL4VectorSequence( waveform->a->data ); LALFree( waveform->a ); } if ( waveform->phi ) { XLALDestroyREAL8Vector( waveform->phi->data ); LALFree( waveform->phi ); } if ( waveform->f ) { XLALDestroyREAL4Vector( waveform->f->data ); LALFree( waveform->f ); } if ( waveform->shift ) { XLALDestroyREAL4Vector( waveform->shift->data ); LALFree( waveform->shift ); } return; }
void XLALSQTPNDestroyCoherentGW(CoherentGW *wave) { //static const char *func = "LALSQTPNDestroyCoherentGW"; if (wave->a) { if (wave->a->data) { XLALDestroyREAL4VectorSequence(wave->a->data); } XLALFree(wave->a); } if (wave->f) { if (wave->f->data) { XLALDestroyREAL4Vector(wave->f->data); } XLALFree(wave->f); } if (wave->phi) { if (wave->phi->data) { XLALDestroyREAL8Vector(wave->phi->data); } XLALFree(wave->phi); } if (wave->shift) { if (wave->shift->data) { XLALDestroyREAL4Vector(wave->shift->data); } XLALFree(wave->shift); } }
REAL8 calculate_ligo_snr_from_strain( REAL4TimeVectorSeries *strain, SimInspiralTable *thisInj, const CHAR ifo[3]) { REAL8 ret = -1, snrSq, freq, psdValue; REAL8 sampleRate = 4096, deltaF; REAL4TimeSeries *chan = NULL; REAL4FFTPlan *pfwd; COMPLEX8FrequencySeries *fftData; UINT4 k; /* create the time series */ chan = XLALCalculateNRStrain( strain, thisInj, ifo, sampleRate ); deltaF = chan->deltaT * strain->data->vectorLength; fftData = XLALCreateCOMPLEX8FrequencySeries( chan->name, &(chan->epoch), 0, deltaF, &lalDimensionlessUnit, chan->data->length/2 + 1 ); /* perform the fft */ pfwd = XLALCreateForwardREAL4FFTPlan( chan->data->length, 0 ); XLALREAL4TimeFreqFFT( fftData, chan, pfwd ); /* compute the SNR for initial LIGO at design */ for ( snrSq = 0, k = 0; k < fftData->data->length; k++ ) { freq = fftData->deltaF * k; if ( ifo[0] == 'V' ) { if (freq < 35) continue; LALVIRGOPsd( NULL, &psdValue, freq ); psdValue /= 9e-46; } else { if (freq < 40) continue; LALLIGOIPsd( NULL, &psdValue, freq ); } fftData->data->data[k] /= 3e-23; snrSq += crealf(fftData->data->data[k]) * crealf(fftData->data->data[k]) / psdValue; snrSq += cimagf(fftData->data->data[k]) * cimagf(fftData->data->data[k]) / psdValue; } snrSq *= 4*fftData->deltaF; XLALDestroyREAL4FFTPlan( pfwd ); XLALDestroyCOMPLEX8FrequencySeries( fftData ); XLALDestroyREAL4Vector ( chan->data); LALFree(chan); ret = sqrt(snrSq); return ret; }
/** * Destroy a AMCoeffs structure. * * \note This function is "NULL-robust" in the sense that it will not crash * on NULL-entries anywhere in this struct, so it can be used * for failure-cleanup even on incomplete structs */ void XLALDestroyAMCoeffs ( AMCoeffs *amcoef ) { if ( ! amcoef ) return; if ( amcoef->a ) XLALDestroyREAL4Vector ( amcoef->a ); if ( amcoef->b ) XLALDestroyREAL4Vector ( amcoef->b ); LALFree ( amcoef ); return; } /* XLALDestroyAMCoeffs() */
/** * KS test of data against an expected exponential distribution * \param [out] ksvalue Pointer to the KS value * \param [in] vector Pointer to the REAL4Vector to compare against an exponential distribution * \return Status value */ INT4 ks_test_exp(REAL8 *ksvalue, REAL4Vector *vector) { INT4 ii; //First the mean value needs to be calculated from the median value REAL4Vector *tempvect = NULL; XLAL_CHECK( (tempvect = XLALCreateREAL4Vector(vector->length)) != NULL, XLAL_EFUNC ); memcpy(tempvect->data, vector->data, sizeof(REAL4)*vector->length); sort_float_ascend(tempvect); //tempvect becomes sorted REAL4 vector_median = 0.0; if (tempvect->length % 2 != 1) vector_median = 0.5*(tempvect->data[(INT4)(0.5*tempvect->length)-1] + tempvect->data[(INT4)(0.5*tempvect->length)]); else vector_median = tempvect->data[(INT4)(0.5*tempvect->length)]; REAL4 vector_mean = (REAL4)(vector_median/LAL_LN2); //Now start doing the K-S testing *ksvalue = 0.0; REAL8 testval1, testval2, testval; REAL8 oneoverlength = 1.0/tempvect->length; for (ii=0; ii<(INT4)tempvect->length; ii++) { REAL8 pval = gsl_cdf_exponential_P(tempvect->data[ii], vector_mean); testval1 = fabs((1.0+ii)*oneoverlength - pval); testval2 = fabs(ii*oneoverlength - pval); testval = fmax(testval1, testval2); if (testval>(*ksvalue)) *ksvalue = testval; } //Destroy stuff XLALDestroyREAL4Vector(tempvect); return XLAL_SUCCESS; } /* ks_test_exp() */
int main( int argc, char *argv[]) { /* sanity check for input arguments */ if ( argc != 1 ) XLAL_ERROR ( XLAL_EINVAL, "The executable '%s' doesn't support any input arguments right now.\n", argv[0] ); printf ("Starting test...\n"); /* set up single- and multi-IFO F-stat input */ REAL4 TwoF = 7.0; UINT4 numDetectors = 2; REAL4Vector *TwoFX = NULL; if ( (TwoFX = XLALCreateREAL4Vector ( numDetectors )) == NULL ) { XLAL_ERROR ( XLAL_EFUNC, "failed to XLALCreateREAL4Vector( %d )\n", numDetectors ); return XLAL_EFAILED; } TwoFX->data[0] = 4.0; TwoFX->data[1] = 12.0; REAL8 rhomaxline = 0.0; /* prior from LV-stat derivation, 0 means pure line veto, +inf means pure multi-Fstat */ REAL8Vector *lX = NULL; /* per-IFO prior odds ratio for line vs. Gaussian noise, NULL is interpreted as l[X]=1 for all X */ /* maximum allowed difference between recalculated and XLAL result */ REAL4 tolerance_allterms = 2e-04; REAL4 tolerance_leadterm = 2e-02; /* compute and compare the results for one set of rhomaxline, lX values */ printf ("Computing LV-stat for TwoF_multi=%f, TwoFX[0]=%f, TwoFX[1]=%f, rhomaxline=%f, priors lX=NULL...\n", TwoF, TwoFX->data[0], TwoFX->data[1], rhomaxline ); if ( XLALCompareLVComputations( TwoF, TwoFX, rhomaxline, lX, tolerance_allterms, tolerance_leadterm ) != XLAL_SUCCESS ) { XLAL_ERROR ( XLAL_EFUNC, "Test failed.\n" ); return XLAL_EFAILED; } /* change the priors to catch more possible problems */ rhomaxline = 5.0; if ( (lX = XLALCreateREAL8Vector ( numDetectors )) == NULL ) { XLAL_ERROR ( XLAL_EFUNC, "failed to XLALCreateREAL8Vector( %d )\n", numDetectors ); return XLAL_EFAILED; } lX->data[0] = 0.5; lX->data[1] = 0.8; /* compute and compare the results for second set of rhomaxline, lX values */ printf ("Computing LV-stat for TwoF_multi=%f, TwoFX[0]=%f, TwoFX[1]=%f, rhomaxline=%f, priors lX=(%f,%f)...\n", TwoF, TwoFX->data[0], TwoFX->data[1], rhomaxline, lX->data[0], lX->data[1] ); if ( XLALCompareLVComputations( TwoF, TwoFX, rhomaxline, lX, tolerance_allterms, tolerance_leadterm ) != XLAL_SUCCESS ) { XLAL_ERROR ( XLAL_EFUNC, "Test failed.\n" ); return XLAL_EFAILED; } /* free memory */ XLALDestroyREAL4Vector(TwoFX); XLALDestroyREAL8Vector(lX); LALCheckMemoryLeaks(); return XLAL_SUCCESS; } /* main */
/** * Compute the RMS value of a REAL4Vector * \param [out] rms Pointer to the output RMS value * \param [in] vector Pointer to a REAL4Vector of values * \return Status value */ INT4 calcRms(REAL4 *rms, REAL4Vector *vector) { REAL4Vector *sqvector = NULL; XLAL_CHECK( (sqvector = XLALCreateREAL4Vector(vector->length)) != NULL, XLAL_EFUNC ); sqvector = XLALSSVectorMultiply(sqvector, vector, vector); XLAL_CHECK( xlalErrno == 0, XLAL_EFUNC ); *rms = sqrtf(calcMean(sqvector)); XLALDestroyREAL4Vector(sqvector); return XLAL_SUCCESS; } /* calcRms() */
/** * Sort a REAL4Vector, keeping the smallest of the values in the output vector * \param [out] output Pointer to a REAL4Vector containing the output vector * \param [in] input Pointer to the REAL4Vector from which to find the smallest values * \return Status value */ INT4 sort_float_smallest(REAL4Vector *output, REAL4Vector *input) { //Copy of the input vector REAL4Vector *tempvect = NULL; XLAL_CHECK( (tempvect = XLALCreateREAL4Vector(input->length)) != NULL, XLAL_EFUNC ); memcpy(tempvect->data, input->data, sizeof(REAL4)*input->length); //qsort rearranges original vector, so sort the copy of the input vector qsort(tempvect->data, tempvect->length, sizeof(REAL4), qsort_REAL4_compar); memcpy(output->data, tempvect->data, sizeof(REAL4)*output->length); XLALDestroyREAL4Vector(tempvect); return XLAL_SUCCESS; } /* sort_float_smallest() */
/** * Calculate the median value from a REAL4Vector * \param [out] median Pointer to the median value * \param [in] vector Pointer to a REAL4Vector * \return Status value */ INT4 calcMedian(REAL4 *median, REAL4Vector *vector) { //Make a copy of the original vector REAL4Vector *tempvect = NULL; XLAL_CHECK( (tempvect = XLALCreateREAL4Vector(vector->length)) != NULL, XLAL_EFUNC ); memcpy(tempvect->data, vector->data, sizeof(REAL4)*vector->length); //qsort() on the copied data qsort(tempvect->data, tempvect->length, sizeof(REAL4), qsort_REAL4_compar); if (tempvect->length % 2 != 1) *median = 0.5*(tempvect->data[(INT4)(0.5*tempvect->length)-1] + tempvect->data[(INT4)(0.5*tempvect->length)]); else *median = tempvect->data[(INT4)(0.5*tempvect->length)]; XLALDestroyREAL4Vector(tempvect); return XLAL_SUCCESS; } /* calcMedian() */
int main( int argc, char *argv[]) { /* sanity check for input arguments */ XLAL_CHECK ( argc == 1, XLAL_EINVAL, "The executable '%s' doesn't support any input arguments right now.\n", argv[0] ); printf ("Starting test...\n"); /* set up single- and multi-IFO F-stat input */ REAL4 TwoF = 7.0; UINT4 numDetectors = 2; REAL4Vector *TwoFX = NULL; XLAL_CHECK ( (TwoFX = XLALCreateREAL4Vector ( numDetectors )) != NULL, XLAL_EFUNC ); TwoFX->data[0] = 4.0; TwoFX->data[1] = 12.0; /* maximum allowed difference between recalculated and XLAL result */ REAL4 tolerance = 1e-06; /* compute and compare the results for one set of Fstar0, oLGX values */ REAL4 Fstar0 = -LAL_REAL4_MAX; /* prior from BSGL derivation, -Inf means pure line veto, +Inf means pure multi-Fstat */ REAL4 *oLGX = NULL; /* per-IFO prior odds ratio for line vs. Gaussian noise, NULL is interpreted as oLG[X]=1 for all X */ printf ("Computing BSGL for TwoF_multi=%f, TwoFX=(%f,%f), priors F*0=%f and oLGX=NULL...\n", TwoF, TwoFX->data[0], TwoFX->data[1], Fstar0 ); XLAL_CHECK ( XLALCompareBSGLComputations( TwoF, numDetectors, TwoFX, Fstar0, oLGX, tolerance ) == XLAL_SUCCESS, XLAL_EFUNC ); /* change the priors to catch more possible problems */ Fstar0 = 10.0; REAL4 oLGXarray[numDetectors]; oLGXarray[0] = 0.5; oLGXarray[1] = 0.8; oLGX = oLGXarray; printf ("Computing BSGL for TwoF_multi=%f, TwoFX=(%f,%f), priors F*0=%f and oLGX=(%f,%f)...\n", TwoF, TwoFX->data[0], TwoFX->data[1], Fstar0, oLGX[0], oLGX[1] ); XLAL_CHECK ( XLALCompareBSGLComputations( TwoF, numDetectors, TwoFX, Fstar0, oLGX, tolerance ) == XLAL_SUCCESS, XLAL_EFUNC ); /* free memory */ XLALDestroyREAL4Vector(TwoFX); LALCheckMemoryLeaks(); return XLAL_SUCCESS; } /* main */
/** * \brief Compute the harmonic mean value of a REAL4Vector of SFT values * * The harmonic mean is computed from the mean values of the SFTs * \param [out] harmonicMean Pointer to the output REAL4 harmonic mean value * \param [in] vector Pointer to a REAL4Value from which to compute the harmonic mean * \param [in] numfbins Number of frequency bins in the SFTs * \param [in] numffts Number of SFTs during the observation time * \return Status value */ INT4 calcHarmonicMean(REAL4 *harmonicMean, REAL4Vector *vector, INT4 numfbins, INT4 numffts) { INT4 values = 0; REAL4Vector *tempvect = NULL; XLAL_CHECK( (tempvect = XLALCreateREAL4Vector(numfbins)) != NULL, XLAL_EFUNC ); for (INT4 ii=0; ii<numffts; ii++) { if (vector->data[ii*numfbins]!=0.0) { memcpy(tempvect->data, &(vector->data[ii*numfbins]), sizeof(REAL4)*numfbins); *harmonicMean += 1.0/calcMean(tempvect); values++; } } if (values>0) *harmonicMean = (REAL4)values/(*harmonicMean); else *harmonicMean = 0.0; XLALDestroyREAL4Vector(tempvect); return XLAL_SUCCESS; } /* calcHarmonicMean() */
/** * Kuiper's test of data against an expected exponential distribution * \param [out] kuipervalue Pointer to the Kuiper's test value * \param [in] vector Pointer to the REAL4Vector to compare against an exponential distribution * \return Status value */ INT4 kuipers_test_exp(REAL8 *kuipervalue, REAL4Vector *vector) { INT4 ii; REAL4Vector *tempvect = NULL; XLAL_CHECK( (tempvect = XLALCreateREAL4Vector(vector->length)) != NULL, XLAL_EFUNC ); memcpy(tempvect->data, vector->data, sizeof(REAL4)*vector->length); sort_float_ascend(tempvect); REAL4 vector_median = 0.0; if (tempvect->length % 2 != 1) vector_median = 0.5*(tempvect->data[(INT4)(0.5*tempvect->length)-1] + tempvect->data[(INT4)(0.5*tempvect->length)]); else vector_median = tempvect->data[(INT4)(0.5*tempvect->length)]; REAL4 vector_mean = (REAL4)(vector_median/LAL_LN2); //Now the Kuiper's test calculation is made REAL8 loval = 0.0, hival = 0.0; REAL8 oneoverlength = 1.0/tempvect->length; loval = -1.0, hival = -1.0; for (ii=0; ii<(INT4)tempvect->length; ii++) { REAL8 pval = gsl_cdf_exponential_P(tempvect->data[ii], vector_mean); REAL8 testval1 = (1.0+ii)*oneoverlength - pval; REAL8 testval2 = ii*oneoverlength - pval; if (hival<testval1) hival = testval1; if (hival<testval2) hival = testval2; if (loval<-testval1) loval = -testval1; if (loval<-testval2) loval = -testval2; } *kuipervalue = hival + loval; XLALDestroyREAL4Vector(tempvect); return XLAL_SUCCESS; } /* kuipers_test_exp() */
/** * 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() */
REAL4 XLALCandleDistanceTD( Approximant approximant, REAL4 candleM1, REAL4 candleM2, REAL4 candlesnr, REAL8 chanDeltaT, INT4 nPoints, REAL8FrequencySeries *spec, UINT4 cut) { LALStatus status = blank_status; InspiralTemplate tmplt; REAL4Vector *waveform = NULL; COMPLEX8Vector *waveFFT = NULL; REAL4FFTPlan *fwdPlan = NULL; REAL8 sigmaSq; REAL8 distance; UINT4 i; memset( &tmplt, 0, sizeof(tmplt) ); /* Create storage for TD and FD template */ waveform = XLALCreateREAL4Vector( nPoints ); waveFFT = XLALCreateCOMPLEX8Vector( spec->data->length ); fwdPlan = XLALCreateForwardREAL4FFTPlan( nPoints, 0 ); /* Populate the template parameters */ tmplt.mass1 = candleM1; tmplt.mass2 = candleM2; tmplt.ieta = 1; tmplt.approximant = approximant; tmplt.tSampling = 1.0/chanDeltaT; tmplt.order = LAL_PNORDER_PSEUDO_FOUR; /* Hardcode for EOBNR for now */ tmplt.fLower = spec->deltaF *cut; tmplt.distance = 1.0e6 * LAL_PC_SI; /* Mpc */ tmplt.massChoice = m1Andm2; tmplt.fCutoff = tmplt.tSampling / 2.0 - spec->deltaF; /* From this, calculate the other parameters */ LAL_CALL( LALInspiralParameterCalc( &status, &tmplt ), &status ); /* Generate the waveform */ LAL_CALL( LALInspiralWave( &status, waveform, &tmplt ), &status ); XLALREAL4ForwardFFT( waveFFT, waveform, fwdPlan ); sigmaSq = 0.0; for ( i = cut; i < waveFFT->length; i++ ) { sigmaSq += ( crealf(waveFFT->data[i]) * crealf(waveFFT->data[i]) + cimagf(waveFFT->data[i]) * cimagf(waveFFT->data[i]) )/ spec->data->data[i]; } sigmaSq *= 4.0 * chanDeltaT / (REAL8)nPoints; /* Now calculate the distance */ distance = sqrt( sigmaSq ) / (REAL8)candlesnr; /* Clean up! */ XLALDestroyREAL4Vector( waveform ); XLALDestroyCOMPLEX8Vector( waveFFT ); XLALDestroyREAL4FFTPlan( fwdPlan ); return (REAL4)distance; }
/** * Destroy an farStruct * \param [in] farstruct Pointer to a farStruct */ void free_farStruct(farStruct *farstruct) { XLALDestroyREAL4Vector(farstruct->topRvalues); farstruct->topRvalues = NULL; XLALFree((farStruct*)farstruct); } /* free_farStruct() */
/** * 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() */
int main(int argc, char *argv[]) { LALStatus status = blank_status; ConfigVariables XLAL_INIT_DECL(config); UserVariables_t XLAL_INIT_DECL(uvar); /* register user-variables */ XLAL_CHECK ( XLALInitUserVars ( &uvar ) == XLAL_SUCCESS, XLAL_EFUNC ); /* read cmdline & cfgfile */ BOOLEAN should_exit = 0; XLAL_CHECK( XLALUserVarReadAllInput( &should_exit, argc, argv ) == XLAL_SUCCESS, XLAL_EFUNC ); if ( should_exit ) { exit(1); } if ( uvar.version ) { XLALOutputVersionString ( stdout, lalDebugLevel ); exit(0); } /* basic setup and initializations */ XLAL_CHECK ( XLALInitCode( &config, &uvar, argv[0] ) == XLAL_SUCCESS, XLAL_EFUNC ); /* ----- allocate memory for AM-coeffs ----- */ AMCoeffs AMold, AMnew1, AMnew2; /**< containers holding AM-coefs computed by 3 different AM functions */ AMold.a = XLALCreateREAL4Vector ( 1 ); AMold.b = XLALCreateREAL4Vector ( 1 ); AMnew1.a = XLALCreateREAL4Vector ( 1 ); AMnew1.b = XLALCreateREAL4Vector ( 1 ); AMnew2.a = XLALCreateREAL4Vector ( 1 ); AMnew2.b = XLALCreateREAL4Vector ( 1 ); XLAL_CHECK ( AMold.a && AMold.b && AMnew1.a && AMnew1.b && AMnew2.a && AMnew2.a, XLAL_ENOMEM, "Failed to XLALCreateREAL4Vector ( 1 )\n" ); /* ----- get detector-state series ----- */ DetectorStateSeries *detStates = NULL; XLAL_CHECK ( (detStates = XLALGetDetectorStates ( config.timestamps, config.det, config.edat, 0 )) != NULL, XLAL_EFUNC ); /* ----- compute associated SSB timing info ----- */ SSBtimes *tSSB = XLALGetSSBtimes ( detStates, config.skypos, config.timeGPS, SSBPREC_RELATIVISTIC ); XLAL_CHECK ( tSSB != NULL, XLAL_EFUNC, "XLALGetSSBtimes() failed with xlalErrno = %d\n", xlalErrno ); /* ===== 1) compute AM-coeffs the 'old way': [used in CFSv1] ===== */ BarycenterInput XLAL_INIT_DECL(baryinput); AMCoeffsParams XLAL_INIT_DECL(amParams); EarthState earth; baryinput.site.location[0] = config.det->location[0]/LAL_C_SI; baryinput.site.location[1] = config.det->location[1]/LAL_C_SI; baryinput.site.location[2] = config.det->location[2]/LAL_C_SI; baryinput.alpha = config.skypos.longitude; baryinput.delta = config.skypos.latitude; baryinput.dInv = 0.e0; /* amParams structure to compute a(t) and b(t) */ amParams.das = XLALMalloc(sizeof(*amParams.das)); amParams.das->pSource = XLALMalloc(sizeof(*amParams.das->pSource)); amParams.baryinput = &baryinput; amParams.earth = &earth; amParams.edat = config.edat; amParams.das->pDetector = config.det; amParams.das->pSource->equatorialCoords.longitude = config.skypos.longitude; amParams.das->pSource->equatorialCoords.latitude = config.skypos.latitude; amParams.das->pSource->orientation = 0.0; amParams.das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL; amParams.polAngle = 0; LAL_CALL ( LALComputeAM ( &status, &AMold, config.timestamps->data, &amParams), &status); XLALFree ( amParams.das->pSource ); XLALFree ( amParams.das ); /* ===== 2) compute AM-coeffs the 'new way' using LALNewGetAMCoeffs() */ LALGetAMCoeffs ( &status, &AMnew1, detStates, config.skypos ); if ( status.statusCode ) { XLALPrintError ("%s: call to LALGetAMCoeffs() failed, status = %d\n\n", __func__, status.statusCode ); XLAL_ERROR ( status.statusCode & XLAL_EFUNC ); } /* ===== 3) compute AM-coeffs the 'newer way' using LALNewGetAMCoeffs() [used in CFSv2] */ LALNewGetAMCoeffs ( &status, &AMnew2, detStates, config.skypos ); if ( status.statusCode ) { XLALPrintError ("%s: call to LALNewGetAMCoeffs() failed, status = %d\n\n", __func__, status.statusCode ); XLAL_ERROR ( status.statusCode & XLAL_EFUNC ); } /* ===== 4) use standalone version of the above [used in FstatMetric_v2] */ REAL8 a0,b0; if ( XLALComputeAntennaPatternCoeffs ( &a0, &b0, &config.skypos, &config.timeGPS, config.det, config.edat ) != XLAL_SUCCESS ) { XLALPrintError ("%s: XLALComputeAntennaPatternCoeffs() failed.\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } /* ==================== output the results ==================== */ printf ("\n"); printf ("----- Input parameters:\n"); printf ("tGPS = { %d, %d }\n", config.timeGPS.gpsSeconds, config.timeGPS.gpsNanoSeconds ); printf ("Detector = %s\n", config.det->frDetector.name ); printf ("Sky position: longitude = %g rad, latitude = %g rad [equatorial coordinates]\n", config.skypos.longitude, config.skypos.latitude ); printf ("\n"); printf ("----- Antenna pattern functions (a,b):\n"); printf ("LALComputeAM: ( %-12.8g, %-12.8g) [REAL4]\n", AMold.a->data[0], AMold.b->data[0] ); printf ("LALGetAMCoeffs: ( %-12.8g, %-12.8g) [REAL4]\n", AMnew1.a->data[0], AMnew1.b->data[0] ); printf ("LALNewGetAMCoeffs: ( %-12.8g, %-12.8g) [REAL4]\n", AMnew2.a->data[0]/config.sinzeta, AMnew2.b->data[0]/config.sinzeta ); printf ("XLALComputeAntennaPatternCoeffs: ( %-12.8g, %-12.8g) [REAL8]\n", a0/config.sinzeta, b0/config.sinzeta ); printf ("\n"); printf ("----- Detector & Earth state:\n"); REAL8 *pos = detStates->data[0].rDetector; printf ("Detector position [ICRS J2000. Units=sec]: rDet = {%g, %g, %g}\n", pos[0], pos[1], pos[2] ); REAL8 *vel = detStates->data[0].vDetector; printf ("Detector velocity [ICRS J2000. Units=c]: vDet = {%g, %g, %g}\n", vel[0], vel[1], vel[2] ); printf ("Local mean sideral time: LMST = %g rad\n", detStates->data[0].LMST); printf ("\n"); printf ("----- SSB timing data:\n"); printf ("TOA difference tSSB - tDet = %g s\n", tSSB->DeltaT->data[0] ); printf ("TOA rate of change dtSSB/dtDet - 1 = %g\n", tSSB->Tdot->data[0] - 1.0 ); printf ("\n\n"); /* ----- done: free all memory */ XLAL_CHECK ( XLALDestroyConfig( &config ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyDetectorStateSeries ( detStates ); XLALDestroyREAL4Vector ( AMold.a ); XLALDestroyREAL4Vector ( AMold.b ); XLALDestroyREAL4Vector ( AMnew1.a ); XLALDestroyREAL4Vector ( AMnew1.b ); XLALDestroyREAL4Vector ( AMnew2.a ); XLALDestroyREAL4Vector ( AMnew2.b ); XLALDestroyREAL8Vector ( tSSB->DeltaT ); XLALDestroyREAL8Vector ( tSSB->Tdot ); XLALFree (tSSB); LALCheckMemoryLeaks(); return 0; } /* main */
void LALReadNRWave_raw(LALStatus *status, /**< pointer to LALStatus structure */ REAL4TimeVectorSeries **out, /**< [out] output time series for h+ and hx */ const CHAR *filename /**< [in] File containing numrel waveform */) { UINT4 length, k, r; REAL4TimeVectorSeries *ret=NULL; REAL4VectorSequence *data=NULL; REAL4Vector *timeVec=NULL; LALParsedDataFile *cfgdata=NULL; REAL4 tmp1, tmp2, tmp3; INITSTATUS(status); ATTATCHSTATUSPTR (status); /* some consistency checks */ ASSERT (filename != NULL, status, NRWAVEIO_ENULL, NRWAVEIO_MSGENULL ); ASSERT ( out != NULL, status, NRWAVEIO_ENULL, NRWAVEIO_MSGENULL ); ASSERT ( *out == NULL, status, NRWAVEIO_ENONULL, NRWAVEIO_MSGENONULL ); if ( XLALParseDataFile ( &cfgdata, filename) != XLAL_SUCCESS ) { ABORT( status, NRWAVEIO_EFILE, NRWAVEIO_MSGEFILE ); } length = cfgdata->lines->nTokens; /*number of data points */ /* allocate memory */ ret = LALCalloc(1, sizeof(*ret)); if (!ret) { ABORT( status, NRWAVEIO_ENOMEM, NRWAVEIO_MSGENOMEM ); } strcpy(ret->name,filename); ret->f0 = 0; data = XLALCreateREAL4VectorSequence (2, length); if (!data) { ABORT( status, NRWAVEIO_ENOMEM, NRWAVEIO_MSGENOMEM ); } timeVec = XLALCreateREAL4Vector (length); if (!timeVec) { ABORT( status, NRWAVEIO_ENOMEM, NRWAVEIO_MSGENOMEM ); } /* now get the data */ for (k = 0; k < length; k++) { r = sscanf(cfgdata->lines->tokens[k], "%f%f%f", &tmp1, &tmp2, &tmp3); /* Check the data file format */ if ( r != 3) { /* there must be exactly 3 data entries -- time, h+, hx */ ABORT( status, NRWAVEIO_EFORMAT, NRWAVEIO_MSGEFORMAT ); } timeVec->data[k] = tmp1; data->data[k] = tmp2; data->data[data->vectorLength + k] = tmp3; } /* scale time */ ret->deltaT = timeVec->data[1] - timeVec->data[0]; /* might also want to go through timeVec to make sure it is evenly spaced */ ret->data = data; (*out) = ret; XLALDestroyREAL4Vector (timeVec); XLALDestroyParsedDataFile ( cfgdata); DETATCHSTATUSPTR(status); RETURN(status); } /* LALReadNRWave() */
//Main program int main(int argc, char *argv[]) { INT4 ii, jj; //counter variables //Turn off gsl error handler gsl_set_error_handler_off(); //Initiate command line interpreter and config file loader struct gengetopt_args_info args_info; struct cmdline_parser_params *configparams; configparams = cmdline_parser_params_create(); //initialize parameters structure configparams->check_required = 0; //don't check for required values at the step if ( cmdline_parser_ext(argc, argv, &args_info, configparams) ) { fprintf(stderr, "%s: cmdline_parser_ext() failed.\n", __func__); XLAL_ERROR(XLAL_FAILURE); } configparams->initialize = 0; //don't reinitialize the parameters structure if ( args_info.config_given && cmdline_parser_config_file(args_info.config_arg, &args_info, configparams) ) { fprintf(stderr, "%s: cmdline_parser_config_file() failed.\n", __func__); XLAL_ERROR(XLAL_FAILURE); } //Check required if ( cmdline_parser_required(&args_info, argv[0]) ) { fprintf(stderr, "%s: cmdline_parser_required() failed.\n", __func__); XLAL_ERROR(XLAL_FAILURE); } //Set lalDebugLevel to user input or 0 if no input //Allocate input parameters structure memory inputParamsStruct *inputParams = new_inputParams(args_info.IFO_given); if (inputParams==NULL) { fprintf(stderr, "%s: new_inputParams() failed.\n", __func__); XLAL_ERROR(XLAL_EFUNC); } //Read TwoSpect input parameters if ( (readTwoSpectInputParams(inputParams, args_info)) != 0 ) { fprintf(stderr, "%s: readTwoSpectInputParams() failed.\n", __func__); XLAL_ERROR(XLAL_EFUNC); } //Initialize ephemeris data structure EphemerisData *edat = XLALInitBarycenter(earth_ephemeris, sun_ephemeris); if (edat==NULL) { fprintf(stderr, "%s: XLALInitBarycenter() failed.\n", __func__); XLAL_ERROR(XLAL_EFUNC); } //Maximum detector velocity in units of c from start of observation time - Tcoh to end of observation + Tcoh REAL4 detectorVmax = CompDetectorVmax(inputParams->searchstarttime-inputParams->Tcoh, inputParams->Tcoh, inputParams->SFToverlap, inputParams->Tobs+2.0*inputParams->Tcoh, inputParams->det[0], edat); if (xlalErrno!=0) { fprintf(stderr, "%s: CompDetectorVmax() failed.\n", __func__); XLAL_ERROR(XLAL_EFUNC); } //Assume maximum bin shift possible inputParams->maxbinshift = (INT4)round(detectorVmax * (inputParams->fmin+0.5*inputParams->fspan) * inputParams->Tcoh)+1; //Read in the T-F data from SFTs fprintf(stderr, "Loading in SFTs... "); REAL8 tfnormalization = 2.0/inputParams->Tcoh/(args_info.avesqrtSh_arg*args_info.avesqrtSh_arg); REAL4Vector *tfdata = readInSFTs(inputParams, &(tfnormalization)); if (tfdata==NULL) { fprintf(stderr, "\n%s: readInSFTs() failed.\n", __func__); XLAL_ERROR(XLAL_EFUNC); } fprintf(stderr, "done\n"); //Removing bad SFTs using K-S test and Kuiper's test if (inputParams->markBadSFTs!=0 && inputParams->signalOnly==0) { fprintf(stderr, "Marking and removing bad SFTs... "); INT4 numffts = (INT4)floor(inputParams->Tobs/(inputParams->Tcoh-inputParams->SFToverlap)-1); //Number of FFTs INT4 numfbins = (INT4)(round(inputParams->fspan*inputParams->Tcoh+2.0*inputParams->dfmax*inputParams->Tcoh)+12+1)+2*inputParams->maxbinshift+inputParams->blksize-1; //Number of frequency bins REAL4Vector *tempvect = XLALCreateREAL4Vector(numfbins); if (tempvect==NULL) { fprintf(stderr, "%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numfbins); XLAL_ERROR(XLAL_EFUNC); } REAL8 ksthreshold = 1.358/(sqrt(numfbins)+0.12+0.11/sqrt(numfbins)); REAL8 kuiperthreshold = 1.747/(sqrt(numfbins)+0.155+0.24/sqrt(numfbins)); //fprintf(stderr, "%f %f\n", ksthreshold, kuiperthreshold); INT4 badsfts = 0, badsfts0 = 0, kuiperoverlap1 = 0, kuiperoverlap2 = 0, totalsfts = 0; FILE *OUTPUT = fopen("./output/kskoutput.dat","a"); for (ii=0; ii<numffts; ii++) { if (tfdata->data[ii*numfbins]!=0.0) { totalsfts++; memcpy(tempvect->data, &(tfdata->data[ii*numfbins]), sizeof(REAL4)*tempvect->length); qsort(tempvect->data, tempvect->length, sizeof(REAL4), qsort_REAL4_compar); REAL4 vector_median = 0.0; if (tempvect->length % 2 != 1) vector_median = 0.5*(tempvect->data[(INT4)(0.5*tempvect->length)-1] + tempvect->data[(INT4)(0.5*tempvect->length)]); else vector_median = tempvect->data[(INT4)(0.5*tempvect->length)]; REAL4 vector_mean = (REAL4)(vector_median/LAL_LN2); REAL8 ksvalue = 0.0, testval1, testval2, testval; REAL8 oneoverlength = 1.0/tempvect->length; for (jj=0; jj<(INT4)tempvect->length; jj++) { testval1 = fabs((1.0+jj)*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean)); testval2 = fabs(jj*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean)); testval = fmax(testval1, testval2); if (testval>ksvalue) ksvalue = testval; } REAL8 loval = 0.0, hival = 0.0; for (jj=0; jj<(INT4)tempvect->length; jj++) { testval1 = (1.0+jj)*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean); testval2 = jj*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean); if (hival<testval1) hival = testval1; if (loval<testval2) loval = testval2; } REAL8 kuiperval1 = hival + loval; loval = -1.0, hival = -1.0; for (jj=0; jj<(INT4)tempvect->length; jj++) { testval1 = (1.0+jj)*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean); testval2 = jj*oneoverlength - gsl_cdf_exponential_P(tempvect->data[jj], vector_mean); if (hival<testval1) hival = testval1; if (hival<testval2) hival = testval2; if (loval<-testval1) loval = -testval1; if (loval<-testval2) loval = -testval2; } REAL8 kuiperval = hival + loval; //fprintf(OUTPUT, "%g %g %g\n", ksvalue, kuiperval1, kuiperval); if (ksvalue>ksthreshold || kuiperval1>kuiperthreshold) badsfts0++; if (ksvalue>ksthreshold || kuiperval>kuiperthreshold) badsfts++; if (kuiperval1>kuiperthreshold && kuiperval>kuiperthreshold) kuiperoverlap1++; if (kuiperval1>kuiperthreshold || kuiperval>kuiperthreshold) kuiperoverlap2++; } } fprintf(OUTPUT, "%f %d %d %d %d\n", inputParams->fmin, badsfts0, badsfts, kuiperoverlap1, kuiperoverlap2); fclose(OUTPUT); fprintf(stderr, "Fraction excluded in K-S and Kuiper's tests = %f\n", (REAL4)badsfts/(REAL4)totalsfts); XLALDestroyREAL4Vector(tempvect); } XLALDestroyREAL4Vector(tfdata); XLALDestroyEphemerisData(edat); cmdline_parser_free(&args_info); free_inputParams(inputParams); return 0; }
void LALFindChirpTDTemplate ( LALStatus *status, FindChirpTemplate *fcTmplt, InspiralTemplate *tmplt, FindChirpTmpltParams *params ) { UINT4 j; UINT4 shift; UINT4 waveLength; UINT4 numPoints; REAL4 *xfac; REAL8 deltaF; REAL8 deltaT; REAL8 sampleRate; const REAL4 cannonDist = 1.0; /* Mpc */ /*CHAR infomsg[512];*/ PPNParamStruc ppnParams; CoherentGW waveform; REAL4Vector *tmpxfac = NULL; /* Used for band-passing */ INITSTATUS(status); ATTATCHSTATUSPTR( status ); /* * * check that the arguments are reasonable * */ /* check that the output structures exist */ ASSERT( fcTmplt, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); ASSERT( fcTmplt->data, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); ASSERT( fcTmplt->data->data, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); /* check that the parameter structure exists */ ASSERT( params, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); ASSERT( params->xfacVec, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); ASSERT( params->xfacVec->data, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); /* check we have an fft plan for the template */ ASSERT( params->fwdPlan, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); /* check that the timestep is positive */ ASSERT( params->deltaT > 0, status, FINDCHIRPTDH_EDELT, FINDCHIRPTDH_MSGEDELT ); /* check that the input exists */ ASSERT( tmplt, status, FINDCHIRPTDH_ENULL, FINDCHIRPTDH_MSGENULL ); /* check that the parameter structure is set to a time domain approximant */ switch ( params->approximant ) { case TaylorT1: case TaylorT2: case TaylorT3: case TaylorT4: case GeneratePPN: case PadeT1: case EOB: case EOBNR: case FindChirpPTF: case EOBNRv2: case IMRPhenomB: case IMRPhenomC: break; default: ABORT( status, FINDCHIRPTDH_EMAPX, FINDCHIRPTDH_MSGEMAPX ); break; } /* store deltaT and zero out the time domain waveform vector */ deltaT = params->deltaT; sampleRate = 1.0 / deltaT; xfac = params->xfacVec->data; numPoints = params->xfacVec->length; memset( xfac, 0, numPoints * sizeof(REAL4) ); ASSERT( numPoints == (2 * (fcTmplt->data->length - 1)), status, FINDCHIRPTDH_EMISM, FINDCHIRPTDH_MSGEMISM ); /* choose the time domain template */ if ( params->approximant == GeneratePPN ) { /* * * generate the waveform using LALGeneratePPNInspiral() from inject * */ /* input parameters */ memset( &ppnParams, 0, sizeof(PPNParamStruc) ); ppnParams.deltaT = deltaT; ppnParams.mTot = tmplt->mass1 + tmplt->mass2; ppnParams.eta = tmplt->mass1 * tmplt->mass2 / ( ppnParams.mTot * ppnParams.mTot ); ppnParams.d = 1.0; ppnParams.fStartIn = params->fLow; ppnParams.fStopIn = -1.0 / (6.0 * sqrt(6.0) * LAL_PI * ppnParams.mTot * LAL_MTSUN_SI); /* generate waveform amplitude and phase */ memset( &waveform, 0, sizeof(CoherentGW) ); LALGeneratePPNInspiral( status->statusPtr, &waveform, &ppnParams ); CHECKSTATUSPTR( status ); /* print termination information and check sampling */ LALInfo( status, ppnParams.termDescription ); if ( ppnParams.dfdt > 2.0 ) { ABORT( status, FINDCHIRPTDH_ESMPL, FINDCHIRPTDH_MSGESMPL ); } if ( waveform.a->data->length > numPoints ) { ABORT( status, FINDCHIRPTDH_ELONG, FINDCHIRPTDH_MSGELONG ); } /* compute h(t) */ for ( j = 0; j < waveform.a->data->length; ++j ) { xfac[j] = waveform.a->data->data[2*j] * cos( waveform.phi->data->data[j] ); } /* free the memory allocated by LALGeneratePPNInspiral() */ LALSDestroyVectorSequence( status->statusPtr, &(waveform.a->data) ); CHECKSTATUSPTR( status ); LALSDestroyVector( status->statusPtr, &(waveform.f->data) ); CHECKSTATUSPTR( status ); LALDDestroyVector( status->statusPtr, &(waveform.phi->data) ); CHECKSTATUSPTR( status ); LALFree( waveform.a ); LALFree( waveform.f ); LALFree( waveform.phi ); /* waveform parameters needed for findchirp filter */ tmplt->approximant = params->approximant; tmplt->tC = ppnParams.tc; tmplt->fFinal = ppnParams.fStop; fcTmplt->tmpltNorm = params->dynRange / ( cannonDist * 1.0e6 * LAL_PC_SI ); fcTmplt->tmpltNorm *= fcTmplt->tmpltNorm; } else { /* * * generate the waveform by calling LALInspiralWave() from inspiral * */ /* set up additional template parameters */ deltaF = 1.0 / ((REAL8) numPoints * deltaT); tmplt->ieta = 1; tmplt->approximant = params->approximant; tmplt->order = params->order; tmplt->massChoice = m1Andm2; tmplt->tSampling = sampleRate; tmplt->fLower = params->fLow; tmplt->fCutoff = sampleRate / 2.0 - deltaF; /* get the template norm right */ if ( params->approximant==EOBNR ) { /* lalinspiral EOBNR code produces correct norm when fed unit signalAmplitude and non-physical distance */ tmplt->signalAmplitude = 1.0; tmplt->distance = -1.0; } else if ( params->approximant==EOBNRv2 ) { /* this formula sets the ampl0 variable to 1.0 * within the lalsimulation EOBNRv2 waveform engine * which again produces a correct template norm */ tmplt->distance = tmplt->totalMass*LAL_MRSUN_SI; } else if ( (params->approximant==IMRPhenomB) || (params->approximant==IMRPhenomC) ) { /* 1Mpc standard distance - not clear if this produces correct norm */ tmplt->distance = 1.0; tmplt->spin1[2] = 2 * tmplt->chi/(1. + sqrt(1.-4.*tmplt->eta)); } /* compute the tau parameters from the input template */ LALInspiralParameterCalc( status->statusPtr, tmplt ); CHECKSTATUSPTR( status ); /* determine the length of the chirp in sample points */ LALInspiralWaveLength( status->statusPtr, &waveLength, *tmplt ); CHECKSTATUSPTR( status ); if ( waveLength > numPoints ) { ABORT( status, FINDCHIRPTDH_ELONG, FINDCHIRPTDH_MSGELONG ); } /* generate the chirp in the time domain */ LALInspiralWave( status->statusPtr, params->xfacVec, tmplt ); CHECKSTATUSPTR( status ); /* template dependent normalization */ fcTmplt->tmpltNorm = 2 * tmplt->mu; fcTmplt->tmpltNorm *= 2 * LAL_MRSUN_SI / ( cannonDist * 1.0e6 * LAL_PC_SI ); fcTmplt->tmpltNorm *= params->dynRange; fcTmplt->tmpltNorm *= fcTmplt->tmpltNorm; } /* Taper the waveform if required */ if ( params->taperTmplt != LAL_SIM_INSPIRAL_TAPER_NONE ) { if ( XLALSimInspiralREAL4WaveTaper( params->xfacVec, params->taperTmplt ) == XLAL_FAILURE ) { ABORTXLAL( status ); } } /* Find the end of the chirp */ j = numPoints - 1; while ( xfac[j] == 0 ) { /* search for the end of the chirp but don't fall off the array */ if ( --j == 0 ) { ABORT( status, FINDCHIRPTDH_EEMTY, FINDCHIRPTDH_MSGEEMTY ); } } ++j; /* Band pass the template if required */ if ( params->bandPassTmplt ) { REAL4Vector bpVector; /*Used to save time */ /* We want to shift the template to the middle of the vector so */ /* that band-passing will work properly */ shift = ( numPoints - j ) / 2; memmove( xfac + shift, xfac, j * sizeof( *xfac ) ); memset( xfac, 0, shift * sizeof( *xfac ) ); memset( xfac + ( numPoints + j ) / 2, 0, ( numPoints - ( numPoints + j ) / 2 ) * sizeof( *xfac ) ); /* Select an appropriate part of the vector to band pass. */ /* band passing the whole thing takes a lot of time */ if ( j > 2 * sampleRate && 2 * j <= numPoints ) { bpVector.length = 2 * j; bpVector.data = params->xfacVec->data + numPoints / 2 - j; } else if ( j <= 2 * sampleRate && j + 2 * sampleRate <= numPoints ) { bpVector.length = j + 2 * sampleRate; bpVector.data = params->xfacVec->data + ( numPoints - j ) / 2 - (INT4)sampleRate; } else { bpVector.length = params->xfacVec->length; bpVector.data = params->xfacVec->data; } if ( XLALBandPassInspiralTemplate( &bpVector, 0.95 * tmplt->fLower, 1.02 * tmplt->fFinal, sampleRate ) == XLAL_FAILURE ) { ABORTXLAL( status ); } /* Now we need to do the shift to the end. */ /* Use a temporary vector to avoid mishaps */ if ( ( tmpxfac = XLALCreateREAL4Vector( numPoints ) ) == NULL ) { ABORTXLAL( status ); } if ( params->approximant == EOBNR || params->approximant == EOBNRv2 || params->approximant == IMRPhenomB || params->approximant == IMRPhenomC ) { /* We need to do something slightly different for EOBNR */ UINT4 endIndx = (UINT4) (tmplt->tC * sampleRate); memcpy( tmpxfac->data, xfac + ( numPoints - j ) / 2 + endIndx, ( numPoints - ( numPoints - j ) / 2 - endIndx ) * sizeof( *xfac ) ); memcpy( tmpxfac->data + numPoints - ( numPoints - j ) / 2 - endIndx, xfac, ( ( numPoints - j ) / 2 + endIndx ) * sizeof( *xfac ) ); } else { memcpy( tmpxfac->data, xfac + ( numPoints + j ) / 2, ( numPoints - ( numPoints + j ) / 2 ) * sizeof( *xfac ) ); memcpy( tmpxfac->data + numPoints - ( numPoints + j ) / 2, xfac, ( numPoints + j ) / 2 * sizeof( *xfac ) ); } memcpy( xfac, tmpxfac->data, numPoints * sizeof( *xfac ) ); XLALDestroyREAL4Vector( tmpxfac ); tmpxfac = NULL; } else if ( params->approximant == EOBNR || params->approximant == EOBNRv2 || params->approximant == IMRPhenomB || params->approximant == IMRPhenomC ) { /* For EOBNR we shift so that tC is at the end of the vector */ if ( ( tmpxfac = XLALCreateREAL4Vector( numPoints ) ) == NULL ) { ABORTXLAL( status ); } /* Set the coalescence index depending on tC */ j = (UINT4) (tmplt->tC * sampleRate); memcpy( tmpxfac->data + numPoints - j, xfac, j * sizeof( *xfac ) ); memcpy( tmpxfac->data, xfac + j, ( numPoints - j ) * sizeof( *xfac ) ); memcpy( xfac, tmpxfac->data, numPoints * sizeof( *xfac ) ); XLALDestroyREAL4Vector( tmpxfac ); tmpxfac = NULL; } else { /* No need for so much shifting around if not band passing */ /* shift chirp to end of vector so it is the correct place for the filter */ memmove( xfac + numPoints - j, xfac, j * sizeof( *xfac ) ); memset( xfac, 0, ( numPoints - j ) * sizeof( *xfac ) ); } /* * * create the frequency domain findchirp template * */ /* fft chirp */ if ( XLALREAL4ForwardFFT( fcTmplt->data, params->xfacVec, params->fwdPlan ) == XLAL_FAILURE ) { ABORTXLAL( status ); } /* copy the template parameters to the findchirp template structure */ memcpy( &(fcTmplt->tmplt), tmplt, sizeof(InspiralTemplate) ); /* normal exit */ DETATCHSTATUSPTR( status ); RETURN( status ); }
void LALTaylorT4WaveformForInjection( LALStatus *status, CoherentGW *waveform, InspiralTemplate *params, PPNParamStruc *ppnParams ) { UINT4 count, i; REAL8 phiC; REAL4Vector *a = NULL; /* pointers to generated amplitude data */ REAL4Vector *ff = NULL; /* pointers to generated frequency data */ REAL8Vector *phi = NULL; /* pointer to generated phase data */ InspiralInit paramsInit; INITSTATUS(status); ATTATCHSTATUSPTR(status); /* Make sure parameter and waveform structures exist. */ ASSERT( params, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL ); ASSERT(waveform, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL); ASSERT( !( waveform->a ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL ); ASSERT( !( waveform->h ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL ); ASSERT( !( waveform->f ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL ); ASSERT( !( waveform->phi ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL ); params->ampOrder = (LALPNOrder) 0; XLALPrintInfo( "WARNING: Amp Order has been reset to %d", params->ampOrder); /* Compute some parameters*/ LALInspiralInit(status->statusPtr, params, ¶msInit); CHECKSTATUSPTR(status); if (paramsInit.nbins == 0) { XLALPrintError( "Error: Estimated length of injection is zero.\n" ); ABORT( status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE ); } /* Now we can allocate memory and vector for coherentGW structure*/ ff = XLALCreateREAL4Vector( paramsInit.nbins ); a = XLALCreateREAL4Vector( 2*paramsInit.nbins ); phi = XLALCreateREAL8Vector( paramsInit.nbins ); if ( !ff || !a || !phi ) { if ( ff ) XLALDestroyREAL4Vector( ff ); if ( a ) XLALDestroyREAL4Vector( a ); if ( phi ) XLALDestroyREAL8Vector( phi ); ABORTXLAL( status ); } /* Call the engine function */ LALTaylorT4WaveformEngine(status->statusPtr, NULL, NULL, a, ff, phi, &count, params, ¶msInit); BEGINFAIL( status ) { XLALDestroyREAL4Vector( ff ); XLALDestroyREAL4Vector( a ); XLALDestroyREAL8Vector( phi ); } ENDFAIL( status ); /*wrap the phase vector*/ phiC = phi->data[count-1] ; for (i = 0; i < count; i++) { phi->data[i] = phi->data[i] - phiC + ppnParams->phi; } /* Allocate the waveform structures. */ if ( ( waveform->a = (REAL4TimeVectorSeries *) LALCalloc(1, sizeof(REAL4TimeVectorSeries) ) ) == NULL ) { XLALDestroyREAL4Vector( ff ); XLALDestroyREAL4Vector( a ); XLALDestroyREAL8Vector( phi ); ABORT( status, LALINSPIRALH_EMEM, LALINSPIRALH_MSGEMEM ); } if ( ( waveform->f = (REAL4TimeSeries *) LALCalloc(1, sizeof(REAL4TimeSeries) ) ) == NULL ) { LALFree( waveform->a ); waveform->a = NULL; XLALDestroyREAL4Vector( ff ); XLALDestroyREAL4Vector( a ); XLALDestroyREAL8Vector( phi ); ABORT( status, LALINSPIRALH_EMEM, LALINSPIRALH_MSGEMEM ); } if ( ( waveform->phi = (REAL8TimeSeries *) LALCalloc(1, sizeof(REAL8TimeSeries) ) ) == NULL ) { LALFree( waveform->a ); waveform->a = NULL; LALFree( waveform->f ); waveform->f = NULL; XLALDestroyREAL4Vector( ff ); XLALDestroyREAL4Vector( a ); XLALDestroyREAL8Vector( phi ); ABORT( status, LALINSPIRALH_EMEM, LALINSPIRALH_MSGEMEM ); } waveform->a->data = XLALCreateREAL4VectorSequence( (UINT4)count, 2 ); waveform->f->data = XLALCreateREAL4Vector( count ); waveform->phi->data = XLALCreateREAL8Vector( count ); if ( !waveform->a->data || !waveform->f->data || !waveform->phi->data ) { if ( waveform->a->data ) XLALDestroyREAL4VectorSequence( waveform->a->data ); if ( waveform->f->data ) XLALDestroyREAL4Vector( waveform->f->data ); if ( waveform->phi->data ) XLALDestroyREAL8Vector( waveform->phi->data ); LALFree( waveform->a ); waveform->a = NULL; LALFree( waveform->f ); waveform->f = NULL; XLALDestroyREAL4Vector( ff ); XLALDestroyREAL4Vector( a ); XLALDestroyREAL8Vector( phi ); ABORTXLAL( status ); } memcpy(waveform->f->data->data , ff->data, count*(sizeof(REAL4))); memcpy(waveform->a->data->data , a->data, 2*count*(sizeof(REAL4))); memcpy(waveform->phi->data->data ,phi->data, count*(sizeof(REAL8))); waveform->a->deltaT = waveform->f->deltaT = waveform->phi->deltaT = ppnParams->deltaT; waveform->a->sampleUnits = lalStrainUnit; waveform->f->sampleUnits = lalHertzUnit; waveform->phi->sampleUnits = lalDimensionlessUnit; waveform->position = ppnParams->position; waveform->psi = ppnParams->psi; snprintf( waveform->a->name, LALNameLength, "T4 inspiral amplitude" ); snprintf( waveform->f->name, LALNameLength, "T4 inspiral frequency" ); snprintf( waveform->phi->name, LALNameLength, "T4 inspiral phase" ); /* --- fill some output ---*/ ppnParams->tc = (double)(count-1) / params->tSampling ; ppnParams->length = count; ppnParams->dfdt = ((REAL4)(waveform->f->data->data[count-1] - waveform->f->data->data[count-2])) * ppnParams->deltaT; ppnParams->fStop = params->fFinal; ppnParams->termCode = GENERATEPPNINSPIRALH_EFSTOP; ppnParams->termDescription = GENERATEPPNINSPIRALH_MSGEFSTOP; ppnParams->fStart = ppnParams->fStartIn; /* --- free memory --- */ XLALDestroyREAL4Vector( ff ); XLALDestroyREAL4Vector( a ); XLALDestroyREAL8Vector( phi ); DETATCHSTATUSPTR(status); RETURN (status); }