37 #include <lal/XLALError.h>
39 #include <lal/AVFactories.h>
40 #include <lal/LogPrintf.h>
41 #include <lal/LALString.h>
43 #include <lal/ProbabilityDensity.h>
44 #include <lal/TransientCW_utils.h>
54 #define EXPLUT_XMAX 20.0
55 #define EXPLUT_LENGTH 2000
57 #define EXPLUT_DXINV ((EXPLUT_LENGTH)/(EXPLUT_XMAX))
79 char windowNameLC [ strlen( windowName ) + 1 ];
80 strcpy( windowNameLC, windowName );
91 if ( winType == -1 ) {
121 UINT4 win_t0 = transientWindow.
t0;
122 UINT4 win_tau = transientWindow.
tau;
124 switch ( transientWindow.
type ) {
140 ( *t1 ) = win_t0 + win_tau;
143 XLALPrintError(
"invalid transient window type %d not in [%d, %d].\n",
164 if ( !series || !series->
data ) {
186 switch ( transientWindow.
type ) {
188 for (
i = 0;
i < ts_length;
i ++ ) {
189 UINT4 ti = lround( ts_t0 +
i * ts_dt );
190 if ( ti < t0 || ti >
t1 ) {
197 for (
i = 0;
i < ts_length;
i ++ ) {
198 UINT4 ti = lround( ts_t0 +
i * ts_dt );
205 XLALPrintError(
"%s: invalid transient window type %d not in [%d, %d].\n",
231 if ( !multiNoiseWeights || multiNoiseWeights->
length == 0 ) {
240 numIFOs = multiNoiseWeights->
length;
241 if (
multiTS->length != numIFOs ) {
259 for ( X = 0; X < numIFOs; X ++ ) {
262 if (
multiTS->data[X]->length != numTS ) {
263 XLALPrintError(
"%s: inconsistent number of timesteps 'multiNoiseWeights[%d]' (%d) and 'multiTS[%d]' (%d).\n",
__func__, X, numTS, X,
multiTS->data[X]->length );
267 switch ( transientWindow.
type ) {
269 for (
i = 0;
i < numTS;
i ++ ) {
277 for (
i = 0;
i < numTS;
i ++ ) {
285 XLALPrintError(
"%s: invalid transient window type %d not in [%d, %d].\n",
318 len = snprintf( buf,
MAXLEN,
"tRef%09d_RA%.9g_DEC%.9g_Freq%.15g",
319 par->refTime.gpsSeconds,
329 if (
par->fkdot[
i] ) {
331 len = snprintf( buf1,
MAXLEN,
"%s_f%ddot%.7g", buf,
i,
par->fkdot[
i] );
340 if (
par->asini > 0 ) {
344 len = strlen( buf ) + 1;
345 if ( ( ret =
LALMalloc( len ) ) == NULL ) {
372 if ( !FstatMap || !FstatMap->
F_mn ) {
389 UINT4 N_tauRange = FstatMap->
F_mn->size2;
392 for (
m = 0;
m < N_t0Range;
m ++ ) {
393 for (
n = 0;
n < N_tauRange;
n ++ ) {
394 REAL8 DeltaF = FstatMap->
maxF - gsl_matrix_get( FstatMap->
F_mn,
m,
n );
405 REAL8 logBhat = FstatMap->
maxF + log( sum_eB );
407 REAL8 normBh = 70.0 / ( N_t0Range * N_tauRange );
411 REAL8 logBstat = log( normBh ) + logBhat;
437 if ( !FstatMap || !FstatMap->
F_mn ) {
452 UINT4 N_tauRange = FstatMap->
F_mn->size2;
460 if ( N_t0Range == 1 && ( windowRange.
t0Band == 0 ) ) {
467 if ( ( N_t0Range == 1 ) && ( windowRange.
t0Band > 0 ) ) {
482 for (
m = 0;
m < N_t0Range;
m ++ ) {
484 for (
n = 0;
n < N_tauRange;
n ++ ) {
485 REAL8 DeltaF = FstatMap->
maxF - gsl_matrix_get( FstatMap->
F_mn,
m,
n );
492 ret->probDens->data[
m] = sum_eF;
524 if ( !FstatMap || !FstatMap->
F_mn ) {
539 UINT4 N_tauRange = FstatMap->
F_mn->size2;
547 if ( N_tauRange == 1 && ( windowRange.
tauBand == 0 ) ) {
554 if ( ( N_tauRange == 1 ) && ( windowRange.
tauBand > 0 ) ) {
569 for (
n = 0;
n < N_tauRange;
n ++ ) {
571 for (
m = 0;
m < N_t0Range;
m ++ ) {
572 REAL8 DeltaF = FstatMap->
maxF - gsl_matrix_get( FstatMap->
F_mn,
m,
n );
579 ret->probDens->data[
n] = sum_eF;
618 if ( !multiFstatAtoms || !multiFstatAtoms->
data || !multiFstatAtoms->
data[0] ) {
629 if ( ( ret =
XLALCalloc( 1,
sizeof( *ret ) ) ) == NULL ) {
637 UINT4 TAtomHalf = TAtom / 2;
651 windowRange.
t0 = t0_data;
653 windowRange.
dt0 = TAtom;
654 windowRange.
tau = numAtoms * TAtom;
656 windowRange.
dtau = TAtom;
682 if ( ( ret->
F_mn = gsl_matrix_calloc( N_t0Range, N_tauRange ) ) == NULL ) {
683 XLALPrintError(
"%s: failed ret->F_mn = gsl_matrix_calloc ( %d, %d )\n",
__func__, N_tauRange, N_t0Range );
692 for (
m = 0;
m < N_t0Range;
m ++ ) {
694 win_mn.
t0 = windowRange.
t0 +
m * windowRange.
dt0;
695 INT4 i_tmp = ( win_mn.
t0 - t0_data + TAtomHalf ) / TAtom;
700 if ( i_t0 >= numAtoms ) {
705 REAL4 Ad = 0, Bd = 0, Cd = 0;
707 UINT4 i_t1_last = i_t0;
709 for (
n = 0;
n < N_tauRange;
n ++ ) {
713 win_mn.
tau = windowRange.
tau +
n * windowRange.
dtau;
723 i_tmp = (
t1 - t0_data + TAtomHalf ) / TAtom - 1;
728 if ( i_t1 >= numAtoms ) {
733 if ( i_t1 == i_t0 ) {
734 XLALPrintError(
"%s: encountered a single-atom Fstat-calculation. This is degenerate and cannot be computed!\n",
__func__ );
735 XLALPrintError(
"Window-values m=%d (t0=%d=t0_data + %d), n=%d (tau=%d) ==> t1_data - t0 = %d\n",
736 m, win_mn.
t0, i_t0 * TAtom,
n, win_mn.
tau, t1_data - win_mn.
t0 );
737 XLALPrintError(
"The most likely cause is that your t0-range covered all of your data: t0 must stay away *at least* 2*TAtom from the end of the data!\n" );
744 switch ( windowRange.
type ) {
753 for (
UINT4 i = i_t0;
i <= i_t1;
i ++ )
758 for (
UINT4 i = i_t1_last;
i <= i_t1;
i ++ )
773 i_t1_last = i_t1 + 1;
785 for (
UINT4 i = i_t0;
i <= i_t1;
i ++ ) {
792 REAL8 win2_i = win_i * win_i;
794 Ad += thisAtom_i->
a2_alpha * win2_i;
795 Bd += thisAtom_i->
b2_alpha * win2_i;
796 Cd += thisAtom_i->
ab_alpha * win2_i;
805 XLALPrintError(
"%s: invalid transient window type %d not in [%d, %d].\n",
815 REAL4 DdInv = 1.0f / Dd;
817 REAL4 F = 0.5 * twoF;
819 if ( F > ret->
maxF ) {
831 gsl_matrix_set( ret->
F_mn,
m,
n, F );
862 if ( !multiAtoms || !multiAtoms->
length || !multiAtoms->
data[0] || (
deltaT == 0 ) ) {
872 for ( X = 0; X <
numDet; X ++ ) {
873 if ( multiAtoms->
data[X]->
TAtom != TAtom ) {
874 XLALPrintError(
"%s: Invalid input, atoms baseline TAtom=%d must be identical for all multiFstatAtomVectors (IFO=%d: TAtom=%d)\n",
883 for ( X = 0; X <
numDet; X ++ ) {
909 for ( X = 0; X <
numDet; X ++ ) {
912 for (
i = 0;
i < numAtomsX;
i ++ ) {
914 UINT4 t_X_i = atom_X_i -> timestamp;
952 if ( thisCand == NULL ) {
953 XLALFilePrintf(
fp,
"%%%% Freq[Hz] Alpha[rad] Delta[rad] fkdot[1] fkdot[2] fkdot[3] t0_ML[%c] tau_ML[%c] maxTwoF logBstat t0_MP[%c] tau_MP[%c]\n", timeUnit, timeUnit, timeUnit, timeUnit );
961 XLALFilePrintf(
fp,
" %- 18.16f %- 19.16f %- 19.16f %- 9.6g %- 9.5g %- 9.5g",
965 if ( timeUnit ==
's' ) {
971 }
else if ( timeUnit ==
'd' ) {
1013 XLALFilePrintf(
fp,
"%%%% Freq[Hz] Alpha[rad] Delta[rad] fkdot[1] fkdot[2] fkdot[3] t0[s] tau[s] twoF\n" );
1016 if ( !windowRange ) {
1023 if ( ( N_t0Range != FstatMap->
F_mn->size1 ) || ( N_tauRange != FstatMap->
F_mn->size2 ) ) {
1024 XLAL_ERROR(
XLAL_EDOM,
"Inconsistent dimensions of windowRange (%ux%u) and FstatMap GSL matrix (%zux%zu).", N_t0Range, N_tauRange, FstatMap->
F_mn->size1, FstatMap->
F_mn->size2 );
1028 for (
UINT4 m = 0;
m < N_t0Range;
m ++ ) {
1031 for (
UINT4 n = 0;
n < N_tauRange;
n ++ ) {
1033 REAL4 this_2F = 2.0 * gsl_matrix_get( FstatMap->
F_mn,
m,
n );
1036 this_t0, this_tau, this_2F
1039 XLALFilePrintf(
fp,
" %- 18.16f %- 19.16f %- 19.16f %- 9.6g %- 9.5g %- 9.5g %10d %10d %- 11.8g\n",
1042 this_t0, this_tau, this_2F
1070 if ( thisCand == NULL ) {
1093 if ( !
fp || !multiAtoms ) {
1100 for ( X = 0; X < multiAtoms->
length; X++ ) {
1133 if ( FstatMap->
F_mn ) {
1134 gsl_matrix_free( FstatMap->
F_mn );
1175 if ( ( ret = gsl_vector_alloc(
EXPLUT_LENGTH + 1 ) ) == NULL ) {
1186 gsl_vector_set( ret,
i, exp( - xi ) );
1208 gsl_vector_free(
expLUT );
1247 return gsl_vector_get(
expLUT, i0 );
static REAL4 compute_fstat_from_fa_fb(COMPLEX8 Fa, COMPLEX8 Fb, REAL4 A, REAL4 B, REAL4 C, REAL4 E, REAL4 Dinv)
#define __func__
log an I/O error, i.e.
pdf1D_t * XLALCreateUniformPDF1D(REAL8 xMin, REAL8 xMax)
Creator function for a uniform 1D pdf over [xMin, xMax].
pdf1D_t * XLALCreateDiscretePDF1D(REAL8 xMin, REAL8 xMax, UINT4 numBins)
Creator function for a generic discrete 1D pdf over [xMin, xMax], discretized into numBins bins.
int XLALNormalizePDF1D(pdf1D_t *pdf)
Method to normalize the given pdf1D.
pdf1D_t * XLALCreateSingularPDF1D(REAL8 x0)
Creator function for a 'singular' 1D pdf, containing a single value with certainty,...
static const char * transientWindowNames[TRANSIENT_LAST]
#define EXPLUT_XMAX
Lookup-table for negative exponentials e^(-x) Holds an array 'data' of 'length' for values e^(-x) for...
static gsl_vector * expLUT
module-global lookup-table for negative exponentials e^(-x)
FstatAtomVector * XLALCreateFstatAtomVector(const UINT4 length)
Create a FstatAtomVector of the given length.
void XLALDestroyFstatAtomVector(FstatAtomVector *atoms)
Free all memory associated with a FstatAtomVector structure.
int XLALFilePrintf(LALFILE *file, const char *fmt,...)
REAL4 XLALComputeAntennaPatternSqrtDeterminant(REAL4 A, REAL4 B, REAL4 C, REAL4 E)
Compute (sqrt of) determinant of the antenna-pattern matrix Mmunu = [ A, C, 0, -E; C B E,...
#define XLAL_INIT_DECL(var,...)
void * XLALCalloc(size_t m, size_t n)
int XLALStringToLowerCase(char *string)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
#define PULSAR_MAX_SPINS
maximal number of spin-parameters (Freq + spindowns) we can handle
@ TRANSIENT_RECTANGULAR
standard rectangular window covering [t0, t0+tau]
@ TRANSIENT_NONE
Note: in this case the window-parameters will be ignored, and treated as rect={data},...
@ TRANSIENT_EXPONENTIAL
exponentially decaying window e^{-t0/tau} starting at t0.
transientFstatMap_t * XLALComputeTransientFstatMap(const MultiFstatAtomVector *multiFstatAtoms, transientWindowRange_t windowRange, BOOLEAN useFReg)
Function to compute transient-window "F-statistic map" over start-time and timescale {t0,...
void XLALDestroyTransientFstatMap(transientFstatMap_t *FstatMap)
Standard destructor for transientFstatMap_t Fully NULL-robust as usual.
int XLALParseTransientWindowName(const char *windowName)
Parse a transient window name string into the corresponding transientWindowType.
int XLALApplyTransientWindow2NoiseWeights(MultiNoiseWeights *multiNoiseWeights, const MultiLIGOTimeGPSVector *multiTS, transientWindow_t transientWindow)
apply transient window to give multi noise-weights, associated with given multi timestamps
static int XLALCreateExpLUT(void)
Generate an exponential lookup-table expLUT for e^(-x) over the interval x in [0, xmax],...
int write_transientCandidate_to_fp(LALFILE *fp, const transientCandidate_t *thisCand, const char timeUnit)
Write one line for given transient CW candidate into output file.
int XLALGetTransientWindowTimespan(UINT4 *t0, UINT4 *t1, transientWindow_t transientWindow)
Helper-function to determine the total timespan of a transient CW window, ie.
#define DAY24
standard 24h day = 86400 seconds ==> this is what's used in the definition of 'tauDays'
FstatAtomVector * XLALmergeMultiFstatAtomsBinned(const MultiFstatAtomVector *multiAtoms, UINT4 deltaT)
Combine N Fstat-atoms vectors into a single 'canonical' binned and ordered atoms-vector.
void XLALDestroyExpLUT(void)
Destructor function for expLUT_t lookup table.
REAL8 XLALFastNegExp(REAL8 mx)
Fast exponential function e^-x using lookup-table (LUT).
int write_MultiFstatAtoms_to_fp(LALFILE *fp, const MultiFstatAtomVector *multiAtoms)
Write multi-IFO F-stat atoms 'multiAtoms' into output stream 'fstat'.
CHAR * XLALPulsarDopplerParams2String(const PulsarDopplerParams *par)
Turn pulsar doppler-params into a single string that can be used for filenames The format is tRefNNNN...
int write_transientCandidateAll_to_fp(LALFILE *fp, const transientCandidate_t *thisCand)
Write full set of t0 and tau grid points for given transient CW candidate into output file.
#define TRANSIENT_EXP_EFOLDING
e-folding parameter for exponential window, after which we truncate the window for efficiency.
int XLALApplyTransientWindow(REAL4TimeSeries *series, transientWindow_t transientWindow)
apply a "transient CW window" described by TransientWindowParams to the given timeseries
pdf1D_t * XLALComputeTransientPosterior_t0(transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap)
Compute transient-CW posterior (normalized) on start-time t0, using given type and parameters of tran...
static REAL8 XLALGetExponentialTransientWindowValue(UINT4 timestamp, UINT4 t0, UINT4 t1, UINT4 tau)
Function to compute the value of an exponential transient-window at a given timestamp.
static REAL8 XLALGetRectangularTransientWindowValue(UINT4 timestamp, UINT4 t0, UINT4 t1)
Function to compute the value of a rectangular transient-window at a given timestamp.
pdf1D_t * XLALComputeTransientPosterior_tau(transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap)
Compute transient-CW posterior (normalized) on timescale tau, using given type and parameters of tran...
REAL8 XLALComputeTransientBstat(transientWindowRange_t windowRange, const transientFstatMap_t *FstatMap)
Compute transient-CW Bayes-factor B_SG = P(x|HypS)/P(x|HypG) (where HypG = Gaussian noise hypothesis)...
void XLALDestroyTransientCandidate(transientCandidate_t *cand)
Standard destructor for transientCandidate_t Fully NULL-robust as usual.
int write_transientFstatMap_to_fp(LALFILE *fp, const transientFstatMap_t *FstatMap, const transientWindowRange_t *windowRange, const PulsarDopplerParams *doppler)
Write full set of t0 and tau grid points (assumed at fixed Doppler parameters) into output file.
#define XLAL_ERROR_REAL8(...)
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
An -statistic 'atom', i.e.
REAL4 b2_alpha
Antenna-pattern factor .
UINT4 timestamp
SFT GPS timestamp in seconds.
REAL4 ab_alpha
Antenna-pattern factor .
REAL4 a2_alpha
Antenna-pattern factor .
A vector of -statistic 'atoms', i.e.
UINT4 TAtom
Time-baseline of 'atoms', typically .
FstatAtom * data
Array of FstatAtom pointers of given length.
UINT4 length
Number of per-SFT 'atoms'.
A multi-detector vector of FstatAtomVector.
FstatAtomVector ** data
Array of FstatAtomVector pointers, one for each detector X.
UINT4 length
Number of detectors.
A collection of (multi-IFO) LIGOTimeGPSVector time-stamps vectors.
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
UINT4 length
number of detectors
REAL8Vector ** data
weights-vector for each detector
Type containing the 'Doppler-parameters' affecting the time-evolution of the phase.
PulsarSpins fkdot
Intrinsic spins: [Freq, f1dot, f2dot, ...
REAL8 Delta
Sky position: DEC (latitude) in equatorial coords and radians.
REAL8 Alpha
Sky position: RA (longitude) in equatorial coords and radians.
Struct holding a transient CW candidate.
transientFstatMap_t * FstatMap
F-statistic over transient-window range {t0, tau} AND ML-estimators { Fmax, t0_Fmax,...
REAL8 t0_MP
maximum-posterior estimate for t0
PulsarDopplerParams doppler
Doppler params of this 'candidate'.
REAL8 tau_MP
maximum-posterior estimate for tau
REAL8 logBstat
log of Bayes-factor, marginalized over transientWindowRange
transientWindowRange_t windowRange
type and parameters specifying the transient window range in {t0, tau} covered
Struct holding a transient-window "F-statistic map" over start-time and timescale {t0,...
gsl_matrix * F_mn
"payload" F-map: F_mn for t0_m = t0 + m*dt0, and tau_n = tau + n*dtau
UINT4 tau_ML
maximum-likelihood estimator for duration Tcoh of max{2F} over the transientWindowRange (in seconds)
UINT4 t0_ML
maximum-likelihood estimator for start-time t0 of max{2F} over transientWindowRange (in GPS seconds)
REAL8 maxF
maximal F-value obtained over transientWindowRange
Struct defining one transient window instance.
UINT4 t0
GPS start-time 't0'.
UINT4 tau
transient timescale tau in seconds
transientWindowType_t type
window-type: none, rectangular, exponential, ....
Struct defining a range of transient windows.
UINT4 tauBand
range of transient timescales tau to search, in seconds
UINT4 dtau
stepsize to search tau-range with, in seconds
UINT4 tau
shortest transient timescale tau in seconds
UINT4 t0
earliest GPS start-time 't0' in seconds
UINT4 dt0
stepsize to search t0-range with, in seconds
transientWindowType_t type
window-type: none, rectangular, exponential, ....
UINT4 t0Band
range of start-times 't0' to search, in seconds