Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInspiral 5.0.3.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
InspiralSpinBankTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Chad Hanna, Jolien Creighton, Benjamin Owen
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 * \author Hanna, C.R. and Owen, B. J.
22 * \file
23 * \ingroup LALInspiralBank_h
24 *
25 * \brief Tests InpsiralSpinBank().
26 *
27 * ### Usage ###
28 *
29 * \code
30 * InspiralSpinBankTest
31 * \endcode
32 *
33 * This program uses InspiralSpinBank() to generate a template bank from
34 * command line parameter input. It also has the option to make a
35 * MATHEMATICA notebook using LALMath3DPlot() which will plot the 3D
36 * template bank. If the <tt>-b</tt> option is specified, the program will
37 * read the template bank from an XML file instead of generating it. (This
38 * only works if LAL is compiled with metaio.)
39 *
40 * ### Command line options ###
41 *
42 * <dl>
43 * <dt>-b</dt><dd>
44 * Specifies the XML file to read template bank from. (Only with metaio.)
45 * </dd><dt>-n</dt><dd>
46 * Specifies the minimum smaller mass between 0 and 5.0 \f$M\odot\f$.
47 * </dd><dt>-x</dt><dd>
48 * Specifies the maximum smaller mass between 0 and 5.0 \f$M\odot\f$.
49 * </dd><dt>-m</dt><dd>
50 * Specifies the minimum mismatch threshold (typically 0.03) but for the
51 * sake of testing it is best to pick a value \f$O[1]\f$ to save compiling time.
52 * </dd><dt>-p</dt><dd>
53 * Specifies that the program should generate a MATHEMATICA notebook
54 * "Math3DNotebook.nb".
55 * </dd></dl>
56 *
57 * ### Notes ###
58 *
59 * <ul>
60 *
61 * <li> The metric used in InspiralSpinBank() is only valid for binary
62 * systems with a total mass \f$<15M\odot\f$ where the minimum larger mass is at
63 * least twice the maximum smaller mass. Choosing mass values that violate
64 * these conditions will cause an error message.
65 *
66 * </li><li> Only up to 20,000 templates will be read from an XML file. Making
67 * an animated image will start bogging most systems down with more than a
68 * few thousand templates, so you can switch the option off by editing the
69 * notebook within Mathematica.
70 *
71 * </li></ul>
72 *
73 */
74
75
76#include <math.h>
77#include <stdio.h>
78#include <stdlib.h>
79#include <string.h>
80#include <sys/types.h>
81#include <sys/stat.h>
82#include <lal/AVFactories.h>
83#include <lal/SeqFactories.h>
84#include <lal/LALConfig.h>
85#include <lal/LALgetopt.h>
86#include <lal/LALDatatypes.h>
87#include <lal/LALInspiralBank.h>
88#include <lal/LALMalloc.h>
89#include <lal/LALMathematica.h>
90#include <lal/LALNoiseModels.h>
91#include <lal/LALStatusMacros.h>
92#include <lal/LALStdlib.h>
93#if LAL_METAIO_ENABLED
94 #include <lal/LIGOLwXMLRead.h>
95#endif
96
97
98/**\name Error Codes */
99/** @{ */
100#define INSPIRALSPINBANKTESTC_ENORM 0 /**< Normal exit */
101#define INSPIRALSPINBANKTESTC_EMEM 1 /**< Memory allocation error */
102#define INSPIRALSPINBANKTESTC_ESUB 2 /**< Subroutine error */
103#define INSPIRALSPINBANKTESTC_EFILE 4 /**< File I/O error */
104/** @} */
105
106/** \cond DONT_DOXYGEN */
107
108#define INSPIRALSPINBANKTESTC_MSGENORM "Normal exit"
109#define INSPIRALSPINBANKTESTC_MSGEMEM "Memory allocation error"
110#define INSPIRALSPINBANKTESTC_MSGESUB "Subroutine error"
111#define INSPIRALSPINBANKTESTC_MSGEFILE "File I/O error"
112
113
114
115int main( int argc, char *argv[] )
116{
117 static LALStatus status;
118 UINT4 loop = 0; /* loop counter */
119 Math3DPointList *list = NULL; /* structure for mathematica plot */
120 Math3DPointList *first = NULL;
121 SnglInspiralTable *bankHead = NULL;
122 SnglInspiralTable *tmplt = NULL;
123 InspiralCoarseBankIn coarseIn;
124 INT4 ntiles = 0; /* number of tiles */
125 INT2 Math3DPlot = 0; /* option flag for Mathematica plot */
126 INT4 opt = 0; /* returning value of LALgetopt() */
127 REAL8Vector *psd = NULL;
128 REAL8 df = 1.0;
129 InspiralTemplate inspiralTemplate;
130 REAL4 noiseMin = 1;
131 BOOLEAN haveXML = 0;
132
133
134 if( (list = (Math3DPointList *) LALCalloc( 1, sizeof( Math3DPointList )))
135 == NULL )
136 {
137 LALError( &status, INSPIRALSPINBANKTESTC_MSGEMEM );
138 printf( INSPIRALSPINBANKTESTC_MSGEMEM );
140 }
141
142 first = list;
143
144 /* Stuff for calculating the PSD and Noise Moments */
145 coarseIn.fLower = inspiralTemplate.fLower = 30;
146 coarseIn.fUpper = inspiralTemplate.fCutoff = 2000;
147 coarseIn.iflso = 0;
148
149 /* Parse options. */
150 do
151 {
152 switch (opt)
153 {
154 case 'b':
155#if LAL_METAIO_ENABLED
156 if( (ntiles = LALSnglInspiralTableFromLIGOLw( &bankHead, LALoptarg, 1,
157 20000)) < 1 )
158 {
159 fprintf( stderr, INSPIRALSPINBANKTESTC_MSGEFILE );
161 }
162 haveXML = 1;
163#endif
164 break;
165 case 'm':
166 coarseIn.mmCoarse = atof( LALoptarg );
167 break;
168 case 'n':
169 coarseIn.mMin = atof( LALoptarg );
170 break;
171 case 'p':
172 Math3DPlot = 1;
173 break;
174 case 's':
175 break;
176 case 'x':
177 coarseIn.MMax = atof( LALoptarg );
178 break;
179 default:
180 coarseIn.mmCoarse = 0.1;
181 coarseIn.mMin = 1.0;
182 coarseIn.MMax = 2*3.0;
183 Math3DPlot = 0;
184 break;
185 }
186 }
187 while( (opt = LALgetopt( argc, argv, "b:n:m:x:ps" )) != -1 );
188
189 /* Generate template bank from model noise if not given an XML file. */
190 if( !haveXML )
191 {
192 coarseIn.shf.data = NULL;
193 memset( &(coarseIn.shf), 0, sizeof( REAL8FrequencySeries ) );
194 coarseIn.shf.f0 = 0;
195 LALDCreateVector( &status, &psd, coarseIn.fUpper );
196 df = 1.0;
198 coarseIn.shf.data = psd;
199 coarseIn.shf.deltaF = df;
200 for( loop = 0; loop < psd->length; loop++ )
201 {
202 if( psd->data[loop] > 0 && psd->data[loop] < noiseMin )
203 {
204 noiseMin = psd->data[loop];
205 }
206 }
207 LALInspiralSpinBank( &status, &bankHead, &ntiles, &coarseIn );
208 if( status.statusCode )
209 {
210 LALError( &status, INSPIRALSPINBANKTESTC_MSGESUB );
211 printf( INSPIRALSPINBANKTESTC_MSGESUB );
213 }
214 }
215
216 /* Convert template bank structure to plot input structure. */
217 if( Math3DPlot )
218 {
219 for( tmplt = bankHead; tmplt != NULL; tmplt = tmplt->next )
220 {
221 list->x = tmplt->psi0;
222 list->y = tmplt->psi3;
223 list->z = tmplt->beta;
224 list->grayLevel = 1.0*loop/ntiles;
225 if( (list = list->next = (Math3DPointList *) LALCalloc( 1, sizeof(
226 Math3DPointList ))) == NULL ) {
227 LALError( &status, INSPIRALSPINBANKTESTC_MSGEMEM );
228 printf( INSPIRALSPINBANKTESTC_MSGEMEM );
230 }
231 }
232 list->next = NULL;
233 LALMath3DPlot( &status, first, &ntiles, NULL );
234 if( status.statusCode )
235 {
236 LALError( &status, INSPIRALSPINBANKTESTC_MSGESUB );
237 printf( INSPIRALSPINBANKTESTC_MSGESUB );
239 }
240
241 /* Clean Up the memory from the MathPlot3D structure */
242 list = first;
243 while( list->next )
244 {
245 first = list->next;
246 LALFree( list );
247 list = first;
248 }
249 }
250
251 /* free the last (first?) memory allocated for Math3DPlot. */
252 LALFree( list );
253
254 if (status.statusCode)
256 else
258}
259/** \endcond */
#define INSPIRALSPINBANKTESTC_EFILE
File I/O error.
#define INSPIRALSPINBANKTESTC_EMEM
Memory allocation error.
#define INSPIRALSPINBANKTESTC_ESUB
Subroutine error.
#define INSPIRALSPINBANKTESTC_ENORM
Normal exit.
#define LALCalloc(m, n)
#define LALFree(p)
int LALgetopt(int argc, char *const *argv, const char *optstring)
char * LALoptarg
#define fprintf
unsigned char BOOLEAN
double REAL8
int16_t INT2
uint32_t UINT4
int32_t INT4
float REAL4
int LALError(LALStatus *status, const char *statement)
void LALInspiralSpinBank(LALStatus *status, SnglInspiralTable **tiles, INT4 *ntiles, InspiralCoarseBankIn *coarseIn)
This function creates a bank of BCVSpin templates to search for precessing binaries.
void LALMath3DPlot(LALStatus *status, Math3DPointList *first, INT4 *ntiles, REAL4 *pointSize)
void LALNoiseSpectralDensity(LALStatus *status, REAL8Vector *psd, void(*NoisePsd)(LALStatus *status, REAL8 *shf, REAL8 f), REAL8 df)
void LALLIGOIPsd(LALStatus UNUSED *status, REAL8 *psd, REAL8 f)
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
Input for choosing a template bank.
REAL8 mMin
minimum mass of components to search for
REAL8FrequencySeries shf
Frequency series containing the PSD.
INT4 iflso
iflso is an integer that tells whether to compute the moments using an upper limit defined by flso; t...
REAL8 MMax
alternatively, maximum total mass of binary to search for
REAL8 fUpper
Upper frequency cutoff.
REAL8 fLower
Lower frequency cutoff.
REAL8 mmCoarse
Coarse grid minimal match.
The inspiral waveform parameter structure containing information about the waveform to be generated.
Definition: LALInspiral.h:205
REAL8 fCutoff
upper frequency cutoff in Hz to be used in generating the waveform; If the last stable orbit frequenc...
Definition: LALInspiral.h:213
REAL8 fLower
lower frequency cutoff of the detector in Hz (input)
Definition: LALInspiral.h:217
struct tagMath3DPointList * next
REAL8Sequence * data
REAL8 * data
struct tagSnglInspiralTable * next
int main(int argc, char **argv)
Definition: version.c:32
double df