/** * Create an AMCeoffs vector for given number of timesteps */ AMCoeffs * XLALCreateAMCoeffs ( UINT4 numSteps ) { AMCoeffs *ret; if ( ( ret = XLALCalloc ( 1, sizeof (*ret) ) ) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( 1, %d )\n", __func__, sizeof (*ret) ); XLAL_ERROR_NULL ( XLAL_ENOMEM ); } if ( ( ret->a = XLALCreateREAL4Vector ( numSteps )) == NULL ) { XLALPrintError ("%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numSteps ); XLALDestroyAMCoeffs ( ret ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } if ( ( ret->b = XLALCreateREAL4Vector ( numSteps )) == NULL ) { XLALPrintError ("%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numSteps ); XLALDestroyAMCoeffs ( ret ); XLAL_ERROR_NULL ( XLAL_EFUNC ); } return ret; } /* XLALCreateAMCoeffs() */
int XLALSQTPNAllocateCoherentGW(CoherentGW *wave, UINT4 length) { if (!wave) { XLAL_ERROR(XLAL_EFAULT); } if (length <= 0) { XLAL_ERROR(XLAL_EBADLEN); } if (wave->a || wave->f || wave->phi || wave->shift) { XLAL_ERROR(XLAL_EFAULT); } wave->a = (REAL4TimeVectorSeries *)LALMalloc(sizeof(REAL4TimeVectorSeries)); wave->f = (REAL4TimeSeries *)LALMalloc(sizeof(REAL4TimeSeries)); wave->phi = (REAL8TimeSeries *)LALMalloc(sizeof(REAL8TimeSeries)); wave->shift = (REAL4TimeSeries *)LALMalloc(sizeof(REAL4TimeSeries)); if (!(wave->a && wave->f && wave->phi && wave->shift)) { XLALSQTPNDestroyCoherentGW(wave); XLAL_ERROR(XLAL_ENOMEM); } xlalErrno = 0; wave->a->data = XLALCreateREAL4VectorSequence(length, 2); wave->f->data = XLALCreateREAL4Vector(length); wave->phi->data = XLALCreateREAL8Vector(length); wave->shift->data = XLALCreateREAL4Vector(length); if (!(wave->a->data && wave->f->data && wave->phi->data && wave->shift->data)) { XLALSQTPNDestroyCoherentGW(wave); XLAL_ERROR(XLAL_ENOMEM); } return XLAL_SUCCESS; }
/** * 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() */
REAL4Vector * XLALComputeFreq( REAL4TimeSeries *hp, REAL4TimeSeries *hc) { REAL4Vector *Freq = NULL; REAL4Vector *hpDot = NULL, *hcDot = NULL; UINT4 k, len; REAL8 dt; len = hp->data->length; dt = hp->deltaT; Freq = LALCalloc(1, sizeof(*Freq)); Freq= XLALCreateREAL4Vector(len); hpDot = LALCalloc(1, sizeof(*hpDot)); hpDot= XLALCreateREAL4Vector(len); hcDot = LALCalloc(1, sizeof(*hcDot)); hcDot= XLALCreateREAL4Vector(len); /* Construct the dot vectors (2nd order differencing) */ hpDot->data[0] = 0.0; hpDot->data[len] = 0.0; hcDot->data[0] = 0.0; hcDot->data[len] = 0.0; for( k = 1; k < len-1; k++) { hpDot->data[k] = 1./(2.*dt) * (hp->data->data[k+1]-hp->data->data[k-1]); hcDot->data[k] = 1./(2.*dt) * (hc->data->data[k+1]-hc->data->data[k-1]); } /* Compute frequency using the fact that */ /*h(t) = A(t) e^(i Phi) = Re(h) + i Im(h) */ for( k = 0; k < len; k++) { Freq->data[k] = hcDot->data[k] * hp->data->data[k] - hpDot->data[k] * hc->data->data[k]; Freq->data[k] /= LAL_TWOPI; Freq->data[k] /= (pow(hp->data->data[k],2.) + pow(hc->data->data[k], 2.)); } return Freq; }
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 */
/** * Sample a number (sampleSize) of values from an alignedREAL4VectorArray (input) randomly from vector 0 up to numberofvectors without accepting any values of zero * Needs this numberofvectors limit because of the IHS algorithm * \param [in] input Pointer to a alignedREAL4VectorArray to be sampled from * \param [in] numberofvectors Number of vectors from the start from which to sample from * \param [in] sampleSize Integer value for the length of the output vector * \param [in] rng Pointer to a gsl_rng generator * \return Newly allocated REAL4Vector of sampled values from the input vector */ REAL4Vector * sampleAlignedREAL4VectorArray_nozerosaccepted(alignedREAL4VectorArray *input, INT4 numberofvectors, INT4 sampleSize, gsl_rng *rng) { REAL4Vector *output = NULL; XLAL_CHECK_NULL( (output = XLALCreateREAL4Vector(sampleSize)) != NULL, XLAL_EFUNC ); for (INT4 ii=0; ii<sampleSize; ii++) { output->data[ii] = input->data[(INT4)floor(gsl_rng_uniform(rng)*numberofvectors)]->data[(INT4)floor(gsl_rng_uniform(rng)*input->data[0]->length)]; while (output->data[ii]==0.0) output->data[ii] = input->data[(INT4)floor(gsl_rng_uniform(rng)*numberofvectors)]->data[(INT4)floor(gsl_rng_uniform(rng)*input->data[0]->length)]; } return output; } /* sampleREAL4VectorSequence_nozerosaccepted() */
/** * 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() */
REAL4Vector * readInSFTs(inputParamsStruct *input, REAL8 *normalization) { INT4 ii, jj; SFTCatalog *catalog = NULL; //Set the start and end times in the LIGO GPS format LIGOTimeGPS start = LIGOTIMEGPSZERO, end = LIGOTIMEGPSZERO; XLALGPSSetREAL8(&start, input->searchstarttime); if (xlalErrno != 0) { fprintf(stderr, "%s: XLALGPSSetREAL8() failed on start time = %.9f.\n", __func__, input->searchstarttime); XLAL_ERROR_NULL(XLAL_EFUNC); } XLALGPSSetREAL8(&end, input->searchstarttime+input->Tobs); if (xlalErrno != 0) { fprintf(stderr, "%s: XLALGPSSetREAL8() failed on end time = %.9f.\n", __func__, input->searchstarttime+input->Tobs); XLAL_ERROR_NULL(XLAL_EFUNC); } //Setup the constraints SFTConstraints constraints; constraints.detector = NULL; constraints.minStartTime = constraints.maxStartTime = NULL; constraints.timestamps = NULL; constraints.detector = input->det[0].frDetector.prefix; constraints.minStartTime = &start; constraints.maxStartTime = &end; //Find SFT files catalog = XLALSFTdataFind(sft_dir_file, &constraints); if (catalog==NULL) { fprintf(stderr,"%s: XLALSFTdataFind() failed.\n", __func__); XLAL_ERROR_NULL(XLAL_EFUNC); } //Determine band size (remember to get extra bins because of the running median and the bin shifts due to detector velocity) REAL8 minfbin = round(input->fmin*input->Tcoh - input->dfmax*input->Tcoh - 0.5*(input->blksize-1) - (REAL8)(input->maxbinshift) - 6.0)/input->Tcoh; REAL8 maxfbin = round((input->fmin + input->fspan)*input->Tcoh + input->dfmax*input->Tcoh + 0.5*(input->blksize-1) + (REAL8)(input->maxbinshift) + 6.0)/input->Tcoh; //Now extract the data SFTVector *sfts = XLALLoadSFTs(catalog, minfbin+0.1/input->Tcoh, maxfbin-0.1/input->Tcoh); if (sfts == NULL) { fprintf(stderr,"%s: XLALLoadSFTs() failed to load SFTs with given input parameters.\n", __func__); XLAL_ERROR_NULL(XLAL_EFUNC); } //Now put the power data into the TF plane, looping through each SFT //If an SFT doesn't exit, fill the TF pixels of the SFT with zeros INT4 numffts = (INT4)floor(input->Tobs/(input->Tcoh-input->SFToverlap)-1); INT4 sftlength; if (sfts->length == 0) sftlength = (INT4)round(maxfbin*input->Tcoh - minfbin*input->Tcoh + 1); else { sftlength = sfts->data->data->length; //Check the length is what we expect if (sftlength!=(INT4)round(maxfbin*input->Tcoh - minfbin*input->Tcoh + 1)) { fprintf(stderr, "%s: sftlength (%d) is not matching expected length (%d).\n", __func__, sftlength, (INT4)round(maxfbin*input->Tcoh - minfbin*input->Tcoh + 1)); XLAL_ERROR_NULL(XLAL_EFPINEXCT); } } INT4 nonexistantsft = 0; REAL4Vector *tfdata = XLALCreateREAL4Vector(numffts*sftlength); if (tfdata==NULL) { fprintf(stderr,"%s: XLALCreateREAL4Vector(%d) failed.\n", __func__, numffts*sftlength); XLAL_ERROR_NULL(XLAL_EFUNC); } //Load the data into the output vector, roughly normalizing as we go along from the input value REAL8 sqrtnorm = sqrt(*(normalization)); for (ii=0; ii<numffts; ii++) { SFTDescriptor *sftdescription = &(catalog->data[ii - nonexistantsft]); if (sftdescription->header.epoch.gpsSeconds == (INT4)round(ii*(input->Tcoh-input->SFToverlap)+input->searchstarttime)) { SFTtype *sft = &(sfts->data[ii - nonexistantsft]); for (jj=0; jj<sftlength; jj++) { COMPLEX8 sftcoeff = sft->data->data[jj]; tfdata->data[ii*sftlength + jj] = (REAL4)((sqrtnorm*crealf(sftcoeff))*(sqrtnorm*crealf(sftcoeff)) + (sqrtnorm*cimagf(sftcoeff))*(sqrtnorm*cimagf(sftcoeff))); //power, normalized } } else { for (jj=0; jj<sftlength; jj++) tfdata->data[ii*sftlength + jj] = 0.0; //Set values to be zero nonexistantsft++; //increment the nonexistantsft counter } } /* for ii < numffts */ //Vladimir's code uses a different SFT normalization factor than MFD if (strcmp(input->sftType, "vladimir") == 0) { REAL4 vladimirfactor = (REAL4)(0.25*(8.0/3.0)); for (ii=0; ii<(INT4)tfdata->length; ii++) tfdata->data[ii] *= vladimirfactor; } //Destroy stuff XLALDestroySFTCatalog(catalog); XLALDestroySFTVector(sfts); fprintf(stderr, "Duty factor = %f\n", 1.0-(REAL4)nonexistantsft/(REAL4)numffts); return tfdata; } /* readInSFTs() */
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() */
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; }
/** * 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 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); }
/** * 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() */
/** * Multi-IFO version of LALGetAMCoeffs(). * Get all antenna-pattern coefficients for all input detector-series. * * NOTE: contrary to LALGetAMCoeffs(), this functions *allocates* the output-vector, * use XLALDestroyMultiAMCoeffs() to free this. */ void LALGetMultiAMCoeffs (LALStatus *status, /**< [in/out] LAL status structure pointer */ MultiAMCoeffs **multiAMcoef, /**< [out] AM-coefficients for all input detector-state series */ const MultiDetectorStateSeries *multiDetStates, /**< [in] detector-states at timestamps t_i */ SkyPosition skypos /**< source sky-position [in equatorial coords!] */ ) { UINT4 X, numDetectors; MultiAMCoeffs *ret = NULL; INITSTATUS(status); ATTATCHSTATUSPTR (status); /* check input */ ASSERT (multiDetStates, status,LALCOMPUTEAMH_ENULL, LALCOMPUTEAMH_MSGENULL); ASSERT (multiDetStates->length, status,LALCOMPUTEAMH_ENULL, LALCOMPUTEAMH_MSGENULL); ASSERT (multiAMcoef, status,LALCOMPUTEAMH_ENULL, LALCOMPUTEAMH_MSGENULL); ASSERT ( *multiAMcoef == NULL, status,LALCOMPUTEAMH_ENONULL, LALCOMPUTEAMH_MSGENONULL); ASSERT ( skypos.system == COORDINATESYSTEM_EQUATORIAL, status, LALCOMPUTEAMH_EINPUT, LALCOMPUTEAMH_MSGEINPUT ); numDetectors = multiDetStates->length; if ( ( ret = LALCalloc( 1, sizeof( *ret ) )) == NULL ) { ABORT (status, LALCOMPUTEAMH_EMEM, LALCOMPUTEAMH_MSGEMEM); } ret->length = numDetectors; if ( ( ret->data = LALCalloc ( numDetectors, sizeof ( *ret->data ) )) == NULL ) { LALFree ( ret ); ABORT (status, LALCOMPUTEAMH_EMEM, LALCOMPUTEAMH_MSGEMEM); } for ( X=0; X < numDetectors; X ++ ) { AMCoeffs *amcoeX = NULL; UINT4 numStepsX = multiDetStates->data[X]->length; ret->data[X] = LALCalloc ( 1, sizeof ( *(ret->data[X]) ) ); amcoeX = ret->data[X]; amcoeX->a = XLALCreateREAL4Vector ( numStepsX ); if ( (amcoeX->b = XLALCreateREAL4Vector ( numStepsX )) == NULL ) { LALPrintError ("\nOut of memory!\n\n"); goto failed; } /* LALGetAMCoeffs (status->statusPtr, amcoeX, multiDetStates->data[X], skypos ); */ LALNewGetAMCoeffs (status->statusPtr, amcoeX, multiDetStates->data[X], skypos ); if ( status->statusPtr->statusCode ) { LALPrintError ( "\nCall to LALNewGetAMCoeffs() has failed ... \n\n"); goto failed; } } /* for X < numDetectors */ goto success; failed: /* free all memory allocated so far */ XLALDestroyMultiAMCoeffs ( ret ); ABORT ( status, -1, "LALGetMultiAMCoeffs() failed" ); success: (*multiAMcoef) = ret; DETATCHSTATUSPTR (status); RETURN(status); } /* LALGetMultiAMCoeffs() */
//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 ); }
/* Main Program */ INT4 main ( INT4 argc, CHAR *argv[] ) { static LALStatus status; INT4 c; UINT4 i; REAL8 dt, totTime; REAL8 sampleRate = -1; REAL8 totalMass = -1, massRatio = -1; REAL8 lowFreq = -1, df, fLow; CHAR *outFile = NULL, *outFileLong = NULL, tail[50]; size_t optarg_len; REAL8 eta; REAL8 newtonianChirpTime, PN1ChirpTime, mergTime; UINT4 numPts; LIGOTimeGPS epoch; REAL8 offset; PhenomCoeffs coeffs; PhenomParams params; REAL4FrequencySeries *Aeff = NULL, *Phieff = NULL; COMPLEX8Vector *uFPlus = NULL, *uFCross = NULL; COMPLEX8 num; REAL4Vector *hPlus = NULL, *hCross = NULL; REAL4TimeSeries *hP = NULL, *hC = NULL; /* REAL4TimeSeries *hP = NULL, *hC = NULL;*/ REAL4FFTPlan *prevPlus = NULL, *prevCross = NULL; /*REAL4Vector *Freq = NULL;*/ UINT4 windowLength; INT4 hPLength; REAL8 linearWindow; /* getopt arguments */ struct option long_options[] = { {"mass-ratio", required_argument, 0, 'q'}, {"low-freq (Hz)", required_argument, 0, 'f'}, {"total-mass (M_sun)", required_argument, 0, 'm'}, {"sample-rate", required_argument, 0, 's'}, {"output-file", required_argument, 0, 'o'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} }; /* parse the arguments */ while ( 1 ) { /* getopt_long stores long option here */ int option_index = 0; /* parse command line arguments */ c = getopt_long_only( argc, argv, "q:t:d:hV", long_options, &option_index ); /* detect the end of the options */ if ( c == -1 ) { break; } switch ( c ) { case 0: fprintf( stderr, "Error parsing option '%s' with argument '%s'\n", long_options[option_index].name, optarg ); exit( 1 ); break; case 'h': /* help message */ print_usage( argv[0] ); exit( 0 ); break; case 'V': /* print version information and exit */ fprintf( stdout, "%s - Compute Ajith's Phenomenological Waveforms " \ "(arXiv:0710.2335) and output them to a plain text file\n" \ "CVS Version: %s\nCVS Tag: %s\n", PROGRAM_NAME, CVS_ID_STRING, \ CVS_NAME_STRING ); exit( 0 ); break; case 'q': /* set mass ratio */ massRatio = atof( optarg ); break; case 'f': /* set low freq */ lowFreq = atof( optarg ); break; case 'm': /* set total mass */ totalMass = atof( optarg ); break; case 's': /* set sample rate */ sampleRate = atof( optarg ); break; case 'o': /* set name of output file */ optarg_len = strlen(optarg) + 1; outFile = (CHAR *)calloc(optarg_len, sizeof(CHAR)); memcpy(outFile, optarg, optarg_len); break; case '?': print_usage( argv[0] ); exit( 1 ); break; default: fprintf( stderr, "ERROR: Unknown error while parsing options\n" ); print_usage( argv[0] ); exit( 1 ); } } if ( optind < argc ) { fprintf( stderr, "ERROR: Extraneous command line arguments:\n" ); while ( optind < argc ) { fprintf ( stderr, "%s\n", argv[optind++] ); } exit( 1 ); } /* * * * * * * * */ /* Main Program */ /* * * * * * * * */ eta = massRatio / pow(1. + massRatio, 2.); /* This freq low is the one used for the FFT */ /* fLow = 2.E-3/(totalMass*LAL_MTSUN_SI); */ fLow = lowFreq; /* Changed by Ajith. 5 May 2008 */ /* Phenomenological coefficients as in Ajith et. al */ GetPhenomCoeffsLongJena( &coeffs ); /* Compute phenomenologial parameters */ ComputeParamsFromCoeffs( ¶ms, &coeffs, eta, totalMass ); /* Check validity of arguments */ /* check we have freqs */ if ( totalMass < 0 ) { fprintf( stderr, "ERROR: --total-mass must be specified\n" ); exit( 1 ); } /* check we have mass ratio and delta t*/ if ( massRatio < 0 ) { fprintf( stderr, "ERROR: --mass-ratio must be specified\n" ); exit( 1 ); } if ( lowFreq < 0 ) { fprintf( stderr, "ERROR: --low-freq must be specified\n" ); exit( 1 ); } if ( sampleRate < 0 ) { fprintf( stderr, "ERROR: --sample-rate must be specified\n" ); exit( 1 ); } if ( lowFreq > params.fCut ) { fprintf( stderr, "\nERROR in --low-freq\n"\ "The value chosen for the low frequency is larger "\ "than the frequency at the merger.\n" "Frequency at the merger: %4.2f Hz\nPick either a lower value"\ " for --low-freq or a lower total mass\n\n", params.fCut); exit(1); } if ( lowFreq < fLow ) { fprintf( stderr, "\nERROR in --low-freq\n"\ "The value chosen for the low frequency is lower "\ "than the lowest frequency computed\nby the implemented FFT.\n" "Lowest frequency allowed: %4.2f Hz\nPick either a higher value"\ " for --low-freq or a higher total mass\n\n", fLow); exit(1); } if ( outFile == NULL ) { fprintf( stderr, "ERROR: --output-file must be specified\n" ); exit( 1 ); } /* Complete file name with details of the input variables */ sprintf(tail, "%s-Phenom_M%3.1f_R%2.1f.dat", outFile, totalMass, massRatio); optarg_len = strlen(tail) + strlen(outFile) + 1; outFileLong = (CHAR *)calloc(optarg_len, sizeof(CHAR)); strcpy(outFileLong, tail); /* check sample rate is enough */ if (sampleRate > 4.*params.fCut) /* Changed by Ajith. 5 May 2008 */ { dt = 1./sampleRate; } else { sampleRate = 4.*params.fCut; dt = 1./sampleRate; } /* Estimation of the time duration of the binary */ /* See Sathya (1994) for the Newtonian and PN1 chirp times */ /* The merger time is overestimated */ newtonianChirpTime = (5./(256.*eta))*pow(totalMass*LAL_MTSUN_SI,-5./3.)*pow(LAL_PI*fLow,-8./3.); PN1ChirpTime = 5.*(743.+924.*eta)/(64512.*eta*totalMass*LAL_MTSUN_SI*pow(LAL_PI*fLow,2.)); mergTime = 2000.*totalMass*LAL_MTSUN_SI; totTime = 1.2 * (newtonianChirpTime + PN1ChirpTime + mergTime); numPts = (UINT4) ceil(totTime/dt); df = 1/(numPts * dt); /* Compute Amplitude and Phase from the paper (Eq. 4.19) */ Aeff = XLALHybridP1Amplitude(¶ms, fLow, df, eta, totalMass, numPts/2+1); Phieff = XLALHybridP1Phase(¶ms, fLow, df, eta, totalMass, numPts/2 +1); /* Construct u(f) = Aeff*e^(i*Phieff) */ XLALComputeComplexVector(&uFPlus, &uFCross, Aeff, Phieff); /* Scale this to units of M */ for (i = 0; i < numPts/2 + 1; i++) { num = uFPlus->data[i]; num.re *= 1./(dt*totalMass*LAL_MTSUN_SI); num.im *= 1./(dt*totalMass*LAL_MTSUN_SI); uFPlus->data[i] = num; num = uFCross->data[i]; num.re *= 1./(dt*totalMass*LAL_MTSUN_SI); num.im *= 1./(dt*totalMass*LAL_MTSUN_SI); uFCross->data[i] = num; } /* Inverse Fourier transform */ LALCreateReverseREAL4FFTPlan( &status, &prevPlus, numPts, 0 ); LALCreateReverseREAL4FFTPlan( &status, &prevCross, numPts, 0 ); hPlus = XLALCreateREAL4Vector(numPts); hCross = XLALCreateREAL4Vector(numPts); LALReverseREAL4FFT( &status, hPlus, uFPlus, prevPlus ); LALReverseREAL4FFT( &status, hCross, uFCross, prevCross ); /* The LAL implementation of the FFT omits the factor 1/n */ for (i = 0; i < numPts; i++) { hPlus->data[i] /= numPts; hCross->data[i] /= numPts; } /* Create TimeSeries to store more info about the waveforms */ /* Note: it could be done easier using LALFreqTimeFFT instead of ReverseFFT */ epoch.gpsSeconds = 0; epoch.gpsNanoSeconds = 0; hP = XLALCreateREAL4TimeSeries("", &epoch, 0, dt, &lalDimensionlessUnit, numPts); hP->data = hPlus; hC = XLALCreateREAL4TimeSeries("", &epoch, 0, dt, &lalDimensionlessUnit, numPts); hC->data = hCross; /* Cutting off the part of the waveform with f < fLow */ /* Freq = XLALComputeFreq( hP, hC); hP = XLALCutAtFreq( hP, Freq, lowFreq); hC = XLALCutAtFreq( hC, Freq, lowFreq); */ /* multiply the last few samples of the time-series by a linearly * dropping window function in order to avid edges in the data * Added by Ajith 6 May 2008 */ hPLength = hP->data->length; windowLength = (UINT4) (20.*totalMass * LAL_MTSUN_SI/dt); for (i=1; i<= windowLength; i++){ linearWindow = (i-1.)/windowLength; hP->data->data[hPLength-i] *= linearWindow; hC->data->data[hPLength-i] *= linearWindow; } /* Convert t column to units of (1/M) */ /* offset *= (1./(totalMass * LAL_MTSUN_SI)); hP->deltaT *= (1./(totalMass * LAL_MTSUN_SI)); */ /* Set t = 0 at the merger (defined as the max of the NR wave) */ XLALFindNRCoalescenceTimeFromhoft( &offset, hP); XLALGPSAdd( &(hP->epoch), -offset); XLALGPSAdd( &(hC->epoch), -offset); /* Print waveforms to file */ LALPrintHPlusCross( hP, hC, outFileLong ); /* Free Memory */ XLALDestroyREAL4FrequencySeries(Aeff); XLALDestroyREAL4FrequencySeries(Phieff); XLALDestroyREAL4FFTPlan(prevPlus); XLALDestroyREAL4FFTPlan(prevCross); XLALDestroyCOMPLEX8Vector(uFPlus); XLALDestroyCOMPLEX8Vector(uFCross); XLALDestroyREAL4TimeSeries(hP); XLALDestroyREAL4TimeSeries(hC); /* XLALDestroyREAL4TimeSeries(hP); */ /* XLALDestroyREAL4TimeSeries(hC); */ return(0); }