Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
chirplen.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Duncan Brown, Patrick R Brady
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 *
22 * File Name: chirplen.c
23 *
24 * Author: Brown, D. A. and Brady, P. R.
25 *
26 *
27 *-----------------------------------------------------------------------
28 */
29
30#include "config.h"
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <math.h>
35#include <string.h>
36#include <sys/types.h>
37#include <sys/stat.h>
38#include <lal/LALError.h>
39#include <lal/LALgetopt.h>
40#include <lal/LALStdio.h>
41#include <lal/LALStdlib.h>
42#include <lal/LALStatusMacros.h>
43#include <lal/LALConstants.h>
44#include <lal/ReadNoiseSpectrum.h>
45#include <lal/SeqFactories.h>
46#include <lal/Units.h>
47#include <lal/Date.h>
48#include <lal/SimulateCoherentGW.h>
49#include <lal/GeneratePPNInspiral.h>
50#include <lal/TimeFreqFFT.h>
51#include <lal/LIGOLwXML.h>
52#include <lal/LIGOLwXMLRead.h>
53#include <lal/LIGOMetadataUtils.h>
54#include <LALAppsVCSInfo.h>
55
56#define CVS_ID_STRING "$Id$"
57#define CVS_NAME_STRING "$Name$"
58#define CVS_REVISION "$Revision$"
59#define CVS_SOURCE "$Source$"
60#define CVS_DATE "$Date$"
61#define PROGRAM_NAME "chirplen"
62
63/* Usage format string. */
64#define USAGE \
65"Usage: %s [options] [LIGOLW XML input files]\n\n"\
66" --help display this message\n"\
67" --version print version information and exit\n"\
68" --machine prints space delimeted output\n"\
69" --m1 m1 mass of 1st binary element in Msun\n"\
70" --m2 m2 mass of 2nd binary element in Msun\n"\
71" --flow fstart low frequency cutoff\n"\
72"\n"
73
74#define FSTART 30.0
75#define DELTAT (1.0/4096.0)
76
77int verbose = 0;
78int machine = 0;
79int chisqFlag = 0;
81
82int main ( int argc, char *argv[] )
83{
84 static LALStatus status;
85 UINT4 i;
86 REAL4 m1 = 0.0;
87 REAL4 m2 = 0.0;
88 float mtot,eta,mchirp,c0,c2,c3,c4,x,x2,x3,x4,x8,chirpTime,f_max;
89 REAL4 inc=0.0;
90 REAL4 longit=0.0;
91 REAL4 latit=0.0;
92
93 /* for PN signals */
94 REAL4 fstart=FSTART;
95 REAL4 fstop=2000.0;
96 PPNParamStruc ppnParams; /* wave generation parameters */
97 REAL4Vector *phiPPN=NULL;
98 CoherentGW waveform; /* amplitude and phase structure */
99 INT4 phiOrder=0;
100 CHAR *waveFile=NULL;
101
102 /* power spectrum and chisqr information */
103 CHAR *specFile=NULL;
104 REAL4 numChisqBins=0.0;
105
106 /* LALgetopt arguments */
107 struct LALoption long_options[] =
108 {
109 {"verbose", no_argument, &verbose, 1 },
110 {"machine", no_argument, &machine, 1 },
111 {"flow", required_argument, 0, 'f'},
112 {"m1", required_argument, 0, 'm'},
113 {"m2", required_argument, 0, 'n'},
114 {"specfile", required_argument, 0, 'o'},
115 {"chisq-bins", required_argument, 0, 'p' },
116 {"wavefile", required_argument, 0, 'q'},
117 {"help", no_argument, 0, 'h'},
118 {"version", no_argument, 0, 'V'},
119 {0, 0, 0, 0}
120 };
121 int c;
122
123
124 /*
125 *
126 * initialize things
127 *
128 */
129
131 setvbuf( stdout, NULL, _IONBF, 0 );
132
133 /* parse the arguments */
134 while ( 1 )
135 {
136 /* LALgetopt_long stores long option here */
137 int option_index = 0;
138 int LALoptarg_len = 0;
139
140 c = LALgetopt_long_only( argc, argv,
141 "f:m:n:o:p:hV", long_options,
142 &option_index );
143
144 /* detect the end of the options */
145 if ( c == -1 )
146 {
147 break;
148 }
149
150 switch ( c )
151 {
152 case 0:
153 /* if this option set a flag, do nothing else now */
154 if ( long_options[option_index].flag != 0 )
155 {
156 break;
157 }
158 else
159 {
160 fprintf( stderr, "Error parsing option %s with argument %s\n",
161 long_options[option_index].name, LALoptarg );
162 exit( 1 );
163 }
164 break;
165
166 case 'f':
167 /* flow */
168 fstart=atof(LALoptarg);
169 break;
170
171 case 'm':
172 /* mass1 */
173 m1=atof(LALoptarg);
174 break;
175
176 case 'n':
177 /* mass2 */
178 m2=atof(LALoptarg);
179 break;
180
181 case 'o':
182 LALoptarg_len = strlen( LALoptarg ) + 1;
183 specFile = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
184 memcpy( specFile, LALoptarg, LALoptarg_len );
185 break;
186
187 case 'p':
188 /* number of chisq bins */
189 numChisqBins=atof(LALoptarg);
190 chisqFlag = 1;
191 break;
192
193 case 'q':
194 LALoptarg_len = strlen( LALoptarg ) + 1;
195 waveFile = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
196 memcpy( waveFile, LALoptarg, LALoptarg_len );
197 printWaveform = 1;
198 break;
199
200 case 'h':
201 /* help message */
202 fprintf( stderr, USAGE , argv[0]);
203 exit( 1 );
204 break;
205
206 case 'V':
207 /* print version information and exit */
208 fprintf( stdout, "Compute some basic properties of inspiral signals\n"
209 "Patrick R Brady and Duncan Brown\n"
210 "CVS Version: " CVS_ID_STRING "\n"
211 "CVS Tag: " CVS_NAME_STRING "\n" );
212 exit( 0 );
213 break;
214
215 case '?':
216 fprintf( stderr, USAGE , argv[0]);
217 exit( 1 );
218 break;
219
220 default:
221 fprintf( stderr, "Error: Unknown error while parsing options\n" );
222 fprintf( stderr, USAGE, argv[0] );
223 exit( 1 );
224 }
225 }
226
227 /* if the chisq is to be computed, check we have everything */
228 if ( chisqFlag ){
229 if ( numChisqBins <= 0.0 || !(specFile) ){
230 fprintf(stderr, "Computing chisq bin boundaries:\n");
231 fprintf(stderr, "Need both numChisqBins and specFile\n");
232 exit(1);
233 }
234 }
235
236 /* maul input and print out some information */
237 if ( m1 <= 0.0 || m2 <= 0.0 ){
238 fprintf(stderr, "Mass parameters m1 and m2 must be positive\n");
239 exit(1);
240 }
241
242 mtot = m1 + m2;
243 eta = ( m1 * m2 ) / ( mtot * mtot );
244 mchirp = pow( eta, 0.6) * (mtot);
245 fstop = f_max = 1.0 / (6.0 * sqrt(6.0) * LAL_PI * mtot * LAL_MTSUN_SI);
246
247 if (verbose){
248 fprintf( stdout, "m1 = %e\tm2 = %e\tfLow = %e\n", m1, m2, fstart );
249 fprintf( stdout, "eta = %0.2f\tm = %0.2f\tmchirp = %0.2f\n",
250 eta, mtot, mchirp);
251 fprintf( stdout, "isco freq = %e Hz\n", f_max );
252 }
253
254
255 /***************************************************************************
256 * this is independent code to compute the duration of the chirp
257 **************************************************************************/
258 c0 = 5*mtot*LAL_MTSUN_SI/(256*eta);
259 c2 = 743.0/252.0 + eta*11.0/3.0;
260 c3 = -32.*LAL_PI/5.;
261 c4 = 3058673.0/508032.0 + eta*(5429.0/504.0 + eta*617.0/72.0);
262 x = pow(LAL_PI*mtot*LAL_MTSUN_SI*fstart, 1.0/3.0);
263 x2 = x*x;
264 x3 = x*x2;
265 x4 = x2*x2;
266 x8 = x4*x4;
267 chirpTime = c0*(1 + c2*x2 + c3*x3 + c4*x4)/x8;
268
269 if (verbose){
270 fprintf( stdout, "length = %e seconds\n", chirpTime );
271 }
272
273 /***************************************************************************
274 * Generate a PN waveform using codes in LAL to determine further
275 * information about the waveforms themselves
276 **************************************************************************/
277 ppnParams.mTot = mtot;
278 ppnParams.eta = eta;
279 ppnParams.d = 1.0e6 * LAL_PC_SI ;
280 ppnParams.phi = 0.0;
281 ppnParams.inc = inc;
282
283 /* Set up other parameter structures. */
284 ppnParams.epoch.gpsSeconds = ppnParams.epoch.gpsNanoSeconds = 0;
285 ppnParams.position.latitude = longit;
286 ppnParams.position.longitude = latit;
288 ppnParams.psi = 0.0;
289 ppnParams.fStartIn = fstart;
290 ppnParams.fStopIn = -fstop;
291 ppnParams.lengthIn = 0;
292 ppnParams.ppn = NULL;
293 ppnParams.deltaT = DELTAT;
294 memset( &waveform, 0, sizeof(CoherentGW) );
295
296 /*******************************************************************
297 * Generate the waveform
298 *******************************************************************/
299 if (phiOrder){
300 ppnParams.ppn = phiPPN;
301 }
303 LALPrintError( "%d: %s\n", ppnParams.termCode, ppnParams.termDescription );
304 if ( ppnParams.dfdt > 2.0 ) {
305 LALPrintError( "Waveform sampling interval is too large:\n"
306 "\tmaximum df*dt = %f", ppnParams.dfdt );
307 }
308
309 /*******************************************************************
310 * Print out the information that's wanted for the inspiral group
311 *******************************************************************/
312 if (machine) {
313
314 fprintf( stdout, "%e %e %e %e %e %e\n", m1, m2,
315 ppnParams.fStart, ppnParams.fStop, ppnParams.tc,
316 (float)(0.5/LAL_PI) * (waveform.phi->data->data[waveform.phi->data->length-1]
317 - waveform.phi->data->data[0]) );
318
319 } else {
320
321 fprintf( stdout, "fStart according to Tev = %e Hz\n", ppnParams.fStart );
322 fprintf( stdout, "fStop according to Tev = %e Hz\n", ppnParams.fStop );
323 fprintf( stdout, "length according to Tev = %e seconds\n", ppnParams.tc );
324 fprintf( stdout, "Ncycle according to Tev = %f \n",
325 (float)(0.5/LAL_PI) * (waveform.phi->data->data[waveform.phi->data->length-1]
326 - waveform.phi->data->data[0]));
327
328 }
329
330 /***********************************************************************
331 * Compute the chisq bin boundaries if requested
332 ***********************************************************************/
333 if ( chisqFlag ){
334 REAL4FrequencySeries spectrum;
335 REAL4 df = 0.125;
336 REAL4 freq = 0.0;
337 REAL4 sum = 0.0;
338 REAL4 chisqSum = 0.0;
339 REAL4 norm = 0.0;
340 UINT4 k = 0;
341
342 spectrum.f0 = ppnParams.fStart;
343 spectrum.deltaF = df;
344 spectrum.data = NULL;
345
346 LAL_CALL( LALCreateVector( &status, &(spectrum.data),
347 1 + (INT4)( (ppnParams.fStop - ppnParams.fStart)/spectrum.deltaF ) ),
348 &status );
349
350 LAL_CALL( LALReadNoiseSpectrum( &status, &spectrum, specFile), &status);
351
352 sum = 0.0;
353 norm = (spectrum.data->data[0] * spectrum.data->data[0]);
354 for ( k=0 ; k<spectrum.data->length ; k++){
355 freq = spectrum.f0 + k * df;
356 sum += norm * pow(freq, -7.0/3.0) /
357 (spectrum.data->data[k] * spectrum.data->data[k]);
358 }
359
360 chisqSum = 0.0;
361 for ( k=0 ; k<spectrum.data->length ; k++){
362 freq = spectrum.f0 + k * df;
363 chisqSum += norm * pow(freq, -7.0/3.0)
364 / (spectrum.data->data[k] * spectrum.data->data[k]);
365 if ( chisqSum/sum >= 1.0/numChisqBins ){
366 fprintf(stdout,"%f ",freq);
367 chisqSum = 0.0;
368 }
369 }
370 if ( chisqSum > 0.0 ){
371 fprintf(stdout,"%f ",freq);
372 }
373 }
374
375 /**********************************************************************
376 * Print out the waveform information
377 **********************************************************************/
378 if ( printWaveform ){
379 FILE *fpout=NULL;
380
381 fpout = fopen(waveFile,"w");
382
383 for(i = 0; i<waveform.phi->data->length ; i++)
384 {
385 float tmper = 0.5/LAL_PI;
386 fprintf(fpout,"%e %e %e\n", i*ppnParams.deltaT,
387 waveform.f->data->data[i] ,
388 tmper * waveform.phi->data->data[i] );
389 }
390
391 fclose(fpout);
392 }
393
394 return 0;
395}
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 k
const double c2
const double c0
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
char * LALoptarg
#define no_argument
#define required_argument
#define fprintf
#define DELTAT
Definition: chirplen.c:75
int verbose
Definition: chirplen.c:77
int main(int argc, char *argv[])
Definition: chirplen.c:82
#define CVS_ID_STRING
Definition: chirplen.c:56
#define FSTART
Definition: chirplen.c:74
#define USAGE
Definition: chirplen.c:64
int machine
Definition: chirplen.c:78
int printWaveform
Definition: chirplen.c:80
int chisqFlag
Definition: chirplen.c:79
#define CVS_NAME_STRING
Definition: chirplen.c:57
void LALGeneratePPNInspiral(LALStatus *, CoherentGW *output, PPNParamStruc *params)
#define LAL_PI
#define LAL_MTSUN_SI
#define LAL_PC_SI
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
int LALPrintError(const char *fmt,...)
void LALReadNoiseSpectrum(LALStatus *stat, REAL4FrequencySeries *spectrum, CHAR *fname)
COORDINATESYSTEM_EQUATORIAL
void LALCreateVector(LALStatus *, REAL4Vector **, UINT4)
REAL8 norm
Definition: inspinj.c:572
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
static LALStatus status
Definition: inspinj.c:552
int i
Definition: inspinj.c:596
eta
m2
m1
waveform
c
float freq
int * flag
INT4 gpsNanoSeconds
REAL4Vector * ppn
const CHAR * termDescription
LIGOTimeGPS epoch
SkyPosition position
REAL4Sequence * data
REAL4 * data
REAL8 longitude
REAL8 latitude
CoordinateSystem system
double f_max
double df