Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DrawCoverageVsPercentagePRC.C
Go to the documentation of this file.
1 //
2 // Draw Error Regions Percentage vs Coverage
3 // Note : this macro is used to generate the PRC report (cwb_report merge_label prc)
4 // Author : Gabriele Vedovato
5 
6 
7 #define NMDC 1
8 
9 //#define DUMP_ASCII
10 
11 double GetPercentage(TString gtype, int iderA, TString fname, int nIFO, float T_win, int pp_inetcc,
12  float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar);
13 
14 void
16  int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar) {
17 
18  if(gtype!="nre" && gtype!="prc" && gtype!="fre") {
19  cout << "DrawCoverageVsPercentagePRC : Error - wrong input gtype (prc/nre/fre)" << endl;
20  gSystem->Exit(1);
21  }
22 
23 
24  char wave_file_name[1024];
25  sprintf(wave_file_name,"merge/wave_%s.%s.root",data_label.Data(),merge_label.Data());
26 
27  TObjArray* token = TString(wave_file_name).Tokenize(TString('/'));
28  TObjString* sfile = (TObjString*)token->At(token->GetEntries()-1);
29  TString ofile = sfile->GetString();
30  ofile.ReplaceAll(".root",".txt");
31  //TString TITLE = sfile->GetString();
32  //TITLE.ReplaceAll(".root","");
33  TString TITLE = "";
34  if(gtype=="prc") TITLE = "pp-plot-prc";
35  if(gtype=="nre") TITLE = "pp-plot-nre";
36  if(gtype=="fre") TITLE = "pp-plot-fre";
37 
38 #ifdef DUMP_ASCII
39  char ofname[1024];
40  if(gtype=="prc") sprintf(ofname,"%s/pp_plot_prc.txt",odir.Data());
41  if(gtype=="nre") sprintf(ofname,"%s/pp_plot_nre.txt",odir.Data());
42  if(gtype=="fre") sprintf(ofname,"%s/pp_plot_fre.txt",odir.Data());
43  ofstream out;
44  out.open(ofname,ios::out);
45  if (!out.good()) {cout << "Error Opening File : " << ofname << endl;exit(1);}
46  cout << "Create file : " << ofname << endl;
47 #endif
48 
49  // if coverage > percentage then erA is too large, the true erA is smaller (erA is conservative)
50  // if coverage < percentage then erA is too small, the true erA is greater (erA is optimistic)
51 
52  double coverage[NMDC][11];
53  for (int i=0;i<NMDC;i++) {
54  coverage[i][0]=0.;
55  coverage[i][10]=100.;
56  for (int j=1;j<10;j++) {
57  coverage[i][j]=GetPercentage(gtype, j,wave_file_name, nIFO, T_win, pp_inetcc,
58  T_cor, pp_irho, T_cut, T_vED, T_pen, T_ifar);
59  if(coverage[i][j]<0) return; // tree do not contains the branch (for example the nre erR array)
60 #ifdef DUMP_ASCII
61  out << j*10 << " " << coverage[i][j] << endl;
62 #endif
63  cout << j*10 << " " << coverage[i][j] << endl;
64  }
65  }
66 #ifdef DUMP_ASCII
67  out.close();
68 #endif
69 
70  TCanvas* canvas = new TCanvas("fom", "PRC", 300,40, 600, 600);
71  canvas->Clear();
72  canvas->ToggleEventStatus();
73  canvas->SetFillColor(0);
74  canvas->SetGridx();
75  canvas->SetGridy();
76  canvas->SetLogy(false);
77  canvas->SetLogx(false);
78 
79  gStyle->SetTitleH(0.062);
80  gStyle->SetTitleW(0.98);
81  gStyle->SetTitleY(0.98);
82  gStyle->SetTitleFont(72);
83  gStyle->SetLineColor(kWhite);
84  gStyle->SetPalette(1,0);
85  gStyle->SetNumberContours(256);
86 
87  Style_t markers[32]= {20,21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,
88  21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,20 };
89 
90  Color_t colors[32] = { 6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7,
91  6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7 };
92 
93  double perc[11]={0,10,20,30,40,50,60,70,80,90,100};
94  TGraph* gr[NMDC+11];
95  for(int i=0;i<NMDC;i++) {
96  gr[i] = new TGraph(11,perc,coverage[i]);
97  gr[i]->SetLineColor(colors[i]);
98  gr[i]->SetLineWidth(1);
99  gr[i]->SetMarkerSize(1);
100  gr[i]->SetMarkerColor(colors[i]);
101  gr[i]->SetMarkerStyle(markers[i]);
102  }
103  double x[2]={0,100};
104  double y[2]={0,100};
105  gr[NMDC+1] = new TGraph(2,x,y);
106  gr[NMDC+1]->SetLineColor(1);
107  gr[NMDC+1]->SetLineWidth(2);
108  gr[NMDC+1]->SetLineStyle(2);
109 
110  TMultiGraph* mg = new TMultiGraph();
111  for(int i=0;i<NMDC;i++) mg->Add(gr[i],"lp");
112  mg->Add(gr[NMDC+1],"lp");
113  mg->Paint("ap");
114  char title[256];
115  sprintf(title,"%s",TITLE.Data());
116  mg->GetHistogram()->SetTitle(title);
117  mg->GetHistogram()->GetXaxis()->SetTitle("Percentage");
118  mg->GetHistogram()->GetYaxis()->SetTitle("Coverage");
119  mg->GetHistogram()->GetXaxis()->SetRangeUser(0,100);
120  mg->GetHistogram()->GetYaxis()->SetRangeUser(0,100);
121  mg->GetHistogram()->GetXaxis()->SetTitleOffset(1.3);
122  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.3);
123  mg->GetHistogram()->GetXaxis()->CenterTitle(true);
124  mg->GetHistogram()->GetYaxis()->CenterTitle(true);
125  mg->GetHistogram()->GetXaxis()->SetLabelFont(42);
126  mg->GetHistogram()->GetXaxis()->SetTitleFont(42);
127  mg->GetHistogram()->GetYaxis()->SetLabelFont(42);
128  mg->GetHistogram()->GetYaxis()->SetTitleFont(42);
129  mg->GetHistogram()->GetXaxis()->SetNdivisions(511);
130  mg->Draw("a");
131 
132  TLegend* leg;
133  double hleg = 0.8-NMDC*0.05;
134  leg = new TLegend(0.1291513,hleg,0.6244966,0.8738739,NULL,"brNDC");
135 
136  leg->SetBorderSize(1);
137  leg->SetTextAlign(22);
138  leg->SetTextFont(12);
139  leg->SetLineColor(1);
140  leg->SetLineStyle(1);
141  leg->SetLineWidth(1);
142  leg->SetFillColor(0);
143  leg->SetFillStyle(1001);
144  leg->SetTextSize(0.04);
145  leg->SetLineColor(kBlack);
146  leg->SetFillColor(kWhite);
147 
148  char label[256];
149  for(int i=0;i<NMDC;i++) {
150  sprintf(label,"%s ",data_label.Data());
151  leg->AddEntry(gr[i],label,"lp");
152  }
153 // leg->Draw();
154 
155  char ofname[1024];
156  if(gtype=="prc") sprintf(ofname,"%s/pp_plot_prc.gif",odir.Data());
157  if(gtype=="nre") sprintf(ofname,"%s/pp_plot_nre.gif",odir.Data());
158  if(gtype=="fre") sprintf(ofname,"%s/pp_plot_fre.gif",odir.Data());
159  TString gfileName=ofname;
160  canvas->Print(gfileName);
161  TString pfileName=gfileName;
162  pfileName.ReplaceAll(".gif",".png");
163  char cmd[1024];
164  sprintf(cmd,"convert %s %s",gfileName.Data(),pfileName.Data());
165  cout << cmd << endl;
166  gSystem->Exec(cmd);
167  sprintf(cmd,"rm %s",gfileName.Data());
168  cout << cmd << endl;
169  gSystem->Exec(cmd);
170  //exit(0);
171 }
172 
173 double GetPercentage(TString gtype, int iderA, TString fname, int nIFO, float T_win, int pp_inetcc,
174  float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar) {
175 
176  TFile *ifile = TFile::Open(fname.Data());
177  TTree* itree = (TTree *) gROOT->FindObject("waveburst");
178  itree->SetEstimate(itree->GetEntries());
179 
180  // check if erR exist
181  if(gtype=="nre") {
182  TString nre_name="erR";
183  TBranch* branch;
184  bool nre_exist=false;
185  TIter next(itree->GetListOfBranches());
186  while ((branch=(TBranch*)next())) {
187  if (nre_name.CompareTo(branch->GetName())==0) nre_exist=true;
188  }
189  if(!nre_exist) return -1;
190  }
191 
192  // check if erF exist
193  if(gtype=="fre") {
194  TString fre_name="erF";
195  TBranch* branch;
196  bool fre_exist=false;
197  TIter next(itree->GetListOfBranches());
198  while ((branch=(TBranch*)next())) {
199  if (fre_name.CompareTo(branch->GetName())==0) fre_exist=true;
200  }
201  if(!fre_exist) return -1;
202  }
203 
204  char selection[1024];
205  char cut[1024];
206  char tmp[1024];
207  sprintf(cut,"abs(time[0]-time[%d])<%f && netcc[%d]>%f && rho[%d]>%f",
208  nIFO,T_win,pp_inetcc,T_cor,pp_irho,T_cut);
209  if(T_vED>0) {strcpy(tmp,cut);sprintf(cut,"%s && neted[0]/ecor<%f",tmp,T_vED);}
210  if(T_pen>0) {strcpy(tmp,cut);sprintf(cut,"%s && penalty>%f",tmp,T_pen);}
211  if(T_ifar>0) {strcpy(tmp,cut);sprintf(cut,"%s && ifar>(24.*3600.*365.)*%f",tmp,T_ifar);}
212  //cout << cut << endl;
213 
214  if(gtype=="prc") sprintf(selection,"erA[0]-erA[%d]>>hist_cumulative_erA1(2000,-100,100)",iderA);
215  if(gtype=="nre") sprintf(selection,"erR[0]-erR[%d]>>hist_cumulative_erA1(2000,-1,1)",iderA);
216  if(gtype=="fre") sprintf(selection,"erF[0]-erF[%d]>>hist_cumulative_erA1(2000,-1,1)",iderA);
217 
218  itree->Draw(selection,cut,"goff");
219  TH1F *hist_cumulative_erA1 = (TH1F*)gDirectory->Get("hist_cumulative_erA1");
220  int size = itree->GetSelectedRows();
221  //cout << "size : " << size << endl;
222  if(size==0) {
223  delete hist_cumulative_erA1;
224  delete itree;
225  delete ifile;
226  return 0;
227  }
228 
229  double integral = hist_cumulative_erA1->ComputeIntegral();
230  if (integral==0) {cout << "Empty histogram !!!" << endl;exit(0);}
231  double* cumulative = hist_cumulative_erA1->GetIntegral();
232  for (int i=0;i<hist_cumulative_erA1->GetNbinsX();i++) hist_cumulative_erA1->SetBinContent(i,cumulative[i]/integral);
233  //cout << "integral " << integral << endl;
234 
235 
236  double perc = 100.*hist_cumulative_erA1->GetBinContent(1001);
237  delete hist_cumulative_erA1;
238  delete itree;
239  delete ifile;
240  //ifile->Close();
241 
242  return perc;
243 }
244 
char cut[512]
double T_ifar
double T_pen
char cmd[1024]
TString("c")
#define TITLE
Definition: TestSiteJ1.C:44
double T_cor
TLegend * leg
Definition: compare_bkg.C:246
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
char odir[1024]
return wmap canvas
i pp_inetcc
Long_t size
Color_t colors[16]
char ofile[512]
int j
Definition: cwb_net.C:10
i drho i
ofstream out
Definition: cwb_merge.C:196
char data_label[512]
Definition: test_config1.C:160
TGraph * gr
void DrawCoverageVsPercentagePRC(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)
TString label
Definition: MergeTrees.C:21
double * tmp
Definition: testWDM_5.C:31
TIter next(twave->GetListOfBranches())
char fname[1024]
TString merge_label
TObjArray * token
#define nIFO
#define NMDC
TFile * ifile
char title[256]
Definition: SSeriesExample.C:1
double T_win
TBranch * branch
double GetPercentage(TString gtype, int iderA, TString fname, 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)
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double T_cut
TTree * itree
double T_vED
wavearray< double > y
Definition: Test10.C:31
TMultiGraph * mg
i drho pp_irho
exit(0)