Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
PredictFstat.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Maximillian Bensch, Reinhard Prix
3 * Copyright (C) 2006 Iraj Gholami, Reinhard Prix
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with with program; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301 USA
19 */
20
21/*********************************************************************************/
22/**
23 * \author I. Gholami, R. Prix
24 * \file
25 * \ingroup lalpulsar_bin_Fstatistic
26 * \brief
27 * Calculate the *expected* (multi-IFO) F-statistic for pulsar GW signals, without actually
28 * performing a search. The "F-statistic" was introduced in \cite JKS98 and Cutler-Schutz 2005.
29 * Contrary to SemiAnalyticF this code can use (multi-IFO) SFTs to specify the startTime,
30 * duration, detectors and noise-floors to use in the estimation.
31 *
32 */
33#include "config.h"
34
35#include <stdio.h>
36
37#include <lal/LALString.h>
38#include <lal/AVFactories.h>
39#include <lal/LALInitBarycenter.h>
40#include <lal/UserInput.h>
41#include <lal/SFTfileIO.h>
42#include <lal/ExtrapolatePulsarSpins.h>
43#include <lal/NormalizeSFTRngMed.h>
44#include <lal/ComputeFstat.h>
45#include <lal/LALHough.h>
46#include <lal/LogPrintf.h>
47#include <lal/FstatisticTools.h>
48#include <lal/TransientCW_utils.h>
49#include <lal/LALPulsarVCSInfo.h>
50
51/* local includes */
52
53/*---------- DEFINES ----------*/
54#define SQ(x) ((x)*(x))
55
56/**
57 * Configuration settings required for and defining a coherent pulsar search.
58 * These are 'pre-processed' settings, which have been derived from the user-input.
59 */
60typedef struct {
61 CHAR *dataSummary; /**< descriptive string describing the data */
62 PulsarAmplitudeParams pap; /**< PulsarAmplitudeParameter {h0, cosi, psi, phi0} */
63 AntennaPatternMatrix Mmunu; /**< antenna-pattern matrix and normalization */
64 UINT4 numSFTs; /**< number of SFTs = Tobs/Tsft */
66
67/*---------- Global variables ----------*/
68extern int vrbflg; /**< defined in lal/lib/std/LALError.c */
69
70ConfigVariables GV; /**< global container for various derived configuration settings */
71
72/* ----- User-variables: can be set from config-file or command-line */
73typedef struct {
74 INT4 RngMedWindow; /**< running-median window to use for noise-floor estimation */
75
76 REAL8 aPlus; /**< '+' polarization amplitude: aPlus [alternative to {h0, cosi}: aPlus = 0.5*h0*(1+cosi^2)] */
77 REAL8 aCross; /**< 'x' polarization amplitude: aCross [alternative to {h0, cosi}: aCross= h0 * cosi] */
78 REAL8 h0; /**< overall GW amplitude h0 [alternative to {aPlus, aCross}] */
79 REAL8 cosi; /**< cos(inclination angle) [alternative to {aPlus, aCross}] */
80 REAL8 psi; /**< polarization angle psi */
81 REAL8 phi0; /**< initial GW phase phi_0 in radians */
82 REAL8 Freq; /**< GW signal frequency */
83 REAL8 Alpha; /**< sky-position angle 'alpha', which is right ascencion in equatorial coordinates */
84 REAL8 Delta; /**< sky-position angle 'delta', which is declination in equatorial coordinates */
85
86 BOOLEAN PureSignal; /**< If true, calculate 2F for pure signal, i.e. E[2F] = 2F = rho^2 */
87 LALStringVector *assumeSqrtSX;/**< Assume stationary Gaussian noise with detector noise-floors sqrt{SX}" */
88
89 CHAR *ephemEarth; /**< Earth ephemeris file to use */
90 CHAR *ephemSun; /**< Sun ephemeris file to use */
91
92 CHAR *DataFiles; /**< SFT input-files to use to determine startTime, duration, IFOs and for noise-floor estimation */
93 CHAR *outputFstat; /**< output file to write F-stat estimation results into */
94 BOOLEAN printFstat; /**< print F-stat estimation results to terminal? */
95 LIGOTimeGPS minStartTime; /**< SFT timestamps (from DataFiles or generated internally) must be >= this GPS timestamp */
96 LIGOTimeGPS maxStartTime; /**< SFT timestamps (from DataFiles) must be < this GPS timestamp */
97 REAL8 duration; /**< SFT timestamps (generated internally) will be < minStartTime+duration */
98
99 LALStringVector *timestampsFiles; /**< Names of timestamps files, one per detector */
100 LALStringVector *IFOs; /**< list of detector-names "H1,H2,L1,.." */
101 REAL8 Tsft; /**< SFT time baseline Tsft */
102
103 CHAR *transientWindowType; /**< name of transient window ('rect', 'exp',...) */
104 LIGOTimeGPS transientStartTime; /**< GPS start-time of transient window */
105 REAL8 transientTau; /**< time-scale in seconds of transient window */
106 REAL8 transientTauDays; /**< DEFUNCT */
107
108
109 BOOLEAN SignalOnly; /**< DEFUNCT: use --assumeSqrtSX */
111
112/* ---------- local prototypes ---------- */
113int main( int argc, char *argv[] );
114
115int initUserVars( UserInput_t *uvar );
116int InitPFS( ConfigVariables *cfg, UserInput_t *uvar );
117
118/*---------- empty initializers ---------- */
119
120/*----------------------------------------------------------------------*/
121/* Main Function starts here */
122/*----------------------------------------------------------------------*/
123/**
124 * MAIN function of PredictFstat code.
125 * Calculates the F-statistic for a given position in the sky and detector
126 * semi-analytically and outputs the final 2F value.
127 */
128int main( int argc, char *argv[] )
129{
130 REAL8 rho2; /* SNR^2 */
131
133 CHAR *VCSInfoString; /* Git version string */
134
135 vrbflg = 1; /* verbose error-messages */
136
137 /* set LAL error-handler */
139
140 /* register all user-variable */
142
143 /* do ALL cmdline and cfgfile handling */
144 BOOLEAN should_exit = 0;
146 if ( should_exit ) {
147 exit( 1 );
148 }
149
150 XLAL_CHECK_MAIN( ( VCSInfoString = XLALVCSInfoString( lalPulsarVCSInfoList, 0, "%% " ) ) != NULL, XLAL_EFUNC );
151
152 /* Initialize code-setup */
154
157
158 /* F-statistic expected mean and standard deviation */
159 const REAL8 twoF_expected = uvar.PureSignal ? ( rho2 ) : ( 4.0 + rho2 );
160 const REAL8 twoF_sigma = uvar.PureSignal ? ( 0 ) : ( sqrt( 8.0 + 4.0 * rho2 ) );
161
162 /* output predicted Fstat-value, if requested */
163 if ( uvar.printFstat ) {
164 fprintf( stdout, "\n%.1f\n", twoF_expected );
165 }
166
167 /* output predicted Fstat-value into file, if requested */
168 if ( uvar.outputFstat ) {
169 FILE *fpFstat = NULL;
170 CHAR *logstr = NULL;
171
172 XLAL_CHECK_MAIN( ( fpFstat = fopen( uvar.outputFstat, "wb" ) ) != NULL, XLAL_ESYS, "\nError opening file '%s' for writing..\n\n", uvar.outputFstat );
173
174 /* log search-footprint at head of output-file */
176
177 fprintf( fpFstat, "%%%% cmdline: %s\n", logstr );
178 XLALFree( logstr );
179
180 fprintf( fpFstat, "%s\n", VCSInfoString );
181
182 /* append 'dataSummary' */
183 fprintf( fpFstat, "%s", GV.dataSummary );
184 /* output E[2F] and std[2F] */
185 fprintf( fpFstat, "twoF_expected = %g;\n", twoF_expected );
186 fprintf( fpFstat, "twoF_sigma = %g;\n", twoF_sigma );
187
188 /* output antenna-pattern matrix MNat_mu_nu = matrix(A, B, C) */
189 {
190 /* compute A = <a^2>, B=<b^2>, C=<ab> from the 'discretized versions Ad, Bc, Cd */
191 REAL8 A = GV.Mmunu.Ad / GV.numSFTs;
192 REAL8 B = GV.Mmunu.Bd / GV.numSFTs;
193 REAL8 C = GV.Mmunu.Cd / GV.numSFTs;
194 REAL8 D = A * B - C * C;
195 fprintf( fpFstat, "A = %f;\n", A );
196 fprintf( fpFstat, "B = %f;\n", B );
197 fprintf( fpFstat, "C = %f;\n", C );
198 fprintf( fpFstat, "D = %f;\n", D );
199 }
200 fclose( fpFstat );
201 } /* if outputFstat */
202
203 /* Free config-Variables and userInput stuff */
206 XLALFree( VCSInfoString );
207
208 /* did we forget anything ? */
210
211 return 0;
212
213} /* main() */
214
215/**
216 * Register all our "user-variables" that can be specified from cmd-line and/or config-file.
217 * Here we set defaults for some user-variables and register them with the UserInput module.
218 */
219int
221{
222 XLAL_CHECK( uvar != NULL, XLAL_EINVAL );
223
224 /* set a few defaults */
226
227 uvar->ephemEarth = XLALStringDuplicate( "earth00-40-DE405.dat.gz" );
228 uvar->ephemSun = XLALStringDuplicate( "sun00-40-DE405.dat.gz" );
229
230 uvar->outputFstat = NULL;
231 uvar->printFstat = 1;
232
233 uvar->minStartTime.gpsSeconds = 0;
234 uvar->maxStartTime.gpsSeconds = LAL_INT4_MAX;
235 uvar->duration = 0;
236
237 uvar->PureSignal = 0;
238
239 uvar->assumeSqrtSX = NULL;
240
241 uvar->phi0 = 0;
242 uvar->transientWindowType = XLALStringDuplicate( "none" );
243
244 uvar->Tsft = 1800;
245
246 /* register all our user-variables */
247 lalUserVarHelpOptionSubsection = "Output control";
248 XLALRegisterUvarMember( outputFstat, STRING, 0, NODEFAULT, "Output-file (octave/matlab) for predicted F-stat value, variance and antenna-patterns" );
249 XLALRegisterUvarMember( printFstat, BOOLEAN, 0, OPTIONAL, "Print predicted F-stat value to terminal" );
250 XLALRegisterUvarMember( PureSignal, BOOLEAN, 'P', OPTIONAL, "If true return 2F=SNR^2 ('pure signal without noise'). Otherwise return E[2F] = 4 + SNR^2." );
251
252 lalUserVarHelpOptionSubsection = "Signal parameters";
253 XLALRegisterUvarMember( h0, REAL8, 's', NODEFAULT, "Overall GW amplitude h0 (required if " UVAR_STR( cosi ) " used, alternatively use " UVAR_STR2AND( aPlus, aCross ) ")." );
254 XLALRegisterUvarMember( cosi, REAL8, 'i', NODEFAULT, "Inclination angle of rotation axis cos(iota) (required if " UVAR_STR( h0 ) " used, alternatively use " UVAR_STR2AND( aPlus, aCross ) ")." );
255 XLALRegisterUvarMember( aPlus, REAL8, 0, NODEFAULT, "'Plus' polarization amplitude A_+ (required if " UVAR_STR( aCross ) " used, alternative to " UVAR_STR2AND( h0, cosi ) ")." );
256 XLALRegisterUvarMember( aCross, REAL8, 0, NODEFAULT, "'Cross' polarization amplitude: A_x (required if " UVAR_STR( aPlus ) " used, alternative to " UVAR_STR2AND( h0, cosi ) ")." );
257
258 XLALRegisterUvarMember( psi, REAL8, 0, OPTIONAL, "Polarisation angle in radians (required if " UVAR_STR4OR( h0, cosi, aPlus, aCross ) " used)" );
259 XLALRegisterUvarMember( phi0, REAL8, 0, OPTIONAL, "Initial GW phase phi0 in radians" );
260
261 XLALRegisterUvarMember( Alpha, RAJ, 'a', OPTIONAL, "Sky position: equatorial J2000 right ascension (required if " UVAR_STR4OR( h0, cosi, aPlus, aCross ) " used)" );
262 XLALRegisterUvarMember( Delta, DECJ, 'd', OPTIONAL, "Sky position: equatorial J2000 right declination (required if " UVAR_STR4OR( h0, cosi, aPlus, aCross ) " used)" );
263
264 lalUserVarHelpOptionSubsection = "Data and noise properties";
265 XLALRegisterUvarMember( DataFiles, STRING, 'D', NODEFAULT, "Per-detector SFTs (for detectors, timestamps and noise-estimate). Possibilities are:\n"
266 " - '<SFT file>;<SFT file>;...', where <SFT file> may contain wildcards\n - 'list:<file containing list of SFT files>'\n"
267 "(Alternatives: " UVAR_STR2AND( assumeSqrtSX, IFOs )" and one of "UVAR_STR( timestampsFiles )" or "UVAR_STR2AND( minStartTime, duration )")." );
268 XLALRegisterUvarMember( Freq, REAL8, 'F', NODEFAULT, "Frequency for noise-floor estimation (required if not given " UVAR_STR( assumeSqrtSX ) ")." );
269 XLALRegisterUvarMember( RngMedWindow, INT4, 'k', OPTIONAL, "Running median size for noise-floor estimation (only used if not given " UVAR_STR( assumeSqrtSX ) ")." );
270
271 XLALRegisterUvarMember( assumeSqrtSX, STRINGVector, 0, OPTIONAL, "Assume stationary per-detector noise-floor sqrt(S[X]) instead of estimating "
272 "(required if not given " UVAR_STR( DataFiles )")." );
273
274 XLALRegisterUvarMember( IFOs, STRINGVector, 0, NODEFAULT, "CSV list of detectors, eg. \"H1,L1,...\" (required if not given " UVAR_STR( DataFiles )")." );
275 XLALRegisterUvarMember( timestampsFiles, STRINGVector, 0, NODEFAULT, "CSV list of SFT timestamps files, one per detector (conflicts with " UVAR_STR( DataFiles ) ")." );
276 XLALRegisterUvarMember( minStartTime, EPOCH, 0, OPTIONAL, "SFT timestamps must be >= this GPS timestamp." );
277 XLALRegisterUvarMember( maxStartTime, EPOCH, 0, OPTIONAL, "SFT timestamps must be < this GPS timestamp (only valid with " UVAR_STR( DataFiles ) ")." );
278 XLALRegisterUvarMember( duration, REAL8, 0, OPTIONAL, "SFT timestamps will be < " UVAR_STR( minStartTime ) "+" UVAR_STR( duration ) " (only valid without " UVAR_STR( DataFiles ) ")." );
279
280 XLALRegisterUvarMember( Tsft, REAL8, 0, OPTIONAL, "Time baseline of SFTs in seconds (conflicts with " UVAR_STR( DataFiles ) ")." );
281
282 lalUserVarHelpOptionSubsection = "Transient signal properties";
283 XLALRegisterUvarMember( transientWindowType, STRING, 0, OPTIONAL, "Transient-signal window function to assume. ('none', 'rect', 'exp')." );
284 XLALRegisterUvarMember( transientStartTime, EPOCH, 0, NODEFAULT, "GPS start-time 't0' of transient signal window." );
285 XLALRegisterUvarMember( transientTau, REAL8, 0, NODEFAULT, "Timescale 'tau' of transient signal window in seconds." );
286
287 // ---------- developer options ----------
289 XLALRegisterUvarMember( ephemEarth, STRING, 0, DEVELOPER, "Earth ephemeris file to use" );
290 XLALRegisterUvarMember( ephemSun, STRING, 0, DEVELOPER, "Sun ephemeris file to use" );
291
292 // ---------- deprecated options ---------
293
294 // ---------- defunct options ---------
295 XLALRegisterUvarMember( transientTauDays, REAL8, 0, DEFUNCT, "use " UVAR_STR( transientTau ) " instead." );
296 XLALRegisterUvarMember( SignalOnly, BOOLEAN, 'S', DEFUNCT, "use --assumeSqrtSX instead" );
297
298 return XLAL_SUCCESS;
299
300} /* initUserVars() */
301
302/** Initialized Fstat-code: handle user-input and set everything up. */
303int
305{
306 XLAL_CHECK( ( cfg != NULL ) && ( uvar != NULL ), XLAL_EINVAL );
307
308 SFTCatalog *catalog = NULL;
309 SkyPosition skypos;
310
311 EphemerisData *edat = NULL; /* ephemeris data */
312 MultiAMCoeffs *multiAMcoef = NULL;
313 MultiDetectorStateSeries *multiDetStates = NULL; /* pos, vel and LMSTs for detector at times t_i */
314
315 { /* Check user-input consistency */
316 BOOLEAN have_h0 = XLALUserVarWasSet( &uvar->h0 );
317 BOOLEAN have_cosi = XLALUserVarWasSet( &uvar->cosi );
318 BOOLEAN have_Ap = XLALUserVarWasSet( &uvar->aPlus );
319 BOOLEAN have_Ac = XLALUserVarWasSet( &uvar->aCross );
320 BOOLEAN have_psi = XLALUserVarWasSet( &uvar->psi );
321 BOOLEAN have_Alpha = XLALUserVarWasSet( &uvar->Alpha );
322 BOOLEAN have_Delta = XLALUserVarWasSet( &uvar->Delta );
323
324 /* ----- handle {h0,cosi} || {aPlus,aCross} freedom ----- */
325 XLAL_CHECK( ( ( have_h0 && !have_cosi ) || ( !have_h0 && have_cosi ) ) == 0, XLAL_EINVAL, "Need both (h0, cosi) to specify signal!\n" );
326 XLAL_CHECK( ( ( have_Ap && !have_Ac ) || ( !have_Ap && have_Ac ) ) == 0, XLAL_EINVAL, "Need both (aPlus, aCross) to specify signal!\n" );
327 XLAL_CHECK( ( have_h0 && have_Ap ) == 0, XLAL_EINVAL, "Overdetermined: specify EITHER (h0,cosi) OR (aPlus,aCross)!\n" );
328 XLAL_CHECK( ( ( have_h0 || have_Ap ) && !( have_psi && have_Alpha && have_Delta ) ) == 0, XLAL_EINVAL, "If " UVAR_STR4OR( h0, cosi, aPlus, aCross ) ", also need a full set of " UVAR_STR3AND( psi, Alpha, Delta ) "." );
329 /* ----- internally we always use h0, cosi */
330 if ( have_h0 ) {
331 cfg->pap.aPlus = 0.5 * uvar->h0 * ( 1.0 + SQ( uvar->cosi ) );
332 cfg->pap.aCross = uvar->h0 * uvar->cosi;
333 } else {
334 cfg->pap.aPlus = uvar->aPlus;
335 cfg->pap.aCross = uvar->aCross;
336 }
337 cfg->pap.psi = uvar->psi;
338 cfg->pap.phi0 = uvar->phi0;
339 }/* check user-input */
340
341 // ----- the following quantities need to specified via the given user inputs
342 REAL8 Tsft;
344
346 MultiLIGOTimeGPSVector *mTS = NULL;
347 MultiNoiseWeights *multiNoiseWeights = NULL;
348
349 // ----- IFOs : only from one of {--IFOs, --DataFiles }: mutually exclusive
350 BOOLEAN have_IFOs = UVAR_SET( IFOs );
351 BOOLEAN have_SFTs = UVAR_SET( DataFiles );
352 BOOLEAN have_Tsft = UVAR_SET( Tsft );
353 XLAL_CHECK( ( have_IFOs || have_SFTs ) && !( have_IFOs && have_SFTs ), XLAL_EINVAL, "Need exactly one of " UVAR_STR2OR( IFOs, DataFiles ) " to determine detectors\n" );
354 XLAL_CHECK( !( have_SFTs && have_Tsft ), XLAL_EINVAL, UVAR_STR( Tsft ) " cannot be specified with " UVAR_STR( DataFiles ) "." );
355
356 // ----- get timestamps from EITHER one of --timestampsFiles, (--minStartTime,--duration) or --SFTs
357 BOOLEAN have_timeSpan = UVAR_SET2( minStartTime, duration );
358 BOOLEAN have_maxStartTime = UVAR_SET( maxStartTime );
359 BOOLEAN have_duration = UVAR_SET( duration );
360 BOOLEAN have_timestamps = UVAR_SET( timestampsFiles );
361 // at least one of {timestamps,minStartTime+duration,SFTs} required
362 XLAL_CHECK( have_timestamps || have_timeSpan == 2 || have_SFTs, XLAL_EINVAL,
363 "Need at least one of {" UVAR_STR( timestampsFiles )", "UVAR_STR2AND( minStartTime, duration )", or "UVAR_STR( DataFiles )"}." );
364 // don't allow timestamps AND SFTs
365 XLAL_CHECK( !( have_timestamps && have_SFTs ), XLAL_EINVAL, UVAR_STR( timestampsFiles ) " is incompatible with " UVAR_STR( DataFiles ) "." );
366 // don't allow maxStartTime WITHOUT SFTs because the old behaviour in that case
367 // was inconsistent and we now require duration instead to avoid ambiguity
368 XLAL_CHECK( !( have_maxStartTime && !have_SFTs ), XLAL_EINVAL, "Using " UVAR_STR( maxStartTime ) " is incompatible with NOT providing " UVAR_STR( DataFiles ) ", please use " UVAR_STR2AND( minStartTime, duration ) " instead." );
369 // don't allow duration AND SFTs either
370 XLAL_CHECK( !( have_duration && have_SFTs ), XLAL_EINVAL, "Using " UVAR_STR( duration ) " is incompatible with " UVAR_STR( DataFiles ) "; if you want to set constraints on the loaded SFTs, please use " UVAR_STR( maxStartTime ) " instead." );
371
372 // if we don't have SFTs, then we need assumeSqrtSX
373 BOOLEAN have_assumeSqrtSX = UVAR_SET( assumeSqrtSX );
374 BOOLEAN have_Freq = UVAR_SET( Freq );
375 XLAL_CHECK( have_SFTs || have_assumeSqrtSX, XLAL_EINVAL, "Need at least one of " UVAR_STR2OR( assumeSqrtSX, DataFiles ) " for noise-floor." );
376 // need --Freq for noise-floor estimation if we don't have --assumeSqrtSX
377 XLAL_CHECK( have_assumeSqrtSX || have_Freq, XLAL_EINVAL, "Need at least one of " UVAR_STR2OR( assumeSqrtSX, Freq ) " for noise-floor." );
378
379 // ----- compute or estimate multiTimestamps ----------
380 if ( have_SFTs ) {
381 SFTConstraints XLAL_INIT_DECL( constraints );
382 MultiSFTCatalogView *multiCatalogView = NULL;
383 /* ----- prepare SFT-reading ----- */
384 constraints.minStartTime = &uvar->minStartTime;
385 constraints.maxStartTime = &uvar->maxStartTime;
386
387 /* ----- get full SFT-catalog of all matching (multi-IFO) SFTs */
388 XLALPrintInfo( "Finding all SFTs to load ... " );
389 XLAL_CHECK( ( catalog = XLALSFTdataFind( uvar->DataFiles, &constraints ) ) != NULL, XLAL_EFUNC );
390 XLALPrintInfo( "done. (found %d SFTs)\n", catalog->length );
391 XLAL_CHECK( catalog->length > 0, XLAL_EINVAL, "No matching SFTs for pattern '%s' and GPS constraints [%d,%d)!\n", uvar->DataFiles, uvar->minStartTime.gpsSeconds, uvar->maxStartTime.gpsSeconds );
392
393 /* ----- deduce start- and end-time of the observation spanned by the data */
394 Tsft = 1.0 / catalog->data[0].header.deltaF;
395
396 XLAL_CHECK( ( multiCatalogView = XLALGetMultiSFTCatalogView( catalog ) ) != NULL, XLAL_EFUNC );
397
398 numDetectors = multiCatalogView->length;
399 // ----- get the (multi-IFO) 'detector-state series' for given catalog
400 XLAL_CHECK( ( mTS = XLALTimestampsFromMultiSFTCatalogView( multiCatalogView ) ) != NULL, XLAL_EFUNC );
401 XLAL_CHECK( mTS->length == numDetectors, XLAL_EINVAL, "Got %d detectors but %d sets of timestamps.", numDetectors, mTS->length );
403
404 // ----- estimate noise-floor from SFTs if --assumeSqrtSX was not given:
405 if ( !have_assumeSqrtSX ) {
406 UINT4 wings = uvar->RngMedWindow / 2 + 10; /* extra frequency-bins needed for rngmed */
407 REAL8 fMax = uvar->Freq + 1.0 * wings / Tsft;
408 REAL8 fMin = uvar->Freq - 1.0 * wings / Tsft;
409
411 XLAL_CHECK( ( multiSFTs = XLALLoadMultiSFTsFromView( multiCatalogView, fMin, fMax ) ) != NULL, XLAL_EFUNC );
412
413 MultiPSDVector *multiRngmed = NULL;
414 XLAL_CHECK( ( multiRngmed = XLALNormalizeMultiSFTVect( multiSFTs, uvar->RngMedWindow, NULL ) ) != NULL, XLAL_EFUNC );
416
417 XLAL_CHECK( ( multiNoiseWeights = XLALComputeMultiNoiseWeights( multiRngmed, uvar->RngMedWindow, 0 ) ) != NULL, XLAL_EFUNC );
418 XLALDestroyMultiPSDVector( multiRngmed );
419 }
420
421 XLALDestroyMultiSFTCatalogView( multiCatalogView );
422 XLALDestroySFTCatalog( catalog );
423
424 } // if have_SFTs
425 else {
426 XLAL_CHECK( XLALParseMultiLALDetector( &multiIFO, uvar->IFOs ) == XLAL_SUCCESS, XLAL_EFUNC );
427 numDetectors = multiIFO.length;
428 Tsft = uvar->Tsft;
429
430 if ( have_timestamps ) {
431 LIGOTimeGPS *endTimeGPS = NULL;
432 if ( have_duration ) {
433 LIGOTimeGPS tempGPS = uvar->minStartTime;
434 XLALGPSAdd( &tempGPS, uvar->duration );
435 endTimeGPS = &tempGPS;
436 }
437 XLAL_CHECK( ( mTS = XLALReadMultiTimestampsFilesConstrained( uvar->timestampsFiles, &( uvar->minStartTime ), endTimeGPS ) ) != NULL, XLAL_EFUNC );
438 XLAL_CHECK( ( mTS->length > 0 ) && ( mTS->data != NULL ), XLAL_EINVAL, "Got empty timestamps-list from XLALReadMultiTimestampsFiles()\n" );
439 XLAL_CHECK( mTS->length == numDetectors, XLAL_EINVAL, "Got %d detectors but %d sets of timestamps.", numDetectors, mTS->length );
440 for ( UINT4 X = 0; X < mTS->length; X ++ ) {
441 mTS->data[X]->deltaT = Tsft; // Tsft information not given by timestamps-file
442 }
443 } // if have_timestamps
444 else if ( have_timeSpan == 2 ) { // if timespan only
445 XLAL_CHECK( ( mTS = XLALMakeMultiTimestamps( uvar->minStartTime, uvar->duration, Tsft, 0, numDetectors ) ) != NULL, XLAL_EFUNC );
446 } // have_timeSpan
447 else {
448 XLAL_ERROR( XLAL_EINVAL, "Something has gone wrong: couldn't deduce timestamps" );
449 }
450 } // if !have_SFTs
451
452 // ---------- determine start-time and total amount of data
454 cfg->numSFTs = 0;
455 for ( UINT4 X = 0; X < numDetectors; X ++ ) {
456 if ( XLALGPSCmp( &( mTS->data[X]->data[0] ), &startTime ) < 0 ) {
457 startTime = mTS->data[X]->data[0];
458 }
459 GV.numSFTs += mTS->data[X]->length;
460 }
462
463 // ---------- compute noise-weights from --assumeSqrtSX instead of from SFTs
464 if ( have_assumeSqrtSX ) {
465 MultiNoiseFloor XLAL_INIT_DECL( assumeSqrtSX );
466 XLAL_CHECK( XLALParseMultiNoiseFloor( &assumeSqrtSX, uvar->assumeSqrtSX, numDetectors ) == XLAL_SUCCESS, XLAL_EFUNC );
467 // no need to check assumeSqrtSX.length - XLALParseMultiNoiseFloor() does it internally
468 for ( UINT4 X = 0; X < numDetectors; X ++ ) {
469 XLAL_CHECK( assumeSqrtSX.sqrtSn[X] > 0, XLAL_EDOM, "all entries of assumeSqrtSX must be >0" );
470 }
471
472 XLAL_CHECK( ( multiNoiseWeights = XLALCalloc( 1, sizeof( *multiNoiseWeights ) ) ) != NULL, XLAL_ENOMEM );
473 XLAL_CHECK( ( multiNoiseWeights->data = XLALCalloc( numDetectors, sizeof( *multiNoiseWeights->data ) ) ) != NULL, XLAL_ENOMEM );
474 multiNoiseWeights->length = numDetectors;
475
476 REAL8 Sinv = 0;
477 for ( UINT4 X = 0; X < numDetectors; X ++ ) {
478 UINT4 numSFTsX = mTS->data[X]->length;
479 XLAL_CHECK( ( multiNoiseWeights->data[X] = XLALCreateREAL8Vector( numSFTsX ) ) != NULL, XLAL_EFUNC );
480
481 REAL8 SXinv = 1.0 / ( SQ( assumeSqrtSX.sqrtSn[X] ) );
482 Sinv += numSFTsX * SXinv;
483 for ( UINT4 j = 0; j < numSFTsX; j ++ ) {
484 multiNoiseWeights->data[X]->data[j] = SXinv;
485 } // for j < numSFTsX
486 } // for X < numDetectors
487
488 // ----- now properly normalize this
489 Sinv /= 1.0 * GV.numSFTs;
490 for ( UINT4 X = 0; X < numDetectors; X ++ ) {
491 UINT4 numSFTsX = mTS->data[X]->length;
492 for ( UINT4 j = 0; j < numSFTsX; j ++ ) {
493 multiNoiseWeights->data[X]->data[j] /= Sinv;
494 } // for j < numSFTsX
495 } // for X < numDetectors
496
497 multiNoiseWeights->Sinv_Tsft = Sinv * Tsft;
498
499 } // if --assumeSqrtSX given
500
501 /* ----- load ephemeris-data ----- */
502 XLAL_CHECK( ( edat = XLALInitBarycenter( uvar->ephemEarth, uvar->ephemSun ) ) != NULL, XLAL_EFUNC );
503
504 // ----- get multiDetectorStates ----------
505 REAL8 tOffset = 0.5 * Tsft;
506 XLAL_CHECK( ( multiDetStates = XLALGetMultiDetectorStates( mTS, &multiIFO, edat, tOffset ) ) != NULL, XLAL_EFUNC );
507
508 /* ----- handle transient-signal window if given ----- */
509 if ( XLALUserVarWasSet( &uvar->transientWindowType ) && strcmp( uvar->transientWindowType, "none" ) ) {
510 transientWindow_t transientWindow; /**< properties of transient-signal window */
511
512 int twtype;
513 XLAL_CHECK( ( twtype = XLALParseTransientWindowName( uvar->transientWindowType ) ) >= 0, XLAL_EFUNC );
514 transientWindow.type = twtype;
515
516 if ( XLALUserVarWasSet( &uvar->transientStartTime ) ) {
517 transientWindow.t0 = uvar->transientStartTime.gpsSeconds; // dropping ns part
518 } else {
519 XLAL_ERROR( XLAL_EINVAL, "Required input " UVAR_STR( transientStartTime ) " missing for transient window type '%s'", uvar->transientWindowType );
520 }
521
522 if ( XLALUserVarWasSet( &uvar->transientTau ) ) {
523 transientWindow.tau = uvar->transientTau;
524 } else {
525 XLAL_ERROR( XLAL_EINVAL, "Required input " UVAR_STR( transientStartTime ) " missing for transient window type '%s'", uvar->transientWindowType );
526 }
527
528 XLAL_CHECK( XLALApplyTransientWindow2NoiseWeights( multiNoiseWeights, mTS, transientWindow ) == XLAL_SUCCESS, XLAL_EFUNC );
529
530 } /* apply transient window to noise-weights */
531
532 // ----- compute antenna-pattern matrix M_munu ----------
533 skypos.longitude = uvar->Alpha;
534 skypos.latitude = uvar->Delta;
536 XLALNormalizeSkyPosition( &skypos.longitude, &skypos.latitude );
537
538 XLAL_CHECK( ( multiAMcoef = XLALComputeMultiAMCoeffs( multiDetStates, multiNoiseWeights, skypos ) ) != NULL, XLAL_EFUNC );
539
540 cfg->Mmunu = multiAMcoef->Mmunu;
541 XLALDestroyMultiAMCoeffs( multiAMcoef );
542
543 /* ----- produce a log-string describing the data-specific setup ----- */
544 {
545 struct tm utc;
546 time_t tp;
547 CHAR dateStr[512], line[1024], summary[2048];
548 tp = time( NULL );
549 sprintf( summary, "%%%% Date: %s", asctime( gmtime( &tp ) ) );
550 strcat( summary, "%% Loaded SFTs: [ " );
551 for ( UINT4 X = 0; X < numDetectors; X ++ ) {
552 sprintf( line, "%s:%d%s", multiIFO.sites[X].frDetector.name, mTS->data[X]->length, ( X < numDetectors - 1 ) ? ", " : " ]\n" );
553 strcat( summary, line );
554 }
555 utc = *XLALGPSToUTC( &utc, ( INT4 )XLALGPSGetREAL8( &startTime ) );
556 strcpy( dateStr, asctime( &utc ) );
557 dateStr[ strlen( dateStr ) - 1 ] = 0;
558 snprintf( line, sizeof( line ), "%%%% Start GPS time tStart = %12.3f (%s GMT)\n", XLALGPSGetREAL8( &startTime ), dateStr );
559 strcat( summary, line );
560 sprintf( line, "%%%% Total amount of data: Tdata = %12.3f s (%.2f days)\n", Tdata, Tdata / 86400 );
561 strcat( summary, line );
562
563 XLAL_CHECK( ( cfg->dataSummary = LALCalloc( 1, strlen( summary ) + 1 ) ) != NULL, XLAL_ENOMEM );
564 strcpy( cfg->dataSummary, summary );
565
567 } /* write dataSummary string */
568
569 /* free everything not needed any more */
571 XLALDestroyMultiNoiseWeights( multiNoiseWeights );
572 XLALDestroyMultiDetectorStateSeries( multiDetStates );
573
574 /* Free ephemeris data */
576
577 return XLAL_SUCCESS;
578
579} /* InitPFS() */
#define LAL_INT4_MAX
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
int j
void LALCheckMemoryLeaks(void)
#define LALCalloc(m, n)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
#define D(j)
int main(int argc, char *argv[])
MAIN function of PredictFstat code.
Definition: PredictFstat.c:128
ConfigVariables GV
global container for various derived configuration settings
Definition: PredictFstat.c:70
int initUserVars(UserInput_t *uvar)
Register all our "user-variables" that can be specified from cmd-line and/or config-file.
Definition: PredictFstat.c:220
int InitPFS(ConfigVariables *cfg, UserInput_t *uvar)
Initialized Fstat-code: handle user-input and set everything up.
Definition: PredictFstat.c:304
int vrbflg
defined in lal/lib/std/LALError.c
#define SQ(x)
Definition: PredictFstat.c:54
#define STRING(a)
UINT2 A
Definition: SFTnaming.c:46
UINT2 B
Definition: SFTnaming.c:47
#define fprintf
const double rho2
const FstatOptionalArgs FstatOptionalArgsDefaults
Global initializer for setting FstatOptionalArgs to default values.
Definition: ComputeFstat.c:90
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 XLALMultiLALDetectorFromMultiSFTCatalogView(MultiLALDetector *multiIFO, const MultiSFTCatalogView *multiView)
Extract multi detector-info from a given multi SFTCatalog view.
int XLALParseMultiNoiseFloor(MultiNoiseFloor *multiNoiseFloor, const LALStringVector *sqrtSX, UINT4 numDetectors)
Parse string-vectors (typically input by user) of N detector noise-floors for detectors ,...
REAL8 XLALComputeOptimalSNR2FromMmunu(const PulsarAmplitudeParams pap, const AntennaPatternMatrix Mmunu)
Calculates the 'optimal' / perfect-match squared signal-to-noise ratio (SNR^2) for a CW signal for gi...
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.
Definition: LALComputeAM.c:469
MultiAMCoeffs * XLALComputeMultiAMCoeffs(const MultiDetectorStateSeries *multiDetStates, const MultiNoiseWeights *multiWeights, SkyPosition skypos)
Multi-IFO version of XLALComputeAMCoeffs().
Definition: LALComputeAM.c:379
unsigned char BOOLEAN
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
int32_t INT4
void * XLALCalloc(size_t m, size_t n)
void XLALFree(void *p)
char char * XLALStringDuplicate(const char *s)
char * XLALVCSInfoString(const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
void void LogPrintfVerbatim(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
LOG_DEBUG
MultiPSDVector * XLALNormalizeMultiSFTVect(MultiSFTVector *multsft, UINT4 blockSize, const MultiNoiseFloor *assumeSqrtSX)
Function for normalizing a multi vector of SFTs in a multi IFO search and returns the running-median ...
void XLALDestroyMultiPSDVector(MultiPSDVector *multvect)
Destroy a multi PSD-vector.
Definition: PSDutils.c:102
MultiNoiseWeights * XLALComputeMultiNoiseWeights(const MultiPSDVector *rngmed, UINT4 blocksRngMed, UINT4 excludePercentile)
Computes weight factors arising from MultiSFTs with different noise floors.
Definition: PSDutils.c:285
void XLALDestroyMultiNoiseWeights(MultiNoiseWeights *weights)
Destroy a MultiNoiseWeights object.
Definition: PSDutils.c:172
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
Definition: SFTcatalog.c:329
void XLALDestroyMultiSFTCatalogView(MultiSFTCatalogView *multiView)
Destroys a MultiSFTCatalogView, without freeing the original catalog that the 'view' was referring to...
Definition: SFTcatalog.c:496
void XLALDestroyMultiSFTVector(MultiSFTVector *multvect)
Destroy a multi SFT-vector.
Definition: SFTtypes.c:424
MultiLIGOTimeGPSVector * XLALReadMultiTimestampsFilesConstrained(const LALStringVector *fnames, const LIGOTimeGPS *minGPS, const LIGOTimeGPS *maxGPS)
Load several timestamps files, return a MultiLIGOTimeGPSVector struct, allocated here.
MultiLIGOTimeGPSVector * XLALMakeMultiTimestamps(LIGOTimeGPS tStart, REAL8 Tspan, REAL8 Tsft, REAL8 Toverlap, UINT4 numDet)
Same as XLALMakeTimestamps() just for several detectors, additionally specify the number of detectors...
MultiSFTCatalogView * XLALGetMultiSFTCatalogView(const SFTCatalog *catalog)
Return a MultiSFTCatalogView generated from an input SFTCatalog.
Definition: SFTcatalog.c:380
MultiLIGOTimeGPSVector * XLALTimestampsFromMultiSFTCatalogView(const MultiSFTCatalogView *multiView)
Given a multi-SFTCatalogView, return a MultiLIGOTimeGPSVector holding the SFT timestamps.
MultiSFTVector * XLALLoadMultiSFTsFromView(const MultiSFTCatalogView *multiCatalogView, REAL8 fMin, REAL8 fMax)
This function loads a MultiSFTVector from a given input MultiSFTCatalogView, otherwise the documentat...
Definition: SFTfileIO.c:449
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
Definition: SFTcatalog.c:71
void XLALDestroyMultiTimestamps(MultiLIGOTimeGPSVector *multiTS)
Destroy a MultiLIGOTimeGPSVector timestamps vector.
void XLALNormalizeSkyPosition(double *restrict longitude, double *restrict latitude)
COORDINATESYSTEM_EQUATORIAL
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
const char * lalUserVarHelpOptionSubsection
#define UVAR_STR4OR(n1, n2, n3, n4)
#define UVAR_STR3AND(n1, n2, n3)
#define UVAR_STR2AND(n1, n2)
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define XLALRegisterUvarMember(name, type, option, category,...)
#define UVAR_STR(n)
#define UVAR_STR2OR(n1, n2)
void CHAR * XLALUserVarGetLog(UserVarLogFormat format)
int XLALUserVarWasSet(const void *cvar)
#define UVAR_SET(n)
#define UVAR_SET2(n1, n2)
UVAR_LOGFMT_CMDLINE
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
struct tm * XLALGPSToUTC(struct tm *utc, INT4 gpssec)
#define xlalErrno
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_ERROR(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EDOM
XLAL_ESYS
XLAL_EINVAL
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
size_t numDetectors
Struct holding the "antenna-pattern" matrix , in terms of the multi-detector scalar product.
Definition: LALComputeAM.h:127
Configuration settings required for and defining a coherent pulsar search.
UINT4 numSFTs
number of SFTs = Tobs/Tsft
Definition: PredictFstat.c:64
PulsarAmplitudeParams pap
PulsarAmplitudeParameter {h0, cosi, psi, phi0}.
Definition: PredictFstat.c:62
AntennaPatternMatrix Mmunu
antenna-pattern matrix and normalization
Definition: PredictFstat.c:63
CHAR * dataSummary
descriptive string describing the data
Definition: PredictFstat.c:61
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
UINT4 runningMedianWindow
If SFT noise weights are calculated from the SFTs, the running median window length to use.
Definition: ComputeFstat.h:141
REAL8 deltaT
'length' of each timestamp (e.g.
Definition: SFTfileIO.h:194
LIGOTimeGPS * data
array of timestamps
Definition: SFTfileIO.h:193
UINT4 length
number of timestamps
Definition: SFTfileIO.h:192
Multi-IFO container for antenna-pattern coefficients and atenna-pattern matrix .
Definition: LALComputeAM.h:137
AntennaPatternMatrix Mmunu
antenna-pattern matrix
Definition: LALComputeAM.h:143
Multi-IFO time-series of DetectorStates.
array of detectors definitions 'LALDetector'
A collection of (multi-IFO) LIGOTimeGPSVector time-stamps vectors.
Definition: SFTfileIO.h:198
UINT4 length
number of timestamps vectors or ifos
Definition: SFTfileIO.h:202
LIGOTimeGPSVector ** data
timestamps vector for each ifo
Definition: SFTfileIO.h:203
array of detector-specific 'noise floors' (ie PSD values), assumed constant over the frequency-band o...
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
Definition: PSDutils.h:71
REAL8 Sinv_Tsft
normalization factor used: (using single-sided PSD!)
Definition: PSDutils.h:77
UINT4 length
number of detectors
Definition: PSDutils.h:75
REAL8Vector ** data
weights-vector for each detector
Definition: PSDutils.h:76
A collection of PSD vectors – one for each IFO in a multi-IFO search.
Definition: PSDutils.h:62
A multi-SFT-catalogue "view": a multi-IFO vector of SFT-catalogs.
Definition: SFTfileIO.h:255
UINT4 length
number of detectors
Definition: SFTfileIO.h:259
A collection of SFT vectors – one for each IFO in a multi-IFO search.
Definition: SFTfileIO.h:179
Type containing the JKS 'amplitude parameters' {h0, cosi, phi0, psi}.
REAL8 aCross
Signal amplitude (cross)
REAL8 psi
polarization angle psi
REAL8 aPlus
Signal amplitude (plus)
REAL8 phi0
initial signal-phase (at some reference time)
REAL8 * data
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
Definition: SFTfileIO.h:238
SFTDescriptor * data
array of data-entries describing matched SFTs
Definition: SFTfileIO.h:243
UINT4 length
number of SFTs in catalog
Definition: SFTfileIO.h:242
'Constraints' for SFT-matching: which detector, within which time-stretch and which timestamps exactl...
Definition: SFTfileIO.h:212
SFTtype header
SFT-header info.
Definition: SFTfileIO.h:228
REAL8 longitude
REAL8 latitude
CoordinateSystem system
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, ....