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
HoughValidateAM.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Badri Krishnan, Reinhard Prix, Alicia Sintes Olives
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_Hough
23 * \author Badri Krishnan and Alicia Sintes
24 * \brief Checking improvements in Hough if amplitude modulation is considered.
25 */
26
27
28#include "MCInjectHoughS2.h"
29#include <lal/LALComputeAM.h>
30#include <lal/ComputeSky.h>
31#include <gsl/gsl_cdf.h>
32
33/* defaults */
34#define EARTHEPHEMERIS ".earth00-40-DE405.dat"
35#define SUNEPHEMERIS "sun00-40-DE405.dat"
36#define MAXFILES 3000 /* maximum number of files to read in a directory */
37#define MAXFILENAMELENGTH 256 /* maximum # of characters of a SFT filename */
38#define IFO 2 /* detector, 1:GEO, 2:LLO, 3:LHO */
39#define THRESHOLD 1.6 /* thresold for peak selection, with respect to the */
40#define NFSIZE 21 /* n-freq. span of the cylinder, to account for spin-down */
41#define BLOCKSRNGMED 101 /* Running median window size */
42
43/* default injected pulsar parameters */
44#define F0 255.0 /* frequency to build the LUT and start search */
45#define FDOT 0.0 /* default spindown parameter */
46#define ALPHA 1.57
47#define DELTA 0.0
48#define COSIOTA 0.5
49#define PHI0 0.0
50#define PSI 0.0
51#define H0 (1.0e-23)
52
53/* default file and directory names */
54#define SFTDIRECTORY "/local_data/badkri/fakesfts/"
55#define FILEOUT "./ValidateAMOut"
56#define TRUE (1==1)
57#define FALSE (1==0)
58
59int main( int argc, char *argv[] )
60{
61
62 static LALStatus status;
63 static LALDetector detector;
64 static LIGOTimeGPSVector timeV;
65 static REAL8Cart3CoorVector velV;
66 static REAL8Vector timeDiffV;
67 static REAL8Vector foft;
69 static SFTParams sftParams;
70
71 static UCHARPeakGram pg1;
72 /* static UCHARPeakGram pg2; */
73 static COMPLEX8SFTData1 sft1;
74 static REAL8PeriodoPSD periPSD;
75
76 REAL4TimeSeries *signalTseries = NULL;
77 SFTVector *inputSFTs = NULL;
78 SFTVector *outputSFTs = NULL;
79 /* data about injected signal */
80 static PulsarData pulsarInject;
81
82 /* the template */
83 static HoughTemplate pulsarTemplate, pulsarTemplate1;
84
85 /* FILE *fpOUT = NULL; */ /* output file pointer */
86 FILE *fpLog = NULL; /* log file pointer */
87 CHAR *logstr = NULL; /* log string containing user input variables */
88 CHAR *fnamelog = NULL; /* name of log file */
89 INT4 nfSizeCylinder;
90
91 EphemerisData *edat = NULL;
92
93 INT4 mObsCoh;
94 REAL8 numberCount2, numberCount1;
95 REAL8 nth1, nth2, erfcInv;
96 /* REAl8 meanAM, sigmaAM, varAM, mean, sigma; */
97 REAL8 mean1, mean2, var1, var2, sumsq, peakprob;
98 REAL8 sftBand;
99 REAL8 timeBase, deltaF, normalizeThr, threshold;
100 /* REAL8 thresholdAM; */
101 UINT4 sftlength;
102 INT4 sftFminBin;
103 REAL8 fHeterodyne;
104 REAL8 tSamplingRate;
105
106 /* grid spacings */
107 REAL8 deltaTheta;
108 INT4 mmP, mmT; /* for loop over mismatched templates */
109
110 /* user input variables */
111 INT4 uvar_ifo, uvar_blocksRngMed;
112 REAL8 uvar_houghFalseAlarm;
113 REAL8 uvar_peakThreshold;
114 REAL8 uvar_alpha, uvar_delta, uvar_h0, uvar_f0;
115 REAL8 uvar_psi, uvar_phi0, uvar_fdot, uvar_cosiota;
116 REAL8 uvar_mismatchW;
117 CHAR *uvar_earthEphemeris = NULL;
118 CHAR *uvar_sunEphemeris = NULL;
119 CHAR *uvar_sftDir = NULL;
120 CHAR *uvar_fnameout = NULL;
121
122 /* vector of weights */
123 REAL8Vector *weight;
124
125 /* set up the default parameters */
126
127 nfSizeCylinder = NFSIZE;
128
129 /* *********************************************************************** */
130 /* set other user input variables */
131 uvar_peakThreshold = THRESHOLD;
132 uvar_ifo = IFO;
134 uvar_mismatchW = 0.0;
135 uvar_houghFalseAlarm = 1.0e-10;
136
137 /* set default pulsar parameters */
138 uvar_h0 = H0;
139 uvar_alpha = ALPHA;
140 uvar_delta = DELTA;
141 uvar_f0 = F0;
142 uvar_fdot = FDOT;
143 uvar_psi = PSI;
144 uvar_cosiota = COSIOTA;
145 uvar_phi0 = PHI0;
146
147 /* now set the default filenames */
148 uvar_earthEphemeris = ( CHAR * )LALMalloc( 512 * sizeof( CHAR ) );
149 strcpy( uvar_earthEphemeris, EARTHEPHEMERIS );
150
151 uvar_sunEphemeris = ( CHAR * )LALMalloc( 512 * sizeof( CHAR ) );
152 strcpy( uvar_sunEphemeris, SUNEPHEMERIS );
153
154 uvar_sftDir = ( CHAR * )LALMalloc( 512 * sizeof( CHAR ) );
155 strcpy( uvar_sftDir, SFTDIRECTORY );
156
157 uvar_fnameout = ( CHAR * )LALMalloc( 512 * sizeof( CHAR ) );
158 strcpy( uvar_fnameout, FILEOUT );
159
160 /* *********************************************************************** */
161 /* register user input variables */
162 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_ifo, "ifo", INT4, 'i', OPTIONAL, "Detector GEO(1) LLO(2) LHO(3)" ) == XLAL_SUCCESS, XLAL_EFUNC );
163 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_blocksRngMed, "blocksRngMed", INT4, 'w', OPTIONAL, "RngMed block size" ) == XLAL_SUCCESS, XLAL_EFUNC );
164 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_peakThreshold, "peakThreshold", REAL8, 't', OPTIONAL, "Peak selection threshold" ) == XLAL_SUCCESS, XLAL_EFUNC );
165 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_houghFalseAlarm, "houghFalseAlarm", REAL8, 0, OPTIONAL, "Overall Hough False alarm" ) == XLAL_SUCCESS, XLAL_EFUNC );
166 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_earthEphemeris, "earthEphemeris", STRING, 'E', OPTIONAL, "Earth Ephemeris file" ) == XLAL_SUCCESS, XLAL_EFUNC );
167 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_sunEphemeris, "sunEphemeris", STRING, 'S', OPTIONAL, "Sun Ephemeris file" ) == XLAL_SUCCESS, XLAL_EFUNC );
168 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_sftDir, "sftDir", STRING, 'D', OPTIONAL, "SFT Directory" ) == XLAL_SUCCESS, XLAL_EFUNC );
169 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_fnameout, "fnameout", STRING, 'o', OPTIONAL, "Output file prefix" ) == XLAL_SUCCESS, XLAL_EFUNC );
170 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_alpha, "alpha", REAL8, 'r', OPTIONAL, "Right ascension" ) == XLAL_SUCCESS, XLAL_EFUNC );
171 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_delta, "delta", REAL8, 'l', OPTIONAL, "Declination" ) == XLAL_SUCCESS, XLAL_EFUNC );
172 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_h0, "h0", REAL8, 'm', OPTIONAL, "h0 to inject" ) == XLAL_SUCCESS, XLAL_EFUNC );
173 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_f0, "f0", REAL8, 'f', OPTIONAL, "Signal frequency" ) == XLAL_SUCCESS, XLAL_EFUNC );
174 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_psi, "psi", REAL8, 'p', OPTIONAL, "Polarization angle" ) == XLAL_SUCCESS, XLAL_EFUNC );
175 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_phi0, "phi0", REAL8, 'P', OPTIONAL, "Initial phase" ) == XLAL_SUCCESS, XLAL_EFUNC );
176 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_cosiota, "cosiota", REAL8, 'c', OPTIONAL, "Cosine of iota" ) == XLAL_SUCCESS, XLAL_EFUNC );
177 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_fdot, "fdot", REAL8, 'd', OPTIONAL, "Spindown parameter" ) == XLAL_SUCCESS, XLAL_EFUNC );
178 XLAL_CHECK_MAIN( XLALRegisterNamedUvar( &uvar_mismatchW, "mismatch", REAL8, 'M', OPTIONAL, "Mismatch in weight calculation" ) == XLAL_SUCCESS, XLAL_EFUNC );
179
180 /* read all command line variables */
181 BOOLEAN should_exit = 0;
183 if ( should_exit ) {
184 exit( 1 );
185 }
186
187 /* *********************************************************************** */
188 /* write the log file */
189 fnamelog = ( CHAR * )LALMalloc( 512 * sizeof( CHAR ) );
190 strcpy( fnamelog, uvar_fnameout );
191 strcat( fnamelog, "_log" );
192 /* open the log file for writing */
193 if ( ( fpLog = fopen( fnamelog, "w" ) ) == NULL ) {
194 fprintf( stderr, "Unable to open file %s for writing\n", fnamelog );
195 LALFree( fnamelog );
196 exit( 1 );
197 }
198
199 /* get the log string */
201
202 fprintf( fpLog, "## Log file for HoughValidateAM \n\n" );
203 fprintf( fpLog, "# User Input:\n" );
204 fprintf( fpLog, "#-------------------------------------------\n" );
205 fprintf( fpLog, "%s", logstr );
206 LALFree( logstr );
207
208 /* append an ident-string defining the exact CVS-version of the code used */
209 {
210 CHAR command[1024] = "";
211 fprintf( fpLog, "\n\n# CVS-versions of executable:\n" );
212 fprintf( fpLog, "# -----------------------------------------\n" );
213 fclose( fpLog );
214
215 sprintf( command, "ident %s | sort -u >> %s", argv[0], fnamelog );
216 /* we don't check this. If it fails, we assume that */
217 /* one of the system-commands was not available, and */
218 /* therefore the CVS-versions will not be logged */
219 if ( system( command ) ) {
220 fprintf( stderr, "\nsystem('%s') returned non-zero status!\n\n", command );
221 }
222
223 LALFree( fnamelog );
224 }
225
226 /* *********************************************************************** */
227 /* set peak selection threshold */
228 LAL_CALL( LALRngMedBias( &status, &normalizeThr, uvar_blocksRngMed ), &status );
229 threshold = uvar_peakThreshold / normalizeThr;
230
231 /* *********************************************************************** */
232 /* set detector */
233 if ( uvar_ifo == 1 ) {
235 }
236 if ( uvar_ifo == 2 ) {
238 }
239 if ( uvar_ifo == 3 ) {
241 }
242
243
244 /* *********************************************************************** */
245 /* copy user input values */
246 pulsarInject.f0 = uvar_f0;
247 pulsarInject.latitude = uvar_delta;
248 pulsarInject.longitude = uvar_alpha;
249 pulsarInject.aPlus = 0.5 * uvar_h0 * ( 1.0 + uvar_cosiota * uvar_cosiota );
250 pulsarInject.aCross = uvar_h0 * uvar_cosiota;
251 pulsarInject.psi = uvar_psi;
252 pulsarInject.phi0 = uvar_phi0;
253 pulsarInject.spindown.length = 1;
254 pulsarInject.spindown.data = NULL;
255 pulsarInject.spindown.data = ( REAL8 * )LALMalloc( sizeof( REAL8 ) );
256 pulsarInject.spindown.data[0] = uvar_fdot;
257
258 /* *********************************************************************** */
259 /* copy these values also to the pulsar template */
260 /* template is complately matched at this point */
261 pulsarTemplate.f0 = uvar_f0;
262 pulsarTemplate.latitude = uvar_delta;
263 pulsarTemplate.longitude = uvar_alpha;
264 pulsarTemplate.spindown.length = 1;
265 pulsarTemplate.spindown.data = NULL;
266 pulsarTemplate.spindown.data = ( REAL8 * )LALMalloc( sizeof( REAL8 ) );
267 pulsarTemplate.spindown.data[0] = uvar_fdot;
268
269 /* *********************************************************************** */
270 /* allocate memory for mismatched spindown template */
271 pulsarTemplate1.spindown.length = 1;
272 pulsarTemplate1.spindown.data = NULL;
273 pulsarTemplate1.spindown.data = ( REAL8 * )LALMalloc( sizeof( REAL8 ) );
274
275 /* *********************************************************************** */
276 /* read sfts */
277 /* note that sft must be long enough -- at least 1Hz */
278 {
279 CHAR *tempDir;
280 tempDir = ( CHAR * )LALMalloc( 512 * sizeof( CHAR ) );
281 strcpy( tempDir, uvar_sftDir );
282 strcat( tempDir, "/*SFT*.*" );
283 sftBand = 0.5;
284 SFTCatalog *catalog = XLALSFTdataFind( tempDir, NULL );
285 XLAL_CHECK_MAIN( catalog != NULL, XLAL_EFUNC );
286 double catalog_deltaF = catalog->data[0].header.deltaF;
287 sftBand += ( nfSizeCylinder + uvar_blocksRngMed ) * catalog_deltaF;
288 inputSFTs = XLALLoadSFTs( catalog, uvar_f0 - sftBand, uvar_f0 + sftBand );
289 XLAL_CHECK_MAIN( inputSFTs != NULL, XLAL_EFUNC );
290 LALFree( tempDir );
291 }
292
293
294 /* *********************************************************************** */
295 /* get sft parameters */
296 mObsCoh = inputSFTs->length;
297 sftlength = inputSFTs->data->data->length;
298 deltaF = inputSFTs->data->deltaF;
299 timeBase = 1.0 / deltaF;
300 sftFminBin = floor( timeBase * inputSFTs->data->f0 + 0.5 );
301
302 /* signal generation parameters */
303 fHeterodyne = sftFminBin * deltaF;
304 tSamplingRate = 2.0 * deltaF * ( sftlength - 1. );
305
306 /* *********************************************************************** */
307 /* create timestamp vector */
308 timeV.length = mObsCoh;
309 timeV.data = NULL;
310 timeV.data = ( LIGOTimeGPS * )LALMalloc( mObsCoh * sizeof( LIGOTimeGPS ) );
311
312 /* *********************************************************************** */
313 /* read timestamps */
314 {
315 INT4 i;
316 SFTtype *sft = NULL;
317
318 sft = inputSFTs->data;
319 for ( i = 0; i < mObsCoh; i++ ) {
320 timeV.data[i].gpsSeconds = sft->epoch.gpsSeconds;
322 ++sft;
323 }
324 }
325
326 /* *********************************************************************** */
327 /* compute the time difference relative to startTime for all SFT */
328 timeDiffV.length = mObsCoh;
329 timeDiffV.data = NULL;
330 timeDiffV.data = ( REAL8 * )LALMalloc( mObsCoh * sizeof( REAL8 ) );
331
332 {
333 REAL8 t0, ts, tn, midTimeBase;
334 INT4 j;
335
336 midTimeBase = 0.5 * timeBase;
337 ts = timeV.data[0].gpsSeconds;
338 tn = timeV.data[0].gpsNanoSeconds * 1.00E-9;
339 t0 = ts + tn;
340 timeDiffV.data[0] = midTimeBase;
341
342 for ( j = 1; j < mObsCoh; ++j ) {
343 ts = timeV.data[j].gpsSeconds;
344 tn = timeV.data[j].gpsNanoSeconds * 1.00E-9;
345 timeDiffV.data[j] = ts + tn - t0 + midTimeBase;
346 }
347 }
348
349 /* *********************************************************************** */
350 /* compute detector velocity for those time stamps */
351 velV.length = mObsCoh;
352 velV.data = NULL;
353 velV.data = ( REAL8Cart3Coor * )LALMalloc( mObsCoh * sizeof( REAL8Cart3Coor ) );
354
355 {
356 VelocityPar velPar;
357 REAL8 vel[3];
358 UINT4 j;
359
360 velPar.detector = detector;
361 velPar.tBase = timeBase;
362 velPar.vTol = 0.0; /* irrelevant */
363 velPar.edat = NULL;
364
365 /* read in ephemeris data */
366 XLAL_CHECK_MAIN( ( edat = XLALInitBarycenter( uvar_earthEphemeris, uvar_sunEphemeris ) ) != NULL, XLAL_EFUNC );
367 velPar.edat = edat;
368
369 /* calculate detector velocity */
370 for ( j = 0; j < velV.length; ++j ) {
371 velPar.startTime.gpsSeconds = timeV.data[j].gpsSeconds;
373
374 LAL_CALL( LALAvgDetectorVel( &status, vel, &velPar ), &status );
375 velV.data[j].x = vel[0];
376 velV.data[j].y = vel[1];
377 velV.data[j].z = vel[2];
378 }
379 }
380
381 /* calculate weights based on amplitude modulation functions */
382
383 /* allocate memory for weight */
384 weight = NULL;
385 LAL_CALL( LALDCreateVector( &status, &weight, mObsCoh ), &status );
386
387 /* calculate amplitude modulation weights */
390 uvar_alpha + uvar_mismatchW,
391 uvar_delta + uvar_mismatchW ), &status );
393
394
395 /* calculate mean and variances */
396 peakprob = exp( -uvar_peakThreshold ); /* probability of peak selection */
397 erfcInv = gsl_cdf_ugaussian_Qinv( uvar_houghFalseAlarm ) / sqrt( 2 ); /* erfcinv(2*uvar_houghFalseAlarm */
398
399 /* usual number count threshold */
400 /* 1 is for the usual hough transform
401 2 is for weighted hough transform */
402 mean1 = mObsCoh * peakprob;
403 var1 = mObsCoh * peakprob * ( 1 - peakprob );
404 nth1 = mean1 + sqrt( 2.0 * var1 ) * erfcInv;
405
406 /* threshold for weighted hough number count */
407 mean2 = mean1; /* this is due to normalization of weights */
408 /* find sum of weights squared */
409 sumsq = 0.0;
410 INT4 j;
411 for ( j = 0; j < mObsCoh; j++ ) {
412 REAL8 tempW;
413 tempW = weight->data[j];
414 sumsq += tempW * tempW;
415 }
416 var2 = sumsq * peakprob * ( 1 - peakprob );
417 nth2 = mean2 + sqrt( 2.0 * var2 ) * erfcInv;
418
419 /* { /\* check sum weight = 1 *\/ */
420 /* REAL8 tempSum=0.0; */
421 /* for (j=0; j<mObsCoh; j++) { */
422 /* tempSum += weight->data[j]; */
423 /* } */
424 /* fprintf(stdout, "%f\n", tempSum); */
425 /* } */
426 /* *********************************************************************** */
427 /* computing varAM */
428 /* { */
429 /* INT4 j; */
430 /* REAL8 x; */
431 /* /\* REAL8 y; *\/ */
432
433 /* varAM = 0.0; */
434
435 /* /\* y=0.0; *\/ */
436 /* for(j=0; j<mObsCoh; j++){ */
437 /* a = aVec->data[j]; */
438 /* b = bVec->data[j]; */
439 /* x = 2.0*(a*a + b*b)/(A+B) -1.0; */
440 /* varAM += x*x; */
441 /* /\* y+=x; *\/ */
442 /* } */
443 /* varAM = varAM/mObsCoh; */
444 /* /\* fprintf(stdout, "zero ?= %g\n", y); *\/ */
445
446 /* } */
447
448
449
450 /* *********************************************************************** */
451 /* set grid spacings */
452 {
453 deltaTheta = 1.0 / ( VTOT * uvar_f0 * timeBase );
454 /* currently unused: REAL8 deltaFdot = deltaF / timeBase; */
455 }
456
457 /* *********************************************************************** */
458 /* allocate memory for f(t) pattern */
459 foft.length = mObsCoh;
460 foft.data = NULL;
461 foft.data = ( REAL8 * )LALMalloc( mObsCoh * sizeof( REAL8 ) );
462
463 /* allocate memory for Hough peripsd structure */
464 periPSD.periodogram.length = sftlength;
465 periPSD.periodogram.data = NULL;
466 periPSD.periodogram.data = ( REAL8 * )LALMalloc( sftlength * sizeof( REAL8 ) );
467 periPSD.psd.length = sftlength;
468 periPSD.psd.data = NULL;
469 periPSD.psd.data = ( REAL8 * )LALMalloc( sftlength * sizeof( REAL8 ) );
470
471 /* allocate memory for peakgrams */
472 pg1.length = sftlength;
473 pg1.data = NULL;
474 pg1.data = ( UCHAR * )LALMalloc( sftlength * sizeof( UCHAR ) );
475
476 /* pg2.length = sftlength; */
477 /* pg2.data = NULL; */
478 /* pg2.data = (UCHAR *)LALMalloc(sftlength* sizeof(UCHAR)); */
479
480 /* *********************************************************************** */
481 /* generate signal and add to input sfts */
482 /* parameters for output sfts */
483 sftParams.Tsft = timeBase;
484 sftParams.timestamps = &( timeV );
485 sftParams.noiseSFTs = inputSFTs;
486
487 /* signal generation parameters */
488 params.orbit.asini = 0 /* isolated pulsar */;
489 /* params.transferFunction = NULL; */
490 params.site = &( detector );
491 params.ephemerides = edat;
492 params.startTimeGPS.gpsSeconds = timeV.data[0].gpsSeconds; /* start time of output time series */
493 params.startTimeGPS.gpsNanoSeconds = timeV.data[0].gpsNanoSeconds; /* start time of output time series */
494 params.duration = timeDiffV.data[mObsCoh - 1] + 0.5 * timeBase; /* length of time series in seconds */
495 params.samplingRate = tSamplingRate;
496 params.fHeterodyne = fHeterodyne;
497 /* reference time for frequency and spindown is first timestamp */
498 params.pulsar.refTime.gpsSeconds = timeV.data[0].gpsSeconds;
499 params.pulsar.refTime.gpsNanoSeconds = timeV.data[0].gpsNanoSeconds;
500
501 params.pulsar.position.longitude = pulsarInject.longitude;
502 params.pulsar.position.latitude = pulsarInject.latitude ;
503 params.pulsar.position.system = COORDINATESYSTEM_EQUATORIAL;
504 params.pulsar.psi = pulsarInject.psi;
505 params.pulsar.aPlus = pulsarInject.aPlus;
506 params.pulsar.aCross = pulsarInject.aCross;
507 params.pulsar.phi0 = pulsarInject.phi0;
508 params.pulsar.f0 = pulsarInject.f0;
509 params.pulsar.spindown = &pulsarInject.spindown ;
510
511 LAL_CALL( LALGeneratePulsarSignal( &status, &signalTseries, &params ), &status );
512 LAL_CALL( LALSignalToSFTs( &status, &outputSFTs, signalTseries, &sftParams ), &status );
513
514 /* fill in elements of sft structure sft1 used in peak selection */
515 sft1.length = sftlength;
516 sft1.fminBinIndex = sftFminBin;
517 sft1.timeBase = timeBase;
518
519
520 /* *********************************************************************** */
521 /* loop over mismatched templates */
522 for ( mmT = 0; mmT <= 0; mmT++ ) {
523 for ( mmP = 0; mmP <= 0; mmP++ ) {
524 INT4 mmFactor;
525
526 /* displace the template */
527 mmFactor = 0;
528 pulsarTemplate1.f0 = pulsarTemplate.f0 /*+ mmFactor * mm * deltaF*/;
529 pulsarTemplate1.latitude = pulsarTemplate.latitude + mmFactor * mmT * deltaTheta;
530 pulsarTemplate1.longitude = pulsarTemplate.longitude + mmFactor * mmP * deltaTheta;
531 pulsarTemplate1.spindown.data[0] = pulsarTemplate.spindown.data[0] /*+ mmFactor * mm * deltaFdot*/;
532
533 /* initialize number counts */
534 numberCount1 = 0.0; /* usual number count */
535 numberCount2 = 0.0; /* number count with amplitude modulation */
536 /* meanAM = 0.0; */ /* mean and variance for new distribution */
537 /* sigmaAM = 0.0; */
538 /* now calculate the number count for the template */
539 for ( j = 0; j < mObsCoh; j++ ) {
540 INT4 ind;
541 REAL8 tempW;
542 /* REAL8 realThrAM; */
543
544 sft1.epoch.gpsSeconds = timeV.data[j].gpsSeconds;
546 sft1.data = outputSFTs->data[j].data->data;
547
549
551 &periPSD.psd, &periPSD.periodogram, &uvar_blocksRngMed ), &status );
552
553
554 /* construct peakgram with usual threshold */
555 LAL_CALL( LALSelectPeakColorNoise( &status, &pg1, &threshold, &periPSD ), &status );
556 /*LAL_CALL( LALSelectPeakColorNoise(&status,&pg2,&thresholdAM,&periPSD), &status); */
557
558
559 /*adjust threshold for amplitude modulation */
560 /* a = aVec->data[j]; */
561 /* b = bVec->data[j]; */
562 /* thresholdAM = threshold * 0.5 * (A+B) / ( a*a + b*b); */
563
564
565 LAL_CALL( ComputeFoft( &status, &foft, &pulsarTemplate1, &timeDiffV, &velV, timeBase ), &status );
566
567 ind = floor( foft.data[j] * timeBase - sftFminBin + 0.5 );
568
569 tempW = weight->data[j];
570 numberCount1 += pg1.data[ind];
571 numberCount2 += tempW * pg1.data[ind];
572
573 /* realThrAM = thresholdAM * normalizeThr; */
574
575 /* meanAM += exp(-realThrAM); */
576 /* sigmaAM += exp(-realThrAM) * (1.0 - exp(-realThrAM)); */
577 } /* end loop over sfts */
578
579 fprintf( stdout, "%g %g %g %g %g %g %g %g %g %g %g\n",
580 uvar_alpha, uvar_delta, uvar_cosiota, mean1, var1, nth1, numberCount1, mean2, var2, nth2, numberCount2 );
581
582
583 /* calculate the number count thresholds */
584 /* mean = mObsCoh * exp(-uvar_peakThreshold); */
585 /* sigma = mean * ( 1.0 - exp(-uvar_peakThreshold)); */
586
587 /* uvar_houghFalseAlarm = 1.0e-10; */
588 /* erfcInv = gsl_cdf_ugaussian_Qinv (uvar_houghFalseAlarm)/sqrt(2); */
589 /* nth1 = mean + sqrt( 2 * sigma ) * erfcInv; */
590 /* /\* use mean and variance to get approximate threshold in Gaussian approximation *\/ */
591 /* nth2 = meanAM + sqrt( 2 * sigmaAM ) * erfcInv; */
592 /* /\* fprintf(stdout, "%g %g %d %d %g %g %d %g %g %g %g\n", *\/ */
593 /* /\* uvar_alpha, uvar_delta, numberCount1, numberCount2, *\/ */
594 /* /\* nth1, nth2, mObsCoh, uvar_peakThreshold, *\/ */
595 /* /\* meanAM, sqrt(sigmaAM), varAM ); *\/ */
596 /* fprintf(stdout, "%g %g %d %d %g %g %g %g \n", */
597 /* uvar_alpha, uvar_delta, numberCount1, numberCount2, */
598 /* nth1, nth2, (numberCount1 -mean)/sqrt(sigma), (numberCount2 - meanAM)/sqrt(sigmaAM) ); */
599
600
601
602 }/* end loop over mmP */
603 }/* end loop over mmT */
604
605
606
607 /* *********************************************************************** */
608 /* free structures created by signal generation routines */
609 LALFree( signalTseries->data->data );
610 LALFree( signalTseries->data );
611 LALFree( signalTseries );
612 signalTseries = NULL;
613 XLALDestroySFTVector( outputSFTs );
614
615 /* destroy input sfts */
616 XLALDestroySFTVector( inputSFTs );
617
618 /* free other structures */
619 LALFree( foft.data );
620 LALFree( pulsarInject.spindown.data );
621 LALFree( pulsarTemplate.spindown.data );
622 LALFree( pulsarTemplate1.spindown.data );
623 LALFree( timeV.data );
624 LALFree( timeDiffV.data );
625 LALFree( velV.data );
627 LALFree( periPSD.periodogram.data );
628 LALFree( periPSD.psd.data );
629
630 LALFree( pg1.data );
631 /* LALFree(pg2.data); */
632
633 /* free amParams */
634 LAL_CALL( LALDDestroyVector( &status, &weight ), &status );
635
636 /* LAL(amc.a->data); */
637 /* LALFree(amc.b->data); */
638
641
644}
645
646
647/******************************************************************/
649 REAL8Vector *foft,
650 HoughTemplate *pulsarTemplate,
651 REAL8Vector *timeDiffV,
653 REAL8 timeBase )
654{
655
656 INT4 mObsCoh;
657 REAL8 f0new, vcProdn, timeDiffN;
658 INT4 f0newBin;
659 REAL8 sourceDelta, sourceAlpha, cosDelta;
660 INT4 j, i, nspin, factorialN;
661 REAL8Cart3Coor sourceLocation;
662
663 /* --------------------------------------------- */
666
667 /* Make sure the arguments are not NULL: */
672
676
677 sourceDelta = pulsarTemplate->latitude;
678 sourceAlpha = pulsarTemplate->longitude;
679 cosDelta = cos( sourceDelta );
680
681 sourceLocation.x = cosDelta * cos( sourceAlpha );
682 sourceLocation.y = cosDelta * sin( sourceAlpha );
683 sourceLocation.z = sin( sourceDelta );
684
685 mObsCoh = foft->length;
686 nspin = pulsarTemplate->spindown.length;
687
688 for ( j = 0; j < mObsCoh; ++j ) { /* loop for all different time stamps */
689 vcProdn = velV->data[j].x * sourceLocation.x
690 + velV->data[j].y * sourceLocation.y
691 + velV->data[j].z * sourceLocation.z;
692 f0new = pulsarTemplate->f0;
693 factorialN = 1;
694 timeDiffN = timeDiffV->data[j];
695
696 for ( i = 0; i < nspin; ++i ) { /* loop for spin-down values */
697 factorialN *= ( i + 1 );
698 f0new += pulsarTemplate->spindown.data[i] * timeDiffN / factorialN;
699 timeDiffN *= timeDiffN;
700 }
701 f0newBin = floor( f0new * timeBase + 0.5 );
702 foft->data[j] = f0newBin * ( 1.0 + vcProdn ) / timeBase;
703 }
704
706 /* normal exit */
707 RETURN( status );
708}
LALDetectorIndexLLODIFF
LALDetectorIndexGEO600DIFF
LALDetectorIndexLHODIFF
#define DRIVEHOUGHCOLOR_MSGENULL
#define INFO(statement)
#define DRIVEHOUGHCOLOR_ENULL
#define DRIVEHOUGHCOLOR_MSGENORM
#define DRIVEHOUGHCOLOR_ENORM
int main(int argc, char *argv[])
#define H0
#define F0
#define NFSIZE
#define PHI0
#define DELTA
#define THRESHOLD
void ComputeFoft(LALStatus *status, REAL8Vector *foft, HoughTemplate *pulsarTemplate, REAL8Vector *timeDiffV, REAL8Cart3CoorVector *velV, REAL8 timeBase)
#define EARTHEPHEMERIS
#define IFO
#define COSIOTA
#define FILEOUT
#define FDOT
#define BLOCKSRNGMED
#define SUNEPHEMERIS
#define SFTDIRECTORY
#define ALPHA
#define PSI
#define LAL_CALL(function, statusptr)
int j
void LALCheckMemoryLeaks(void)
#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 LALSelectPeakColorNoise(LALStatus *status, UCHARPeakGram *pg, REAL8 *thr, REAL8PeriodoPSD *in)
Function for selecting peaks in colored noise – obsolete – use LAL functions in NormalizeSFTRngMed....
Definition: PeakSelect.c:286
void LALPeriodo2PSDrng(LALStatus *status, REAL8Periodogram1 *psd, REAL8Periodogram1 *peri, INT4 *blocksRNG)
Wrapper for LALRunningMedian code – obsolete – use LAL functions in NormalizeSFTRngMed....
Definition: PeakSelect.c:215
#define STRING(a)
void COMPLEX8SFT2Periodogram1(LALStatus *status, REAL8Periodogram1 *peri, COMPLEX8SFTData1 *sft)
OBSOLETE – Use LAL functions from SFTfileIO.c instead.
Definition: SFTbin.c:69
#define fprintf
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
void LALGeneratePulsarSignal(LALStatus *status, REAL4TimeSeries **signalvec, const PulsarSignalParams *params)
void LALSignalToSFTs(LALStatus *status, SFTVector **outputSFTs, const REAL4TimeSeries *signalvec, const SFTParams *params)
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
unsigned char UCHAR
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
void LALHOUGHNormalizeWeights(LALStatus *status, REAL8Vector *weightV)
Normalizes weight factors so that their sum is N.
Definition: DriveHough.c:668
void LALHOUGHComputeAMWeights(LALStatus *status, REAL8Vector *weightV, LIGOTimeGPSVector *timeV, LALDetector *detector, EphemerisData *edat, REAL8 alpha, REAL8 delta)
Computes weight factors arising from amplitude modulation – it multiplies an existing weight vector.
Definition: DriveHough.c:712
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
void LALRngMedBias(LALStatus *status, REAL8 *biasFactor, INT4 blkSize)
void XLALDestroySFTVector(SFTVector *vect)
XLAL interface to destroy an SFTVector.
Definition: SFTtypes.c:300
SFTVector * XLALLoadSFTs(const SFTCatalog *catalog, REAL8 fMin, REAL8 fMax)
Load the given frequency-band [fMin, fMax) (half-open) from the SFT-files listed in the SFT-'catalogu...
Definition: SFTfileIO.c:87
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
COORDINATESYSTEM_EQUATORIAL
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
void XLALDestroyUserVars(void)
void CHAR * XLALUserVarGetLog(UserVarLogFormat format)
#define XLALRegisterNamedUvar(cvar, name, type, option, category,...)
UVAR_LOGFMT_CFGFILE
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALAvgDetectorVel(LALStatus *status, REAL8 v[3], VelocityPar *in)
This function outputs the average velocity REAL8 v[3] of the detector during a time interval.
Definition: Velocity.c:34
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
int deltaF
ts
REAL8 uvar_fdot
CHAR * uvar_sftDir
REAL8 uvar_f0
INT4 uvar_blocksRngMed
REAL8 uvar_psi
double t0
COMPLEX8Sequence * data
A vector of COMPLEX8FrequencySeries.
COMPLEX8FrequencySeries * data
Pointer to the data array.
UINT4 length
Number of elements in array.
LIGOTimeGPS epoch
Definition: SFTbin.h:138
REAL8 timeBase
Definition: SFTbin.h:139
COMPLEX8 * data
Definition: SFTbin.h:142
INT4 fminBinIndex
Definition: SFTbin.h:140
COMPLEX8 * data
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
REAL8Vector spindown
INT4 gpsNanoSeconds
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
REAL8Vector spindown
Input parameters to GeneratePulsarSignal(), defining the source and the time-series.
REAL4Sequence * data
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
structure containing psd and periodogram of a sft – obsolete – use LAL functions
Definition: PeakSelect.h:124
REAL8Periodogram1 periodogram
Definition: PeakSelect.h:126
REAL8Periodogram1 psd
Definition: PeakSelect.h:125
REAL8 * data
Definition: SFTbin.h:163
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
SFTtype header
SFT-header info.
Definition: SFTfileIO.h:228
Parameters defining the SFTs to be returned from LALSignalToSFTs().
REAL8 Tsft
length of each SFT in seconds
const LIGOTimeGPSVector * timestamps
timestamps to produce SFTs for (can be NULL)
const SFTVector * noiseSFTs
noise SFTs to be added (can be NULL)
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
This structure stores the parameters required by XLALBarycenter() to calculate Earth velocity at a gi...
Definition: Velocity.h:84
EphemerisData * edat
ephemeris data pointer from XLALInitBarycenter()
Definition: Velocity.h:86
LALDetector detector
the detector
Definition: Velocity.h:85
REAL8 tBase
duration of interval
Definition: Velocity.h:88
LIGOTimeGPS startTime
start of time interval
Definition: Velocity.h:87
REAL8 vTol
fractional accuracy required for velocity (redundant for average velocity calculation)
Definition: Velocity.h:89
double duration
double psi