Logo coherent WaveBurst  
Library Reference Guide
Logo
DrawRECvsINJ.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 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 //
20 // Draw injected vs detected events distributions vs SNRnet
21 // Note : this macro is used to generate the PRC report (cwb_report merge_label prc)
22 // Author : Gabriele Vedovato
23 
24 namespace DrawRECvsINJ_namespace { // used to avoid conflict with global variables
25 
26 #include <vector>
27 
28 void RECvsINJ(int mtype, TString gtype, TString ptitle, TString xtitle, TString ytitle, int nIFO, float T_win,
29  int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar);
30 
31 // --------------------------------------------------------
32 // Global variables
33 // --------------------------------------------------------
34 TCanvas* gCANVAS = NULL; // canvas object
35 TTree* gTRWAVE = NULL; // wave tree
36 TTree* gTRMDC = NULL; // mdc tree
37 
38 
39 void
41  int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar) {
42 
43  if(gtype!="distance" && gtype!="snr") {
44  cout << "DrawRECvsINJ : Error - wrong input gtype (snr/distance)" << endl;
45  gSystem->Exit(1);
46  }
47 
48  // ------------------------------------------------
49  // create canvas
50  // ------------------------------------------------
51  gCANVAS = new TCanvas("fom", "PRC", 300,40, 600, 500);
52  gCANVAS->Range(-19.4801,-9.25,-17.4775,83.25);
53  gCANVAS->SetBorderSize(2);
54  gCANVAS->SetFrameFillColor(0);
55  gCANVAS->SetGridx();
56  gCANVAS->SetGridy();
57 
58  // ------------------------------------------------
59  // open wave/mdc trees
60  // ------------------------------------------------
61  // open wave file
62  char sim_file_name[1024];
63  sprintf(sim_file_name,"merge/wave_%s.%s.root",data_label.Data(),merge_label.Data());
64  TFile* fwave = TFile::Open(sim_file_name);
65  gTRWAVE = (TTree*) gROOT->FindObject("waveburst");
66  // open mdc file
67  char mdc_file_name[1024];
68  sprintf(mdc_file_name,"merge/mdc_%s.%s.root",data_label.Data(),merge_label.Data());
69  TFile *fmdc = TFile::Open(mdc_file_name);
70  gTRMDC = (TTree*) gROOT->FindObject("mdc");
71 
72  TString ptitle;
74  TString ytitle;
75 
76  if(gtype=="snr") gCANVAS->SetLogx(true);
77  gCANVAS->SetLogy(true);
78  ptitle="Reconstructed events vs Injected events";
79  gStyle->SetOptStat(0);
80  //if(nIFO==2) xtitle = "sqrt(hrss[0]^2+hrss[1]^2)";
81  //if(nIFO==3) xtitle = "sqrt(hrss[0]^2+hrss[1]^2+hrss[2]^2)";
82  xtitle = gtype=="snr" ? "Injected SNRnet" : "distance (Mpc)";
83  ytitle = "counts";
84 
85  RECvsINJ(0, gtype, ptitle, xtitle, ytitle, nIFO, T_win, pp_inetcc, T_cor, pp_irho, T_cut, T_vED, T_pen, T_ifar);
86 
87  char ofname[1024];
88  if(gtype=="snr") {
89  sprintf(ofname,"%s/inj_vs_rec_snr.gif",odir.Data());
90  } else {
91  sprintf(ofname,"%s/inj_vs_rec_distance.gif",odir.Data());
92  }
93  gCANVAS->Print(ofname);
94  char cmd[1024];
95  TString pfname(ofname);
96  pfname.ReplaceAll(".gif",".png");
97  sprintf(cmd,"convert %s %s",ofname,pfname.Data());
98  cout << cmd << endl;
99  gSystem->Exec(cmd);
100  sprintf(cmd,"rm %s",ofname);
101  cout << cmd << endl;
102  gSystem->Exec(cmd);
103  //exit(0);
104 
105 }
106 
107 void RECvsINJ(int mtype, TString gtype, TString ptitle, TString xtitle, TString ytitle, int nIFO, float T_win,
108  int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar) {
109 
110  char sel[256]="";
111  char tmp[256]="";
112  char cut[256]="";
113  char title[256]="";
114 
115  // INJECTED
116  sprintf(cut,"");
117  if(gtype=="snr") {
118  strcpy(tmp,"snr[0]*snr[0]");
119  for(int i=1;i<nIFO;i++) {sprintf(sel,"%s+snr[%d]*snr[%d]",tmp,i,i);strcpy(tmp,sel);}
120  strcpy(tmp,sel);sprintf(sel,"sqrt(%s)>>hist(10000,1,10000)",tmp);
121  } else {
122  double dmin = gTRMDC->GetMinimum("distance");
123  double dmax = gTRMDC->GetMaximum("distance");
124  sprintf(sel,"distance>>hist(30,%f,%f)",dmin,dmax);
125  }
126  gTRMDC->Draw(sel,cut,"");
127  int nmdc = gTRMDC->GetSelectedRows();
128  cout << "nmdc : " << nmdc << endl;
129 
130  TH2F *htemp = (TH2F*)gPad->GetPrimitive("hist");
131  htemp->GetXaxis()->SetTitle(xtitle);
132  htemp->GetYaxis()->SetTitle(ytitle);
133  //htemp->GetXaxis()->SetRangeUser(4e-25,1e-21);
134  if(gtype=="snr") {
135  htemp->GetYaxis()->SetRangeUser(0.1, pow(10.,TMath::Ceil(TMath::Log10(htemp->GetMaximum()))));
136  } else {
137  htemp->GetXaxis()->SetRangeUser(gTRMDC->GetMinimum("distance"),gTRMDC->GetMaximum("distance"));
138  htemp->SetMinimum(0.9);
139  }
140  htemp->GetXaxis()->SetTitleOffset(1.35);
141  htemp->GetYaxis()->SetTitleOffset(1.35);
142  htemp->GetXaxis()->CenterTitle(true);
143  htemp->GetYaxis()->CenterTitle(true);
144  htemp->GetXaxis()->SetLabelFont(42);
145  htemp->GetXaxis()->SetTitleFont(42);
146  htemp->GetYaxis()->SetLabelFont(42);
147  htemp->GetYaxis()->SetTitleFont(42);
148 
149 
150  // DETECTED
151  if(gtype=="snr") {
152  strcpy(tmp,"iSNR[0]");
153  for(int i=1;i<nIFO;i++) {sprintf(sel,"%s+iSNR[%d]",tmp,i);strcpy(tmp,sel);}
154  strcpy(tmp,sel);sprintf(sel,"sqrt(%s)",tmp);
155  } else {
156  sprintf(sel,"range[1]");
157  }
158  sprintf(cut,"abs(time[0]-time[%d])<%g && netcc[%d]>%g && rho[%d]>%g",
159  nIFO,T_win,pp_inetcc,T_cor,pp_irho,T_cut);
160  if(T_vED>0) {strcpy(tmp,cut);sprintf(cut,"%s && neted[0]/ecor<%f",tmp,T_vED);}
161  if(T_pen>0) {strcpy(tmp,cut);sprintf(cut,"%s && penalty>%f",tmp,T_pen);}
162  if(T_ifar>0) {strcpy(tmp,cut);sprintf(cut,"%s && ifar>(24.*3600.*365.)*%f",tmp,T_ifar);}
163  gTRWAVE->SetLineColor(kRed);
164  gTRWAVE->SetFillColor(kRed);
165  gTRWAVE->Draw(sel,cut,"same");
166  int nwave = gTRWAVE->GetSelectedRows();
167  cout << "nwave : " << nwave << endl;
168  sprintf(title,"%s",cut);
169 
170  sprintf(title,"%s : inj = %d : rec : %d",ptitle.Data(),nmdc,nwave);
171  htemp->SetTitle(title);
172 
173 /*
174  // print plot
175  char ofname[256];
176  if(mtype==0) {
177  sprintf(ofname,"%s/%s_%s.png",
178  gODIR.Data(),gPTYPE.Data(),"ALL");
179  } else {
180  sprintf(ofname,"%s/%s_%s.png",
181  gODIR.Data(),gPTYPE.Data(),gMDC->wfList[mtype-1].name.Data());
182  }
183  cout << ofname << endl;
184  gCANVAS->Print(ofname);
185 */
186 
187  return;
188 }
189 
190 } // end namespace
191 
192 void
194  int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar) {
195 
196  DrawRECvsINJ_namespace::DrawRECvsINJ(gtype, data_label, odir, merge_label, nIFO, T_win,
197  pp_inetcc, T_cor, pp_irho, T_cut, T_vED, T_pen, T_ifar);
198  return;
199 }
double T_ifar
char xtitle[1024]
void DrawRECvsINJ(TString gtype, TString data_label, TString odir, TString merge_label, int nIFO, float T_win, int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar)
Definition: DrawRECvsINJ.C:40
double T_pen
TString("c")
double T_cor
char odir[1024]
i pp_inetcc
i drho i
int nmdc
#define nIFO
vector< int > mtype
Definition: cwb_report_pe.C:66
char data_label[512]
Definition: test_config1.C:160
double * tmp
Definition: testWDM_5.C:31
char cut[512]
TString merge_label
int nwave
TString sel("slag[1]:slag[2]")
void RECvsINJ(int mtype, TString gtype, TString ptitle, TString xtitle, TString ytitle, int nIFO, float T_win, int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar)
Definition: DrawRECvsINJ.C:107
char sim_file_name[1024]
char title[256]
Definition: SSeriesExample.C:1
double T_win
char cmd[1024]
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double T_cut
double T_vED
char mdc_file_name[1024]
i drho pp_irho