Logo coherent WaveBurst  
Library Reference Guide
Logo
injection.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko, Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #include <fstream>
20 #include "injection.hh"
21 #include "TH2.h"
22 #include "TStyle.h"
23 #include "TCanvas.h"
24 
25 #define MDC_TREE_NAME "mdc"
26 
27 ClassImp(injection) // used by THtml doc
28 
29 TTree* injection::Init(TString fName, int n)
30 {
31  iFile = TFile::Open(fName);
32  if((iFile==NULL) || (iFile!=NULL && !iFile->IsOpen())) {
33  cout << "injection::Init : Error opening root file " << fName.Data() << endl;
34  exit(1);
35  }
36 
37  TTree* tree = (TTree *) iFile->Get(MDC_TREE_NAME);
38  if(tree) {
39  ndim = tree->GetUserInfo()->GetSize(); // get number of detectors
40  if(ndim>0) {
41  if(n>0 && ndim!=n) {
42  cout << "injection::Init : number of detectors declared in the constructor (" << n
43  << ") are not equals to the one ("<<ndim<<") declared in the root file : "
44  << fName.Data() << endl;
45  exit(1);
46  }
47  } else ndim=n;
48  } else {
49  cout << "injection::Init : object tree " << MDC_TREE_NAME
50  << " not present in the root file " << fName.Data() << endl;
51  exit(1);
52  }
53 
54  if(ndim==0) {
55  cout << "injection::Init : number of detectors is not declared in the constructor or"
56  << " not present in the root file : " << endl << fName.Data() << endl;
57  exit(1);
58  }
59 
60  return tree;
61 }
62 
63 // Set branch addresses
64 void injection::Init(TTree *tree)
65 {
66  if (tree == 0) return;
67  fChain = tree;
68  fCurrent = -1;
69  fChain->SetMakeClass(1);
70 
71  fChain->SetBranchAddress("run",&run);
72  fChain->SetBranchAddress("ndim",&ndim);
73  fChain->SetBranchAddress("nevent",&nevent);
74  fChain->SetBranchAddress("eventID",&eventID);
75  fChain->SetBranchAddress("type",&type);
76  fChain->SetBranchAddress("name",&name);
77  fChain->SetBranchAddress("log",&log);
78 
79  fChain->SetBranchAddress("factor",&factor);
80  fChain->SetBranchAddress("distance",&distance);
81  fChain->SetBranchAddress("mchirp",&mchirp);
82  fChain->SetBranchAddress("rp0",&rp0);
83  fChain->SetBranchAddress("e0",&e0);
84  fChain->SetBranchAddress("redshift",&redshift);
85  fChain->SetBranchAddress("gps",&gps);
86  fChain->SetBranchAddress("strain",&strain);
87  fChain->SetBranchAddress("psi",psi);
88  fChain->SetBranchAddress("iota",iota);
89  fChain->SetBranchAddress("phi",phi);
90  fChain->SetBranchAddress("theta",theta);
91  fChain->SetBranchAddress("bp",bp);
92  fChain->SetBranchAddress("bx",bx);
93 
94  fChain->SetBranchAddress("time",time);
95  fChain->SetBranchAddress("duration",duration);
96 
97  fChain->SetBranchAddress("frequency",frequency);
98  fChain->SetBranchAddress("bandwidth",bandwidth);
99  fChain->SetBranchAddress("hrss",hrss);
100  fChain->SetBranchAddress("snr",snr);
101  fChain->SetBranchAddress("Deff",Deff);
102  fChain->SetBranchAddress("mass",mass);
103  fChain->SetBranchAddress("spin",spin);
104 
105  Notify();
106 }
107 
108 // allocate memory
110 {
111  if (!name) name= new string();
112  else {delete name;name= new string();}
113  if (!log) log= new string();
114  else {delete log; log= new string();}
115  if (!psi) psi= (Float_t*)malloc(2*sizeof(Float_t));
116  else psi= (Float_t*)realloc(psi,2*sizeof(Float_t));
117  if (!iota) iota= (Float_t*)malloc(2*sizeof(Float_t));
118  else iota= (Float_t*)realloc(iota,2*sizeof(Float_t));
119  if (!phi) phi= (Float_t*)malloc(2*sizeof(Float_t));
120  else phi= (Float_t*)realloc(phi,2*sizeof(Float_t));
121  if (!theta) theta= (Float_t*)malloc(2*sizeof(Float_t));
122  else theta= (Float_t*)realloc(theta,2*sizeof(Float_t));
123  if (!bp) bp= (Float_t*)malloc(ndim*sizeof(Float_t));
124  else bp= (Float_t*)realloc(bp,ndim*sizeof(Float_t));
125  if (!bx) bx= (Float_t*)malloc(ndim*sizeof(Float_t));
126  else bx= (Float_t*)realloc(bx,ndim*sizeof(Float_t));
127 
128  if (!time) time= (Double_t*)malloc(ndim*sizeof(Double_t));
129  else time= (Double_t*)realloc(time,ndim*sizeof(Double_t));
130  if (!duration) duration= (Float_t*)malloc(ndim*sizeof(Float_t));
131  else duration= (Float_t*)realloc(duration,ndim*sizeof(Float_t));
132 
133  if (!frequency) frequency=(Float_t*)malloc(ndim*sizeof(Float_t));
134  else frequency=(Float_t*)realloc(frequency,ndim*sizeof(Float_t));
135  if (!bandwidth) bandwidth=(Float_t*)malloc(ndim*sizeof(Float_t));
136  else bandwidth=(Float_t*)realloc(bandwidth,ndim*sizeof(Float_t));
137  if (!hrss) hrss= (Double_t*)malloc(ndim*sizeof(Double_t));
138  else hrss= (Double_t*)realloc(hrss,ndim*sizeof(Double_t));
139  if (!snr) snr= (Float_t*)malloc(ndim*sizeof(Float_t));
140  else snr= (Float_t*)realloc(snr,ndim*sizeof(Float_t));
141  if (!Deff) Deff= (Float_t*)malloc(ndim*sizeof(Float_t));
142  else Deff= (Float_t*)realloc(Deff,ndim*sizeof(Float_t));
143  if (!mass) mass= (Float_t*)malloc(2*sizeof(Float_t));
144  else mass= (Float_t*)realloc(mass,2*sizeof(Float_t));
145  if (!spin) spin= (Float_t*)malloc(6*sizeof(Float_t));
146  else spin= (Float_t*)realloc(spin,6*sizeof(Float_t));
147  if (!pwf) pwf= (wavearray<double>**)malloc(ndim*sizeof(wavearray<double>*));
148  else pwf= (wavearray<double>**)realloc(pwf,ndim*sizeof(wavearray<double>*));
149 
150  for(int n=0; n<ndim; n++) pwf[n] = NULL;
151 
152  return;
153 }
154 
155 // init array
157 {
158 // for(int i=0;i<NIFO_MAX;i++) pD[i]=NULL;
159  return;
160 }
161 
163 {
164  // Called when loading a new file.
165  // Get branch pointers.
166  b_ndim = fChain->GetBranch("ndim");
167  b_run = fChain->GetBranch("run");
168  b_nevent = fChain->GetBranch("nevent");
169  b_eventID = fChain->GetBranch("eventID");
170  b_type = fChain->GetBranch("type");
171  b_name = fChain->GetBranch("name");
172  b_log = fChain->GetBranch("log");
173  b_factor = fChain->GetBranch("factor");
174  b_distance = fChain->GetBranch("distance");
175  b_mchirp = fChain->GetBranch("mchirp");
176  b_rp0 = fChain->GetBranch("rp0");
177  b_e0 = fChain->GetBranch("e0");
178  b_redshift = fChain->GetBranch("redshift");
179  b_gps = fChain->GetBranch("gps");
180  b_strain = fChain->GetBranch("strain");
181  b_psi = fChain->GetBranch("psi");
182  b_iota = fChain->GetBranch("iota");
183  b_phi = fChain->GetBranch("phi");
184  b_theta = fChain->GetBranch("theta");
185  b_bp= fChain->GetBranch("bx");
186  b_bx = fChain->GetBranch("bp");
187  b_time = fChain->GetBranch("time");
188  b_duration = fChain->GetBranch("duration");
189  b_frequency = fChain->GetBranch("frequency");
190  b_bandwidth = fChain->GetBranch("bandwidth");
191  b_hrss = fChain->GetBranch("hrss");
192  b_snr = fChain->GetBranch("snr");
193  b_Deff = fChain->GetBranch("Deff");
194  b_mass = fChain->GetBranch("mass");
195  b_spin = fChain->GetBranch("spin");
196 
197  return kTRUE;
198 }
199 
201 {
202  if (!fChain) return 0;
203  return fChain->GetEntry(entry);
204 };
206 {
207  if (!fChain) return 0;
208  return fChain->GetEntries();
209 };
210 
212 {
213 // Print contents of entry.
214 // If entry is not specified, print current entry
215  if (!fChain) return;
216  fChain->Show(entry);
217 }
218 
219 
220 //++++++++++++++++++++++++++++++++++++++++++++++
221 // set single event tree
222 //++++++++++++++++++++++++++++++++++++++++++++++
224 {
225  TTree* waveTree = new TTree(MDC_TREE_NAME,MDC_TREE_NAME);
226 
227  char cpsi[16];
228  char ciota[16];
229  char cphi[16];
230  char ctheta[16];
231  char cbp[16];
232  char cbx[16];
233  char ctime[16];
234  char cduration[16];
235  char cfrequency[16];
236  char cbandwidth[16];
237  char chrss[16];
238  char csnr[16];
239  char cDeff[16];
240  char cmass[16];
241  char cspin[16];
242 
243  sprintf(cpsi, "psi[2]/F");
244  sprintf(ciota, "iota[2]/F");
245  sprintf(cphi, "phi[2]/F");
246  sprintf(ctheta, "theta[2]/F");
247  sprintf(cbp, "bp[%1d]/F",ndim);
248  sprintf(cbx, "bx[%1d]/F",ndim);
249  sprintf(ctime, "time[%1d]/D",ndim);
250  sprintf(cduration, "duration[%1d]/F",ndim);
251  sprintf(cfrequency, "frequency[%1d]/F",ndim);
252  sprintf(cbandwidth, "bandwidth[%1d]/F",ndim);
253  sprintf(chrss, "hrss[%1d]/D",ndim);
254  sprintf(csnr, "snr[%1d]/F",ndim);
255  sprintf(cDeff, "Deff[%1d]/F",ndim);
256  sprintf(cmass, "mass[2]/F");
257  sprintf(cspin, "spin[6]/F");
258 
259  //==================================
260  // Define trigger tree
261  //==================================
262 
263  waveTree->Branch("ndim", &ndim, "ndim/I");
264  waveTree->Branch("run", &run, "run/I");
265  waveTree->Branch("nevent", &nevent, "nevent/I");
266  waveTree->Branch("eventID", &eventID, "eventID/I");
267  waveTree->Branch("type", &type, "type/I");
268  waveTree->Branch("name", name);
269  waveTree->Branch("log", log);
270  waveTree->Branch("factor", &factor, "factor/F");
271  waveTree->Branch("distance", &distance, "distance/F");
272  waveTree->Branch("mchirp", &mchirp, "mchirp/F");
273  waveTree->Branch("rp0", &rp0, "rp0/F");
274  waveTree->Branch("e0", &e0, "e0/F");
275  waveTree->Branch("redshift", &redshift, "redshift/F");
276  waveTree->Branch("gps", &gps, "gps/D");
277  waveTree->Branch("strain", &strain, "strain/D");
278  waveTree->Branch("psi", psi, cpsi);
279  waveTree->Branch("iota", iota, ciota);
280  waveTree->Branch("phi", phi, cphi);
281  waveTree->Branch("theta", theta, ctheta);
282  waveTree->Branch("bp", bp, cbp);
283  waveTree->Branch("bx", bx, cbx);
284  waveTree->Branch("time", time, ctime);
285  waveTree->Branch("duration", duration, cduration);
286  waveTree->Branch("frequency", frequency, cfrequency);
287  waveTree->Branch("bandwidth", bandwidth, cbandwidth);
288  waveTree->Branch("hrss", hrss, chrss);
289  waveTree->Branch("snr", snr, csnr);
290  waveTree->Branch("Deff", Deff, cDeff);
291  waveTree->Branch("mass", mass, cmass);
292  waveTree->Branch("spin", spin, cspin);
293 
294  return waveTree;
295 }
296 
298 {
299  int i;
300 
301  if(this->ndim != a.ndim) { this->ndim=a.ndim; this->allocate(); }
302 
303  this->run= a.run;
304  this->nevent= a.nevent;
305  this->eventID= a.eventID;
306  this->factor= a.factor;
307  this->distance= a.distance;
308  this->mchirp= a.mchirp;
309  this->rp0= a.rp0;
310  this->e0= a.e0;
311  this->redshift= a.redshift;
312  this->gps= a.gps;
313  this->type= a.type;
314  *this->name= *a.name;
315  *this->log= *a.log;
316  this->strain= a.strain;
317  this->psi[0]= a.psi[0];
318  this->iota[0]= a.iota[0];
319  this->phi[0]= a.phi[0];
320  this->theta[0]= a.theta[0];
321  this->psi[1]= a.psi[1];
322  this->phi[1]= a.phi[1];
323  this->theta[1]= a.theta[1];
324  this->mass[0]= a.mass[1];
325  this->mass[1]= a.mass[1];
326 
327  for(i=0; i<6; i++) this->spin[i] = a.spin[i];
328 
329  for(i=0; i<ndim; i++){
330 
331  this->bp[i]= a.bp[i];
332  this->bx[i]= a.bx[i];
333  this->time[i]= a.time[i];
334  this->duration[i]= a.duration[i];
335  this->frequency[i]= a.frequency[i];
336  this->bandwidth[i]= a.bandwidth[i];
337  this->hrss[i]= a.hrss[i];
338  this->snr[i]= a.snr[i];
339  this->Deff[i]= a.Deff[i];
340  }
341  return *this;
342 }
343 
344 
345 
346 //++++++++++++++++++++++++++++++++++++++++++++++++++++
347 // fill this with data
348 //++++++++++++++++++++++++++++++++++++++++++++++++++++
349 Bool_t injection::fill_in(network* net, int id, bool checkEdges)
350 {
351  bool save = true;
352 
353  size_t N = net->mdc__IDSize();
354  size_t I = net->mdcTypeSize();
355  size_t M = net->ifoListSize();
356 
357  int ID = id<0 ? abs(id+1) : abs(id);
358 
359  if(!N || !M || !I || ID<0) return false;
360 
361  size_t i,m,nst;
362  string itag;
363  char* p;
364  char ch[1024];
365  double hphp, hxhx, hphx, T0, To, Eo;
366  double Pi = 3.14159265358979312;
367  detector* pd;
368 
369  this->gps = net->getifo(0)->getTFmap()->start();
370  size_t K = net->getifo(0)->getTFmap()->size();
371  double R = net->getifo(0)->getTFmap()->wavearray<double>::rate();
372  double sTARt = this->gps + net->Edge + 1.;
373  double sTOp = this->gps + K/R - net->Edge - 1.;
374 
375  if((net->getmdcTime(ID)<sTARt || net->getmdcTime(ID)>sTOp) && checkEdges) return false;
376 
377  this->eventID = ID;
378 
379  string str(net->getmdcList(ID));
380  sprintf(ch,"%s",str.c_str());
381 
382  this->log->assign(ch, strlen(ch));
383  this->log->erase(std::remove(this->log->begin(), this->log->end(), '\n'), this->log->end()); // remove new line
384 
385  if((p = strtok(ch," \t")) == NULL) return false;
386 
387  p = strtok(NULL," \t"); // get MDC strain
388  this->strain = atof(p);
389 
390  p = strtok(NULL," \t"); // skip
391  p = strtok(NULL," \t"); // skip
392  p = strtok(NULL," \t"); // get internal phi
393  //this->iota[0] = atof(p); // get iota[0]
394  //p = strtok(NULL," \t"); // get internal phi
395  this->iota[1] = atof(p); // get iota[1]
396  this->phi[1] = atof(p);
397  p = strtok(NULL," \t"); // get internal psi
398  this->psi[1] = atof(p);
399  p = strtok(NULL," \t"); // get external theta
400  if(fabs(atof(p))>1) {
401  cout<<"injection:fill_in error: external theta not valid, must be [-1,1]\n"<<endl;
402  exit(1);
403  }
404  this->theta[0] = acos(atof(p));
405  this->theta[0]*= 180/Pi;
406  p = strtok(NULL," \t"); // get external phi
407  this->phi[0] = atof(p) > 0 ? atof(p) : 2*Pi+atof(p);
408  this->phi[0]*= 180/Pi;
409  p = strtok(NULL," \t"); // get external psi
410  this->psi[0] = atof(p);
411  this->psi[0]*= 180/Pi;
412 
413  p = strtok(NULL," \t"); // skip
414  p = strtok(NULL," \t"); // injection time
415 
416  // printf("%12.3f %12.3f %12.3f \n",this->time[0],sTARt,sTOp);
417 
418  p = strtok(NULL," \t"); // injection name
419 
420  this->name->assign(p, strlen(p));
421 
422  for(i=0; i<I; i++) {
423  itag = net->getmdcType(i);
424  if(itag.find(p) == string::npos) continue;
425  this->type = i+1; break;
426  }
427 
428  p = strtok(NULL," \t"); // h+h+
429  hphp = atof(p);
430  p = strtok(NULL," \t"); // hxhx
431  hxhx = atof(p);
432  p = strtok(NULL," \t"); // h+hx
433  hphx = atof(p);
434 
435  save = true;
436  for(m=0; m<M; m++) { // loop over detectors
437  nst = str.find(net->getifo(m)->Name);
438  if(nst >= str.length()) {
439  cout<<"injection:fill_in error: no injections for detector "
440  << net->getifo(m)->Name <<" was found in the injection list !!!\n\n";
441  save = false;
442  exit(1);
443  }
444 
445  itag = str.substr(nst);
446  sprintf(ch,"%s",itag.c_str());
447  if((p = strtok(ch," \t")) == NULL) continue; // detector name
448 
449  p = strtok(NULL," \t"); // time
450  this->time[m] = atof(p);
451 // if(this->time[m]<sTARt || this->time[m]>sTOp) save = false;
452 
453 // printf("%13.3f %13.3f %13.3f\n",sTARt,time[m],sTOp);
454 
455  p = strtok(NULL," \t"); // F+
456  this->bp[m] = atof(p);
457  p = strtok(NULL," \t"); // Fx
458  this->bx[m] = atof(p);
459 
460  nst = str.find("insp") < str.find("ebbh") ? str.find("insp") : str.find("ebbh");
461  this->Deff[m] = 0.;
462  if(nst < str.length()) { // inspiral MDC log
463  p = strtok(NULL," \t"); // effective distance
464  this->Deff[m] = atof(p);
465  }
466  else { // standard burst MDC log
467  this->hrss[m] = hphp*bp[m]*bp[m] + hxhx*bx[m]*bx[m] + 2*hphx*bp[m]*bx[m];
468  this->hrss[m] = this->hrss[m]>0. ? sqrt(this->hrss[m]) : 0.;
469  }
470  }
471 
472  if(!save) return save;
473 
474  nst = str.find("distance");
475  this->distance = 0.;
476  if(nst < str.length()) {
477  itag = str.substr(nst);
478  sprintf(ch,"%s",itag.c_str());
479  if((p = strtok(ch," \t")) != NULL)
480  this->distance = atof(strtok(NULL," \t"));
481  }
482 
483  nst = str.find("mass1");
484  this->mass[0] = 0.;
485  if(nst < str.length()) {
486  itag = str.substr(nst);
487  sprintf(ch,"%s",itag.c_str());
488  if((p = strtok(ch," \t")) != NULL)
489  this->mass[0] = atof(strtok(NULL," \t"));
490  }
491 
492  nst = str.find("mass2");
493  this->mass[1] = 0.;
494  if(nst < str.length()) {
495  itag = str.substr(nst);
496  sprintf(ch,"%s",itag.c_str());
497  if((p = strtok(ch," \t")) != NULL)
498  this->mass[1] = atof(strtok(NULL," \t"));
499  }
500 
501  nst = str.find("mchirp");
502  this->mchirp = 0.;
503  if(nst < str.length()) {
504  itag = str.substr(nst);
505  sprintf(ch,"%s",itag.c_str());
506  if((p = strtok(ch," \t")) != NULL)
507  this->mchirp = atof(strtok(NULL," \t"));
508  }
509 
510  nst = str.find("rp0");
511  this->rp0 = 0.;
512  if(nst < str.length()) {
513  itag = str.substr(nst);
514  sprintf(ch,"%s",itag.c_str());
515  if((p = strtok(ch," \t")) != NULL)
516  this->rp0 = atof(strtok(NULL," \t"));
517  }
518 
519  nst = str.find("e0");
520  this->e0 = 0.;
521  if(nst < str.length()) {
522  itag = str.substr(nst);
523  sprintf(ch,"%s",itag.c_str());
524  if((p = strtok(ch," \t")) != NULL)
525  this->e0 = atof(strtok(NULL," \t"));
526  }
527 
528  nst = str.find("redshift");
529  this->redshift = 0.;
530  if(nst < str.length()) {
531  itag = str.substr(nst);
532  sprintf(ch,"%s",itag.c_str());
533  if((p = strtok(ch," \t")) != NULL)
534  this->redshift = atof(strtok(NULL," \t"));
535  }
536 
537  nst = str.find("spin1");
538  this->spin[0] = 0.;
539  this->spin[1] = 0.;
540  this->spin[2] = 0.;
541  if(nst < str.length()) {
542  itag = str.substr(nst);
543  sprintf(ch,"%s",itag.c_str());
544  if((p = strtok(ch," \t")) != NULL) {
545  this->spin[0] = atof(strtok(NULL," \t"));
546  this->spin[1] = atof(strtok(NULL," \t"));
547  this->spin[2] = atof(strtok(NULL," \t"));
548  }
549  }
550 
551  nst = str.find("spin2");
552  this->spin[3] = 0.;
553  this->spin[4] = 0.;
554  this->spin[5] = 0.;
555  if(nst < str.length()) {
556  itag = str.substr(nst);
557  sprintf(ch,"%s",itag.c_str());
558  if((p = strtok(ch," \t")) != NULL) {
559  this->spin[3] = atof(strtok(NULL," \t"));
560  this->spin[4] = atof(strtok(NULL," \t"));
561  this->spin[5] = atof(strtok(NULL," \t"));
562  }
563  }
564 
565 // read simulation parameters from the detector objects
566 
567  To = Eo = 0.;
568  for(m=0; m<M; m++) { // loop over detectors
569  pd = net->getifo(m);
570  if(!pd->HRSS.size()) continue;
571  To += pd->TIME.data[ID]*pd->ISNR.data[ID]*pd->ISNR.data[ID];
572  Eo += pd->ISNR.data[ID]*pd->ISNR.data[ID];
573  if(pd->TIME.data[ID] < 1.) save = false;
574  }
575 
576  if(!save || Eo<=0.) return save;
577 
578  To /= Eo; // central injection time
579  T0 = this->time[0];
580  for(m=0; m<M; m++) { // loop over detectors
581  pd = net->getifo(m);
582  if(!pd->HRSS.size()) continue;
583  this->frequency[m] = pd->FREQ.data[ID];
584  this->bandwidth[m] = pd->BAND.data[ID];
585  this->time[m] += To - T0;
586  this->duration[m] = pd->TDUR.data[ID];
587  this->hrss[m] = pd->HRSS.data[ID];
588  this->snr[m] = sqrt(pd->ISNR.data[ID]);
589 
590  int idSize = pd->IWFID.size();
591  int wfIndex=-1;
592  for (int mm=0; mm<idSize; mm++) if (pd->IWFID[mm]==id) wfIndex=mm;
593  this->pwf[m] = wfIndex>=0 ? pd->IWFP[wfIndex] : NULL;
594  }
595 
596  return save;
597 }
598 
599 //++++++++++++++++++++++++++++++++++++++++++++++++++++
600 // output injection metadata
601 //++++++++++++++++++++++++++++++++++++++++++++++++++++
602 void injection::output(TTree* waveTree, network* net, double factor, bool checkEdges)
603 {
604  size_t N = net->mdc__IDSize();
605  size_t I = net->mdcTypeSize();
606  size_t M = net->ifoListSize();
607  if(!N || !M || !I) return;
608  double FACTOR = fabs(factor); // used to tag events in root file
609  factor = factor<=0 ? 1 : fabs(factor); // used to rescale injected events
610 
611 
612  size_t n,m;
613 
614  // add detectors to tree user info
615  if(waveTree!=NULL) {
616  int dsize = waveTree->GetUserInfo()->GetSize();
617  if(dsize!=0 && dsize!=M) {
618  cout<<"injection::output(): wrong user detector list in header tree"<<endl; exit(1);
619  }
620  if(dsize==0) {
621  for(int n=0;n<M;n++) {
622  // must be done a copy because detector object
623  // is destroyed when waveTree is destroyed
624  detector* pD = new detector(*net->getifo(n));
625  waveTree->GetUserInfo()->Add(pD);
626  }
627  }
628  }
629 
630  this->run = net->nRun;
631  this->nevent = 0;
632 
633  for(n=0; n<N; n++) {
634  this->eventID = net->getmdc__ID(n);
635  if(this->fill_in(net,this->eventID,checkEdges)) {
636  this->nevent++;
637  this->factor = FACTOR;
638  this->strain *= factor;
639  this->distance /= factor;
640  for(m=0; m<M; m++) {
641  this->hrss[m] *= factor;
642  this->snr[m] *= factor;
643  this->Deff[m] /= factor;
644  }
645  waveTree->Fill();
646  }
647  }
648 }
649 
650 
651 
652 /*
653 Int_t injection::LoadTree(Int_t entry)
654 {
655 // Set the environment to read one entry
656  if (!fChain) return -5;
657  Int_t centry = fChain->LoadTree(entry);
658  if (centry < 0) return centry;
659  if (fChain->IsA() != TChain::Class()) return centry;
660  TChain *chain = (TChain*)fChain;
661  if (chain->GetTreeNumber() != fCurrent) {
662  fCurrent = chain->GetTreeNumber();
663  Notify();
664  }
665  return centry;
666 }
667 
668 Int_t injection::Cut(Int_t entry)
669 {
670 // This function may be called from Loop.
671 // returns 1 if entry is accepted.
672 // returns -1 otherwise.
673  return 1;
674 }
675 
676 void injection::Loop()
677 {
678 // In a ROOT session, you can do:
679 // Root > .L injection.C
680 // Root > injection t
681 // Root > t.GetEntry(12); // Fill t data members with entry number 12
682 // Root > t.Show(); // Show values of entry 12
683 // Root > t.Show(16); // Read and show values of entry 16
684 // Root > t.Loop(); // Loop on all entries
685 //
686 
687 // This is the loop skeleton where:
688 // jentry is the global entry number in the chain
689 // ientry is the entry number in the current Tree
690 // Note that the argument to GetEntry must be:
691 // jentry for TChain::GetEntry
692 // ientry for TTree::GetEntry and TBranch::GetEntry
693 //
694 // To read only selected branches, Insert statements like:
695 // METHOD1:
696 // fChain->SetBranchStatus("*",0); // disable all branches
697 // fChain->SetBranchStatus("branchname",1); // activate branchname
698 // METHOD2: replace line
699 // fChain->GetEntry(jentry); //read all branches
700 //by b_branchname->GetEntry(ientry); //read only this branch
701  if (fChain == 0) return;
702 
703  Int_t nentries = Int_t(fChain->GetEntriesFast());
704 
705  Int_t nbytes = 0, nb = 0;
706  for (Int_t jentry=0; jentry<nentries;jentry++) {
707  Int_t ientry = LoadTree(jentry);
708  if (ientry < 0) break;
709  nb = fChain->GetEntry(jentry); nbytes += nb;
710  // if (Cut(ientry) < 0) continue;
711  }
712 }
713 */
714 
715 
716 
717 
718 
719 
720 
721 
Int_t fCurrent
pointer to the analyzed TTree or TChain
Definition: injection.hh:60
TTree * tree
Definition: TimeSortTree.C:20
size_t mdcTypeSize()
Definition: network.hh:410
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
TBranch * b_nevent
Definition: injection.hh:107
TBranch * b_hrss
Definition: injection.hh:134
TTree * Init(TString fName, int n)
Definition: injection.cc:29
double sTARt
Double_t * time
beam pattern coefficients for hx
Definition: injection.hh:89
Float_t rp0
Definition: injection.hh:76
string * name
Definition: injection.hh:69
TBranch * b_psi
Definition: injection.hh:121
Float_t e0
Definition: injection.hh:77
double M
Definition: DrawEBHH.C:13
void Init()
Definition: ChirpMass.C:284
TBranch * b_bandwidth
Definition: injection.hh:132
Int_t GetEntry(Int_t)
Definition: injection.cc:200
std::vector< double > * getmdcTime()
Definition: network.hh:422
void init()
Definition: injection.cc:156
TBranch * b_distance
Definition: injection.hh:114
wavearray< double > a(hp.size())
int n
Definition: cwb_net.C:28
Bool_t Notify()
Definition: injection.cc:162
TString("c")
void output(TTree *, network *, double, bool=true)
Definition: injection.cc:602
size_t nRun
Definition: network.hh:572
int ID
Definition: TestMDC.C:70
wavearray< double > HRSS
Definition: detector.hh:371
Float_t * snr
injected hrss in the detectors
Definition: injection.hh:96
TBranch * b_Deff
Definition: injection.hh:136
TBranch * b_name
Definition: injection.hh:110
string getmdcType(size_t n)
Definition: network.hh:420
Float_t * iota
source psi angle
Definition: injection.hh:83
string getmdcList(size_t n)
Definition: network.hh:418
TBranch * b_duration
Definition: injection.hh:129
Float_t * duration
injection gps time
Definition: injection.hh:90
Float_t * bandwidth
average center_of_hrss frequency
Definition: injection.hh:93
TTree * setTree()
Definition: injection.cc:223
int m
Definition: cwb_net.C:28
virtual void start(double s)
Definition: wavearray.hh:137
Double_t strain
Definition: injection.hh:81
i drho i
TBranch * b_snr
Definition: injection.hh:135
TBranch * b_theta
Definition: injection.hh:124
#define N
TBranch * b_bp
Definition: injection.hh:125
Float_t * theta
source phi angle
Definition: injection.hh:85
Double_t gps
Definition: injection.hh:80
Int_t ndim
current Tree number in a TChain
Definition: injection.hh:61
TBranch * b_redshift
Definition: injection.hh:118
double Edge
Definition: network.hh:578
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:431
TBranch * b_e0
Definition: injection.hh:117
TBranch * b_iota
Definition: injection.hh:122
virtual size_t size() const
Definition: wavearray.hh:145
TBranch * b_spin
Definition: injection.hh:138
Float_t redshift
Definition: injection.hh:78
char str[1024]
Float_t * psi
Definition: injection.hh:82
void Show(Int_t entry=-1)
Definition: injection.cc:211
Float_t factor
injection log
Definition: injection.hh:72
TBranch * b_type
Definition: injection.hh:109
Double_t * hrss
estimated bandwidth
Definition: injection.hh:95
virtual injection & operator=(const injection &)
Definition: injection.cc:297
wavearray< double > TIME
Definition: detector.hh:375
double Pi
Float_t mchirp
Definition: injection.hh:74
TBranch * b_frequency
Definition: injection.hh:131
TBranch * b_mass
Definition: injection.hh:137
Int_t GetEntries()
Definition: injection.cc:205
Float_t * mass
detector specific effective distance
Definition: injection.hh:98
size_t mdc__IDSize()
Definition: network.hh:414
TBranch * b_phi
Definition: injection.hh:123
TBranch * b_rp0
Definition: injection.hh:116
TBranch * b_factor
Definition: injection.hh:113
Int_t run
number of detectors
Definition: injection.hh:65
TBranch * b_eventID
Definition: injection.hh:108
std::vector< wavearray< double > * > IWFP
Definition: detector.hh:379
wavearray< double > TDUR
Definition: detector.hh:376
double * entry
Definition: cwb_setcuts.C:224
std::vector< int > IWFID
Definition: detector.hh:378
Float_t * phi
source iota angle
Definition: injection.hh:84
Int_t type
Definition: injection.hh:68
wavearray< double > BAND
Definition: detector.hh:374
void allocate()
Definition: injection.cc:109
TBranch * b_run
Definition: injection.hh:106
Float_t * bx
beam pattern coefficients for hp
Definition: injection.hh:87
#define MDC_TREE_NAME
Definition: injection.cc:25
TBranch * b_log
Definition: injection.hh:111
WSeries< double > * getTFmap()
param: no parameters
Definition: detector.hh:179
Float_t distance
Definition: injection.hh:73
double sTOp
char Name[16]
Definition: detector.hh:327
double fabs(const Complex &x)
Definition: numpy.cc:55
TBranch * b_strain
Definition: injection.hh:120
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
string * log
injection name
Definition: injection.hh:70
TBranch * b_gps
Definition: injection.hh:119
Float_t * bp
source theta angle
Definition: injection.hh:86
DataType_t * data
Definition: wavearray.hh:319
TBranch * b_bx
Definition: injection.hh:126
wavearray< double > FREQ
Definition: detector.hh:373
Int_t eventID
Definition: injection.hh:67
bool save
double ctime
Float_t * frequency
estimated duration
Definition: injection.hh:92
Bool_t fill_in(network *, int, bool=true)
Definition: injection.cc:349
size_t getmdc__ID(size_t n)
Definition: network.hh:426
char fName[256]
TBranch * b_mchirp
Definition: injection.hh:115
wavearray< double > ** pwf
[x1,y1,z1,x2,y2,z2] components of spin vector
Definition: injection.hh:101
TBranch * b_ndim
pointer to the reconstructed waveform
Definition: injection.hh:105
Float_t * spin
[m1,m2], binary mass parameters
Definition: injection.hh:99
TTree * fChain
root input file cointainig the mdc TTree
Definition: injection.hh:59
wavearray< double > ISNR
Definition: detector.hh:372
detector ** pD
Int_t nevent
Definition: injection.hh:66
Float_t * Deff
injected snr in the detectors
Definition: injection.hh:97
exit(0)
TBranch * b_time
Definition: injection.hh:128