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