Logo coherent WaveBurst  
Library Reference Guide
Logo
DrawCoverageVsPercentagePRC.C
Go to the documentation of this file.
1 // Plot Error Regions Percentage vs Coverage
2 // In this examples we use 4 mdc types at SNR = 10*sqrt(nIFO)
3 
4 #define NMDC 4
5 
6 #define NETSNR (10*sqrt(3.))
7 
8 //#define nIFO 2
9 #define nIFO 3
10 
11 
12 double factors[3] = {10.*sqrt(nIFO), 20.*sqrt(nIFO), 30.*sqrt(nIFO)};
13 TString mdc[4] = {"WNB250_100_0d100","SG235Q3","SG235Q8d9","SGC235Q9"};
14 
15 double GetPercentage(int idmdc, int iderA, int idfactor, TString fname);
16 
17 void DrawCoverageVsPercentagePRC(TString ifile, int idfactor, bool save=false)
18 {
19 
20  TObjArray* token = TString(ifile).Tokenize(TString('/'));
21  TObjString* sfile = (TObjString*)token->At(token->GetEntries()-1);
22  TString TITLE = sfile->GetString();
23  TString ofile = sfile->GetString();
24  ofile.ReplaceAll(".root",".txt");
25  TITLE.ReplaceAll(".root","");
26 
27  ofstream out;
28  out.open(ofile.Data(),ios::out);
29  if (!out.good()) {cout << "Error Opening File : " << ofile.Data() << endl;exit(1);}
30  cout << "Create file : " << ofile.Data() << endl;
31 
32  // if coverage > percentage then erA is too large, the true erA is smaller (erA is conservative)
33  // if coverage < percentage then erA is too small, the true erA is greater (erA is optimistic)
34 
35  double coverage[NMDC][11];
36  for (int i=0;i<NMDC;i++) {
37  coverage[i][0]=0.;
38  coverage[i][10]=100.;
39  for (int j=1;j<10;j++) {
40  coverage[i][j]=GetPercentage(i+1,j,idfactor,ifile);
41  out << mdc[i].Data() << " " << j*10 << " " << coverage[i][j] << endl;
42  //cout << mdc[i].Data() << " " << j*10 << " " << coverage[i][j] << endl;
43  }
44  }
45  out.close();
46 
47  TCanvas* canvas = new TCanvas("fom", "PRC", 300,40, 600, 600);
48  canvas->Clear();
49  canvas->ToggleEventStatus();
50  canvas->SetFillColor(0);
51  canvas->SetGridx();
52  canvas->SetGridy();
53  canvas->SetLogy(false);
54  canvas->SetLogx(false);
55 
56  gStyle->SetTitleH(0.032);
57  gStyle->SetTitleW(0.98);
58  gStyle->SetTitleY(0.98);
59  gStyle->SetTitleFont(72);
60  gStyle->SetLineColor(kWhite);
61  gStyle->SetPalette(1,0);
62  gStyle->SetNumberContours(256);
63 
64  Style_t markers[32]= {20,21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,
65  21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,20 };
66 
67  Color_t colors[32] = { 6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7,
68  6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7 };
69 
70  double perc[11]={0,10,20,30,40,50,60,70,80,90,100};
71  TGraph* gr[NMDC+11];
72  for(int i=0;i<NMDC;i++) {
73  gr[i] = new TGraph(11,perc,coverage[i]);
74  gr[i]->SetLineColor(colors[i]);
75  gr[i]->SetLineWidth(1);
76  gr[i]->SetMarkerColor(colors[i]);
77  gr[i]->SetMarkerStyle(markers[i]);
78  }
79  double x[2]={0,100};
80  double y[2]={0,100};
81  gr[NMDC+1] = new TGraph(2,x,y);
82  gr[NMDC+1]->SetLineColor(1);
83  gr[NMDC+1]->SetLineWidth(2);
84  gr[NMDC+1]->SetLineStyle(2);
85 
86  TMultiGraph* mg = new TMultiGraph();
87  for(int i=0;i<NMDC;i++) mg->Add(gr[i],"lp");
88  mg->Add(gr[NMDC+1],"lp");
89  mg->Paint("ap");
90  char title[256];
91  sprintf(title,"%s - netSNR = %3.2f",TITLE.Data(),NETSNR);
92  mg->GetHistogram()->SetTitle(title);
93  mg->GetHistogram()->GetXaxis()->SetTitle("Percentage");
94  mg->GetHistogram()->GetYaxis()->SetTitle("Coverage");
95  mg->GetHistogram()->GetXaxis()->SetRangeUser(0,100);
96  mg->GetHistogram()->GetYaxis()->SetRangeUser(0,100);
97  mg->GetHistogram()->GetXaxis()->SetTitleOffset(1.3);
98  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.3);
99  mg->GetHistogram()->GetXaxis()->CenterTitle(true);
100  mg->GetHistogram()->GetYaxis()->CenterTitle(true);
101  mg->GetHistogram()->GetXaxis()->SetLabelFont(42);
102  mg->GetHistogram()->GetXaxis()->SetTitleFont(42);
103  mg->GetHistogram()->GetYaxis()->SetLabelFont(42);
104  mg->GetHistogram()->GetYaxis()->SetTitleFont(42);
105  mg->Draw("a");
106 
107  TLegend* leg;
108  double hleg = 0.8-NMDC*0.05;
109  leg = new TLegend(0.1291513,hleg,0.6244966,0.8738739,NULL,"brNDC");
110 
111  leg->SetBorderSize(1);
112  leg->SetTextAlign(22);
113  leg->SetTextFont(12);
114  leg->SetLineColor(1);
115  leg->SetLineStyle(1);
116  leg->SetLineWidth(1);
117  leg->SetFillColor(0);
118  leg->SetFillStyle(1001);
119  leg->SetTextSize(0.04);
120  leg->SetLineColor(kBlack);
121  leg->SetFillColor(kWhite);
122 
123  char label[256];
124  for(int i=0;i<NMDC;i++) {
125  sprintf(label,"%s ",mdc[i].Data());
126  leg->AddEntry(gr[i],label,"lp");
127  }
128  leg->Draw();
129 
130  if(save) {
131  char label[64];sprintf(label,"_%g_CovVsPerc.gif",factors[idfactor]);
132  TString gfileName=ofile;
133  gfileName.ReplaceAll(".txt",label);
134  canvas->Print(gfileName);
135  TString pfileName=gfileName;
136  pfileName.ReplaceAll(".gif",".png");
137  char cmd[1024];
138  sprintf(cmd,"convert %s %s",gfileName.Data(),pfileName.Data());
139  cout << cmd << endl;
140  gSystem->Exec(cmd);
141  sprintf(cmd,"rm %s",gfileName.Data());
142  cout << cmd << endl;
143  gSystem->Exec(cmd);
144  exit(0);
145  }
146 }
147 
148 double GetPercentage(int idmdc, int iderA, int idfactor, TString fname) {
149 
150  TFile *ifile = TFile::Open(fname.Data());
151  TTree* itree = (TTree *) gROOT->FindObject("waveburst");
152  itree->SetEstimate(itree->GetEntries());
153 
154  char selection[1024];
155  char tree_cut[1024];
156  sprintf(tree_cut,"abs(time[0]-time[3])<0.1 && type[1]==%d && abs(factor-%f)<0.1",idmdc,factors[idfactor]);
157  //cout << tree_cut << endl;
158 
159  sprintf(selection,"erA[0]-erA[%d]>>hist_cumulative_erA1(2000,-100,100)",iderA);
160  itree->Draw(selection,tree_cut,"goff");
161  int size = itree->GetSelectedRows();
162  TH1D* hist_cumulative_erA1 = (TH1D*)gDirectory->Get("hist_cumulative_erA1");
163  //cout << "size : " << size << endl;
164  if(size==0) {
165  delete hist_cumulative_erA1;
166  delete itree;
167  delete ifile;
168  return 0;
169  }
170 
171  double integral = hist_cumulative_erA1->ComputeIntegral();
172  if (integral==0) {cout << "Empty histogram !!!" << endl;exit(0);}
173  double* cumulative = hist_cumulative_erA1->GetIntegral();
174  for (int i=0;i<hist_cumulative_erA1->GetNbinsX();i++) hist_cumulative_erA1->SetBinContent(i,cumulative[i]/integral);
175  //cout << "integral " << integral << endl;
176 
177 
178  double perc = 100.*hist_cumulative_erA1->GetBinContent(1001);
179  delete hist_cumulative_erA1;
180  delete itree;
181  delete ifile;
182  //ifile->Close();
183 
184  return perc;
185 }
186 
char ofile[1024]
TString("c")
#define TITLE
Definition: TestSiteJ1.C:44
ofstream out
Definition: cwb_merge.C:214
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<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ 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
TString mdc[4]
return wmap canvas
Long_t size
Color_t colors[16]
int j
Definition: cwb_net.C:28
i drho i
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
char fname[1024]
TObjArray * token
double factors[3]
#define nIFO
TFile * ifile
char title[256]
Definition: SSeriesExample.C:1
#define NETSNR
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)
char cmd[1024]
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
TTree * itree
#define NMDC
bool save
wavearray< double > y
Definition: Test10.C:31
TMultiGraph * mg
exit(0)