Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MakeFARvsRHO.C
Go to the documentation of this file.
1 #define XIFO 4
2 
3 #pragma GCC system_header
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TTree.h"
8 #include "TSystem.h"
9 #include "TString.h"
10 #include "TObjArray.h"
11 #include "TObjString.h"
12 #include "TRandom.h"
13 #include "TComplex.h"
14 #include "TMath.h"
15 #include "TCut.h"
16 #include <fstream>
17 #include <vector>
18 #include "Toolbox.hh"
19 #include "wavearray.hh"
20 
21 // used to generate "far vr rho" file
22 void
23 MakeFARvsRHO(TString bin, TString wave_file, double bkg_livetime, TString ofName, bool ocolumns2=true) {
24 
25  #include "../../cwb/postproduction/O1/GW150914_search_bins.hh"
26 
27  bin.ToUpper();
28  if(bin!="UNMODELED" && bin!="CONSTRAINED" && bin!="CHIRP" && bin!="EUNMODELED" && bin!="ECONSTRAINED") {
29  cout << "MakeFAR - Error : bin not defined !!!" << endl;
30  gSystem->Exit(1);
31  }
32 
33  if(bkg_livetime<=0) {
34  cout << "MakeFAR - Error : bkg_livetime <= 0 !!!" << endl;
35  gSystem->Exit(1);
36  }
37 
38  CWB::Toolbox::checkFile(wave_file);
39 
40  TString selection = "";
41  if(bin=="UNMODELED") selection = unmodeled.GetTitle();
42  if(bin=="CONSTRAINED") selection = constrained.GetTitle();
43  if(bin=="CHIRP") selection = chirp.GetTitle();
44  if(bin=="EUNMODELED") selection = eunmodeled.GetTitle();
45  if(bin=="ECONSTRAINED") selection = econstrained.GetTitle();
46 
47  TFile *wfile = TFile::Open(wave_file.Data());
48  TTree* twave = (TTree *) gROOT->FindObject("waveburst");
49 
50  char sel[1024];
51  sprintf(sel,selection.Data());
52  sprintf(sel,"%s && (lag[2]!=0 || slag[2]!=0)", sel);
53  cout << sel << endl;
54 
55  twave->Draw("rho[0]",sel,"goff");
56  double* trho = twave->GetV1();
57  int N = twave->GetSelectedRows();
58  cout << "N " << N << endl;
59 
60  int pp_rho_min = 7;
61  int pp_rho_max = 500;
62  float pp_rho_wbin = 0.01;
63  int pp_rho_bin = float(pp_rho_max-pp_rho_min)/pp_rho_wbin;
64  double drho = double(pp_rho_max-pp_rho_min)/double(pp_rho_bin);
65 
66  wavearray<double> Xcut(pp_rho_bin);
67  wavearray<double> Ycut(pp_rho_bin); Ycut = 0.;
68  for(int j=0; j<Xcut.size(); j++) {
69  Xcut.data[j] = pp_rho_min+j*drho;
70  for(int i=0; i<N; i++) {
71  if(trho[i] > Xcut.data[j]) {Ycut.data[j] += 1.;}
72  }
73  }
74 
75  vector<double> rho,far;
76  for(int j=Xcut.size()-1; j>=0; j--) {
77  if (Ycut[j]<=0) continue;
78  rho.push_back(Xcut[j]);
79  far.push_back(Ycut[j]);
80  }
81 
82  // write output file
83  ofstream outa;
84  outa.open(ofName.Data(),ios::out);
85  if(!outa.good()) {cout << "Error Opening File " << ofName << endl;exit(1);}
86  //outa << "RHO" << "\t\t" << "1/years" << "\t\t" << "e_RHO" << "\t" << "e_1/years" << endl << endl;
87  for(int i=0;i<Xcut.size(); i++) if (Ycut[i]>0) {
88  double x = Xcut[i];
89  double ex = 0;
90  double y = Ycut[i]/bkg_livetime;
91  double ey = sqrt(Ycut[i])/bkg_livetime;
92  if(ocolumns2) { // 2 columns
93  if(y>=1) outa << x << "\t\t" << y << endl;
94  if(y<1) outa << x << "\t\t" << y << endl;
95  } else { // 4 columns
96  //cout << i << " " << x << " " << y << " " << ex << " " << ey << endl;
97  if(y>=1) outa << x << "\t\t" << y << "\t\t" << ex << "\t" << ey << endl;
98  if(y<1) outa << x << "\t\t" << y << "\t" << ex << "\t" << ey << endl;
99  }
100  }
101  outa.close();
102 
103  return;
104 }
105 
double rho
virtual size_t size() const
Definition: wavearray.hh:127
TCut chirp
TString ofName
TCut unmodeled
TString("c")
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
int j
Definition: cwb_net.C:10
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
#define N
ofstream out
Definition: cwb_merge.C:196
void MakeFARvsRHO(TString bin, TString wave_file, double bkg_livetime, TString ofName, bool ocolumns2=true)
Definition: MakeFARvsRHO.C:23
TFile * wfile
wavearray< double > Ycut(pp_rho_bin)
wavearray< double > Xcut(pp_rho_bin)
double pp_rho_min
TCut eunmodeled
pp_rho_bin
double pp_rho_max
TString sel("slag[1]:rho[1]")
TCut econstrained
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
TCut constrained
DataType_t * data
Definition: wavearray.hh:301
wavearray< double > y
Definition: Test10.C:31
exit(0)