Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-3a66518
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
FstatMetric_v2.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006, 2008, 2009 Reinhard Prix
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20/**
21 * \file
22 * \ingroup lalpulsar_bin_Fstatistic
23 * \author Reinhard Prix
24 * \brief
25 * This module deals with calculating various F-statistic metric approximations,
26 * Fisher matrices and mismatches. Contrary to previous implementations
27 * this consistently uses gsl-integration, and allows for very generic
28 * handling of different coordinate systems in the Doppler parameter space.
29 *
30 * In particular, it allows for easy extensions to new coordinates and Doppler parameters.
31 */
32
33/* ---------- includes ---------- */
34#include <math.h>
35#include <errno.h>
36#include <string.h>
37
38#include <gsl/gsl_vector.h>
39#include <gsl/gsl_matrix.h>
40
41#include <lal/UserInput.h>
42#include <lal/LALConstants.h>
43#include <lal/Date.h>
44#include <lal/LALInitBarycenter.h>
45#include <lal/AVFactories.h>
46#include <lal/SkyCoordinates.h>
47#include <lal/ComputeFstat.h>
48#include <lal/GetEarthTimes.h>
49#include <lal/SFTfileIO.h>
50#include <lal/LALString.h>
51
52#include <lal/ComputeFstat.h>
53#include <lal/LogPrintf.h>
54#include <lal/StringVector.h>
55#include <lal/UniversalDopplerMetric.h>
56#include <lal/MetricUtils.h>
57#include <lal/LALPulsarVCSInfo.h>
58
59/* ---------- Error codes and messages ---------- */
60#define FSTATMETRIC_EMEM 1
61#define FSTATMETRIC_EINPUT 2
62#define FSTATMETRIC_ENULL 3
63#define FSTATMETRIC_ENONULL 4
64#define FSTATMETRIC_EFILE 5
65#define FSTATMETRIC_EXLAL 6
66
67
68#define FSTATMETRIC_MSGEMEM "Out of memory."
69#define FSTATMETRIC_MSGEINPUT "Invalid input."
70#define FSTATMETRIC_MSGENULL "Illegal NULL input"
71#define FSTATMETRIC_MSGENONULL "Output field not initialized to NULL"
72#define FSTATMETRIC_MSGEFILE "File IO error"
73#define FSTATMETRIC_MSGEXLAL "XLAL function call failed"
74
75/* ----- compile switches ----- */
76/* uncomment the following to turn off range-checking in GSL vector-functions */
77/* #define GSL_RANGE_CHECK_OFF 1*/
78
79#define METRIC_FORMAT "% .16e" /* fprintf-format used for printing metric components */
80
81/*---------- local defines ---------- */
82#define TRUE (1==1)
83#define FALSE (1==0)
84
85#define OneBillion 1.0e9
86#define ORB_V0 1e-4
87
88/* ----- Macros ----- */
89/** convert GPS-time to REAL8 */
90#define GPS2REAL8(gps) (1.0 * (gps).gpsSeconds + 1.e-9 * (gps).gpsNanoSeconds )
91
92/** Simple Euklidean scalar product for two 3-dim vectors in cartesian coords */
93#define SCALAR(u,v) ((u)[0]*(v)[0] + (u)[1]*(v)[1] + (u)[2]*(v)[2])
94
95/** copy 3 components of Euklidean vector */
96#define COPY_VECT(dst,src) do { (dst)[0] = (src)[0]; (dst)[1] = (src)[1]; (dst)[2] = (src)[2]; } while(0)
97
98#define SQ(x) ((x) * (x))
99
100/* ---------- local types ---------- */
101
102/**
103 * Rudimentary first sketch of a history type, to encode all
104 * the history-trail leading to a certain result from primal inputs.
105 *
106 * This will be extended in the future and moved into LAL.
107 */
108typedef struct {
109 CHAR *app_name; /**< name (and path) of this application */
110 CHAR *cmdline; /**< commandline used to produce this result */
111 CHAR *VCSInfoString; /**< Git source-version + configure string */
113
114
115typedef struct {
116 EphemerisData *edat; /**< ephemeris data (from XLALInitBarycenter()) */
117 LALSegList segmentList; /**< segment list contains start- and end-times of all segments */
118 PulsarParams signalParams; /**< GW signal parameters: Amplitudes + doppler */
119 MultiLALDetector multiIFO; /**< (multi-)detector info */
120 MultiNoiseFloor multiNoiseFloor; /**< ... and corresponding noise-floors to be used as weights */
121 DopplerCoordinateSystem coordSys; /**< array of enums describing Doppler-coordinates to compute metric in */
122 ResultHistory_t *history; /**< history trail leading up to and including this application */
124
125
126typedef struct {
127 LALStringVector *IFOs; /**< list of detector-names "H1,H2,L1,.." or single detector*/
128 LALStringVector *sqrtSX; /**< (string-) list of per-IFO sqrt{Sn} values, \f$ \sqrt{S_X} \f$ */
129
130 REAL8 Freq; /**< target-frequency */
131 REAL8 Alpha; /**< skyposition Alpha: radians, equatorial coords. */
132 REAL8 Delta; /**< skyposition Delta: radians, equatorial coords. */
133 REAL8 f1dot; /**< target 1. spindown-value df/dt */
134 REAL8 f2dot; /**< target 2. spindown-value d2f/dt2 */
135 REAL8 f3dot; /**< target 3. spindown-value d3f/dt3 */
136 REAL8 orbitasini; /**< target projected semimajor axis of binary orbit [Units: light seconds] */
137 REAL8 orbitPeriod; /**< target period of binary orbit [Units: s]. */
138 LIGOTimeGPS orbitTp; /**< target time of periapse passage of the CW source in a binary orbit [Units: GPS seconds] */
139 REAL8 orbitArgp; /**< target argument of periapse of binary orbit [Units: rad] */
140 REAL8 orbitEcc; /**< target eccentricity of binary orbit [Units: none] */
141
142 CHAR *ephemEarth; /**< Earth ephemeris file to use */
143 CHAR *ephemSun; /**< Sun ephemeris file to use */
144
145 LIGOTimeGPS refTime; /**< GPS reference time of Doppler parameters */
146
147 LIGOTimeGPS startTime; /**< GPS start time of observation */
148 REAL8 duration; /**< length of observation in seconds */
149 INT4 Nseg; /**< number of segments to split duration into */
150 CHAR *segmentList; /**< ALTERNATIVE: specify segment file with format: repeated lines <startGPS endGPS duration[h] NumSFTs>" */
151
152 REAL8 h0; /**< GW amplitude h_0 */
153 REAL8 cosi; /**< cos(iota) */
154 REAL8 psi; /**< polarization-angle psi */
155 REAL8 phi0; /**< initial GW phase phi_0 */
156
157 CHAR *outputMetric; /**< filename to write metrics into */
158
159 CHAR *detMotionStr; /**< string specifying type of detector-motion to use */
160
161 INT4 metricType; /**< type of metric to compute: 0=phase-metric, 1=F-metric(s), 2=both */
162
163 INT4 projection; /**< project metric onto subspace orthogonal to this coordinate-axis (0=none, 1=1st-coordinate axis, ...) */
164
165 LALStringVector *coords; /**< list of Doppler-coordinates to compute metric in, see --coordsHelp for possible values */
166 BOOLEAN coordsHelp; /**< output help-string explaining all the possible Doppler-coordinate names for --cords */
167
168 BOOLEAN approxPhase; /**< use an approximate phase-model, neglecting Roemer delay in spindown coordinates */
169
171
172/* ---------- global variables ----------*/
173extern int vrbflg;
174
175/* ---------- local prototypes ---------- */
176int initUserVars( UserVariables_t *uvar );
177int XLALInitCode( ConfigVariables *cfg, const UserVariables_t *uvar, const char *app_name );
178
179int XLALOutputDopplerMetric( FILE *fp, const DopplerPhaseMetric *Pmetric, const DopplerFstatMetric *Fmetric, const ResultHistory_t *history );
180
183
184/*============================================================
185 * FUNCTION definitions
186 *============================================================*/
187
188int
189main( int argc, char *argv[] )
190{
193 DopplerMetricParams XLAL_INIT_DECL( metricParams );
194
195 vrbflg = 1; /* verbose error-messages */
196
197 /* set LAL error-handler */
199
200 /* register user-variables */
201 if ( initUserVars( &uvar ) != XLAL_SUCCESS ) {
202 XLALPrintError( "%s(): initUserVars() failed\n", __func__ );
203 return EXIT_FAILURE;
204 }
205
206 /* read cmdline & cfgfile */
207 BOOLEAN should_exit = 0;
209 if ( should_exit ) {
210 return EXIT_FAILURE;
211 }
212
213 CHAR *VCSInfoString;
214 if ( ( VCSInfoString = XLALVCSInfoString( lalPulsarVCSInfoList, 0, "%% " ) ) == NULL ) {
215 XLALPrintError( "XLALVCSInfoString failed.\n" );
216 exit( 1 );
217 }
218
219 if ( uvar.coordsHelp ) {
220 CHAR *helpstr;
221 if ( ( helpstr = XLALDopplerCoordinateHelpAll() ) == NULL ) {
222 LogPrintf( LOG_CRITICAL, "XLALDopplerCoordinateHelpAll() failed!\n\n" );
223 return -1;
224 }
225 printf( "\n%s\n", helpstr );
226 XLALFree( helpstr );
227 return 0;
228 } /* if coordsHelp */
229
230 /* basic setup and initializations */
231 XLAL_CHECK( XLALInitCode( &config, &uvar, argv[0] ) == XLAL_SUCCESS, XLAL_EFUNC, "XLALInitCode() failed with xlalErrno = %d\n\n", xlalErrno );
232 config.history->VCSInfoString = VCSInfoString;
233
234 /* parse detector motion string */
235 int detMotionType = XLALParseDetectorMotionString( uvar.detMotionStr );
236 XLAL_CHECK( detMotionType != XLAL_FAILURE, XLAL_EFUNC, "Failed to pass detector motion string '%s'", uvar.detMotionStr );
237 metricParams.detMotionType = detMotionType;
238
239 metricParams.segmentList = config.segmentList;
240 metricParams.coordSys = config.coordSys;
241 metricParams.multiIFO = config.multiIFO;
242 metricParams.multiNoiseFloor = config.multiNoiseFloor;
243 metricParams.signalParams = config.signalParams;
244 metricParams.projectCoord = uvar.projection - 1; /* user-input counts from 1, but interally we count 0=1st coord. (-1==no projection) */
245 metricParams.approxPhase = uvar.approxPhase;
246
247
248 /* ----- compute metric full metric + Fisher matrix ---------- */
249 DopplerPhaseMetric *Pmetric = NULL;
250 if ( uvar.metricType == 0 || uvar.metricType == 2 ) {
251 if ( ( Pmetric = XLALComputeDopplerPhaseMetric( &metricParams, config.edat ) ) == NULL ) {
252 LogPrintf( LOG_CRITICAL, "Something failed in XLALComputeDopplerPhaseMetric(). xlalErrno = %d\n\n", xlalErrno );
253 return -1;
254 }
255 }
256 DopplerFstatMetric *Fmetric = NULL;
257 if ( uvar.metricType == 1 || uvar.metricType == 2 ) {
258 if ( ( Fmetric = XLALComputeDopplerFstatMetric( &metricParams, config.edat ) ) == NULL ) {
259 LogPrintf( LOG_CRITICAL, "Something failed in XLALComputeDopplerFstatMetric(). xlalErrno = %d\n\n", xlalErrno );
260 return -1;
261 }
262 }
263
264 /* ---------- output results ---------- */
265 if ( uvar.outputMetric ) {
266 FILE *fpMetric;
267 if ( ( fpMetric = fopen( uvar.outputMetric, "wb" ) ) == NULL ) {
268 LogPrintf( LOG_CRITICAL, "%s: failed to open '%s' for writing. error = '%s'\n",
269 __func__, uvar.outputMetric, strerror( errno ) );
270 return FSTATMETRIC_EFILE;
271 }
272
273 if ( XLALOutputDopplerMetric( fpMetric, Pmetric, Fmetric, config.history ) != XLAL_SUCCESS ) {
274 LogPrintf( LOG_CRITICAL, "%s: failed to write Doppler metric into output-file '%s'. xlalErrno = %d\n\n",
275 __func__, uvar.outputMetric, xlalErrno );
276 return FSTATMETRIC_EFILE;
277 }
278
279 fclose( fpMetric );
280
281 } /* if outputMetric */
282
283 /* ----- done: free all memory */
286 if ( XLALDestroyConfig( &config ) != XLAL_SUCCESS ) {
287 LogPrintf( LOG_CRITICAL, "%s: XLADestroyConfig() failed, xlalErrno = %d.\n\n", __func__, xlalErrno );
288 return FSTATMETRIC_EXLAL;
289 }
290
292
293 return 0;
294} /* main */
295
296
297/** register all "user-variables" */
298int
300{
301
302 /* set a few defaults */
303 uvar->ephemEarth = XLALStringDuplicate( "earth00-40-DE405.dat.gz" );
304 uvar->ephemSun = XLALStringDuplicate( "sun00-40-DE405.dat.gz" );
305
306 uvar->Freq = 100;
307 uvar->f1dot = 0.0;
308 uvar->f2dot = 0.0;
309 uvar->f3dot = 0.0;
310 uvar->h0 = 1;
311 uvar->phi0 = 0;
312
313 uvar->startTime.gpsSeconds = 714180733;
314 uvar->duration = 10 * 3600;
315 uvar->Nseg = 1;
316 uvar->segmentList = NULL;
317
318 uvar->refTime.gpsSeconds = -1; /* default: use mid-time */
319
320 uvar->projection = 0;
321 if ( ( uvar->IFOs = XLALCreateStringVector( "H1", NULL ) ) == NULL ) {
322 LogPrintf( LOG_CRITICAL, "Call to XLALCreateStringVector() failed with xlalErrno = %d\n", xlalErrno );
324 }
325
326 uvar->sqrtSX = NULL;
327
329 uvar->metricType = 0; /* by default: compute only phase metric */
330
331 if ( ( uvar->coords = XLALCreateStringVector( "freq", "alpha", "delta", "f1dot", NULL ) ) == NULL ) {
332 LogPrintf( LOG_CRITICAL, "Call to XLALCreateStringVector() failed with xlalErrno = %d\n", xlalErrno );
334 }
335
336 uvar->approxPhase = FALSE;
337
338 /* register all our user-variables */
339
340 XLALRegisterUvarMember( IFOs, STRINGVector, 'I', OPTIONAL, "CSV list of detectors, eg. \"H1,H2,L1,G1, ...\" " );
341 XLALRegisterUvarMember( sqrtSX, STRINGVector, 0, OPTIONAL, "[for F-metric weights] CSV list of detectors' noise-floors sqrt{Sn}" );
342 XLALRegisterUvarMember( Alpha, RAJ, 'a', OPTIONAL, "Sky: equatorial J2000 right ascension (in radians or hours:minutes:seconds)" );
343 XLALRegisterUvarMember( Delta, DECJ, 'd', OPTIONAL, "Sky: equatorial J2000 declination (in radians or degrees:minutes:seconds)" );
344 XLALRegisterUvarMember( Freq, REAL8, 'f', OPTIONAL, "Target frequency" );
345 XLALRegisterUvarMember( f1dot, REAL8, 's', OPTIONAL, "First spindown-value df/dt" );
346 XLALRegisterUvarMember( f2dot, REAL8, 0, OPTIONAL, "Second spindown-value d2f/dt2" );
347 XLALRegisterUvarMember( f3dot, REAL8, 0, OPTIONAL, "Third spindown-value d3f/dt3" );
348
349 XLALRegisterUvarMember( orbitasini, REAL8, 0, OPTIONAL, "Target projected semimajor axis of binary orbit (Units: light seconds)" );
350 XLALRegisterUvarMember( orbitPeriod, REAL8, 0, OPTIONAL, "Target period of binary orbit (Units: s)." );
351 XLALRegisterUvarMember( orbitTp, EPOCH, 0, OPTIONAL, "Target time of periapse passage of the CW source in a binary orbit (Units: GPS seconds)" );
352 XLALRegisterUvarMember( orbitArgp, REAL8, 0, OPTIONAL, "Target argument of periapse of binary orbit (Units: rad)" );
353 XLALRegisterUvarMember( orbitEcc, REAL8, 0, OPTIONAL, "Target eccentricity of binary orbit (Units: none)" );
354
355 XLALRegisterUvarMember( refTime, EPOCH, 0, OPTIONAL, "Reference epoch for phase-evolution parameters (format 'xx.yy[GPS|MJD]'). [0=startTime, default=mid-time]" );
356 XLALRegisterUvarMember( startTime, EPOCH, 't', OPTIONAL, "Start time of observation (format 'xx.yy[GPS|MJD]')" );
357
358 XLALRegisterUvarMember( duration, REAL8, 'T', OPTIONAL, "Duration of observation in seconds" );
359 XLALRegisterUvarMember( Nseg, INT4, 'N', OPTIONAL, "Compute semi-coherent metric for this number of segments within 'duration'" );
360 XLALRegisterUvarMember( segmentList, STRING, 0, OPTIONAL, "ALTERNATIVE: specify segment file with format: repeated lines <startGPS endGPS duration[h] NumSFTs>" );
361 XLALRegisterUvarMember( ephemEarth, STRING, 0, OPTIONAL, "Earth ephemeris file to use" );
362 XLALRegisterUvarMember( ephemSun, STRING, 0, OPTIONAL, "Sun ephemeris file to use" );
363
364 XLALRegisterUvarMember( h0, REAL8, 0, OPTIONAL, "GW amplitude h0" );
365 XLALRegisterUvarMember( cosi, REAL8, 0, OPTIONAL, "Pulsar orientation-angle cos(iota) [-1,1]" );
366 XLALRegisterUvarMember( psi, REAL8, 0, OPTIONAL, "Wave polarization-angle psi [0, pi]" );
367 XLALRegisterUvarMember( phi0, REAL8, 0, OPTIONAL, "GW initial phase phi_0 [0, 2pi]" );
368
369 XLALRegisterUvarMember( metricType, INT4, 0, OPTIONAL, "type of metric to compute: 0=phase-metric, 1=F-metric(s), 2=both" );
370 XLALRegisterUvarMember( outputMetric, STRING, 'o', OPTIONAL, "Output the metric components (in octave format) into this file." );
371 XLALRegisterUvarMember( projection, INT4, 0, OPTIONAL, "Project onto subspace orthogonal to this axis: 0=none, 1=1st-coord, 2=2nd-coord etc" );
372
373 XLALRegisterUvarMember( coords, STRINGVector, 'c', OPTIONAL, "Doppler-coordinates to compute metric in (see --coordsHelp)" );
374 XLALRegisterUvarMember( coordsHelp, BOOLEAN, 0, OPTIONAL, "output help-string explaining all the possible Doppler-coordinate names for --coords" );
375
376 XLALRegisterUvarMember( detMotionStr, STRING, 0, DEVELOPER, "Detector-motion string: S|O|S+O where S=spin|spinz|spinxy and O=orbit|ptoleorbit" );
377 XLALRegisterUvarMember( approxPhase, BOOLEAN, 0, DEVELOPER, "Use an approximate phase-model, neglecting Roemer delay in spindown coordinates (or orders >= 1)" );
378
379 return XLAL_SUCCESS;
380
381} /* initUserVars() */
382
383
384/**
385 * basic initializations: set-up 'ConfigVariables'
386 */
387int
388XLALInitCode( ConfigVariables *cfg, const UserVariables_t *uvar, const char *app_name )
389{
390 if ( !cfg || !uvar || !app_name ) {
391 LogPrintf( LOG_CRITICAL, "%s: illegal NULL pointer input.\n\n", __func__ );
393 }
394
395 /* Init ephemerides */
396 XLAL_CHECK( ( cfg->edat = XLALInitBarycenter( uvar->ephemEarth, uvar->ephemSun ) ) != NULL, XLAL_EFUNC );
397
398 // ----- figure out which segments to use
399 BOOLEAN manualSegments = XLALUserVarWasSet( &uvar->duration ) || XLALUserVarWasSet( &uvar->startTime ) || XLALUserVarWasSet( &uvar->Nseg );
400 if ( manualSegments && uvar->segmentList ) {
401 XLAL_ERROR( XLAL_EDOM, "Can specify EITHER {--startTime, --duration, --Nseg} OR --segmentList\n" );
402 }
403 LIGOTimeGPS startTimeGPS;
405 if ( uvar->segmentList == NULL ) {
406 XLAL_CHECK( uvar->Nseg >= 1, XLAL_EDOM, "Invalid input --Nseg=%d: number of segments must be >= 1\n", uvar->Nseg );
407 XLAL_CHECK( uvar->duration >= 1, XLAL_EDOM, "Invalid input --duration=%f: duration must be >= 1 s\n", uvar->duration );
408 startTimeGPS = uvar->startTime;
409 int ret = XLALSegListInitSimpleSegments( &cfg->segmentList, startTimeGPS, uvar->Nseg, uvar->duration / uvar->Nseg );
410 XLAL_CHECK( ret == XLAL_SUCCESS, XLAL_EFUNC, "XLALSegListInitSimpleSegments() failed with xlalErrno = %d\n", xlalErrno );
411 duration = uvar->duration;
412 } else {
414 XLAL_CHECK( segList != NULL, XLAL_EIO, "XLALReadSegmentsFromFile() failed to load segment list from file '%s', xlalErrno = %d\n", uvar->segmentList, xlalErrno );
415 cfg->segmentList = ( *segList ); // copy *contents*
416 XLALFree( segList );
417 startTimeGPS = cfg->segmentList.segs[0].start;
418 UINT4 Nseg = cfg->segmentList.length;
419 LIGOTimeGPS endTimeGPS = cfg->segmentList.segs[Nseg - 1].end;
420 duration = XLALGPSDiff( &endTimeGPS, &startTimeGPS );
421 }
422
423 /* ----- figure out reference time */
424 LIGOTimeGPS refTimeGPS;
425
426 /* treat special values first */
427 if ( uvar->refTime.gpsSeconds == 0 ) { /* 0 = use startTime */
428 refTimeGPS = uvar->startTime;
429 } else if ( !XLALUserVarWasSet( &uvar->refTime ) ) { /* default = use mid-time of observation */
430 refTimeGPS = startTimeGPS;
431 XLALGPSAdd( &refTimeGPS, duration / 2.0 );
432 } else {
433 refTimeGPS = uvar->refTime;
434 }
435
436 /* ----- get parameter-space point from user-input) */
437
438 cfg->signalParams.Amp.aPlus = 0.5 * uvar->h0 * ( 1.0 + SQ( uvar->cosi ) );
439 cfg->signalParams.Amp.aCross = uvar->h0 * uvar->cosi;
440 cfg->signalParams.Amp.psi = uvar->psi;
441 cfg->signalParams.Amp.phi0 = uvar->phi0;
442
443 {
445 XLAL_INIT_MEM( ( *dop ) );
446 dop->refTime = refTimeGPS;
447 dop->Alpha = uvar->Alpha;
448 dop->Delta = uvar->Delta;
449 dop->fkdot[0] = uvar->Freq;
450 dop->fkdot[1] = uvar->f1dot;
451 dop->fkdot[2] = uvar->f2dot;
452 dop->fkdot[3] = uvar->f3dot;
453 dop->asini = uvar->orbitasini;
454 dop->period = uvar->orbitPeriod;
455 dop->tp = uvar->orbitTp;
456 dop->ecc = uvar->orbitEcc;
457 dop->argp = uvar->orbitArgp;
458 }
459
460 /* ----- initialize IFOs and (Multi-)DetectorStateSeries ----- */
464
465 if ( uvar->sqrtSX ) {
467 }
468
469 /* ---------- translate coordinate system into internal representation ---------- */
470 if ( XLALDopplerCoordinateNames2System( &cfg->coordSys, uvar->coords ) ) {
471 LogPrintf( LOG_CRITICAL, "%s: Call to XLALDopplerCoordinateNames2System() failed. errno = %d\n\n", __func__, xlalErrno );
473 }
474
475 /* ---------- record full 'history' up to and including this application ---------- */
476 {
477 CHAR *cmdline = NULL;
478 CHAR *tmp;
479 size_t len = strlen( app_name ) + 1;
480
481 if ( ( cfg->history = XLALCalloc( 1, sizeof( *cfg->history ) ) ) == NULL ) {
482 LogPrintf( LOG_CRITICAL, "%s: XLALCalloc(1,%zu) failed.\n\n", __func__, sizeof( *cfg->history ) );
484 }
485
486 if ( ( tmp = XLALMalloc( len ) ) == NULL ) {
487 LogPrintf( LOG_CRITICAL, "%s: XLALMalloc (%zu) failed.\n\n", __func__, len );
489 }
490 strcpy( tmp, app_name );
491 cfg->history->app_name = tmp;
492
493 /* get commandline describing search*/
494 if ( ( cmdline = XLALUserVarGetLog( UVAR_LOGFMT_CMDLINE ) ) == NULL ) {
495 LogPrintf( LOG_CRITICAL, "%s: XLALUserVarGetLog() failed with xlalErrno = %d.\n\n", __func__, xlalErrno );
497 }
498 cfg->history->cmdline = cmdline;
499 } /* record history */
500
501
502 return XLAL_SUCCESS;
503
504} /* XLALInitCode() */
505
506
507/** Destructor for internal configuration struct */
508int
510{
511 if ( !cfg ) {
512 LogPrintf( LOG_CRITICAL, "%s: invalid NULL input!\n\n", __func__ );
514 }
515
517
519
521
522 XLALSegListClear( &( cfg->segmentList ) );
523 return XLAL_SUCCESS;
524
525} /* XLALDestroyConfig() */
526
527
528int
529XLALOutputDopplerMetric( FILE *fp, const DopplerPhaseMetric *Pmetric, const DopplerFstatMetric *Fmetric, const ResultHistory_t *history )
530{
531 UINT4 i;
532 REAL8 A, B, C, D;
533
534 // ----- input sanity checks
535 XLAL_CHECK( fp != NULL, XLAL_EFAULT );
536 XLAL_CHECK( Pmetric != NULL || Fmetric != NULL, XLAL_EFAULT );
537 const DopplerMetricParams *meta = ( Pmetric != NULL ) ? &( Pmetric->meta ) : &( Fmetric->meta );
538 XLAL_CHECK( XLALSegListIsInitialized( &( meta->segmentList ) ), XLAL_EINVAL, "Got un-initialized segment list in 'metric->meta.segmentList'\n" );
539 UINT4 Nseg = meta->segmentList.length;
540 XLAL_CHECK( Nseg >= 1, XLAL_EDOM, "Got invalid zero-length segment list 'metric->meta.segmentList'\n" );
541
542 /* useful shortcuts */
543 const PulsarDopplerParams *doppler = &( meta->signalParams.Doppler );
544 const PulsarAmplitudeParams *Amp = &( meta->signalParams.Amp );
545
546 /* output history info */
547 if ( history ) {
548 if ( history->app_name ) {
549 fprintf( fp, "%%%% app_name: %s\n", history->app_name );
550 }
551 if ( history->cmdline ) {
552 fprintf( fp, "%%%% commandline: %s\n", history->cmdline );
553 }
554 if ( history->VCSInfoString ) {
555 fprintf( fp, "%%%% Code Version: %s\n", history->VCSInfoString );
556 }
557 }
558
559 fprintf( fp, "DopplerCoordinates = { " );
560 for ( i = 0; i < meta->coordSys.dim; i ++ ) {
561 if ( i > 0 ) {
562 fprintf( fp, ", " );
563 }
564 fprintf( fp, "\"%s\"", XLALDopplerCoordinateName( meta->coordSys.coordIDs[i] ) );
565 }
566 fprintf( fp, "};\n" );
567
568 { /* output projection info */
569 const char *pname;
570 if ( meta->projectCoord < 0 ) {
571 pname = "None";
572 } else {
574 }
575
576 fprintf( fp, "%%%% Projection onto subspace orthogonal to coordinate: '%s'\n", pname );
577 }
578
579 fprintf( fp, "%%%% DetectorMotionType = '%s'\n", XLALDetectorMotionName( meta->detMotionType ) );
580 fprintf( fp, "aPlus = %g;\naCross = %g;\npsi = %g;\nphi0 = %g;\n", Amp->aPlus, Amp->aCross, Amp->psi, Amp->phi0 );
581 if ( fabs( Amp->aPlus ) >= fabs( Amp->aCross ) ) { /* Assume GW at twice the spin frequency only */
582 REAL8 h0, cosi;
583 h0 = Amp->aPlus + sqrt( SQ( Amp->aPlus ) - SQ( Amp->aCross ) );
584 if ( h0 > 0 ) {
585 cosi = Amp->aCross / h0;
586 } else {
587 cosi = 0;
588 }
589 fprintf( fp, "h0 = %g;\ncosi = %g;\n", h0, cosi );
590 }
591 fprintf( fp, "%%%% DopplerPoint = {\n" );
592 fprintf( fp, "refTime = %.1f;\n", XLALGPSGetREAL8( &doppler->refTime ) );
593 fprintf( fp, "Alpha = %f;\nDelta = %f;\n", doppler->Alpha, doppler->Delta );
594 fprintf( fp, "fkdot = [%f, %g, %g, %g ];\n", doppler->fkdot[0], doppler->fkdot[1], doppler->fkdot[2], doppler->fkdot[3] );
595
596 if ( doppler->asini > 0 ) {
597 fprintf( fp, "%%%% orbit = { \n" );
598 fprintf( fp, "%%%% tp = {%d, %d}\n", doppler->tp.gpsSeconds, doppler->tp.gpsNanoSeconds );
599 fprintf( fp, "%%%% argp = %g\n", doppler->argp );
600 fprintf( fp, "%%%% asini = %g\n", doppler->asini );
601 fprintf( fp, "%%%% ecc = %g\n", doppler->ecc );
602 fprintf( fp, "%%%% period = %g\n", doppler->period );
603 fprintf( fp, "%%%% }\n" );
604 } /* if doppler->orbit */
605 fprintf( fp, "%%%% }\n" );
606
607 LIGOTimeGPS *tStart = &( meta->segmentList.segs[0].start );
608 LIGOTimeGPS *tEnd = &( meta->segmentList.segs[Nseg - 1].end );
609 REAL8 Tspan = XLALGPSDiff( tEnd, tStart );
610 fprintf( fp, "startTime = %.1f;\n", XLALGPSGetREAL8( tStart ) );
611 fprintf( fp, "Tspan = %.1f;\n", Tspan );
612 fprintf( fp, "Nseg = %d;\n", Nseg );
613 fprintf( fp, "detectors = {" );
614 for ( i = 0; i < meta->multiIFO.length; i ++ ) {
615 if ( i > 0 ) {
616 fprintf( fp, ", " );
617 }
618 fprintf( fp, "\"%s\"", meta->multiIFO.sites[i].frDetector.name );
619 }
620 fprintf( fp, "};\n" );
621 fprintf( fp, "detectorWeights = [" );
622 for ( i = 0; i < meta->multiNoiseFloor.length; i ++ ) {
623 if ( i > 0 ) {
624 fprintf( fp, ", " );
625 }
626 fprintf( fp, "%f", meta->multiNoiseFloor.sqrtSn[i] );
627 }
628 fprintf( fp, "];\n" );
629
630 /* ----- output phase metric ---------- */
631 if ( Pmetric != NULL ) {
632 fprintf( fp, "\ng_ij = " );
634 fprintf( fp, "maxrelerr_gPh = %.2e;\n", Pmetric->maxrelerr );
635
636 gsl_matrix *gN_ij = NULL;
637 if ( XLALNaturalizeMetric( &gN_ij, NULL, Pmetric->g_ij, meta ) != XLAL_SUCCESS ) {
638 XLALPrintError( "%s: something failed Naturalizing phase metric g_ij!\n", __func__ );
640 }
641 fprintf( fp, "\ngN_ij = " );
643 gsl_matrix_free( gN_ij );
644
645 gsl_matrix *gDN_ij = NULL;
646 if ( XLALDiagNormalizeMetric( &gDN_ij, NULL, Pmetric->g_ij ) != XLAL_SUCCESS ) {
647 XLALPrintError( "%s: something failed NormDiagonalizing phase metric g_ij!\n", __func__ );
649 }
650 fprintf( fp, "\ngDN_ij = " );
652 gsl_matrix_free( gDN_ij );
653 }
654
655 /* ----- output F-metric (and related matrices ---------- */
656 if ( Fmetric != NULL ) {
657 fprintf( fp, "\ngF_ij = " );
659 fprintf( fp, "\ngFav_ij = " );
661 fprintf( fp, "\nm1_ij = " );
663 fprintf( fp, "\nm2_ij = " );
665 fprintf( fp, "\nm3_ij = " );
667 fprintf( fp, "maxrelerr_gF = %.2e;\n", Fmetric->maxrelerr );
668 }
669
670 /* ----- output Fisher matrix ---------- */
671 if ( Fmetric != NULL && Fmetric->Fisher_ab != NULL ) {
672 A = gsl_matrix_get( Fmetric->Fisher_ab, 0, 0 );
673 B = gsl_matrix_get( Fmetric->Fisher_ab, 1, 1 );
674 C = gsl_matrix_get( Fmetric->Fisher_ab, 0, 1 );
675
676 D = A * B - C * C;
677
678 fprintf( fp, "\nA = %.16g;\nB = %.16g;\nC = %.16g;\nD = %.16g;\n", A, B, C, D );
679 fprintf( fp, "\nrho2 = %.16g;\n", Fmetric->rho2 );
680
681 fprintf( fp, "\nFisher_ab = " );
683 }
684
685 // ---------- output segment list at the end, as this can potentially become quite long and distracting
686 char *seglist_octave;
687 XLAL_CHECK( ( seglist_octave = XLALSegList2String( &( meta->segmentList ) ) ) != NULL, XLAL_EFUNC, "XLALSegList2String() with xlalErrno = %d\n", xlalErrno );
688 fprintf( fp, "\n\nsegmentList = %s;\n", seglist_octave );
689 XLALFree( seglist_octave );
690
691
692 return XLAL_SUCCESS;
693
694} /* XLALOutputDopplerMetric() */
695
696
697/**
698 * Destructor for ResultHistory type
699 */
700void
702{
703
704 if ( !history ) {
705 return;
706 }
707
708 if ( history->app_name ) {
709 XLALFree( history->app_name );
710 }
711
712 if ( history->cmdline ) {
713 XLALFree( history->cmdline );
714 }
715
716 if ( history->VCSInfoString ) {
717 XLALFree( history->VCSInfoString );
718 }
719
720 XLALFree( history );
721
722 return;
723
724} /* XLALDestroyResultHistory() */
#define __func__
log an I/O error, i.e.
#define FSTATMETRIC_EXLAL
int main(int argc, char *argv[])
#define FSTATMETRIC_EFILE
int XLALDestroyConfig(ConfigVariables *cfg)
Destructor for internal configuration struct.
#define METRIC_FORMAT
int XLALOutputDopplerMetric(FILE *fp, const DopplerPhaseMetric *Pmetric, const DopplerFstatMetric *Fmetric, const ResultHistory_t *history)
int initUserVars(UserVariables_t *uvar)
register all "user-variables"
int vrbflg
defined in lal/lib/std/LALError.c
#define FALSE
#define SQ(x)
int XLALInitCode(ConfigVariables *cfg, const UserVariables_t *uvar, const char *app_name)
basic initializations: set-up 'ConfigVariables'
void XLALDestroyResultHistory(ResultHistory_t *history)
Destructor for ResultHistory type.
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
#define tEnd
#define D(j)
#define STRING(a)
UINT2 A
Definition: SFTnaming.c:46
UINT2 B
Definition: SFTnaming.c:47
#define fprintf
int XLALParseMultiLALDetector(MultiLALDetector *detInfo, const LALStringVector *detNames)
Parse string-vectors (typically input by user) of N detector-names for detectors ,...
int XLALParseMultiNoiseFloor(MultiNoiseFloor *multiNoiseFloor, const LALStringVector *sqrtSX, UINT4 numDetectors)
Parse string-vectors (typically input by user) of N detector noise-floors for detectors ,...
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.
unsigned char BOOLEAN
#define XLAL_INIT_MEM(x)
double REAL8
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
int32_t INT4
void * XLALMalloc(size_t n)
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 int XLALfprintfGSLmatrix(FILE *fp, const char *fmt, const gsl_matrix *gij) _LAL_GCC_VPRINTF_FORMAT_(2)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
LOG_CRITICAL
int XLALDiagNormalizeMetric(gsl_matrix **p_gpr_ij, gsl_matrix **p_transform, const gsl_matrix *g_ij)
Diagonally-normalize a metric .
Definition: MetricUtils.c:391
int XLALNaturalizeMetric(gsl_matrix **p_gpr_ij, gsl_matrix **p_transform, const gsl_matrix *g_ij, const DopplerMetricParams *metricParams)
Return a metric in naturalized coordinates.
Definition: MetricUtils.c:456
LALSegList * XLALReadSegmentsFromFile(const char *fname)
Function to read a segment list from given filename, returns a sorted LALSegList.
char * XLALSegList2String(const LALSegList *seglist)
int XLALSegListClear(LALSegList *seglist)
int XLALSegListInitSimpleSegments(LALSegList *seglist, LIGOTimeGPS startTime, UINT4 Nseg, REAL8 Tseg)
int XLALSegListIsInitialized(const LALSegList *seglist)
LALStringVector * XLALCreateStringVector(const CHAR *str1,...)
int XLALDopplerCoordinateNames2System(DopplerCoordinateSystem *coordSys, const LALStringVector *coordNames)
Given a LALStringVector of coordinate-names, parse them into a 'DopplerCoordinateSystem',...
const CHAR * XLALDetectorMotionName(DetectorMotionType detMotionType)
Provide a pointer to a static string containing the DopplerCoordinate-name cooresponding to the enum ...
CHAR * XLALDopplerCoordinateHelpAll(void)
Return a string (allocated here) containing a full name - helpstring listing for all doppler-coordina...
void XLALDestroyDopplerFstatMetric(DopplerFstatMetric *metric)
Free a DopplerFstatMetric structure.
void XLALDestroyDopplerPhaseMetric(DopplerPhaseMetric *metric)
Free a DopplerPhaseMetric structure.
const CHAR * XLALDopplerCoordinateName(DopplerCoordinateID coordID)
Provide a pointer to a static string containing the DopplerCoordinate-name cooresponding to the enum ...
int XLALParseDetectorMotionString(const CHAR *detMotionString)
Parse a detector-motion type string into the corresponding enum-number,.
DopplerFstatMetric * XLALComputeDopplerFstatMetric(const DopplerMetricParams *metricParams, const EphemerisData *edat)
Calculate the general (single-segment coherent, or multi-segment semi-coherent) full (multi-IFO) Fsta...
DopplerPhaseMetric * XLALComputeDopplerPhaseMetric(const DopplerMetricParams *metricParams, const EphemerisData *edat)
Calculate an approximate "phase-metric" with the specified parameters.
@ DETMOTION_SPIN
Full spin motion.
@ DETMOTION_ORBIT
Ephemeris-based orbital motion.
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define XLALRegisterUvarMember(name, type, option, category,...)
void CHAR * XLALUserVarGetLog(UserVarLogFormat format)
int XLALUserVarWasSet(const void *cvar)
UVAR_LOGFMT_CMDLINE
#define xlalErrno
#define XLAL_ERROR(...)
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFAULT
XLAL_EFUNC
XLAL_EDOM
XLAL_EIO
XLAL_EINVAL
XLAL_FAILURE
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
Configuration settings required for and defining a coherent pulsar search.
ResultHistory_t * history
history trail leading up to and including this application
MultiLALDetector multiIFO
detectors to generate data for (if provided by user and not via noise files)
MultiNoiseFloor multiNoiseFloor
... and corresponding noise-floors to be used as weights
LALSegList segmentList
segment list contains start- and end-times of all segments
DopplerCoordinateSystem coordSys
array of enums describing Doppler-coordinates to compute metric in
PulsarParams signalParams
GW signal parameters: Amplitudes + doppler.
EphemerisData * edat
ephemeris data
type describing a Doppler coordinate system: lists the number of dimensions and the symbolic names of...
DopplerCoordinateID coordIDs[DOPPLERMETRIC_MAX_DIM]
coordinate 'names'
UINT4 dim
number of dimensions covered
Struct to hold the output of XLALComputeDopplerFstatMetric(), including meta-info on the number of di...
gsl_matrix * m3_ij
Fstat-metric sub components.
double maxrelerr
estimate for largest relative error in Fmetric component integrations
gsl_matrix * gFav_ij
'average' Fstat-metric
gsl_matrix * gF_ij
full F-statistic metric gF_ij, including antenna-pattern effects (see )
DopplerMetricParams meta
"meta-info" describing/specifying the type of Doppler metric
REAL8 rho2
signal SNR rho^2 = A^mu M_mu_nu A^nu
gsl_matrix * Fisher_ab
Full 4+n dimensional Fisher matrix, ie amplitude + Doppler space.
meta-info specifying a Doppler-metric
MultiLALDetector multiIFO
detectors to compute metric for
DetectorMotionType detMotionType
the type of detector-motion assumed: full spin+orbit, pure orbital, Ptole, ...
PulsarParams signalParams
parameter-space point to compute metric for (doppler + amplitudes)
INT4 projectCoord
project metric onto subspace orthogonal to this axis (-1 = none, 0 = 1st coordinate,...
LALSegList segmentList
segment list: Nseg segments of the form (startGPS endGPS numSFTs)
MultiNoiseFloor multiNoiseFloor
and associated per-detector noise-floors to be used for weighting.
DopplerCoordinateSystem coordSys
number of dimensions and coordinate-IDs of Doppler-metric
Struct to hold the output of XLALComputeDopplerPhaseMetric(), including meta-info on the number of di...
double maxrelerr
estimate for largest relative error in phase-metric component integrations
gsl_matrix * g_ij
symmetric matrix holding the phase-metric, averaged over segments
DopplerMetricParams meta
"meta-info" describing/specifying the type of Doppler metric
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
LALFrDetector frDetector
CHAR name[LALNameLength]
LIGOTimeGPS end
LIGOTimeGPS start
UINT4 length
LALSeg * segs
INT4 gpsNanoSeconds
array of detectors definitions 'LALDetector'
UINT4 length
number of detectors
LALDetector sites[PULSAR_MAX_DETECTORS]
array of site information
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
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)
Type containing the 'Doppler-parameters' affecting the time-evolution of the phase.
REAL8 period
Binary: orbital period (sec)
LIGOTimeGPS tp
Binary: time of observed periapsis passage (in SSB)
PulsarSpins fkdot
Intrinsic spins: [Freq, f1dot, f2dot, ... ] where fkdot = d^kFreq/dt^k.
REAL8 Delta
Sky position: DEC (latitude) in equatorial coords and radians.
LIGOTimeGPS refTime
Reference time of pulsar parameters (in SSB!)
REAL8 Alpha
Sky position: RA (longitude) in equatorial coords and radians.
REAL8 ecc
Binary: orbital eccentricity.
REAL8 asini
Binary: projected, normalized orbital semi-major axis (s).
REAL8 argp
Binary: argument of periapsis (radians)
Type defining the parameters of a pulsar-source of CW Gravitational waves.
PulsarAmplitudeParams Amp
'Amplitude-parameters': h0, cosi, phi0, psi
PulsarDopplerParams Doppler
'Phase-evolution parameters': {skypos, fkdot, orbital params }
Rudimentary first sketch of a history type, to encode all the history-trail leading to a certain resu...
CHAR * cmdline
commandline used to produce this result
CHAR * VCSInfoString
Git source-version + configure string.
CHAR * app_name
name (and path) of this application
user input variables
Definition: compareFstats.c:51
REAL8 Alpha
Right ascension [radians] alpha of pulsar.
INT4 duration
Duration of requested signal in seconds.
REAL8 orbitArgp
Argument of periapsis (radians)
REAL8 duration
length of observation in seconds
REAL8 psi
Polarization angle psi.
CHAR * ephemSun
Sun ephemeris file to use.
BOOLEAN approxPhase
use an approximate phase-model, neglecting Roemer delay in spindown coordinates
REAL8 h0
overall signal amplitude h0
LIGOTimeGPS refTime
Pulsar reference epoch tRef in SSB ('0' means: use startTime converted to SSB)
CHAR * detMotionStr
string specifying type of detector-motion to use
CHAR * ephemEarth
Earth ephemeris file to use.
REAL8 phi0
Initial phase phi.
REAL8 f2dot
Second spindown parameter f''.
LIGOTimeGPS orbitTp
'true' epoch of periapsis passage
INT4 metricType
type of metric to compute: 0=phase-metric, 1=F-metric(s), 2=both
REAL8 Freq
physical start frequency to compute PSD for (excluding rngmed wings)
CHAR * segmentList
ALTERNATIVE: specify segment file with format: repeated lines <startGPS endGPS duration[h] NumSFTs>".
INT4 Nseg
number of segments to split duration into
LALStringVector * coords
list of Doppler-coordinates to compute metric in, see –coordsHelp for possible values
INT4 projection
project metric onto subspace orthogonal to this coordinate-axis (0=none, 1=1st-coordinate axis,...
LIGOTimeGPS startTime
Start-time of requested signal in detector-frame (GPS seconds)
REAL8 Delta
Declination [radians] delta of pulsar.
REAL8 orbitasini
Projected orbital semi-major axis in seconds (a/c)
REAL8 f1dot
First spindown parameter f'.
LALStringVector * IFOs
list of detector-names "H1,H2,L1,.." or single detector
LALStringVector * sqrtSX
Add Gaussian noise: list of respective detectors' noise-floors sqrt{Sn}".
BOOLEAN coordsHelp
output help-string explaining all the possible Doppler-coordinate names for –cords
REAL8 orbitEcc
Orbital eccentricity.
REAL8 f3dot
Third spindown parameter f'''.
REAL8 orbitPeriod
Orbital period (seconds)
REAL8 cosi
cos(iota) of inclination angle iota
CHAR * outputMetric
filename to write metrics into