Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mdc.cc
Go to the documentation of this file.
1 #include "mdc.hh"
2 #include "constants.hh"
3 
4 #ifdef _USE_LAL
5 // LAL Stuff
6 #define FAILMSG( stat, func, file, line, id ) \
7  do { \
8  if ( lalDebugLevel & LALERROR ) \
9  { \
10  LALPrintError( "Error[0]: file %s, line %d, %s\n" \
11  "\tLAL_CALL: Function call `%s' failed.\n", file, line, id, func ); \
12  } \
13  } while( 0 )
14 
15 #define LAL_CALL( function, statusptr ) \
16  ((function),lal_errhandler(statusptr,#function,__FILE__,__LINE__,"$Id$"))
17 
18 LALStatus blank_status;
19 
20 typedef int ( *lal_errhandler_t )(
21  LALStatus *,
22  const char *func,
23  const char *file,
24  const int line,
25  volatile const char *id
26  );
27 
28 int LAL_ERR_ABRT(
29  LALStatus *stat,
30  const char *func,
31  const char *file,
32  const int line,
33  volatile const char *id
34  )
35 {
36  if ( stat->statusCode )
37  {
38  FAILMSG( stat, func, file, line, id );
39  abort();
40  }
41  return 0;
42 }
43 
44 int LAL_ERR_EXIT(
45  LALStatus *stat,
46  const char *func,
47  const char *file,
48  const int line,
49  volatile const char *id
50  )
51 {
52  if ( stat->statusCode )
53  {
54  FAILMSG( stat, func, file, line, id );
55  exit( 1 );
56  }
57  return stat->statusCode;
58 }
59 
60 //#define LAL_ERR_DFLT LAL_ERR_ABRT
61 lal_errhandler_t lal_errhandler = LAL_ERR_ABRT;
62 
63 // see LAL binj.c
64 static
65 ProcessParamsTable **add_process_param(ProcessParamsTable **proc_param, const ProcessTable *process,
66  const char *type, const char *param, const char *value) {
67  *proc_param = XLALCreateProcessParamsTableRow(process);
68  snprintf((*proc_param)->program, sizeof((*proc_param)->program), "%s", "cWB");
69  snprintf((*proc_param)->type, sizeof((*proc_param)->type), "%s", type);
70  snprintf((*proc_param)->param, sizeof((*proc_param)->param), "--%s", param);
71  snprintf((*proc_param)->value, sizeof((*proc_param)->value), "%s", value);
72  return &(*proc_param)->next;
73 }
74 
75 #define ADD_PROCESS_PARAM(proc_param, process, type, param, value) \
76  do { proc_param = add_process_param(proc_param, process, type, param, value); } while(0)
77 
78 #endif
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /* BEGIN_HTML
82 <p>The mdc class is designed to easily produce mdc data for simulation
83 
84 Overview:
85 <ol style="list-style-type: upper-roman;">
86  <li><a href="#init">Init</a></li>
87  <li><a href="#conf">Configuration</a>
88  <ol>
89  <li><a href="#conf:setparms">Set Injection Params</a></li>
90  <li><a href="#conf:waveform">Add Waveforms</a></li>
91  <li><a href="#conf:skydistribution">Set SkyDistribution</a></li>
92  </ol>
93  </li>
94  <li><a href="#getdata">Get Data</a></li>
95  <li><a href="#writeframe">Write Frame</a></li>
96 </ol>
97 
98 <h3><a name="init">I. Init</a></h3>
99 Object mdc must be instantiate setting the network detectors:
100 <br><br>
101 <pre>
102  root[] char wf_name[256];
103  root[] waveform wf;
104  root[] vector<mdcpar> par;
105  root[] int nIFO = 3; // number of detectors
106  root[] TString ifo[3] = {"L1","H1","V1"};
107  root[] mdc MDC(nIFO,ifo); // create a mdc object
108 </pre>
109 <h3><a name="conf">II. Configuration</a></h3>
110 In the configuration phase must be define injection parameters, waveforms and sky distribution:
111 <br>
112 <h3><a name="conf:setparms">II.1 Set Injection Params</a></h3>
113 <br>
114 <pre>
115  root[] // --------------------------------------------------------
116  root[] // define injection parameters
117  root[] // --------------------------------------------------------
118  root[] MDC.SetInjHrss(2.5e-21);
119  root[] MDC.SetInjRate(0.0333333);
120  root[] MDC.SetInjJitter(10.0);
121 </pre>
122 <h3><a name="conf:setparms">II.2 Add Waveforms</a></h3>
123 <br>
124 <pre>
125  root[] // --------------------------------------------------------
126  root[] // Add SinGaussian waveform
127  root[] // --------------------------------------------------------
128  root[] par.resize(2);
129  root[] par[0].name="frequency"; par[0].value=235.;
130  root[] par[1].name="Q"; par[1].value=8.9;
131  root[] MDC.AddWaveform(MDC_SG, par);
132  root[] MDC.Print(); // list defined waveforms
133 </pre>
134 <h3><a name="conf:setparms">II.3 Set SkyDistribution</a></h3>
135 <br>
136 <pre>
137  root[] // --------------------------------------------------------
138  root[] // define sky distribution
139  root[] // --------------------------------------------------------
140  root[] par.resize(3);
141  root[] par[0].name="entries";par[0].value=100000; // pool of events
142  root[] par[1].name="rho_min";par[1].value=1; // min rho // Kpc
143  root[] par[2].name="rho_max";par[2].value=100; // max rho // Kpc
144  root[] MDC.SetSkyDistribution(MDC_RANDOM,par,seed);
145 </pre>
146 <h3><a name="getdata">III. Get Data</a></h3>
147 <br>
148 <pre>
149  root[] // --------------------------------------------------------
150  root[] // get data
151  root[] // --------------------------------------------------------
152  root[] waveform x;
153  root[] x.start(0);x.rate(16384);x.size(600*x.rate());
154  root[] MDC.Get(x,ifo[0]);
155 </pre>
156 <h3><a name="writeframe">IV. Write Frame</a></h3>
157 <br>
158 <pre>
159  root[] // --------------------------------------------------------
160  root[] // write frame
161  root[] // --------------------------------------------------------
162  root[] TString frDir = "frames";
163  root[] TString frLabel = "TEST";
164  root[] size_t gps = 123456789;
165  root[] size_t length = 1000; // sec
166  root[] bool log = true;
167  root[] TString ofName = MDC.WriteFrameFile(frDir, frLabel, gps, length, log);
168 </pre>
169 
170 </p>
171 
172 END_HTML */
173 ////////////////////////////////////////////////////////////////////////////////
174 
175 ClassImp(CWB::mdc)
176 
177 //______________________________________________________________________________
178 CWB::mdc::mdc() {
179 //
180 // mdc default constructor
181 //
182 
183  Init();
184  net=NULL;
185 }
186 
187 //______________________________________________________________________________
189 //
190 // mdc constructor
191 //
192 // Input: nIFO - number of detectors
193 // ifo - array of detector names
194 //
195 
196  Init();
197  net = new network;
198 
199  for(int n=0;n<nIFO;n++) net->add(new detector(const_cast<char*>(ifo[n].Data())));
200 }
201 
202 //______________________________________________________________________________
204 //
205 // mdc constructor
206 //
207 // Input: nIFO - number of detectors
208 // pD - array of detector objects
209 //
210 
211  Init();
212  net = new network;
213 
214  for(int n=0; n<nIFO; n++) {
215  detector* _pD = NULL;
216  if(pD[n]->isBuiltin()) _pD = new detector(pD[n]->Name);
217  else _pD = new detector(pD[n]->getDetectorParams());
218  this->net->add(_pD);
219  }
220 }
221 
222 //______________________________________________________________________________
224 //
225 // mdc constructor
226 //
227 // Input: net - network object
228 //
229 
230  Init();
231 
232  if(net!=NULL) {
233 
234  this->net = new network;
235 
236  int nIFO=net->ifoListSize();
237  for(int n=0; n<nIFO; n++) {
238  detector* pD = NULL;
239  if(net->getifo(n)->isBuiltin()) pD = new detector(net->getifo(n)->Name);
240  else pD = new detector(net->getifo(n)->getDetectorParams());
242  pD->setPolarization(polarization);
243  this->net->add(pD);
244  }
245  } else {
246  this->net = NULL;
247  }
248 }
249 
250 //______________________________________________________________________________
252 //
253 // mdc copy constructor
254 //
255 
256  *this = value;
257 }
258 
259 //______________________________________________________________________________
261 //
262 // mdc destructor
263 //
264 
265  if(net!=NULL) {
266  for(int n=0;n<(int)net->ifoListSize();n++) delete net->getifo(n);
267  delete net;
268  }
269  if(inj!=NULL) delete inj;
270  if(sky_distribution!=MDC_LOGFILE)
271  if(inj_tree!=NULL) delete inj_tree;
272 
273  if(psp!=NULL) delete psp;
274  if(stft!=NULL) delete stft;
275  if(pts!=NULL) delete pts;
276 }
277 
278 //______________________________________________________________________________
279 CWB::mdc&
281 //
282 // mdc copy constructor
283 //
284 
285  if(value.net!=NULL) {
286  if(net==NULL) net = new network;
287  else {for(int n=0;n<(int)net->ifoListSize();n++) delete net->getifo(n);}
288  *(net)=*(value.net);
289  net->ifoList.resize(0);
290  int nIFO=value.net->ifoListSize();
291  for(int n=0; n<nIFO; n++) {
292  detector* pD = value.net->getifo(n);
293  if(value.net->getifo(n)->isBuiltin()) net->add(new detector(pD->Name));
294  else net->add(new detector(pD->getDetectorParams()));
296  net->getifo(n)->setPolarization(polarization);
297  }
298  }
299 
300  if(value.inj!=NULL) {
301  int nIFO=net->ifoListSize();
302  if(inj!=NULL) delete inj;
303  inj = new injection(nIFO);
304  inj_tree = inj->setTree();
305  if(value.inj_tree!=NULL) {
306  inj->output(inj_tree,net,1,false);
307  delete inj;
308  inj = new injection(inj_tree,nIFO);
309  }
310  }
311 
312 // if(psp!=NULL) delete psp; psp=NULL;
313 // if(stft!=NULL) delete stft; stft=NULL;
314 // if(pts!=NULL) delete pts; pts=NULL;
315 
316  mdc_coordinates = value.mdc_coordinates;
317  sky_distribution = value.sky_distribution;
318 
319  inspXML = value.inspXML;
320  inspDIR = value.inspDIR;
321  inspName = value.inspName;
322  inspOptions = value.inspOptions;
323  waveName = value.waveName;
324 
325  inj_rate = value.inj_rate;
326  inj_offset = value.inj_offset;
327  inj_jitter = value.inj_jitter;
328  inj_hrss = value.inj_hrss;
329  srcList_seed = value.srcList_seed;
330 
331  wfList.clear(); this->wfList = value.wfList;
332  mdcList.clear(); this->mdcList = value.mdcList;
333  mdcType.clear(); this->mdcType = value.mdcType;
334  xmlType.clear(); this->xmlType = value.xmlType;
335  mdcTime.clear(); this->mdcTime = value.mdcTime;
336  mdcName.clear(); this->mdcName = value.mdcName;
337  srcList.clear(); this->srcList = value.srcList;
338  nameList.clear(); this->nameList = value.nameList;
339  thList.clear(); this->thList = value.thList;
340  phList.clear(); this->phList = value.phList;
341  psiList.clear(); this->psiList = value.psiList;
342  rhoList.clear(); this->rhoList = value.rhoList;
343  iotaList.clear(); this->iotaList = value.iotaList;
344  hrssList.clear(); this->hrssList = value.hrssList;
345  gpsList.clear(); this->gpsList = value.gpsList;
346  IDList.clear(); this->IDList = value.IDList;
347  idList.clear(); this->idList = value.idList;
348 
349  return *this;
350 }
351 
352 //______________________________________________________________________________
353 void
355 //
356 // mdc init
357 //
358 // Input: seed - seed for random generation
359 //
360 
361  inj=NULL;
362  inj_tree=NULL;
363  psp=NULL;
364  stft=NULL;
365  pts=NULL;
366  inspXML="";
367  inspDIR="";
368  inspName="";
369  inspOptions="";
370  waveName="";
371  xml_filename="";
372 
373  epzoom = EPZOOM;
374 
375  sky_distribution = MDC_RANDOM;
376  inj_jitter = MDC_INJ_JITTER;
377  inj_rate = MDC_INJ_RATE;
378  inj_offset = 0.;
379  inj_hrss = MDC_INJ_HRSS;
380  inj_length = MDC_INJ_LENGTH;
381  srcList_seed = 0;
382  gRandom->SetSeed(seed);
383 
384  wfList.clear();
385  mdcList.clear();
386  mdcType.clear();
387  xmlType.clear();
388  mdcTime.clear();
389  mdcName.clear();
390  srcList.clear();
391  nameList.clear();
392  thList.clear();
393  phList.clear();
394  psiList.clear();
395  rhoList.clear();
396  iotaList.clear();
397  hrssList.clear();
398  gpsList.clear();
399  IDList.clear();
400  idList.clear();
401 }
402 
403 //______________________________________________________________________________
404 double
405 CWB::mdc::GetPar(TString name, vector<mdcpar> par, bool& error) {
406 //
407 // Return Waveform parameter
408 //
409 //
410 // Input: name - parameter name
411 // par - vector of parameters
412 //
413 // Return: parameter value
414 //
415 
416  for(int i=0;i<(int)par.size();i++) {
417  if(par[i].name.CompareTo(name)==0) return par[i].value;
418  }
419  error=true;
420  return 0.;
421 }
422 
423 //______________________________________________________________________________
424 TString
425 CWB::mdc::GetParString(TString name, vector<mdcpar> par, bool& error) {
426 //
427 // Return Waveform string parameter
428 //
429 //
430 // Input: name - parameter name
431 // par - vector of parameters
432 //
433 // Return: parameter string
434 //
435 
436  for(int i=0;i<(int)par.size();i++) {
437  if(par[i].name.CompareTo(name)==0) return par[i].svalue;
438  }
439  error=true;
440  return "";
441 }
442 
443 //______________________________________________________________________________
444 mdcid
445 CWB::mdc::AddWaveform(MDC_TYPE mdc_type, vector<mdcpar> par, TString uname) {
446 //
447 // Add Waveform to this object
448 //
449 //
450 // Input: mdc_type - name of mdc
451 // par - input mdc parameters
452 //
453 // mdc_type & par can be one of the following choices :
454 //
455 // MDC_SG/MDC_SGL = Linear SinGaussian
456 // MDC_SGC = Circular SinGaussian
457 // MDC_SGE = Elliptical SinGaussian // created as SGC (ellipticity must be defined by iota)
458 // vector<mdcpar> par(2);
459 // ` par[0].name="frequency"; par[0].value=XXX; // Hz
460 // par[1].name="Q"; par[1].value=YYY;
461 //
462 // MDC_CG/MDC_CGL = Linear CosGaussian
463 // MDC_CGC = Circular CosGaussian
464 // MDC_CGE = Elliptical CosGaussian // created as CGC (ellipticity must be defined by iota)
465 // vector<mdcpar> par(2);
466 // ` par[0].name="frequency"; par[0].value=XXX; // Hz
467 // par[1].name="Q"; par[1].value=YYY;
468 //
469 // MDC_RD/MDC_RDL = Linear RingDown
470 // MDC_RDC = Circular RingDown
471 // MDC_RDE = Elliptical RingDown // created as RGC (ellipticity must be defined by iota)
472 // vector<mdcpar> par(2);
473 // ` par[0].name="frequency"; par[0].value=XXX; // Hz
474 // par[1].name="tau"; par[1].value=YYY;
475 //
476 // MDC_SGE_LAL = LAL SinGaussian (see definition in LALSimBurst.c)
477 // Difference from MDC_SGE : LAL use CG instead of SG !!!
478 // force eccentricity=0 --> circularly polarized
479 // force polarization=0
480 // NOTE : created as SGC (ellipticity must be defined by iota)
481 // polarization=0 (polarization is defined by psi)
482 // vector<mdcpar> par(2);
483 // ` par[0].name="frequency"; par[0].value=XXX; // Hz
484 // par[1].name="Q"; par[1].value=YYY;
485 //
486 // MDC_WNB = White Noise Burst
487 // vector<mdcpar> par(x);
488 // par[0].name="frequency"; par[0].value=XXX; // Hz : initial frequency
489 // par[1].name="bandwidth"; par[1].value=YYY; // Hz
490 // par[2].name="duration"; par[2].value=ZZZ; // sec
491 // par[3].name="pseed"; par[3].value=ppp; // (opt) seed fo hp component (def=0)
492 // par[4].name="xseed"; par[4].value=xxx; // (opt) seed fo hx component (def=0)
493 // par[5].name="mode"; par[5].value=mmm; // (opt) 0/1 a/symmetric respect central freq
494 // // 0 = (default)
495 //
496 // MDC_WNB_LAL = LAL White Noise Burst (see definition in LALSimBurst.c)
497 // Difference from MDC_WNB : LAL has a gaussian envelope also in frequency
498 // NOtE : LAL seed = waveform_number = hseed*10000000000+lseed
499 // vector<mdcpar> par(5);
500 // par[0].name="frequency"; par[0].value=XXX; // Hz : central frequency
501 // par[1].name="bandwidth"; par[1].value=YYY; // Hz
502 // par[2].name="duration"; par[2].value=ZZZ; // sec
503 // par[3].name="lseed"; par[3].value=ppp; // low seed (max 10 int digits)
504 // par[4].name="hseed"; par[4].value=xxx; // high seed (max 10 int digits)
505 //
506 // MDC_GA = Gaussian Burst
507 // vector<mdcpar> par(1);
508 // par[0].name="duration"; par[0].value=XXX; // sec
509 //
510 // MDC_GA_LAL = LAL Gaussian (see definition in LALSimBurst.c)
511 // vector<mdcpar> par(1);
512 // par[0].name="duration"; par[0].value=XXX; // sec
513 //
514 // MDC_SC_LAL = LAL Generates cosmic string cusp waveforms (see definition in XLALGenerateStringCusp, LALSimBurst.c)
515 // vector<mdcpar> par(1);
516 // par[0].name="frequency"; par[0].value=XXX; // High frequency cut-off (Hertz)
517 // par[1].name="amplitude"; par[1].value=YYY; // amplitude (strain)
518 //
519 // MDC_EBBH = Eccentric Binary Black Holes // created as Circular (ellipticity must be defined by iota)
520 // // are generated with hrss @ distance GM/c^2 meters
521 // // custom hrss is disabled
522 // vector<mdcpar> par(1);
523 // par[0].name="file_name"; // ebbh list file name [.lst/.root]
524 // // .lst format : one event for each line
525 // // -> m1 m2 rp0 e0 (hp,hx are generated 'On The Fly')
526 // // .root format : one event for each entry
527 // // -> id m1 m2 rp0 e0 hp hx
528 // par[1].name="tree cuts"; // optional : used .root file to select tree entries
529 //
530 // or
531 //
532 // vector<mdcpar> par(1);
533 // par[0].name="ebbh parameters"; // ebbh parameters : id m1 m2 rp0 e0 dist(Kpc) redshift
534 //
535 // uname - is the name of waveform, if uname="" then uses the builtin name (default)
536 // not enable for MDC_EBBH
537 //
538 // Return: the name of waveform
539 //
540 //
541 // Note : For the elliptically polarized MDC's, they were produced as follows:
542 //
543 // h(t) = F_+ h_+(t) + F_x h_x(t)
544 //
545 // where
546 //
547 // h_+ = 0.5*(1+cos(iota) * A(t) cos(Phi(t))
548 // h_x = cos(iota) * A(t) sin(Phi(t))
549 //
550 // See Patrick's document here: (https://dcc.ligo.org/LIGO-P1000041)
551 //
552 
553  // check if mdc_type is in the MDC_TYPE list
554  if(mdc_type<0 || mdc_type>=MDC_USER) {
555  cout << "CWB::mdc::AddWaveform - Error : mdc type " << mdc_type << " not allowed !!!" << endl;
556  exit(1);
557  }
558 
559  char wf_name[128];
560  waveform wf;
561  mdcid waveid = {"",0,0};
562 
563  // get number of decimals to be used to format the waveform name
564  bool error=false;
565  int decimals = (int)GetPar("decimals",par,error);
566  if(error) decimals = -1; // default format (like BurstMDC)
567 
568  if((mdc_type==MDC_RDE) ||
569  (mdc_type==MDC_RDC) ||
570  (mdc_type==MDC_RD)) {
571 
572  error=false;
573  double frequency = GetPar("frequency",par,error);
574  double tau = GetPar("tau",par,error);
575  double iota=0.;
576  if(mdc_type==MDC_RDE) iota = 0.; // iota can be customized with SetSkyDistribution
577  if(mdc_type==MDC_RDC) iota = 0.;
578  if(mdc_type==MDC_RD) iota = 90.;
579 
580  if(error) {
581  cout << "CWB::mdc::AddWaveform - "
582  << "Error : num par must be at least 2 [frequency,tau]" << endl;
583  exit(1);
584  }
585 
586  int d1 = decimals==-1 ? 0 : decimals;
587  int d2 = decimals==-1 ? 1 : decimals;
588 
589  if(mdc_type==MDC_RD) sprintf(wf_name, "RD_%.*f_%.*f",d1,frequency,d2,tau);
590  if(mdc_type==MDC_RDC) sprintf(wf_name,"RDC_%.*f_%.*f",d1,frequency,d2,tau);
591  if(mdc_type==MDC_RDE) sprintf(wf_name,"RDE_%.*f_%.*f",d1,frequency,d2,tau);
592 
593  wf.type = mdc_type;
594  wf.name = wf_name;
595  wf.name.ReplaceAll(".","d");
596  if(uname!="") wf.name = uname;
597  wf.hp = GetRD(frequency,tau,iota,0);
598  wf.hx = GetRD(frequency,tau,iota,1);
599  wf.hpPath = wf.name;
600  wf.hxPath = wf.name;
601  wf.par=par;
602  return AddWaveform(wf);
603 
604  } else
605  if((mdc_type==MDC_SGC) ||
606  (mdc_type==MDC_SGE) ||
607  (mdc_type==MDC_SG)) {
608 
609  error=false;
610  double frequency = GetPar("frequency",par,error);
611  double Q = GetPar("Q" ,par,error);
612 
613  if(error) {
614  cout << "CWB::mdc::AddWaveform - Error : num par must be 2 [frequency,Q]" << endl;
615  exit(1);
616  }
617 
618  int d1 = decimals==-1 ? 0 : decimals;
619  int d2 = decimals==-1 ? 1 : decimals;
620 
621  if(mdc_type==MDC_SG) sprintf(wf_name, "SG%.*fQ%.*f",d1,frequency,d2,Q);
622  if(mdc_type==MDC_SGC) sprintf(wf_name,"SGC%.*fQ%.*f",d1,frequency,d2,Q);
623  if(mdc_type==MDC_SGE) sprintf(wf_name,"SGE%.*fQ%.*f",d1,frequency,d2,Q);
624 
625  wf.type = mdc_type;
626  wf.name = wf_name;
627  wf.name.ReplaceAll(".","d");
628  if(decimals==-1) wf.name.ReplaceAll("d0","");
629  if(uname!="") wf.name = uname;
630  wf.hp = GetSGQ(frequency,Q);
631  if(mdc_type==MDC_SG) { // iota = 90
632  wf.hx = wf.hp;
633  wf.hx = 0;
634  wf.hpPath = wf.name;
635  wf.hxPath = "";
636  } else { // iota = 0; for MDC_SGE iota can be customized with SetSkyDistribution
637  wf.hx = GetCGQ(frequency,Q);
638  wf.hpPath = wf.name;
639  wf.hxPath = wf.name;
640  }
641  wf.par=par;
642  return AddWaveform(wf);
643 
644  } else
645  if((mdc_type==MDC_CGC) ||
646  (mdc_type==MDC_CGE) ||
647  (mdc_type==MDC_CG)) {
648 
649  error=false;
650  double frequency = GetPar("frequency",par,error);
651  double Q = GetPar("Q" ,par,error);
652 
653  if(error) {
654  cout << "CWB::mdc::AddWaveform - Error : num par must be 2 [frequency,Q]" << endl;
655  exit(1);
656  }
657 
658  int d1 = decimals==-1 ? 0 : decimals;
659  int d2 = decimals==-1 ? 1 : decimals;
660 
661  if(mdc_type==MDC_CG) sprintf(wf_name, "CG%.*fQ%.*f",d1,frequency,d2,Q);
662  if(mdc_type==MDC_CGC) sprintf(wf_name,"CGC%.*fQ%.*f",d1,frequency,d2,Q);
663  if(mdc_type==MDC_CGE) sprintf(wf_name,"CGE%.*fQ%.*f",d1,frequency,d2,Q);
664 
665  wf.type = mdc_type;
666  wf.name = wf_name;
667  wf.name.ReplaceAll(".","d");
668  if(decimals==-1) wf.name.ReplaceAll("d0","");
669  if(uname!="") wf.name = uname;
670  wf.hp = GetCGQ(frequency,Q);
671  if(mdc_type==MDC_CG) { // iota = 90
672  wf.hx = wf.hp;
673  wf.hx = 0;
674  wf.hpPath = wf.name;
675  wf.hxPath = "";
676  } else { // iota = 0; for MDC_CGE iota can be customized with SetSkyDistribution
677  wf.hx = GetSGQ(frequency,Q);
678  wf.hpPath = wf.name;
679  wf.hxPath = wf.name;
680  }
681  wf.par=par;
682  return AddWaveform(wf);
683 
684  } else
685  if(mdc_type==MDC_WNB) {
686 
687  error=false;
688  double frequency = GetPar("frequency",par,error);
689  double bandwidth = GetPar("bandwidth",par,error);
690  double duration = GetPar("duration" ,par,error);
691 
692  if(error) {
693  cout << "CWB::mdc::AddWaveform - "
694  << "Error : WNB par must at least "
695  << "[frequency,bandwidth,duration]" << endl;
696  exit(1);
697  }
698 
699  error=false; int pseed = (int)GetPar("pseed",par,error); if(error) pseed=0;
700  error=false; int xseed = (int)GetPar("xseed",par,error); if(error) xseed=0;
701  error=false; bool mode = (bool)GetPar("mode",par,error); if(error) mode=0;
702 
703  int d1 = decimals==-1 ? 0 : decimals;
704  int d2 = decimals==-1 ? 0 : decimals;
705  int d3 = decimals==-1 ? 3 : decimals;
706 
707  sprintf(wf_name,"WNB%.*f_%.*f_%.*f",d1,frequency,d2,bandwidth,d3,duration);
708 
709  wf.type = mdc_type;
710  wf.name = wf_name;
711  wf.name.ReplaceAll(".","d");
712  if(uname!="") wf.name = uname;
713  wf.hp = GetWNB(frequency,bandwidth,duration,pseed,mode);
714  wf.hpPath = wf.name;
715  wf.hx = GetWNB(frequency,bandwidth,duration,xseed,mode);
716  wf.hxPath = wf.name;
717  wf.par=par;
718  return AddWaveform(wf);
719 
720  } else
721  if(mdc_type==MDC_GA) {
722 
723  error=false;
724  double duration = GetPar("duration" ,par,error);
725 
726  if(error) {
727  cout << "CWB::mdc::AddWaveform - "
728  << "Error : num par must at least 1 "
729  << "[duration]" << endl;
730  exit(1);
731  }
732 
733  int d1 = decimals==-1 ? 1 : decimals;
734 
735  sprintf(wf_name,"GA%.*f",d1,1000.*duration);
736 
737  wf.type = mdc_type;
738  wf.name = wf_name;
739  wf.name.ReplaceAll(".","d");
740  if(uname!="") wf.name = uname;
741  wf.hp = GetGA(duration);
742  wf.hpPath = wf.name;
743  wf.hx = wf.hp;
744  wf.hx = 0;
745  wf.hxPath = "";
746  wf.par=par;
747  return AddWaveform(wf);
748 
749  } else
750  if(mdc_type==MDC_GA_LAL) { // use LAL GA waveform
751 
752 #if LAL_VERSION_MAJOR > 6 || (LAL_VERSION_MAJOR == 6 && \
753  (LAL_VERSION_MINOR > 15 || (LAL_VERSION_MINOR == 15 && \
754  LAL_VERSION_MICRO >= 0 ))) // LAL_VERSION >= 6.15.0
755 #ifdef _USE_LAL
756  error=false;
757  double duration = GetPar("duration",par,error);
758 
759  if(error) {
760  cout << "CWB::mdc::AddWaveform - "
761  << "Error : wrong input LAL GA parameters : "
762  << "[duration,decimals(opt)]" << endl;
763  exit(1);
764  }
765 
766  // create & populate SimBurst structure
767  SimBurst *sim_burst = XLALCreateSimBurst();
768  strcpy(sim_burst->waveform, "Gaussian");
769  sim_burst->duration = duration;
770  mdcpar mpar={"normalization",1};par.push_back(mpar); // force normalization
771  waveid = AddWaveform(MDC_GA_LAL, sim_burst, par, uname);
772  XLALDestroySimBurst(sim_burst);
773  return waveid;
774 #else
775  cout << "CWB::mdc::AddWaveform - "
776  << "Error : MDC_GA_LAL is enabled only with LAL" << endl;
777  exit(1);
778 #endif
779 #else
780  cout << "CWB::mdc::AddWaveform - MDC_GA_LAL can not be used with LAL ver < 6.15.0" << endl;
781  exit(1);
782 #endif
783 
784  } else
785  if(mdc_type==MDC_SGE_LAL) { // use LAL SG waveform
786 
787 #ifdef _USE_LAL
788  error=false;
789  double frequency = GetPar("frequency",par,error);
790  double Q = GetPar("Q",par,error);
791 
792  if(error) {
793  cout << "CWB::mdc::AddWaveform - "
794  << "Error : wrong input LAL SG parameters : "
795  << "[frequency,Q,decimals(opt)]" << endl;
796  exit(1);
797  }
798 
799  // create & populate SimBurst structure
800  SimBurst *sim_burst = XLALCreateSimBurst();
801  strcpy(sim_burst->waveform, "SineGaussian");
802  sim_burst->frequency = frequency;
803  sim_burst->q = Q;
804  sim_burst->hrss = 1;
805  // force eccentricity=0 --> circularly polarized (it is a SG parameter)
806  // the ellipticity is applied elsewhere using iota
807  sim_burst->pol_ellipse_e=0.;
808  // force polarization=0 (it is a SG parameter)
809  // the polarization is applied elsewhere using psi
810  sim_burst->pol_ellipse_angle=0.;
811  mdcpar mpar={"normalization",1};par.push_back(mpar); // force normalization
812  waveid = AddWaveform(MDC_SGE_LAL, sim_burst, par, uname);
813  XLALDestroySimBurst(sim_burst);
814  return waveid;
815 #else
816  cout << "CWB::mdc::AddWaveform - "
817  << "Error : MDC_SGE_LAL is enabled only with LAL" << endl;
818  exit(1);
819 #endif
820 
821  } else
822  if(mdc_type==MDC_WNB_LAL) { // use LAL WNB waveform != from cWB WNB
823 
824 #ifdef _USE_LAL
825  error=false;
826  double frequency = GetPar("frequency",par,error);
827  double bandwidth = GetPar("bandwidth",par,error);
828  double duration = GetPar("duration" ,par,error);
829  // LAL waveform_number = hseed*10000000000+lseed
830  int lseed = (int)GetPar("lseed" ,par,error);
831  int hseed = (int)GetPar("hseed" ,par,error);
832 
833  if(error) {
834  cout << "CWB::mdc::AddWaveform - "
835  << "Error : wrong input LAL WNB parameters : "
836  << "[frequency,bandwidth,duration,lseed,hseed,decimals(opt)]" << endl;
837  exit(1);
838  }
839 
840  // create & populate SimBurst structure
841  SimBurst *sim_burst = XLALCreateSimBurst();
842  strcpy(sim_burst->waveform, "BTLWNB");
843  sim_burst->frequency = frequency;
844  sim_burst->duration = duration;
845  sim_burst->bandwidth = bandwidth;
846  sim_burst->egw_over_rsquared = 1;
847  sim_burst->waveform_number = hseed*10000000000+lseed;
848  mdcpar mpar={"normalization",1};par.push_back(mpar); // force normalization
849  waveid = AddWaveform(MDC_WNB_LAL, sim_burst, par, uname);
850  XLALDestroySimBurst(sim_burst);
851  return waveid;
852 #else
853  cout << "CWB::mdc::AddWaveform - "
854  << "Error : MDC_WNB_LAL is enabled only with LAL" << endl;
855  exit(1);
856 #endif
857 
858  } else
859  if(mdc_type==MDC_SC_LAL) { // use LAL cosmic string cusp waveform
860 
861 #if LAL_VERSION_MAJOR > 6 || (LAL_VERSION_MAJOR == 6 && \
862  (LAL_VERSION_MINOR > 15 || (LAL_VERSION_MINOR == 15 && \
863  LAL_VERSION_MICRO >= 0 ))) // LAL_VERSION >= 6.15.0
864 #ifdef _USE_LAL
865  error=false;
866  double frequency = GetPar("frequency",par,error);
867  double amplitude = GetPar("amplitude",par,error);
868 
869  if(error) {
870  cout << "CWB::mdc::AddWaveform - "
871  << "Error : wrong input LAL SC parameters : "
872  << "[frequency,amplitude,decimals(opt)]" << endl;
873  exit(1);
874  }
875 
876  // create & populate SimBurst structure
877  SimBurst *sim_burst = XLALCreateSimBurst();
878  strcpy(sim_burst->waveform, "StringCusp");
879  sim_burst->frequency = frequency;
880  if(amplitude>0) {
881  sim_burst->amplitude = amplitude;
882  } else {
883  sim_burst->amplitude = 1;
884  mdcpar mpar={"normalization",1};par.push_back(mpar); // force normalization
885  }
886  waveid = AddWaveform(MDC_SC_LAL, sim_burst, par, uname);
887  XLALDestroySimBurst(sim_burst);
888  return waveid;
889 #else
890  cout << "CWB::mdc::AddWaveform - "
891  << "Error : MDC_SC_LAL is enabled only with LAL" << endl;
892  exit(1);
893 #endif
894 #else
895  cout << "CWB::mdc::AddWaveform - MDC_SC_LAL can not be used with LAL ver < 6.15.0" << endl;
896  exit(1);
897 #endif
898 
899  } else
900  if(mdc_type==MDC_EBBH) {
901 
902 #ifdef _USE_EBBH
903 
904  if(par.size()<1) {
905  cout << "CWB::mdc::AddWaveform - "
906  << "Error : num par must at least 1 "
907  << "[file name (.lst/.root) : list of eBBH mdc]" << endl;
908  exit(1);
909  }
910 
911  TString fName = par[0].name; // get list file name of eBBH mdc
912 
913  if(fName.EndsWith(".lst")) { // read lst file
914 
915  ifstream in;
916  in.open(fName,ios::in);
917  if (!in.good()) {
918  cout << "CWB::mdc::AddWaveform - Error Opening File : " << fName << endl;
919  exit(1);
920  }
921 
922  // get number of entries
923  int entries=0;
924  char str[1024];
925  while(true) {
926  in.getline(str,1024);
927  if (!in.good()) break;
928  if(str[0] != '#') entries++;
929  }
930  cout << "entries " << entries << endl;
931  in.clear(ios::goodbit);
932  in.seekg(0, ios::beg);
933 
934  double m1,m2,rp0,e0,dist,redshift;
935  int id;
936  int fpos=0;
937  while (1) {
938  fpos=in.tellg();
939  in.getline(str,1024);
940  if(str[0] == '#') continue;
941  if (!in.good()) break;
942 
943  dist=0;
944  redshift=0;
945  std::stringstream linestream(str);
946  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist >> redshift)) {
947  linestream.str(str);
948  linestream.clear(); // clear stringstream error status
949  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist)) {
950  linestream.str(str);
951  linestream.clear(); // clear stringstream error status
952  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0)) {
953  cout << "CWB::mdc::AddWaveform - Wrong Format for File : " << fName << endl;
954  cout << "input line : " << endl;
955  cout << str << endl;
956  cout << "must be : " << endl;
957  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << endl;
958  cout << "or : " << endl;
959  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << " dist " << endl;
960  cout << "or : " << endl;
961  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << " dist " << " redshift " << endl;
962  exit(1);
963  }
964  }
965  }
966 
967  wf.type = mdc_type;
968  wf.name = "eBBH";
969  wf.hpPath = "eBBH";
970  wf.hxPath = "eBBH";
971  wf.par.resize(1);
972  wf.par[0].name=str;
973  wf.par[0].value=MDC_EBBH;
974  waveid = AddWaveform(wf);
975  }
976 
977  in.close();
978  return waveid;
979 
980  } else
981  if(fName.EndsWith(".root")) { // read root file
982 
983  TFile* efile = new TFile(fName);
984  if(efile==NULL) {
985  cout << "CWB::mdc::AddWaveform - Error opening root file : " << fName.Data() << endl;
986  exit(1);
987  }
988 
989  int id;
990  double m1,m2,rp0,e0,dist,redshift;
993 
994  TTree* etree = (TTree *) efile->Get("ebbh");
995  if(etree==NULL) {
996  cout << "CWB::mdc::AddWaveform - file : " << fName.Data()
997  << " not contains tree ebbh" << endl;
998  exit(1);
999  }
1000 
1001  etree->SetBranchAddress("id",&id);
1002  etree->SetBranchAddress("m1",&m1);
1003  etree->SetBranchAddress("m2",&m2);
1004  etree->SetBranchAddress("rp0",&rp0);
1005  etree->SetBranchAddress("e0",&e0);
1006  etree->SetBranchAddress("hp",&hp);
1007  etree->SetBranchAddress("hx",&hx);
1008  int dstatus = (etree->GetBranch("dist")==NULL) ? 0 : etree->SetBranchAddress("dist",&dist);
1009  int rstatus = (etree->GetBranch("redshift")==NULL) ? 0 : etree->SetBranchAddress("redshift",&redshift);
1010 
1011  TString ecut = "";
1012  if(par.size()==2) ecut = par[1].name; // get tree selection cut of eBBH mdc
1013  etree->Draw("Entry$",ecut,"goff");
1014  double* entry = etree->GetV1();
1015  int esize = etree->GetSelectedRows();
1016  for(int i=0;i<esize;i++) {
1017  etree->GetEntry(entry[i]);
1018  char str[256];
1019  if(rstatus) sprintf(str,"%d %f %f %f %f %f %f",id,m1,m2,rp0,e0,dist,redshift);
1020  else if(dstatus) sprintf(str,"%d %f %f %f %f %f",id,m1,m2,rp0,e0,dist);
1021  else sprintf(str,"%d %f %f %f %f",id,m1,m2,rp0,e0);
1022 
1023  //cout << id << " " << m1 << " " << m2 << " " << rp0 << " " << e0 << endl;
1024 
1025  wf.type = mdc_type;
1026  wf.name = "eBBH";
1027  wf.hpPath = "eBBH";
1028  wf.hxPath = "eBBH";
1029  wf.par.resize(2);
1030  wf.par[0].name=str;
1031  wf.par[0].value=MDC_EBBH;
1032  wf.par[1].name=fName;
1033  wf.par[1].value=entry[i];
1034  waveid = AddWaveform(wf);
1035  }
1036  delete hp;
1037  delete hx;
1038  delete efile;
1039  return waveid;
1040 
1041  } else { // eBBH values are defined in the par[0].name
1042 
1043  char str[1024];
1044  sprintf(str,par[0].name.Data());
1045  double m1,m2,rp0,e0,dist,redshift;
1046  int id;
1047  dist=0;
1048  redshift=0;
1049  std::stringstream linestream(str);
1050  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist >> redshift)) {
1051  linestream.str(str);
1052  linestream.clear(); // clear stringstream error status
1053  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist)) {
1054  linestream.str(str);
1055  linestream.clear(); // clear stringstream error status
1056  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0)) {
1057  cout << "CWB::mdc::AddWaveform - Wrong Input Parameter Format : " << str << endl;
1058  cout << "input line : " << endl;
1059  cout << str << endl;
1060  cout << "must be : " << endl;
1061  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << endl;
1062  cout << "or : " << endl;
1063  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << " dist " << endl;
1064  cout << "or : " << endl;
1065  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << " dist " << " redshift " << endl;
1066  exit(1);
1067  }
1068  }
1069  }
1070 
1071  wf.type = mdc_type;
1072  wf.name = "eBBH";
1073  wf.hpPath = "eBBH";
1074  wf.hxPath = "eBBH";
1075  wf.par.resize(1);
1076  wf.par[0].name=str;
1077  wf.par[0].value=MDC_EBBH;
1078  waveid = AddWaveform(wf);
1079  }
1080 
1081 #else
1082  cout << "CWB::mdc::AddWaveform - Error : MDC_EBBH not enabled !!!" << endl;
1083  exit(1);
1084 #endif
1085 
1086  return waveid;
1087  }
1088 
1089  cout << "CWB::mdc::AddWaveform - Warning : waveform not added !!!" << endl;
1090  return waveid;
1091 }
1092 
1093 #ifdef _USE_LAL
1094 //______________________________________________________________________________
1095 mdcid
1096 CWB::mdc::AddWaveform(MDC_TYPE mdc_type, SimBurst* sim_burst, vector<mdcpar> par, TString uname) {
1097 //
1098 // Add LAL SimBurst Waveform to this object
1099 //
1100 //
1101 // Input: mdc_type - name of mdc
1102 //
1103 // MDC_SGE_LAL = LAL SinGaussian
1104 // Difference from MDC_SGE : LAL use CG instead of SG !!!
1105 // Uses eccentricity instead of ellipticity !!!
1106 //
1107 // MDC_WNB_LAL = LAL White Noise Burst
1108 // Difference from MDC_WNB : LAL has a gaussian envelope also in frequency
1109 //
1110 // MDC_GA_LAL = LAL Gaussian Burst
1111 //
1112 // MDC_SC_LAL = LAL Cosmic String Cusp
1113 //
1114 // sim_burst - The LAL SimBurst structure describes a burst injection
1115 // (see LIGOMetadataTables.h)
1116 //
1117 // par - number of decimals used to format the waveform name
1118 // if not defined ; used default format
1119 // vector<mdcpar> par(1);
1120 // par[0].name="decimals"; par[0].value=XXX;
1121 // par[1].name="normalization"; par[1].value=X; // X= 0/1 = disabled/enabled
1122 //
1123 // uname - is the name of waveform, if uname="" then uses the builtin name (default)
1124 //
1125 // Return: the name of the waveform
1126 //
1127 
1128  // check if mdc_type is in the MDC_TYPE list
1129  if(mdc_type<0 || mdc_type>=MDC_USER) {
1130  cout << "CWB::mdc::AddWaveform - Error : mdc type " << mdc_type << " not allowed !!!" << endl;
1131  exit(1);
1132  }
1133  if(sim_burst==NULL) {
1134  cout << endl << "CWB::mdc::AddWaveform - "
1135  << "Error in LAL AddWaveform : SimBurst is NULL" << endl;
1136  exit(1);
1137  }
1138 
1139  char wf_name[128];
1140  waveform wf;
1141 
1142  // get number of decimals to be used to format the waveform name
1143  bool error=false;
1144  int decimals = (int)GetPar("decimals",par,error);
1145  if(error) decimals = -1; // default format (like BurstMDC)
1146  error=false;
1147  int normalization = (int)GetPar("normalization",par,error);
1148  if(error) normalization = 0; // default : use normalization defined in sim_burst
1149 
1150  REAL8TimeSeries *hp=NULL;
1151  REAL8TimeSeries *hx=NULL;
1152 
1153  REAL8 deltaT = 1./MDC_SAMPLE_RATE;
1154 
1155  /* Get waveform from LAL : see GenerateBurst.c */
1156  int ret = XLALGenerateSimBurst(&hp, &hx, sim_burst, deltaT);
1157  if( ret==XLAL_FAILURE ) {
1158  cout << endl << "CWB::mdc::AddWaveform - "
1159  << "Error in LAL AddWaveform : check sim burst parameters" << endl;
1160  exit(1);
1161  }
1162  if(hp->data->length!=hx->data->length) {
1163  cout << "CWB::mdc::AddWaveform - Error : LAL hp,hx size not equal !!!" << endl;
1164  exit(1);
1165  }
1166 
1167  // create waveform arrays hp,hx
1168  wf.hp.resize(hp->data->length);
1169  wf.hp.rate(MDC_SAMPLE_RATE);
1170  wf.hx=wf.hp;
1171 
1172  double sum;
1173  // fill hp
1174  wf.hp=0; sum=0;
1175  for(int i=0;i<wf.hp.size();i++) {wf.hp[i]=hp->data->data[i]; sum+=pow(wf.hp[i],2);}
1176  if(normalization&&sum>0) wf.hp *= sqrt(MDC_SAMPLE_RATE/sum/2.); // normalization -> 1/sqrt(2)
1177  // fill hx
1178  wf.hx=0; sum=0;
1179  for(int i=0;i<wf.hx.size();i++) {wf.hx[i]=hx->data->data[i]; sum+=pow(wf.hx[i],2);}
1180  if(normalization&&sum>0) wf.hx *= sqrt(MDC_SAMPLE_RATE/sum/2.); // normalization -> 1/sqrt(2)
1181 
1182  XLALDestroyREAL8TimeSeries(hp);
1183  XLALDestroyREAL8TimeSeries(hx);
1184 
1185  if(mdc_type==MDC_SGE_LAL) {
1186 
1187  int d1 = decimals==-1 ? 0 : decimals;
1188  int d2 = decimals==-1 ? 1 : decimals;
1189 
1190  wf.par.resize(4);
1191  wf.par[0].name="frequency"; wf.par[0].value=sim_burst->frequency;
1192  wf.par[1].name="Q"; wf.par[1].value=sim_burst->q;
1193  wf.par[2].name="eccentricity"; wf.par[2].value=sim_burst->pol_ellipse_e;
1194  wf.par[3].name="phase"; wf.par[3].value=sim_burst->pol_ellipse_angle;
1195 
1196  sprintf(wf_name, "LAL_SGE%.*fQ%.*f",d1,wf.par[0].value,d2,wf.par[1].value);
1197 
1198  wf.type = mdc_type;
1199  wf.name = wf_name;
1200  wf.name.ReplaceAll(".","d");
1201  if(decimals==-1) wf.name.ReplaceAll("d0","");
1202  if(uname!="") wf.name = uname;
1203  wf.hpPath = wf.name;
1204  wf.hxPath = wf.name;
1205  mdcid waveid = AddWaveform(wf);
1206  return waveid;
1207 
1208  } else
1209  if(mdc_type==MDC_WNB_LAL) {
1210 
1211  int d1 = decimals==-1 ? 0 : decimals;
1212  int d2 = decimals==-1 ? 0 : decimals;
1213  int d3 = decimals==-1 ? 3 : decimals;
1214 
1215  wf.par.resize(3);
1216  wf.par[0].name="frequency"; wf.par[0].value=sim_burst->frequency;
1217  wf.par[1].name="bandwidth"; wf.par[1].value=sim_burst->bandwidth;
1218  wf.par[2].name="duration"; wf.par[2].value=sim_burst->duration;
1219 
1220  sprintf(wf_name,"LAL_WNB%.*f_%.*f_%.*f",d1,wf.par[0].value,d2,wf.par[1].value,d3,wf.par[2].value);
1221 
1222  wf.type = mdc_type;
1223  wf.name = wf_name;
1224  wf.name.ReplaceAll(".","d");
1225  if(uname!="") wf.name = uname;
1226  wf.hpPath = wf.name;
1227  wf.hxPath = wf.name;
1228  mdcid waveid = AddWaveform(wf);
1229  return waveid;
1230 
1231  } else
1232  if(mdc_type==MDC_GA_LAL) {
1233 
1234  int d1 = decimals==-1 ? 1 : decimals;
1235 
1236  wf.par.resize(1);
1237  wf.par[0].name="duration"; wf.par[0].value=sim_burst->duration;
1238 
1239  sprintf(wf_name,"LAL_GA%.*f",d1,1000.*wf.par[0].value);
1240 
1241  wf.type = mdc_type;
1242  wf.name = wf_name;
1243  wf.name.ReplaceAll(".","d");
1244  if(uname!="") wf.name = uname;
1245  wf.hpPath = wf.name;
1246  wf.hxPath = wf.name;
1247  mdcid waveid = AddWaveform(wf);
1248  return waveid;
1249  } else
1250  if(mdc_type==MDC_SC_LAL) {
1251 
1252  int d1 = decimals==-1 ? 1 : decimals;
1253 
1254  wf.par.resize(2);
1255  wf.par[0].name="frequency"; wf.par[0].value=sim_burst->frequency;
1256  wf.par[1].name="amplitude"; wf.par[1].value=sim_burst->amplitude;
1257 
1258  sprintf(wf_name,"LAL_SC%.*f",d1,wf.par[0].value);
1259 
1260  wf.hx=0; // string cup waveforms are linearly polarized
1261  wf.type = mdc_type;
1262  wf.name = wf_name;
1263  wf.name.ReplaceAll(".","d");
1264  if(uname!="") wf.name = uname;
1265  wf.hpPath = wf.name;
1266  wf.hxPath = wf.name;
1267  mdcid waveid = AddWaveform(wf);
1268  return waveid;
1269  }
1270 
1271  cout << "CWB::mdc::AddWaveform - Warning : LAL waveform not added !!!" << endl;
1272  mdcid waveid = {"",0,0};
1273  return waveid;
1274 }
1275 #endif
1276 
1277 //______________________________________________________________________________
1278 void
1280 //
1281 // Add Waveform to this object
1282 //
1283 //
1284 // Input: mdc_name - name of mdc
1285 // hp_fName - name of the input text file which contains hp component
1286 //
1287 // NOTE: the input text file is composed by two columns of ascii values (time hp/hx)
1288 //
1289 
1290  AddWaveform(mdc_name, hp_fName, "");
1291  return;
1292 }
1293 
1294 //______________________________________________________________________________
1295 void
1296 CWB::mdc::AddWaveform(TString mdc_name, TString hp_fName, TString hx_fName) {
1297 //
1298 // Add Waveform to this object
1299 //
1300 //
1301 // Input: mdc_name - name of mdc
1302 // hp_fName - name of the input text file which contains hp component
1303 // hx_fName - name of the input text file which contains hx component
1304 //
1305 // NOTE: the input text file is composed by two columns of ascii values (time hp/hx)
1306 //
1307 
1308  waveform wf;
1309  wf.type=MDC_USER;
1310  wf.name=mdc_name;
1311  ReadWaveform(wf.hp, hp_fName);
1312  wf.hpPath=hp_fName;
1313  if(hx_fName.Sizeof()>1) {
1314  ReadWaveform(wf.hx, hx_fName);
1315  wf.hxPath=hx_fName;
1316  } else {
1317  wf.hx=wf.hp; wf.hx=0;
1318  wf.hxPath="";
1319  }
1320 
1321  if(wf.hp.size()!=wf.hx.size()) {
1322  cout << "CWB::mdc::AddWaveform - Error : hp,hx size not equal !!!" << endl;
1323  exit(1);
1324  }
1325  if(wf.hp.rate()!=wf.hx.rate()) {
1326  cout << "CWB::mdc::AddWaveform - Error : hp,hx rate not equal !!!" << endl;
1327  exit(1);
1328  }
1329 
1330  // check if waveform is already declared in the wfList
1331  int ID=-1;
1332  for(int i=0;i<(int)wfList.size();i++) if(wfList[i].name.CompareTo(mdc_name)==0) {ID=i;break;}
1333 
1334  if(ID==-1) { // waveform is not in the list
1335  wfList.push_back(wf);
1336  } else {
1337  wfList[ID].list.push_back(wf);
1338  }
1339 
1340  return;
1341 }
1342 
1343 //______________________________________________________________________________
1344 void
1345 CWB::mdc::AddWaveform(TString mdc_name, TString hp_fName, double srate, vector<mdcpar> par) {
1346 //
1347 // Add Waveform to this object
1348 //
1349 //
1350 // Input: mdc_name - name of mdc
1351 // hp_fName - name of the input text file which contains hp component
1352 // srate - sample rate of the input waveform (Hz)
1353 // par - these parameters are only for infos and are stored in the waveform structure
1354 //
1355 // NOTE: the input text file s composed by a column of ascii values (hp/hx)
1356 // at constant sample rate (srate)
1357 //
1358 
1359  AddWaveform(mdc_name, hp_fName, "", srate, par);
1360  return;
1361 }
1362 
1363 //______________________________________________________________________________
1364 void
1365 CWB::mdc::AddWaveform(TString mdc_name, TString hp_fName, TString hx_fName,
1366  double srate, vector<mdcpar> par) {
1367 //
1368 // Add Waveform to this object
1369 //
1370 //
1371 // Input: mdc_name - name of mdc
1372 // hp_fName - name of the input text file which contains hp component
1373 // hx_fName - name of the input text file which contains hx component
1374 // srate - sample rate of the input waveform (Hz)
1375 // par - these parameters are only for infos and are stored in the waveform structure
1376 // only hrss is used to modify the input waveform :
1377 // - hrss<0 : wf-hrss is not modify
1378 // - hrss=0 : wf-hrss is normalized to 1 (default)
1379 // - hrss>0 : wf-hrss is normalized to hrss
1380 //
1381 // NOTE: the input text file s composed by a column of ascii values (hp/hx)
1382 // at constant sample rate (srate)
1383 //
1384 
1385  waveform wf;
1386  wf.type=MDC_USER;
1387  wf.name=mdc_name;
1388  ReadWaveform(wf.hp, hp_fName, srate);
1389  wf.hpPath=hp_fName;
1390  if(hx_fName.Sizeof()>1) {
1391  ReadWaveform(wf.hx, hx_fName, srate);
1392  wf.hxPath=hx_fName;
1393  } else {
1394  wf.hx=wf.hp; wf.hx=0;
1395  wf.hxPath="";
1396  }
1397 
1398  if(wf.hp.size()!=wf.hx.size()) {
1399  cout << "CWB::mdc::AddWaveform - Error : hp,hx size not equal !!!" << endl;
1400  exit(1);
1401  }
1402  if(wf.hp.rate()!=wf.hx.rate()) {
1403  cout << "CWB::mdc::AddWaveform - Error : hp,hx rate not equal !!!" << endl;
1404  exit(1);
1405  }
1406 
1407  // extract hrss from parameters
1408  bool error=false;
1409  double hrss_par = GetPar("hrss",par,error);
1410  if(error) hrss_par=0.;
1411 
1412  // normalization
1413  double hrssp=0; for (int i=0;i<(int)wf.hp.size();i++) hrssp+=wf.hp[i]*wf.hp[i];
1414  double hrssc=0; for (int i=0;i<(int)wf.hx.size();i++) hrssc+=wf.hx[i]*wf.hx[i];
1415  hrssp=sqrt(hrssp/wf.hp.rate());
1416  hrssc=sqrt(hrssc/wf.hx.rate());
1417  double hrss=sqrt(hrssp*hrssp+hrssc*hrssc);
1418 
1419  // if(hrss_par=0) hrss is normalized to 1
1420  if(hrss_par==0) {
1421  for(int i=0;i<(int)wf.hp.size();i++) {wf.hp[i]/=hrss;wf.hx[i]/=hrss;}
1422  hrssp /= hrss;
1423  hrssc /= hrss;
1424  hrss = 1.;
1425  }
1426  // if(hrss_par>0) hrss is normalized to hrss_par
1427  if(hrss_par>0) {
1428  for(int i=0;i<(int)wf.hp.size();i++) {wf.hp[i]/=hrss/hrss_par;wf.hx[i]/=hrss/hrss_par;}
1429  hrssp /= hrss/hrss_par;
1430  hrssc /= hrss/hrss_par;
1431  hrss = hrss_par;
1432  }
1433 
1434  // set htss,hrssp,hrssc and add par to waveform
1435  bool bhrss=false;
1436  vector<mdcpar> wfpar;
1437  for(int i=0;i<par.size();i++) {
1438  if(par[i].name=="hrss") {par[i].value=hrss;bhrss=true;}
1439  wfpar.push_back(par[i]);
1440  }
1441  mdcpar upar = {"hrss",1.,""}; if(!bhrss) wfpar.push_back(upar);
1442  mdcpar ppar = {"hrssp",hrssp,""}; wfpar.push_back(ppar);
1443  mdcpar cpar = {"hrssc",hrssc,""}; wfpar.push_back(cpar);
1444  wf.par=wfpar;
1445 
1446  // check if waveform is already declared in the wfList
1447  int ID=-1;
1448  for(int i=0;i<(int)wfList.size();i++) if(wfList[i].name.CompareTo(mdc_name)==0) {ID=i;break;}
1449 
1450  if(ID==-1) { // waveform is not in the list
1451  wfList.push_back(wf);
1452  } else {
1453  wfList[ID].list.push_back(wf);
1454  }
1455 
1456  return;
1457 }
1458 
1459 //______________________________________________________________________________
1460 mdcid
1462 //
1463 // Add Waveform to this object
1464 //
1465 //
1466 // Input: wf - waveform structure
1467 
1468  if(wf.hp.size()!=wf.hx.size()) {
1469  cout << "CWB::mdc::AddWaveform - Error : hp,hx size not equal !!!" << endl;
1470  exit(1);
1471  }
1472  if(wf.hp.rate()!=wf.hx.rate()) {
1473  cout << "CWB::mdc::AddWaveform - Error : hp,hx rate not equal !!!" << endl;
1474  exit(1);
1475  }
1476 
1477  // check if wf mdc type is in the MDC_TYPE list
1478  if(wf.type<0 || wf.type>MDC_USER) {
1479  cout << "CWB::mdc::AddWaveform - Error : mdc type not allowed !!!" << endl;
1480  exit(1);
1481  }
1482 
1483  // check if waveform is already declared in the wfList
1484  int ID=-1;
1485  for(int i=0;i<(int)wfList.size();i++) if(wfList[i].name.CompareTo(wf.name)==0) {ID=i;break;}
1486 
1487  if(ID==-1) { // waveform is not in the list
1488  wfList.push_back(wf);
1489  } else {
1490  wfList[ID].list.push_back(wf);
1491  }
1492 
1493  mdcid waveid;
1494  waveid.name = wf.name;
1495  waveid.ID = ID==-1 ? wfList.size()-1 : ID;
1496  waveid.id = ID==-1 ? 0 : wfList[ID].list.size();
1497  return waveid;
1498 }
1499 
1500 //______________________________________________________________________________
1501 TString
1503 //
1504 // Get burst/inspiral mdc data of the detector = ifo
1505 //
1506 //
1507 // Input: x - the input start/stop gps time are obtained from the wavearray values
1508 // start = x.start(); stop = x.start()+x.size()/x.rate()
1509 // ifo - name of the detector defined in the network
1510 //
1511 // Output: x - x.data contains the mdc data
1512 //
1513 // Return: log - ascii string with mdc parameters
1514 //
1515 
1516  TString listLog;
1517 #ifdef _USE_LAL
1518  if(inspOptions!="") listLog=GetInspiral(x, ifo); // new inspiral mdc
1519  else listLog=GetBurst(x, ifo); // built-in mdc
1520 #else
1521  listLog=GetBurst(x, ifo); // built-in mdc
1522 #endif
1523 
1524  return listLog;
1525 }
1526 
1527 //______________________________________________________________________________
1528 TString
1530 //
1531 // Get burst mdc data of the detector = ifo
1532 //
1533 //
1534 // Input: x - the input start/stop gps time are obtained from the wavearray values
1535 // start = x.start(); stop = x.start()+x.size()/x.rate()
1536 // ifo - name of the detector defined in the network
1537 //
1538 // Output: x - x.data contains the mdc data
1539 //
1540 // Return: log - ascii string with mdc parameters
1541 //
1542 
1543  if(net==NULL) {
1544  cout << "CWB::mdc::GetBurst - Error : Dummy method : network is not initialized " << endl;
1545  exit(1);
1546  }
1547  if(x.rate()!=MDC_SAMPLE_RATE) {
1548  cout << "CWB::mdc::GetBurst - Error : x.rate() != " << MDC_SAMPLE_RATE << endl;
1549  exit(1);
1550  }
1551 
1552  TString listLog="";
1553  double deg2rad = TMath::Pi()/180.;
1554  double rad2deg = 180./TMath::Pi();
1555 
1556  double dt = 1./x.rate();
1557 
1558  double start = x.start();
1559  double stop = x.start()+x.size()*dt;
1560 
1561  x=0.;
1562 
1563  mdcList.clear();
1564  mdcType.clear();
1565  mdcTime.clear();
1566  srcList.clear();
1567 
1568  srcList = GetSourceList(start, stop);
1569 
1570  // fill mdcType list
1571  if(sky_distribution==MDC_XMLFILE) {
1572  mdcType=xmlType;
1573  } else {
1574  for(int i=0;i<(int)wfList.size();i++) {
1575  bool save=true;
1576  for(int j=0; j<(int)mdcType.size(); j++){
1577  if(wfList[i].name.CompareTo(mdcType[j])==0) {save = false; break;}
1578  }
1579  if(save) {
1580  mdcType.push_back(wfList[i].name.Data());
1581  }
1582  }
1583  }
1584 
1585  for(int k=0;k<(int)srcList.size();k++) {
1586 
1587  double gps = srcList[k].gps;
1588  double theta = srcList[k].theta;
1589  double phi = srcList[k].phi;
1590  double psi = srcList[k].psi;
1591  double rho = srcList[k].rho;
1592  double iota = srcList[k].iota;
1593  double hrss = srcList[k].hrss;
1594 
1595  //cout.precision(14);
1596  //cout << "wf : " << srcList[k].wf.name.Data() << " type :" << srcList[k].wf.type
1597  // << " gps : " << gps << " theta : " << theta << " phi : " << phi
1598  // << " psi : " << psi << " rho : " << rho << " iota : " << iota << endl;
1599 
1600  double fPlus = GetAntennaPattern(ifo, phi, theta, psi, "hp");
1601  double fCross = GetAntennaPattern(ifo, phi, theta, psi, "hx");
1602  double tShift = 0.;
1603  if(sky_distribution==MDC_XMLFILE) {
1604  // Time Delay is computed respect to geocenter
1605  // this is required to be LAL compliant
1606  tShift = GetDelay(ifo,"",phi,theta);
1607  } else {
1608  // Time Delay is computed respect to the first detector in the network
1609  tShift = GetDelay(ifo,net->ifoName[0],phi,theta);
1610  }
1611 
1612  // if allowed then set ellipticity
1613  bool ellipticity=false;
1614  // if MDC_XMLFILE than hp,hx already contains the eccentricity rescaling
1615  if((srcList[k].wf.type==MDC_SGE_LAL)&&(sky_distribution!=MDC_XMLFILE)) ellipticity=true;
1616  if(srcList[k].wf.type==MDC_SGE) ellipticity=true;
1617  if(srcList[k].wf.type==MDC_CGE) ellipticity=true;
1618  if(srcList[k].wf.type==MDC_RDE) ellipticity=true;
1619  if(srcList[k].wf.type==MDC_EBBH) ellipticity=true;
1620  if(srcList[k].wf.type==MDC_USER) ellipticity=true;
1621  double ePlus = ellipticity ? (1+cos(iota*deg2rad)*cos(iota*deg2rad))/2 : 1.;
1622  double eCross = ellipticity ? cos(iota*deg2rad) : 1.;
1623  // if ellipticity=false we force iota to be 90
1624  if(!ellipticity) srcList[k].iota=90;
1625  // for circular waves we force iota to be 0
1626  if(srcList[k].wf.type==MDC_RDC) srcList[k].iota=0;
1627  if(srcList[k].wf.type==MDC_SGC) srcList[k].iota=0;
1628  if(srcList[k].wf.type==MDC_CGC) srcList[k].iota=0;
1629 
1630  waveform wf = srcList[k].wf;
1631 
1632  // build waveform vector
1633  int iShift = fabs(tShift)*wf.hp.rate();
1634  wavearray<double> w(wf.hp.size()+iShift); // add iShift to take into account time shift
1635  w.rate(wf.hp.rate());w=0;
1636  double SimHpHp=0;
1637  double SimHcHc=0;
1638  double SimHpHc=0;
1639  iShift = tShift<0 ? iShift : 0;
1640  for(int i=0;i<(int)wf.hp.size();i++) {
1641  w[i+iShift] = ePlus*fPlus*wf.hp[i]+eCross*fCross*wf.hx[i];
1642  SimHpHp+=wf.hp[i]*wf.hp[i];
1643  SimHcHc+=wf.hx[i]*wf.hx[i];
1644  SimHpHc+=wf.hp[i]*wf.hx[i];
1645  }
1646  SimHpHp*=dt;
1647  SimHcHc*=dt;
1648  SimHpHc*=dt;
1649  double SrcHrss=sqrt(SimHpHp+SimHcHc);
1650  std::stringstream linestream;
1651  int id; double m1,m2,rp0,e0,dist=0.;
1652  switch(srcList[k].wf.type) {
1653  case MDC_EBBH :
1654  // check if distance is already defined by the user
1655  linestream.str(wf.par[0].name.Data());
1656  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist)) {
1657  // distance is not defined
1658  // for eBBH hp,hx are already scaled to 10 Kpc
1659  // add distance in Kpc to par string
1660  char pars[256];
1661  sprintf(pars,"%s %g",srcList[k].wf.par[0].name.Data(),rho);
1662  srcList[k].wf.par[0].name = pars;
1663  }
1664  break;
1665  case MDC_WNB_LAL :
1666  if(sky_distribution==MDC_XMLFILE) {
1667  // for MDC_WNB_LAL the hrss is not present in the sim_table
1668  hrss=SrcHrss;
1669  srcList[k].hrss=hrss;
1670  }
1671  break;
1672  case MDC_SGE_LAL :
1673  if(sky_distribution==MDC_XMLFILE) {
1674  // if MDC_XMLFILE than iota is computed from the eccentricity
1675  // (see SetSkyDistribution MDC_XMLFILE)
1676  double eccentricity = iota>1e-10 ? iota : 1e-10;
1677  // in GetBurstLog the iota is reverted to eccentricity
1678  srcList[k].iota = (1.-sqrt(1-eccentricity*eccentricity))/eccentricity;
1679  srcList[k].iota = acos(srcList[k].iota)*rad2deg;
1680  // if MDC_XMLFILE than hp,hx contain the eccentricity rescaling
1681  // SimHpHp,SimHcHc,SimHpHc must be rescaled according to the eccentricity
1682 /*
1683  double ePlus = (1+cos(iota*deg2rad)*cos(iota*deg2rad))/2;
1684  double eCross = cos(iota*deg2rad);
1685  SimHpHp *= 1./(ePlus*ePlus);
1686  SimHcHc *= fabs(eCross)>1e-5 ? 1./(eCross*eCross) : 0.;
1687  SimHpHc *= fabs(eCross)>1e-5 ? 1./(ePlus*eCross) : 0.;
1688 */
1689  //double eccentricity = cosi2e(cos(iota*deg2rad));
1690  double E = eccentricity;
1691  double A = 1./sqrt(2-E*E);
1692  double B = A*sqrt(1-E*E);
1693  SimHpHp *= 1./(A*A)/2.;
1694  SimHcHc *= fabs(B)>1e-5 ? 1./(B*B)/2. : 0.;
1695  SimHpHc *= fabs(B)>1e-5 ? 1./(A*B)/2. : 0.;
1696  if(SimHcHc==0) SimHcHc=SimHpHp;
1697 
1698  //cout << "A " << A << " B " << B << " E " << E << endl;
1699  //cout << "SimHpHp : " << SimHpHp << " " << " SimHcHc " << SimHcHc << " SimHpHc " << SimHpHc << endl;
1700  //cout << "hrss : " << hrss << " " << " sqrt(SimHpHp+SimHcHc) " << sqrt(SimHpHp+SimHcHc) << endl;
1701  }
1702  break;
1703  default :
1704  if(inj_hrss>0) {
1705  // scaled source to hrss (variable for each source) or inj_hrss (fixed for all source) : @ 10Kpc
1706  SimHpHp *= hrss>0 ? pow(hrss/SrcHrss,2) : pow(inj_hrss/SrcHrss,2);
1707  SimHcHc *= hrss>0 ? pow(hrss/SrcHrss,2) : pow(inj_hrss/SrcHrss,2);
1708  SimHpHc *= hrss>0 ? pow(hrss/SrcHrss,2) : pow(inj_hrss/SrcHrss,2);
1709  w *= hrss>0 ? hrss/SrcHrss : inj_hrss/SrcHrss;
1710  } else {
1711  // the hrss @ 10Kpc is the one which is defined by hp,hc waveforms
1712  srcList[k].hrss = SrcHrss;
1713  }
1714  }
1715  // scale amplitude with the inverse of distance (standard candle @ 10Kpc)
1716  if(rho>0) {
1717  SimHpHp*=100./pow(rho,2);
1718  SimHcHc*=100./pow(rho,2);
1719  SimHpHc*=100./pow(rho,2);
1720  w*=10./rho;
1721  }
1722 
1723  TimeShift(w, tShift);
1724 
1725  // compute the number of samples (sT) of the mdc central time T
1726  double T = GetCentralTime(wf);
1727  int sT = TMath::Nint(T*w.rate());
1728 
1729  // offset (oS) of inj time respect to beginning of array
1730  // iShift must be subtracted !!!
1731  int oS = (srcList[k].gps-start)*x.rate()-iShift;
1732 
1733  // add waveform to mdc vector : T @ gps time
1734  for(int i=0;i<(int)w.size();i++) {
1735  int j=i+oS-sT;
1736  if (j>=(int)x.size()) break;
1737  if (j>=0) x[j]=w[i];
1738  }
1739 
1740  // add waveform log string to mdc log string
1741  TString log = GetBurstLog(srcList[k], start, SimHpHp, SimHcHc, SimHpHc);
1742  listLog = listLog+log;
1743 
1744  // add infos to lists
1745  mdcList.push_back(log.Data());
1746 // mdcType.push_back(srcList[k].wf.name.Data());
1747  mdcTime.push_back(srcList[k].gps);
1748 /*
1749  bool save=true;
1750  for(int j=0; j<(int)mdcType.size(); j++){
1751  if(srcList[k].wf.name.CompareTo(mdcType[j])==0) {save = false; break;}
1752  }
1753  if(save) {
1754  mdcType.push_back(srcList[k].wf.name.Data());
1755  }
1756 */
1757  }
1758 
1759  return listLog;
1760 }
1761 
1762 //______________________________________________________________________________
1763 void
1765 //
1766 // Read Waveform from input ascii file
1767 //
1768 //
1769 // Input: fName - name of the input text file which contains hp component
1770 //
1771 // Output: x - wavearray x.data contains waveform data
1772 //
1773 // NOTE: the input text file is composed by two columns of ascii values
1774 //
1775 
1776  Long_t id,fsize,flags,mt;
1777  int estat = gSystem->GetPathInfo(fName.Data(),&id,&fsize,&flags,&mt);
1778  if (estat!=0) {
1779  cout << "CWB::mdc::ReadWaveform - File : " << fName.Data() << " Not Exist" << endl;
1780  exit(1);
1781  }
1782 
1783  // read Waveform
1784  ifstream in;
1785  in.open(fName.Data(),ios::in);
1786  if (!in.good()) {cout << "CWB::mdc::ReadWaveform - Error Opening File : " << fName.Data() << endl;exit(1);}
1787 
1788  int size=0;
1789  char* str = new char[fsize+1];
1790  TObjArray* tok;
1791  while(true) {
1792  in.getline(str,fsize+1);
1793  if (!in.good()) break;
1794  if(str[0] != '#') size++;
1795  else continue;
1796  tok = TString(str).Tokenize(TString(' '));
1797  if(tok->GetEntries()!=2) {
1798  cout << "CWB::mdc::ReadWaveform - Input file with bad format : must be 2 columns " << endl;
1799  exit(1);
1800  }
1801  delete tok;
1802  }
1803  in.clear(ios::goodbit);
1804  in.seekg(0, ios::beg);
1805 
1807  w.resize(size);
1809 
1810  int cnt=0;
1811  double tMin=1.e30;
1812  double tMax=0.;
1813  while (1) {
1814  int pos = in.tellg();
1815  in.getline(str,1024);
1816  if (!in.good()) break;
1817  if(str[0] != '#') {
1818  in.seekg(pos);
1819  in >> t.data[cnt] >> w.data[cnt];
1820  if (!in.good()) break;
1821  if(t[cnt]<tMin) tMin=t[cnt];
1822  if(t[cnt]>tMax) tMax=t[cnt];
1823  cnt++;
1824  }
1825  }
1826  in.close();
1827  delete [] str;
1828 
1829  // convert to rate MDC_SAMPLE_RATE
1830 
1831  x.rate(MDC_SAMPLE_RATE);
1832  x.start(0.);
1833  int offset = 0.05*x.rate();
1834  x.resize(offset+int(x.rate()*(tMax-tMin)));
1835  x=0.;
1836 
1837  double dt=1./x.rate();
1839  for (int i=0;i<(int)r.size();i++) r[i] = tMin+(i-offset)*dt;
1840 
1841  CWB::Toolbox::convertSampleRate(t, w, r, x);
1842 
1843  return;
1844 }
1845 
1846 //______________________________________________________________________________
1847 void
1849 //
1850 // Read Waveform from input ascii file
1851 //
1852 //
1853 // Input: fName - name of the input text file which contains hp component
1854 // srate - sample rate of the input waveform (Hz)
1855 //
1856 // Output: x - wavearray x.data contains waveform data
1857 //
1858 // NOTE: the input text file s composed by a column of ascii values
1859 // at constant sample rate (srate)
1860 //
1861 
1862  Long_t id,fsize,flags,mt;
1863  int estat = gSystem->GetPathInfo(fName.Data(),&id,&fsize,&flags,&mt);
1864  if (estat!=0) {
1865  cout << "CWB::mdc::ReadWaveform - File : " << fName.Data() << " Not Exist" << endl;
1866  exit(1);
1867  }
1868 
1869  // read Waveform
1870  ifstream in;
1871  in.open(fName.Data(),ios::in);
1872  if (!in.good()) {cout << "CWB::mdc::ReadWaveform - Error Opening File : " << fName.Data() << endl;exit(1);}
1873 
1874  int size=0;
1875  char* str = new char[fsize+1];
1876  TObjArray* tok;
1877  while(true) {
1878  in.getline(str,fsize+1);
1879  if (!in.good()) break;
1880  if(str[0] != '#') size++;
1881  tok = TString(str).Tokenize(TString(' '));
1882  if((tok->GetEntries()!=1)&&(size>1)) {
1883  cout << "CWB::mdc::ReadWaveform - Input file with bad format : must be 1 column " << endl;
1884  exit(1);
1885  }
1886  if((tok->GetEntries()>1)&&(size==1)) { // all data are in one line
1887  x.resize(tok->GetEntries());
1888  x.rate(srate);
1889  for(int i=0;i<x.size();i++) { // get data from line
1890  TString stok = ((TObjString*)tok->At(i))->GetString();
1891  x[i]=stok.Atof(); // fill array
1892  }
1893  size=0;break;
1894  }
1895  delete tok;
1896  }
1897  in.clear(ios::goodbit);
1898  in.seekg(0, ios::beg);
1899 
1900  if(size>0) { // data are written with 1 column format
1901  x.resize(size);
1902  x.rate(srate);
1903 
1904  int cnt=0;
1905  while (1) {
1906  in.getline(str,1024);
1907  if (!in.good()) break;
1908  if(str[0] != '#') {
1909  x[cnt]=TString(str).Atof();
1910  cnt++;
1911  }
1912  }
1913  }
1914  in.close();
1915 
1916  // resample data if is not equals to the default
1917  if(srate!=MDC_SAMPLE_RATE) {
1920  y*=x.rms()/y.rms(); // set y energy = x energy
1921  x=y;
1922  }
1923 
1924  delete [] str;
1925 
1926  return;
1927 }
1928 
1929 //______________________________________________________________________________
1930 void
1931 CWB::mdc::GetSourceCoordinates(double gps, double& theta, double& phi, double& psi, double& rho,
1932  double& iota, double& hrss, int& ID, int& id) {
1933 //
1934 // Get source coordinates (earth system) from the user defined sky distribution
1935 //
1936 //
1937 // Output: gps - time (sec)
1938 // theta - latitude (degrees)
1939 // phi - longitude (degrees)
1940 // psi - polarization (degrees)
1941 // rho - distance (KPc)
1942 // iota - elliptical inclination angle (degrees)
1943 // hrss - sqrt(hp^2+hx^2)
1944 //
1945 
1946  GetSourceCoordinates(theta, phi, psi, rho, iota, hrss, ID, id);
1947 
1948  if((sky_distribution==MDC_GWGC)||
1949  (sky_distribution==MDC_MNGD)||
1950  (sky_distribution==MDC_CELESTIAL_FIX)) {
1951 
1952  if(gps>0) phi=sm.RA2phi(phi,gps); // celestial 2 earth coordinates
1953  }
1954 
1955  return;
1956 }
1957 
1958 //______________________________________________________________________________
1959 void
1960 CWB::mdc::GetSourceCoordinates(double& theta, double& phi, double& psi, double& rho,
1961  double& iota, double& hrss, int& ID, int& id) {
1962 //
1963 // Get source coordinates (earth system) from the user defined sky distribution
1964 //
1965 //
1966 // Output: theta - latitude (degrees)
1967 // phi - longitude (degrees)
1968 // psi - polarization (degrees)
1969 // rho - distance (KPc)
1970 // iota - elliptical inclination angle (degrees)
1971 // hrss - sqrt(hp^2+hx^2)
1972 //
1973 
1974  if((sky_distribution==MDC_GWGC)||
1975  (sky_distribution==MDC_MNGD)||
1976  (sky_distribution==MDC_RANDOM)||
1977  (sky_distribution==MDC_CELESTIAL_FIX)||
1978  (sky_distribution==MDC_EARTH_FIX)) {
1979 
1980  if(thList.size()==0) {
1981  cout << "CWB::mdc::GetSourceCoordinates - Error : injections not defined !!!" << endl;
1982  exit(1);
1983  }
1984 
1985  int id = gRandom->Uniform(0,thList.size());
1986 
1987  theta = thList[id];
1988  phi = phList[id];
1989  psi = psiList[id];
1990  rho = rhoList[id];
1991  iota = iotaList[id];
1992  hrss = hrssList[id];
1993  ID = IDList[id];
1994  id = idList[id];
1995 
1996  GeographicToCwb(phi,theta,phi,theta);
1997 
1998  } else {
1999 
2000  if(inj==NULL) {
2001  cout << "CWB::mdc::GetSourceCoordinates - Error : distribution not defined !!!" << endl;
2002  exit(1);
2003  }
2004  }
2005 
2006  return;
2007 }
2008 
2009 //______________________________________________________________________________
2010 waveform
2012 //
2013 // Return waveform randomly selected from the input list
2014 //
2015 
2016  ID = (int)gRandom->Uniform(0,wfList.size());
2017  id = (int)gRandom->Uniform(0,1+wfList[ID].list.size());
2018 
2019  waveform wf = id==0 ? wfList[ID] : wfList[ID].list[id-1];
2020  GetWaveform(wf); // if hp,hx are empty -> fill waveforms
2021  return wf;
2022 }
2023 
2024 //______________________________________________________________________________
2025 vector<source>
2027 //
2028 // Get a list of waveforms in the interval [start, stop]
2029 //
2030 //
2031 // Input: start - start time
2032 // stop - stop time
2033 //
2034 // Return the source list
2035 //
2036 
2037  if((stop-start)<=2*inj_length) {
2038  cout << "CWB::mdc::GetSourceList - Warning : buffer too small (stop-start)<=2*inj_length !!!" << endl;
2039  exit(1);
2040  }
2041 
2042  // fix random choice setting seed=start+srcList_seed
2043  gRandom->SetSeed(int(start)+srcList_seed);
2044 
2045  source src;
2046 
2047  double timeStep = inj_rate>0 ? 1./inj_rate : 1./MDC_INJ_RATE;
2048 
2049  int iStart=int(0.5+start/timeStep);
2050  int iStop=int(stop/timeStep);
2051 
2052  if(iStart==0) iStart+=1;
2053  vector<source> src_list;
2054 
2055  if(sky_distribution==MDC_LOGFILE) {
2056 
2057  if(inj_tree==NULL) {
2058  cout << "CWB::mdc::GetSourceList - Error : injection object is NULL" << endl;
2059  exit(1);
2060  }
2061 
2062  // gps are valid if are inside the range [start+inj_length, stop-inj_length]
2063  // inj_length is the scratch
2064  char cut[128];sprintf(cut,"time[0]>=%f && time[0]<%f",start+inj_length,stop-inj_length);
2065  inj_tree->Draw("Entry$",cut,"goff");
2066  int entries = inj_tree->GetSelectedRows();
2067  float phi[4];
2068  float theta[4];
2069  float psi[2];
2070  double time[2*NIFO_MAX];
2071  int type[2];
2072 
2073  inj_tree->SetBranchAddress("phi",phi);
2074  inj_tree->SetBranchAddress("theta",theta);
2075  inj_tree->SetBranchAddress("psi",psi);
2076  inj_tree->SetBranchAddress("time",time);
2077  inj_tree->SetBranchAddress("type",type);
2078 
2079  double* entry = inj_tree->GetV1();
2080  for(int i=0;i<entries;i++) {
2081  inj_tree->GetEntry(entry[i]);
2082  src.theta = theta[0];
2083  src.phi = phi[0];
2084  src.psi = psi[0];
2085  src.gps = time[0];
2086  src.rho = 10.;
2087  src.iota = 0.;
2088  src.hrss = 0.;
2089  int TYPE = (type[0]-1)<mdcName.size() ? type[0]-1 : 0;
2090  int ID = GetWaveformID(mdcName[TYPE])!=-1 ? GetWaveformID(mdcName[TYPE]) : 0;
2091  int id = (int)gRandom->Uniform(0,1+wfList[ID].list.size());
2092  src.wf = GetWaveform(ID,id);
2093  src_list.push_back(src);
2094  }
2095  } else if((sky_distribution==MDC_CUSTOM)||(sky_distribution==MDC_XMLFILE)) {
2096  for(int i=0;i<(int)gpsList.size();i++) {
2097  // gps are valid if are inside the range [start+inj_length, stop-inj_length]
2098  // inj_length is the scratch
2099  src.gps = gpsList[i];
2100  if(src.gps<=start+inj_length) continue;
2101  if(src.gps>=stop-inj_length) continue;
2102  src.theta = thList[i];
2103  src.phi = phList[i];
2104  src.psi = psiList[i];
2105  src.rho = rhoList[i];
2106  src.iota = iotaList[i];
2107  src.hrss = hrssList[i];
2108  src.ID = IDList[i];
2109  src.id = idList[i];
2110  if(src.ID<0) { // select waveform by name (default)
2111  src.ID = GetWaveformID(nameList[i])!=-1 ? GetWaveformID(nameList[i]) : 0;
2112  } else { // select waveform by ID,id
2113  src.ID = (src.ID < wfList.size()) ? src.ID : 0;
2114  }
2115  if(src.id<0) { // select waveform by name (default)
2116  src.id = (int)gRandom->Uniform(0,1+wfList[src.ID].list.size());
2117  } else { // select waveform by ID,id
2118  src.id = (src.id <= wfList[src.ID].list.size()) ? src.id : 0;
2119  }
2120  src.wf = GetWaveform(src.ID,src.id);
2121  src_list.push_back(src);
2122  }
2123  } else {
2124  for(int i=iStart;i<=iStop;i++) {
2125  if(gpsList.size()>0) src.gps=gpsList[0]; // fix gps
2126  else src.gps=inj_offset+i*timeStep+gRandom->Uniform(-inj_jitter,inj_jitter);
2127  // gps are valid if are inside the range [start+inj_length, stop-inj_length]
2128  // inj_length is the scratch
2129  if(src.gps<=start+inj_length) continue;
2130  if(src.gps>=stop-inj_length) continue;
2131  GetSourceCoordinates(src.gps, src.theta, src.phi, src.psi, src.rho, src.iota, src.hrss, src.ID, src.id);
2132  src.wf = GetSourceWaveform(src.ID, src.id);
2133 
2134  if(src.wf.par.size() && src.wf.par[0].value==MDC_EBBH) { // eBBH waveform
2135  int id; double m1,m2,rp0,e0,dist=0.;
2136  std::stringstream linestream(src.wf.par[0].name.Data());
2137  // get user defined distance
2138  if((linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist)) src.rho=dist;
2139  }
2140 
2141  src_list.push_back(src);
2142  if(gpsList.size()>0) break; // fix gps, only one injection
2143  }
2144  }
2145 
2146  return src_list;
2147 }
2148 
2149 //______________________________________________________________________________
2150 TString
2151 CWB::mdc::GetBurstLog(source src, double FrameGPS, double SimHpHp, double SimHcHc, double SimHpHc) {
2152 //
2153 // Get Log string
2154 //
2155 // Input: src - source structure
2156 // FrameGPS - Frame gps time
2157 // SimHpHp - Energy of hp component
2158 // SimHcHc - Energy of hc component
2159 // SimHpHc - Cross component of hp hc
2160 //
2161 
2162  if(net==NULL) {
2163  cout << "CWB::mdc::GetBurstLog - Error : Dummy method : network is not initialized " << endl;
2164  exit(1);
2165  }
2166 
2167  double deg2rad = TMath::Pi()/180.;
2168 
2169  // log burstMDC parameters
2170  char logString[10000]="";
2171 
2172  char GravEn_SimID[1024];
2173  double hrss = src.hrss>0 ? src.hrss : inj_hrss;
2174  TString hpPath = src.wf.hpPath.Sizeof()>1 ? src.wf.hpPath : src.wf.name;
2175  sprintf(GravEn_SimID,"%s",hpPath.Data());
2176  if(src.wf.hxPath.Sizeof()>1) sprintf(GravEn_SimID,"%s;%s",GravEn_SimID,src.wf.hxPath.Data());
2177  // scale amplitude with the inverse of distance (standard candle @ 10Kpc)
2178  //double SimHrss = src.rho>0 ? 10.*sqrt(SimHpHp+SimHcHc)/src.rho : sqrt(SimHpHp+SimHcHc);
2179  double SimHrss = sqrt(SimHpHp+SimHcHc);
2180  double SimEgwR2 = 0.0;
2181  double GravEn_Ampl = src.rho>0 ? 10.*hrss/src.rho : hrss;
2182  double Internal_x = cos(src.iota*deg2rad);
2183  double Internal_phi = 0.0;
2184  double External_x = cos(src.theta*deg2rad); // DOM
2185  double External_phi = src.phi*deg2rad;
2186  double External_psi = src.psi*deg2rad;
2187 
2188  double EarthCtrGPS = src.gps;
2189  char SimName[64]; strcpy(SimName,src.wf.name.Data());
2190 
2191  sprintf(logString,"%s",GravEn_SimID);
2192  sprintf(logString,"%s %e",logString,SimHrss);
2193  sprintf(logString,"%s %e",logString,SimEgwR2);
2194  sprintf(logString,"%s %e",logString,GravEn_Ampl);
2195  sprintf(logString,"%s %e",logString,Internal_x);
2196  sprintf(logString,"%s %e",logString,Internal_phi);
2197  sprintf(logString,"%s %e",logString,External_x);
2198  sprintf(logString,"%s %e",logString,External_phi);
2199  sprintf(logString,"%s %e",logString,External_psi);
2200 
2201  sprintf(logString,"%s %10.6f",logString,FrameGPS);
2202  sprintf(logString,"%s %10.6f",logString,EarthCtrGPS);
2203  sprintf(logString,"%s %s",logString,SimName);
2204  sprintf(logString,"%s %e",logString,SimHpHp);
2205  sprintf(logString,"%s %e",logString,SimHcHc);
2206  sprintf(logString,"%s %e",logString,SimHpHc);
2207 
2208  int nIFO=net->ifoListSize();
2209  TString refIFO=net->ifoName[0];
2210  for(int i=0;i<nIFO;i++) {
2211  TString ifo=net->ifoName[i];
2212  double IFOctrGPS = EarthCtrGPS;
2213  if(sky_distribution==MDC_XMLFILE) {
2214  // Time Delay is computed respect to geocenter
2215  // this is required to be LAL compliant
2216  IFOctrGPS += GetDelay(ifo,"",src.phi,src.theta);
2217  } else {
2218  // Time Delay is computed respect to the first detector in the network
2219  IFOctrGPS += GetDelay(ifo,refIFO,src.phi,src.theta);
2220  }
2221  double IFOfPlus = GetAntennaPattern(ifo, src.phi, src.theta, src.psi, "hp");
2222  double IFOfCross = GetAntennaPattern(ifo, src.phi, src.theta, src.psi, "hx");
2223  if(src.wf.name=="eBBH") { // if MDC is eBBH add auxiliary infos
2224  int id; double m1,m2,rp0,e0,distance=0.;
2225  std::stringstream linestream(src.wf.par[0].name.Data());
2226  linestream >> id >> m1 >> m2 >> rp0 >> e0 >> distance;
2227  // compute effective distance
2228  double cosiota = cos(src.iota*deg2rad);
2229  double eff_dist = distance / sqrt(pow(IFOfPlus*(1.+pow(cosiota,2)),2)/4.+pow(IFOfCross*cosiota,2));
2230  sprintf(logString,"%s %s %10.6f %e %e %g",logString,ifo.Data(),IFOctrGPS,IFOfPlus,IFOfCross,eff_dist/1000.);
2231  } else {
2232  sprintf(logString,"%s %s %10.6f %e %e",logString,ifo.Data(),IFOctrGPS,IFOfPlus,IFOfCross);
2233  }
2234  }
2235 
2236  if(src.wf.name=="eBBH") { // if MDC is eBBH add auxiliary infos
2237  int id; double m1,m2,rp0,e0,distance=0.,redshift=0.;
2238  std::stringstream linestream(src.wf.par[0].name.Data());
2239  linestream >> id >> m1 >> m2 >> rp0 >> e0 >> distance >> redshift;
2240  sprintf(logString, "%s ebbh ",logString);
2241  sprintf(logString, "%s mass1 %g ",logString, m1);
2242  sprintf(logString, "%s mass2 %g ",logString, m2);
2243  sprintf(logString, "%s rp0 %g ",logString, rp0);
2244  sprintf(logString, "%s e0 %g ",logString, e0);
2245  sprintf(logString, "%s distance %g ",logString, distance/1000.); // converted in Mpc (compatible with LAL)
2246  sprintf(logString, "%s redshift %g ",logString, redshift);
2247  // chirp mass (solar units)
2248  double M = (m1+m2);
2249  double mu = (m1*m2)/(m1+m2);
2250  double eta = mu/M;
2251  double mchirp = pow(mu,3./5)*pow(M,2./5);
2252  sprintf(logString, "%s mchirp %g ",logString, mchirp);
2253  } else {
2254  // distance is converted in Mpc (compatible with LAL)
2255  if(src.rho>0) sprintf(logString, "%s distance %g ",logString, src.rho/1000.);
2256  }
2257 
2258  return logString;
2259 }
2260 
2261 //______________________________________________________________________________
2262 watplot*
2263 CWB::mdc::Draw(int ID, int id, TString polarization, MDC_DRAW type, TString options, Color_t color) {
2264 //
2265 // Draw waveform in time/frequency domain
2266 //
2267 //
2268 // Input: ID - major id of waveform list
2269 // id - minor id of waveform list (Ex : the list WNB with different random waveforms)
2270 // polarization - hp/hx
2271 // type - MDC_TIME, MDC_FFT, MDC_TF
2272 // options - graphic options
2273 // color - option for MDC_TIME, MDC_FFT
2274 //
2275 
2276  watplot* plot=NULL;
2277  polarization.ToUpper();
2278  waveform wf = GetWaveform(ID,id);
2279  if(wf.status) {
2280  if(polarization.Contains("HP")) plot=Draw(wf.hp,type,options,color);
2281  if(polarization.Contains("HX")) plot=Draw(wf.hx,type,options,color);
2282  }
2283  return plot;
2284 }
2285 
2286 //______________________________________________________________________________
2287 watplot*
2289 //
2290 // Draw waveform in time/frequency domain
2291 //
2292 //
2293 // Input: name - waveform name
2294 // polarization - hp/hx
2295 // type - MDC_TIME, MDC_FFT, MDC_TF
2296 // options - graphic options
2297 // color - option for MDC_TIME, MDC_FFT
2298 //
2299 
2300  watplot* plot=NULL;
2301  polarization.ToUpper();
2302  waveform wf = GetWaveform(name,id);
2303  if(wf.status) {
2304  if(polarization.Contains("HP")) plot=Draw(wf.hp,type,options,color);
2305  if(polarization.Contains("HX")) plot=Draw(wf.hx,type,options,color);
2306  }
2307  return plot;
2308 }
2309 
2310 //______________________________________________________________________________
2311 watplot*
2312 CWB::mdc::Draw(TString ifo, double gpsStart, double gpsEnd, int id,
2313  MDC_DRAW type, TString options, Color_t color) {
2314 //
2315 // Draw waveform in time/frequency domain contained in the interval [gpsStart,gpsEnd]
2316 //
2317 //
2318 // Input: ifo - detector name
2319 // gpsStart - start interval time
2320 // gpsEnd - stop interval time
2321 // id - sequential numer of the waveform contained in the interval
2322 // type - MDC_TIME, MDC_FFT, MDC_TF
2323 // options - graphic options
2324 // color - option for MDC_TIME, MDC_FFT
2325 //
2326 
2328  y.rate(MDC_SAMPLE_RATE);
2329  y.start(gpsStart);
2330  y.resize((gpsEnd-gpsStart)*y.rate());
2331  Get(y,ifo);
2332 
2333  if((int)mdcTime.size()==0) {
2334  cout << "CWB::mdc::Draw : Error - No events in the selected period" << endl;
2335  exit(1);
2336  }
2337  if(id>=(int)mdcTime.size()) id=(int)mdcTime.size()-1;
2338  double tOffset = mdcTime[id]-y.start();
2339  double tWindow = inj_length;
2340  int iStart = (tOffset-tWindow/2)*y.rate(); if(iStart<0) iStart=0;
2341  int iEnd = (tOffset+tWindow/2)*y.rate(); if(iEnd>y.size()) iEnd=y.size();
2342 
2343  // make an array centered around the selected event
2344  wavearray<double> x(tWindow*y.rate());
2345  x.rate(y.rate());
2346  for(int i=iStart;i<iEnd;i++) x[i-iStart]=y[i];
2347 
2348  watplot* plot=NULL;
2349 
2350  if(type==MDC_TIME) plot=DrawTime(x,options,color);
2351  if(type==MDC_FFT) plot=DrawFFT(x,options,color);
2352  if(type==MDC_TF) DrawTF(x);
2353 
2354  return plot;
2355 }
2356 
2357 //______________________________________________________________________________
2358 watplot*
2360 //
2361 // Draw waveform in time/frequency domain
2362 //
2363 //
2364 // Input: x - wavearray which contains waveform data
2365 // type - MDC_TIME, MDC_FFT, MDC_TF
2366 // options - graphic options
2367 // color - option for MDC_TIME, MDC_FFT
2368 //
2369 
2370  watplot* plot=NULL;
2371 
2372  if(type==MDC_TIME) plot=DrawTime(x,options,color);
2373  if(type==MDC_FFT) plot=DrawFFT(x,options,color);
2374  if(type==MDC_TF) DrawTF(x,options);
2375 
2376  return plot;
2377 }
2378 
2379 //______________________________________________________________________________
2380 watplot*
2382 //
2383 // Draw waveform in time domain
2384 //
2385 //
2386 // Input: x - wavearray which contains waveform data
2387 // options - draw options (same as TGraph)
2388 // if contains ZOOM then the interval around the signal is showed
2389 //
2390 
2391  if(x.rate()<=0) {
2392  cout << "CWB::mdc::DrawTime : Error - rate must be >0" << endl;
2393  exit(1);
2394  }
2395 
2396  options.ToUpper();
2397  options.ReplaceAll(" ","");
2398  if(stft!=NULL) delete stft;
2399  if(options.Contains("SAME")&&(pts!=NULL)) {
2400  } else {
2401  if(pts!=NULL) delete pts;
2402  char name[32];sprintf(name,"TIME-gID:%d",int(gRandom->Rndm(13)*1.e9));
2403  pts = new watplot(const_cast<char*>(name),200,20,800,500);
2404  }
2405  double tStart,tStop;
2406  if(options.Contains("ZOOM")) {
2407  options.ReplaceAll("ZOOM","");
2408  GetTimeRange(x, tStart, tStop, epzoom);
2409  tStart+=x.start();
2410  tStop+=x.start();
2411  } else {
2412  tStart=x.start();
2413  tStop=x.start()+x.size()/x.rate();
2414  }
2415  if(!options.Contains("SAME")) {
2416  if(!options.Contains("A")) options=options+" A";
2417  if(!options.Contains("L")) options=options+" L";
2418  if(!options.Contains("P")) options=options+" P";
2419  }
2420  pts->plot(x, const_cast<char*>(options.Data()), color, tStart, tStop);
2421 
2422  return pts;
2423 }
2424 
2425 //______________________________________________________________________________
2426 watplot*
2428 //
2429 // Draw waveform spectrum
2430 //
2431 //
2432 // Input: x - wavearray which contains waveform data
2433 // options - draw options (same as TGraph)
2434 // if contains ZOOM then the interval around the signal is showed
2435 // if contains NOLOGX/NOLOGY X/Y axis are linear
2436 //
2437 
2438  options.ToUpper();
2439  options.ReplaceAll(" ","");
2440  if(stft!=NULL) delete stft;
2441  if(options.Contains("SAME")&&(pts!=NULL)) {
2442  } else {
2443  if(pts!=NULL) delete pts;
2444  char name[32];sprintf(name,"FREQ-gID:%d",int(gRandom->Rndm(13)*1.e9));
2445  pts = new watplot(const_cast<char*>(name),200,20,800,500);
2446  }
2447 
2448  double fLow = 32.;
2449  double fHigh = x.rate()/2.;
2450  double tStart,tStop;
2451  if(options.Contains("ZOOM")) {
2452  options.ReplaceAll("ZOOM","");
2453  GetTimeRange(x, tStart, tStop, epzoom);
2454  tStart+=x.start();
2455  tStop+=x.start();
2456  } else {
2457  tStart=x.start();
2458  tStop=x.start()+x.size()/x.rate();
2459  }
2460  bool logx = true;
2461  if(options.Contains("NOLOGX")) {logx=false;options.ReplaceAll("NOLOGX","");}
2462  bool logy = true;
2463  if(options.Contains("NOLOGY")) {logy=false;options.ReplaceAll("NOLOGY","");}
2464  pts->plot(x, const_cast<char*>(options.Data()), color, tStart, tStop, true, fLow, fHigh);
2465  pts->canvas->SetLogx(logx);
2466  pts->canvas->SetLogy(logy);
2467 
2468  return pts;
2469 }
2470 
2471 //______________________________________________________________________________
2472 void
2474 //
2475 // Draw waveform spectrogram
2476 //
2477 //
2478 // Input: x - wavearray which contains waveform data
2479 // options - draw options (same as TH2D)
2480 //
2481 
2482  int nfact=4;
2483  int nfft=nfact*512;
2484  int noverlap=nfft-10;
2485  double fparm=nfact*6;
2486 
2487  double tStart,tStop;
2488  if(options.Contains("ZOOM")) {
2489  options.ReplaceAll("ZOOM","");
2490  GetTimeRange(x, tStart, tStop, epzoom);
2491  tStart+=x.start();
2492  tStop+=x.start();
2493  } else {
2494  tStart=x.start();
2495  tStop=x.start()+x.size()/x.rate();
2496  }
2497 
2498  if(stft!=NULL) delete stft;
2499  if(pts!=NULL) delete pts;
2500  stft = new CWB::STFT(x,nfft,noverlap,"amplitude","gauss",fparm);
2501 
2502  double fLow = 32.;
2503  double fHigh = x.rate()/2.;
2504  stft->Draw(tStart,tStop,fLow,fHigh,0,0,1);
2505  stft->GetCanvas()->SetLogy(true);
2506 
2507  return;
2508 }
2509 
2510 //______________________________________________________________________________
2511 waveform
2513 //
2514 // Get waveform
2515 //
2516 //
2517 // Input: ID - major id of waveform list
2518 // id - minor id of waveform list (Ex : the list WNB with different random waveforms)
2519 //
2520 // Return waveform structure
2521 //
2522 
2523  waveform wf;
2524 
2525  // check if waveform is declared in the wfList
2526  if(ID<0||ID>=(int)wfList.size()) {
2527  cout << "CWB::mdc::GetWaveform - Error : ID " << ID << " not in the list" << endl;
2528  wf.status=false;
2529  return wf;
2530  }
2531 
2532  id = (id<0||id>(int)wfList[ID].list.size()) ? 0 : id;
2533  if((int)wfList[ID].list.size()==0) {
2534  wf=wfList[ID];
2535  } else {
2536  wf = id==0 ? wf=wfList[ID] : wfList[ID].list[id-1];
2537  }
2538 
2539  GetWaveform(wf); // if hp,hx are empty -> fill waveforms
2540 
2541  wf.status=true;
2542  return wf;
2543 }
2544 
2545 //______________________________________________________________________________
2546 void
2548 //
2549 // if hp,hx are empty -> fill waveforms
2550 // only MDC_EBBH is implemented
2551 //
2552 
2553  if((wf.hp.size()==0)&&(wf.hx.size()==0)) {
2554 #ifdef _USE_EBBH
2555  if(wf.par[0].value==MDC_EBBH) { // Get eBBH waveform
2556  int id;
2557  double m1,m2,rp0,e0,dist=0.,redshift=0.;
2558  std::stringstream linestream(wf.par[0].name.Data());
2559  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist >> redshift)) {
2560  linestream.str(wf.par[0].name.Data());
2561  linestream.clear(); // clear stringstream error status
2562  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0 >> dist)) {
2563  linestream.str(wf.par[0].name.Data());
2564  linestream.clear(); // clear stringstream error status
2565  if(!(linestream >> id >> m1 >> m2 >> rp0 >> e0)) {
2566  cout << "CWB::mdc::GetWaveform - Wrong eBBH parameter format : " << endl;
2567  cout << "input line : " << endl;
2568  cout << wf.par[0].name.Data() << endl;
2569  cout << "must be : " << endl;
2570  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << endl;
2571  cout << "or : " << endl;
2572  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << " dist " << endl;
2573  cout << "or : " << endl;
2574  cout << "event# " << "id " << " m1 " << " m2 " << " rp0 " << " e0 " << " dist " << " redshift " << endl;
2575  exit(1);
2576  }
2577  }
2578  }
2579 
2580  if(wf.par.size()==1) { // create eBBH on the fly
2581 
2582  getEBBH(m1,m2,rp0,e0,wf.hp,wf.hx);
2583 
2584  // the distance of source is G*M/c^2 meters
2586  double M = watconstants::SolarMass();
2588  double pc = watconstants::Parsec();
2589  double distance_source_Kpc = (m1+m2)*G*M/(c*c)/pc/1.e3;
2590 
2591  // rescale hp,hx to 10 Kpc
2592  wf.hp*=distance_source_Kpc/10.;
2593  wf.hx*=distance_source_Kpc/10.;
2594 
2595  } else
2596  if(wf.par.size()==2) { // read eBBH from file
2597 
2598  TString fName = wf.par[1].name; // get root file name
2599  int entry = int(wf.par[1].value); // get tree entry number
2600 
2601  TFile* efile = new TFile(fName);
2602  if(efile==NULL) {
2603  cout << "CWB::mdc::GetWaveform - Error opening root file : " << fName.Data() << endl;
2604  exit(1);
2605  }
2606 
2609 
2610  TTree* etree = (TTree *) efile->Get("ebbh");
2611  if(etree==NULL) {
2612  cout << "CWB::mdc::GetWaveform - file : " << fName.Data()
2613  << " not contains tree ebbh" << endl;
2614  exit(1);
2615  }
2616 
2617  etree->SetBranchAddress("hp",&hp);
2618  etree->SetBranchAddress("hx",&hx);
2619 
2620  etree->GetEntry(entry);
2621 
2622  if(hp->size()!=hx->size()) {
2623  cout << "CWB::mdc::GetWaveform - Error : hp,hx size not equal !!!" << endl;
2624  exit(1);
2625  }
2626  if(hp->rate()!=hx->rate()) {
2627  cout << "CWB::mdc::GetWaveform - Error : hp,hx rate not equal !!!" << endl;
2628  exit(1);
2629  }
2630 
2631  wf.hp = *hp;
2632  wf.hx = *hx;
2633 
2634  delete hp;
2635  delete hx;
2636  delete efile;
2637 
2638  } else {
2639  cout << "CWB::mdc::GetWaveform - Error : wrong number of parameters not !!!" << endl;
2640  exit(1);
2641  }
2642  }
2643 #endif
2644  if((wf.hp.size()==0)&&(wf.hx.size()==0)) {
2645  cout << "CWB::mdc::GetWaveform - Error : hp,hp are empty !!!" << endl;
2646  exit(1);
2647  }
2648  }
2649 }
2650 
2651 //______________________________________________________________________________
2652 waveform
2654 //
2655 // Get waveform
2656 //
2657 //
2658 // Input: name - name of waveform
2659 // id - minor id of waveform
2660 //
2661 // Return waveform structure
2662 //
2663 
2664  waveform wf;
2665 
2666  // check if waveform is declared in the wfList
2667  int ID=-1;
2668  for(int i=0;i<(int)wfList.size();i++) if(wfList[i].name.CompareTo(name)==0) {ID=i;break;}
2669  if(ID<0) {
2670  wf.status=false;
2671  return wf;
2672  } else {
2673  id = (id<0||id>(int)wfList[ID].list.size()-1) ? 0 : id;
2674  if((int)wfList[id].list.size()==0) {
2675  wf=wfList[ID];
2676  } else {
2677  wf=wfList[ID].list[id];
2678  }
2679 
2680  GetWaveform(wf); // if hp,hx are empty -> fill waveforms
2681 
2682  wf.status=true;
2683  return wf;
2684  }
2685 }
2686 
2687 //______________________________________________________________________________
2688 int
2690 //
2691 // Get waveform
2692 //
2693 //
2694 // Input: name - name of waveform
2695 //
2696 // Return waveform ID
2697 //
2698 
2699  // check waveform name declared in the wfList
2700  int ID=-1;
2701  for(int i=0;i<(int)wfList.size();i++) if(wfList[i].name.CompareTo(name)==0) {ID=i;break;}
2702  return ID;
2703 }
2704 
2705 //______________________________________________________________________________
2706 void
2707 CWB::mdc::Print(int level) {
2708 //
2709 // Print list of waveforms
2710 //
2711 //
2712 // Input: level - if level=0 only the waveforms with major id are listed
2713 //
2714 
2715  cout << endl;
2716  for(int i=0;i<(int)wfList.size();i++) {
2717  printf("ID : %02i (x% 3i) \t%s\n",i,(int)wfList[i].list.size()+1,wfList[i].name.Data());
2718  printf("% 3i - ",1);
2719  for(int k=0;k<(int)wfList[i].par.size();k++)
2720  if(wfList[i].par[k].svalue!="") {
2721  printf("%s = %s ",wfList[i].par[k].name.Data(),wfList[i].par[k].svalue.Data());
2722  } else {
2723  printf("%s = %g ",wfList[i].par[k].name.Data(),wfList[i].par[k].value);
2724  }
2725  printf("\n");
2726  if(level>0) {
2727  for(int j=0;j<(int)wfList[i].list.size();j++) {
2728  printf("% 3i - ",j+2);
2729  for(int k=0;k<(int)wfList[i].par.size();k++)
2730  if(wfList[i].list[j].par[k].svalue!="") {
2731  printf("%s = %s ",wfList[i].list[j].par[k].name.Data(),wfList[i].list[j].par[k].svalue.Data());
2732  } else {
2733  printf("%s = %g ",wfList[i].list[j].par[k].name.Data(),wfList[i].list[j].par[k].value);
2734  }
2735  printf("\n");
2736  }
2737  }
2738  }
2739  cout << endl;
2740  return;
2741 }
2742 
2743 //______________________________________________________________________________
2744 double
2746 //
2747 // Get mdc central time
2748 //
2749 //
2750 // Input: wf - waveform structure which contains the waveform data
2751 //
2752 // Retun central time
2753 //
2754 
2755  wavearray<double> z=wf.hp; z+=wf.hx;
2756  return GetCentralTime(z);
2757 }
2758 
2759 //______________________________________________________________________________
2760 double
2762 //
2763 // Get mdc central time
2764 //
2765 //
2766 // Input: x - wavearray which contains the waveform data
2767 //
2768 // Retun central time
2769 //
2770 
2771  double a;
2772  double E=0.,T=0.;
2773  int size=(int)x.size();
2774  double rate=x.rate();
2775  for(int j=0;j<size;j++) {
2776  a = x[j];
2777  T += a*a*j/rate; // central time
2778  E += a*a; // energy
2779  }
2780  T = E>0 ? T/E : 0.5*size/rate;
2781 
2782  return T;
2783 }
2784 
2785 //______________________________________________________________________________
2786 double
2788 //
2789 // Get mdc central frequency
2790 //
2791 //
2792 // Input: wf - waveform structure which contains the waveform data
2793 //
2794 // Retun central frequency
2795 //
2796 
2797  wavearray<double> z=wf.hp; z+=wf.hx;
2798  return GetCentralFrequency(z);
2799 }
2800 
2801 //______________________________________________________________________________
2802 double
2804 //
2805 // Get mdc central frequency
2806 //
2807 //
2808 // Input: x - wavearray which contains the waveform data
2809 //
2810 // Retun central frequency
2811 //
2812 
2813  double a;
2814  double E=0.,F=0.;
2815  int size=(int)x.size();
2816  double rate=x.rate();
2817  x.FFTW(1);
2818  double dF=(rate/(double)size)/2.;
2819  for(int j=0;j<size/2;j+=2) {
2820  a = x[j]*x[j]+x[j+1]*x[j+1];
2821  F += a*j*dF; // central frequency
2822  E += a; // energy
2823  }
2824  F = E>0 ? F/E : 0.5*rate;
2825 
2826  return F;
2827 }
2828 
2829 //______________________________________________________________________________
2830 double
2831 CWB::mdc::GetTimeRange(wavearray<double> x, double& tMin, double& tMax, double efraction) {
2832 //
2833 // Get mdc time interval
2834 //
2835 //
2836 // Input: x - wavearray which contains the waveform data
2837 //
2838 // Output: tMin - start time interval
2839 // tMax - stop time interval
2840 //
2841 
2842  if(efraction<0) efraction=0;
2843  if(efraction>1) efraction=1;
2844 
2845  int N = x.size();
2846 
2847  double E = 0; // signal energy
2848  double avr = 0; // average
2849  for(int i=0;i<N;i++) {avr+=i*x[i]*x[i]; E+=x[i]*x[i];}
2850  int M=int(avr/E); // central index
2851 
2852  // search range which contains percentage P of the total energy E
2853  int jB=0;
2854  int jE=N-1;
2855  double a,b;
2856  double sum = ((M>=0)&&(M<N)) ? x[M]*x[M] : 0.;
2857  for(int j=1; j<N; j++) {
2858  a = ((M-j>=0)&&(M-j<N)) ? x[M-j] : 0.;
2859  b = ((M+j>=0)&&(M+j<N)) ? x[M+j] : 0.;
2860  if(a) jB=M-j;
2861  if(b) jE=M+j;
2862  sum += a*a+b*b;
2863  if(sum/E > efraction) break;
2864  }
2865 
2866  tMin = jB/x.rate();
2867  tMax = jE/x.rate();
2868 
2869  return tMax-tMin;
2870 }
2871 
2872 //______________________________________________________________________________
2873 void
2875 //
2876 // apply time shift
2877 //
2878 //
2879 // Input: x - wavearray which contains the waveform data
2880 // time - time shift (sec)
2881 //
2882 
2883  if(tShift==0) return;
2884 
2885  // search begin,end of non zero data
2886  int ibeg=0; int iend=0;
2887  for(int i=0;i<(int)x.size();i++) {
2888  if(x[i]!=0 && ibeg==0) ibeg=i;
2889  if(x[i]!=0) iend=i;
2890  }
2891  int ilen=iend-ibeg+1;
2892  // create temporary array for FFTW & add scratch buffer + tShift
2893  int ishift = fabs(tShift)*x.rate();
2894  int isize = 2*ilen+2*ishift;
2895  isize = isize + (isize%4 ? 4 - isize%4 : 0); // force to be multiple of 4
2896  wavearray<double> w(isize);
2897  w.rate(x.rate()); w=0;
2898  // copy x data !=0 in the middle of w array & set x=0
2899  for(int i=0;i<ilen;i++) {w[i+ishift+ilen/2]=x[ibeg+i];x[ibeg+i]=0;}
2900 
2901  double pi = TMath::Pi();
2902  // apply time shift to waveform vector
2903  w.FFTW(1);
2904  TComplex C;
2905  double df = w.rate()/w.size();
2906  //cout << "tShift : " << tShift << endl;
2907  for (int ii=0;ii<(int)w.size()/2;ii++) {
2908  TComplex X(w[2*ii],w[2*ii+1]);
2909  X=X*C.Exp(TComplex(0.,-2*pi*ii*df*tShift)); // Time Shift
2910  w[2*ii]=X.Re();
2911  w[2*ii+1]=X.Im();
2912  }
2913  w.FFTW(-1);
2914 
2915  // copy shifted data to input x array
2916  for(int i=0;i<(int)w.size();i++) {
2917  int j=ibeg-(ishift+ilen/2)+i;
2918  if((j>=0)&&(j<(int)x.size())) x[j]=w[i];
2919  }
2920 
2921  return;
2922 }
2923 
2924 //______________________________________________________________________________
2925 void
2927 //
2928 // apply phase shift
2929 //
2930 //
2931 // Input: x - wavearray which contains the waveform data
2932 // pShift - phase shift (degrees)
2933 //
2934 
2935  if(pShift==0) return;
2936 
2937  // search begin,end of non zero data
2938  int ibeg=0; int iend=0;
2939  for(int i=0;i<(int)x.size();i++) {
2940  if(x[i]!=0 && ibeg==0) ibeg=i;
2941  if(x[i]!=0) iend=i;
2942  }
2943  int ilen=iend-ibeg+1;
2944  // create temporary array for FFTW & add scratch buffer + tShift
2945  int isize = 2*ilen;
2946  isize = isize + (isize%4 ? 4 - isize%4 : 0); // force to be multiple of 4
2947  wavearray<double> w(isize);
2948  w.rate(x.rate()); w=0;
2949  // copy x data !=0 in the middle of w array & set x=0
2950  for(int i=0;i<ilen;i++) {w[i+isize/4]=x[ibeg+i];x[ibeg+i]=0;}
2951 
2952  // apply phase shift to waveform vector
2953  w.FFTW(1);
2954  TComplex C;
2955  //cout << "pShift : " << pShift << endl;
2956  pShift*=TMath::Pi()/180.;
2957  for (int ii=0;ii<(int)w.size()/2;ii++) {
2958  TComplex X(w[2*ii],w[2*ii+1]);
2959  X=X*C.Exp(TComplex(0.,-pShift)); // Phase Shift
2960  w[2*ii]=X.Re();
2961  w[2*ii+1]=X.Im();
2962  }
2963  w.FFTW(-1);
2964 
2965  // copy shifted data to input x array
2966  for(int i=0;i<(int)w.size();i++) {
2967  int j=ibeg-isize/4+i;
2968  if((j>=0)&&(j<(int)x.size())) x[j]=w[i];
2969  }
2970 
2971  return;
2972 }
2973 
2974 //______________________________________________________________________________
2976 CWB::mdc::GetSGQ(double frequency, double Q) {
2977 //
2978 // Get SinGaussian
2979 //
2980 //
2981 // Input: frequency - SG frequency (Hz)
2982 // Q - SG Q factor
2983 //
2984 // Return wavearray data containing the waveform
2985 //
2986 
2987  wavearray<double> x(int(inj_length*MDC_SAMPLE_RATE));
2988  x.rate(MDC_SAMPLE_RATE);
2989  x=0;
2990  double amplitude=1.;
2991  double duration = Q/(TMath::TwoPi()*frequency);
2992  AddSGBurst(x, amplitude, frequency, duration,0);
2993 
2994  return x;
2995 }
2996 
2997 //______________________________________________________________________________
2999 CWB::mdc::GetCGQ(double frequency, double Q) {
3000 //
3001 // Get CosGaussian
3002 //
3003 //
3004 // Input: frequency - CG frequency (Hz)
3005 // Q - CG Q factor
3006 //
3007 // Return wavearray data containing the waveform
3008 //
3009 
3010  wavearray<double> x(int(inj_length*MDC_SAMPLE_RATE));
3011  x.rate(MDC_SAMPLE_RATE);
3012  x=0;
3013  double amplitude=1.;
3014  double duration = Q/(TMath::TwoPi()*frequency);
3015  AddCGBurst(x, amplitude, frequency, duration,0);
3016 
3017  return x;
3018 }
3019 
3020 #define GA_FORMULA_WNB "[0]*TMath::Exp(-TMath::Power((x-[2])/[1],2)/2)"
3021 
3022 //______________________________________________________________________________
3024 CWB::mdc::GetWNB(double frequency, double bandwidth, double duration, int seed, bool mode) {
3025 //
3026 // Get White Band Gaussian Noise
3027 //
3028 //
3029 // Input: frequency - start white band frequency (Hz)
3030 // bandwidth - (Hz)
3031 // duration - (sec)
3032 // mode - if mode=1 -> apply Patrik Sutton Method
3033 // simmetric respect to the central frequency
3034 // if mode=0 -> asymmetric respect to the central frequency
3035 //
3036 // Return wavearray data containing the waveform
3037 //
3038 
3039  gRandom->SetSeed(seed);
3040 
3041  // Generate white gaussian noise 1 sec
3042  wavearray<double> x(int(inj_length*MDC_SAMPLE_RATE));
3043  x.rate(MDC_SAMPLE_RATE);
3044  for (int i=0;i<(int)x.size();i++) x[i]=gRandom->Gaus(0,1);
3045 
3046  double dt = 1./x.rate();
3047  double df = x.rate()/x.size();
3048 
3049  // Apply a band limited cut in frequency
3050  x.FFTW(1);
3051  if(mode==1) {
3052  // set zero bins outside the range [0,bandwidth/2]
3053  // Heterodyne up by frequency+bandwidth/2 (move zero frequency to center of desidered band)
3054  int bFrequency = frequency/df;
3055  int bBandwidth = (bandwidth/2.)/df;
3056  wavearray<double> y=x; y=0;
3057  int bin = 2*(bFrequency+bBandwidth);
3058  y[bin]=x[0];
3059  y[bin+1]=x[1];
3060  for (int i=1;i<bBandwidth;i++) {
3061  y[bin+2*i]=x[2*i];
3062  y[bin+2*i+1]=x[2*i+1];
3063 
3064  y[bin-2*i]=x[2*i];
3065  y[bin-2*i+1]=-x[2*i+1];
3066  }
3067  x=y;;
3068  x.FFTW(-1);
3069  } else {
3070  // set zero bins outside the range [frequency,frequency+bandwidth]
3071  int bLow = frequency/df;
3072  int bHigh = (frequency+bandwidth)/df;
3073  for (int i=0;i<bLow;i++) {x[2*i]=0;x[2*i+1]=0;}
3074  for (int i=bHigh;i<(int)x.size()/2;i++) {x[2*i]=0;x[2*i+1]=0;}
3075  x.FFTW(-1);
3076  }
3077 
3078  // Apply a gaussian shape in time
3079  double function_range = 1.; // duration 1 sec
3080  TF1* ga_function = new TF1("Gaussian",GA_FORMULA_WNB,-function_range/2,function_range/2);
3081  ga_function->SetParameter(0,1);
3082  ga_function->SetParameter(1,duration);
3083  ga_function->SetParameter(2,function_range/2);
3084  for (int i=0;i<(int)x.size();i++) x[i]*=ga_function->Eval(dt*(i+1));
3085 
3086  // normalization
3087  double hrss=0;
3088  for (int i=0;i<(int)x.size();i++) hrss+=x[i]*x[i];
3089  hrss=sqrt(hrss*dt);
3090  for (int i=0;i<(int)x.size();i++) x[i]*=(1./sqrt(2.))*1./hrss;
3091 
3092  delete ga_function;
3093 
3094  return x;
3095 }
3096 
3097 #define GA_FORMULA "[0]*TMath::Exp(-TMath::Power((x-[2])/[1],2))"
3098 
3099 //______________________________________________________________________________
3102 //
3103 // Get Gaussian signal
3104 //
3105 //
3106 // Input: duration - (sec)
3107 //
3108 // Return wavearray data containing the waveform
3109 
3110  // Apply a gaussian shape in time
3111  double function_range = 1.; // duration 1 sec
3112  TF1* ga_function = new TF1("Gaussian",GA_FORMULA,-function_range/2,function_range/2);
3113  ga_function->SetParameter(0,1);
3114  ga_function->SetParameter(1,duration);
3115  ga_function->SetParameter(2,function_range/2);
3116 
3117  double dt = 1./MDC_SAMPLE_RATE;
3118 
3119  // plus component
3120  wavearray<double> x(int(inj_length*MDC_SAMPLE_RATE));
3121  x.rate(MDC_SAMPLE_RATE);
3122  for (int i=0;i<(int)x.size();i++) x[i]=ga_function->Eval(dt*(i+1));
3123 
3124  // normalization
3125  double hrss=0;
3126  for (int i=0;i<(int)x.size();i++) hrss+=x[i]*x[i];
3127  hrss=sqrt(hrss*dt);
3128  for (int i=0;i<(int)x.size();i++) x[i]*=1./hrss;
3129 
3130  delete ga_function;
3131 
3132  return x;
3133 }
3134 
3135 #define RD_FORMULA "(((x-1./4./[2]+TMath::Abs(x-1./4./[2]))/2./(x-1./4./[2]))*[0]*TMath::Cos(TMath::TwoPi()*[2]*x)+[1]*TMath::Sin(TMath::TwoPi()*[2]*x))*TMath::Exp(-x/[3])" // Heaviside in cos like Andrea Vicere'
3136 
3137 //______________________________________________________________________________
3139 CWB::mdc::GetRD(double frequency, double tau, double iota, bool polarization) {
3140 //
3141 // Get RingDown signal
3142 //
3143 //
3144 // Input: frequency - (Hz)
3145 // tau - (sec)
3146 // iota - (degrees)
3147 // polarization - (degrees)
3148 //
3149 // Return wavearray data containing the waveform
3150 //
3151 
3152  iota*=TMath::Pi()/180.;
3153 
3154  double c2 = TMath::Cos(iota);
3155  double c1 = (1+c2*c2)/2.;
3156 
3157  if (c1/c2<1e-10) c1=0;
3158 
3159  char rd_formula[256] = RD_FORMULA;
3160  double function_range = 1.; // duration 1 sec
3161  TF1* rd_function = new TF1("RingDown",rd_formula,0.,function_range);
3162  rd_function->SetParameter(2,frequency);
3163  rd_function->SetParameter(3,tau);
3164 
3165  double time_offset=0.05; // it is necessary to allows negative time shift
3166  double dt = 1./MDC_SAMPLE_RATE;
3167 
3168  // plus component
3169  wavearray<double> x(int(inj_length*MDC_SAMPLE_RATE));
3170  x.rate(MDC_SAMPLE_RATE);
3171  rd_function->SetParameter(0,c1);
3172  rd_function->SetParameter(1,0);
3173  for (int i=0;i<(int)x.size();i++) {
3174  double time = dt*(i+1)-time_offset;
3175  if (time>=0) x[i]=rd_function->Eval(time); else x[i]=0;
3176  }
3177 
3178  // cross component
3179  wavearray<double> y(int(inj_length*MDC_SAMPLE_RATE));
3180  y.rate(MDC_SAMPLE_RATE);
3181  rd_function->SetParameter(0,0);
3182  rd_function->SetParameter(1,c2);
3183  for (int i=0;i<(int)y.size();i++) {
3184  double time = dt*(i+1)-time_offset;
3185  if (time>=0) y[i]=rd_function->Eval(time); else y[i]=0;
3186  }
3187 
3188  double hrss=0;
3189  for (int i=0;i<(int)x.size();i++) hrss+=x[i]*x[i]+y[i]*y[i];
3190  hrss=sqrt(hrss*dt);
3191  for (int i=0;i<(int)x.size();i++) x[i]*=1./hrss;
3192  for (int i=0;i<(int)y.size();i++) y[i]*=1./hrss;
3193 
3194  delete rd_function;
3195 
3196  return polarization==0 ? x : y;
3197 }
3198 
3199 //______________________________________________________________________________
3200 void
3201 CWB::mdc::AddGauss(wavearray<double> &td, double v, double u) {
3202 //
3203 // Add Gaussian Noise
3204 //
3205 //
3206 // Input: td - wavearray with input data signal
3207 // v - sigma of gaussian noise
3208 // u - median of gaussian noise
3209 //
3210 // Output: td - Return input signal + gaussian noise
3211 //
3212 
3213  int n=td.size();
3214  for (int i=0; i < n; i++){
3215  td.data[i] += v*gRandom->Gaus(0.,1.)+u;
3216  }
3217 }
3218 
3219 //______________________________________________________________________________
3220 void
3222 //
3223 // Add exponential noise
3224 //
3225 //
3226 // Input: td - wavearray with input data signal
3227 // v - 1/tau of exponential
3228 // M - number of random values added for each sample
3229 //
3230 // Output: td - Return input signal + exponential noise
3231 //
3232 
3233  int i,j;
3234  double x,y;
3235  int m=abs(M);
3236  int n=td.size();
3237  for (i=0; i<n; i++){
3238  y = 0.;
3239  for (j=0; j<m; j++){
3240  x = gRandom->Exp(v);
3241  if(M>0) y += x;
3242  else if(x>y) y=x;
3243  }
3244  td.data[i] += y;
3245  }
3246 }
3247 
3248 //______________________________________________________________________________
3249 void
3250 CWB::mdc::AddSGBurst(wavearray<double> &td, double a, double f, double s, double d) {
3251 //
3252 // Add SinGaussian burst
3253 //
3254 //
3255 // Input: td - wavearray with input data signal
3256 // a - amplitude
3257 // f - frequency (Hz)
3258 // s - gaussian RMS
3259 // d - duration (sec)
3260 //
3261 // Output: td - Return input signal + SinGaussian burst
3262 //
3263 
3264  int n=td.size();
3265  double r = td.rate();
3266  int m;
3267  double g, t;
3268  double sum = 0.;
3269  double delay = d;
3270 
3271  m = int(6*s*r);
3272  if(m > n/2-1) m = n/2-2;
3273 
3274  for (int i=0; i < m; i++){
3275  t = i/r;
3276  g = 2*TMath::Exp(-t*t/2/s/s)*TMath::Sin(2*PI*f*t);
3277  sum += g*g;
3278  }
3279  a *= TMath::Sqrt(r/sum);
3280 
3281  td.data[n/2+int(delay*r)] += 0;
3282  for (int i=1; i < m; i++){
3283  t = i/r;
3284  g = a*TMath::Exp(-t*t/2/s/s)*TMath::Sin(2*PI*f*t);
3285  td.data[n/2+i+int(delay*r)] += g;
3286  td.data[n/2-i+int(delay*r)] -= g;
3287  }
3288 }
3289 
3290 //______________________________________________________________________________
3291 void
3292 CWB::mdc::AddCGBurst(wavearray<double> &td, double a, double f, double s, double d) {
3293 //
3294 // Add CosGaussian burst
3295 //
3296 //
3297 // Input: td - wavearray with input data signal
3298 // a - amplitude
3299 // f - frequency (Hz)
3300 // s - gaussian RMS
3301 // d - duration (sec)
3302 //
3303 // Output: td - Return input signal + CosGaussian burst
3304 //
3305 
3306  int n=td.size();
3307  double r = td.rate();
3308  int m;
3309  double g, t;
3310  double sum = 0.;
3311  double delay = d;
3312 
3313  m = int(6*s*r);
3314  if(m > n/2-1) m = n/2-2;
3315 
3316  for (int i=0; i < m; i++){
3317  t = i/r;
3318  g = 2*TMath::Exp(-t*t/2/s/s)*TMath::Cos(2*PI*f*t);
3319  sum += g*g;
3320  }
3321  a *= TMath::Sqrt(r/sum);
3322 
3323  td.data[n/2+int(delay*r)] += a;
3324  for (int i=1; i < m; i++){
3325  t = i/r;
3326  g = a*TMath::Exp(-t*t/2/s/s)*TMath::Cos(2*PI*f*t);
3327  td.data[n/2+i+int(delay*r)] += g;
3328  td.data[n/2-i+int(delay*r)] += g;
3329  }
3330 }
3331 
3332 //______________________________________________________________________________
3333 void
3335 //
3336 // Add windowed Gaussian noise
3337 //
3338 //
3339 // Input: td - wavearray with input data signal
3340 // a - amplitude
3341 // s - gaussian RMS
3342 //
3343 // Output: td - Return input signal + windowed Gaussian noise
3344 //
3345 
3346  int n=td.size();
3347  double r = td.rate();
3348  int m;
3349  double g, t;
3350  double sum = 0.;
3351 
3352  m = int(3*s*r);
3353  if(m > n/2-1) m = n/2-2;
3354  wavearray<double> gn(2*m);
3355 
3356 
3357  for (int i=0; i < m; i++){
3358  t = i/r;
3359  g = TMath::Exp(-t*t/2/s/s);
3360  gn.data[m+i] = g*gRandom->Gaus(0.,1.);
3361  gn.data[m-i-1] = g*gRandom->Gaus(0.,1.);
3362  sum += gn.data[m+i]*gn.data[m+i] + gn.data[m-i-1]*gn.data[m-i-1];
3363  }
3364  a *= TMath::Sqrt(r/sum);
3365 
3366  for (int i=0; i < m; i++){
3367  t = i/r;
3368  td.data[n/2+i] += a*gn.data[m+i];
3369  td.data[n/2-i] += a*gn.data[m-i-1];
3370  }
3371 }
3372 
3373 // --------------------------------------------------------
3374 // Miyamoto-Nagai Galactic Disk Model
3375 // www.astro.utu.fi/~cflynn/galdyn/lecture4.html
3376 // a=[0]
3377 // b=[1] scale length
3378 // R=x, z=y
3379 // --------------------------------------------------------
3380 
3381 #define MNGD_NUMERATOR "([0]*((x-[3])*(x-[3])+y*y)+([0]+3*sqrt(z*z+[1]*[1]))*pow([0]+sqrt(z*z+[1]*[1]),2))"
3382 #define MNGD_DENOMINATOR "(pow(((x-[3])*(x-[3])+y*y)+pow([0]+sqrt(z*z+[1]*[1]),2),5./2.)*pow(z*z+[1]*[1],3./2.))"
3383 
3384 #define MNGD_B 0.3 // Kpc
3385 #define MNGD_Md1 6.6e10 // Msol
3386 #define MNGD_A1 5.81 // Kpc
3387 #define MNGD_Md2 -2.9e10 // Msol
3388 #define MNGD_A2 17.43 // Kpc
3389 #define MNGD_Md3 3.3e9 // Msol
3390 #define MNGD_A3 34.86 // Kpc
3391 
3392 #define MNGD_XMAX 40
3393 #define MNGD_YMAX 4
3394 
3395 #define MNGD_SOLAR_SISTEM_DISTANCE_FROM_GC 7.62 // 7.62 [+/-0.32] Kpc it.wikipedia.org/wiki/Via_Lattea
3396 
3397 
3398 //______________________________________________________________________________
3399 void
3401 //
3402 // Set Sky Distribution
3403 //
3404 // see SetSkyDistribution(MDC_DISTRIBUTION sky_distribution, TString fName, vector<mdcpar> par, int seed)
3405 //
3406 //
3407 
3408  vector<mdcpar> par;
3409  SetSkyDistribution(sky_distribution, fName, par, seed, add);
3410  return;
3411 }
3412 
3413 //______________________________________________________________________________
3414 void
3415 CWB::mdc::SetSkyDistribution(MDC_DISTRIBUTION sky_distribution, vector<mdcpar> par, int seed, bool add) {
3416 //
3417 // Set Sky Distribution
3418 //
3419 // see SetSkyDistribution(MDC_DISTRIBUTION sky_distribution, TString fName, vector<mdcpar> par, int seed)
3420 //
3421 
3422  SetSkyDistribution(sky_distribution, "", par, seed, add);
3423  return;
3424 }
3425 
3426 //______________________________________________________________________________
3427 void
3428 CWB::mdc::SetSkyDistribution(MDC_DISTRIBUTION sky_distribution, TString fName, vector<mdcpar> par, int seed, bool add) {
3429 //
3430 // Set Sky Distribution
3431 //
3432 //
3433 // Input: sky_distribution - sky distribution type
3434 // fName - input file name
3435 // par - input sky distribution parameters
3436 // seed - seed for random selection
3437 // add - add (def=false) if true the distribution is added to the current one
3438 //
3439 // sky_distribution & par & fName can be one of the following choices :
3440 //
3441 // MDC_RANDOM = random sky distribution (fName not used)
3442 // fName can be used to define a custom rho distribution
3443 // example : fName="pow(x,2)"
3444 // do not use par[n].name="rho_dist";
3445 // vector<mdcpar> par(1);
3446 // par[0].name="entries"; par[0].value=XXX; // number of random events
3447 // par.resize(3);
3448 // par[1].name="rho_min"; par[1].value=MIN; // min distance in kPc
3449 // par[2].name="rho_max"; par[2].value=MAX; // max distance in kPc
3450 // // if(rho_min>0 && rho_max>=rho_min)
3451 // // the amplitude is rescaled to 10/rho (10 Kpc is the stantard candle distance)
3452 // // if rho_min,rho_max are not defined the amplitude is not rescaled
3453 // //
3454 // par[n].name="rho_dist"; // define the rho distribution
3455 // par[n].value=x; // dist is rho^x
3456 // // if "rho_dist" is not defined then the distance of events
3457 // // is randomly selected from a (rho*rho) distribution
3458 // // so the sky distribution is uniform in volume
3459 //
3460 // par[m].name="iota"; par[m].value=iota; // ellipticity [0:180] deg
3461 // // if<0 || >180 -> iota=random
3462 // // default : iota=0
3463 // par[p].name="psi"; par[p].value=psi; // polarization (deg)
3464 // // if not defined -> random
3465 //
3466 // MDC_EARTH_FIX = earth fixed greographical coordinates (latitude, longitude)
3467 // MDC_CELESTIAL_FIX = celestial fixed coordinates (DEC, RA)
3468 // vector<mdcpar> par(2);
3469 // par[0].name="theta"; par[0].value=XXX; // degrees
3470 // par[1].name="phi"; par[1].value=YYY; // degrees
3471 // par.resize(3);
3472 // par[2].name="psi"; par[2].value=ZZZ; // degrees
3473 // par.resize(4);
3474 // par[3].name="rho"; par[3].value=UUU; // kPc
3475 // par.resize(5);
3476 // par[4].name="gps"; par[4].value=VVV; // sec
3477 // par.resize(6);
3478 // par[5].name="entries"; par[5].value=TTT; // number of random events
3479 // par.resize(7);
3480 // par[6].name="iota"; par[6].value=iota; // ellipticity [0:180] deg
3481 // // if<0 || >180 -> random
3482 //
3483 // MDC_MNGD = Miyamoto-Nagai Galactic Disk Model (fName,par not used)
3484 // www.astro.utu.fi/~cflynn/galdyn/lecture4.html
3485 // vector<mdcpar> par(1);
3486 // par[0].name="entries"; par[0].value=XXX; // number of random events
3487 // par.resize(2);
3488 // par[1].name="iota"; par[1].value=iota; // ellipticity [0:180] deg
3489 // // if<0 || >180 -> random
3490 //
3491 // MDC_GWGC = Gravitation Wave Galaxy Catalog (par not used)
3492 // fName = path name of galaxy catalog
3493 // vector<mdcpar> par(1);
3494 // par[0].name="distance_thr"; par[0].value=XXX; // distance max (Kpc)
3495 // par.resize(2);
3496 // par[1].name="iota"; par[1].value=iota; // ellipticity [0:180] deg
3497 // // if<0 || >180 -> random
3498 //
3499 // MDC_XMLFILE = mdc xml file
3500 // fName = path name of mdc xml file (LAL xml format)
3501 // par[0].name="start"; par[0].value=XXX; // start GPS time to search in XML file
3502 // par[1].name="stop"; par[1].value=YYY; // stop GPS time to search in XML file
3503 // par[2].name="hrss_factor"; par[2].value=ZZZ; // used to rescale hrss (default=1)
3504 // par[3].name="decimals"; par[3].value=WWW; // used to format the MDC name (default=1)
3505 // par[4].name="engine";par[4].value=V; // mdc engine : 0->AAL, 1->CWB (default=1)
3506 // par[5].name="auto";par[5].value=T; // 0/1->disaable/enable (default=0)
3507 // NOTE : if auto=0 the MDC names must be provided by user using the following setup:
3508 // par[6].name="type"; par[6].svalue="MDC_NAME1"; // MDC name1 (with CWB Format)
3509 // par[X].name="type"; par[X].svalue="MDC_NAMEX"; // MDC nameX (with CWB Format)
3510 // par[N].name="type"; par[N].svalue="MDC_NAMEN"; // MDC nameN (with CWB Format)
3511 //
3512 // MDC_LOGFILE = mdc log file
3513 // fName = path name of mdc log file
3514 //
3515 // MDC_CUSTOM = user define distribution
3516 // fName = path name of user file
3517 // file format : gps name theta phi psi rho iota hrss ID id
3518 // theta = [0:180] deg : phi = [0:360] deg : psi = [0:180] deg : iota = [0:180] deg
3519 // ID/id are the major/minor id waveform numbers
3520 // if ID=-1 then 'name' is used, if id=1 then id is selected randomly
3521 //
3522 // Note1: the angle iota is the inclination of the system which originates the burst with respect to the line of sight
3523 // iota = 0 : the line of sight is perpendicular to the orbit plane
3524 // iota = 90 : the line of sight has 0 deg inclination angle respect to the orbit plane
3525 // the h+ ellipticity factor is : (1+cos[iota]*cos[iota])/2
3526 // the hx ellipticity factor is : cos[iota]
3527 //
3528 // Note2: rho defines the distance of the source in Kpc
3529 // if rho=0 then the hrss is the one defined with SetInjHrss (default)
3530 // if rho>0 then the hrss is rescaled by a factor 10/rho;
3531 // the hrss defined with SetInjHrss is the hrss at 10Kpc
3532 //
3533 
3534  gRandom->SetSeed(seed);
3535 
3536  this->sky_distribution=sky_distribution;
3537  this->sky_file=fName;
3538  this->sky_parms=par;
3539 
3540  double rad2deg = 180./TMath::Pi();
3541 
3542  if(!add) {
3543  nameList.clear();
3544  thList.clear();
3545  phList.clear();
3546  psiList.clear();
3547  rhoList.clear();
3548  iotaList.clear();
3549  hrssList.clear();
3550  gpsList.clear();
3551  IDList.clear();
3552  idList.clear();
3553  }
3554 
3555  if(sky_distribution==MDC_RANDOM) {
3556 
3557  bool error=false;
3558  int entries = GetPar("entries",par,error);
3559  double rho_min = GetPar("rho_min",par,error);
3560  if(error) rho_min=0.;
3561  double rho_max = GetPar("rho_max",par,error);
3562  if(error) rho_max=0.;
3563 
3564  if(entries<=0) {
3565  cout << "CWB::mdc::SetSkyDistribution - "
3566  << "Error : entries must be positive" << endl;
3567  exit(1);
3568  }
3569  if(rho_max>0 && rho_min<=0) {
3570  cout << "CWB::mdc::SetSkyDistribution - " << "Error : rho_min must be > 0" << endl;
3571  exit(1);
3572  }
3573  if(rho_min>rho_max) {
3574  cout << "CWB::mdc::SetSkyDistribution - " << "Error : rho_min must be <= rho_max" << endl;
3575  exit(1);
3576  }
3577 
3578  cout << "CWB::mdc::SetSkyDistribution - All Sky random distribution" << endl;
3579 
3580  TF1 *rd = NULL;
3581  // define the rho distribution
3582  if(rho_min!=rho_max) {
3583  double rho_dist = GetPar("rho_dist",par,error);
3584  char rho_dist_func[256];
3585  if((!error)&&(fName=="")) sprintf(rho_dist_func,"pow(x,%f)",rho_dist); // custom pow(rho,rho_dist)
3586  else if(( error)&&(fName=="")) sprintf(rho_dist_func,"pow(x,2)"); // default distribution
3587  else if(( error)&&(fName!="")) strcpy(rho_dist_func,fName.Data()); // custom formula
3588  else if((!error)&&(fName!="")) { // ambiguoius definition
3589  cout << "CWB::mdc::SetSkyDistribution - "
3590  << "Error : ambiguous rho distribution - is defined twice "
3591  << " 1) as rho_dist params, 2) as formula" << endl;
3592  exit(1);
3593  }
3594  rd = new TF1("rd",rho_dist_func,rho_min,rho_max); // sky distribution rho^rho_dist
3595  TF1* rdcheck = (TF1*)gROOT->GetListOfFunctions()->FindObject("rd"); // check if formula is correct
3596  if(rdcheck==NULL) {
3597  cout << "CWB::mdc::SetSkyDistribution - "
3598  << "Error : wrong formula format : " << rho_dist_func << endl;
3599  exit(1);
3600  }
3601  }
3602 
3603  for(int n=0;n<entries;n++) {
3604  thList.push_back(rad2deg*acos(gRandom->Uniform(-1,1))-90.);
3605  phList.push_back(gRandom->Uniform(-180,180));
3606  if(rd!=NULL) rhoList.push_back(rd->GetRandom());
3607  else rhoList.push_back(rho_min);
3608 
3609  error=false;double value=GetPar("psi",par,error);
3610  double psi = error ? gRandom->Uniform(0,180) : value;
3611  psiList.push_back(psi);
3612 
3613  error=false;double iota = GetPar("iota",par,error);
3614  if(error) iotaList.push_back(0);
3615  else if(iota>=0&&iota<=180) iotaList.push_back(iota);
3616  else iotaList.push_back(rad2deg*acos(gRandom->Uniform(-1,1)));
3617 
3618  hrssList.push_back(0);
3619  IDList.push_back(-1);
3620  idList.push_back(-1);
3621  }
3622 
3623  if(rd!=NULL) delete rd;
3624 
3625  } else
3626  if(sky_distribution==MDC_MNGD) {
3627 
3628  bool error=false;
3629  double entries = GetPar("entries",par,error);
3630 
3631  if(error) {
3632  cout << "CWB::mdc::SetSkyDistribution - "
3633  << "Error : num par must be 1 [entries]" << endl;
3634  exit(1);
3635  }
3636 
3637  cout << "CWB::mdc::SetSkyDistribution - the Miyamoto-Nagai Galactic Disk Model" << endl;
3638 
3639  char formula[256];
3640  sprintf(formula,"[1]*[1]*[2]*%s/%s",MNGD_NUMERATOR,MNGD_DENOMINATOR);
3641 
3642  TF3 *gd1 = new TF3("gd1",formula,-MNGD_XMAX,MNGD_XMAX,-MNGD_XMAX,MNGD_XMAX,-MNGD_YMAX,MNGD_YMAX);
3643  gd1->SetParameter(0,MNGD_A1); // a
3644  gd1->SetParameter(1,MNGD_B); // b
3645  gd1->SetParameter(2,MNGD_Md1); // b
3646  gd1->SetParameter(3,MNGD_SOLAR_SISTEM_DISTANCE_FROM_GC);
3647 
3648  TF3 *gd2 = new TF3("gd2",formula,-MNGD_XMAX,MNGD_XMAX,-MNGD_XMAX,MNGD_XMAX,-MNGD_YMAX,MNGD_YMAX);
3649  gd2->SetParameter(0,MNGD_A2); // a
3650  gd2->SetParameter(1,MNGD_B); // b
3651  gd2->SetParameter(2,MNGD_Md2); // b
3652  gd2->SetParameter(3,MNGD_SOLAR_SISTEM_DISTANCE_FROM_GC);
3653 
3654  TF3 *gd3 = new TF3("gd3",formula,-MNGD_XMAX,MNGD_XMAX,-MNGD_XMAX,MNGD_XMAX,-MNGD_YMAX,MNGD_YMAX);
3655  gd3->SetParameter(0,MNGD_A3); // a
3656  gd3->SetParameter(1,MNGD_B); // b
3657  gd3->SetParameter(2,MNGD_Md3); // b
3658  gd3->SetParameter(3,MNGD_SOLAR_SISTEM_DISTANCE_FROM_GC);
3659 
3660  TF3* gd = new TF3("gd","gd1+gd2+gd3",-MNGD_XMAX,MNGD_XMAX,-MNGD_XMAX,MNGD_XMAX,-MNGD_YMAX,MNGD_YMAX);
3661 
3662  gd->SetNpx(100);
3663  gd->SetNpy(100);
3664  gd->SetNpz(100);
3665 
3666  // Generate randomly sources from the Gatactic Disk
3667 
3668  XYZVector xyz;
3670  xyz.SetXYZ(xgc,ygc,zgc);
3671 
3672  double ilongitude = xyz.Phi()*rad2deg;
3673  double ilatitude = -(xyz.Theta()-TMath::Pi()/2.)*rad2deg;
3674  double olongitude,olatitude;
3675  GalacticToEquatorial(ilongitude, ilatitude, olongitude, olatitude);
3676  double gc_phi = olongitude;
3677  double gc_theta = olatitude;
3678  double gc_rho = sqrt(xyz.mag2());
3679 
3680  cout << "gc_phi : " << gc_phi << " gc_theta : " << gc_theta << " " << gc_rho << endl;
3681 
3682  double x,y,z;
3683  for(int n=0;n<entries;n++) {
3684 
3685  gd->GetRandom3(x,y,z);
3686  xyz.SetXYZ(x,y,z);
3687 
3688  double ilongitude = xyz.Phi()*rad2deg;
3689  double ilatitude = -(xyz.Theta()-TMath::Pi()/2.)*rad2deg;
3690  double olongitude,olatitude;
3691  GalacticToEquatorial(ilongitude, ilatitude, olongitude, olatitude);
3692  phList.push_back(olongitude);
3693  thList.push_back(olatitude);
3694  psiList.push_back(gRandom->Uniform(0,180));
3695  rhoList.push_back(sqrt(xyz.mag2()));
3696 
3697  error=false;double iota = GetPar("iota",par,error);
3698  if(error) iotaList.push_back(0);
3699  else if(iota>=0&&iota<=180) iotaList.push_back(iota);
3700  else iotaList.push_back(rad2deg*acos(gRandom->Uniform(-1,1)));
3701 
3702  hrssList.push_back(0);
3703  IDList.push_back(-1);
3704  idList.push_back(-1);
3705  }
3706 
3707  delete gd1;
3708  delete gd2;
3709  delete gd3;
3710  delete gd;
3711 
3712  } else
3713  if(sky_distribution==MDC_GWGC) {
3714 
3715  bool error=false;
3716  double distance_thr = GetPar("distance_thr",par,error);
3717 
3718  if(error) {
3719  cout << "CWB::mdc::SetSkyDistribution - "
3720  << "Error : num par must be 1 [distance_thr]" << endl;
3721  exit(1);
3722  }
3723 
3724  cout << "CWB::mdc::SetSkyDistribution - Gravitational Wave Galaxy Catalog" << endl;
3725  cout << "CWB::mdc::SetSkyDistribution - Distance Threshold " << distance_thr << " Kpc" << endl;
3726 
3727  ifstream in;
3728  in.open(fName,ios::in);
3729  if (!in.good()) {cout << "CWB::mdc::SetSkyDistribution - Error Opening File : " << fName << endl;exit(1);}
3730 
3731  // get number of entries
3732  int entries=0;
3733  char str[1024];
3734  while(true) {
3735  in.getline(str,1024);
3736  if (!in.good()) break;
3737  if(str[0] != '#') entries++;
3738  }
3739  cout << "entries " << entries << endl;
3740  in.clear(ios::goodbit);
3741  in.seekg(0, ios::beg);
3742 
3743  char iline[1024];
3744  in.getline(iline,1024); // skip first line (header)
3745  while (1) {
3746 
3747  in.getline(iline,1024);
3748  if (!in.good()) break;
3749  TObjArray* tok = TString(iline).Tokenize(TString('|'));
3750 
3751  TObjString* tra = (TObjString*)tok->At(2);
3752  TObjString* tdec = (TObjString*)tok->At(3);
3753  TObjString* tdist = (TObjString*)tok->At(14);
3754 
3755  delete tok;
3756 
3757  double ra = tra->GetString().Atof();
3758  double dec = tdec->GetString().Atof();
3759  double dist = tdist->GetString().Atof(); // Mpc
3760 
3761  dist *= 1000; // Mpc -> Kpc
3762  if (dist<distance_thr) {
3763  thList.push_back(dec);
3764  phList.push_back(ra*360./24.);
3765  psiList.push_back(gRandom->Uniform(0,180));
3766  rhoList.push_back(dist);
3767 
3768  error=false;double iota = GetPar("iota",par,error);
3769  if(error) iotaList.push_back(0);
3770  else if(iota>=0&&iota<=180) iotaList.push_back(iota);
3771  else iotaList.push_back(rad2deg*acos(gRandom->Uniform(-1,1)));
3772 
3773  hrssList.push_back(0);
3774  IDList.push_back(-1);
3775  idList.push_back(-1);
3776  }
3777  }
3778 
3779  } else
3780  if(sky_distribution==MDC_CUSTOM) {
3781 
3782  cout << "CWB::mdc::SetSkyDistribution - User Custom Distribution" << endl;
3783 
3784  ifstream in;
3785  in.open(fName,ios::in);
3786  if (!in.good()) {cout << "CWB::mdc::SetSkyDistribution - Error Opening File : " << fName << endl;exit(1);}
3787 
3788  // get number of entries
3789  int entries=0;
3790  char str[1024];
3791  while(true) {
3792  in.getline(str,1024);
3793  if (!in.good()) break;
3794  if(str[0] != '#') entries++;
3795  }
3796  cout << "entries " << entries << endl;
3797  in.clear(ios::goodbit);
3798  in.seekg(0, ios::beg);
3799 
3800  char name[128];
3801  double gps,psi,rho,iota,hrss;
3802  double theta,phi; // geographic coordinates
3803  int ID,id;
3804  int fpos=0;
3805  while (1) {
3806  fpos=in.tellg();
3807  in.getline(str,1024);
3808  if(str[0] == '#') continue;
3809  if (!in.good()) break;
3810 
3811  std::stringstream linestream(str);
3812  if(!(linestream >> gps >> name >> theta >> phi >> psi >> rho >> iota >> hrss >> ID >> id)) {
3813  cout << "CWB::mdc::SetSkyDistribution - Wrong Format for File : " << fName << endl;
3814  cout << "input line : " << endl;
3815  cout << str << endl;
3816  cout << "must be : " << endl;
3817  cout << "gps " << "name " << "theta " << "phi " << "psi "
3818  << "rho " << "iota " << "hrss " << "ID " << "id " << "..." << endl;
3819  exit(1);
3820  }
3821  //cout << gps << " " << name << " " << theta << " " << phi << " " << psi
3822  // << " " << rho << " " << iota << " " << hrss << " " << ID << " " << id << endl;
3823 
3824  gpsList.push_back(gps);
3825  nameList.push_back(name);
3826  thList.push_back(theta);
3827  phList.push_back(phi);
3828  psiList.push_back(psi);
3829  rhoList.push_back(rho);
3830  iotaList.push_back(iota);
3831  hrssList.push_back(hrss);
3832  IDList.push_back(ID);
3833  idList.push_back(id);
3834  }
3835 
3836  in.close();
3837 
3838  } else
3839  if(sky_distribution==MDC_XMLFILE) {
3840 
3841 #ifdef _USE_LAL
3842  cout << "CWB::mdc::SetSkyDistribution - User Distribution from XML" << endl;
3843 
3844 #if LAL_VERSION_MAJOR > 6 || (LAL_VERSION_MAJOR == 6 && \
3845  (LAL_VERSION_MINOR > 14 || (LAL_VERSION_MINOR == 14 && \
3846  LAL_VERSION_MICRO >= 0 ))) // LAL_VERSION >= 6.14.0
3847 #else
3848  cout << "CWB::mdc::SetSkyDistribution - LAL XML File can not be used with LAL ver < 6.14.0" << endl;
3849  exit(1);
3850 #endif
3851 
3852  Long_t id,fsize,flags,mt;
3853  int estat = gSystem->GetPathInfo(fName.Data(),&id,&fsize,&flags,&mt);
3854  if (estat!=0) {
3855  cout << "CWB::mdc::SetSkyDistribution - XML File : " << fName.Data() << " Not Exist" << endl;
3856  exit(1);
3857  }
3858 
3859  bool error;
3860 
3861  // get decimals
3862  error=false;
3863  int decimals = GetPar("decimals",par,error);
3864  if(error) decimals=1;
3865 
3866  // get hrss_factor : is a user factor used to rescale hrss
3867  error=false;
3868  double hrss_factor = GetPar("hrss_factor",par,error);
3869  if(error) hrss_factor=1;
3870 
3871  // get mdc engine : aal=0, cwb=1 (default)
3872  error=false;
3873  int engine = GetPar("engine",par,error);
3874  if(error) engine=1;
3875 
3876  // get auto mode for MDC type : if auto=0 the MDC names must be provided by user
3877  error=false;
3878  int AUTO = GetPar("auto",par,error);
3879  if(error) AUTO=0;
3880 
3881  // get time range for injections
3882  error=false;
3883  double start = GetPar("start",par,error);
3884  if(error) start=0;
3885  error=false;
3886  double stop = GetPar("stop",par,error);
3887  if(error) stop=std::numeric_limits<double>::max();;
3888 
3889  xmlType.clear();
3890  if(!AUTO) { // get user defined xml types
3891  for(int n=0;n<par.size();n++) {
3892  error=false;
3893  vector<mdcpar> xpar(1); xpar[0]=par[n];
3894  TString type = GetParString("type",xpar,error);
3895  if(!error) { // add to xmlType if type is not present in the xmlType list
3896  bool present=false;
3897  for(int m=0;m<xmlType.size();m++) {
3898  if(type==xmlType[m]) {present=true;break;}
3899  }
3900  if(!present) xmlType.push_back(type.Data());
3901  }
3902  }
3903  }
3904 
3905  // read sim_burst table from XML file (see LIGOLwXMLBurstRead.c)
3906  LIGOTimeGPS gpsStartTime = {(int)start, 0};
3907  LIGOTimeGPS gpsStopTime = {(int)stop, 0};
3908  SimBurst* sim_burst = XLALSimBurstTableFromLIGOLw(fName.Data(),&gpsStartTime,&gpsStopTime);
3909  if(sim_burst==NULL) {
3910  cout << "CWB::mdc::SetSkyDistribution - XML File : " << fName.Data() << endl;
3911  cout << " No Events present in the range : " << (int)start << ":" << (int)stop <<endl;
3912  }
3913  skymap sm; // used to convert ra -> phi
3914  int sim_burst_index=0;
3915  for(; sim_burst; sim_burst = sim_burst->next) {
3916 
3917  sim_burst_index++;
3918 
3919  // the gps time of the injection corresponds to the sample at t=0
3920  // in the resultant time series. See XLALGenerateSimBurst in GenerateBurst.c
3921  double gps = sim_burst->time_geocent_gps.gpsSeconds;
3922  gps += 1.e-9*sim_burst->time_geocent_gps.gpsNanoSeconds;
3923 
3924  if(gps<start || gps>stop) continue; // skip if injection is not in the time range
3925 
3926  char name[128]= "";
3927 
3928  // read waveform parameters (see XLALWriteLIGOLwXMLSimBurstTable in LIGOLwXML.c)
3929  double phi = sm.RA2phi(rad2deg*sim_burst->ra,gps);
3930  double theta = rad2deg*(TMath::PiOver2()-sim_burst->dec);
3931  double psi = rad2deg*sim_burst->psi;
3932  double frequency = sim_burst->frequency;
3933  double Q = sim_burst->q;
3934  double duration = sim_burst->duration;
3935  double bandwidth = sim_burst->bandwidth;
3936  double rho = -1.; // rho<0 -> no hrss rescaling in GetBurst
3937  double phase = rad2deg*sim_burst->pol_ellipse_angle;
3938  double eccentricity = sim_burst->pol_ellipse_e;
3939  double hrss = sim_burst->hrss * hrss_factor;
3940  double amplitude = sim_burst->amplitude;
3941  double egw_over_rsquared = sim_burst->egw_over_rsquared;
3942  double waveform_number = sim_burst->waveform_number;
3943 
3944  // NOTE : iota is set to eccentricity but is not used because LAL implicity
3945  // apply with the parameter sim_burst->pol_ellipse_e
3946  // NOTE : CWB uses ellipticity, instead LAL uses eccentricity :
3947  // see XLALSimBurstSineGaussian in LALSimBurst.c
3948  // NOTE : the parameter phase is used by LAL to generate SG,CG waveforms
3949  // when random polarization is used the phase parameter is not effective
3950  // because the polarization angle is equivalent to the phase angle
3951 
3952  // eccentricity is saved in iota parameter, it is used in CWB::mdc::GetBurst
3953  double iota = eccentricity;
3954  //double cosi = e2cosi(eccentricity);
3955  //double iota = acos(cosi)*180./TMath::Pi();
3956 
3957  mdcid waveid;
3958  vector<mdcpar> wpar;
3959 
3960  // Convert LAL SimBurst defined in LALSimBurst.c into cWB MDC waveforms
3961  if(TString(sim_burst->waveform)=="Gaussian") {
3962 
3963  // add gaussian waveform
3964  wpar.resize(2);
3965  wpar[0].name="duration"; wpar[0].value=duration;
3966  wpar[1].name="decimals"; wpar[1].value=decimals;
3967  waveid = engine ? AddWaveform(MDC_GA, wpar) :
3968  AddWaveform(MDC_GA_LAL, sim_burst, wpar);
3969  sprintf(name,waveid.name.Data());
3970 
3971  } else
3972  if(TString(sim_burst->waveform)=="SineGaussian") {
3973 
3974  // add sinegaussian waveform
3975  wpar.resize(3);
3976  wpar[0].name="frequency"; wpar[0].value=frequency;
3977  wpar[1].name="Q"; wpar[1].value=Q;
3978  wpar[2].name="decimals"; wpar[2].value=decimals;
3979  waveid = engine ? AddWaveform(MDC_SGE, wpar) :
3980  AddWaveform(MDC_SGE_LAL, sim_burst, wpar);
3981  sprintf(name,waveid.name.Data());
3982 
3983  } else
3984  if(TString(sim_burst->waveform)=="BTLWNB") {
3985 
3986  // add whitenoiseburst waveform
3987  wpar.resize(7);
3988  wpar[0].name="frequency"; wpar[0].value=frequency;
3989  wpar[1].name="bandwidth"; wpar[1].value=bandwidth;
3990  wpar[2].name="duration"; wpar[2].value=duration;
3991  wpar[3].name="pseed"; wpar[3].value=seed+2*sim_burst_index;
3992  wpar[4].name="xseed"; wpar[4].value=seed+2*sim_burst_index+1;
3993  wpar[5].name="mode"; wpar[5].value=0; // asymmetric
3994  wpar[6].name="decimals"; wpar[6].value=decimals;
3995  waveid = engine ? AddWaveform(MDC_WNB, wpar) :
3996  AddWaveform(MDC_WNB_LAL, sim_burst, wpar);
3997  sprintf(name,waveid.name.Data());
3998 
3999  } else
4000  if(TString(sim_burst->waveform)=="StringCusp") {
4001 
4002  // add string cusp waveform
4003  wpar.resize(3);
4004  wpar[0].name="frequency"; wpar[0].value=frequency;
4005  wpar[1].name="amplitude"; wpar[1].value=amplitude;
4006  wpar[2].name="decimals"; wpar[2].value=decimals;
4007  waveid = AddWaveform(MDC_SC_LAL, sim_burst, wpar);
4008  sprintf(name,waveid.name.Data());
4009 
4010  }
4011 
4012  if(AUTO) {
4013  // fill xmlType
4014  for(int i=0;i<(int)wfList.size();i++) {
4015  bool save=true;
4016  for(int j=0; j<(int)xmlType.size(); j++){
4017  if(wfList[i].name.CompareTo(xmlType[j])==0) {save = false; break;}
4018  }
4019  if(save) {
4020  xmlType.push_back(wfList[i].name.Data());
4021  }
4022  }
4023  } else {
4024  // check if waveid.name is in the xmlType list
4025  bool present=false;
4026  for(int n=0;n<xmlType.size();n++) {
4027  if(waveid.name==xmlType[n]) {present=true;break;}
4028  }
4029  if(!present) {
4030  cout << "CWB::mdc::SetSkyDistribution - "
4031  << "Error : mdc type " << waveid.name << " is not in the xmlType list" << endl;
4032  cout<<endl<<"xmlType list : "<<endl<<endl;
4033  for(int n=0;n<xmlType.size();n++) {
4034  cout << "xmlType[" << n << "] : " << xmlType[n] << endl;
4035  }
4036  cout<<endl;
4037  exit(1);
4038  }
4039  }
4040 
4041  //cout.precision(3);
4042  //cout << (int)gps << " " << name << " th: " << theta << " ph: " << phi << " psi: " << psi
4043  // << " f: " << frequency << " Q: " << Q << " d: " << duration << " b: " << bandwidth
4044  // << " p:" << phase << " e: " << eccentricity << endl;
4045 
4046  // fill event parameter list
4047  gpsList.push_back(gps);
4048  nameList.push_back(name);
4049  thList.push_back(theta);
4050  phList.push_back(phi);
4051  psiList.push_back(psi);
4052  rhoList.push_back(rho);
4053  iotaList.push_back(iota);
4054  hrssList.push_back(hrss);
4055  IDList.push_back(waveid.ID);
4056  idList.push_back(waveid.id);
4057  }
4058 #else
4059  cout << "CWB::mdc::SetSkyDistribution - "
4060  << "Error : User Distribution from XML is enabled only with LAL" << endl;
4061  exit(1);
4062 #endif
4063 
4064  } else
4065  if((sky_distribution==MDC_EARTH_FIX)||
4066  (sky_distribution==MDC_CELESTIAL_FIX)) {
4067 
4068  bool error=false;
4069  bool gerror=false;
4070  double theta = GetPar("theta",par,error);
4071  if(gerror) gerror=error;
4072  double phi = GetPar("phi",par,error);
4073  if(gerror) gerror=error;
4074 
4075  if(gerror) {
4076  cout << "CWB::mdc::SetSkyDistribution - "
4077  << "Error : num par must be at least 2 [theta,phi,(psi,rho,gps)]" << endl;
4078  exit(1);
4079  }
4080 
4081  double value,psi,rho,iota,hrss;
4082  value=psi=rho=iota=0.;
4083  error=false;value=GetPar("entries",par,error);
4084  int entries = error ? 10000 : int(value);
4085  for(int n=0;n<entries;n++) {
4086  error=false;value=GetPar("psi",par,error);
4087  psi = error ? gRandom->Uniform(0,180) : value;
4088  error=false;value=GetPar("rho",par,error);
4089  rho = error ? 0. : value;
4090  error=false;value=GetPar("gps",par,error);
4091  if(!error) gpsList.push_back(value);
4092 
4093  error=false;iota = GetPar("iota",par,error);
4094  if(error) iotaList.push_back(0);
4095  else if(iota>=0&&iota<=180) iotaList.push_back(iota);
4096  else iotaList.push_back(rad2deg*acos(gRandom->Uniform(-1,1)));
4097 
4098  thList.push_back(theta);
4099  phList.push_back(phi);
4100  psiList.push_back(psi);
4101  rhoList.push_back(rho);
4102  hrssList.push_back(0);
4103  IDList.push_back(-1);
4104  idList.push_back(-1);
4105  }
4106  } else
4107  if(sky_distribution==MDC_LOGFILE) {
4108  if(net==NULL) {
4109  cout << "CWB::mdc::SetSkyDistribution - Error : Dummy method : network is not initialized " << endl;
4110  exit(1);
4111  }
4112  int nInj=net->readMDClog(const_cast<char*>(fName.Data()),0.);
4113  printf("CWB::mdc::SetSkyDistribution - injections loaded : %d\n",nInj);
4114  for(int k=0;k<nInj;k++) net->mdc__ID.push_back(k);
4115  size_t N = net->mdc__IDSize();
4116  size_t M = net->mdcTypeSize();
4117  cout << N << " " << M << endl;
4118  // fill mdcName vector with name of MDC (used in GetSourceList)
4119  mdcName.clear();
4120  for(int k=0;k<M;k++) mdcName.push_back(net->mdcType[k]);
4121  int nIFO=net->ifoListSize();
4122  inj = new injection(nIFO);
4123  inj_tree = inj->setTree();
4124  inj->output(inj_tree,net,1,false);
4125  delete inj;
4126  inj = new injection(inj_tree,nIFO);
4127  cout << "inj entries : " << inj->GetEntries() << endl;
4128  }
4129 
4130  return;
4131 }
4132 
4133 //______________________________________________________________________________
4134 void
4135 CWB::mdc::DrawSkyDistribution(TString name, TString projection, TString coordinate, double resolution, bool background) {
4136 //
4137 // Draw Sky Distribution
4138 //
4139 //
4140 // Input: name - unique name for canvas plot
4141 // projection - hammer, sinusoidal, parabolic
4142 // coordinate - geographic, celestial
4143 // resolution - default 2, define the resolution of pixels
4144 // background - false/true : if true draw a background color (blue)
4145 //
4146 
4147  if(psp!=NULL) delete psp;
4148  psp = new gskymap(0.4,0,180,0,360);
4149  psp->SetOptions(projection,coordinate,resolution/2);
4150 
4151  if(background) {
4152  psp->SetGridxColor(kWhite);
4153  psp->SetGridyColor(kWhite);
4154  } else {
4155  psp->SetGridxColor(kBlack);
4156  psp->SetGridyColor(kBlack);
4157  }
4158 // psp->SetGalacticDisk(true);
4159 // psp->SetGalacticDiskColor(kYellow);
4160 
4161  int entries=0;
4162  int size=360*2*resolution*180*2*resolution;
4164 
4165  double zmax=0.;
4166  if(sky_distribution==MDC_LOGFILE) {
4167 
4168  if(inj_tree==NULL) {
4169  cout << "CWB::mdc::DrawSkyDistribution - Error : injection object is NULL" << endl;
4170  exit(1);
4171  }
4172 
4173  inj_tree->Draw("theta[0]:phi[0]:distance[0]:time[0]","","goff");
4174  entries = inj_tree->GetSelectedRows();
4175  size += entries;
4176  x.resize(size); y.resize(size); z.resize(size);
4177  double* theta = inj_tree->GetV1();
4178  double* phi = inj_tree->GetV2();
4179  double* distance = inj_tree->GetV3();
4180  double* gps = inj_tree->GetV4();
4181  coordinate.ToUpper();
4182  if(coordinate.CompareTo("CELESTIAL")==0) {
4183  for(int n=0;n<entries;n++) x[n] = sm.phi2RA(phi[n],gps[n]); // celestial 2 earth coordinates
4184  } else {
4185  for(int n=0;n<entries;n++) x[n] = phi[n];
4186  }
4187  for(int n=0;n<entries;n++) {
4188  y[n] = theta[n];
4189  z[n] = distance[n];
4190  if(zmax<z[n]) zmax=z[n];
4191  }
4192 
4193  } else {
4194  entries = (int)rhoList.size();
4195  size += entries;
4196  x.resize(size); y.resize(size); z.resize(size);
4197  for(int n=0;n<entries;n++) {
4198  x[n]=phList[n];
4199  y[n]=thList[n];
4200  z[n]=rhoList[n];
4201  if(zmax<z[n]) zmax=z[n];
4202  }
4203  }
4204 
4205  if(entries==0) {
4206  cout << "CWB::mdc::DrawSkyDistribution - Warning : no entries in sky distribution " << endl;
4207  exit(1);
4208  }
4209 
4210  size=entries;
4211  // add blue background
4212  if(background) {
4213  for (int i=0;i<360*2*resolution;i++) {
4214  for (int j=0;j<180*2*resolution;j++) {
4215  double ph = i/(double)(2*resolution);
4216  double th = j/(double)(2*resolution);
4217  x[size]=ph;
4218  y[size]=th;
4219  z[size]=zmax;
4220  size++;
4221  }
4222  }
4223  }
4224 
4225  // sort source respect to distance
4226  if(entries>1) {
4227  Int_t *index = new Int_t[size];
4228  TMath::Sort(size,z.data,index,true);
4229  wavearray<double> T(size);
4230  for (int i=0;i<size;i++) T[i]=x[index[i]];
4231  for (int i=0;i<size;i++) x[i]=T[i];
4232  for (int i=0;i<size;i++) T[i]=y[index[i]];
4233  for (int i=0;i<size;i++) y[i]=T[i];
4234  for (int i=0;i<size;i++) T[i]=z[index[i]];
4235  for (int i=0;i<size;i++) z[i]=T[i];
4236  T.resize(0);
4237  delete [] index;
4238  }
4239 
4240  psp->FillData(size, x.data, y.data, z.data);
4241 
4242  psp->SetZaxisTitle("Kpc");
4243  psp->Draw(-2);
4244 
4245  x.resize(0);
4246  y.resize(0);
4247  z.resize(0);
4248 
4249  return;
4250 }
4251 
4252 //______________________________________________________________________________
4253 TString
4254 CWB::mdc::WriteFrameFile(TString frDir, TString frLabel, size_t gps, size_t length, bool log, vector<TString> chName) {
4255 //
4256 // Write mdc to frame file
4257 //
4258 //
4259 // Input: frDir - output directory
4260 // frLabel - label used for output file name
4261 // file name path = frDir/network-frLabel-(gps/100000)/network-frLabel-gps.gwf
4262 // gps - time of frame (sec - integer)
4263 // length - time length of frame (sec - integer)
4264 // log - if 'true' then write log file
4265 // chName - channel name list, list size must be 0 or nIFO
4266 // if list size=0 then chName is IFO_NAME:GW-H
4267 // if list size=nIFO then is chName[n]="" then chName is IFO_NAME:GW-H
4268 //
4269 // Return log string
4270 //
4271 
4272  if(net==NULL) {
4273  cout << "CWB::mdc::WriteFrameFile - Error : Dummy method : network is not initialized " << endl;
4274  exit(1);
4275  }
4276 
4277  int nIFO=net->ifoListSize();
4278  char ifoLabel[64]="";
4279  for(int i=0;i<nIFO;i++) sprintf(ifoLabel,"%s%s",ifoLabel,net->ifoName[i]);
4280 
4281  // check input chName
4282  if(chName.size()!=0 && chName.size()!=nIFO) {
4283  cout << "CWB::mdc::WriteFrameFile - Error : chName list size must be equals to nIFO " << nIFO << endl;
4284  exit(1);
4285  }
4286 
4287  // make sub directory
4288  char sdir[64];
4289  sprintf(sdir,"%s-%s-%04d",ifoLabel,frLabel.Data(),int(gps/100000));
4290  char cmd[128];sprintf(cmd,"mkdir -p %s/%s",frDir.Data(),sdir);
4291  cout << cmd << endl;
4292  gSystem->Exec(cmd);
4293 
4294  char frFile[512];
4295  sprintf(frFile,"%s/%s/%s-%s-%lu-%lu.gwf",frDir.Data(),sdir,ifoLabel,frLabel.Data(),gps,length);
4296  cout << frFile << endl;
4297  FrFile *ofp = FrFileONew(frFile,1); // gzip compression
4298 
4299  /*----------------------- Create a new frame ---------*/
4300 
4301  FrameH* simFrame = FrameNew(const_cast<char*>(ifoLabel));
4302  simFrame->frame = 0;
4303  simFrame->run = -1;
4304  simFrame->dt = length;
4305  simFrame->GTimeS = gps;
4306  simFrame->GTimeN = 0;
4307 
4309  x.rate(MDC_SAMPLE_RATE);
4310  x.start(gps);
4311  char chNAME[64];
4312  for(int i=0;i<nIFO;i++) {
4313 
4314  TString ifo=net->ifoName[i];
4315  if(chName.size()) {
4316  if(chName[i]!="") sprintf(chNAME,"%s",chName[i].Data());
4317  else sprintf(chNAME,"%s:GW-H",net->ifoName[i]);
4318  } else {
4319  sprintf(chNAME,"%s:GW-H",net->ifoName[i]);
4320  }
4321 
4322  Get(x,ifo);
4323 
4324  cout << "Size (sec) " << x.size()/x.rate() << endl;
4325  FrProcData* proc = FrProcDataNew(simFrame,chNAME,x.rate(),x.size(),-64);
4326  if(proc == NULL) {cout << "CWB::mdc::WriteFrameFile - Cannot create FrProcData" << endl; exit(-1);}
4327  proc->timeOffset = 0;
4328  proc->tRange = simFrame->dt;
4329  proc->type = 1; // Time Serie
4330 
4331  for (int i=0;i<(int)proc->data->nData;i++) proc->data->dataD[i] = x[i];
4332  }
4333 
4334  int err=FrameWrite(simFrame,ofp);
4335  if (err) {cout << "CWB::mdc::WriteFrameFile - Error writing frame" << endl;exit(1);}
4336  FrameFree(simFrame);
4337 
4338  if (ofp!=NULL) FrFileOEnd(ofp);
4339 
4340 
4341  // log string
4342  TString logString = "";
4343  for(int i=0;i<(int)mdcList.size();i++) logString = logString+mdcList[i]+"\n";
4344 
4345  // write log file
4346  if(log) {
4347  TString logFile=frFile;
4348  logFile.ReplaceAll(".gwf","-Log.txt");
4349  DumpLog(logFile);
4350 /*
4351  ofstream out;
4352  out.open(logFile.Data(),ios::out);
4353  if (!out.good()) {cout << "CWB::mdc::WriteFrameFile - Error Opening File : " << logFile.Data() << endl;exit(1);}
4354  out.precision(14);
4355  for(int i=0;i<(int)mdcList.size();i++) out << mdcList[i] << endl;
4356  out.close();
4357 */
4358  }
4359 
4360  return logString;
4361 }
4362 
4363 //______________________________________________________________________________
4364 void
4366 //
4367 // Write waveform to file
4368 //
4369 //
4370 // Input: fname - output file name
4371 // ID - major id of waveform list
4372 // id - minor id of waveform list (Ex : the list WNB with different random waveforms)
4373 // polarization - hp/hx
4374 //
4375 
4376  polarization.ToUpper();
4377  waveform wf = GetWaveform(ID,id);
4378  if(wf.status) {
4379  if(polarization.Contains("HP")) Dump(fname, wf.hp);
4380  if(polarization.Contains("HX")) Dump(fname, wf.hx);
4381  }
4382  return;
4383 }
4384 
4385 //______________________________________________________________________________
4386 void
4388 //
4389 // Write waveform to file
4390 //
4391 //
4392 // Input: fname - output file name
4393 // name - name of waveform
4394 // id - minor id of waveform list (Ex : the list WNB with different random waveforms)
4395 // polarization - hp/hx
4396 //
4397 
4398  polarization.ToUpper();
4399  waveform wf = GetWaveform(name,id);
4400  if(wf.status) {
4401  if(polarization.Contains("HP")) Dump(fname, wf.hp);
4402  if(polarization.Contains("HX")) Dump(fname, wf.hx);
4403  }
4404  return;
4405 }
4406 
4407 //______________________________________________________________________________
4408 void
4410 //
4411 // Write waveform to file
4412 //
4413 //
4414 // Input: fname - output file name
4415 // x - wavearray which contains the waveform data
4416 //
4417 
4418  ofstream out;
4419  out.open(fname.Data(),ios::out);
4420  if (!out.good()) {cout << "CWB::mdc::WriteFrameFile - Error Opening File : " << fname.Data() << endl;exit(1);}
4421  out.precision(14);
4422  for(int i=0;i<(int)x.size();i++) out << x[i] << endl;
4423  out.close();
4424 
4425  return;
4426 }
4427 
4428 //______________________________________________________________________________
4429 void
4431 //
4432 // Write all waveform to file
4433 //
4434 //
4435 // Input: dname - output directory name
4436 // all file are written under dname
4437 //
4438 
4439  // create dir
4440  char cmd[256];
4441  sprintf(cmd,"mkdir -p %s",dname.Data());
4442  gSystem->Exec(cmd);
4443 
4444  char sid[8];
4445  for(int i=0;i<(int)wfList.size();i++) {
4446  //cout << "ID : " << i << "\t" << wfList[i].name.Data() << endl;
4447  Dump(dname+"/"+wfList[i].name+"~01.txt", i, 0, "hp");
4448  Dump(dname+"/"+wfList[i].name+"~02.txt", i, 0, "hx");
4449  printf("%s\n",TString(dname+"/"+wfList[i].name+"~01.txt").Data());
4450  printf("%s\n",TString(dname+"/"+wfList[i].name+"~02.txt").Data());
4451  for(int j=0;j<(int)wfList[i].list.size();j++) {
4452  //cout << " id : " << j+1 << "\t" << wfList[i].list[j].name.Data() << endl;
4453  sprintf(sid,"~%02d",2*(j+1)+1);
4454  Dump(dname+"/"+wfList[i].name+sid+".txt", i, j+1, "hp");
4455  printf("%s\n",TString(dname+"/"+wfList[i].name+sid+".txt").Data());
4456  sprintf(sid,"~%02d",2*(j+1)+1);
4457  Dump(dname+"/"+wfList[i].name+sid+".txt", i, j+1, "hx");
4458  printf("%s\n",TString(dname+"/"+wfList[i].name+sid+".txt").Data());
4459  }
4460  }
4461  return;
4462 }
4463 
4464 //______________________________________________________________________________
4465 double
4467 //
4468 // Get Antenna Pattern
4469 //
4470 //
4471 // Input: ifo - name of detector
4472 // phi - longitude (degrees)
4473 // theta - latitude (degrees)
4474 // psi - polarization (degrees)
4475 // polarization - hp/hx -
4476 //
4477 
4478  int nIFO = net ? net->ifoListSize() : 0;
4479 
4480  int ifoId=-1;
4481  detector* pD=NULL;
4482  for(int n=0; n<nIFO; n++) if(ifo.CompareTo(net->ifoName[n])==0) ifoId=n;
4483  if(ifoId>=0) pD = net->getifo(ifoId);
4484  else pD = new detector(const_cast<char*>(ifo.Data()));
4485 
4486  wavecomplex F = pD->antenna(theta,phi,psi);
4487  if(ifoId<0) delete pD;
4488  polarization.ToUpper();
4489  if(polarization.Contains("HP")) return F.real(); else return F.imag();
4490 }
4491 
4492 //______________________________________________________________________________
4493 double
4494 CWB::mdc::GetDelay(TString ifo1, TString ifo2, double phi, double theta) {
4495 //
4496 // Get Delay Traveling Time between two detectors
4497 //
4498 //
4499 // Input: ifo1 - name of the first detector
4500 // ifo2 - name of the second detector
4501 // if ifo2="" -> return ifo1 delay respect to geocenter
4502 // phi - longitude (degrees)
4503 // theta - latitude (degrees)
4504 //
4505 
4506  if(ifo1.CompareTo(ifo2)==0) return 0.0;
4507 
4508  int nIFO = net ? net->ifoListSize() : 0;
4509 
4510  int ifoId1=-1;
4511  detector* pD1=NULL;
4512  for(int n=0; n<nIFO; n++) if(ifo1.CompareTo(net->ifoName[n])==0) ifoId1=n;
4513  if(ifoId1>=0) pD1 = net->getifo(ifoId1);
4514  else pD1 = new detector(const_cast<char*>(ifo1.Data()));
4515 
4516  if(ifo2=="") {
4517  if(ifoId1<0) delete pD1;
4518  double delay = pD1->getTau(theta,phi);
4519  return delay; // return Delay Traveling Time between ifo1 and geocenter
4520  }
4521 
4522  int ifoId2=-1;
4523  detector* pD2=NULL;
4524  for(int n=0; n<nIFO; n++) if(ifo2.CompareTo(net->ifoName[n])==0) ifoId2=n;
4525  if(ifoId2>=0) pD2 = net->getifo(ifoId2);
4526  else pD2 = new detector(const_cast<char*>(ifo2.Data()));
4527 
4528  double delay = pD1->getTau(theta,phi)-pD2->getTau(theta,phi);
4529 
4530  if(ifoId1<0) delete pD1;
4531  if(ifoId2<0) delete pD2;
4532 
4533  return delay; // return Delay Traveling Time between ifo1 and ifo2
4534 }
4535 
4536 //______________________________________________________________________________
4537 void
4539 //
4540 // Dump log header to file
4541 //
4542 //
4543 // Input: fName - name of output file
4544 // label - label of file
4545 // size - number of mdc - if size<=0 use inj tree
4546 //
4547 
4548  if(size<=0 && inj==NULL) {
4549  cout << "CWB::mdc::DumpLogHeader - Error : dump needs injection object " << endl;
4550  exit(1);
4551  }
4552 
4553  // WRITE field headings to log file
4554 
4555  ofstream out;
4556  out.open(fName.Data(),ios::out);
4557  if (!out.good()) {cout << "CWB::mdc::DumpLogHeader - Error Opening File : " << fName.Data() << endl;exit(1);}
4558 
4559  int nIFO=net->ifoListSize();
4560 
4561  out << "# Log File for Burst " << label.Data() << endl;
4562  out << "# Produced by CWB::mdc " << wat::Time("now").GetDateString().Data() << endl;
4563  out << "# The following detectors were simulated" << endl;
4564  for(int n=0;n<nIFO;n++) out << "# - " << net->ifoName[n] << endl;
4565  if(size>0) {
4566  out << "# There were " << size << " injections" << endl;
4567  } else {
4568  out << "# There were " << net->mdcList.size() << " injections" << endl;
4569 // for(int i=0;i<(int)wfList.size();i++) {
4570 // out << "# Burst MDC Sim type " << wfList[i].name.Data() << endl;
4571 // }
4572  for(int i=0;i<(int)net->mdcType.size();i++) {
4573  char cut[16];sprintf(cut,"type==%d",i+1);
4574  inj_tree->Draw("type",cut,"goff");
4575  int ninj = inj_tree->GetSelectedRows();
4576  out << "# Burst MDC Sim type " << net->mdcType[i].data() << "\t occurred " << ninj << " times" << endl;
4577  }
4578  }
4579 
4580  out << "# GravEn_SimID SimHrss SimEgwR2 GravEn_Ampl ";
4581  out << "Internal_x Internal_phi ";
4582  out << "External_x External_phi External_psi ";
4583  out << "FrameGPS EarthCtrGPS SimName SimHpHp SimHcHc SimHpHc ";
4584  for(int n=0;n<nIFO;n++) {
4585  out << net->ifoName[n] << " " <<
4586  net->ifoName[n] << "ctrGPS " <<
4587  net->ifoName[n] << "fPlus " <<
4588  net->ifoName[n] << "fCross ";
4589  }
4590  out << endl;
4591 
4592  out.close();
4593 
4594  return;
4595 }
4596 
4597 #ifdef _USE_LAL
4598 //______________________________________________________________________________
4599 void
4600 CWB::mdc::CreateBurstXML(TString fName, vector<mdcpar> xml_parms) {
4601 //
4602 // Create XML file : Create XML LAL file + Add Header
4603 // see LAL LIGOLwXML.c
4604 //
4605 // Input: fName - name of the xml output file
4606 // xml_parms - contains custom auxiliary parameters to be added to the parameter table
4607 //
4608 
4609  if(inspName!="") {
4610  cout << "CWB::mdc::CreateBurstXML : Error : This function is allowed only for Burst !!!" << endl;
4611  exit(1);
4612  }
4613 
4614  if(xml_filename!="") {
4615  cout << "CWB::mdc::CreateBurstXML : Error : file XML already opened !!!" << endl;
4616  exit(1);
4617  }
4618 
4619  bool error=false;
4620  // extract start_time - start GPS time of interval in which to synthesize injections
4621  double start_time = GetPar("start_time",xml_parms,error); if(error) start_time = 0;
4622  // extract end_time - end GPS time of interval in which to synthesize injections
4623  double end_time = GetPar("end_time",xml_parms,error); if(error) end_time = 0;
4624 
4625  xml_filename = fName;
4626  xml_process_table_head = NULL;
4627  xml_process_params_table_head = NULL;
4628  xml_search_summary_table_head = NULL;
4629  xml_time_slide_table_head = NULL;
4630  xml_sim_burst_table_head = NULL;
4631  xml_sim_burst = &xml_sim_burst_table_head;
4632 
4633  TString ifos="";
4634  if(net!=NULL) for(int n=0;n<(int)net->ifoListSize();n++) ifos+=net->getifo(n)->Name+TString(",");
4635  if(ifos!="") ifos.Resize(ifos.Sizeof()-2);
4636 
4637  // Fill Process table
4638  xml_process_table_head = xml_process = XLALCreateProcessTableRow();
4639  sprintf(xml_process->program, "cWB"); // program name entry
4640  XLALGPSTimeNow(&xml_process->start_time); // start time
4641  sprintf(xml_process->version, watversion('r')); // git version
4642  sprintf(xml_process->cvs_repository, "https://git.ligo.org/cWB/library/");
4643  char cmd_line[2048]="";
4644  for(int i=0;i<gApplication->Argc();i++) sprintf(cmd_line,"%s %s",cmd_line,gApplication->Argv(i));
4645  sprintf(xml_process->comment, cmd_line); // save command line used to start the application
4646  sprintf(xml_process->domain, "cWB"); // online flag and domain
4647  // unix process id, username, host, and process_id
4648  UserGroup_t* uinfo = gSystem->GetUserInfo();
4649  xml_process->unix_procid = gSystem->GetPid();
4650  sprintf(xml_process->node, gSystem->HostName());
4651  sprintf(xml_process->username, uinfo->fUser);
4652  sprintf(xml_process->ifos,ifos.Data());
4653  xml_process->process_id = 0;
4654 
4655  // Fill Process parameter table
4656  ProcessParamsTable **paramaddpoint = &xml_process_params_table_head;
4657  if(net!=NULL) for(int n=0;n<(int)net->ifoListSize();n++) {
4658  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "string", "instrument", net->getifo(n)->Name);
4659  }
4660  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "double", "inj-hrss",
4661  TString::Format("%f",GetInjHrss()).Data());
4662  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "double", "time-step",
4663  TString::Format("%f",1./GetInjRate()).Data());
4664  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "double", "jitter",
4665  TString::Format("%f",GetInjJitter()).Data());
4666  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "enum", "sky-distribution",
4667  DistributionToString(sky_distribution));
4668  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "string", "sky-file", sky_file.Data());
4669  for(int i=0;i<sky_parms.size();i++) {
4670  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "double",
4671  sky_parms[i].name.Data(), TString::Format("%f",sky_parms[i].value).Data());
4672  }
4673  for(int i=0;i<xml_parms.size();i++) {
4674  if(xml_parms[i].svalue!="") {
4675  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "string",
4676  xml_parms[i].name.Data(), xml_parms[i].svalue.Data());
4677  } else {
4678  ADD_PROCESS_PARAM(paramaddpoint, xml_process, "double",
4679  xml_parms[i].name.Data(), TString::Format("%f",xml_parms[i].value).Data());
4680  }
4681  }
4682 
4683  // Fill Search summary table
4684  xml_search_summary_table_head = xml_search_summary = XLALCreateSearchSummaryTableRow(xml_process);
4685  sprintf(xml_search_summary->comment, "");
4686  sprintf(xml_search_summary->ifos,ifos.Data());
4687  xml_search_summary->nnodes = 1;
4688  wat::Time in_start_time(start_time);
4689  xml_search_summary->in_start_time.gpsSeconds = in_start_time.GetSec();
4690  xml_search_summary->in_start_time.gpsNanoSeconds = in_start_time.GetNSec();
4691  xml_search_summary->out_start_time.gpsSeconds = in_start_time.GetSec();
4692  xml_search_summary->out_start_time.gpsNanoSeconds = in_start_time.GetNSec();
4693  wat::Time in_end_time(end_time);
4694  xml_search_summary->in_end_time.gpsSeconds = in_end_time.GetSec();
4695  xml_search_summary->in_end_time.gpsNanoSeconds = in_end_time.GetNSec();
4696  xml_search_summary->out_end_time.gpsSeconds = in_end_time.GetSec();
4697  xml_search_summary->out_end_time.gpsNanoSeconds = in_end_time.GetNSec();
4698 
4699 }
4700 #endif
4701 
4702 #ifdef _USE_LAL
4703 //______________________________________________________________________________
4704 void
4705 CWB::mdc::FillBurstXML(bool verbose) {
4706 //
4707 // Fill XML LAL to file with event parameters
4708 //
4709 // NOTE : this function can be used only afer CreateBurstXML
4710 //
4711 
4712  if(xml_filename=="") {
4713  cout << "CWB::mdc::FillBurstXML : Error : file XML not declared !!! use CreateBurstXML" << endl;
4714  exit(1);
4715  }
4716 
4717  double NaN = std::numeric_limits<double>::quiet_NaN();
4718  const double deg2rad = TMath::Pi()/180.;
4719 
4720  if(verbose) {
4721  cout << "gps" << "\t\t" << "wf-name" << "\t\t\t" << "theta" << "\t" << "phi" << "\t" << "psi"
4722  << "\t" << "rho" << "\t" << "iota" << "\t" << "hrss" << "\t" << "ID" << "\t" << "id" << endl;
4723  }
4724 
4725  bool error=false;
4726  for(int i=0;i<(int)srcList.size();i++) {
4727  waveform wf = GetWaveform(srcList[i].ID, srcList[i].id);
4728  double hrss = srcList[i].hrss>0 ? srcList[i].hrss : inj_hrss;
4729  if(verbose) {
4730  cout << std::setprecision(13) << srcList[i].gps << "\t" << std::setprecision(6)
4731  << wf.name.Data() << "\t" << srcList[i].theta << "\t"
4732  << srcList[i].phi << "\t" << srcList[i].psi << "\t" << srcList[i].rho << "\t"
4733  << srcList[i].iota << "\t" << hrss << "\t" << srcList[i].ID << "\t" << srcList[i].id << endl;
4734  }
4735 
4736  SimBurst *sim_burst = XLALCreateSimBurst();
4737  if(!sim_burst) {*xml_sim_burst=NULL; return;}
4738 
4739  // fill sim_burst structure
4740  strcpy(sim_burst->waveform, wf.name.Data());
4741 
4742  wat::Time time(srcList[i].gps);
4743  sim_burst->time_geocent_gps.gpsSeconds = time.GetSec();
4744  sim_burst->time_geocent_gps.gpsNanoSeconds = time.GetNSec();
4745 
4746  sim_burst->ra = deg2rad*sm.phi2RA(srcList[i].phi,srcList[i].gps);
4747  sim_burst->dec = TMath::PiOver2()-deg2rad*srcList[i].theta;
4748  sim_burst->psi = deg2rad*srcList[i].psi;
4749  error=false;
4750  sim_burst->frequency = GetPar("frequency",wf.par,error);if(error) sim_burst->frequency=NaN;
4751  error=false;
4752  sim_burst->q = GetPar("Q",wf.par,error); if(error) sim_burst->q=NaN;
4753  error=false;
4754  sim_burst->duration = GetPar("duration",wf.par,error); if(error) sim_burst->duration=NaN;
4755  error=false;
4756  sim_burst->bandwidth = GetPar("bandwidth",wf.par,error);if(error) sim_burst->bandwidth=NaN;
4757  sim_burst->pol_ellipse_angle = 0;
4758  sim_burst->pol_ellipse_e = cos(deg2rad*srcList[i].iota);
4759  sim_burst->hrss = hrss;
4760  sim_burst->amplitude = 0;
4761  sim_burst->egw_over_rsquared = 0;
4762  sim_burst->waveform_number = srcList[i].ID;
4763 
4764  *xml_sim_burst = sim_burst;
4765  xml_sim_burst = &(*xml_sim_burst)->next;
4766  }
4767 
4768 }
4769 #endif
4770 
4771 #ifdef _USE_LAL
4772 //______________________________________________________________________________
4773 void
4774 CWB::mdc::CloseBurstXML() {
4775 //
4776 // Close XML LAL file
4777 //
4778 // NOTE : this function can be used only afer CreateBurstXML
4779 //
4780 
4781  if(xml_filename=="") {
4782  cout << "CWB::mdc::CloseBurstXML : Error : file XML not declared !!! use CreateBurstXML" << endl;
4783  exit(1);
4784  }
4785 
4786  XLALGPSTimeNow(&xml_process->end_time);
4787 
4788  // write xml file (see LAL binj.c)
4789  LIGOLwXMLStream *xml;
4790 
4791  xml = XLALOpenLIGOLwXMLFile(xml_filename.Data());
4792 
4793  /* process table */
4794  if(XLALWriteLIGOLwXMLProcessTable(xml, xml_process_table_head)) {
4795  cout << "CWB::mdc::CloseBurstXML : Error in XLALWriteLIGOLwXMLProcessTable" << endl;
4796  exit(1);
4797  }
4798  /* process params table */
4799  if(XLALWriteLIGOLwXMLProcessParamsTable(xml, xml_process_params_table_head)) {
4800  cout << "CWB::mdc::CloseBurstXML : Error in XLALWriteLIGOLwXMLProcessParamsTable" << endl;
4801  exit(1);
4802  }
4803  /* search summary table */
4804  if(XLALWriteLIGOLwXMLSearchSummaryTable(xml, xml_search_summary_table_head)) {
4805  cout << "CWB::mdc::CloseBurstXML : Error in XLALWriteLIGOLwXMLSearchSummaryTable" << endl;
4806  exit(1);
4807  }
4808  /* time slide table */
4809  if(XLALWriteLIGOLwXMLTimeSlideTable(xml, xml_time_slide_table_head)) {
4810  cout << "CWB::mdc::CloseBurstXML : Error in XLALWriteLIGOLwXMLTimeSlideTable" << endl;
4811  exit(1);
4812  }
4813  /* sim burst table */
4814  if(XLALWriteLIGOLwXMLSimBurstTable(xml, xml_sim_burst_table_head)) {
4815  cout << "CWB::mdc::CloseBurstXML : Error in XLALWriteLIGOLwXMLSimBurstTable" << endl;
4816  exit(1);
4817  }
4818 
4819  XLALCloseLIGOLwXMLFile(xml);
4820 
4821  xml_filename = "";
4822  XLALDestroyProcessTable(xml_process_table_head);
4823  XLALDestroyProcessParamsTable(xml_process_params_table_head);
4824  XLALDestroyTimeSlideTable(xml_time_slide_table_head);
4825  XLALDestroySearchSummaryTable(xml_search_summary_table_head);
4826  XLALDestroySimBurstTable(xml_sim_burst_table_head);
4827 }
4828 #endif
4829 
4830 #ifdef _USE_LAL
4831 //______________________________________________________________________________
4832 TString
4833 CWB::mdc::GetBurstNameLAL(TString options) {
4834 //
4835 // convert LAL Burst options to the name used in mdc class
4836 //
4837 // options : --name Gaussian --duration value
4838 // options : --name SineGaussian --frequency value --q value
4839 // options : --name BTLWNB --frequency value --bandwidth value --duration value
4840 // options : --name StringCusp --frequency value
4841 //
4842 // --decimals value number of decimals used to format the waveform name
4843 // if not defined ; used default format
4844 //
4845 
4846  TString wfname = "";
4847 
4848  CWB::Toolbox TB;
4849  TString name = TB.getParameter(options,"--name");
4850  bool error=false;
4851  if(name=="") error=true;
4852  if((name=="Gaussian")&&(name!="SineGaussian")&&(name=="BTLWNB")) error=true;
4853  if(error) {
4854  cout << "CWB::mdc::GetBurstNameLAL : Error - Not valid --name option" << endl;
4855  cout << "available --name options are : Gaussian/SineGaussian/BTLWNB" << endl;
4856  return "";
4857  }
4858 
4859  // get number of decimals to be used to format the waveform name
4860  int decimals = -1;
4861  TString sdecimals = TB.getParameter(options,"--decimals");
4862  if(sdecimals.IsDigit()) decimals = sdecimals.Atoi();
4863 
4864  if(name=="Gaussian") {
4865 
4866  int d1 = decimals==-1 ? 1 : decimals;
4867 
4868  float duration;
4869  TString sduration = TB.getParameter(options,"--duration");
4870  if(sduration.IsFloat()) {
4871  duration = sduration.Atof();
4872  } else {
4873  cout << "CWB::mdc::GetBurstNameLAL : Error : --duration not defined or not a number!!! " << endl;
4874  return "";
4875  }
4876 
4877  wfname = TString::Format("LAL_GA%.*f",d1,1000.*duration);
4878  wfname.ReplaceAll(".","d");
4879  return wfname;
4880 
4881  } else if(name=="SineGaussian") {
4882 
4883  int d1 = decimals==-1 ? 0 : decimals;
4884  int d2 = decimals==-1 ? 1 : decimals;
4885 
4886  float frequency;
4887  TString sfrequency = TB.getParameter(options,"--frequency");
4888  if(sfrequency.IsFloat()) {
4889  frequency = sfrequency.Atof();
4890  } else {
4891  cout << "CWB::mdc::GetBurstNameLAL : Error : --frequency not defined or not a number!!! " << endl;
4892  return "";
4893  }
4894 
4895  float q;
4896  TString sq = TB.getParameter(options,"--q");
4897  if(sq.IsFloat()) {
4898  q = sq.Atof();
4899  } else {
4900  cout << "CWB::mdc::GetBurstNameLAL : Error : --q not defined or not a number!!! " << endl;
4901  return "";
4902  }
4903 
4904  wfname = TString::Format("LAL_SGE%.*fQ%.*f",d1,frequency,d2,q);
4905  wfname.ReplaceAll(".","d");
4906  if(decimals==-1) wfname.ReplaceAll("d0","");
4907  return wfname;
4908 
4909  } else if(name=="BTLWNB") {
4910 
4911  int d1 = decimals==-1 ? 0 : decimals;
4912  int d2 = decimals==-1 ? 0 : decimals;
4913  int d3 = decimals==-1 ? 3 : decimals;
4914 
4915  float frequency;
4916  TString sfrequency = TB.getParameter(options,"--frequency");
4917  if(sfrequency.IsFloat()) {
4918  frequency = sfrequency.Atof();
4919  } else {
4920  cout << "CWB::mdc::GetBurstNameLAL : Error : --frequency not defined or not a number!!! " << endl;
4921  return "";
4922  }
4923 
4924  float bandwidth;
4925  TString sbandwidth = TB.getParameter(options,"--bandwidth");
4926  if(sbandwidth.IsFloat()) {
4927  bandwidth = sbandwidth.Atof();
4928  } else {
4929  cout << "CWB::mdc::GetBurstNameLAL : Error : --bandwidth not defined or not a number!!! " << endl;
4930  return "";
4931  }
4932 
4933  float duration;
4934  TString sduration = TB.getParameter(options,"--duration");
4935  if(sduration.IsFloat()) {
4936  duration = sduration.Atof();
4937  } else {
4938  cout << "CWB::mdc::GetBurstNameLAL : Error : --duration not defined or not a number!!! " << endl;
4939  return "";
4940  }
4941 
4942  wfname = TString::Format("LAL_WNB%.*f_%.*f_%.*f",d1,frequency,d2,bandwidth,d3,duration);
4943  wfname.ReplaceAll(".","d");
4944  return wfname;
4945 
4946  } else if(name=="StringCusp") {
4947 
4948  int d1 = decimals==-1 ? 1 : decimals;
4949 
4950  float frequency;
4951  TString sfrequency = TB.getParameter(options,"--frequency");
4952  if(sfrequency.IsFloat()) {
4953  frequency = sfrequency.Atof();
4954  } else {
4955  cout << "CWB::mdc::GetBurstNameLAL : Error : --frequency not defined or not a number!!! " << endl;
4956  return "";
4957  }
4958 
4959  wfname = TString::Format("LAL_SC%.*f",d1,1000.*frequency);
4960  wfname.ReplaceAll(".","d");
4961  return wfname;
4962 
4963  }
4964 
4965  return wfname;
4966 }
4967 #endif
4968 
4969 //______________________________________________________________________________
4970 double
4972 //
4973 // convert the LAL eccentricity used to generate SineGaussian waveform into the
4974 // equivalent iota value
4975 //
4976 // e : eccentricity [0:1]
4977 //
4978 // return the cos(iota) value
4979 //
4980 // CWB uses the following formula :
4981 // h_+ = 0.5*(1+cos(iota)^2) * A(t) cos(Phi(t))
4982 // h_x = cos(iota) * A(t) sin(Phi(t))
4983 // while LAL uses :
4984 // h_+ = A * A(t) cos(Phi(t))
4985 // h_x = B * A(t) sin(Phi(t))
4986 // where :
4987 // A = 1/sqrt(2-E*E) ; B = A*sqrt(1-E*E)
4988 // and E is the eccentricity
4989 // it follows that A*A+B*B=1
4990 //
4991 
4992  if(e<0 || e>1) {
4993  cout << "CWB::mdc::e2cosi - Error : eccentricity must be defined in the range [0:1] " << endl;
4995  }
4996 
4997  double E = e<0.9999999999 ? e : 0.9999999999; // avoid x1,x2=nan
4998  double A = 1./sqrt(2-E*E);
4999  double B = A*sqrt(1-E*E);
5000  double x1 = (A+sqrt(A*A-B*B))/(B*B);
5001  double x2 = (A-sqrt(A*A-B*B))/(B*B);
5002  double x = fabs(x1*B)>1 ? x2 : x1;
5003 
5004  double cosi = -x*B;
5005 
5006  return cosi;
5007 }
5008 
5009 //______________________________________________________________________________
5010 double
5011 CWB::mdc::cosi2e(double cosi) {
5012 //
5013 // convert cos(iota) into the equivalent LAL eccentricity used
5014 // to generate SineGaussian waveform
5015 //
5016 // cosi : cos(iota) [-1:1]
5017 //
5018 // return the eccentricity value
5019 //
5020 
5021  if(fabs(cosi)>1) {
5022  cout << "CWB::mdc::cosi2e - Error : cosi must be defined in the range [-1:1] " << endl;
5024  }
5025 
5026  double A = (1+cosi*cosi)/2;
5027  double B = -cosi;
5028 
5029  double C = sqrt(A*A+B*B);
5030  A/=C; B/=C;
5031 
5032  double E = sqrt(1-(B*B)/(A*A));
5033 
5034  return E;
5035 }
5036 
5037 //______________________________________________________________________________
5038 void
5040 //
5041 // Dump log to file
5042 //
5043 //
5044 // Input: fName - name of output file
5045 // label - label of file
5046 // append - false/true -> create new file/append to the file
5047 //
5048 
5049  if(fName.Contains(".root")) {
5050 
5051  if(inj==NULL) {
5052  cout << "CWB::mdc::DumpLog - Error : dump to root needs injection object " << endl;
5053  exit(1);
5054  }
5055 
5056  TFile froot(fName,"RECREATE");
5057  if(label.Sizeof()>1) this->Write(label); else this->Write("WaveMDC");
5058  inj_tree->Write();
5059  cout << "CWB::mdc::DumpLog - inj entries written : " << inj_tree->GetEntries() << endl;
5060  froot.Write();
5061  froot.Close();
5062 
5063  } else
5064  if(fName.Contains(".txt")) {
5065 
5066  // log string
5067  TString logString = "";
5068  for(int i=0;i<(int)mdcList.size();i++) logString = logString+mdcList[i]+"\n";
5069 
5070  // write log file
5071  ofstream out;
5072  if(append) out.open(fName.Data(),ios::app);
5073  else out.open(fName.Data(),ios::out);
5074  if (!out.good()) {cout << "CWB::mdc::DumpLog - Error Opening File : " << fName.Data() << endl;exit(1);}
5075  out.precision(14);
5076  for(int i=0;i<(int)mdcList.size();i++) out << mdcList[i] << endl;
5077  out.close();
5078 
5079  } else
5080  if(fName.Contains(".lst")) {
5081 
5082  // write source list file
5083  ofstream out;
5084  if(append) out.open(fName.Data(),ios::app);
5085  else out.open(fName.Data(),ios::out);
5086  if (!out.good()) {cout << "CWB::mdc::DumpLog - Error Opening File : " << fName.Data() << endl;exit(1);}
5087  out.precision(14);
5088  out << "#gps\t\t" << "name\t\t" << "theta\t" << "phi\t" << "psi\t"
5089  << "rho\t" << "iota\t" << "hrss\t" << "ID\t" << "id\t" << endl;
5090  for(int i=0;i<(int)srcList.size();i++) {
5091  waveform wf = GetWaveform(srcList[i].ID, srcList[i].id);
5092  double hrss = srcList[i].hrss>0 ? srcList[i].hrss : inj_hrss;
5093  out << srcList[i].gps << "\t" << wf.name.Data() << "\t" << srcList[i].theta << "\t"
5094  << srcList[i].phi << "\t" << srcList[i].psi << "\t" << srcList[i].rho << "\t"
5095  << srcList[i].iota << "\t" << hrss << "\t" << srcList[i].ID << "\t" << srcList[i].id << endl;
5096  }
5097  out.close();
5098 
5099  } else {
5100  cout << "CWB::mdc::DumpLog - Error : file extention must be .root" << endl;
5101  exit(1);
5102  }
5103 
5104  return;
5105 }
5106 
5107 #ifdef _USE_LAL
5108 //______________________________________________________________________________
5109 TString
5110 CWB::mdc::GetInspiral(wavearray<double>& x, TString ifo) {
5111 //
5112 // Get inspiral mdc data of the detector = ifo
5113 //
5114 //
5115 // Input: x - the input start/stop gps time are obtained from the wavearray values
5116 // start = x.start(); stop = x.start()+x.size()/x.rate()
5117 // ifo - name of the detector defined in the network
5118 //
5119 // Output: x - x.data contains the mdc data
5120 //
5121 // Return: log - ascii string with mdc parameters
5122 //
5123 
5124  if(net==NULL) {
5125  cout << "CWB::mdc::GetInspiral - Error : Dummy method : network is not initialized " << endl;
5126  exit(1);
5127  }
5128  if(x.rate()!=MDC_SAMPLE_RATE) {
5129  cout << "CWB::mdc::GetInspiral - Error : x.rate() != " << MDC_SAMPLE_RATE << endl;
5130  exit(1);
5131  }
5132 
5133  x=0.;
5134 
5135  // start/end times
5136  int gpsStartSec = x.start();
5137  int gpsEndSec = gpsStartSec + x.size()/x.rate();
5138 
5139  // injections
5140  INT4 numInjections = 0;
5141  SimInspiralTable *injections = NULL;
5142  TString injectionFile = GenInspiralXML(0., 0., false);
5143 
5144  // set default debug level
5145  lal_errhandler = LAL_ERR_EXIT;
5146 
5147  XLALSetSilentErrorHandler();
5148 
5149  // read the injections
5150  numInjections = SimInspiralTableFromLIGOLw(&injections, injectionFile.Data(), gpsStartSec, gpsEndSec);
5151 
5152  if ( numInjections == 0 ) {
5153  fprintf( stderr, "CWB::mdc::GetInspiral - Warning : No injections in specified time\n");
5154  return "";
5155  } else {
5156  fprintf( stdout, "CWB::mdc::GetInspiral : Read %d injection(s) from the file '%s'\n",
5157  numInjections, injectionFile.Data() );
5158  }
5159 
5160  // reset lists
5161  mdcList.clear();
5162  mdcType.clear();
5163  mdcTime.clear();
5164 
5165  fprintf(stdout, "CWB::mdc::GetInspiral : Generating injection for: %s",ifo.Data());
5166 
5167  FindChirpInjectSignals(x, injections, ifo);
5168 
5169  fprintf(stdout, "\n");
5170 
5171  // loop over injections
5172  SimInspiralTable *thisInj = NULL;
5173  for (thisInj = injections; thisInj; thisInj = thisInj->next)
5174  {
5175  // add waveform log string to mdc log string
5176  TString log = GetInspiralLog(inspName,x.start(),thisInj);
5177  //cout << "LOG : " << log.Data() << endl;
5178 
5179  // add infos to lists
5180  mdcList.push_back(log.Data());
5181  double gps = thisInj->geocent_end_time.gpsSeconds+1.e-9*thisInj->geocent_end_time.gpsNanoSeconds;
5182  mdcTime.push_back(gps);
5183  }
5184  mdcType.push_back(inspName.Data());
5185 
5186  if(inspXML=="") gSystem->Exec(TString("rm ")+injectionFile); // remove injectionFile file
5187 
5188  while ( injections ) {
5189  SimInspiralTable *thisInj = NULL;
5190  thisInj = injections;
5191  injections = injections->next;
5192  LALFree( thisInj );
5193  }
5194 
5195  LALCheckMemoryLeaks();
5196  return "";
5197 }
5198 #endif
5199 
5200 #ifdef _USE_LAL
5201 //______________________________________________________________________________
5202 TString
5203 CWB::mdc::GetInspiralLog(TString inspName, double FrameGPS, SimInspiralTable *thisInj) {
5204 //
5205 // Get Log string for inspiral mdc
5206 //
5207 // Input: inspName - name of inspiral
5208 // FrameGPS - Frame gps time
5209 // thisInj - List of waveform parameters
5210 //
5211 
5212  if(net==NULL) {
5213  cout << "CWB::mdc::GetInspiralLog - Error : Dummy method : network is not initialized " << endl;
5214  exit(1);
5215  }
5216 
5217  // network ifos
5218  INT4 nIFO=net->ifoListSize();
5219 
5220  // declare variables
5221  float f_isco;
5222  REAL8 gmst;
5223  REAL8 longitude;
5224  char output[2048]="";
5225 
5226  // GravEn_SimID
5227  if (strncmp(thisInj->waveform, "NumRel", LIGOMETA_WAVEFORM_MAX) == 0)
5228  sprintf(output, "%s ", thisInj->numrel_data);
5229  else
5230  sprintf(output, "file ");
5231  // GravEn_Ampl
5232  sprintf(output, "%s 1 ",output);
5233  // StartSamp1
5234  sprintf(output, "%s 0 ",output);
5235  // StartSamp2
5236  sprintf(output, "%s 0 ",output);
5237  // Internal_x
5238  sprintf(output, "%s %g ",output, cos(thisInj->inclination));
5239  // Internal_phi
5240  sprintf(output, "%s %g ",output, thisInj->coa_phase);
5241  // External_x
5242  sprintf(output, "%s %g ",output, cos(thisInj->latitude - LAL_PI_2));
5243  // External_phi
5244  gmst = fmod(XLALGreenwichMeanSiderealTime(&thisInj->geocent_end_time), LAL_TWOPI);
5245  longitude = fmod(thisInj->longitude - gmst, LAL_TWOPI);
5246  if (longitude < 0)
5247  longitude += LAL_TWOPI;
5248  sprintf(output, "%s %g ",output, longitude);
5249  // External_psi
5250  sprintf(output, "%s %g ",output, thisInj->polarization);
5251  // FrameGPS
5252  sprintf(output, "%s %d ",output, int(FrameGPS));
5253  // SimStartGPS
5254  sprintf(output, "%s %d.%09d ",output, thisInj->geocent_end_time.gpsSeconds, thisInj->geocent_end_time.gpsNanoSeconds);
5255  // SimName
5256  sprintf(output, "%s %s ",output, inspName.Data());
5257  // SimHpHp
5258  sprintf(output, "%s 0 ",output);
5259  // SimHcHc
5260  sprintf(output, "%s 0 ",output);
5261  // SimHpHc
5262  sprintf(output, "%s 0 ",output);
5263 
5264  // IFO GPS F_+ F_x eff_dist
5265  for(int n=0;n<nIFO;n++) {
5266  TString ifo;
5267  double latitude,longitude,polarization;
5268  double theta,phi,psi;
5269  double rad2deg = 180./TMath::Pi();
5270 
5271  ifo = net->ifoName[n];
5272  latitude=thisInj->latitude;
5273  longitude=thisInj->longitude;
5274  polarization=thisInj->polarization;
5275  theta = LAL_PI_2-latitude; // LAL -> CWB
5276  theta*=rad2deg;
5277  longitude = fmod(longitude - gmst, LAL_TWOPI);
5278  if (longitude < 0) longitude += LAL_TWOPI;
5279  phi = longitude > 0 ? longitude : 2*TMath::Pi()+longitude;
5280  phi*= rad2deg;
5281  psi = polarization*rad2deg;
5282 
5283  double fp = GetAntennaPattern(ifo, phi, theta, psi, "hp");
5284  double fc = GetAntennaPattern(ifo, phi, theta, psi, "hx");
5285 
5286  // compute the gw delay between ifo and earth center
5287  double d2r = TMath::Pi()/180.;
5288 
5289  detector* D = net->getifo(n);
5290  detectorParams dP = D->getDetectorParams(); // get ifo parameters
5291  double D_theta = dP.latitude;
5292  double D_phi = dP.longitude;
5293  double D_R = sqrt(D->Rv[0]*D->Rv[0]+D->Rv[1]*D->Rv[1]+D->Rv[2]*D->Rv[2]); // earth radius
5294  GeographicToCwb(D_phi,D_theta,D_phi,D_theta);
5295  TVector3 dV(1,0,0); // set vector to ifo direction
5296  dV.SetTheta(D_theta*d2r);
5297  dV.SetPhi(D_phi*d2r);
5298 
5299  TVector3 sV(1,0,0); // set vector to source direction
5300  sV.SetTheta(theta*d2r);
5301  sV.SetPhi(phi*d2r);
5302 
5303  double cos_dVdS = dV.Dot(sV); // get cos between ifo and source direction
5304  double D_geocent_delay=-cos_dVdS*D_R/speedlight; // gw time delay ifo-geo_center
5305  int tShift_sec = int(fabs(D_geocent_delay));
5306  int tShift_nsec = int(1e9*(fabs(D_geocent_delay)-tShift_sec));
5307 
5308  // add gw time delay ifo geo_center to geocent_end_time
5309  int end_time_gpsSeconds = thisInj->geocent_end_time.gpsSeconds;
5310  int end_time_gpsNanoSeconds = thisInj->geocent_end_time.gpsNanoSeconds;
5311  if(D_geocent_delay>=0) {
5312  end_time_gpsSeconds += tShift_sec;
5313  end_time_gpsNanoSeconds += tShift_nsec;
5314  if ( end_time_gpsNanoSeconds >= 1000000000 ) {
5315  end_time_gpsSeconds += INT_4S( end_time_gpsNanoSeconds / 1000000000 );
5316  end_time_gpsNanoSeconds = end_time_gpsNanoSeconds % 1000000000;
5317  }
5318  } else {
5319  end_time_gpsSeconds -= tShift_sec;
5320  if ( end_time_gpsNanoSeconds >= tShift_nsec ) {
5321  end_time_gpsNanoSeconds -= tShift_nsec;
5322  } else {
5323  --end_time_gpsSeconds;
5324  end_time_gpsNanoSeconds += 1000000000 - tShift_nsec;
5325  }
5326  }
5327 
5328  // compute effective distance
5329  double cosiota = cos(thisInj->inclination);
5330  double eff_dist = thisInj->distance / sqrt(pow(fp*(1.+pow(cosiota,2)),2)/4.+pow(fc*cosiota,2));
5331 
5332  sprintf(output, "%s %s %d.%09d %e %e %g ",output, ifo.Data(), end_time_gpsSeconds,
5333  end_time_gpsNanoSeconds, fp, fc, eff_dist);
5334  }
5335 
5336  // calculate frequency of innermost stable circulat orbit
5337  // taken from: gr-qc/0612100
5338  f_isco = 205 * (20 / (thisInj->mass1 + thisInj->mass2));
5339 
5340  // numerical relativity specific parameters
5341  sprintf(output, "%s insp ",output);
5342  sprintf(output, "%s distance %g ",output, thisInj->distance);
5343  sprintf(output, "%s mass1 %g ",output, thisInj->mass1);
5344  sprintf(output, "%s mass2 %g ",output, thisInj->mass2);
5345  sprintf(output, "%s mchirp %g ",output, thisInj->mchirp);
5346  sprintf(output, "%s spin1 %g %g %g ",output, thisInj->spin1x, thisInj->spin1y, thisInj->spin1z);
5347  sprintf(output, "%s spin2 %g %g %g ",output, thisInj->spin2x, thisInj->spin2y, thisInj->spin2z);
5348  sprintf(output, "%s freq %g %g\n",output, thisInj->f_lower, f_isco);
5349 
5350  return output;
5351 }
5352 #endif
5353 
5354 #ifdef _USE_LAL
5355 //______________________________________________________________________________
5356 void
5358 //
5359 // Set inspiral mdc parameters
5360 //
5361 // Input: inspName - name of inspiral
5362 // inspOptions - list of options (see lalapps_inspinj options)
5363 // to dump all the available options do: 'lalapps_inspinj --help'
5364 // for any details refer to the LAL documentation.
5365 // There are some special options added only for the mdc class
5366 // --xml "file.xml" : read mdc injection's parameters from xml file
5367 // --output "file.xml" : write mdc injection's parameters to xml file
5368 // --dir "tmp dir" : directory used to store the temporary xml file,
5369 // default=/tmp
5370 //
5371 // Note : The LAL function used to generate the waveforms is defined in LALInspiralWave.c
5372 // for LAL version < 6.13.2 it is : XLALSimInspiralChooseWaveformFromSimInspiral
5373 // for LAL version >= 6.13.2 it is : XLALInspiralTDWaveformFromSimInspiral
5374 //
5375 // If --waveform is used together with the --xml option the waveform name
5376 // in the xml file is overwritten with the waveform user name
5377 
5378 // const int nOpt = 12;
5379 // const int nOpt = 10;
5380  const int nOpt = 7;
5381  TString option[nOpt] = {"--help","--verbose","--user-tag","--write-compress",
5382  "--ipn-gps-time","--t-distr",
5383  "--write-sim-ring"};
5384 // "--gps-start-time","--gps-end-time","--ipn-gps-time","--t-distr",
5385 // "--time-step","--time-interval","--write-sim-ring"};
5386 
5387  if(inspName.Sizeof()<=1) {
5388  cout << "CWB::mdc::SetInspiral - Error : inspName not declared" << endl;
5389  exit(1);
5390  }
5391 
5392  for(int i=0;i<nOpt;i++) {
5393  if(inspOptions.Contains(option[i])) {
5394  cout << "CWB::mdc::SetInspiral - Error : option " << option[i].Data()
5395  << " not allowed in CWB" << endl;
5396  exit(1);
5397  }
5398  }
5399 
5400  // approximant is substitute with waveform
5401  // approximant is maintained only for back compatibility
5402  inspOptions.ReplaceAll("--approximant","--waveform");
5403 
5404  TObjArray* token = inspOptions.Tokenize(TString(" "));
5405 
5406  // check options waveform and xml
5407  int bxml=0;
5408  int bwaveform=0;
5409  for(int i=0;i<token->GetEntries();i++) {
5410  TObjString* otoken = (TObjString*)token->At(i);
5411  TString stoken = otoken->GetString();
5412  if(stoken=="--xml") bxml++;
5413  if(stoken=="--waveform") bwaveform++;
5414  }
5415  if(!bxml) { // xlm is build by mdc cwb
5416  if(bwaveform!=1) {
5417  cout << "CWB::mdc::SetInspiral - Error : ";
5418  if(bwaveform>1) cout << "imultiple declaration of waveform option" << endl;
5419  if(!bwaveform) cout << "missing waveform option" << endl;
5420  exit(1);
5421  }
5422  }
5423 
5424  TString inspDump="";
5425  TString inspOutput="";
5426 
5427  // exctract xml, dir, time-step & check waveform
5428  cout << "CWB::mdc::SetInspiral - Read options ..." << endl;
5429  for(int i=0;i<token->GetEntries();i++) {
5430  TObjString* otoken = (TObjString*)token->At(i);
5431  TString stoken = otoken->GetString();
5432  if(stoken=="--xml") {
5433  otoken = (TObjString*)token->At(i+1);
5434  stoken = otoken->GetString();
5435  cout << "--xml = " << stoken.Data() << endl;
5436  CWB::Toolbox TB;
5437  TB.checkFile(stoken.Data());
5438  this->inspXML=stoken;
5439  }
5440  if(stoken=="--dir") {
5441  // xml temporary dir
5442  otoken = (TObjString*)token->At(i+1);
5443  stoken = otoken->GetString();
5444  cout << "--dir = " << stoken.Data() << endl;
5445  CWB::Toolbox TB;
5446  TB.checkFile(stoken.Data());
5447  this->inspDIR=stoken;
5448  // remove dir option from inspOptions
5449  inspOptions.ReplaceAll("--dir","");
5450  inspOptions.ReplaceAll(stoken,"");
5451  }
5452  if(stoken=="--output") {
5453  otoken = (TObjString*)token->At(i+1);
5454  stoken = otoken->GetString();
5455  cout << "--output = " << stoken.Data() << endl;
5456  inspOutput=stoken;
5457  // remove output option from inspOptions
5458  inspOptions.ReplaceAll("--output","");
5459  inspOptions.ReplaceAll(stoken,"");
5460  }
5461  if(stoken=="--dump") {
5462  otoken = (TObjString*)token->At(i+1);
5463  stoken = otoken->GetString();
5464  cout << "--dump = " << stoken.Data() << endl;
5465  inspDump=stoken;
5466  // remove dump option from inspOptions
5467  inspOptions.ReplaceAll("--dump","");
5468  inspOptions.ReplaceAll(stoken,"");
5469  }
5470  if(stoken=="--time-step") {
5471  otoken = (TObjString*)token->At(i+1);
5472  stoken = otoken->GetString();
5473  cout << "--time-step = " << stoken.Data() << endl;
5474  inj_rate = 1./stoken.Atof();
5475  }
5476  if(stoken=="--time-interval") {
5477  otoken = (TObjString*)token->At(i+1);
5478  stoken = otoken->GetString();
5479  cout << "--time-interval = " << stoken.Data() << endl;
5480  inj_jitter = stoken.Atof();
5481  }
5482  if(stoken=="--waveform") {
5483  otoken = (TObjString*)token->At(i+1);
5484  stoken = otoken->GetString();
5485  cout << "--waveform = " << stoken.Data() << endl;
5486  this->waveName=stoken;
5487  if(XLALGetApproximantFromString(stoken.Data()) == XLAL_FAILURE) {
5488  cout << "CWB::mdc::SetInspiral - waveform : \'" << stoken.Data()
5489  << "\' not allowed !!!" << endl;
5490  exit(1);
5491  }
5492  }
5493  }
5494 
5495  delete token;
5496 
5497  if(this->inspDIR=="") {
5498  cout << endl;
5499  cout << "CWB::mdc::SetInspiral - Error : temporary dir not defined !!! Use --dir option" << endl;
5500  cout << endl;
5501  cout << " if this option is called from a config plugin add the following line to the inspOptions : " << endl;
5502  cout << " inspOptions+= \"--dir \"+TString(cfg->tmp_dir)+\" " << endl;
5503  cout << " before to call : 'MDC.SetInspiral(inspOptions);'" << endl << endl;
5504  cout << " and these lines to the plugin : " << endl;
5505  cout << " // export config object to the config plugin" << endl;
5506  cout << " sprintf(cmd,\"CWB::config* cfg = (CWB::config*)%p;\",cfg);" << endl;
5507  cout << " gROOT->ProcessLine(cmd);" << endl;
5508  cout << " before to execute the config plugin : 'cfg->configPlugin.Exec(NULL,&error);'" << endl;
5509  cout << endl;
5510  exit(1);
5511  }
5512 
5513  this->inspName=inspName;
5514  this->inspOptions=inspOptions;
5515 
5516  // write xml file & exit
5517  if(inspDump!="") {
5518  TString injectionFile = GenInspiralXML(0, 0, false);
5519  cout << "Save inspiral injection file to " << inspDump.Data() << endl;
5520  if(inspXML=="") gSystem->Exec("mv "+injectionFile+" "+inspDump);
5521  else gSystem->Exec("cp "+injectionFile+" "+inspDump);
5522  exit(0);
5523  }
5524 
5525  // write xml file
5526  if(inspOutput!="") {
5527  // Check if file exist
5528  Long_t id,size=0,flags,mt;
5529  int estat = gSystem->GetPathInfo(inspOutput.Data(),&id,&size,&flags,&mt);
5530  if (estat!=0) { // skip if file already exist
5531  TString injectionFile = GenInspiralXML(0, 0, false);
5532  cout << "Save inspiral injection file to " << inspOutput.Data() << endl;
5533  gSystem->Exec("cp "+injectionFile+" "+inspOutput);
5534  }
5535  }
5536 
5537  // dummy exec to check if parameters are correct
5538  if(inspXML=="") GenInspiralXML(900000000, 900000000, true);
5539 
5540  return;
5541 }
5542 #endif
5543 
5544 #ifdef _USE_LAL
5545 //______________________________________________________________________________
5546 TString
5547 CWB::mdc::GetInspiralOption(TString inspOption) {
5548 //
5549 // Get inspiral mdc parameters
5550 //
5551 // Input: inspOption - name of inspiral xml option
5552 //
5553 
5554  if(inspOptions=="") return ""; // inspOptions not defined
5555 
5556  if(inspXML!="") { // xml is provided by user
5557 
5558  // read XML
5559  ifstream in;
5560  in.open(inspXML.Data(),ios::in);
5561  if (!in.good()) {cout << "CWB::mdc::GetInspiralOption - Error Opening xml File : "
5562  << inspXML.Data() << endl;gSystem->Exit(1);}
5563 
5564  char str[2048];
5565  while(true) {
5566  in.getline(str,2048);
5567  if (!in.good()) break;
5568  if(TString(str).Contains("inspinj")&&TString(str).Contains(inspOption)) {
5569  TObjArray* token = TString(str).Tokenize(TString(","));
5570  if(token->GetEntries()!=5) {cout << "CWB::mdc::GetInspiralOption - bad line format : "
5571  << str << endl;gSystem->Exit(1);}
5572  TObjString* otoken = (TObjString*)token->At(4);
5573  TString stoken = otoken->GetString();
5574  stoken.ReplaceAll("\"","");
5575  delete token;
5576  return stoken; // return token
5577  }
5578  }
5579 
5580  in.close();
5581  } else { // inspOptions provided by the user
5582 
5583  TObjArray* token = inspOptions.Tokenize(TString(" "));
5584  for(int i=0;i<token->GetEntries();i++) {
5585  TObjString* otoken = (TObjString*)token->At(i);
5586  TString stoken = otoken->GetString();
5587  if(stoken.Contains(inspOption)) {
5588  otoken = (TObjString*)token->At(i+1);
5589  stoken = otoken->GetString();
5590  stoken.ReplaceAll("\"","");
5591  return stoken;
5592  }
5593  }
5594  delete token;
5595  }
5596 
5597  return "";
5598 }
5599 #endif
5600 
5601 #ifdef _USE_LAL
5602 //______________________________________________________________________________
5603 TString
5604 CWB::mdc::GenInspiralXML(int gps_start_time, int gps_end_time, bool rmFile) {
5605 //
5606 // Get XML inspiral mdc parameters
5607 //
5608 // Input: gps_start_time - start time
5609 // gps_end_time - stop time
5610 // rmFile - remove temporary file
5611 //
5612 // Return XML string
5613 //
5614 
5615  if(inspXML!="") return inspXML; // xml is provided by user
5616 
5617  TString lalinspinj_exec;
5618  if(gSystem->Getenv("LALINSPINJ_EXEC")==NULL) {
5619  cout << "CWB::mdc::GenInspiralXML - Error : environment LALINSPINJ_EXEC is not defined!!!" << endl;exit(1);
5620  } else {
5621  lalinspinj_exec=TString(gSystem->Getenv("LALINSPINJ_EXEC"));
5622  }
5623 
5624  // test if command is well done (dummy exec)
5625  TString ofName = GetTemporaryFileName("inspiral","xml",inspDIR,true);
5626 
5627  TString cmdOptions = inspOptions;
5628  cmdOptions += " --output "+ofName;
5629  if(gps_start_time!=0) {
5630  cmdOptions += " --gps-start-time ";
5631  cmdOptions += gps_start_time;
5632  }
5633  if(gps_end_time!=0) {
5634  cmdOptions += " --gps-end-time ";
5635  cmdOptions += gps_end_time;
5636  }
5637 
5638  char cmd[1024];
5639  sprintf(cmd,"%s %s",lalinspinj_exec.Data(),cmdOptions.Data());
5640  cout << cmd << endl;
5641  int error = gSystem->Exec(cmd);
5642  if(rmFile) gSystem->Exec(TString("rm ")+ofName); // remove temporary file
5643 
5644  if(error) {
5645  cout << endl;
5646  char help[1024];
5647  sprintf(help,"%s --help",lalinspinj_exec.Data());
5648  gSystem->Exec(help);
5649  cout << endl;
5650  cout << "CWB::mdc::GenInspiralXML - Error in exececuting :" << endl << endl;
5651  cout << cmd << endl << endl;
5652  exit(1);
5653  }
5654 
5655  return ofName;
5656 }
5657 #endif
5658 
5659 //______________________________________________________________________________
5660 TString
5662 //
5663 // Get a temporary file name
5664 //
5665 // Input: tag - tag string
5666 // ext - file extension tag
5667 // mkdir - if true create temporary dir
5668 //
5669 
5670 
5671  gRandom->SetSeed(0);
5672  int rnID = int(gRandom->Rndm(13)*1.e9);
5673 
5674  if(dir=="/tmp") { // use /tmp dir
5675  // create temporary dir
5676  UserGroup_t* uinfo = gSystem->GetUserInfo();
5677  TString uname = uinfo->fUser;
5678  dir="/tmp/"+uname;
5679  int error=0;
5680  if(mkdir) error=gSystem->Exec(TString("mkdir -p ")+dir);
5681  if(error) {
5682  cout << endl;
5683  cout << "CWB::mdc::GetTemporaryFileName - Error in exececuting :" << endl << endl;
5684  cout << TString(TString("mkdir -p ")+dir) << endl << endl;
5685  exit(1);
5686  }
5687  }
5688 
5689  char fName[256];
5690  sprintf(fName,"%s/%s_%d.%s",dir.Data(),tag.Data(),rnID,ext.Data());
5691 
5692  return TString(fName);
5693 }
5694 
5695 #ifdef _USE_LAL
5696 //______________________________________________________________________________
5697 void
5698 CWB::mdc::FindChirpInjectSignals(wavearray<double>& w, SimInspiralTable *injections, TString ifo) {
5699 //
5700 // Get inspiral for user define detectors
5701 //
5702 //
5703 // Input: injections - structure which contains the parameters of waveforms
5704 //
5705 // Output: w - wavearray which contains the waveform data
5706 //
5707 
5708  double rad2deg = 180./TMath::Pi();
5709  double deg2rad = TMath::Pi()/180.;
5710  double fp,fx;
5711  double latitude,longitude,polarization;
5712  double theta,phi,psi;
5713  double gmst;
5714 
5716  w=0; z=w;
5717 
5718  REAL8TimeSeries *hp=NULL;
5719  REAL8TimeSeries *hx=NULL;
5720 
5721  //TString ifoRef=net->ifoName[0];
5722 
5723  // get detector location
5724  int nIFO = net ? net->ifoListSize() : 0;
5725  int ifoId=-1;
5726  detector* pD=NULL;
5727  for(int n=0; n<nIFO; n++) if(ifo.CompareTo(net->ifoName[n])==0) ifoId=n;
5728  if(ifoId>=0) pD = net->getifo(ifoId);
5729  else pD = new detector(const_cast<char*>(ifo.Data()));
5730  detectorParams dP = pD->getDetectorParams();
5731  REAL8 location[3] = {pD->Rv[0],pD->Rv[1],pD->Rv[2]};
5732  if(ifoId<0) delete pD;
5733 
5734  // loop over injections
5735  SimInspiralTable *thisInj = NULL;
5736  for (thisInj = injections; thisInj; thisInj = thisInj->next)
5737  {
5738  REAL8 deltaT = 1./w.rate();
5739  if(waveName!="") strcpy(thisInj->waveform,waveName.Data());
5740 
5741  // get approximant ( see LALSimInspiral.c )
5742  Approximant approximant = (Approximant)XLALSimInspiralGetApproximantFromString(thisInj->waveform);
5743 /*
5744  cout << endl << endl;
5745  cout << "---------------------------------------------------------------------------------" << endl;
5746  cout << "CWB::mdc::FindChirpInjectSignals" << endl;
5747  cout << "---------------------------------------------------------------------------------" << endl;
5748  cout << "thisSim->numrel_data : " << thisInj->numrel_data << endl;
5749  cout << "thisSim->waveform : " << thisInj->waveform << endl;
5750  cout << "thisSim->amp_order : " << thisInj->amp_order << endl;
5751  cout << "APPROXIMANT : " << approximant << " (NR_hdf5=" << NR_hdf5 << ")" << endl;
5752  cout << endl;
5753 */
5754  if(approximant==NR_hdf5) {
5755 
5756 #if LAL_VERSION_MAJOR > 6 || (LAL_VERSION_MAJOR == 6 && \
5757  (LAL_VERSION_MINOR > 18 || (LAL_VERSION_MINOR == 18 && \
5758  (LAL_VERSION_MICRO > 0 || (LAL_VERSION_MICRO == 0 && LAL_VERSION_DEVEL >= 1))))) // LAL_VERSION >= 6.18.0.1
5759 
5760  // see LALInferenceReadData.c
5761  LALDict *LALpars=XLALCreateDict();
5762  XLALSimInspiralWaveformParamsInsertNumRelData(LALpars, thisInj->numrel_data);
5763 
5764  // see LALSimInspiral.c
5765  REAL8 f_min = XLALSimInspiralfLow2fStart(thisInj->f_lower, thisInj->amp_order, approximant);
5766 /*
5767  cout << endl;
5768  printf("CWB::mdc::FindChirpInjectSignals - Injecting with approximant = %d\n", approximant);
5769  printf("CWB::mdc::FindChirpInjectSignals - Injecting with numrel_data = %s\n", thisInj->numrel_data);
5770  printf("CWB::mdc::FindChirpInjectSignals - Injecting with waveform = %s\n", thisInj->waveform);
5771  printf("CWB::mdc::FindChirpInjectSignals - Injecting with f_min = %f\n", f_min);
5772  printf("CWB::mdc::FindChirpInjectSignals - Injecting with f_lower = %f\n", thisInj->f_lower);
5773  printf("CWB::mdc::FindChirpInjectSignals - Injecting with amp_order = %d\n", thisInj->amp_order);
5774  printf("CWB::mdc::FindChirpInjectSignals - Injecting with mass1 = %f\n", thisInj->mass1);
5775  printf("CWB::mdc::FindChirpInjectSignals - Injecting with mass2 = %f\n", thisInj->mass2);
5776  printf("CWB::mdc::FindChirpInjectSignals - Injecting with spin1x = %f\n", thisInj->spin1x);
5777  printf("CWB::mdc::FindChirpInjectSignals - Injecting with spin2x = %f\n", thisInj->spin2x);
5778  printf("CWB::mdc::FindChirpInjectSignals - Injecting with spin1y = %f\n", thisInj->spin1y);
5779  printf("CWB::mdc::FindChirpInjectSignals - Injecting with spin2y = %f\n", thisInj->spin2y);
5780  printf("CWB::mdc::FindChirpInjectSignals - Injecting with spin1z = %f\n", thisInj->spin1z);
5781  printf("CWB::mdc::FindChirpInjectSignals - Injecting with spin2z = %f\n", thisInj->spin2z);
5782  printf("CWB::mdc::FindChirpInjectSignals - Injecting with distance = %f\n", thisInj->distance);
5783  printf("CWB::mdc::FindChirpInjectSignals - Injecting with inclination = %f\n", thisInj->inclination);
5784  printf("CWB::mdc::FindChirpInjectSignals - Injecting with coa_phase = %f\n", thisInj->coa_phase);
5785  cout << endl;
5786 */
5787  if( thisInj->amp_order!=0 ) {
5788  cout << endl << "CWB::mdc::FindChirpInjectSignals - "
5789  << "Error : amp_order must be 0 for NR waveform : "
5790  << "check inspiral parameters" << endl;
5791  exit(1);
5792  }
5793 
5794  // see LALSimInspiral.c
5795  int ret = XLALSimInspiralChooseTDWaveform(&hp, &hx, thisInj->mass1*LAL_MSUN_SI, thisInj->mass2*LAL_MSUN_SI,
5796  thisInj->spin1x, thisInj->spin1y, thisInj->spin1z,
5797  thisInj->spin2x, thisInj->spin2y, thisInj->spin2z,
5798  thisInj->distance*LAL_PC_SI*1.0e6, thisInj->inclination,
5799  thisInj->coa_phase, 0., 0., 0.,
5800  deltaT, f_min, thisInj->f_lower,
5801  LALpars, approximant);
5802 
5803  XLALDestroyDict(LALpars);
5804 
5805  if( ret==XLAL_FAILURE ) {
5806  cout << endl << "CWB::mdc::GetInspiral - "
5807  << "Error in XLALInspiralTDWaveformFromSimInspiral : "
5808  << "check inspiral parameters" << endl;
5809  exit(1);
5810  }
5811 #else
5812  cout << endl << "CWB::mdc::GetInspiral - "
5813  << "Error - NR_hdf5 not supported for LAL_VERSION < 6.18.0.1" << endl;
5814  exit(1);
5815 #endif
5816 
5817  } else {
5818 
5819 #if LAL_VERSION_MAJOR > 6 || (LAL_VERSION_MAJOR == 6 && \
5820  (LAL_VERSION_MINOR > 13 || (LAL_VERSION_MINOR == 13 && \
5821  LAL_VERSION_MICRO >= 2 ))) // LAL_VERSION >= 6.13.2
5822 
5823  // see LALInspiralWave.c
5824  int ret = XLALInspiralTDWaveformFromSimInspiral(&hp, &hx, thisInj, deltaT);
5825  if( ret==XLAL_FAILURE ) {
5826  cout << endl << "CWB::mdc::GetInspiral - "
5827  << "Error in XLALInspiralTDWaveformFromSimInspiral : "
5828  << "check inspiral parameters" << endl;
5829  exit(1);
5830  }
5831 #else
5832  cout << endl << "CWB::mdc::GetInspiral - "
5833  << "Error - LAL_VERSION < 6.13.2 not supported " << endl;
5834  exit(1);
5835 #endif
5836 
5837  }
5838 
5839  /* add the time of the injection at the geocentre to the
5840  * start times of the h+ and hx time series. after this,
5841  * their epochs mark the start of those time series at the
5842  * geocentre. (see http://www.lsc-group.phys.uwm.edu/cgit/gstlal/tree/gstlal/gst/lal/gstlal_simulation.c) */
5843 
5844  XLALGPSAddGPS(&hp->epoch, &thisInj->geocent_end_time);
5845  XLALGPSAddGPS(&hx->epoch, &thisInj->geocent_end_time);
5846 
5847  wat::Time gpsbuf(w.start());
5848  wat::Time gpsinj(hp->epoch.gpsSeconds,hp->epoch.gpsNanoSeconds);
5849  wat::Time gpsoff=gpsinj;gpsoff-=gpsbuf;
5850 
5851  int bininj = int(gpsoff.GetDouble()/deltaT);
5852  double binoff = fmod(gpsoff.GetDouble(),deltaT);
5853 
5854  bininj+=hp->data->length;
5855  if(bininj>w.size()) {
5856  cout << "CWB::mdc::FindChirpInjectSignals - Warning " << endl;
5857  cout << " signal length " << hp->data->length*deltaT
5858  << " (sec) is too high, signal is cutted to fit the buffer length" << endl;
5859  cout << " Decrease the injection rate and/or reduce the waveform length" << endl;
5860  bininj=w.size()-1;
5861  }
5862 
5863  gmst = fmod(XLALGreenwichMeanSiderealTime(&thisInj->geocent_end_time), LAL_TWOPI);
5864 
5865  latitude=thisInj->latitude;
5866  longitude=thisInj->longitude;
5867  polarization=thisInj->polarization;
5868  theta = LAL_PI_2-latitude; // LAL -> CWB
5869  theta*=rad2deg;
5870  longitude = fmod(longitude - gmst, LAL_TWOPI);
5871  if (longitude < 0) longitude += LAL_TWOPI;
5872  phi = longitude > 0 ? longitude : 2*TMath::Pi()+longitude;
5873  phi*= rad2deg;
5874  psi = polarization*rad2deg;
5875 
5876  fp = GetAntennaPattern(ifo, phi, theta, psi, "hp");
5877  fx = GetAntennaPattern(ifo, phi, theta, psi, "hx");
5878 
5879  // check if the injection length is greater of the buffer
5880  int length = hp->data->length<w.size() ? hp->data->length : w.size();
5881  z=0;
5882  for(int i=bininj;i>=0;i--) {
5883  int j=length-(bininj-i)-1;
5884  if(j<0) break;
5885  z[i] = fp*hp->data->data[j]+fx*hx->data->data[j]; // detector wave projection
5886  }
5887  // apply time shift respect to the ifoRef
5888  //double tShift = GetDelay(ifo,ifoRef,phi,theta);
5889  double tShift = XLALTimeDelayFromEarthCenter(location, thisInj->longitude, thisInj->latitude, &hp->epoch);
5890  // add to tShift the bin time offset
5891  tShift+=binoff;
5892  TimeShift(z, tShift);
5893  for(int i=0;i<(int)w.size();i++) w[i]+=z[i];
5894 
5895  XLALDestroyREAL8TimeSeries( hp );
5896  XLALDestroyREAL8TimeSeries( hx );
5897  hp = NULL; hx = NULL;
5898  }
5899  return;
5900 }
5901 #endif
5902 
5903 #ifdef _USE_LAL
5904 //______________________________________________________________________________
5906 CWB::mdc::GetInspiral(TString pol, int gps_start_time, int gps_end_time) {
5907 //
5908 // Get inspiral waveform
5909 //
5910 //
5911 // Input: pol - wave polarization : hp, hx
5912 // gps_start_time - start time
5913 // gps_end_time - stop time
5914 //
5915 // Output: w - wavearray which contains the waveform data
5916 //
5917 
5919  w.rate(MDC_SAMPLE_RATE);
5920 
5921  if(pol!="hp" && pol!="hx") {
5922  fprintf( stderr, "CWB::mdc::GetInspiral - Warning : wrong polarization (enter hp or hx)\n");
5923  return w;
5924  }
5925 
5926  // start/end times
5927  int gpsStartSec = gps_start_time;
5928  int gpsEndSec = gps_end_time;
5929 
5930  // injections
5931  INT4 numInjections = 0;
5932  SimInspiralTable *injections = NULL;
5933  TString injectionFile = GenInspiralXML(0., 0., false);
5934 
5935  // set default debug level
5936  lal_errhandler = LAL_ERR_EXIT;
5937 
5938  XLALSetSilentErrorHandler();
5939 
5940  // read the injections
5941  numInjections = SimInspiralTableFromLIGOLw(&injections, injectionFile.Data(), gpsStartSec, gpsEndSec);
5942 
5943  if ( numInjections == 0 ) {
5944  fprintf( stderr, "CWB::mdc::GetInspiral - Warning : No injections in specified time\n");
5945  return w;
5946  } else {
5947  fprintf( stdout, "CWB::mdc::GetInspiral : Read %d injection(s) from the file '%s'\n",
5948  numInjections, injectionFile.Data() );
5949  }
5950 
5951  REAL8TimeSeries *hp=NULL;
5952  REAL8TimeSeries *hx=NULL;
5953 
5954  // loop over injections
5955  SimInspiralTable *thisInj = NULL;
5956  for (thisInj = injections; thisInj; thisInj = thisInj->next)
5957  {
5958  REAL8 deltaT = 1./w.rate();
5959 
5960  // get approximant ( see LALSimInspiral.c )
5961  Approximant approximant = (Approximant)XLALSimInspiralGetApproximantFromString(thisInj->waveform);
5962 /*
5963  cout << endl << endl;
5964  cout << "---------------------------------------------------------------------------------" << endl;
5965  cout << "CWB::mdc::GetInspiral" << endl;
5966  cout << "---------------------------------------------------------------------------------" << endl;
5967  cout << "thisSim->numrel_data : " << thisInj->numrel_data << endl;
5968  cout << "thisSim->waveform : " << thisInj->waveform << endl;
5969  cout << "thisSim->amp_order : " << thisInj->amp_order << endl;
5970  cout << "APPROXIMANT : " << approximant << " (NR_hdf5=" << NR_hdf5 << ")" << endl;
5971  cout << endl;
5972 */
5973  if(approximant==NR_hdf5) {
5974 
5975 #if LAL_VERSION_MAJOR > 6 || (LAL_VERSION_MAJOR == 6 && \
5976  (LAL_VERSION_MINOR > 18 || (LAL_VERSION_MINOR == 18 && \
5977  (LAL_VERSION_MICRO > 0 || (LAL_VERSION_MICRO == 0 && LAL_VERSION_DEVEL >= 1))))) // LAL_VERSION >= 6.18.0.1
5978 
5979  // see LALInferenceReadData.c
5980  LALDict *LALpars=XLALCreateDict();
5981  XLALSimInspiralWaveformParamsInsertNumRelData(LALpars, thisInj->numrel_data);
5982 
5983  // see LALSimInspiral.c
5984  REAL8 f_min = XLALSimInspiralfLow2fStart(thisInj->f_lower, thisInj->amp_order, approximant);
5985 /*
5986  cout << endl;
5987  printf("CWB::mdc::GetInspiral - Injecting with approximant = %d\n", approximant);
5988  printf("CWB::mdc::GetInspiral - Injecting with numrel_data = %s\n", thisInj->numrel_data);
5989  printf("CWB::mdc::GetInspiral - Injecting with waveform = %s\n", thisInj->waveform);
5990  printf("CWB::mdc::GetInspiral - Injecting with f_min = %f\n", f_min);
5991  printf("CWB::mdc::GetInspiral - Injecting with f_lower = %f\n", thisInj->f_lower);
5992  printf("CWB::mdc::GetInspiral - Injecting with amp_order = %d\n", thisInj->amp_order);
5993  printf("CWB::mdc::GetInspiral - Injecting with mass1 = %f\n", thisInj->mass1);
5994  printf("CWB::mdc::GetInspiral - Injecting with mass2 = %f\n", thisInj->mass2);
5995  printf("CWB::mdc::GetInspiral - Injecting with spin1x = %f\n", thisInj->spin1x);
5996  printf("CWB::mdc::GetInspiral - Injecting with spin2x = %f\n", thisInj->spin2x);
5997  printf("CWB::mdc::GetInspiral - Injecting with spin1y = %f\n", thisInj->spin1y);
5998  printf("CWB::mdc::GetInspiral - Injecting with spin2y = %f\n", thisInj->spin2y);
5999  printf("CWB::mdc::GetInspiral - Injecting with spin1z = %f\n", thisInj->spin1z);
6000  printf("CWB::mdc::GetInspiral - Injecting with spin2z = %f\n", thisInj->spin2z);
6001  printf("CWB::mdc::GetInspiral - Injecting with distance = %f\n", thisInj->distance);
6002  printf("CWB::mdc::GetInspiral - Injecting with inclination = %f\n", thisInj->inclination);
6003  printf("CWB::mdc::GetInspiral - Injecting with coa_phase = %f\n", thisInj->coa_phase);
6004  cout << endl;
6005 */
6006  if( thisInj->amp_order!=0 ) {
6007  cout << endl << "CWB::mdc::GetInspiral - "
6008  << "Error : amp_order must be 0 for NR waveform : "
6009  << "check inspiral parameters" << endl;
6010  exit(1);
6011  }
6012 
6013  // see LALSimInspiral.c
6014  int ret = XLALSimInspiralChooseTDWaveform(&hp, &hx, thisInj->mass1*LAL_MSUN_SI, thisInj->mass2*LAL_MSUN_SI,
6015  thisInj->spin1x, thisInj->spin1y, thisInj->spin1z,
6016  thisInj->spin2x, thisInj->spin2y, thisInj->spin2z,
6017  thisInj->distance*LAL_PC_SI*1.0e6, thisInj->inclination,
6018  thisInj->coa_phase, 0., 0., 0.,
6019  deltaT, f_min, thisInj->f_lower,
6020  LALpars, approximant);
6021 
6022  XLALDestroyDict(LALpars);
6023 
6024  if( ret==XLAL_FAILURE ) {
6025  cout << endl << "CWB::mdc::GetInspiral - "
6026  << "Error in XLALInspiralTDWaveformFromSimInspiral : "
6027  << "check inspiral parameters" << endl;
6028  exit(1);
6029  }
6030 #else
6031  cout << endl << "CWB::mdc::GetInspiral - "
6032  << "Error - NR_hdf5 not supported for LAL_VERSION < 6.18.0.1" << endl;
6033  exit(1);
6034 #endif
6035 
6036  } else {
6037 
6038 #if LAL_VERSION_MAJOR > 6 || (LAL_VERSION_MAJOR == 6 && \
6039  (LAL_VERSION_MINOR > 13 || (LAL_VERSION_MINOR == 13 && \
6040  LAL_VERSION_MICRO >= 2 ))) // LAL_VERSION >= 6.13.2
6041 
6042  // see LALInspiralWave.c
6043  int ret = XLALInspiralTDWaveformFromSimInspiral(&hp, &hx, thisInj, deltaT);
6044  if( ret==XLAL_FAILURE ) {
6045  cout << endl << "CWB::mdc::GetInspiral - "
6046  << "Error in XLALInspiralTDWaveformFromSimInspiral : "
6047  << "check inspiral parameters" << endl;
6048  exit(1);
6049  }
6050 #else
6051  cout << endl << "CWB::mdc::GetInspiral - "
6052  << "Error - LAL_VERSION < 6.13.2 not supported " << endl;
6053  exit(1);
6054 #endif
6055 
6056  }
6057 
6058  /* add the time of the injection at the geocentre to the
6059  * start times of the h+ and hx time series. after this,
6060  * their epochs mark the start of those time series at the
6061  * geocentre. (see http://www.lsc-group.phys.uwm.edu/cgit/gstlal/tree/gstlal/gst/lal/gstlal_simulation.c) */
6062 
6063  XLALGPSAddGPS(&hp->epoch, &thisInj->geocent_end_time);
6064  XLALGPSAddGPS(&hx->epoch, &thisInj->geocent_end_time);
6065 
6066  // fill output wavearray
6067  if(pol=="hp") {
6068  w.resize(hp->data->length);
6069  w.start(hp->epoch.gpsSeconds);
6070  for(int i=0;i<(int)w.size();i++) w[i] = hp->data->data[i];
6071  }
6072  if(pol=="hx") {
6073  w.resize(hx->data->length);
6074  w.start(hx->epoch.gpsSeconds);
6075  for(int i=0;i<(int)w.size();i++) w[i] = hx->data->data[i];
6076  }
6077 
6078  XLALDestroyREAL8TimeSeries(hp);
6079  XLALDestroyREAL8TimeSeries(hx);
6080  hp = NULL; hx = NULL;
6081 
6082  break; // break after the first waveform
6083  }
6084 
6085  if(inspXML=="") gSystem->Exec(TString("rm ")+injectionFile); // remove injectionFile file
6086 
6087  while ( injections ) {
6088  SimInspiralTable *thisInj = NULL;
6089  thisInj = injections;
6090  injections = injections->next;
6091  LALFree( thisInj );
6092  }
6093 
6094  LALCheckMemoryLeaks();
6095 
6096  return w;
6097 }
6098 #endif
6099 
TVector3 xyz
MDC_DISTRIBUTION
Definition: mdc.hh:146
wavearray< double > t(hp.size())
MDC_DRAW
Definition: mdc.hh:171
std::vector< char * > ifoName
Definition: network.hh:591
size_t mdcTypeSize()
Definition: network.hh:392
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
void Dump(TString fname, int ID, int id, TString polarization)
Definition: mdc.cc:4365
int id
Definition: mdc.hh:180
double pc
Definition: DrawEBHH.C:15
double rho
detectorParams getDetectorParams()
Definition: detector.cc:201
char cut[512]
#define EPZOOM
Definition: mdc.hh:116
int ID
Definition: mdc.hh:209
waveform GetSourceWaveform(int &ID, int &id)
Definition: mdc.cc:2011
TObjString * tdist
Definition: ConvertGWGC.C:42
virtual size_t size() const
Definition: wavearray.hh:127
Definition: mdc.hh:172
double xgc
static const double C
Definition: GNGen.cc:10
#define MDC_INJ_RATE
Definition: mdc.hh:109
double imag() const
Definition: wavecomplex.hh:52
int noverlap
Definition: TestDelta.C:20
TString inspDIR
Definition: mdc.hh:438
TString ofName
static double g(double e)
Definition: GNGen.cc:98
TString GetDateString()
Definition: time.cc:443
void Init()
Definition: ChirpMass.C:280
watplot * Draw(TString name, int id=0, TString polarization="hp", MDC_DRAW type=MDC_TIME, TString options="ALP", Color_t color=kBlack)
Definition: mdc.cc:2288
double duration
par[0] value
double ygc
detector D
Definition: TestBandPass.C:15
Definition: mdc.hh:189
double gc_theta
bool status
Definition: mdc.hh:191
size_t add(detector *)
param: detector structure return number of detectors in the network
Definition: network.cc:2528
tuple f
Definition: cwb_online.py:91
printf("total live time: non-zero lags = %10.1f \n", liveTot)
static double GetTimeRange(wavearray< double > x, double &tMin, double &tMax, double efraction=EPZOOM)
Definition: mdc.cc:2831
std::vector< float > psiList
Definition: mdc.hh:421
char cmd[1024]
size_t readMDClog(char *, double=0., int=11, int=12)
param: MDC log file param: approximate gps time
Definition: network.cc:3339
TString Get(wavearray< double > &x, TString ifo)
Definition: mdc.cc:1502
TString inspOptions
Definition: mdc.hh:440
#define GA_FORMULA_WNB
Definition: mdc.cc:3020
fprintf(stdout,"start=%f duration=%f rate=%f\n", x.start(), x.size()/x.rate(), x.rate())
Definition: ced.hh:24
double dist
Definition: ConvertGWGC.C:48
double min(double x, double y)
Definition: eBBH.cc:13
int offset
Definition: TestSTFT_2.C:19
std::vector< std::string > mdcList
Definition: mdc.hh:357
double fHigh
virtual void rate(double r)
Definition: wavearray.hh:123
#define MDC_INJ_LENGTH
Definition: mdc.hh:111
#define MNGD_Md2
Definition: mdc.cc:3387
char logFile[1024]
Definition: cwb_merge_log.C:13
wavearray< double > a(hp.size())
static double GetCentralTime(wavearray< double > x)
Definition: mdc.cc:2761
WSeries< float > v[nIFO]
Definition: cwb_net.C:62
Definition: mdc.hh:128
Definition: mdc.hh:177
gx Draw(GWAT_TIME)
par[0] name
#define B
int n
Definition: cwb_net.C:10
Definition: mdc.hh:173
Definition: mdc.hh:151
wavearray< double > z
Definition: Test10.C:32
double rho_min
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
double olatitude
char * watversion(char c='s')
Definition: watversion.hh:21
TString("c")
std::vector< std::string > mdcType
Definition: mdc.hh:358
wavearray< double > GetSGQ(double frequency, double Q)
Definition: mdc.cc:2976
int ID
Definition: TestMDC.C:70
MDC SetSkyDistribution(MDC_CELESTIAL_FIX, par, seed)
static void PhaseShift(wavearray< double > &x, double pShift=0.)
Definition: mdc.cc:2926
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
double frequency
double phase
TF3 * gd3
double SolarMass()
Definition: constants.hh:184
unsigned int srcList_seed
Definition: mdc.hh:434
void GetSourceCoordinates(double &theta, double &phi, double &psi, double &rho, double &iota, double &hrss, int &ID, int &id)
Definition: mdc.cc:1960
double amplitude
float theta
int nfact
Definition: TestDelta.C:18
int nfft
Definition: TestDelta.C:19
network * net
Definition: mdc.hh:408
std::vector< double > gpsList
Definition: mdc.hh:425
Complex Exp(double phase)
Definition: numpy.cc:33
TH2F * ph
TString waveName
Definition: mdc.hh:441
static void AddExp(wavearray< double > &td, double v, int M)
Definition: mdc.cc:3221
double ilatitude
MDC_TYPE
Definition: mdc.hh:118
cout<<"Comparison bkg events above threshold: "<< entriesx<< endl;double *rhox=cnet.GetV1();comph=(TH1D *) gDirectory-> Get("hcomp")
Definition: compare_bkg.C:201
wavearray< double > GetGA(double duration)
Definition: mdc.cc:3101
Long_t flags
std::vector< float > phList
Definition: mdc.hh:420
std::vector< std::string > mdcType
Definition: network.hh:595
wavearray< double > hp
Definition: mdc.hh:196
double real() const
Definition: wavecomplex.hh:51
float mchirp
Definition: cbc_plots.C:436
double inj_rate
Definition: mdc.hh:429
waveform wf
int polarization
std::vector< int > IDList
Definition: mdc.hh:426
double olongitude
Long_t size
wavearray< double > hp
Definition: DrawInspiral.C:43
char refIFO[4]
Definition: test_config1.C:14
void setPolarization(POLARIZATION polarization=TENSOR)
Definition: detector.hh:288
#define M
Definition: UniqSLagsList.C:3
int m
Definition: cwb_net.C:10
virtual void start(double s)
Definition: wavearray.hh:119
std::vector< size_t > mdc__ID
Definition: network.hh:597
int j
Definition: cwb_net.C:10
i drho i
double longitude
Definition: detector.hh:34
#define MNGD_DENOMINATOR
Definition: mdc.cc:3382
TList * list
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
int isize
std::vector< detector * > ifoList
Definition: network.hh:590
double GetDelay(TString ifo1, TString ifo2, double phi, double theta)
Definition: mdc.cc:4494
#define N
watplot * DrawTime(wavearray< double > &x, TString options="ALP", Color_t color=kBlack)
Definition: mdc.cc:2381
mdc & operator=(const mdc &)
Definition: mdc.cc:280
CWB::Toolbox TB
Definition: ComputeSNR.C:5
#define MNGD_A3
Definition: mdc.cc:3390
mdcid AddWaveform(MDC_TYPE mdc_type, vector< mdcpar > par, TString uname="")
Definition: mdc.cc:445
void Print(int level=0)
Definition: mdc.cc:2707
Definition: mdc.hh:133
char ifoLabel[64]
double pi
Definition: TestChirp.C:18
char ifo[NIFO_MAX][8]
std::vector< std::string > nameList
Definition: mdc.hh:418
network ** net
NOISE_MDC_SIMULATION.
void Draw(double t1=0.0, double t2=0.0, double f1=0.0, double f2=0.0, double z1=0.0, double z2=0.0, int dpaletteId=DUMMY_PALETTE_ID, Option_t *option="colfz")
Definition: STFT.cc:76
size_t ifoListSize()
Definition: network.hh:413
float distance
Definition: cbc_plots.C:436
double gps
Definition: mdc.hh:202
void SetSkyDistribution(MDC_DISTRIBUTION sky_distribution, vector< mdcpar > par, int seed=0, bool add=false)
Definition: mdc.cc:3415
TString GetTemporaryFileName(TString tag="mdc", TString ext="txt", TString dir="/tmp", bool mkdir=false)
Definition: mdc.cc:5661
Definition: mdc.hh:126
#define PI
Definition: watfun.hh:14
#define MDC_INJ_JITTER
Definition: mdc.hh:110
size_t mode
dV
Temporay patch for redshifted mass distributions, i.e. point-like in source frame and spread over mul...
double GetPar(TString name, vector< mdcpar > par, bool &error)
Definition: mdc.cc:405
Definition: mdc.hh:174
int GetWaveformID(TString name)
Definition: mdc.cc:2689
TString inspXML
Definition: mdc.hh:437
virtual double rms()
Definition: wavearray.cc:1188
wavearray< double > w
Definition: Test1.C:27
nc append(pix)
#define nIFO
ofstream out
Definition: cwb_merge.C:196
POLARIZATION getPolarization()
Definition: detector.hh:289
#define MNGD_NUMERATOR
Definition: mdc.cc:3381
std::vector< std::string > xmlType
Definition: mdc.hh:359
void DrawSkyDistribution(TString name="skymap", TString projection="", TString coordinate="Geographic", double resolution=2, bool background=true)
Definition: mdc.cc:4135
tlive_fix Write()
#define RD_FORMULA
Definition: mdc.cc:3135
wavearray< double > GetCGQ(double frequency, double Q)
Definition: mdc.cc:2999
float phi
TString chName[NIFO_MAX]
double ra
Definition: ConvertGWGC.C:46
#define MNGD_Md3
Definition: mdc.cc:3389
Definition: mdc.hh:125
static void AddGauss(wavearray< double > &td, double v, double u=0.)
Definition: mdc.cc:3201
Definition: mdc.hh:138
char str[1024]
double rho
Definition: mdc.hh:206
TString name
Definition: mdc.hh:192
x plot
wavecomplex antenna(double, double, double=0.)
param: source theta,phi, polarization angle psi in degrees
Definition: detector.cc:473
double hrss
Definition: TestMDC.C:70
float psi
double time[6]
Definition: cbc_plots.C:435
TString hxPath
Definition: mdc.hh:194
double G
Definition: DrawEBHH.C:12
TString uname
int ID
Definition: mdc.hh:179
Definition: mdc.hh:216
wavearray< double > hx
Definition: DrawInspiral.C:44
TString WriteFrameFile(TString frDir, TString frLabel, size_t gps, size_t length=1000, bool log=false, vector< TString > chName=vector< TString >())
Definition: mdc.cc:4254
#define GA_FORMULA
Definition: mdc.cc:3097
TF3 * gd1
Definition: mdc.hh:123
double deg2rad
static void convertSampleRate(wavearray< double > iw, wavearray< double > ow)
Definition: Toolbox.cc:5045
TCanvas * c1
i() int(T_cor *100))
double rho_max
void DumpLogHeader(TString fName, TString label="", int size=0)
Definition: mdc.cc:4538
#define MDC_SAMPLE_RATE
Definition: mdc.hh:114
double hrss
Definition: mdc.hh:208
int id
Definition: mdc.hh:210
TString label
Definition: MergeTrees.C:21
double Pi
std::vector< std::string > mdcList
Definition: network.hh:594
const int NIFO_MAX
Definition: wat.hh:4
bool log
Definition: WaveMDC.C:41
vector< mdcpar > par
Definition: mdc.hh:195
cout<< "Injected signals: "<< mdc.GetEntries()<< endl;cout<< "Injected signals in histogram factor_events_inj: "<< NEVTS<< endl;float myifar, ecor, m1, m2, netcc[3], neted, penalty;float rho[2];float chirp[6];float range[2];float frequency[2];float iSNR[3], sSNR[3];sim.SetBranchAddress("mass", mass);sim.SetBranchAddress("factor",&factor);sim.SetBranchAddress("range", range);sim.SetBranchAddress("chirp", chirp);sim.SetBranchAddress("rho", rho);sim.SetBranchAddress("netcc", netcc);sim.SetBranchAddress("neted",&neted);sim.SetBranchAddress("ifar",&myifar);sim.SetBranchAddress("ecor",&ecor);sim.SetBranchAddress("penalty",&penalty);sim.SetBranchAddress("time", mytime);sim.SetBranchAddress("iSNR", iSNR);sim.SetBranchAddress("sSNR", sSNR);sim.SetBranchAddress("spin", spin);sim.SetBranchAddress("frequency", frequency);float **volume=new float *[NBINS_mass1];float **volume_first_shell=new float *[NBINS_mass1];float **radius=new float *[NBINS_mass1];float **error_volume=new float *[NBINS_mass1];float **error_volume_first_shell=new float *[NBINS_mass1];float **error_radius=new float *[NBINS_mass1];for(int i=0;i< NBINS_mass1;i++){volume[i]=new float[NBINS_mass2];volume_first_shell[i]=new float[NBINS_mass2];radius[i]=new float[NBINS_mass2];error_volume[i]=new float[NBINS_mass2];error_volume_first_shell[i]=new float[NBINS_mass2];error_radius[i]=new float[NBINS_mass2];for(int j=0;j< NBINS_mass2;j++){volume[i][j]=0.;volume_first_shell[i][j]=0.;radius[i][j]=0.;error_volume[i][j]=0.;error_volume_first_shell[i][j]=0.;error_radius[i][j]=0.;}}float **spin_mtot_volume=new float *[NBINS_MTOT+1];float **spin_mtot_radius=new float *[NBINS_MTOT+1];float **error_spin_mtot_volume=new float *[NBINS_MTOT+1];float **error_spin_mtot_radius=new float *[NBINS_MTOT+1];for(int i=0;i< NBINS_MTOT+1;i++){spin_mtot_volume[i]=new float[NBINS_SPIN+1];spin_mtot_radius[i]=new float[NBINS_SPIN+1];error_spin_mtot_volume[i]=new float[NBINS_SPIN+1];error_spin_mtot_radius[i]=new float[NBINS_SPIN+1];for(int j=0;j< NBINS_SPIN+1;j++){spin_mtot_volume[i][j]=0.;error_spin_mtot_volume[i][j]=0.;spin_mtot_radius[i][j]=0.;error_spin_mtot_radius[i][j]=0.;}}char fname[1024];sprintf(fname,"%s/recovered_signals.txt", netdir);ofstream fev;fev.open(fname, std::ofstream::out);sprintf(line,"#GPS@L1 FAR[Hz] eFAR[Hz] Pval ""ePval factor rho frequency iSNR sSNR \n");fev<< line<< endl;ofstream *fev_single=new ofstream[nfactor];for(int l=1;l< nfactor+1;l++){sprintf(fname,"%s/recovered_signals_%d.txt", netdir, l);fev_single[l-1].open(fname, std::ofstream::out);fev_single[l-1]<< line<< endl;}double Vrho[RHO_NBINS], eVrho[RHO_NBINS], Rrho[RHO_NBINS], eRrho[RHO_NBINS], Trho[RHO_NBINS];for(int i=0;i< RHO_NBINS;i++){Vrho[i]=0.;eVrho[i]=0.;Rrho[i]=0.;eRrho[i]=0.;Trho[i]=RHO_MIN+i *RHO_BIN;}double dV, dV1, dV_spin_mtot, nevts, internal_volume;int nT;int countv=0;int cnt=0;int cnt2=0;int cntfreq=0;bool bcut=false;double liveTot=sim.GetMaximum("ifar");double BKG_LIVETIME_yr=liveTot/CYS;double BKG_LIVETIME_Myr=BKG_LIVETIME_yr/(1.e6);cout.precision(14);cout<< "Total live time ---> background
MDC TimeShift(MDC.wfList[14].hx, 0.001)
const char * DistributionToString(MDC_DISTRIBUTION n)
Definition: mdc.hh:157
TString frDir[NIFO_MAX]
TString GetBurst(wavearray< double > &x, TString ifo)
Definition: mdc.cc:1529
int ninj
Definition: cwb_mkeff.C:52
waveform wf
Definition: mdc.hh:211
#define MNGD_B
Definition: mdc.cc:3384
static double tau
Definition: geodesics.cc:8
char fname[1024]
Definition: mdc.hh:183
wavearray< double > GetWNB(double frequency, double bandwidth, double duration, int seed=0, bool mode=0)
Definition: mdc.cc:3024
size_t mdc__IDSize()
Definition: network.hh:396
Definition: mdc.hh:121
TString inspOptions
#define speedlight
Definition: watfun.hh:15
char output[256]
int k
m1
Definition: cbc_plots.C:606
UserGroup_t * uinfo
Definition: cwb_frdisplay.C:73
void Dump(WSeries< double > &w, double t1, double t2, const char *fname)
double Parsec()
Definition: constants.hh:188
double RA2phi(double ph, double gps)
Definition: skymap.hh:195
Definition: mdc.hh:122
r add(tfmap,"hchannel")
#define MNGD_XMAX
Definition: mdc.cc:3392
static double A
Definition: geodesics.cc:8
TObjArray * token
double F
Definition: skymap.hh:45
double latitude
Definition: detector.hh:33
std::vector< int > idList
Definition: mdc.hh:427
vector< mdcpar > par
TString inspName
Definition: mdc.hh:439
double * entry
Definition: cwb_setcuts.C:206
double e
double GetCentralFrequency(wavearray< double > x)
#define MNGD_YMAX
Definition: mdc.cc:3393
void DrawTF(wavearray< double > &x, TString options="")
Definition: mdc.cc:2473
watplot * DrawFFT(wavearray< double > &x, TString options="ALP", Color_t color=kBlack)
Definition: mdc.cc:2427
double GetCentralTime(wavearray< double > x)
vector< waveform > wfList
Definition: mdc.hh:355
char tag[256]
Definition: cwb_merge.C:74
TFile * froot
TString GetString(TTree *tree, int run, int lag, TString psfix)
Definition: Toolfun.hh:261
double inj_jitter
Definition: mdc.hh:431
static double cosi2e(double cosi)
Definition: mdc.cc:5011
double gc_rho
static void AddCGBurst(wavearray< double > &td, double a, double f, double s, double d=0.)
Definition: mdc.cc:3292
double inj_offset
Definition: mdc.hh:430
double dt
double iota
Definition: mdc.hh:207
TString GetBurstLog(source src, double FrameGPS, double SimHpHp, double SimHcHc, double SimHpHc)
Definition: mdc.cc:2151
virtual void FFTW(int=1)
Definition: wavearray.cc:878
#define MNGD_Md1
Definition: mdc.cc:3385
regression r
Definition: Regression_H1.C:44
double GravitationalConstant()
Definition: constants.hh:113
static void TimeShift(wavearray< double > &x, double tShift=0.)
Definition: mdc.cc:2874
double zgc
double Rv[3]
Definition: detector.hh:312
s s
Definition: cwb_net.C:137
injection * inj
Definition: mdc.hh:409
double rad2deg
MDC_COORDINATES mdc_coordinates
Definition: mdc.hh:412
static void AddWGNoise(wavearray< double > &td, double a, double s)
Definition: mdc.cc:3334
TF3 * gd2
char options[256]
Definition: mdc.hh:119
Definition: mdc.hh:150
mdc()
Definition: mdc.cc:178
wavearray< double > hx
Definition: mdc.hh:197
double e0
Definition: RescaleEBBH.C:17
char cmd_line[512]
Definition: cwb_net.C:136
double psi
Definition: mdc.hh:205
double gps
std::vector< std::string > mdcName
Definition: mdc.hh:361
double ilongitude
double T
Definition: testWDM_4.C:11
TLine * line
Definition: compare_bkg.C:482
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:5943
ifstream in
double fLow
MDC_DISTRIBUTION sky_distribution
Definition: mdc.hh:413
wavearray< int > index
std::vector< float > rhoList
Definition: mdc.hh:422
vector< source > GetSourceList(double start, double stop)
Definition: mdc.cc:2026
char Name[16]
Definition: detector.hh:309
int getEBBH(double m1, double m2, double rmin0, double e0, wavearray< double > &Hp, wavearray< double > &Hx, double t_end)
Definition: eBBH.cc:53
double fabs(const Complex &x)
Definition: numpy.cc:37
string file
Definition: cwb_online.py:385
wavearray< double > GetWaveform(int ifoId, network *NET, int lag, int id, char type, bool shift=true)
double inj_hrss
Definition: mdc.hh:432
void resample(const wavearray< DataType_t > &, double, int=6)
Definition: wavearray.cc:485
double Q
double theta
Definition: mdc.hh:203
waveform GetWaveform(int ID, int id=0)
Definition: mdc.cc:2512
TCanvas * GetCanvas()
Definition: STFT.hh:52
int estat
void ReadWaveform(wavearray< double > &x, TString fName, double srate)
Definition: mdc.cc:1848
strcpy(RunLabel, RUN_LABEL)
int cnt
double df
static double e2cosi(double e)
Definition: mdc.cc:4971
double gc_phi
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
TObjString * tra
Definition: ConvertGWGC.C:40
void GalacticToEquatorial(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:29
~mdc()
Definition: mdc.cc:260
double getTau(double, double)
param: source theta,phi angles in degrees
Definition: detector.cc:681
char wf_name[256]
Long_t mt
#define MNGD_A2
Definition: mdc.cc:3388
double distance_source_Kpc
Definition: DrawEBHH.C:16
TString GetParString(TString name, vector< mdcpar > par, bool &error)
Definition: mdc.cc:425
TF3 * gd
std::vector< double > hrssList
Definition: mdc.hh:424
TCanvas * c2
Definition: slag.C:207
std::vector< float > iotaList
Definition: mdc.hh:423
DataType_t * data
Definition: wavearray.hh:301
#define MNGD_A1
Definition: mdc.cc:3386
MDC AddWaveform(MDC_SGC, par)
void DumpLog(TString fName, TString label="", bool append=false)
Definition: mdc.cc:5039
Long_t id
#define INT_4S
Definition: time.hh:16
TObjString * tdec
Definition: ConvertGWGC.C:41
void Init(int seed=0)
Definition: mdc.cc:354
std::vector< source > srcList
Definition: mdc.hh:362
double GetDouble()
Definition: time.cc:302
static double GetCentralFrequency(wavearray< double > x)
Definition: mdc.cc:2803
#define MNGD_SOLAR_SISTEM_DISTANCE_FROM_GC
Definition: mdc.cc:3395
double GetAntennaPattern(TString ifo, double phi, double theta, double psi=0., TString polarization="hp")
Definition: mdc.cc:4466
char formula[256]
void GeographicToCwb(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:403
int rnID
bool save
std::vector< double > mdcTime
Definition: mdc.hh:360
MDC ReadWaveform(x,"Waveforms/SG554Q8d9.txt", 16384.)
POLARIZATION
Definition: detector.hh:42
double phi
Definition: mdc.hh:204
MDC DumpLog("GHLTV-GWGC_v1-968600000-300000.root","CIAO")
Definition: mdc.hh:201
wavearray< double > GetRD(double frequency, double tau, double iota, bool polarization=0)
Definition: mdc.cc:3139
#define MDC_INJ_HRSS
Definition: mdc.hh:112
char fName[256]
for(int i=0;i< 101;++i) Cos2[2][i]=0
virtual void resize(unsigned int)
Definition: wavearray.cc:445
Definition: mdc.hh:127
double length
Definition: TestBandPass.C:18
wavearray< double > y
Definition: Test10.C:31
double rp0
Definition: RescaleEBBH.C:16
vector< waveform > list
Definition: mdc.hh:198
MDC_TYPE type
Definition: mdc.hh:190
TString name
Definition: mdc.hh:178
TString frLabel[NIFO_MAX]
Definition: mdc.hh:136
TTree * inj_tree
Definition: mdc.hh:410
double fparm
Definition: TestDelta.C:22
TString hpPath
Definition: mdc.hh:193
Definition: mdc.hh:129
Definition: mdc.hh:135
char GravEn_SimID[1024]
detector ** pD
static void AddSGBurst(wavearray< double > &td, double a, double f, double s, double d=0.)
Definition: mdc.cc:3250
TString ifos[60]
std::vector< float > thList
Definition: mdc.hh:419
CWB::STFT * stft
Definition: ChirpMass.C:117
MDC SetInspiral("inspNameTEST", inspOptions)
exit(0)
double SpeedOfLightInVacuo()
Definition: constants.hh:96
bool isBuiltin()
Definition: detector.hh:286
double avr
m2
Definition: cbc_plots.C:607