50#include <gsl/gsl_rng.h>
52#include <lal/LALString.h>
53#include <lal/SkyCoordinates.h>
54#include <lal/AVFactories.h>
55#include <lal/LALInitBarycenter.h>
56#include <lal/UserInput.h>
57#include <lal/LogPrintf.h>
58#include <lal/ComputeFstat.h>
59#include <lal/TransientCW_utils.h>
60#include <lal/ProbabilityDensity.h>
61#include <lal/SynthesizeCWDraws.h>
62#include <lal/LineRobustStats.h>
63#include <lal/StringVector.h>
64#include <lal/LALPulsarVCSInfo.h>
67#define SQ(x) ((x)*(x))
68#define SQUARE(x) ( (x) * (x) )
69#define CUBE(x) ((x)*(x)*(x))
70#define QUAD(x) ((x)*(x)*(x)*(x))
78typedef struct tagBSGLComponents {
120 CHAR *outputInjParams;
157int main(
int argc,
char *argv[] );
177int main(
int argc,
char *argv[] )
185 gsl_set_error_handler_off();
212 if ( uvar.lineIFO ) {
214 if ( strcmp( uvar.lineIFO, uvar.IFOs->data[X] ) == 0 ) {
219 XLALPrintError(
"\nError in function %s, line %d : Could not match detector ID \"%s\" for line injection to any detector.\n\n",
__func__, __LINE__, uvar.lineIFO );
225 FILE *fpStats = NULL;
226 if ( uvar.outputStats ) {
227 if ( ( fpStats = fopen( uvar.outputStats,
"wb" ) ) == NULL ) {
231 fprintf( fpStats,
"%s", cfg.logString );
238 FILE *fpInjParams = NULL;
239 if ( uvar.outputInjParams ) {
240 if ( ( fpInjParams = fopen( uvar.outputInjParams,
"wb" ) ) == NULL ) {
244 fprintf( fpInjParams,
"%s", cfg.logString );
253 BSGLSetup *BSGLsetup = NULL;
254 if ( uvar.computeBSGL ) {
256 REAL4 *oLGX_p = NULL;
258 if ( uvar.oLGX != NULL ) {
268 for (
i = 0;
i < uvar.numDraws;
i ++ ) {
274 multiAtoms =
XLALSynthesizeTransientAtoms( &injParamsDrawn, cfg.skypos, cfg.AmpPrior, cfg.transientInjectRange, cfg.multiDetStates, cfg.SignalOnly, &multiAMBuffer, cfg.rng, lineX, cfg.multiNoiseWeights );
291 XLALPrintError(
"\nError in function %s, line %d : Failed call to XLALComputeFstatFromAtoms().\n\n",
__func__, __LINE__ );
298 XLALPrintError(
"\nError in function %s, line %d : Failed call to XLALComputeFstatFromAtoms().\n\n",
__func__, __LINE__ );
302 if ( uvar.computeBSGL ) {
303 synthStats.log10BSGL =
XLALComputeBSGL( synthStats.TwoF, synthStats.TwoFX, BSGLsetup );
308 if ( uvar.outputAtoms ) {
312 UINT4 len = strlen( uvar.outputAtoms ) + 20;
313 if ( ( fnameAtoms =
XLALCalloc( 1, len ) ) == NULL ) {
317 sprintf( fnameAtoms,
"%s_%04d_of_%04d.dat", uvar.outputAtoms,
i + 1, uvar.numDraws );
319 if ( ( fpAtoms =
XLALFileOpen( fnameAtoms,
"wb" ) ) == NULL ) {
351 fclose( fpInjParams );
368 if ( cfg.logString ) {
371 gsl_rng_free( cfg.rng );
390 uvar->outputStats = NULL;
398 uvar->dataStartGPS = 814838413;
407 uvar->computeBSGL = 1;
414 uvar->fixedh0Nat = -1;
416 uvar->fixedh0NatMax = -1;
417 uvar->fixedRhohMax = -1;
423 uvar->lineIFO = NULL;
426#define DEFAULT_TRANSIENT "rect"
436 XLALRegisterUvarMember( fixedh0NatMax,
REAL8, 0, OPTIONAL,
"Alternative 3: if >=0 draw GW amplitude h0 in [0, h0NatMax ] (FReg prior)" );
437 XLALRegisterUvarMember( fixedRhohMax,
REAL8, 0, OPTIONAL,
"Alternative 4: if >=0 draw rhoh=h0*(detM)^(1/8) in [0, rhohMax] (canonical F-stat prior)" );
443 XLALRegisterUvarMember( AmpPriorType,
INT4, 0, OPTIONAL,
"Enumeration of types of amplitude-priors: 0=physical, 1=canonical" );
446 XLALRegisterUvarMember( lineIFO,
STRING, 0, OPTIONAL,
"Insert a line (signal in this one IFO, pure gaussian noise in others), e.g. \"H1\"" );
453 XLALRegisterUvarMember( oLGX, STRINGVector, 0, OPTIONAL,
"BSGL: prior per-detector line-vs-Gauss odds, length must be numDetectors. (Defaults to oLGX=1/Ndet)" );
455 XLALRegisterUvarMember(
sqrtSX, STRINGVector, 0, OPTIONAL,
"Per-detector noise PSD sqrt(SX). Only ratios relevant to compute noise weights. Defaults to 1,1,..." );
466 XLALRegisterUvarMember( useFReg,
BOOLEAN, 0, OPTIONAL,
"use 'regularized' Fstat (1/D)*e^F (if TRUE) for marginalization, or 'standard' e^F (if FALSE)" );
499 const char fmt[] =
"%%%% cmdline: %s\n%%%%\n%s%%%%\n";
500 UINT4 len = strlen( vcs ) + strlen( cmdline ) + strlen(
fmt ) + 1;
531 gsl_rng_default_seed = uvar->
randSeed;
533 cfg->
rng = gsl_rng_alloc( gsl_rng_default );
541 LogPrintf(
LOG_CRITICAL,
"%s: XLALInitBarycenter failed: could not load Earth ephemeris '%s' and Sun ephemeris '%s'\n",
__func__, uvar->ephemEarth, uvar->ephemSun );
550 UINT4 numSteps = (
UINT4 ) ceil( uvar->dataDuration / uvar->TAtom );
560 multiTS->data[X]->deltaT = uvar->TAtom;
562 for (
i = 0;
i < numSteps;
i ++ ) {
563 UINT4 ti = uvar->dataStartGPS +
i * uvar->TAtom;
564 multiTS->data[X]->data[
i].gpsSeconds = ti;
565 multiTS->data[X]->data[
i].gpsNanoSeconds = 0;
575 if ( uvar->sqrtSX ) {
607 const UINT4 AmpPriorBins = 100;
610 if ( !AmpPrior || !uvar ) {
621 if ( uvar->fixedh0Nat >= 0 ) {
624 if ( uvar->fixedSNR >= 0 ) {
627 if ( uvar->fixedh0NatMax >= 0 ) {
630 if ( uvar->fixedRhohMax >= 0 ) {
633 if ( numSets != 1 ) {
634 XLALPrintError(
"%s: Specify (>=0) exactly *ONE* amplitude-prior range of {fixedh0Nat, fixedSNR, fixedh0NatMax, fixedRhohMax}\n",
__func__ );
641 if ( uvar->fixedh0Nat >= 0 )
646 if ( uvar->fixedSNR >= 0 )
651 AmpPrior->
fixedSNR = uvar->fixedSNR;
652 AmpPrior->
fixRhohMax = ( uvar->fixedRhohMax >= 0 );
673 if ( uvar->fixedh0NatMax >= 0 ) {
674 h0NatMax = uvar->fixedh0NatMax;
676 if ( uvar->fixedRhohMax >= 0 ) {
677 h0NatMax = uvar->fixedRhohMax;
680 switch ( uvar->AmpPriorType ) {
694 if ( AmpPrior->
pdf_psi == NULL )
715 for (
i = 0;
i < pdf->probDens->length;
i ++ ) {
716 REAL8 xMid = 0.5 * ( pdf->xTics->data[
i] + pdf->xTics->data[
i + 1] );
717 pdf->probDens->data[
i] =
CUBE( xMid );
729 for (
i = 0;
i < pdf->probDens->length;
i ++ ) {
730 REAL8 xMid = 0.5 * ( pdf->xTics->data[
i] + pdf->xTics->data[
i + 1] );
732 pdf->probDens->data[
i] =
CUBE(
y );
737 if ( AmpPrior->
pdf_psi == NULL )
774 if ( !
stats && !injParams ) {
776 char stat_header_string[256] =
"";
778 snprintf( stat_header_string,
sizeof( stat_header_string ),
"2F " );
779 for (
UINT4 X = 0; X <
IFOs->length ; X ++ ) {
780 snprintf( buf0,
sizeof( buf0 ),
" 2F_%s",
IFOs->data[X] );
781 UINT4 len1 = strlen( stat_header_string ) + strlen( buf0 ) + 1;
782 XLAL_CHECK( len1 <=
sizeof( stat_header_string ),
XLAL_EBADLEN,
"Assembled output string too long! (%d > %zu)", len1,
sizeof( stat_header_string ) );
783 strcat( stat_header_string, buf0 );
786 snprintf( buf0,
sizeof( buf0 ),
" log10BSGL" );
787 strcat( stat_header_string, buf0 );
789 fprintf(
fp,
"%%%% freq alpha delta f1dot %s\n", stat_header_string );
800 char statString[256] =
"";
802 snprintf( statString,
sizeof( statString ),
"%.6f",
stats->TwoF );
803 for (
UINT4 X = 0; X <
IFOs->length ; X ++ ) {
804 snprintf( buf0,
sizeof( buf0 ),
" %.6f",
stats->TwoFX[X] );
805 UINT4 len1 = strlen( statString ) + strlen( buf0 ) + 1;
806 XLAL_CHECK( len1 <=
sizeof( statString ),
XLAL_EBADLEN,
"Assembled output string too long! (%d > %zu)", len1,
sizeof( statString ) );
807 strcat( statString, buf0 );
810 snprintf( buf0,
sizeof( buf0 ),
" %.6f",
stats->log10BSGL );
811 strcat( statString, buf0 );
848 REAL8 sqrtSnTotal = 0;
849 UINT4 numSFTsTotal = 0;
851 sqrtSnTotal +=
multiTS->data[X]->length /
SQ( multiNoiseFloor->
sqrtSn[X] );
852 numSFTsTotal +=
multiTS->data[X]->length;
854 sqrtSnTotal = sqrt( numSFTsTotal / sqrtSnTotal );
859 REAL8 noise_weight_X =
SQ( sqrtSnTotal / multiNoiseFloor->
sqrtSn[X] );
#define __func__
log an I/O error, i.e.
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
pdf1D_t * XLALCreateSingularPDF1D(REAL8 x0)
Creator function for a 'singular' 1D pdf, containing a single value with certainty,...
pdf1D_t * XLALCreateDiscretePDF1D(REAL8 xMin, REAL8 xMax, UINT4 numBins)
Creator function for a generic discrete 1D pdf over [xMin, xMax], discretized into numBins bins.
pdf1D_t * XLALCreateUniformPDF1D(REAL8 xMin, REAL8 xMax)
Creator function for a uniform 1D pdf over [xMin, xMax].
void XLALDestroyPDF1D(pdf1D_t *pdf)
Destructor function for 1-D pdf.
REAL4 XLALComputeFstatFromAtoms(const MultiFstatAtomVector *multiFstatAtoms, const INT4 X)
Compute single-or multi-IFO Fstat '2F' from multi-IFO 'atoms'.
void XLALDestroyMultiFstatAtomVector(MultiFstatAtomVector *multiAtoms)
Free all memory associated with a MultiFstatAtomVector structure.
int XLALParseMultiLALDetector(MultiLALDetector *detInfo, const LALStringVector *detNames)
Parse string-vectors (typically input by user) of N detector-names for detectors ,...
void XLALDestroyMultiDetectorStateSeries(MultiDetectorStateSeries *mdetStates)
Helper function to get rid of a multi-IFO DetectorStateSeries Note, this is "NULL-robust" in the sens...
MultiDetectorStateSeries * XLALGetMultiDetectorStates(const MultiLIGOTimeGPSVector *multiTS, const MultiLALDetector *multiIFO, const EphemerisData *edat, REAL8 tOffset)
Get the detector-time series for the given MultiLIGOTimeGPSVector.
int XLALParseMultiNoiseFloor(MultiNoiseFloor *multiNoiseFloor, const LALStringVector *sqrtSX, UINT4 numDetectors)
Parse string-vectors (typically input by user) of N detector noise-floors for detectors ,...
int XLALFileClose(LALFILE *file)
LALFILE * XLALFileOpen(const char *path, const char *mode)
int XLALFilePrintf(LALFILE *file, const char *fmt,...)
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 XLALDestroyMultiAMCoeffs(MultiAMCoeffs *multiAMcoef)
Destroy a MultiAMCoeffs structure.
#define XLAL_INIT_DECL(var,...)
void * XLALMalloc(size_t n)
void * XLALCalloc(size_t m, size_t n)
char char * XLALStringDuplicate(const char *s)
char * XLALVCSInfoString(const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
BSGLSetup * XLALCreateBSGLSetup(const UINT4 numDetectors, const REAL4 Fstar0sc, const REAL4 oLGX[PULSAR_MAX_DETECTORS], const BOOLEAN useLogCorrection, const UINT4 numSegments)
REAL4 XLALComputeBSGL(const REAL4 twoF, const REAL4 twoFX[PULSAR_MAX_DETECTORS], const BSGLSetup *setup)
Single-bin wrapper of XLALVectorComputeBSGL(), provided for backwards compatibility.
int XLALParseLinePriors(REAL4 oLGX[PULSAR_MAX_DETECTORS], const LALStringVector *oLGX_string)
Parse string-vectors (typically input by user) of N per-detector line-to-Gaussian prior ratios to a ...
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
void XLALDestroyMultiNoiseWeights(MultiNoiseWeights *weights)
Destroy a MultiNoiseWeights object.
#define PULSAR_MAX_DETECTORS
maximal number of detectors we can handle (for static arrays of detector quantities)
@ TRANSIENT_NONE
Note: in this case the window-parameters will be ignored, and treated as rect={data},...
LIGOTimeGPSVector * XLALCreateTimestampVector(UINT4 len)
Allocate a LIGOTimeGPSVector.
void XLALDestroyMultiTimestamps(MultiLIGOTimeGPSVector *multiTS)
Destroy a MultiLIGOTimeGPSVector timestamps vector.
MultiLIGOTimeGPSVector * XLALCreateMultiLIGOTimeGPSVector(UINT4 numDetectors)
Simple creator function for MultiLIGOTimeGPSVector with numDetectors entries.
COORDINATESYSTEM_EQUATORIAL
LALStringVector * XLALCreateStringVector(const CHAR *str1,...)
int write_InjParams_to_fp(FILE *fp, const InjParams_t *par, const UINT4 dataStartGPS, const BOOLEAN outputMmunuX, const UINT4 numDetectors)
Write an injection-parameters structure to the given file-pointer, adding one line with the injection...
MultiFstatAtomVector * XLALSynthesizeTransientAtoms(InjParams_t *injParamsOut, SkyPosition skypos, AmplitudePrior_t AmpPrior, transientWindowRange_t transientInjectRange, const MultiDetectorStateSeries *multiDetStates, BOOLEAN SignalOnly, multiAMBuffer_t *multiAMBuffer, gsl_rng *rng, INT4 lineX, const MultiNoiseWeights *multiNoiseWeights)
Generates a multi-Fstat atoms vector for given parameters, drawing random parameters wherever require...
@ AMP_PRIOR_TYPE_CANONICAL
'canonical' priors: uniform in A^mu up to h_max
@ AMP_PRIOR_TYPE_PHYSICAL
'physical' priors: isotropic pdf{cosi,psi,phi0} AND flat pdf(h0)
void XLALDestroyExpLUT(void)
Destructor function for expLUT_t lookup table.
int write_MultiFstatAtoms_to_fp(LALFILE *fp, const MultiFstatAtomVector *multiAtoms)
Write multi-IFO F-stat atoms 'multiAtoms' into output stream 'fstat'.
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK_NULL(assertion,...)
Signal (amplitude) parameter ranges.
pdf1D_t * pdf_h0Nat
pdf for h0/sqrt{Sn}
REAL8 fixedSNR
alternative 1: adjust h0 to fix the optimal SNR of the signal
BOOLEAN fixRhohMax
alternative 2: draw h0 with fixed rhohMax = h0Max * (detM)^(1/8) <==> canonical Fstat prior
pdf1D_t * pdf_phi0
pdf(phi0)
pdf1D_t * pdf_cosi
pdf(cosi)
pdf1D_t * pdf_psi
pdf(psi)
Type containing multi- and single-detector -statistics and line-robust statistic.
UINT4 numDetectors
number of detectors, numDetectors=0 should make all code ignore the TwoFX field.
REAL4 TwoF
multi-detector -statistic value
REAL4 log10BSGL
line-robust statistic
Configuration settings required for and defining a coherent pulsar search.
REAL4 * oLGX
per-detector line prior odds
gsl_rng * rng
gsl random-number generator
AmplitudePrior_t AmpPrior
amplitude-parameter priors to draw signals from
SkyPosition skypos
(Alpha,Delta,system).
CHAR * logString
logstring for file-output, containing cmdline-options + code VCS version info
BOOLEAN SignalOnly
dont generate noise-draws: will result in non-random 'signal only' values of F and B
MultiDetectorStateSeries * multiDetStates
multi-detector state series covering observation time
transientWindowRange_t transientSearchRange
transient-window range for the search (flat priors)
MultiNoiseWeights * multiNoiseWeights
per-detector noise weights SX^-1/S^-1, no per-SFT variation (can be NULL for unit weights)
transientWindowRange_t transientInjectRange
transient-window range for injections (flat priors)
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
Hold all (generally) randomly drawn injection parameters: skypos, amplitude-params,...
Multi-IFO time-series of DetectorStates.
A multi-detector vector of FstatAtomVector.
array of detectors definitions 'LALDetector'
A collection of (multi-IFO) LIGOTimeGPSVector time-stamps vectors.
array of detector-specific 'noise floors' (ie PSD values), assumed constant over the frequency-band o...
REAL8 sqrtSn[PULSAR_MAX_DETECTORS]
per-IFO sqrt(PSD) values , where
UINT4 length
number of detectors
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
REAL8 Sinv_Tsft
normalization factor used: (using single-sided PSD!)
UINT4 length
number of detectors
REAL8Vector ** data
weights-vector for each detector
struct for buffering of AM-coeffs, if signal for same sky-position is injected
Struct defining a range of transient windows.
transientWindowType_t type
window-type: none, rectangular, exponential, ....
int main(int argc, char *argv[])
MAIN function Generates samples of B-stat and F-stat according to their pdfs for given signal-params.
int XLALInitCode(ConfigVariables *cfg, const UserInput_t *uvar)
Initialize Fstat-code: handle user-input and set everything up.
int XLALInitAmplitudePrior(AmplitudePrior_t *AmpPrior, const UserInput_t *uvar)
Initialize amplitude-prior pdfs from the user-input.
int vrbflg
defined in lal/lib/std/LALError.c
int write_BSGL_candidate_to_fp(FILE *fp, const BSGLComponents *stats, const LALStringVector *IFOs, const InjParams_t *injParams, const BOOLEAN haveBSGL)
Write one line for given BSGL candidate into output file.
MultiNoiseWeights * XLALComputeConstantMultiNoiseWeightsFromNoiseFloor(const MultiNoiseFloor *multiNoiseFloor, const MultiLIGOTimeGPSVector *multiTS, const UINT4 Tsft)
int XLALInitUserVars(UserInput_t *uvar)
Register all our "user-variables" that can be specified from cmd-line and/or config-file.