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
ComputeAntennaPattern.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 Reinhard Prix, 2013 David Keitel
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_Tools
23 * \author David Keitel, Reinhard Prix
24 * \brief
25 * Simple standalone code to provide ASCII output for antenna-pattern function and matrix
26 * for given detector(s) and sky-location
27 * based on PrintDetectorState
28 *
29 */
30
31/* ---------- includes ---------- */
32#include "config.h"
33
34#include <math.h>
35#include <errno.h>
36#include <string.h>
37
38#include <lal/UserInput.h>
39#include <lal/LALInitBarycenter.h>
40#include <lal/ComputeFstat.h>
41#include <lal/LALString.h>
42#include <lal/StringVector.h>
43#include <lal/LALPulsarVCSInfo.h>
44
45/* ----- compile switches ----- */
46
47/*---------- local defines ---------- */
48
49/* ----- Macros ----- */
50#define SQ(x) ( (x) * (x) )
51
52/* ---------- local types ---------- */
53
54typedef struct {
55 EphemerisData *edat; /**< ephemeris data (from XLALInitBarycenter()) */
56 UINT4 numDetectors; /**< number of detectors */
57 MultiDetectorStateSeries *multiDetStates; /**< detector state time series */
58 MultiNoiseWeights *multiNoiseWeights; /**< per-detector noise weights */
59 MultiLIGOTimeGPSVector *multiTimestamps; /**< timestamps vector (LIGOtimeGPS format) */
60 UINT4 numTimeStamps; /**< number of timestamps (SFTs) for all detectors */
61 UINT4Vector *numTimeStampsX; /**< number of timestamps (SFTs) per detector */
62 REAL8Vector *Alpha; /**< skyposition Alpha: radians, equatorial coords */
63 REAL8Vector *Delta; /**< skyposition Delta: radians, equatorial coords */
64 UINT4 numSkyPoints; /**< common length of Alpha and Delta vectors */
66
67
68typedef struct {
69 LALStringVector *IFOs; /**< list of detector-names "H1,H2,L1,.." or single detector*/
70
71 REAL8 Alpha; /**< a single skyposition Alpha: radians, equatorial coords. */
72 REAL8 Delta; /**< a single skyposition Delta: radians, equatorial coords. */
73 CHAR *skyGridFile; /**< alternative: matrix of (Alpha,Delta) pairs from a file */
74
75 CHAR *ephemEarth; /**< Earth ephemeris file to use */
76 CHAR *ephemSun; /**< Sun ephemeris file to use */
77
78 LALStringVector *timeGPS; /**< GPS timestamps to compute detector state for (REAL8 format) */
79 LALStringVector *timeStampsFiles; /**< alternative: read in timestamps from file(s) */
80 INT4 Tsft; /**< assumed length of SFTs, needed for offset to timestamps when comparing to CFS_v2, PFS etc */
81
82 LALStringVector *noiseSqrtShX; /**< per-detector noise PSD sqrt(SX) */
83 BOOLEAN singleIFOweighting; /**< Normalize single-IFO quantities by single-IFO SX instead of Stot */
84
85 CHAR *outab; /**< output file for antenna pattern functions a(t), b(t) at each timestamp */
86 CHAR *outABCD; /**< output file for antenna pattern matrix elements A, B, C, D averaged over timestamps */
87
89
90/* ---------- global variables ----------*/
91extern int vrbflg;
92
93/* ---------- local prototypes ---------- */
95int XLALInitCode( ConfigVariables *cfg, const UserVariables_t *uvar, const char *app_name );
97
98/*============================================================
99 * FUNCTION definitions
100 *============================================================*/
101
102int
103main( int argc, char *argv[] )
104{
105
108
109 /* register user-variables */
110
112
113 /* read cmdline & cfgfile */
114 BOOLEAN should_exit = 0;
116 if ( should_exit ) {
117 exit( 1 );
118 }
119
120 /* basic setup and initializations */
121 XLAL_CHECK( XLALInitCode( &config, &uvar, argv[0] ) == XLAL_SUCCESS, XLAL_EFUNC );
122
123 /* prepare output files */
124 FILE *fpOutab = NULL;
125 if ( uvar.outab ) {
126
127 XLAL_CHECK( ( fpOutab = fopen( uvar.outab, "wb" ) ) != NULL, XLAL_EIO, "Error opening file '%s' for writing...", uvar.outab );
128
129 /* write header info in comments */
131
132 /* write the command-line */
133 for ( int a = 0; a < argc; a++ ) {
134 fprintf( fpOutab, "%%%% argv[%d]: '%s'\n", a, argv[a] );
135 }
136
137 /* write column headings */
138 fprintf( fpOutab, "%%%% columns:\n%%%% Alpha Delta tGPS " );
139 if ( config.numDetectors == 1 ) {
140 fprintf( fpOutab, " a(t) b(t)" );
141 } else {
142 for ( UINT4 X = 0; X < config.numDetectors; X++ ) {
143 char *detectorID;
144 detectorID = config.multiDetStates->data[X]->detector.frDetector.prefix;
145 fprintf( fpOutab, " a_%s(t) b_%s(t)", detectorID, detectorID );
146 }
147 }
148 fprintf( fpOutab, "\n" );
149
150 }
151
152 FILE *fpOutABCD = NULL;
153 if ( uvar.outABCD ) {
154
155 XLAL_CHECK( ( fpOutABCD = fopen( uvar.outABCD, "wb" ) ) != NULL, XLAL_EIO, "Error opening file '%s' for writing...", uvar.outABCD );
156
157 /* write header info in comments */
159
160 /* write the command-line */
161 for ( int a = 0; a < argc; a++ ) {
162 fprintf( fpOutABCD, "%%%% argv[%d]: '%s'\n", a, argv[a] );
163 }
164
165 /* write column headings */
166 fprintf( fpOutABCD, "%%%% columns:\n%%%% Alpha Delta" );
167 if ( config.numDetectors == 1 ) {
168 char *detectorID;
169 detectorID = config.multiDetStates->data[0]->detector.frDetector.prefix;
170 fprintf( fpOutABCD, " A_%s B_%s C_%s D_%s", detectorID, detectorID, detectorID, detectorID );
171 } else {
172 fprintf( fpOutABCD, " A B C D" );
173 }
174 if ( config.numDetectors > 1 ) {
175 fprintf( fpOutABCD, " " );
176 for ( UINT4 X = 0; X < config.numDetectors; X++ ) {
177 char *detectorID;
178 detectorID = config.multiDetStates->data[X]->detector.frDetector.prefix;
179 fprintf( fpOutABCD, " A_%s B_%s C_%s D_%s", detectorID, detectorID, detectorID, detectorID );
180 }
181 }
182 fprintf( fpOutABCD, "\n" );
183
184 }
185
186 /* loop over sky positions (outer loop, could allow for buffering if necessary) */
187 for ( UINT4 n = 0; n < config.numSkyPoints; n++ ) {
188 SkyPosition skypos;
190 skypos.longitude = config.Alpha->data[n];
191 skypos.latitude = config.Delta->data[n];
192
193 /* do the actual computation of the antenna pattern functions */
194 MultiAMCoeffs *multiAM;
195 XLAL_CHECK( ( multiAM = XLALComputeMultiAMCoeffs( config.multiDetStates, config.multiNoiseWeights, skypos ) ) != NULL, XLAL_EFUNC, "XLALComputeAMCoeffs() failed." );
196
197 /* for multi-IFO run with weights, do it again, without weights, to get single-IFO quantities consistent with single-IFO runs
198 * FIXME: remove this temporary hack when MultiAmCoeffs have been changed to include non-weighted single-IFO quantities
199 */
200 MultiAMCoeffs *multiAMforSingle = NULL;
201 MultiAMCoeffs *multiAMunweighted = NULL;
202 if ( uvar.singleIFOweighting && ( config.numDetectors > 1 ) && ( config.multiNoiseWeights != NULL ) ) {
203 XLAL_CHECK( ( multiAMunweighted = XLALComputeMultiAMCoeffs( config.multiDetStates, NULL, skypos ) ) != NULL, XLAL_EFUNC, "XLALComputeAMCoeffs() failed." );
204 multiAMforSingle = multiAMunweighted;
205 } else {
206 multiAMforSingle = multiAM;
207 }
208
209 /* write out the data for this sky point */
210 if ( uvar.outab ) { // output a(t), b(t) at each timestamp
211 for ( UINT4 t = 0; t < config.numTimeStampsX->data[0]; t++ ) { // FIXME: does not work for different multi-IFO numTimeStampsX
212 fprintf( fpOutab, "%.7f %.7f %d", config.Alpha->data[n], config.Delta->data[n], config.multiTimestamps->data[0]->data[t].gpsSeconds );
213 for ( UINT4 X = 0; X < config.numDetectors; X++ ) {
214 fprintf( fpOutab, " %12.8f %12.8f", multiAMforSingle->data[X]->a->data[t], multiAMforSingle->data[X]->b->data[t] );
215 } // for ( UINT4 X=0; X < config.numDetectors; X++ )
216 fprintf( fpOutab, "\n" );
217 } // for (UINT4 t = 0; t < config.numTimeStamps; t++)
218 } // if ( uvar.outab )
219
220 if ( uvar.outABCD ) { // output ABCD averaged over all timestamps
221 // FIXME: stop doing average manually when AMCoeffs is changed to contain averaged values
222 REAL8 A = multiAM->Mmunu.Ad / config.numTimeStamps;
223 REAL8 B = multiAM->Mmunu.Bd / config.numTimeStamps;
224 REAL8 C = multiAM->Mmunu.Cd / config.numTimeStamps;
225 REAL8 D = A * B - SQ( C );
226 fprintf( fpOutABCD, "%.7f %.7f %12.8f %12.8f %12.8f %12.8f", config.Alpha->data[n], config.Delta->data[n], A, B, C, D );
227 if ( config.numDetectors > 1 ) {
228 for ( UINT4 X = 0; X < config.numDetectors; X++ ) {
229 REAL4 AX = multiAMforSingle->data[X]->A / config.numTimeStampsX->data[X];
230 REAL4 BX = multiAMforSingle->data[X]->B / config.numTimeStampsX->data[X];
231 REAL4 CX = multiAMforSingle->data[X]->C / config.numTimeStampsX->data[X];
232 REAL4 DX = AX * BX - SQ( CX );
233 fprintf( fpOutABCD, " %12.8f %12.8f %12.8f %12.8f", AX, BX, CX, DX );
234 }
235 }
236 fprintf( fpOutABCD, "\n" );
237 } // if ( uvar.outABCD )
238
239 XLALDestroyMultiAMCoeffs( multiAM );
240 if ( multiAMunweighted ) {
241 XLALDestroyMultiAMCoeffs( multiAMunweighted );
242 }
243
244 } // for (UINT4 n = 0; n < config.numSkyPoints; n++)
245
246 /* ----- close output files ----- */
247 if ( fpOutab ) {
248 fprintf( fpOutab, "\n" );
249 fclose( fpOutab );
250 }
251 if ( fpOutABCD ) {
252 fprintf( fpOutABCD, "\n" );
253 fclose( fpOutABCD );
254 }
255
256 /* ----- done: free all memory */
258
260
261 return 0;
262} /* main */
263
264
265/** register all "user-variables" */
266int
268{
269 XLAL_CHECK( uvar != NULL, XLAL_EINVAL );
270
271 /* set a few defaults */
272 XLAL_CHECK( ( uvar->IFOs = XLALCreateStringVector( "H1", NULL ) ) != NULL, XLAL_ENOMEM, "Call to XLALCreateStringVector() failed." );
273
274 uvar->ephemEarth = XLALStringDuplicate( "earth00-40-DE405.dat.gz" );
275 uvar->ephemSun = XLALStringDuplicate( "sun00-40-DE405.dat.gz" );
276
277 uvar->Alpha = 0.0;
278 uvar->Delta = 0.0;
279 uvar->skyGridFile = NULL;
280
281 uvar->timeGPS = NULL;
282 uvar->outab = 0;
283 uvar->outABCD = 0;
284 uvar->singleIFOweighting = 0;
285 uvar->Tsft = 1800;
286
287 uvar->noiseSqrtShX = NULL;
288
289 /* register all user-variables */
290 XLALRegisterUvarMember( IFOs, STRINGVector, 'I', OPTIONAL, "Comma-separated list of detectors, eg. \"H1,H2,L1,G1, ...\" [only 1 detector supported at the moment] " );
291
292 XLALRegisterUvarMember( Alpha, REAL8, 'a', OPTIONAL, "single skyposition Alpha in radians, equatorial coords." );
293 XLALRegisterUvarMember( Delta, REAL8, 'd', OPTIONAL, "single skyposition Delta in radians, equatorial coords." );
294
295 XLALRegisterUvarMember( skyGridFile, STRING, 's', OPTIONAL, "Alternatively: sky-grid file" );
296
297 XLALRegisterUvarMember( timeGPS, STRINGVector, 't', OPTIONAL, "GPS time at which to compute detector states (separate multiple timestamps by commata)" );
298 XLALRegisterUvarMember( timeStampsFiles, STRINGVector, 'T', OPTIONAL, "Alternative: time-stamps file(s) (comma-separated list per IFO, or one for all)" );
299 XLALRegisterUvarMember( Tsft, INT4, 0, OPTIONAL, "Assumed length of one SFT in seconds; needed for timestamps offset consistency with F-stat based codes" );
300
301 XLALRegisterUvarMember( noiseSqrtShX, STRINGVector, 0, OPTIONAL, "Per-detector noise PSD sqrt(SX). Only ratios relevant to compute noise weights. Defaults to 1,1,..." );
302 XLALRegisterUvarMember( singleIFOweighting, BOOLEAN, 0, OPTIONAL, "Normalize single-IFO quantities by single-IFO SX instead of Stot" );
303
304 XLALRegisterUvarMember( ephemEarth, STRING, 0, OPTIONAL, "Earth ephemeris file to use" );
305 XLALRegisterUvarMember( ephemSun, STRING, 0, OPTIONAL, "Sun ephemeris file to use" );
306
307 XLALRegisterUvarMember( outab, STRING, 'o', OPTIONAL, "output file for antenna pattern functions a(t), b(t) at each timestamp" );
308 XLALRegisterUvarMember( outABCD, STRING, 'O', OPTIONAL, "output file for antenna pattern matrix elements A, B, C, D averaged over timestamps" );
309
310 return XLAL_SUCCESS;
311
312} /* XLALInitUserVars() */
313
314
315/**
316 * basic initializations: deal with user input and return standardized 'ConfigVariables'
317 */
318int
319XLALInitCode( ConfigVariables *cfg, const UserVariables_t *uvar, const char *app_name )
320{
321 XLAL_CHECK( cfg && uvar && app_name, XLAL_EINVAL, "Illegal NULL pointer input." );
322
323 /* init ephemeris data */
324 XLAL_CHECK( ( cfg->edat = XLALInitBarycenter( uvar->ephemEarth, uvar->ephemSun ) ) != NULL, XLAL_EFUNC, "XLALInitBarycenter failed: could not load Earth ephemeris '%s' and Sun ephemeris '%s.", uvar->ephemEarth, uvar->ephemSun );
325
326 cfg->numDetectors = uvar->IFOs->length;
327
328 cfg->numTimeStamps = 0;
329 XLAL_CHECK( ( cfg->numTimeStampsX = XLALCreateUINT4Vector( cfg->numDetectors ) ) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector(%d) failed.", cfg->numDetectors );
330
331 BOOLEAN haveTimeGPS = XLALUserVarWasSet( &uvar->timeGPS );
332 BOOLEAN haveTimeStampsFiles = XLALUserVarWasSet( &uvar->timeStampsFiles );
333
334 XLAL_CHECK( !( haveTimeGPS && haveTimeStampsFiles ), XLAL_EINVAL, "Can't handle both timeStampsFiles and timeGPS input options." );
335 XLAL_CHECK( haveTimeGPS || haveTimeStampsFiles, XLAL_EINVAL, "Need either timeStampsFiles or timeGPS input option." );
336 if ( haveTimeStampsFiles ) {
337 XLAL_CHECK( ( uvar->timeStampsFiles->length == 1 ) || ( uvar->timeStampsFiles->length == cfg->numDetectors ), XLAL_EINVAL, "Length of timeStampsFiles list is neither 1 (one file for all detectors) nor does it match the number of detectors. (%d != %d)", uvar->timeStampsFiles->length, cfg->numDetectors );
338 XLAL_CHECK( ( uvar->timeStampsFiles->length == 1 ) || !uvar->outab, XLAL_EINVAL, "At the moment, can't produce a(t), b(t) output (--outab) when given per-IFO --timeStampsFiles." );
339 }
340
341 if ( haveTimeStampsFiles && ( uvar->timeStampsFiles->length == cfg->numDetectors ) ) {
342
344
345 XLAL_CHECK( ( cfg->multiTimestamps->length > 0 ) && ( cfg->multiTimestamps->data != NULL ), XLAL_EINVAL, "Got empty timestamps-list from XLALReadMultiTimestampsFiles()" );
346
347 }
348
349 else {
350
351 /* prepare multiTimestamps structure */
352 UINT4 nTS = 0;
353 XLAL_CHECK( ( cfg->multiTimestamps = XLALCalloc( 1, sizeof( *cfg->multiTimestamps ) ) ) != NULL, XLAL_ENOMEM, "Allocating multiTimestamps failed." );
354 XLAL_CHECK( ( cfg->multiTimestamps->data = XLALCalloc( cfg->numDetectors, sizeof( cfg->multiTimestamps->data ) ) ) != NULL, XLAL_ENOMEM, "Allocating multiTimestamps->data failed." );
356
357 if ( haveTimeGPS ) { /* set up timestamps vector from timeGPS, use same for all IFOs */
358
359 nTS = uvar->timeGPS->length;
360 XLAL_CHECK( ( cfg->multiTimestamps->data[0] = XLALCreateTimestampVector( nTS ) ) != NULL, XLAL_EFUNC, "XLALCreateTimestampVector( %d ) failed.", nTS );
361
362 /* convert input REAL8 times into LIGOTimeGPS for first detector */
363 for ( UINT4 t = 0; t < nTS; t++ ) {
364 REAL8 temp_real8_timestamp = 0;
365 XLAL_CHECK( 1 == sscanf( uvar->timeGPS->data[t], "%" LAL_REAL8_FORMAT, &temp_real8_timestamp ), XLAL_EINVAL, "Illegal REAL8 commandline argument to --timeGPS[%d]: '%s'", t, uvar->timeGPS->data[t] );
366 XLAL_CHECK( XLALGPSSetREAL8( &cfg->multiTimestamps->data[0]->data[t], temp_real8_timestamp ) != NULL, XLAL_EFUNC, "Failed to convert input GPS %g into LIGOTimeGPS", temp_real8_timestamp );
367 } // for (UINT4 t = 0; t < nTS; t++)
368
369 } // if ( haveTimeGPS )
370
371 else { // haveTimeStampsFiles || haveTimeStampsFile
372
373 CHAR *singleTimeStampsFile = NULL;
374 if ( haveTimeStampsFiles ) {
375 singleTimeStampsFile = uvar->timeStampsFiles->data[0];
376 }
377
378 XLAL_CHECK( ( cfg->multiTimestamps->data[0] = XLALReadTimestampsFile( singleTimeStampsFile ) ) != NULL, XLAL_EFUNC );
379 nTS = cfg->multiTimestamps->data[0]->length;
380
381 } // else: haveTimeStampsFiles || haveTimeStampsFile
382
383 /* copy timestamps from first detector to all others */
384 if ( cfg->numDetectors > 1 ) {
385 for ( UINT4 X = 1; X < cfg->numDetectors; X++ ) {
386 XLAL_CHECK( ( cfg->multiTimestamps->data[X] = XLALCreateTimestampVector( nTS ) ) != NULL, XLAL_EFUNC, "XLALCreateTimestampVector( %d ) failed.", nTS );
387 for ( UINT4 t = 0; t < nTS; t++ ) {
390 } // for (UINT4 t = 0; t < nTS; t++)
391 } // for ( UINT4 X=1; X < cfg->numDetectors X++ )
392 } // if ( cfg->numDetectors > 1 )
393
394 } // if !( haveTimeStampsFiles && ( uvar->timeStampsFiles->length == cfg->numDetectors ) )
395
396 for ( UINT4 X = 0; X < cfg->numDetectors; X++ ) {
397 cfg->numTimeStampsX->data[X] = cfg->multiTimestamps->data[X]->length;
398 cfg->numTimeStamps += cfg->numTimeStampsX->data[X];
399 }
400
401 /* convert detector names into site-info */
402 MultiLALDetector multiDet;
404
405 /* get detector states */
406 XLAL_CHECK( ( cfg->multiDetStates = XLALGetMultiDetectorStates( cfg->multiTimestamps, &multiDet, cfg->edat, 0.5 * uvar->Tsft ) ) != NULL, XLAL_EFUNC, "XLALGetDetectorStates() failed." );
407
408 BOOLEAN haveAlphaDelta = ( XLALUserVarWasSet( &uvar->Alpha ) && XLALUserVarWasSet( &uvar->Delta ) );
409 BOOLEAN haveSkyGrid = XLALUserVarWasSet( &uvar->skyGridFile );
410
411 XLAL_CHECK( !( haveAlphaDelta && haveSkyGrid ), XLAL_EINVAL, "Can't handle both Alpha/Delta and skyGridFile input options." );
412 XLAL_CHECK( haveAlphaDelta || haveSkyGrid, XLAL_EINVAL, "Need either Alpha/Delta or skyGridFile input option." );
413
414 if ( haveAlphaDelta ) { /* parse this into one-element Alpha, Delta vectors */
415 XLAL_CHECK( ( cfg->Alpha = XLALCreateREAL8Vector( 1 ) ) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector(1) failed." );
416 cfg->Alpha->data[0] = uvar->Alpha;
417 XLAL_CHECK( ( cfg->Delta = XLALCreateREAL8Vector( 1 ) ) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector(1) failed." );
418 cfg->Delta->data[0] = uvar->Delta;
419 cfg->numSkyPoints = 1;
420 } // if (haveAlphaDelta)
421
422 else if ( haveSkyGrid ) {
423 LALParsedDataFile *data = NULL;
424 XLAL_CHECK( XLALParseDataFile( &data, uvar->skyGridFile ) == XLAL_SUCCESS, XLAL_EFUNC, "Failed to parse data file '%s'.", uvar->skyGridFile );
425 cfg->numSkyPoints = data->lines->nTokens;
426 XLAL_CHECK( ( cfg->Alpha = XLALCreateREAL8Vector( cfg->numSkyPoints ) ) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector( %d ) failed.", cfg->numSkyPoints );
427 XLAL_CHECK( ( cfg->Delta = XLALCreateREAL8Vector( cfg->numSkyPoints ) ) != NULL, XLAL_EFUNC, "XLALCreateREAL8Vector( %d ) failed.", cfg->numSkyPoints );
428 for ( UINT4 n = 0; n < cfg->numSkyPoints; n++ ) {
429 XLAL_CHECK( 2 == sscanf( data->lines->tokens[n], "%" LAL_REAL8_FORMAT "%" LAL_REAL8_FORMAT, &cfg->Alpha->data[n], &cfg->Delta->data[n] ), XLAL_EDATA, "Could not parse 2 numbers from line %d in candidate-file '%s':\n'%s'", n, uvar->skyGridFile, data->lines->tokens[n] );
430 } // for (UINT4 n=0; n < cfg->numSkyPoints; n++)
432 } // else if ( haveSkyGrid )
433
434 if ( uvar->noiseSqrtShX ) { /* translate user-input PSD sqrt(SX) to noise-weights (this actually does not care whether they were normalized or not) */
435
436 if ( uvar->noiseSqrtShX->length != cfg->numDetectors ) {
437 fprintf( stderr, "Length of noiseSqrtShX vector does not match number of detectors! (%d != %d)\n", uvar->noiseSqrtShX->length, cfg->numDetectors );
439 }
440 REAL8Vector *noiseSqrtShX = NULL;
441 if ( ( noiseSqrtShX = XLALCreateREAL8Vector( cfg->numDetectors ) ) == NULL ) {
442 fprintf( stderr, "Failed call to XLALCreateREAL8Vector( %d )\n", cfg->numDetectors );
444 }
445
446 REAL8 psd_normalization = 0;
447
448 for ( UINT4 X = 0; X < cfg->numDetectors; X++ ) {
449
450 if ( 1 != sscanf( uvar->noiseSqrtShX->data[X], "%" LAL_REAL8_FORMAT, &noiseSqrtShX->data[X] ) ) {
451 fprintf( stderr, "Illegal REAL8 commandline argument to --noiseSqrtShX[%d]: '%s'\n", X, uvar->noiseSqrtShX->data[X] );
453 }
454
455 if ( noiseSqrtShX->data[X] <= 0.0 ) {
456 fprintf( stderr, "Non-positive input PSD ratio for detector X=%d: noiseSqrtShX[X]=%f\n", X, noiseSqrtShX->data[X] );
458 }
459
460 psd_normalization += 1.0 / SQ( noiseSqrtShX->data[X] );
461
462 } /* for X < cfg->numDetectors */
463
464 psd_normalization = ( REAL8 )cfg->numDetectors / psd_normalization; /* S = NSFT / sum S_Xalpha^-1, no per-SFT variation here -> S = Ndet / sum S_X^-1 */
465
466 /* create multi noise weights */
467 if ( ( cfg->multiNoiseWeights = XLALCalloc( 1, sizeof( *cfg->multiNoiseWeights ) ) ) == NULL ) {
468 XLALPrintError( "%s: failed to XLALCalloc ( 1, %zu )\n", __func__, sizeof( *cfg->multiNoiseWeights ) );
470 }
471 if ( ( cfg->multiNoiseWeights->data = XLALCalloc( cfg->numDetectors, sizeof( *cfg->multiNoiseWeights->data ) ) ) == NULL ) {
472 XLALPrintError( "%s: failed to XLALCalloc ( %d, %zu )\n", __func__, cfg->numDetectors, sizeof( *cfg->multiNoiseWeights->data ) );
474 }
476
477 for ( UINT4 X = 0; X < cfg->numDetectors; X++ ) {
478
479 REAL8 noise_weight_X = psd_normalization / SQ( noiseSqrtShX->data[X] ); /* w_Xalpha = S_Xalpha^-1/S^-1 = S / S_Xalpha */
480
481 /* create k^th weights vector */
482 if ( ( cfg->multiNoiseWeights->data[X] = XLALCreateREAL8Vector( cfg->numTimeStampsX->data[X] ) ) == NULL ) {
483 /* free weights vectors created previously in loop */
485 XLAL_ERROR( XLAL_EFUNC, "Failed to allocate noiseweights for IFO X = %d\n", X );
486 } /* if XLALCreateREAL8Vector() failed */
487
488 /* loop over rngmeds and calculate weights -- one for each sft */
489 for ( UINT4 alpha = 0; alpha < cfg->numTimeStampsX->data[X]; alpha++ ) {
490 cfg->multiNoiseWeights->data[X]->data[alpha] = noise_weight_X;
491 }
492
493 } /* for X < cfg->numDetectors */
494
495 XLALDestroyREAL8Vector( noiseSqrtShX );
496
497 } /* if ( uvar->noiseSqrtShX ) */
498
499 else {
500 cfg->multiNoiseWeights = NULL;
501 }
502
503 return XLAL_SUCCESS;
504
505} /* XLALInitCode() */
506
507
508/** Destructor for internal configuration struct */
509int
511{
512 XLAL_CHECK( cfg != NULL, XLAL_EINVAL );
513
515
518
521
523
526
527 return XLAL_SUCCESS;
528
529} /* XLALDestroyConfig() */
int main(int argc, char *argv[])
int XLALDestroyConfig(ConfigVariables *cfg)
Destructor for internal configuration struct.
int vrbflg
defined in lal/lib/std/LALError.c
#define SQ(x)
int XLALInitCode(ConfigVariables *cfg, const UserVariables_t *uvar, const char *app_name)
basic initializations: deal with user input and return standardized 'ConfigVariables'
int XLALInitUserVars(UserVariables_t *uvar)
register all "user-variables"
#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
#define D(j)
#define STRING(a)
UINT2 A
Definition: SFTnaming.c:46
UINT2 B
Definition: SFTnaming.c:47
#define fprintf
int XLALParseDataFile(LALParsedDataFile **cfgdata, const CHAR *fname)
void XLALDestroyParsedDataFile(LALParsedDataFile *cfgdata)
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.
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
float REAL4
void * XLALCalloc(size_t m, size_t n)
#define LAL_REAL8_FORMAT
char char * XLALStringDuplicate(const char *s)
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
void XLALDestroyMultiNoiseWeights(MultiNoiseWeights *weights)
Destroy a MultiNoiseWeights object.
Definition: PSDutils.c:172
static const INT4 a
LIGOTimeGPSVector * XLALCreateTimestampVector(UINT4 len)
Allocate a LIGOTimeGPSVector.
Definition: SFTtimestamps.c:47
LIGOTimeGPSVector * XLALReadTimestampsFile(const CHAR *fname)
backwards compatible wrapper to XLALReadTimestampsFileConstrained() without GPS-time constraints
void XLALDestroyMultiTimestamps(MultiLIGOTimeGPSVector *multiTS)
Destroy a MultiLIGOTimeGPSVector timestamps vector.
MultiLIGOTimeGPSVector * XLALReadMultiTimestampsFiles(const LALStringVector *fnames)
backwards compatible wrapper to XLALReadMultiTimestampsFilesConstrained() without GPS-time constraint...
COORDINATESYSTEM_EQUATORIAL
LALStringVector * XLALCreateStringVector(const CHAR *str1,...)
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define XLALRegisterUvarMember(name, type, option, category,...)
int XLALUserVarWasSet(const void *cvar)
void XLALDestroyUINT4Vector(UINT4Vector *vector)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
UINT4Vector * XLALCreateUINT4Vector(UINT4 length)
#define XLAL_ERROR(...)
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_ENOMEM
XLAL_EDATA
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EIO
XLAL_EINVAL
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
float data[BLOCKSIZE]
Definition: hwinject.c:360
n
double alpha
REAL4 B
summed antenna-pattern matrix coefficient:
Definition: LALComputeAM.h:67
REAL4Vector * b
(weighted) per-SFT antenna-pattern function
Definition: LALComputeAM.h:65
REAL4 A
summed antenna-pattern matrix coefficient:
Definition: LALComputeAM.h:66
REAL4 C
summed antenna-pattern matrix coefficient:
Definition: LALComputeAM.h:68
REAL4Vector * a
(weighted) per-SFT antenna-pattern function
Definition: LALComputeAM.h:64
Configuration settings required for and defining a coherent pulsar search.
UINT4 numTimeStamps
number of timestamps (SFTs) for all detectors
REAL8 Alpha
sky position alpha in radians
MultiDetectorStateSeries * multiDetStates
multi-detector state series covering observation time
UINT4 numDetectors
number of detectors
REAL8Vector * Alpha
skyposition Alpha: radians, equatorial coords
UINT4 numSkyPoints
common length of Alpha and Delta vectors
MultiLIGOTimeGPSVector * multiTimestamps
a vector of timestamps (only set if provided from dedicated time stamp files)
UINT4Vector * numTimeStampsX
number of timestamps (SFTs) per detector
MultiNoiseWeights * multiNoiseWeights
per-detector noise weights SX^-1/S^-1, no per-SFT variation (can be NULL for unit weights)
REAL8 Delta
sky position delta in radians
REAL8Vector * Delta
skyposition Delta: radians, equatorial coords
EphemerisData * edat
ephemeris data
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
INT4 gpsNanoSeconds
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
AMCoeffs ** data
noise-weighted AM-coeffs , and
Definition: LALComputeAM.h:142
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
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
Definition: PSDutils.h:71
UINT4 length
number of detectors
Definition: PSDutils.h:75
REAL8Vector ** data
weights-vector for each detector
Definition: PSDutils.h:76
REAL4 * data
REAL8 * data
REAL8 longitude
REAL8 latitude
CoordinateSystem system
UINT4 * data
user input variables
Definition: compareFstats.c:51
REAL8 Alpha
Right ascension [radians] alpha of pulsar.
CHAR * ephemSun
Sun ephemeris file to use.
CHAR * outab
output file for antenna pattern functions a(t), b(t) at each timestamp
CHAR * ephemEarth
Earth ephemeris file to use.
LALStringVector * timeStampsFiles
alternative: read in timestamps from file(s)
REAL8 Delta
Declination [radians] delta of pulsar.
BOOLEAN singleIFOweighting
Normalize single-IFO quantities by single-IFO SX instead of Stot.
REAL8 Tsft
SFT time baseline Tsft.
LALStringVector * IFOs
list of detector-names "H1,H2,L1,.." or single detector
CHAR * outABCD
output file for antenna pattern matrix elements A, B, C, D averaged over timestamps
CHAR * skyGridFile
alternative: matrix of (Alpha,Delta) pairs from a file
INT4 Tsft
assumed length of SFTs, needed for offset to timestamps when comparing to CFS_v2, PFS etc
LALStringVector * timeGPS
GPS timestamps to compute detector state for (REAL8 format)
LALStringVector * noiseSqrtShX
per-detector noise PSD sqrt(SX)