Logo coherent WaveBurst  
Library Reference Guide
Logo
DrawRadiusIFAR2.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Francesco Salemi
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 //
20 // Draw Radius vs IFAR
21 // Note : this macro is used to generate the CBC report
22 // Author : Francesco Salemi
23 /*
24 #include "TROOT->h"
25 #include "TSystem->h"
26 #include "TFile->h"
27 #include "TTree->h"
28 #include <fstream>
29 #include <iostream>
30 #include "TGraph->h"
31 #include "TMultiGraph->h"
32 #include "TCanvas->h"
33 #include "TH1F->h"
34 #include "TMath->h"
35 #include "TH1F->h"
36 #include "TH2F->h"
37 #include <TComplex->h>
38 #include <TStyle->h>
39 #include <TRandom->h>
40 #include "TVector3->h"
41 #include "TRotation->h"
42 #include "Math/Vector3Dfwd->h"
43 #include "Math/Rotation3D->h"
44 */
45 
46 #define MINIFAR 0.01
47 #define MAXIFAR 1000.
48 #define MINRADIUS 0
49 #define MAXRADIUS 1000
50 //#define SEL ""
51 //#define SEL "mass[0]+mass[1]>75.75"
52 //#define SEL "mass[0]+mass[1]<27.25"
53 
54 //void DrawRadiusIFAR2(char* sim_file_name, char* mdc_file_name, float shell_volume, char* netdir, double liveTot, float T_ifar=0.0, float T_win=0.2, float internal_volume=0.0, int TRIALS = 1){
55 TGraphErrors* DrawRadiusIFAR2(char* sim_file_name, char* mdc_file_name, TString SEL, float shell_volume){
56 
57  TCanvas* co_canvas;
58  co_canvas = new TCanvas("sd2", "SD2", 3, 47, 1000, 802);
59  co_canvas->SetGridx();
60  co_canvas->SetGridy();
61  co_canvas->SetLogx();
62 
63 
64  float myifar, ecor, m1, m2, netcc[3], neted, penalty;
65  float rho[2];
66  double mytime[6];
67  float factor, distance, mchirp;
68  float mass[2];
69  float spin[6];
70  float chi[3];
71 
72  float chirp[6];
73  float range[2];
74 
75  TFile* filein = new TFile(sim_file_name);
76  TTree* sim_org = nullptr;
77  filein->GetObject("waveburst",sim_org);
78  gROOT->cd();
79  TTree* sim = sim_org->CopyTree(SEL);
80  sim->SetBranchAddress("mass", mass);
81  sim->SetBranchAddress("factor", &factor);
82  sim->SetBranchAddress("range", range);
83  sim->SetBranchAddress("chirp", chirp);
84  sim->SetBranchAddress("rho", rho);
85  sim->SetBranchAddress("netcc", netcc);
86  sim->SetBranchAddress("ifar", &myifar);
87  sim->SetBranchAddress("time", mytime);
88  sim->SetBranchAddress("spin", spin);
89 
90 
91  /*
92  TChain sim("waveburst");
93  sim->Add(sim_file_name);
94  sim->SetBranchAddress("mass", mass);
95  sim->SetBranchAddress("factor", &factor);
96  sim->SetBranchAddress("range", range);
97  sim->SetBranchAddress("chirp", chirp);
98  sim->SetBranchAddress("rho", rho);
99  sim->SetBranchAddress("netcc", netcc);
100  sim->SetBranchAddress("ifar", &myifar);
101  sim->SetBranchAddress("time", mytime);
102  sim->SetBranchAddress("spin", spin);
103 */
104 
105  TFile* filein2 = new TFile(mdc_file_name);
106  TTree* mdc_org = nullptr;
107  filein2->GetObject("mdc",mdc_org);
108  gROOT->cd();
109  TTree* mdc = mdc_org->CopyTree(SEL);
110  mdc->SetBranchAddress("time",mytime);
111  mdc->SetBranchAddress("mass", mass);
112  mdc->SetBranchAddress("factor", &factor);
113  mdc->SetBranchAddress("distance", &distance);
114  mdc->SetBranchAddress("mchirp", &mchirp);
115  mdc->SetBranchAddress("spin", spin);
116 
117 
118  int nevts = (int)mdc->GetEntries();
119  float shell_volume_per_injection = shell_volume/nevts;
120 
121  float maxIFAR = 0.0;
122  float CYS = 86400.*365.25;
123  if (sim->GetListOfBranches()->FindObject("ifar")) {
124  maxIFAR =
125  TMath::CeilNint(sim->GetMaximum("ifar") / CYS );
126  cout << "Maximum empirically estimated IFAR : " << maxIFAR << " [years]" << endl;
127  } else {
128  cout << "Missing ifar branch: either use cbc_plots or add it "
129  "to wave tree->->->"
130  << endl;
131  exit(1);
132  }
133  double dV = 0.0;
134  std::vector<double> vdv;
135  std::vector<double> vifar;
136  std::vector<double> vMtot;
137 
138  sim->BuildIndex("ifar","rho[1]"); //BEWARE rho[1] should be search depandent!
139  TTreeIndex *I1=(TTreeIndex*)sim->GetTreeIndex(); // get the tree index
140  Long64_t* index1=I1->GetIndex(); //create an array of entries in sorted order
141 
142  cout << nevts << " injected signals " << sim->GetEntries("ifar>0") << " recovered signals" <<endl;
143  int countv = 0;
144  int countvifar = 0;
145  for (int g = 0; g < (int)sim->GetEntries(); g++) {
146  sim->GetEntry(index1[g]);
147  //cout << g << " " <<index1[g] <<" " << myifar/CYS << " ";
148  if (myifar <= T_ifar * CYS) {
149  countvifar++;
150  //cout << g << " " <<index1[g] <<" " << myifar/CYS << " ";
151  continue;
152 
153  }
154 
155  if ((mytime[0] - mytime[nIFO]) < -T_win ||
156  (mytime[0] - mytime[nIFO]) > 2 * T_win) {
157  countv++;
158  continue;
159  } // NOT checking for detector 1 and 2: very small bias...
160 
161  dV = pow(range[1], 2) * shell_volume_per_injection * pow(chirp[0] / 1.22,5./6.);
162  vdv.push_back(dV+internal_volume);
163  vifar.push_back(myifar);
164  vMtot.push_back(mass[0]+mass[1]);
165 
166  }
167  cout << endl;
168  cout << countvifar << " events vetoed by T_ifar : " << T_ifar << endl;
169  cout << countv << " events vetoed by T_win" << endl;
170  cout << vdv.size() << " events selected" << endl;
171  // Int_t *mindex = new Int_t[vdv->size()];
172  // TMath::Sort((int)vdv->size(), &vifar[0], mindex, true);
173  std::vector<double> vV;
174  std::vector<double> veV;
175  std::vector<double> vR;
176  std::vector<double> veR;
177  std::vector<double> vsifar;
178  std::vector<double> vseifar;
179 
180 //cout << "DEB2" << endl;
181  vV.push_back(vdv[vdv.size()-1]);
182  veV.push_back(pow(vdv[vdv.size()-1], 2));
183  vsifar.push_back(vifar[vdv.size()-1]);
184  //cout << "DEB3" << endl;
185  // break;
186  int mcount = 0;
187  for (int i = vdv.size()-1; i >= 0; i--) {
188  if (vifar[i] == 0) {
189  continue;
190  }
191  if (vifar[i] == vsifar[mcount]) {
192  vV[mcount] += vdv[i];
193  veV[mcount] += pow(vdv[i], 2);
194  } else {
195  vsifar.push_back(vifar[i]);
196  vseifar.push_back(TMath::Sqrt(TMath::Nint(liveTot * vifar[i])));
197  vV.push_back(vV[mcount] + vdv[i]);
198  veV.push_back(veV[mcount] + pow(vdv[i], 2));
199  mcount++;
200  }
201  }
202  cout << "Length of ifar/volume vector: " << vV.size() << endl;
203  float Tscale = 1.0;
204  for (int i = 0; i < vV.size(); i++) {
205  veV[i] = TMath::Sqrt(veV[i]);
206  vfar[i] *= TRIALS * CYS;
207  vefar[i] *= TRIALS * CYS;
208  vsifar[i] /= (TRIALS * CYS);
209  vR.push_back(
210  pow(3. / (4. * TMath::Pi()* Tscale) * vV[i], 1. / 3.));
211  veR.push_back(pow(3. / (4 * TMath::Pi() * Tscale), 1. / 3.) *
212  1. / 3 * pow(vV[i], -2. / 3.) * veV[i]);
213  //cout << vsifar[i] << " " <<
214  }
215 
216 
217 
218 
219 
220  TGraphErrors *co_gr = new TGraphErrors(vR.size(), &vsifar[0], &vR[0], 0, &veR[0]);
221  co_gr->GetYaxis()->SetTitle("Sensitive Distance [Mpc]");
222  co_gr->GetXaxis()->SetTitle("Inverse False Alarm Rate [yr]");
223  co_gr->GetXaxis()->SetLimits(MINIFAR,MAXIFAR);
224  co_gr->GetYaxis()->SetRangeUser(MINRADIUS,MAXRADIUS);
225  co_gr->GetXaxis()->SetTitleOffset(1.3);
226  co_gr->GetYaxis()->SetTitleOffset(1.25);
227  co_gr->GetXaxis()->SetTickLength(0.01);
228  co_gr->GetYaxis()->SetTickLength(0.01);
229  co_gr->GetXaxis()->CenterTitle(kTRUE);
230  co_gr->GetYaxis()->CenterTitle(kTRUE);
231  co_gr->GetXaxis()->SetTitleFont(42);
232  co_gr->GetXaxis()->SetLabelFont(42);
233  co_gr->GetYaxis()->SetTitleFont(42);
234  co_gr->GetYaxis()->SetLabelFont(42);
235  co_gr->SetMarkerStyle(20);
236  co_gr->SetMarkerSize(1.0);
237  co_gr->SetMarkerColor(1);
238  co_gr->SetLineColor(kBlue);
239  co_gr->SetTitle("");
240  co_gr->SetFillColor(kBlue);
241  co_gr->SetFillStyle(3001);
242  // h->Draw("e2same");
243  co_gr->Draw("aple3");
244 
245 
246 
247 
248  /* char fname[1024];
249  sprintf(fname, "%s/ROC_IFAR2.png", netdir);
250  co_canvas->Update();
251  co_canvas->SaveAs(fname);
252 */
253  return co_gr;
254  //exit(0);
255 
256 }
257 
double rho
#define MAXIFAR
float Tscale
double T_ifar
TChain sim("waveburst")
static double g(double e)
Definition: GNGen.cc:116
int mcount
std::vector< double > vseifar
float factor
double m1
TH1F * ecor
TString("c")
#define MINIFAR
float CYS
TString mdc[4]
std::vector< double > vR
i drho i
std::vector< double > vdv
#define MAXRADIUS
#define nIFO
std::vector< double > vfar
i() int(T_cor *100))
double Pi
std::vector< double > vsifar
cout<< fileout<< endl;out.open(fileout, ios::out);if(!out.good()) { cout<< "cwb_mkhtml_cbc.C : Error Opening File : "<< fileout<< endl;exit(1);} out<< "<br><br><< endl; MakePlotsHtmlCellTable( &out, "Effective Radii", "data/Effective_radius.png", "Effective radius:m1 vs m2", "data/Effective_radius_chi.png", "Effective radius:M< sub > total</sub > vs & chi
float mchirp
std::vector< double > veR
double liveTot
std::vector< double > vifar
float spin[6]
#define MINRADIUS
char sim_file_name[1024]
TGraphErrors * DrawRadiusIFAR2(char *sim_file_name, char *mdc_file_name, TString SEL, float shell_volume)
std::vector< double > veV
double T_win
cout<< endl;if(write_ascii) { fev.close();for(int l=0;l< nfactor;l++) { fev_single[l].close();} } cout<< "Recovered entries: "<< cnt<< endl;cout<< "Recovered entries: "<< cnt2<< endl;cout<< "Recovered entries cut by frequency: "<< cntfreq<< endl;cout<< "Recovered entries vetoed: "<< countv<< endl;cout<< "dV : "<< dV<< " dV1 : "<< dV1<< endl;internal_volume=4./3. *TMath::Pi() *pow(minDistance[0]/1000., 3.);if(INCLUDE_INTERNAL_VOLUME) { for(int i=0;i< vdv.size();i++) { if(vdv[i] > 0.0) { vdv[i]+=internal_volume;} } for(int i=0;i< RHO_NBINS;i++) { if(Vrho[i] > 0.0) { Vrho[i]+=internal_volume;} } for(int i=0;i< NBINS_MTOT+1;i++) { for(int j=0;j< NBINS_SPIN+1;j++) { if(spin_mtot_volume[i][j] > 0.0) { spin_mtot_volume[i][j]+=internal_volume;} } } for(int i=0;i< NBINS_mass;i++) { for(int j=0;j< NBINS_mass2;j++) { if(volume[i][j] > 0.0) { volume[i][j]+=internal_volume;} } } } Int_t *mindex=new Int_t[vdv.size()];TMath::Sort((int) vdv.size(), &vifar[0], mindex, true);std::vector< double > vV
double mytime[6]
double m2
float distance
float mass[2]
float * shell_volume
char mdc_file_name[1024]
std::vector< double > vefar
TCanvas * co_canvas
int TRIALS
exit(0)