Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gwf2xml.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Stephen Fairhurst
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: gwf2xml.c
23 *
24 * Author: Fairhurst, S
25 *
26 *
27 *-----------------------------------------------------------------------
28 */
29
30#include <math.h>
31#include <stdio.h>
32#include <stdlib.h>
33
34#include <FrameL.h>
35
36#include <lal/LALgetopt.h>
37#include <lal/Date.h>
38#include <lal/LIGOLwXML.h>
39#include <lal/LIGOLwXMLRead.h>
40#include <lal/LIGOMetadataTables.h>
41
42#define SNR_MIN 6.
43#define SNR_MAX 1.e+10
44#define SIM_MIN 1.0e-30
45#define SIM_MAX 1.0e+10
46
47
48#define USAGE \
49"Usage: gwf2xml [options]\n"\
50 "\n"\
51 " --help display this message\n"\
52 " --input FILE read input data from frame FILE\n"\
53 " --output FILE write output data to xml FILE\n"\
54 " --snr-threshold SNR set the minimum SNR of triggers (default 6)\n"\
55 " --ifo IFO set the IFO from which the triggers have come\n"\
56
57char *ifo = NULL;
58
59/* FIXME: work around for FrameL const string issue */
60static char * ignore_const(const char *s)
61{
62 union {const char *c; char *s; } u = {s};
63 return u.s;
64}
65
66static int frEvent2snglInspiral(SnglInspiralTable **snglInspiralEvent,
67 FrEvent *frameEvent )
68{
69 FrEvent *frEvt = NULL;
70 SnglInspiralTable *snglEvt = NULL;
71 int numEvt = 0;
72 double timeAfter = 0;
73
74 /* If we already have events in snglInspiralEvent,
75 * wind on to the end of the list */
76 for( snglEvt = *snglInspiralEvent; snglEvt; snglEvt=snglEvt->next);
77
78 /* store the frameEvents in the snglInspiral linked list */
79 for(frEvt=frameEvent; frEvt; frEvt=frEvt->next, ++numEvt)
80 {
81 if ( !(*snglInspiralEvent) )
82 {
83 *snglInspiralEvent = snglEvt = (SnglInspiralTable * )
84 LALCalloc( 1, sizeof(SnglInspiralTable) );
85 }
86 else
87 {
88 snglEvt = snglEvt->next = (SnglInspiralTable * )
89 LALCalloc( 1, sizeof(SnglInspiralTable) );
90 }
91
92 /* read data from the frEvt */
93 snprintf(snglEvt->search, LIGOMETA_SEARCH_MAX, "%s", frEvt->name);
94 snglEvt->snr = frEvt->amplitude;
95 snglEvt->end.gpsSeconds = frEvt->GTimeS;
96 snglEvt->end.gpsNanoSeconds = frEvt->GTimeN;
97 timeAfter = frEvt->timeAfter;
98 XLALGPSAdd(&snglEvt->end,timeAfter);
99 snglEvt->eff_distance = FrEventGetParam ( frEvt, ignore_const("distance (Mpc)") );
100 snglEvt->mass1 = FrEventGetParam ( frEvt, ignore_const("mass1") );
101 snglEvt->mass2 = FrEventGetParam ( frEvt, ignore_const("mass2") );
102 snglEvt->tau0 =FrEventGetParam ( frEvt, ignore_const("tau0") );
103 snglEvt->tau3 = FrEventGetParam ( frEvt, ignore_const("tau1p5") );
104 snglEvt->coa_phase = FrEventGetParam ( frEvt, ignore_const("phase") );
105 snglEvt->chisq = FrEventGetParam ( frEvt, ignore_const("chi2") );
106
107 /* populate additional colums */
108 snglEvt->mtotal = snglEvt->mass1 + snglEvt->mass2;
109 snglEvt->eta = (snglEvt->mass1 * snglEvt->mass2) /
110 (snglEvt->mtotal * snglEvt->mtotal);
111 snglEvt->mchirp = pow( snglEvt->eta, 0.6) * snglEvt->mtotal;
112 snprintf(snglEvt->ifo, LIGOMETA_IFO_MAX, "%s", ifo);
113 }
114 return( numEvt );
115}
116
117
118static int frSimEvent2simInspiral (SimInspiralTable **simInspiralEvent,
119 FrSimEvent *frSimEvent )
120{
121 FrSimEvent *frSimEvt = NULL;
122 SimInspiralTable *simEvt = NULL;
123 int numSim = 0;
124
125 /* If we already have events in snglInspiralEvent,
126 * wind on to the end of the list */
127 for( simEvt = *simInspiralEvent; simEvt; simEvt = simEvt->next);
128
129 /* store the frameEvents in the snglInspiral linked list */
130 for( frSimEvt = frSimEvent; frSimEvt; frSimEvt = frSimEvt->next, ++numSim)
131 {
132 if ( !(*simInspiralEvent) )
133 {
134 *simInspiralEvent = simEvt = (SimInspiralTable * )
135 LALCalloc( 1, sizeof(SimInspiralTable) );
136 }
137 else
138 {
139 simEvt = simEvt->next = (SimInspiralTable * )
140 LALCalloc( 1, sizeof(SimInspiralTable) );
141 }
142
143 /* read data from the frSimEvt */
144 snprintf(simEvt->waveform, LIGOMETA_SEARCH_MAX, "%s", frSimEvt->name);
145 simEvt->geocent_end_time.gpsSeconds = frSimEvt->GTimeS;
146 simEvt->geocent_end_time.gpsNanoSeconds = frSimEvt->GTimeN;
147 simEvt->v_end_time = simEvt->geocent_end_time;
148
149
150 simEvt->distance = FrSimEventGetParam ( frSimEvt, ignore_const("distance") );
151 simEvt->eff_dist_v = simEvt->distance;
152
153 simEvt->mass1 = FrSimEventGetParam ( frSimEvt, ignore_const("m1") );
154 simEvt->mass2 = FrSimEventGetParam ( frSimEvt, ignore_const("m2") );
155 }
156
157 return ( numSim );
158}
159
160int main( int argc, char *argv[] )
161{
162 /* program option variables */
163 char *inputFileName = NULL;
164 char *outputFileName = NULL;
165
166
167 /* frame data structures */
168 FrFile *iFile;
169 FrEvent *frameEvent = NULL;
170 FrSimEvent *frSimEvent = NULL;
171
172 double tStart;
173 double tEnd;
174 double duration;
175 double snrMin = SNR_MIN;
176 double snrMax = SNR_MAX;
177
178 double simMin = SIM_MIN;
179 double simMax = SIM_MAX;
180
181 int numEvt = 0;
182 int numSim = 0;
183 /* xml data structures */
184
185 SnglInspiralTable *snglInspiralEvent = NULL;
186 SnglInspiralTable *snglEvt = NULL;
187
188 SimInspiralTable *simInspiralEvent = NULL;
189 SimInspiralTable *simEvt = NULL;
190
191 LIGOLwXMLStream *xmlStream;
193
194 /*
195 *
196 * parse command line arguments
197 *
198 */
199
200
201 while (1)
202 {
203 /* LALgetopt arguments */
204 static struct LALoption long_options[] =
205 {
206 {"help", no_argument, 0, 'h'},
207 {"input", required_argument, 0, 'i'},
208 {"output", required_argument, 0, 'o'},
209 {"snr-threshold", required_argument, 0, 's'},
210 {"ifo", required_argument, 0, 'd'},
211 {0, 0, 0, 0}
212 };
213 int c;
214
215 /* LALgetopt_long stores the option index here. */
216 int option_index = 0;
217 size_t LALoptarg_len;
218
219 c = LALgetopt_long_only ( argc, argv, "hi:o:s:",
220 long_options, &option_index );
221
222 /* detect the end of the options */
223 if ( c == - 1 )
224 break;
225
226 switch ( c )
227 {
228 case 0:
229 /* if this option set a flag, do nothing else now */
230 if ( long_options[option_index].flag != 0 )
231 {
232 break;
233 }
234 else
235 {
236 fprintf( stderr, "error parsing option %s with argument %s\n",
237 long_options[option_index].name, LALoptarg );
238 exit( 1 );
239 }
240 break;
241
242 case 'h':
243 fprintf( stdout, USAGE );
244 exit( 0 );
245 break;
246
247 case 'i':
248 /* create storage for the input file name */
249 LALoptarg_len = strlen( LALoptarg ) + 1;
250 inputFileName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
251 memcpy( inputFileName, LALoptarg, LALoptarg_len );
252 break;
253
254 case 'o':
255 /* create storage for the output file name */
256 LALoptarg_len = strlen( LALoptarg ) + 1;
257 outputFileName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
258 memcpy( outputFileName, LALoptarg, LALoptarg_len );
259 break;
260
261 case 'd':
262 /* create storage for the output file name */
263 LALoptarg_len = strlen( LALoptarg ) + 1;
264 ifo = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
265 memcpy( ifo, LALoptarg, LALoptarg_len );
266 break;
267
268 case 's':
269 snrMin = (double) atof( LALoptarg );
270 if ( snrMin < 0 )
271 {
272 fprintf( stdout, "invalid argument to --%s:\n"
273 "threshold must be >= 0: "
274 "(%f specified)\n",
275 long_options[option_index].name, snrMin );
276 exit( 1 );
277 }
278 break;
279
280 case '?':
281 exit( 1 );
282 break;
283
284 default:
285 fprintf( stderr, "unknown error while parsing options\n" );
286 exit( 1 );
287 }
288 }
289
290 if ( LALoptind < argc )
291 {
292 fprintf( stderr, "extraneous command line arguments:\n" );
293 while ( LALoptind < argc )
294 {
295 fprintf ( stderr, "%s\n", argv[LALoptind++] );
296 }
297 exit( 1 );
298 }
299
300 /*
301 *
302 * read in the triggers from the input frame file
303 *
304 */
305
306 iFile = FrFileINew(inputFileName);
307
308 /* set start time, duration and amplitude window
309 this should be turned into command line arguments */
310
311 tStart = FrFileITStart(iFile);
312 tEnd = FrFileITEnd(iFile);
313 duration = tEnd - tStart;
314
315 /* read in the events */
316 frameEvent = FrEventReadT(iFile, ignore_const("*clustered"), tStart, duration,
317 snrMin, snrMax);
318
319
320 /*Write out details of events to SnglInspiralTable*/
321 numEvt = frEvent2snglInspiral( &snglInspiralEvent, frameEvent);
322
323 fprintf( stdout, "Read in %d triggers from frEvent structure in %s\n",
324 numEvt, inputFileName );
325
326 /* free the frame events */
327 FrEventFree(frameEvent);
328
329
330 /*
331 *
332 * read in the simEvent from the input frame file
333 *
334 */
335
336 frSimEvent = FrSimEventReadT (iFile, ignore_const("cb*"), tStart, duration,
337 simMin, simMax);
338
339 /*Write out details of events to SnglInspiralTable*/
340 numSim = frSimEvent2simInspiral( &simInspiralEvent, frSimEvent);
341
342 fprintf( stdout, "Read in %d injections from frEvent structure in %s\n",
343 numSim, inputFileName );
344
345 /* free the frame events */
346 FrSimEventFree(frSimEvent);
347
348
349 /*
350 *
351 * write a search summary table
352 *
353 */
354
355 /* create the search summary and zero out the summvars table */
356 searchsumm = (SearchSummaryTable *) calloc( 1, sizeof(SearchSummaryTable) );
357
358 searchsumm->in_start_time.gpsSeconds = tStart;
359 searchsumm->in_end_time.gpsSeconds = tEnd;
360
361 searchsumm->out_start_time.gpsSeconds = tStart;
362 searchsumm->out_end_time.gpsSeconds = tEnd;
363 searchsumm->nnodes = 1;
364 if (numEvt)
365 {
366 searchsumm->nevents = numEvt;
367 }
368 else if (numSim)
369 {
370 searchsumm->nevents = numSim;
371 }
372
373
374 /*
375 *
376 * write output data to xml file
377 *
378 */
379
380 /* write xml output file */
382
383 /* Write search_summary table */
385
386
387 /* Write the results to the inspiral table */
388 if ( snglInspiralEvent )
389 XLALWriteLIGOLwXMLSnglInspiralTable( xmlStream, snglInspiralEvent );
390
391 /* Write the results to the sim inspiral table */
392 if ( simInspiralEvent )
393 XLALWriteLIGOLwXMLSimInspiralTable( xmlStream, simInspiralEvent );
394
395 /* close the output file */
396 XLALCloseLIGOLwXMLFile( xmlStream );
397
398
399 /*
400 *
401 * free memory and exit
402 *
403 */
404
405
406 /* free the inspiral events we saved */
407 while ( snglInspiralEvent )
408 {
409 snglEvt = snglInspiralEvent;
410 snglInspiralEvent = snglInspiralEvent->next;
411 LALFree( snglEvt );
412 }
413
414 /* free the sim inspiral events we saved */
415 while ( simInspiralEvent )
416 {
417 simEvt = simInspiralEvent;
418 simInspiralEvent = simInspiralEvent->next;
419 LALFree( simEvt );
420 }
421
423 exit( 0 );
424}
void LALCheckMemoryLeaks(void)
#define LALCalloc(m, n)
#define LALFree(p)
#define tEnd
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
int LALoptind
char * LALoptarg
#define no_argument
#define required_argument
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLSimInspiralTable(LIGOLwXMLStream *, const SimInspiralTable *)
int XLALWriteLIGOLwXMLSnglInspiralTable(LIGOLwXMLStream *xml, const SnglInspiralTable *sngl_inspiral)
int XLALWriteLIGOLwXMLSearchSummaryTable(LIGOLwXMLStream *, const SearchSummaryTable *)
#define LIGOMETA_SEARCH_MAX
#define LIGOMETA_IFO_MAX
#define fprintf
int s
INT4 duration
Definition: blindinj.c:123
const double u
char CHAR
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
int main(int argc, char *argv[])
Definition: gwf2xml.c:160
#define SIM_MIN
Definition: gwf2xml.c:44
#define USAGE
Definition: gwf2xml.c:48
static int frEvent2snglInspiral(SnglInspiralTable **snglInspiralEvent, FrEvent *frameEvent)
Definition: gwf2xml.c:66
#define SIM_MAX
Definition: gwf2xml.c:45
#define SNR_MIN
Definition: gwf2xml.c:42
#define SNR_MAX
Definition: gwf2xml.c:43
static int frSimEvent2simInspiral(SimInspiralTable **simInspiralEvent, FrSimEvent *frSimEvent)
Definition: gwf2xml.c:118
char * ifo
Definition: gwf2xml.c:57
static char * ignore_const(const char *s)
Definition: gwf2xml.c:60
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
char * outputFileName
Definition: inspinj.c:480
searchsumm
c
int * flag
INT4 gpsNanoSeconds
LIGOTimeGPS geocent_end_time
LIGOTimeGPS v_end_time
struct tagSimInspiralTable * next
CHAR waveform[LIGOMETA_WAVEFORM_MAX]
CHAR ifo[LIGOMETA_IFO_MAX]
LIGOTimeGPS end
struct tagSnglInspiralTable * next
CHAR search[LIGOMETA_SEARCH_MAX]