Logo coherent WaveBurst  
Library Reference Guide
Logo
DrawROCxPE.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 // this macro produces the PE ROC plot
19 //
20 // How to use: root 'DrawROCPE("roc_config.txt")'
21 //
22 // roc_config.txt format
23 //
24 // signal_statistic_1.txt noise_statistic_1.txt roc#1
25 // signal_statistic_2.txt noise_statistic_2.txt roc#2
26 //
27 // the files *_statistic_*.txt are produced in the final output directory by the cwb_pereport command
28 // - */distributions/pestat_ResidualEnergy_statistic.txt
29 //
30 // roc#* are the labels displayed in the output plot legend
31 //
32 
33 
34 #define nROC_MAX 10
35 #define wSIZE 100
36 
37 int readStatistic(TString fname, vector<float>& vstat) ;
38 int readConfig(TString fname, vector<TString>& vfsignal, vector<TString>& vfnoise, vector<TString>& vname);
39 void PlotROC(int nroc, TString ofname="");
40 
42 
45 
47 
48 void DrawROCxPE(TString ifname, TString ofname="") {
49 
50  // init blind colors
51  gCOLOR[0] = CWB::Toolbox::getTableau10BlindColor("DeepSkyBlue4");
52  gCOLOR[1] = CWB::Toolbox::getTableau10BlindColor("DarkOrange1");
61 
62  vector<TString> vfsignal;
63  vector<TString> vfnoise;
64  vector<TString> vname;
65  int nROC = readConfig(ifname, vfsignal, vfnoise, vname);
66 
67  for(int n=0;n<nROC;n++) {
68 
69  gNAME[n] = vname[n];
70  gNAME[n].ReplaceAll("*"," ");
71 
72  vector<float> vsignal;
73  vector<float> vnoise;
74 
75  int nsignal = readStatistic(vfsignal[n], vsignal);
76  int nnoise = readStatistic(vfnoise[n], vnoise);
77 
78  wSIGNAL[n].resize(wSIZE);
79  wNOISE[n].resize(wSIZE);
80 
81  wSIGNAL[n]=1.0;
82 
83  float dthr = vnoise[vnoise.size()-1]/wSIZE;
84 
85  for(int i=0;i<wSIZE;i++) {
86 
87  float thr = i*dthr;
88 
89  int isignal=0;
90  for(int j=vsignal.size();j>=0;j--) if(vsignal[j]>thr) isignal++;
91  int inoise=0;
92  for(int j=vnoise.size();j>=0;j--) if(vnoise[j]>thr) inoise++;
93 
94  wSIGNAL[n][i] = (float)isignal/(float)vsignal.size();
95  wNOISE[n][i] = (float)inoise/(float)vnoise.size();
96  }
97  }
98 
99  PlotROC(nROC, ofname);
100 }
101 
102 void PlotROC(int nROC, TString ofname) {
103 
104  // create plots
105  gStyle->SetFrameBorderMode(0); // remove the red box around canvas
106  gROOT->ForceStyle();
107 
108  gStyle->SetMarkerColor(50);
109  gStyle->SetLineColor(kWhite);
110  gStyle->SetTitleW(0.98);
111  gStyle->SetTitleH(0.05);
112  gStyle->SetTitleY(0.98);
113  gStyle->SetFillColor(kWhite);
114  gStyle->SetLineColor(kWhite);
115  gStyle->SetTitleFont(12,"D");
116 // gStyle->SetTitleSize(0.18);
117 
118  TCanvas *canvas = new TCanvas("ROC", "ROC", 300, 40, 800, 500);
119  canvas->Clear();
120  canvas->ToggleEventStatus();
121  canvas->SetLogx();
122  canvas->SetLogy();
123  canvas->SetGridx();
124  canvas->SetGridy();
125  canvas->SetFillColor(kWhite);
126 
127  double xmin=2e20;
128  double xmax=0;
129  double ymin=2e20;
130  double ymax=0;
131  TGraph* gr[nROC_MAX];
132  for(int n=0;n<nROC;n++) {
133  gr[n] = new TGraph(wSIZE,wNOISE[n].data,wSIGNAL[n].data);
134  for(int i=0;i<wSIZE;i++) {
135  if(wNOISE[n][i]<xmin) xmin=wNOISE[n][i];
136  if(wNOISE[n][i]<xmax) xmax=wNOISE[n][i];
137  if(wSIGNAL[n][i]<ymin) ymin=wSIGNAL[n][i];
138  if(wSIGNAL[n][i]<ymax) ymax=wSIGNAL[n][i];
139  }
140  }
141 
142  for(int n=0;n<nROC;n++) {
143  gr[n]->SetLineWidth(2);
144  gr[n]->SetMarkerColor(gCOLOR[n]);
145  gr[n]->SetMarkerStyle(20);
146  gr[n]->SetMarkerSize(0.0);
147  gr[n]->SetLineColor(gCOLOR[n]);
148  gr[n]->SetLineStyle(1);
149  }
150 
151  TMultiGraph* mg = new TMultiGraph();
152  char gTitle[256];
153  sprintf(gTitle,"ROC");
154  mg->SetTitle(gTitle);
155  for(int n=0;n<nROC;n++) mg->Add(gr[n]);
156  //mg->Paint("APL");
157  mg->Paint("AP");
158 
159  mg->GetHistogram()->GetXaxis()->SetLabelSize(0.04);
160  mg->GetHistogram()->GetYaxis()->SetLabelSize(0.04);
161  mg->GetHistogram()->GetXaxis()->SetTitleSize(0.04);
162  mg->GetHistogram()->GetYaxis()->SetTitleSize(0.04);
163  mg->GetHistogram()->GetXaxis()->SetLabelFont(42);
164  mg->GetHistogram()->GetYaxis()->SetLabelFont(42);
165  mg->GetHistogram()->GetYaxis()->SetLabelOffset(0.01);
166  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.5);
167 
168  mg->GetHistogram()->GetXaxis()->SetRangeUser(xmin,xmax);
169  mg->GetHistogram()->GetYaxis()->SetRangeUser(ymin,ymax);
170 
171  mg->GetHistogram()->GetYaxis()->SetNdivisions(509);
172 
173  mg->GetXaxis()->SetTitle(gr[0]->GetXaxis()->GetTitle());
174  mg->GetXaxis()->SetLabelFont(42);
175  mg->GetYaxis()->SetLabelFont(42);
176  mg->GetXaxis()->SetTitleFont(42);
177  mg->GetYaxis()->SetTitleFont(42);
178  mg->GetXaxis()->SetTitleOffset(0.70);
179  mg->GetYaxis()->SetTitleOffset(0.80);
180  mg->GetXaxis()->SetTitleSize(0.06);
181  mg->GetYaxis()->SetTitleSize(0.06);
182  mg->GetXaxis()->SetTitle("p-value");
183  mg->GetYaxis()->SetTitle("efficiency");
184  mg->GetXaxis()->CenterTitle(true);
185  mg->GetYaxis()->CenterTitle(true);
186 
187  mg->Draw("ALP");
188 
189  // draw the legend
190 
191  TLegend* leg;
192  double hleg = 0.18+nROC*0.06;
193  leg = new TLegend(0.4636591,0.1624473,0.8759398,hleg,NULL,"brNDC");
194 
195  leg->SetBorderSize(1);
196  leg->SetTextAlign(22);
197  leg->SetTextFont(12);
198  leg->SetLineColor(1);
199  leg->SetLineStyle(1);
200  leg->SetLineWidth(1);
201  leg->SetFillColor(0);
202  leg->SetFillStyle(1001);
203  leg->SetTextSize(0.05);
204  leg->SetLineColor(kBlack);
205  leg->SetFillColor(kWhite);
206 
207  for(int n=0;n<nROC;n++) {
208  char legLabel[256];
209  sprintf(legLabel,"%s",gNAME[n].Data());
210  leg->AddEntry(gr[n],legLabel,"lp");
211  }
212  leg->Draw();
213 
214  // save plot
215  if(ofname!="") canvas->Print(ofname);
216 
217  return;
218 }
219 
220 int readStatistic(TString fname, vector<float>& vstat) {
221 
222  float stat;
223 
224  ifstream in;
225  in.open(fname.Data(),ios::in);
226  if (!in.good()) {cout << "Error Opening File : " << fname.Data() << endl;exit(1);}
227 
228  while (1) {
229  in >> stat;
230  if (!in.good()) break;
231  vstat.push_back(stat);
232  }
233  in.close();
234 
235  return vstat.size();
236 }
237 
238 int readConfig(TString fname, vector<TString>& vfsignal, vector<TString>& vfnoise, vector<TString>& vname) {
239 
240  char fsignal[1024];
241  char fnoise[1024];
242  char name[1024];
243 
244  ifstream in;
245  in.open(fname.Data(),ios::in);
246  if (!in.good()) {cout << "Error Opening File : " << fname.Data() << endl;exit(1);}
247 
248  while (1) {
249  in >> fsignal >> fnoise >> name;
250  if (!in.good()) break;
251  if(TString(fsignal[0])=="#") continue;
252  vfsignal.push_back(fsignal);
253  vfnoise.push_back(fnoise);
254  vname.push_back(name);
255  }
256  in.close();
257 
258  return vname.size();
259 }
260 
int readConfig(TString fname, vector< TString > &vfsignal, vector< TString > &vfnoise, vector< TString > &vname)
Definition: DrawROCxPE.C:238
wavearray< double > wNOISE[nROC_MAX]
Definition: DrawROCxPE.C:44
void DrawROCxPE(TString ifname, TString ofname="")
Definition: DrawROCxPE.C:48
void PlotROC(int nroc, TString ofname="")
Definition: DrawROCxPE.C:102
par [0] name
int n
Definition: cwb_net.C:28
TString("c")
#define nROC_MAX
Definition: DrawROCxPE.C:34
return wmap canvas
int j
Definition: cwb_net.C:28
i drho i
int nROC
Definition: MakeROC.C:35
virtual size_t size() const
Definition: wavearray.hh:145
wavearray< double > wSIGNAL[nROC_MAX]
Definition: DrawROCxPE.C:43
TString gNAME[nROC_MAX]
Definition: DrawROCxPE.C:46
TGraph * gr
cout<<"Number of Entries: "<< num<< endl;double *slag1=new double[slag_entries];slag1=wave.GetV1();double *slag2=new double[slag_entries];slag2=wave.GetV2();char mytitle[256];double SlagMax=wave.GetMaximum("slag")+segLen/2.;double SlagMin=wave.GetMinimum("slag") -segLen/2.;int NSlag=TMath::FloorNint((SlagMax-SlagMin)/segLen);cout<< "SLAG MAX : "<< wave.GetMaximum("slag")<< " s SLAG MIN : "<< wave.GetMinimum("slag")<< " s #SLAGS : "<< NSlag-1<< endl;if(NSlag==1){cout<<"Just one slag....Skipping further execution!"<< endl;exit(0);} sprintf(mytitle,"FAR distribution over slags (post cat3 & rho>%f)", T_cut);TH2F *Slag=new TH2F("SLAG", mytitle, NSlag, SlagMin/86400., SlagMax/86400., NSlag, SlagMin/86400., SlagMax/86400.);Slag-> GetXaxis() -> SetTitle("slag[1] shift [day]")
char fname[1024]
int readStatistic(TString fname, vector< float > &vstat)
Definition: DrawROCxPE.C:220
#define wSIZE
Definition: DrawROCxPE.C:35
ifstream in
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
int gCOLOR[nROC_MAX]
Definition: DrawROCxPE.C:41
static Int_t getTableau10BlindColor(Int_t index)
Definition: Toolbox.cc:7275
virtual void resize(unsigned int)
Definition: wavearray.cc:463
vector< TString > vname
Definition: cwb_report_pe.C:94
TMultiGraph * mg
exit(0)