Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MakeROC.C
Go to the documentation of this file.
1 // this macro produces the ROC report page
2 // the ROC is reported for each MDC @ fixed injection factor
3 // Author : Gabriele Vedovato
4 //
5 // run ex : root 'MakeROC.C("definitions.C")'
6 // definitions.C contains all definitions
7 //
8 // --------------------------------------------------------------
9 // ROC definitions
10 // --------------------------------------------------------------
11 // #define nROC N // number of ROC compared
12 // #TString ROC_TITLE = "..."; // report title
13 // #TString ROC_DIR = "..."; // output report directory (Ex: report/dump/roc)
14 // #TString ROC_WWW = "..."; // www link of the ROC plots
15 //
16 // --------------------------------------------------------------
17 // reports SIM/BKG dir/www-links
18 // --------------------------------------------------------------
19 // TString ROC_NAME[nROC] = {"name1",...};
20 // TString SIM_WWW[nROC] = {"https:sim_link1",...};
21 // TString BKG_WWW[nROC] = {"https:bkg_link1",...};
22 // TString SIM_DIR[nROC] = {"sim_dir1",...};
23 // TString BKG_DIR[nROC] = {"bkg_dir1",...};
24 //
25 // --------------------------------------------------------------
26 // plot line definitions
27 // --------------------------------------------------------------
28 // int LINE_COLOR[nROC] = {4,2,3}; // Ex: {blue.red,green}
29 // int LINE_STYLE[nROC] = {1,1,1}; // Ex: {solid,solid,solid}
30 //
31 
32 #define MDC_TYPE_NULL 100000
33 #define nROC_MAX 20
34 
35 int nROC;
47 
48 int readParameters(TString fname, vector<TString>& mdc_name,
49  vector<int>& mdc_type, vector<float>& factor);
50 int readParameters(TString fname, vector<double>& rho, vector<double>& par);
51 void PlotROC(int nroc, int ieff, TString mdc_name, float factor, TString ofDir);
52 void MakeHtml(TString roc_dir, int ieff, TString ROC_WWW,
54 
55 void
56 MakeROC(TString cfgFile, int ieff=50, int imdc_type=MDC_TYPE_NULL) {
57 
58  gROOT->Macro(cfgFile);
59 
60  char cmd[1024];
61 
62  char roc_dir[1024];
63  sprintf(roc_dir,"%s_%d",ROC_DIR.Data(),ieff);
64 
65  if(ROC_DIR!="") CWB::Toolbox::mkDir(roc_dir,true);
66  if(ROC_DIR!="") gROOT->SetBatch(true);
67 
68  // copy input list file to output plot dir
69  sprintf(cmd,"cp %s %s/.",cfgFile.Data(),roc_dir);
70  gSystem->Exec(cmd);
71 
72  vector<TString> mdc_name;
73  vector<int> mdc_type;
74  vector<float> factor;
75  char fname[1024];
76  sprintf(fname,"%s/eff_%d_threshold_factors.txt",SIM_DIR[0].Data(),ieff);
77  int nmdc = readParameters(fname, mdc_name, mdc_type, factor);
78  // copy eff_threshold_factors.txt file to output plot dir
79  sprintf(cmd,"cp %s %s/.",fname,roc_dir);
80  gSystem->Exec(cmd);
81  //cout << "nmdc : " << nmdc << endl;
82  // check if it is consisten with the others parameters
83  for(int n=1;n<nROC;n++) {
84  vector<TString> xmdc_name;
85  vector<int> xmdc_type;
86  vector<float> xfactor;
87  char xfname[1024];
88  sprintf(xfname,"%s/eff_%d_threshold_factors.txt",SIM_DIR[n].Data(),ieff);
89  cout << "Process File : " << xfname << endl;
90  int xnmdc = readParameters(xfname, xmdc_name, xmdc_type, xfactor);
91  if(nmdc!=xnmdc) {
92  cout << "Num parameters files inconsistents : " << xfname << endl;
93  exit(1);
94  }
95  wavearray<int> check(xnmdc);
96  check=-1;
97  for(int i=0;i<nmdc;i++) {
98  for(int j=0;j<nmdc;j++) {
99  if(TString(xmdc_name[i]).Contains(mdc_name[j])) check[j]=i;
100  if(TString(mdc_name[j]).Contains(xmdc_name[i])) check[j]=i;
101  }
102  }
103  for(int i=0;i<nmdc;i++) if(check[i]) if(factor[i]!=xfactor[check[i]]) check[i]=-1;
104  for(int i=0;i<nmdc;i++) {
105  if(check[i]==-1) {
106  cout << "Parameters files inconsistents : " << endl;
107  cout << "xmdc_name : " << xmdc_name[i] << " mdc_name : " << mdc_name[check[i]] << endl;
108  cout << "xfactor : " << xfactor[i] << " factor : " << factor[check[i]] << endl;
109  exit(1);
110  }
111  }
112  }
113 
114  // list available mdc names
115  if(imdc_type<0) {
116  cout << "-------------------------------------------------" << endl;
117  cout << "list of availables mdc types" << endl;
118  cout << "-------------------------------------------------" << endl;
119  for(int j=0;j<nmdc;j++) {
120  cout << "mdc_type : " << mdc_type[j] << "\tmdc_name : " << mdc_name[j] << endl;
121  }
122  cout << "-------------------------------------------------" << endl;
123  exit(1);
124  }
125 
126  if((imdc_type!=MDC_TYPE_NULL)&&((imdc_type<0)||(imdc_type>=nmdc))) {
127  cout << "mdc_type not allowed" << endl;
128  exit(1);
129  }
130 
131  for(int j=0;j<nmdc;j++) {
132  if((imdc_type!=MDC_TYPE_NULL)&&(imdc_type!=mdc_type[j])) continue;
133  PlotROC(nROC, ieff, mdc_name[j], factor[j], roc_dir);
134  }
135 
136  if((ROC_DIR!="")&&(imdc_type==MDC_TYPE_NULL)) {
137  MakeHtml(roc_dir, ieff, ROC_WWW, BKG_WWW, SIM_WWW, ROC_NAME);
138  cout << endl;
139  cout << "ROC report page : " << endl;
140  cout << roc_dir << endl;
141  cout << ROC_WWW << "_" << ieff << endl;
142  cout << endl;
143  gSystem->Exit(0);
144  }
145 }
146 
147 void PlotROC(int nroc, int ieff, TString mdc_name, float factor, TString ofDir) {
148 
149  // create plots
150  gStyle->SetFrameBorderMode(0); // remove the red box around canvas
151  gROOT->ForceStyle();
152 
153  gStyle->SetTitleFont(72);
154  gStyle->SetMarkerColor(50);
155  gStyle->SetLineColor(kWhite);
156  gStyle->SetTitleW(0.98);
157  gStyle->SetTitleH(0.05);
158  gStyle->SetTitleY(0.98);
159  gStyle->SetFillColor(kWhite);
160  gStyle->SetLineColor(kWhite);
161  gStyle->SetTitleFont(12,"D");
162 
163  TCanvas *canvas = new TCanvas("roc", "roc", 300,40, 800, 500);
164  canvas->Clear();
165  canvas->ToggleEventStatus();
166  canvas->SetLogx();
167  canvas->SetGridx();
168  canvas->SetGridy();
169  canvas->SetFillColor(kWhite);
170 
171  double eff_min=1;
172  double eff_max=0;
173  char fname[1024];
174  TGraph* gr[nROC_MAX];
175  for(int n=0;n<nROC;n++) {
176  vector<double> rho_far;
177  vector<double> rho_eff;
178  vector<double> far;
179  vector<double> eff;
180  // read FAR
181  sprintf(fname,"%s/rate_threshold_veto.txt",BKG_DIR[n].Data());
182  cout << "rate_threshold : " << fname << endl;
183  int far_size = readParameters(fname, rho_far, far);
184  // read EFF
185  sprintf(fname,"%s/eff_%d_threshold_%s.txt",SIM_DIR[n].Data(),ieff,mdc_name.Data());
186  cout << "eff_threshold : " << fname << endl;
187  int sim_size = readParameters(fname, rho_eff, eff);
188  if(far_size!=sim_size) {
189  cout << "rate_threshold not compatible with eff_threshold" << endl;
190  cout << "far_size : " << far_size << " sim_size : " << sim_size << endl;
191  gSystem->Exit(1);
192  }
193  for(int j=0;j<sim_size;j++) {
194  if(rho_far[j]!=rho_eff[j]) {
195  cout << "rate_threshold not compatible with eff_threshold" << endl;
196  cout << "thresholds values are different" << endl;
197  cout << j << " rho_far : " << rho_far[j] << " =rho_eff : " << rho_eff[j] << endl;
198  gSystem->Exit(1);
199  }
200  }
201  int wsize=0;
202  wavearray<double> wfar(far_size);
203  wavearray<double> weff(sim_size);
204  for(int j=0;j<sim_size;j++) {
205  wfar[wsize]=far[j];
206  weff[wsize]=eff[j];
207  if((wfar[wsize]>0)&&(weff[wsize]>0)) {
208  if(weff[wsize]<eff_min) eff_min=weff[wsize];
209  if(weff[wsize]>eff_max) eff_max=weff[wsize];
210  //cout << wsize << " " << wfar[wsize] << " " << weff[wsize] << endl;
211  wsize++;
212  }
213  }
214  gr[n] = new TGraph(wsize,wfar.data,weff.data);
215  }
216  for(int n=0;n<nROC;n++) {
217  gr[n]->SetLineWidth(2);
218  gr[n]->SetMarkerColor(LINE_COLOR[n]);
219  gr[n]->SetMarkerStyle(20);
220  gr[n]->SetLineColor(LINE_COLOR[n]);
221  gr[n]->SetLineStyle(LINE_STYLE[n]);
222  }
223 
224  TMultiGraph* mg = new TMultiGraph();
225  char gTitle[256];
226  sprintf(gTitle,"ROC : mdc = %s : factor = %g",mdc_name.Data(),factor);
227  mg->SetTitle(gTitle);
228  for(int n=0;n<nROC;n++) mg->Add(gr[n]);
229  //mg->Paint("APL");
230  mg->Paint("AP");
231 
232  mg->GetHistogram()->GetXaxis()->SetLabelSize(0.04);
233  mg->GetHistogram()->GetYaxis()->SetLabelSize(0.04);
234  mg->GetHistogram()->GetXaxis()->SetTitleSize(0.04);
235  mg->GetHistogram()->GetYaxis()->SetTitleSize(0.04);
236  mg->GetHistogram()->GetXaxis()->SetLabelFont(42);
237  mg->GetHistogram()->GetYaxis()->SetLabelFont(42);
238  mg->GetHistogram()->GetYaxis()->SetLabelOffset(0.01);
239  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.5);
240 
241 // mg->GetHistogram()->GetXaxis()->SetRangeUser(1e-9,1e-3);
242 // mg->GetHistogram()->GetYaxis()->SetRangeUser(eff_min,eff_max);
243  mg->GetHistogram()->GetYaxis()->SetRangeUser(0,1);
244 
245  mg->GetXaxis()->SetTitle(gr[0]->GetXaxis()->GetTitle());
246  mg->GetXaxis()->SetLabelFont(42);
247  mg->GetYaxis()->SetLabelFont(42);
248  mg->GetXaxis()->SetTitleFont(42);
249  mg->GetYaxis()->SetTitleFont(42);
250  mg->GetXaxis()->SetTitleOffset(1.20);
251  mg->GetYaxis()->SetTitleOffset(1.20);
252  mg->GetXaxis()->SetTitleSize(0.04);
253  mg->GetYaxis()->SetTitleSize(0.04);
254  mg->GetXaxis()->SetTitle("FAR");
255  mg->GetYaxis()->SetTitle("Efficiency");
256 
257  mg->Draw("ALP");
258 
259  // draw the legend
260 
261  TLegend* leg;
262  double hleg = 0.15+nROC*0.05;
263  leg = new TLegend(0.61,hleg,0.99,0.15,NULL,"brNDC");
264 
265  leg->SetBorderSize(1);
266  leg->SetTextAlign(22);
267  leg->SetTextFont(12);
268  leg->SetLineColor(1);
269  leg->SetLineStyle(1);
270  leg->SetLineWidth(1);
271  leg->SetFillColor(0);
272  leg->SetFillStyle(1001);
273  leg->SetTextSize(0.03);
274  leg->SetLineColor(kBlack);
275  leg->SetFillColor(kWhite);
276 
277  for(int n=0;n<nROC;n++) {
278  char legLabel[256];
279  sprintf(legLabel,"%s",ROC_NAME[n].Data());
280  leg->AddEntry(gr[n],legLabel,"lp");
281  }
282  leg->Draw();
283 
284  // save plot
285  if(ofDir!="") {
286  char gfileName[1024];
287  sprintf(gfileName,"%s/roc_%s.gif",ofDir.Data(),mdc_name.Data());
288  canvas->Print(gfileName);
289  TString pfileName=gfileName;
290  pfileName.ReplaceAll(".gif",".png");
291  char cmd[1024];
292  sprintf(cmd,"convert %s %s",gfileName,pfileName.Data());
293  cout << cmd << endl;
294  gSystem->Exec(cmd);
295  sprintf(cmd,"rm %s",gfileName);
296  cout << cmd << endl;
297  gSystem->Exec(cmd);
298  }
299 
300  return;
301 }
302 
303 int readParameters(TString fname, vector<TString>& mdc_name,
304  vector<int>& mdc_type, vector<float>& factor) {
305  // read factor50 from custom input file
306 
307  char xmdc_name[256];
308  int xmdc_type;
309  float xfactors;
310 
311  ifstream in;
312  in.open(fname.Data(),ios::in);
313  if (!in.good()) {cout << "Error Opening File : " << fname.Data() << endl;exit(1);}
314 
315  while (1) {
316  in >> xmdc_name >> xmdc_type >> xfactors;
317  if (!in.good()) break;
318  //cout << xmdc_name <<" "<< xmdc_type <<" "<< xfactors << endl;
319  mdc_name.push_back(xmdc_name);
320  mdc_type.push_back(xmdc_type);
321  factor.push_back(xfactors);
322  }
323  in.close();
324 
325  return mdc_name.size();
326 }
327 
328 int readParameters(TString fname, vector<double>& rho, vector<double>& par) {
329  // read rho,par input file
330 
331  rho.clear();
332  par.clear();
333 
334  double xrho;
335  double xpar;
336 
337  ifstream in;
338  in.open(fname.Data(),ios::in);
339  if (!in.good()) {cout << "Error Opening File : " << fname.Data() << endl;exit(1);}
340 
341  while (1) {
342  in >> xrho >> xpar;
343  if (!in.good()) break;
344  //cout << xrho <<" "<< xpar << endl;
345  rho.push_back(xrho);
346  par.push_back(xpar);
347  }
348  in.close();
349 
350  return rho.size();
351 }
352 
353 void MakeHtml(TString roc_dir, int ieff, TString ROC_WWW,
355 
356  vector<TString> mdc_name;
357  vector<int> mdc_type;
358  vector<float> factor;
359  char fname[1024];
360  sprintf(fname,"%s/eff_%d_threshold_factors.txt",roc_dir.Data(),ieff);
361  int nmdc = readParameters(fname, mdc_name, mdc_type, factor);
362 
363  char roc_html_file[1024];sprintf(roc_html_file,"%s/index.html",roc_dir.Data());
364  ofstream out;
365  out.open(roc_html_file,ios::out); // create index.html
366  char oline[1024];
367  out << "<html>" << endl;
368  out << "<font color=\"black\" style=\"font-weight:bold;\"><center><p><h2>"
369  << ROC_TITLE << "</h2><p><center></font>" << endl;
370 
371  for(int n=0;n<nROC;n++) {
372  out << "<h4>" << ROC_NAME[n] << " : " << endl;
373  sprintf(oline,"<a target=\"_parent\" href=\"%s\">bkg report page</a>",BKG_WWW[n].Data());
374  out << oline << endl;
375  out << "---" << endl;
376  sprintf(oline,"<a target=\"_parent\" href=\"%s\">sim report page</a>",SIM_WWW[n].Data());
377  out << oline << endl;
378  out << "</h4>" << endl;
379  }
380 
381  out << "<hr><br>" << endl;
382  for(int i=0;i<mdc_name.size();i++) {
383  out << "<table border=0 cellpadding=2 align=\"center\">" << endl;
384  out << "<tr align=\"center\">" << endl;
385  out << "<td><font style=\"font-weight:bold;\"><center><p><h2>"
386  << mdc_name[i] << "</h2><p><center></font></td>" << endl;
387  out << "</tr>" << endl;
388  out << "<tr align=\"center\">" << endl;
389  sprintf(oline,"<td><a href=\"%s_%d/roc_%s.png\"><img src=\"%s_%d/roc_%s.png\" width=650></a></td>",
390  ROC_WWW.Data(),ieff,mdc_name[i].Data(),ROC_WWW.Data(),ieff,mdc_name[i].Data());
391  out << oline << endl;
392  out << "</tr>" << endl;
393  out << "</table>" << endl;
394  }
395  out << "</html>" << endl;
396  out.close();
397 
398  return;
399 }
400 
double rho
char cmd[1024]
TString BKG_DIR[nROC_MAX]
Definition: MakeROC.C:44
int n
Definition: cwb_net.C:10
TString("c")
void PlotROC(int nroc, int ieff, TString mdc_name, float factor, TString ofDir)
Definition: MakeROC.C:147
float xfactors
TLegend * leg
Definition: compare_bkg.C:246
int xmdc_type
return wmap canvas
TString REP_WWW
Definition: MakeROC.C:36
void MakeROC(TString cfgFile, int ieff=50, int imdc_type=MDC_TYPE_NULL)
Definition: MakeROC.C:56
TString SIM_WWW[nROC_MAX]
Definition: MakeROC.C:45
int j
Definition: cwb_net.C:10
int LINE_COLOR[nROC_MAX]
Definition: MakeROC.C:41
i drho i
int nROC
Definition: MakeROC.C:35
ofstream out
Definition: cwb_merge.C:196
int nmdc
Definition: cbc_plots.C:791
double factor
#define nROC_MAX
Definition: MakeROC.C:33
TGraph * gr
TString ROC_WWW
Definition: MakeROC.C:39
char oline[1024]
char fname[1024]
int LINE_STYLE[nROC_MAX]
Definition: MakeROC.C:42
TString ROC_DIR
Definition: MakeROC.C:38
TString BKG_WWW[nROC_MAX]
Definition: MakeROC.C:46
vector< mdcpar > par
TString SIM_DIR[nROC_MAX]
Definition: MakeROC.C:43
int readParameters(TString fname, vector< TString > &mdc_name, vector< int > &mdc_type, vector< float > &factor)
Definition: MakeROC.C:303
void MakeHtml(TString roc_dir, int ieff, TString ROC_WWW, TString *BKG_WWW, TString *SIM_WWW, TString *ROC_NAME)
Definition: MakeROC.C:353
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]")
Definition: slag.C:91
TString ROC_NAME[nROC_MAX]
Definition: MakeROC.C:40
ifstream in
TString ROC_TITLE
Definition: MakeROC.C:37
static void mkDir(TString dir, bool question=false, bool remove=true)
Definition: Toolbox.cc:4000
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
DataType_t * data
Definition: wavearray.hh:301
#define MDC_TYPE_NULL
Definition: MakeROC.C:32
size_t imdc_type[NMDC_MAX]
Definition: cwb_mkeff.C:45
char xmdc_name[256]
int check
TMultiGraph * mg
exit(0)