60#define GENERATEPULSARSIGNALTESTC_ENORM 0
61#define GENERATEPULSARSIGNALTESTC_EIFO 1
62#define GENERATEPULSARSIGNALTESTC_EMOD 2
63#define GENERATEPULSARSIGNALTESTC_EBIN 3
64#define GENERATEPULSARSIGNALTESTC_EBINS 4
68#define GENERATEPULSARSIGNALTESTC_MSGENORM "Normal exit"
69#define GENERATEPULSARSIGNALTESTC_MSGEIFO "IFO not supported"
70#define GENERATEPULSARSIGNALTESTC_MSGEMOD "SFT max power from LALSignalToSFTs and LALFastGeneratePulsarSFTs differs"
71#define GENERATEPULSARSIGNALTESTC_MSGEBIN "SFT freq with max power from LALSignalToSFTs and LALFastGeneratePulsarSFTs differs by more than 1 bin"
72#define GENERATEPULSARSIGNALTESTC_MSGEBINS "SFTs freq with max power from LALSignalToSFTs and LALFastGeneratePulsarSFTs differs too often"
79#define TESTNUMBER_TO_PRINT 1
80#define SFTINDEX_TO_PRINT 0
88#define INCLUDE_SEQUENTIAL_MISMATCH
96#include <lal/LALStdio.h>
97#include <lal/LALStdlib.h>
98#include <lal/LALConstants.h>
99#include <lal/StreamInput.h>
100#include <lal/AVFactories.h>
101#include <lal/SeqFactories.h>
102#include <lal/VectorOps.h>
103#include <lal/DetectorSite.h>
104#include <lal/Units.h>
105#include <lal/LALDatatypes.h>
106#include <lal/LALBarycenter.h>
107#include <lal/LALInitBarycenter.h>
109#include <lal/GeneratePulsarSignal.h>
110#include <lal/Random.h>
113#define UNUSED __attribute__ ((unused))
127int main(
int UNUSED argc,
char **argv )
136 status.statusDescription = NULL;
140 RunGeneratePulsarSignalTest( &
status );
142 if (
status.statusCode ) {
143 fprintf( stderr,
"Error: statusCode = %i statusDescription = %s \n",
status.statusCode,
status.statusDescription );
149 if ( lalDebugLevel &
LALINFO ) {
151 " %s\n", *argv, __FILE__, __LINE__,
152 "$Id$", ( GENERATEPULSARSIGNALTESTC_MSGENORM ) );
191 char earthFile[] = TEST_PKG_DATA_DIR
"earth00-40-DE405.dat.gz";
192 char sunFile[] = TEST_PKG_DATA_DIR
"sun00-40-DE405.dat.gz";
196 REAL8 **freqDerivData;
197 INT4 numSkyPosTotal = 8;
198 INT4 numSpinDown = 1;
199 INT4 numFreqDerivTotal = 2;
200 INT4 numFreqDerivIncludingNoSpinDown;
204 REAL8 DeltaRA = 0.01;
205 REAL8 DeltaDec = 0.01;
206 REAL8 DeltaFDeriv1 = -1.0e-10;
207 REAL8 DeltaFDeriv2 = 0.0;
208 REAL8 DeltaFDeriv3 = 0.0;
209 REAL8 DeltaFDeriv4 = 0.0;
210 REAL8 DeltaFDeriv5 = 0.0;
214 REAL8 f0SFT = 943.12;
216 UINT4 gpsStartTimeSec = 765432109;
217 UINT4 gpsStartTimeNan = 0;
223 INT4 nBinsSFT = (
INT4 )( bandSFT * tSFT + 0.5 );
226 REAL8 f0SGNL = f0SFT + bandSFT / 2.0;
227 REAL8 dfSGNL = 1.0 / tSFT;
228 REAL8 bandSGNL = 0.005;
229 INT4 nBinsSGNL = (
INT4 )( bandSGNL * tSFT + 0.5 );
230 INT4 nsamples = 18000;
236 REAL4 maxDiffSFTMod, diffAtMaxPower;
237 REAL4 overallMaxDiffSFTMod;
238 REAL4 maxMod, fastMaxMod;
239 INT4 jMaxMod, jFastMaxMod;
240 REAL4 tmpDiffSFTMod, sftMod, fastSFTMod;
241 REAL4 smallMod = 1.e-30;
243 REAL4 epsBinErrorRate;
244 INT4 binErrorCount = 0;
248#ifdef INCLUDE_RANDVAL_MISMATCH
269 for ( iSky = 0; iSky < numSkyPosTotal; iSky++ ) {
274 skyPosData[iSky][1] = 0.03 *
LAL_PI / 2.0;
275 }
else if ( iSky == 1 ) {
277 skyPosData[iSky][1] = -0.57 *
LAL_PI / 2.0;
278 }
else if ( iSky == 2 ) {
280 skyPosData[iSky][1] = 0.86 *
LAL_PI / 2.0;
281 }
else if ( iSky == 3 ) {
283 skyPosData[iSky][1] = -0.07 *
LAL_PI / 2.0;
284 }
else if ( iSky == 4 ) {
286 skyPosData[iSky][1] = 0.99 *
LAL_PI / 2.0;
287 }
else if ( iSky == 5 ) {
289 skyPosData[iSky][1] = -0.99 *
LAL_PI / 2.0;
290 }
else if ( iSky == 6 ) {
292 skyPosData[iSky][1] = 0.19 *
LAL_PI / 2.0;
293 }
else if ( iSky == 7 ) {
295 skyPosData[iSky][1] = 0.01 *
LAL_PI / 2.0;
297 skyPosData[iSky][0] = 0.0;
298 skyPosData[iSky][1] = 0.0;
302 freqDerivData = NULL;
303 if ( numSpinDown > 0 ) {
305 for ( jDeriv = 0; jDeriv < numFreqDerivTotal; jDeriv++ ) {
308 for ( k = 0;
k < numSpinDown;
k++ ) {
309 freqDerivData[jDeriv][
k] = 0.0;
311 }
else if ( jDeriv == 1 ) {
312 for ( k = 0;
k < numSpinDown;
k++ ) {
313 freqDerivData[jDeriv][
k] = 1.e-9;
316 for ( k = 0;
k < numSpinDown;
k++ ) {
317 freqDerivData[jDeriv][
k] = 0.0;
321 numFreqDerivIncludingNoSpinDown = numFreqDerivTotal;
323 numFreqDerivIncludingNoSpinDown = 1;
333 if ( numSpinDown > 0 ) {
338 pPulsarSignalParams->
transfer = NULL;
342 if ( strstr(
IFO,
"LHO" ) ) {
344 }
else if ( strstr(
IFO,
"LLO" ) ) {
346 }
else if ( strstr(
IFO,
"GEO" ) ) {
348 }
else if ( strstr(
IFO,
"VIRGO" ) ) {
350 }
else if ( strstr(
IFO,
"TAMA" ) ) {
356 pPulsarSignalParams->
site = &cachedDetector;
369 pSFTParams->
Tsft = tSFT;
373#ifdef INCLUDE_RANDVAL_MISMATCH
375 fpRandom = fopen(
"/dev/urandom",
"r" );
376 rndCount = fread( &
seed,
sizeof(
INT4 ), 1, fpRandom );
392 pSFTandSignalParams->
resTrig = 0;
394 if ( pSFTandSignalParams->
resTrig > 0 ) {
398 for ( k = 0;
k <= pSFTandSignalParams->
resTrig;
k++ ) {
401 pSFTandSignalParams->
sinVal[
k] = sin( pSFTandSignalParams->
trigArg[k] );
402 pSFTandSignalParams->
cosVal[
k] = cos( pSFTandSignalParams->
trigArg[k] );
405 pSFTandSignalParams->
pSigParams = pPulsarSignalParams;
407 pSFTandSignalParams->
nSamples = nsamples;
408 pSFTandSignalParams->
Dterms = Dterms;
415 for ( iSky = 0; iSky < numSkyPosTotal; iSky++ ) {
419#ifdef INCLUDE_SEQUENTIAL_MISMATCH
420 randval = ( (
REAL4 )( iSky ) ) / ( (
REAL4 )( numSkyPosTotal ) );
422#ifdef INCLUDE_RANDVAL_MISMATCH
427 cosTmpDEC = cos( skyPosData[iSky][1] );
428 if ( cosTmpDEC != 0.0 ) {
429 tmpDeltaRA = DeltaRA / cosTmpDEC;
436#ifdef INCLUDE_SEQUENTIAL_MISMATCH
437 randval = ( (
REAL4 )( iSky ) ) / ( (
REAL4 )( numSkyPosTotal ) );
439#ifdef INCLUDE_RANDVAL_MISMATCH
448 XLALPrintError(
"XLALConvertGPS2SSB() failed with xlalErrno = %d\n", xlalErrno );
461 for ( jDeriv = 0; jDeriv < numFreqDerivIncludingNoSpinDown; jDeriv++ ) {
463 if ( numSpinDown > 0 ) {
464 for ( k = 0;
k < numSpinDown;
k++ ) {
466#ifdef INCLUDE_SEQUENTIAL_MISMATCH
467 if ( freqDerivData[jDeriv][k] < 0.0 ) {
468 randval = ( (
REAL4 )( iSky ) ) / ( (
REAL4 )( numSkyPosTotal ) );
473#ifdef INCLUDE_RANDVAL_MISMATCH
478 pPulsarSignalParams->
pulsar.
spindown->
data[
k] = freqDerivData[jDeriv][
k] + ( ( (
REAL8 )randval ) - 0.5 ) * DeltaFDeriv1;
479 }
else if ( k == 1 ) {
480 pPulsarSignalParams->
pulsar.
spindown->
data[
k] = freqDerivData[jDeriv][
k] + ( ( (
REAL8 )randval ) - 0.5 ) * DeltaFDeriv2;
481 }
else if ( k == 2 ) {
482 pPulsarSignalParams->
pulsar.
spindown->
data[
k] = freqDerivData[jDeriv][
k] + ( ( (
REAL8 )randval ) - 0.5 ) * DeltaFDeriv3;
483 }
else if ( k == 3 ) {
484 pPulsarSignalParams->
pulsar.
spindown->
data[
k] = freqDerivData[jDeriv][
k] + ( ( (
REAL8 )randval ) - 0.5 ) * DeltaFDeriv4;
485 }
else if ( k == 4 ) {
486 pPulsarSignalParams->
pulsar.
spindown->
data[
k] = freqDerivData[jDeriv][
k] + ( ( (
REAL8 )randval ) - 0.5 ) * DeltaFDeriv5;
496 for ( iFreq = 0; iFreq < nBinsSGNL; iFreq++ ) {
500#ifdef INCLUDE_SEQUENTIAL_MISMATCH
501 randval = ( (
REAL4 )( iFreq ) ) / ( (
REAL4 )( nBinsSGNL ) );
503#ifdef INCLUDE_RANDVAL_MISMATCH
511#ifdef INCLUDE_SEQUENTIAL_MISMATCH
512 randval = ( (
REAL4 )( iFreq ) ) / ( (
REAL4 )( nBinsSGNL ) );
514#ifdef INCLUDE_RANDVAL_MISMATCH
518 cosIota = 2.0 * ( (
REAL8 )randval ) - 1.0;
521 pPulsarSignalParams->
pulsar.
aPlus = (
REAL4 )( 0.5 * h_0 * ( 1.0 + cosIota * cosIota ) );
526#ifdef INCLUDE_SEQUENTIAL_MISMATCH
527 randval = ( (
REAL4 )( iFreq ) ) / ( (
REAL4 )( nBinsSGNL ) );
529#ifdef INCLUDE_RANDVAL_MISMATCH
537 randval = ( (
REAL4 )( iFreq ) ) / ( (
REAL4 )( nBinsSGNL ) );
538#ifdef INCLUDE_RANDVAL_MISMATCH
542 pPulsarSignalParams->
pulsar.
f0 = f0SGNL + iFreq * dfSGNL + ( ( (
REAL8 )randval ) - 0.5 ) * dfSGNL;
554#ifdef PRINT_OUTPUTSFT
555 if ( testNumber == TESTNUMBER_TO_PRINT ) {
556 i = SFTINDEX_TO_PRINT;
557 fprintf( stdout,
"iFreq = %i, inject h_0 = %23.10e \n", iFreq, h_0 );
558 fprintf( stdout,
"iFreq = %i, inject cosIota = %23.10e, A_+ = %23.10e, A_x = %23.10e \n", iFreq, cosIota, pPulsarSignalParams->
pulsar.
aPlus, pPulsarSignalParams->
pulsar.
aCross );
559 fprintf( stdout,
"iFreq = %i, inject psi = %23.10e \n", iFreq, pPulsarSignalParams->
pulsar.
psi );
560 fprintf( stdout,
"iFreq = %i, inject phi0 = %23.10e \n", iFreq, pPulsarSignalParams->
pulsar.
phi0 );
561 fprintf( stdout,
"iFreq = %i, search f0 = %23.10e, inject f0 = %23.10e \n", iFreq, f0SGNL + iFreq * dfSGNL, pPulsarSignalParams->
pulsar.
f0 );
564 for ( j = 0;
j < nBinsSFT;
j++ ) {
576#ifdef PRINT_FASTOUTPUTSFT
577 if ( testNumber == TESTNUMBER_TO_PRINT ) {
580 i = SFTINDEX_TO_PRINT;
583 fprintf( stdout,
"iFreq = %i, inject h_0 = %23.10e \n", iFreq, h_0 );
584 fprintf( stdout,
"iFreq = %i, inject cosIota = %23.10e, A_+ = %23.10e, A_x = %23.10e \n", iFreq, cosIota, pPulsarSignalParams->
pulsar.
aPlus, pPulsarSignalParams->
pulsar.
aCross );
585 fprintf( stdout,
"iFreq = %i, inject psi = %23.10e \n", iFreq, pPulsarSignalParams->
pulsar.
psi );
586 fprintf( stdout,
"iFreq = %i, fPlus, fCross = %23.10e, %23.10e \n", iFreq, fPlus, fCross );
587 fprintf( stdout,
"iFreq = %i, inject phi0 = %23.10e \n", iFreq, pPulsarSignalParams->
pulsar.
phi0 );
588 fprintf( stdout,
"iFreq = %i, search f0 = %23.10e, inject f0 = %23.10e \n", iFreq, f0SGNL + iFreq * dfSGNL, pPulsarSignalParams->
pulsar.
f0 );
591 for ( j = 0;
j < nBinsSFT;
j++ ) {
601 overallMaxDiffSFTMod = 0.0;
605 diffAtMaxPower = 0.0;
611 for ( j = 0;
j < nBinsSFT;
j++ ) {
613 sftMod = sqrt( sftMod );
615 fastSFTMod = sqrt( fastSFTMod );
616 if ( fabs( sftMod ) > smallMod ) {
617 tmpDiffSFTMod = fabs( ( sftMod - fastSFTMod ) / sftMod );
618 if ( tmpDiffSFTMod > maxDiffSFTMod ) {
619 maxDiffSFTMod = tmpDiffSFTMod;
621 if ( tmpDiffSFTMod > overallMaxDiffSFTMod ) {
622 overallMaxDiffSFTMod = tmpDiffSFTMod;
624 if ( sftMod > maxMod ) {
628 if ( fastSFTMod > fastMaxMod ) {
629 fastMaxMod = fastSFTMod;
634 if ( fabs( maxMod ) > smallMod ) {
635 diffAtMaxPower = fabs( ( maxMod - fastMaxMod ) / maxMod );
637#ifdef PRINT_MAXSFTPOWER
638 fprintf( stdout,
"maxSFTMod, testNumber %i, SFT %i, bin %i = %g \n", testNumber,
i, jMaxMod, maxMod );
639 fprintf( stdout,
"maxFastSFTMod, testNumber %i, SFT %i, bin %i = %g \n", testNumber,
i, jFastMaxMod, fastMaxMod );
642#ifdef PRINT_MAXDIFFSFTPOWER
643 fprintf( stdout,
"maxDiffSFTMod, testNumber %i, SFT %i, bin %i = %g \n", testNumber,
i, jMaxDiff, maxDiffSFTMod );
646#ifdef PRINT_DIFFATMAXPOWER
647 fprintf( stdout,
"diffAtMaxPower, testNumber %i, SFT %i, bins %i and %i = %g \n", testNumber,
i, jMaxMod, jFastMaxMod, diffAtMaxPower );
650#ifdef PRINT_ERRORATMAXPOWER
651 if ( diffAtMaxPower > epsDiffMod ) {
652 fprintf( stdout,
"diffAtMaxPower, testNumber %i, SFT %i, bins %i and %i = %g exceeded epsDiffMod = %g \n", testNumber,
i, jMaxMod, jFastMaxMod, diffAtMaxPower, epsDiffMod );
656 if ( jMaxMod != jFastMaxMod ) {
657 fprintf( stdout,
"MaxPower occurred in different bins: testNumber %i, SFT %i, bins %i and %i\n", testNumber,
i, jMaxMod, jFastMaxMod );
662 if ( jMaxMod != jFastMaxMod ) {
665 if ( diffAtMaxPower > epsDiffMod ) {
669 if ( fabs( ( (
REAL8 )( jMaxMod - jFastMaxMod ) ) ) > 1.1 ) {
673#ifdef PRINT_OVERALLMAXDIFFSFTPOWER
674 fprintf( stdout,
"overallMaxDiffSFTMod, testNumber = %i, SFT %i, bin %i = %g \n", testNumber, iOverallMaxDiffSFTMod, jOverallMaxDiff, overallMaxDiffSFTMod );
680 for ( j = 0;
j < nBinsSFT;
j++ ) {
712 epsBinErrorRate = 0.20;
713 if ( ( ( (
REAL4 )binErrorCount ) / ( (
REAL4 )testNumber ) ) > epsBinErrorRate ) {
717#ifdef INCLUDE_RANDVAL_MISMATCH
726 if ( numSpinDown > 0 ) {
730 LALFree( pPulsarSignalParams );
737 LALFree( pSkyConstAndZeroPsiAMResponse );
739 if ( pSFTandSignalParams->
resTrig > 0 ) {
744 LALFree( pSFTandSignalParams );
747 for (
i = 0;
i < numSkyPosTotal;
i++ ) {
752 if ( numSpinDown > 0 ) {
754 for (
i = 0;
i < numFreqDerivTotal;
i++ ) {
LALDetectorIndexGEO600DIFF
LALDetectorIndexTAMA300DIFF
LALDetectorIndexVIRGODIFF
#define GENERATEPULSARSIGNALTESTC_EMOD
SFT max power from LALSignalToSFTs and LALFastGeneratePulsarSFTs differs.
#define GENERATEPULSARSIGNALTESTC_EBIN
SFT freq with max power from LALSignalToSFTs and LALFastGeneratePulsarSFTs differs by more than 1 bin...
#define GENERATEPULSARSIGNALTESTC_EBINS
SFTs freq with max power from LALSignalToSFTs and LALFastGeneratePulsarSFTs differs too often.
#define GENERATEPULSARSIGNALTESTC_EIFO
IFO not supported.
#define GENERATEPULSARSIGNALTESTC_ENORM
Normal exit.
void LALCheckMemoryLeaks(void)
#define ABORT(statusptr, code, mesg)
#define CHECKSTATUSPTR(statusptr)
#define XLAL_CHECK_LAL(sp, assertion,...)
#define ATTATCHSTATUSPTR(statusptr)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
int main(int argc, char **argv)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
int XLALConvertGPS2SSB(LIGOTimeGPS *SSBout, LIGOTimeGPS GPSin, const PulsarSignalParams *params)
Convert earth-frame GPS time into barycentric-frame SSB time for given source.
void LALGeneratePulsarSignal(LALStatus *status, REAL4TimeSeries **signalvec, const PulsarSignalParams *params)
void LALFastGeneratePulsarSFTs(LALStatus *status, SFTVector **outputSFTs, const SkyConstAndZeroPsiAMResponse *input, const SFTandSignalParams *params)
Fast generation of Fake SFTs for a pure pulsar signal.
void LALSignalToSFTs(LALStatus *status, SFTVector **outputSFTs, const REAL4TimeSeries *signalvec, const SFTParams *params)
void LALComputeSkyAndZeroPsiAMResponse(LALStatus *status, SkyConstAndZeroPsiAMResponse *output, const SFTandSignalParams *params)
/deprecated Move to attic? Wrapper for LALComputeSky() and LALComputeDetAMResponse() that finds the s...
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
void XLALDestroyEphemerisData(EphemerisData *edat)
Destructor for EphemerisData struct, NULL robust.
void LALCreateRandomParams(LALStatus *status, RandomParams **params, INT4 seed)
void LALUniformDeviate(LALStatus *status, REAL4 *deviate, RandomParams *params)
void LALDestroyRandomParams(LALStatus *status, RandomParams **params)
void XLALDestroySFTVector(SFTVector *vect)
XLAL interface to destroy an SFTVector.
COORDINATESYSTEM_EQUATORIAL
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
A vector of COMPLEX8FrequencySeries.
COMPLEX8FrequencySeries * data
Pointer to the data array.
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
A vector of 'timestamps' of type LIGOTimeGPS.
LIGOTimeGPS * data
array of timestamps
UINT4 length
number of timestamps
Input parameters to GeneratePulsarSignal(), defining the source and the time-series.
REAL8 asini
projected, normalized orbital semi-major axis (s)
SkyPosition position
source location (in radians)
const COMPLEX8FrequencySeries * transfer
detector transfer function (NULL if not used)
const EphemerisData * ephemerides
Earth and Sun ephemerides.
UINT4 dtPolBy2
half-interval for the polarisation response look-up table for LALPulsarSimulateCoherentGW()
REAL8 fHeterodyne
heterodyning frequency for output time-series
REAL4 aPlus
plus-polarization amplitude at tRef
struct PulsarSignalParams::@4 orbit
REAL4 psi
polarization angle (radians) at tRef
struct PulsarSignalParams::@3 pulsar
REAL8 phi0
initial phase (radians) at tRef
LIGOTimeGPS startTimeGPS
start time of output time series
UINT4 dtDelayBy2
half-interval for the Doppler delay look-up table for LALPulsarSimulateCoherentGW()
const LALDetector * site
detector location and orientation
REAL8Vector * spindown
wave-frequency spindowns at tRef (NOT f0-normalized!)
LIGOTimeGPS refTime
reference time of pulsar parameters (in SSB!)
REAL8 f0
WAVE-frequency(!) at tRef (in Hz)
REAL4 aCross
cross-polarization amplitude at tRef
REAL8 samplingRate
sampling rate of time-series (= 2 * frequency-Band)
UINT4 duration
length of time series in seconds
Parameters defining the SFTs to be returned from LALSignalToSFTs().
REAL8 Tsft
length of each SFT in seconds
const LIGOTimeGPSVector * timestamps
timestamps to produce SFTs for (can be NULL)
const SFTVector * noiseSFTs
noise SFTs to be added (can be NULL)
Parameters defining the pulsar signal and SFTs used by LALFastGeneratePulsarSFTs().
REAL8 * sinVal
sinVal holds lookup table (LUT) values for doing trig sin calls
INT4 nSamples
nsample from noise SFT header; 2x this equals effective number of time samples
PulsarSignalParams * pSigParams
REAL8 * cosVal
cosVal holds lookup table (LUT) values for doing trig cos calls
REAL8 * trigArg
array of arguments to hold lookup table (LUT) values for doing trig calls
INT4 Dterms
use this to fill in SFT bins with fake data as per LALDemod else fill in bin with zero
INT4 resTrig
length sinVal, cosVal; domain: -2pi to 2pi; resolution = 4pi/resTrig
Sky Constants and beam pattern response functions used by LALFastGeneratePulsarSFTs().
REAL8 * skyConst
vector of A and B sky constants
REAL4 * fPlusZeroPsi
vector of Fplus values for psi = 0 at midpoint of each SFT
REAL4 * fCrossZeroPsi
vector of Fcross values for psi = 0 at midpoint of each SFT