LALPulsar 7.1.2.1-bf6a62b
ValidateHoughMultiChi2Test.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006 Llucia Sancho de la Jordana,
3 * Badri Krishnan, Alicia M. Sintes
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 * \file
23 * \ingroup lalpulsar_bin_Hough
24 * \author Badri Krishnan, Alicia Sintes
25 * \brief Driver code for performing Hough transform search on non-demodulated
26 * data using SFTs from possible multiple IFOs
27 *
28 * History: Created by Sancho de la Jordana, Sintes and Krishnan December 15, 2006
29 */
30
31
32#include "DriveHoughColor.h"
33#include "MCInjectHoughMulti.h"
34
35/* globals, constants and defaults */
36
37/* boolean global variables for controlling output */
39
40/* #define EARTHEPHEMERIS "./earth05-09.dat" */
41/* #define SUNEPHEMERIS "./sun05-09.dat" */
42
43#define EARTHEPHEMERIS "/home/llucia/chi2/earth05-09.dat"
44#define SUNEPHEMERIS "/home/llucia/chi2/sun05-09.dat"
45
46#define MAXFILENAMELENGTH 512 /* maximum # of characters of a filename */
47
48#define DIROUT "./outMultiChi2Test" /* output directory */
49#define BASENAMEOUT "HM" /* prefix file output */
50
51#define THRESHOLD 1.6 /* thresold for peak selection, with respect to the
52 the averaged power in the search band */
53#define FALSEALARM 1.0e-9 /* Hough false alarm for candidate selection */
54#define SKYFILE "./skypatchfile"
55#define F0 310.0 /* frequency to build the LUT and start search */
56#define FBAND 0.05 /* search frequency band */
57#define NFSIZE 21 /* n-freq. span of the cylinder, to account for spin-down search */
58#define BLOCKSRNGMED 101 /* Running median window size */
60#define TRUE (1==1)
61#define FALSE (1==0)
63#define NBLOCKSTEST 8 /* number of data blocks to do Chi2 test */
64
66#define SFTDIRECTORY "/local_data/sintes/SFT-S5-120-130/*SFT*.*"
67
68/* local function prototype */
69
70
71
72/* ****************************************
73 * Structure, HoughParamsTest, typedef
74 */
75
76typedef struct tagHoughParamsTest {
77 UINT4 length; /* number p of blocks to split the data into */
78 UINT4 *numberSFTp; /* Ni SFTs in each data block */
79 REAL8 *sumWeight; /* Pointer to the sumWeight of each block of data */
80 REAL8 *sumWeightSquare; /* Pointer to the sumWeightSquare of each block of data */
82
83/******************************************/
84
85/* function to Split the SFTs into p blocks */
86
88 REAL8Vector *weightsV,
89 HoughParamsTest *chi2Params );
90
91
92/******************************************/
94int main( int argc, char *argv[] )
95{
96
97 /* LALStatus pointer */
98 static LALStatus status;
99
100 /* time and velocity */
101 static LIGOTimeGPSVector timeV;
102 static REAL8Cart3CoorVector velV;
103 static REAL8Vector timeDiffV;
104 LIGOTimeGPS firstTimeStamp;
105
106 /* standard pulsar sft types */
107 MultiSFTVector *inputSFTs = NULL;
108 UINT4 binsSFT;
109 UINT4 sftFminBin;
110 UINT4 numsft;
111
112 INT4 k;
113 FILE *fp = NULL;
114
115 /* information about all the ifos */
116 MultiDetectorStateSeries *mdetStates = NULL;
117 UINT4 numifo;
118
119 /* vector of weights */
120 REAL8Vector weightsV;
121
122 /* ephemeris */
123 EphemerisData *edat = NULL;
124
125 static UCHARPeakGram pg1;
126 static HoughTemplate pulsarTemplate;
127 static REAL8Vector foft;
128
129 /* miscellaneous */
130 UINT4 mObsCoh;
131 REAL8 timeBase, deltaF;
132 REAL8 numberCount;
133
134 /* Chi2Test parameters */
135 HoughParamsTest chi2Params;
136 REAL8Vector numberCountV; /* Vector with the number count of each block inside */
137 REAL8 numberCountTotal; /* Sum over all the numberCounts */
138 REAL8 chi2;
139
140 /* sft constraint variables */
141 LIGOTimeGPS startTimeGPS, endTimeGPS;
142 LIGOTimeGPSVector *inputTimeStampsVector = NULL;
143
144
145 REAL8 alphaPeak, meanN, sigmaN;
146
147 /* user input variables */
148 BOOLEAN uvar_weighAM, uvar_weighNoise;
149 INT4 uvar_blocksRngMed, uvar_nfSizeCylinder, uvar_maxBinsClean;
151 REAL8 uvar_fStart, uvar_peakThreshold, uvar_fSearchBand;
152 REAL8 uvar_Alpha, uvar_Delta, uvar_Freq, uvar_fdot;
153 REAL8 uvar_AlphaWeight, uvar_DeltaWeight;
154 CHAR *uvar_earthEphemeris = NULL;
155 CHAR *uvar_sunEphemeris = NULL;
156 CHAR *uvar_sftDir = NULL;
157 CHAR *uvar_timeStampsFile = NULL;
158 CHAR *uvar_outfile = NULL;
159 LALStringVector *uvar_linefiles = NULL;
160 INT4 uvar_p;
161
162
163 /* Set up the default parameters */
164
165 /* LAL error-handler */
167
168 uvar_weighAM = TRUE;
169 uvar_weighNoise = TRUE;
171 uvar_nfSizeCylinder = NFSIZE;
172 uvar_fStart = F0;
173 uvar_fSearchBand = FBAND;
174 uvar_peakThreshold = THRESHOLD;
175 uvar_maxBinsClean = 100;
176 uvar_startTime = 0;
178
179 uvar_Alpha = 1.0;
180 uvar_Delta = 1.0;
181 uvar_Freq = 310.0;
182 uvar_fdot = 0.0;
183
184 uvar_AlphaWeight = uvar_Alpha;
185 uvar_DeltaWeight = uvar_Delta;
186
187 uvar_p = NBLOCKSTEST;
188 chi2Params.length = uvar_p;
189 chi2Params.numberSFTp = NULL;
190 chi2Params.sumWeight = NULL;
191 chi2Params.sumWeightSquare = NULL;
192
193 uvar_outfile = ( CHAR * )LALCalloc( MAXFILENAMELENGTH, sizeof( CHAR ) );
194 strcpy( uvar_outfile, "./tempout" );
195
196 uvar_earthEphemeris = ( CHAR * )LALCalloc( MAXFILENAMELENGTH, sizeof( CHAR ) );
197 strcpy( uvar_earthEphemeris, EARTHEPHEMERIS );
198
199 uvar_sunEphemeris = ( CHAR * )LALCalloc( MAXFILENAMELENGTH, sizeof( CHAR ) );
200 strcpy( uvar_sunEphemeris, SUNEPHEMERIS );
201
202
203 uvar_sftDir = ( CHAR * )LALCalloc( MAXFILENAMELENGTH, sizeof( CHAR ) );
204 strcpy( uvar_sftDir, SFTDIRECTORY );
205
206
207 /* register user input variables */
208 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_fStart, "fStart", REAL8, 'f', OPTIONAL, "Start search frequency" ) == XLAL_SUCCESS, XLAL_EFUNC );
209 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_fSearchBand, "fSearchBand", REAL8, 'b', OPTIONAL, "Search frequency band" ) == XLAL_SUCCESS, XLAL_EFUNC );
210 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_startTime, "startTime", REAL8, 0, OPTIONAL, "GPS start time of observation" ) == XLAL_SUCCESS, XLAL_EFUNC );
211 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_endTime, "endTime", REAL8, 0, OPTIONAL, "GPS end time of observation" ) == XLAL_SUCCESS, XLAL_EFUNC );
212 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_timeStampsFile, "timeStampsFile", STRING, 0, OPTIONAL, "Input time-stamps file" ) == XLAL_SUCCESS, XLAL_EFUNC );
213 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_peakThreshold, "peakThreshold", REAL8, 0, OPTIONAL, "Peak selection threshold" ) == XLAL_SUCCESS, XLAL_EFUNC );
214 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_weighAM, "weighAM", BOOLEAN, 0, OPTIONAL, "Use amplitude modulation weights" ) == XLAL_SUCCESS, XLAL_EFUNC );
215 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_weighNoise, "weighNoise", BOOLEAN, 0, OPTIONAL, "Use SFT noise weights" ) == XLAL_SUCCESS, XLAL_EFUNC );
216 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_earthEphemeris, "earthEphemeris", STRING, 'E', OPTIONAL, "Earth Ephemeris file" ) == XLAL_SUCCESS, XLAL_EFUNC );
217 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_sunEphemeris, "sunEphemeris", STRING, 'S', OPTIONAL, "Sun Ephemeris file" ) == XLAL_SUCCESS, XLAL_EFUNC );
218 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_sftDir, "sftDir", STRING, 'D', REQUIRED, "SFT filename pattern. Possibilities are:\n"
219 " - '<SFT file>;<SFT file>;...', where <SFT file> may contain wildcards\n - 'list:<file containing list of SFT files>'" ) == XLAL_SUCCESS, XLAL_EFUNC );
220 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_linefiles, "linefiles", STRINGVector, 0, OPTIONAL, "Comma separated List of linefiles (filenames must contain IFO name)" ) == XLAL_SUCCESS, XLAL_EFUNC );
221
222 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_Alpha, "Alpha", REAL8, 0, OPTIONAL, "Sky location (longitude)" ) == XLAL_SUCCESS, XLAL_EFUNC );
223 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_Delta, "Delta", REAL8, 0, OPTIONAL, "Sky location (latitude)" ) == XLAL_SUCCESS, XLAL_EFUNC );
224 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_Freq, "Freq", REAL8, 0, OPTIONAL, "Template frequency" ) == XLAL_SUCCESS, XLAL_EFUNC );
225 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_fdot, "fdot", REAL8, 0, OPTIONAL, "First spindown" ) == XLAL_SUCCESS, XLAL_EFUNC );
226
227 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_AlphaWeight, "AlphaWeight", REAL8, 0, OPTIONAL, "sky Alpha for weight calculation" ) == XLAL_SUCCESS, XLAL_EFUNC );
228 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_DeltaWeight, "DeltaWeight", REAL8, 0, OPTIONAL, "sky Delta for weight calculation" ) == XLAL_SUCCESS, XLAL_EFUNC );
229
230 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_nfSizeCylinder, "nfSizeCylinder", INT4, 0, OPTIONAL, "Size of cylinder of PHMDs" ) == XLAL_SUCCESS, XLAL_EFUNC );
231
232 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_blocksRngMed, "blocksRngMed", INT4, 0, OPTIONAL, "Running Median block size" ) == XLAL_SUCCESS, XLAL_EFUNC );
233 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_maxBinsClean, "maxBinsClean", INT4, 0, OPTIONAL, "Maximum number of bins in cleaning" ) == XLAL_SUCCESS, XLAL_EFUNC );
234 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_outfile, "outfile", STRING, 0, OPTIONAL, "output file name" ) == XLAL_SUCCESS, XLAL_EFUNC );
235
236 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_p, "pdatablock", INT4, 'p', OPTIONAL, "Number of data blocks for veto tests" ) == XLAL_SUCCESS, XLAL_EFUNC );
237
238
239 /* read all command line variables */
240 BOOLEAN should_exit = 0;
242 if ( should_exit ) {
243 exit( 1 );
244 }
245
246 /* very basic consistency checks on user input */
247 if ( uvar_fStart < 0 ) {
248 fprintf( stderr, "start frequency must be positive\n" );
249 exit( 1 );
250 }
251
252 if ( uvar_fSearchBand < 0 ) {
253 fprintf( stderr, "search frequency band must be positive\n" );
254 exit( 1 );
255 }
256
257 if ( uvar_peakThreshold < 0 ) {
258 fprintf( stderr, "peak selection threshold must be positive\n" );
259 exit( 1 );
260 }
261
262
263 /***** start main calculations *****/
264
265 chi2Params.length = uvar_p;
266 chi2Params.numberSFTp = ( UINT4 * )LALMalloc( uvar_p * sizeof( UINT4 ) );
267 chi2Params.sumWeight = ( REAL8 * )LALMalloc( uvar_p * sizeof( REAL8 ) );
268 chi2Params.sumWeightSquare = ( REAL8 * )LALMalloc( uvar_p * sizeof( REAL8 ) );
269
270
271 /* read sft Files and set up weights */
272 {
273 /* new SFT I/O data types */
274 SFTCatalog *catalog = NULL;
275 static SFTConstraints constraints;
276
277 REAL8 doppWings, f_min, f_max;
278
279 /* set detector constraint */
280 constraints.detector = NULL;
281
283 XLALGPSSetREAL8( &startTimeGPS, uvar_startTime );
284 constraints.minStartTime = &startTimeGPS;
285 }
286
288 XLALGPSSetREAL8( &endTimeGPS, uvar_endTime );
289 constraints.maxStartTime = &endTimeGPS;
290 }
291
292 if ( XLALUserVarWasSet( &uvar_timeStampsFile ) ) {
293 XLAL_CHECK_MAIN( ( inputTimeStampsVector = XLALReadTimestampsFile( uvar_timeStampsFile ) ) != NULL, XLAL_EFUNC );
294 constraints.timestamps = inputTimeStampsVector;
295 }
296
297 /* get sft catalog */
298 XLAL_CHECK_MAIN( ( catalog = XLALSFTdataFind( uvar_sftDir, &constraints ) ) != NULL, XLAL_EFUNC );
299 if ( ( catalog == NULL ) || ( catalog->length == 0 ) ) {
300 fprintf( stderr, "Unable to match any SFTs with pattern '%s'\n", uvar_sftDir );
301 exit( 1 );
302 }
303
304 /* now we can free the inputTimeStampsVector */
305 if ( XLALUserVarWasSet( &uvar_timeStampsFile ) ) {
306 XLALDestroyTimestampVector( inputTimeStampsVector );
307 }
308
309 /* get some sft parameters */
310 mObsCoh = catalog->length; /* number of sfts */
311 deltaF = catalog->data->header.deltaF; /* frequency resolution */
312 timeBase = 1.0 / deltaF; /* coherent integration time */
313 // unused: UINT8 f0Bin = floor( uvar_fStart * timeBase + 0.5); /* initial search frequency */
314 // unused: INT4 length = uvar_fSearchBand * timeBase; /* total number of search bins - 1 */
315
316 /* catalog is ordered in time so we can get start, end time and tObs*/
317 firstTimeStamp = catalog->data[0].header.epoch;
318 // unused: LIGOTimeGPS lastTimeStamp = catalog->data[mObsCoh - 1].header.epoch;
319
320 /* allocate memory for velocity vector */
321 velV.length = mObsCoh;
322 velV.data = NULL;
323 velV.data = ( REAL8Cart3Coor * )LALCalloc( mObsCoh, sizeof( REAL8Cart3Coor ) );
324
325 /* allocate memory for timestamps vector */
326 timeV.length = mObsCoh;
327 timeV.data = NULL;
328 timeV.data = ( LIGOTimeGPS * )LALCalloc( mObsCoh, sizeof( LIGOTimeGPS ) );
329
330 /* allocate memory for vector of time differences from start */
331 timeDiffV.length = mObsCoh;
332 timeDiffV.data = NULL;
333 timeDiffV.data = ( REAL8 * )LALCalloc( mObsCoh, sizeof( REAL8 ) );
334
335 /* add wings for Doppler modulation and running median block size*/
336 doppWings = ( uvar_fStart + uvar_fSearchBand ) * VTOT;
337 f_min = uvar_fStart - doppWings - ( uvar_blocksRngMed + uvar_nfSizeCylinder ) * deltaF;
338 f_max = uvar_fStart + uvar_fSearchBand + doppWings + ( uvar_blocksRngMed + uvar_nfSizeCylinder ) * deltaF;
339
340 /* read sft files making sure to add extra bins for running median */
341 /* read the sfts */
342 XLAL_CHECK_MAIN( ( inputSFTs = XLALLoadMultiSFTs( catalog, f_min, f_max ) ) != NULL, XLAL_EFUNC );
343
344
345 /* clean sfts if required */
346 if ( XLALUserVarWasSet( &uvar_linefiles ) ) {
347 RandomParams *randPar = NULL;
348 FILE *fpRand = NULL;
349 INT4 seed, ranCount;
350
351 if ( ( fpRand = fopen( "/dev/urandom", "r" ) ) == NULL ) {
352 fprintf( stderr, "Error in opening /dev/urandom" );
353 exit( 1 );
354 }
355
356 if ( ( ranCount = fread( &seed, sizeof( seed ), 1, fpRand ) ) != 1 ) {
357 fprintf( stderr, "Error in getting random seed" );
358 exit( 1 );
359 }
360
361 LAL_CALL( LALCreateRandomParams( &status, &randPar, seed ), &status );
362
363 LAL_CALL( LALRemoveKnownLinesInMultiSFTVector( &status, inputSFTs, uvar_maxBinsClean, uvar_blocksRngMed, uvar_linefiles, randPar ), &status );
364
365 LAL_CALL( LALDestroyRandomParams( &status, &randPar ), &status );
366 fclose( fpRand );
367 } /* end cleaning */
368
369
370 /* SFT info -- assume all SFTs have same length */
371 numifo = inputSFTs->length;
372 binsSFT = inputSFTs->data[0]->data->data->length;
373 sftFminBin = ( INT4 ) floor( inputSFTs->data[0]->data[0].f0 * timeBase + 0.5 );
374
375
376 XLALDestroySFTCatalog( catalog );
377
378 } /* end of sft reading block */
379
380
381
382 /* get detector velocities weights vector, and timestamps */
383 {
384 MultiNoiseWeights *multweight = NULL;
385 MultiPSDVector *multPSD = NULL;
386 UINT4 iIFO, iSFT, j;
387
388 /* get ephemeris */
389 XLAL_CHECK_MAIN( ( edat = XLALInitBarycenter( uvar_earthEphemeris, uvar_sunEphemeris ) ) != NULL, XLAL_EFUNC );
390
391
392 /* normalize sfts */
393 XLAL_CHECK_MAIN( ( multPSD = XLALNormalizeMultiSFTVect( inputSFTs, uvar_blocksRngMed, NULL ) ) != NULL, XLAL_EFUNC );
394
395 /* set up weights */
396 weightsV.length = mObsCoh;
397 weightsV.data = ( REAL8 * )LALCalloc( 1, mObsCoh * sizeof( REAL8 ) );
398
399 /* initialize all weights to unity */
401
402 /* compute multi noise weights if required */
403 if ( uvar_weighNoise ) {
404 XLAL_CHECK_MAIN( ( multweight = XLALComputeMultiNoiseWeights( multPSD, uvar_blocksRngMed, 0 ) ) != NULL, XLAL_EFUNC );
405 }
406
407 /* we are now done with the psd */
408 XLALDestroyMultiPSDVector( multPSD );
409
410 /* get information about all detectors including velocity and timestamps */
411 /* note that this function returns the velocity at the
412 mid-time of the SFTs -- should not make any difference */
413 const REAL8 tOffset = 0.5 / inputSFTs->data[0]->data[0].deltaF;
414 XLAL_CHECK_MAIN( ( mdetStates = XLALGetMultiDetectorStatesFromMultiSFTs( inputSFTs, edat, tOffset ) ) != NULL, XLAL_EFUNC );
415
416 /* copy the timestamps, weights, and velocity vector */
417 for ( j = 0, iIFO = 0; iIFO < numifo; iIFO++ ) {
418
419 numsft = mdetStates->data[iIFO]->length;
420
421 for ( iSFT = 0; iSFT < numsft; iSFT++, j++ ) {
422
423 velV.data[j].x = mdetStates->data[iIFO]->data[iSFT].vDetector[0];
424 velV.data[j].y = mdetStates->data[iIFO]->data[iSFT].vDetector[1];
425 velV.data[j].z = mdetStates->data[iIFO]->data[iSFT].vDetector[2];
426
427 if ( uvar_weighNoise ) {
428 weightsV.data[j] = multweight->data[iIFO]->data[iSFT];
429 }
430
431 /* mid time of sfts */
432 timeV.data[j] = mdetStates->data[iIFO]->data[iSFT].tGPS;
433
434 } /* loop over SFTs */
435
436 } /* loop over IFOs */
437
438 if ( uvar_weighNoise ) {
440 }
441
442 /* compute the time difference relative to startTime for all SFTs */
443 for ( j = 0; j < mObsCoh; j++ ) {
444 timeDiffV.data[j] = XLALGPSDiff( timeV.data + j, &firstTimeStamp );
445 }
446
447 if ( uvar_weighNoise ) {
448 XLALDestroyMultiNoiseWeights( multweight );
449 }
450
451 } /* end block for noise weights, velocity and time */
452
453
454
455 /* calculate amplitude modulation weights if required */
456 if ( uvar_weighAM ) {
457 MultiAMCoeffs *multiAMcoef = NULL;
458 UINT4 iIFO, iSFT;
459 SkyPosition skypos;
460
461 /* get the amplitude modulation coefficients */
462 skypos.longitude = uvar_AlphaWeight;
463 skypos.latitude = uvar_DeltaWeight;
465 XLAL_CHECK_MAIN( ( multiAMcoef = XLALComputeMultiAMCoeffs( mdetStates, NULL, skypos ) ) != NULL, XLAL_EFUNC );
466
467 /* loop over the weights and multiply them by the appropriate
468 AM coefficients */
469 for ( k = 0, iIFO = 0; iIFO < numifo; iIFO++ ) {
470
471 numsft = mdetStates->data[iIFO]->length;
472
473 for ( iSFT = 0; iSFT < numsft; iSFT++, k++ ) {
474
475 REAL8 a, b;
476
477 a = multiAMcoef->data[iIFO]->a->data[iSFT];
478 b = multiAMcoef->data[iIFO]->b->data[iSFT];
479 weightsV.data[k] *= ( a * a + b * b );
480 } /* loop over SFTs */
481 } /* loop over IFOs */
482
484
485 XLALDestroyMultiAMCoeffs( multiAMcoef );
486 } /* end AM weights calculation */
487
488
489 /* misc. memory allocations */
490
491 /* memory for one spindown */
492 pulsarTemplate.spindown.length = 1;
493 pulsarTemplate.spindown.data = NULL;
494 pulsarTemplate.spindown.data = ( REAL8 * )LALMalloc( sizeof( REAL8 ) );
495
496 /* copy template parameters */
497 pulsarTemplate.spindown.data[0] = uvar_fdot;
498 pulsarTemplate.f0 = uvar_Freq;
499 pulsarTemplate.latitude = uvar_Delta;
500 pulsarTemplate.longitude = uvar_Alpha;
501
502 /* memory for f(t) vector */
503 foft.length = mObsCoh;
504 foft.data = NULL;
505 foft.data = ( REAL8 * )LALMalloc( mObsCoh * sizeof( REAL8 ) );
506
507 /* memory for peakgram */
508 pg1.length = binsSFT;
509 pg1.data = NULL;
510 pg1.data = ( UCHAR * )LALCalloc( binsSFT, sizeof( UCHAR ) );
511
512 /* memory for number Count Vector */
513 numberCountV.length = uvar_p;
514 numberCountV.data = NULL;
515 numberCountV.data = ( REAL8 * )LALMalloc( uvar_p * sizeof( REAL8 ) );
516
517 /* block for calculating peakgram and number count */
518 {
519 UINT4 iIFO, iSFT, ii, numberSFTp;
520 INT4 ind;
521 REAL8 sumWeightSquare;
522 SFTtype *sft;
523
524 /* compute mean and sigma for noise only */
525 /* first calculate the sum of the weights squared */
526 sumWeightSquare = 0.0;
527 for ( k = 0; k < ( INT4 )mObsCoh; k++ ) {
528 sumWeightSquare += weightsV.data[k] * weightsV.data[k];
529 }
530
531 /* probability of selecting a peak expected mean and standard deviation for noise only */
532 alphaPeak = exp( - uvar_peakThreshold );
533 meanN = mObsCoh * alphaPeak;
534 sigmaN = sqrt( sumWeightSquare * alphaPeak * ( 1.0 - alphaPeak ) );
535
536
537 /* the received frequency as a function of time */
538 LAL_CALL( ComputeFoft( &status, &foft, &pulsarTemplate, &timeDiffV, &velV, timeBase ), &status );
539
540 LAL_CALL( SplitSFTs( &status, &weightsV, &chi2Params ), &status );
541
542 /* loop over SFT, generate peakgram and get number count */
543 UINT4 j;
544 j = 0;
545 iIFO = 0;
546 iSFT = 0;
547
548 numsft = mdetStates->data[iIFO]->length;
549
550
551 for ( k = 0 ; k < uvar_p ; k++ ) {
552
553 numberSFTp = chi2Params.numberSFTp[k];
554 numberCount = 0;
555
556 for ( ii = 0 ; ( ii < numberSFTp ) && ( iIFO < numifo ) ; ii++ ) {
557
558 sft = inputSFTs->data[iIFO]->data + iSFT;
559
560 LAL_CALL( SFTtoUCHARPeakGram( &status, &pg1, sft, uvar_peakThreshold ), &status );
561
562 ind = floor( foft.data[j] * timeBase - sftFminBin + 0.5 );
563
564 numberCount += pg1.data[ind] * weightsV.data[j];
565
566 j++;
567
568 iSFT++;
569
570 if ( iSFT >= numsft ) {
571
572 iIFO++;
573 iSFT = 0;
574 if ( iIFO < numifo ) {
575 numsft = mdetStates->data[iIFO]->length;
576 }
577 }
578
579 } /* loop over SFTs */
580
581 numberCountV.data[k] = numberCount;
582
583 } /* loop over blocks */
584
585 }
586
587 /* Chi2 Test */
588 {
589 REAL8 eta; /* Auxiliar variable */
590 REAL8 nj, sumWeightj, sumWeightSquarej;
591
592
593 numberCountTotal = 0;
594 chi2 = 0;
595
596 for ( k = 0; k < uvar_p ; k++ ) {
597 numberCountTotal += numberCountV.data[k];
598 }
599
600 eta = numberCountTotal / mObsCoh;
601 INT4 j;
602 for ( j = 0 ; j < ( uvar_p ) ; j++ ) {
603
604 nj = numberCountV.data[j];
605 sumWeightj = chi2Params.sumWeight[j];
606 sumWeightSquarej = chi2Params.sumWeightSquare[j];
607
608 chi2 += ( nj - sumWeightj * eta ) * ( nj - sumWeightj * eta ) / ( sumWeightSquarej * eta * ( 1 - eta ) );
609 }
610 }
611
612
613
614
615 fp = fopen( uvar_outfile, "w" );
616 setvbuf( fp, ( char * )NULL, _IOLBF, 0 );
617 fprintf( fp, "%g %g %g %g %g %g %g %g \n", ( numberCountTotal - meanN ) / sigmaN, meanN, sigmaN, chi2, uvar_Freq, uvar_Alpha, uvar_Delta, uvar_fdot );
618 /* fprintf(stdout, "%g %g %g %g %g %g %g %g \n", (numberCountTotal - meanN)/sigmaN, meanN ,sigmaN, chi2, uvar_Freq, uvar_Alpha, uvar_Delta, uvar_fdot);*/
619 fclose( fp );
620
621
622
623 /* free memory */
624 LALFree( pulsarTemplate.spindown.data );
625 LALFree( timeV.data );
626 LALFree( timeDiffV.data );
627 LALFree( foft.data );
628 LALFree( velV.data );
629
630 LALFree( weightsV.data );
631
633
635
636 XLALDestroyMultiSFTVector( inputSFTs );
637 LALFree( pg1.data );
638
639 LALFree( numberCountV.data );
640
641 LALFree( chi2Params.numberSFTp );
642 LALFree( chi2Params.sumWeight );
643 LALFree( chi2Params.sumWeightSquare );
644
646
648
649 if ( lalDebugLevel ) {
651 }
652
653 return status.statusCode;
654}
655
656
657
658
659
662 REAL8Vector *foft,
663 HoughTemplate *pulsarTemplate,
664 REAL8Vector *timeDiffV,
666 REAL8 timeBase )
667{
668
669 INT4 mObsCoh;
670 REAL8 f0new, vcProdn, timeDiffN;
671 INT4 f0newBin;
672 REAL8 sourceDelta, sourceAlpha, cosDelta;
673 INT4 j, i, nspin, factorialN;
674 REAL8Cart3Coor sourceLocation;
675
676 /* --------------------------------------------- */
679
680 /* Make sure the arguments are not NULL: */
685
689
690 sourceDelta = pulsarTemplate->latitude;
691 sourceAlpha = pulsarTemplate->longitude;
692 cosDelta = cos( sourceDelta );
693
694 sourceLocation.x = cosDelta * cos( sourceAlpha );
695 sourceLocation.y = cosDelta * sin( sourceAlpha );
696 sourceLocation.z = sin( sourceDelta );
697
698 mObsCoh = foft->length;
699 nspin = pulsarTemplate->spindown.length;
700
701 for ( j = 0; j < mObsCoh; ++j ) { /* loop for all different time stamps */
702 vcProdn = velV->data[j].x * sourceLocation.x
703 + velV->data[j].y * sourceLocation.y
704 + velV->data[j].z * sourceLocation.z;
705 f0new = pulsarTemplate->f0;
706 factorialN = 1;
707 timeDiffN = timeDiffV->data[j];
708
709 for ( i = 0; i < nspin; ++i ) { /* loop for spin-down values */
710 factorialN *= ( i + 1 );
711 f0new += pulsarTemplate->spindown.data[i] * timeDiffN / factorialN;
712 timeDiffN *= timeDiffN;
713 }
714 f0newBin = floor( f0new * timeBase + 0.5 );
715 foft->data[j] = f0newBin * ( 1.0 + vcProdn ) / timeBase;
716 }
717
719 /* normal exit */
720 RETURN( status );
721}
722
723
724
725
726
727
730 REAL8Vector *weightsV,
731 HoughParamsTest *chi2Params )
732{
733
734 UINT4 j = 0; /* index of each block. It runs betwen 0 and p */
735 UINT4 iSFT = 0;
736 REAL8 *weights_ptr; /* pointer to weightsV.data */
737 REAL8 sumWeightpMax; /* Value of sumWeight we want to fix in each set of SFTs */
738 UINT4 numberSFT; /* Counter with the # of SFTs in each block */
739 UINT4 mObsCoh, p;
740 REAL8 partialsumWeightp, partialsumWeightSquarep;
741
742 /* --------------------------------------------- */
745
746 /* Make sure the arguments are not NULL: */
749
756
757 mObsCoh = weightsV->length;
758 p = chi2Params->length;
759
760 sumWeightpMax = ( REAL8 )( mObsCoh ) / p; /* Compute the value of the sumWeight we want to fix in each set of SFT's */
761 weights_ptr = weightsV->data; /* Make the pointer to point to the first position of the vector weightsV.data */
762
763 iSFT = 0;
764 for ( j = 0; j < p; j++ ) {
765
766 partialsumWeightSquarep = 0;
767 partialsumWeightp = 0;
768
769 for ( numberSFT = 0; ( partialsumWeightp < sumWeightpMax ) && ( iSFT < mObsCoh ); numberSFT++, iSFT++ ) {
770
771 partialsumWeightp += *weights_ptr;
772 partialsumWeightSquarep += ( *weights_ptr ) * ( *weights_ptr );
773 weights_ptr++;
774
775 } /* loop over SFTs */
776
778
779 chi2Params->numberSFTp[j] = numberSFT;
780 chi2Params->sumWeight[j] = partialsumWeightp;
781 chi2Params->sumWeightSquare[j] = partialsumWeightSquarep;
782
783 } /* loop over the p blocks of data */
784
786 /* normal exit */
787 RETURN( status );
788}
Header file for non-demodulated Hough search.
#define DRIVEHOUGHCOLOR_MSGEBAD
#define DRIVEHOUGHCOLOR_MSGENULL
#define DRIVEHOUGHCOLOR_ENULL
#define DRIVEHOUGHCOLOR_EBAD
#define LAL_INT4_MAX
void REPORTSTATUS(LALStatus *status)
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
#define LAL_CALL(function, statusptr)
int j
int k
void LALCheckMemoryLeaks(void)
#define LALCalloc(m, n)
#define LALMalloc(n)
#define LALFree(p)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
void SFTtoUCHARPeakGram(LALStatus *status, UCHARPeakGram *pg, const SFTtype *sft, REAL8 thr)
Convert a normalized sft into a peakgram by selecting bins in which power exceeds a threshold.
Definition: PeakSelect.c:371
#define STRING(a)
#define fprintf
int main(int argc, char *argv[])
void SplitSFTs(LALStatus *status, REAL8Vector *weightsV, HoughParamsTest *chi2Params)
BOOLEAN uvar_printSigma
#define F0
#define NFSIZE
#define THRESHOLD
#define NBLOCKSTEST
void ComputeFoft(LALStatus *status, REAL8Vector *foft, HoughTemplate *pulsarTemplate, REAL8Vector *timeDiffV, REAL8Cart3CoorVector *velV, REAL8 timeBase)
#define EARTHEPHEMERIS
BOOLEAN uvar_printTemplates
#define TRUE
BOOLEAN uvar_printStats
BOOLEAN uvar_printMaps
BOOLEAN uvar_printEvents
#define BLOCKSRNGMED
#define FBAND
#define SUNEPHEMERIS
#define MAXFILENAMELENGTH
#define SFTDIRECTORY
void XLALDestroyMultiDetectorStateSeries(MultiDetectorStateSeries *mdetStates)
Helper function to get rid of a multi-IFO DetectorStateSeries Note, this is "NULL-robust" in the sens...
MultiDetectorStateSeries * XLALGetMultiDetectorStatesFromMultiSFTs(const MultiSFTVector *multiSFTs, const EphemerisData *edat, REAL8 tOffset)
Get the 'detector state' (ie detector-tensor, position, velocity, etc) for the given multi-vector of ...
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
unsigned char UCHAR
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
#define lalDebugLevel
void LALHOUGHNormalizeWeights(LALStatus *status, REAL8Vector *weightV)
Normalizes weight factors so that their sum is N.
Definition: DriveHough.c:668
void LALHOUGHInitializeWeights(LALStatus *status, REAL8Vector *weightV)
Initializes weight factors to unity.
Definition: DriveHough.c:633
#define VTOT
Total detector velocity/c TO BE CHANGED DEPENDING ON DETECTOR.
Definition: LUT.h:207
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 LALCreateRandomParams(LALStatus *status, RandomParams **params, INT4 seed)
static const INT4 a
void LALDestroyRandomParams(LALStatus *status, RandomParams **params)
void LALRemoveKnownLinesInMultiSFTVector(LALStatus *status, MultiSFTVector *MultiSFTVect, INT4 width, INT4 window, LALStringVector *linefiles, RandomParams *randPar)
top level function to remove lines from a multi sft vector given a list of files containing list of k...
Definition: lib/SFTClean.c:953
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
Definition: SFTcatalog.c:329
MultiSFTVector * XLALLoadMultiSFTs(const SFTCatalog *inputCatalog, REAL8 fMin, REAL8 fMax)
Function to load a catalog of SFTs from possibly different detectors.
Definition: SFTfileIO.c:416
void XLALDestroyMultiSFTVector(MultiSFTVector *multvect)
Destroy a multi SFT-vector.
Definition: SFTtypes.c:424
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
LIGOTimeGPSVector * XLALReadTimestampsFile(const CHAR *fname)
backwards compatible wrapper to XLALReadTimestampsFileConstrained() without GPS-time constraints
void XLALDestroyTimestampVector(LIGOTimeGPSVector *vect)
De-allocate a LIGOTimeGPSVector.
Definition: SFTtimestamps.c:69
COORDINATESYSTEM_EQUATORIAL
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
#define XLALRegisterNamedUvar(cvar, name, type, option, category,...)
int XLALUserVarWasSet(const void *cvar)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
eta
int deltaF
chi2
REAL8 uvar_fdot
CHAR * uvar_sftDir
REAL8 uvar_startTime
INT4 uvar_blocksRngMed
REAL8 uvar_endTime
REAL4Vector * b
(weighted) per-SFT antenna-pattern function
Definition: LALComputeAM.h:65
REAL4Vector * a
(weighted) per-SFT antenna-pattern function
Definition: LALComputeAM.h:64
COMPLEX8Sequence * data
COMPLEX8FrequencySeries * data
Pointer to the data array.
REAL8 vDetector[3]
Cart.
LIGOTimeGPS tGPS
GPS timestamps corresponding to this entry.
DetectorState * data
array of DetectorState entries
UINT4 length
total number of entries
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
REAL8Vector spindown
A vector of 'timestamps' of type LIGOTimeGPS.
Definition: SFTfileIO.h:188
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
Multi-IFO time-series of DetectorStates.
DetectorStateSeries ** data
vector of pointers to DetectorStateSeries
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
Definition: PSDutils.h:71
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 collection of SFT vectors – one for each IFO in a multi-IFO search.
Definition: SFTfileIO.h:179
UINT4 length
number of ifos
Definition: SFTfileIO.h:183
SFTVector ** data
sftvector for each ifo
Definition: SFTfileIO.h:184
REAL4 * data
Three dimensional Cartessian coordinates.
Definition: LUT.h:308
REAL8 y
Definition: LUT.h:310
REAL8 x
Definition: LUT.h:309
REAL8 z
Definition: LUT.h:311
REAL8Cart3Coor * data
x.y.z
UINT4 length
number of elements
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
CHAR * detector
2-char channel-prefix describing the detector (eg 'H1', 'H2', 'L1', 'G1' etc)
Definition: SFTfileIO.h:213
LIGOTimeGPSVector * timestamps
list of timestamps
Definition: SFTfileIO.h:216
LIGOTimeGPS * maxStartTime
only include SFTs whose epoch is < maxStartTime
Definition: SFTfileIO.h:215
LIGOTimeGPS * minStartTime
only include SFTs whose epoch is >= minStartTime
Definition: SFTfileIO.h:214
SFTtype header
SFT-header info.
Definition: SFTfileIO.h:228
REAL8 longitude
REAL8 latitude
CoordinateSystem system
Explicit peakgram structure – 1 if power in bin is above threshold and 0 if below.
Definition: PeakSelect.h:114
UCHAR * data
pointer to the data {0,1}
Definition: PeakSelect.h:120
INT4 length
number of elements in data
Definition: PeakSelect.h:118
double f_min
double f_max