Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_report_sim.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 
19 // post-production macro for the simulation report : used by the cwb_report command
20 {
21  #define EPSILON 0.001
22  #define NMDC_MAX 64
23 
24  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
25  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
26  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
27  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PPARAMETERS_FILE"));
28  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_UPPARAMETERS_FILE"));
29  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_EPPARAMETERS_FILE"));
30 
31 #ifndef _USE_ROOT6
32  // the CWB_CAT_NAME declared in CWB_EPPARAMETERS_FILE is not visible. why?
33  // the include is defined again
34  #undef GTOOLBOX_HH
35 #else
36  #include "GToolbox.hh"
37 #endif
38 
39  if(nIFO==1) { // Single Detector Mode
41  config.Import();
42  config.SetSingleDetectorMode();
43  config.Export();
44  }
45 
46  // initialize the ifo name (takes into account the non built-in detectors)
47  char IFO[NIFO_MAX][32];
48  for(int n=0;n<nIFO;n++) {
49  if(strlen(ifo[n])!=0) strcpy(IFO[n],ifo[n]); else strcpy(IFO[n],detParms[n].name);
50  }
51 
52  CWB::Toolbox::mkDir(netdir,!pp_batch);
53 
54  gStyle->SetTitleOffset(1.4,"X");
55  gStyle->SetTitleOffset(1.2,"Y");
56  gStyle->SetLabelOffset(0.014,"X");
57  gStyle->SetLabelOffset(0.010,"Y");
58  gStyle->SetLabelFont(42,"X");
59  gStyle->SetLabelFont(42,"Y");
60  gStyle->SetTitleFont(42,"X");
61  gStyle->SetTitleFont(42,"Y");
62  gStyle->SetLabelSize(0.03,"X");
63  gStyle->SetLabelSize(0.03,"Y");
64 
65  gStyle->SetTitleH(0.050);
66  gStyle->SetTitleW(0.95);
67  gStyle->SetTitleY(0.98);
68  gStyle->SetTitleFont(12,"D");
69  gStyle->SetTitleColor(kBlue,"D");
70  gStyle->SetTextFont(12);
71  gStyle->SetTitleFillColor(kWhite);
72  //gStyle->SetLineColor(kWhite);
73  gStyle->SetNumberContours(256);
74  gStyle->SetCanvasColor(kWhite);
75  gStyle->SetStatBorderSize(1);
76 // gStyle->SetOptStat(kFALSE);
77 
78  gStyle->SetStatX(0.878);
79  gStyle->SetStatY(0.918);
80  gStyle->SetStatW(0.200);
81  gStyle->SetStatH(0.160);
82 // gStyle->SetStatBorderSize(1);
83  gStyle->SetStatColor(0);
84 
85  // remove the red box around canvas
86  gStyle->SetFrameBorderMode(0);
87  gROOT->ForceStyle();
88 
89  cout<<"cwb_report_sim.C starts..."<<endl;
90 
91 
92  Color_t colors[NMDC_MAX] = { 6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7,
93  6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7,
94  6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7,
95  6, 3, 2, 8,43, 7, 8, 4, 4, 2,43, 1, 3, 1, 6, 7 };
96  Style_t markers[NMDC_MAX]= {20,21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,
97  21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,20,
98  21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,20,
99  21,22,23,29,29,21,22,20,21,22,23,29,20,21,22,20 };
100  // histograms
101  TH2F* HH[NIFO_MAX][NMDC_MAX];
102  TH2F* NRE[NIFO_MAX][NMDC_MAX];
103  TH1F* hT[NMDC_MAX];
104  TH1F* hF[NMDC_MAX];
105  TGraphErrors* EFF[NMDC_MAX];
106 
107  for(int i=0;i<NMDC_MAX;i++) {
108  for(int j=0;j<nIFO;j++) HH[j][i]=NULL;
109  for(int j=0;j<nIFO;j++) NRE[j][i]=NULL;
110  hT[i]=NULL;
111  hF[i]=NULL;
112  EFF[i]=NULL;
113  }
114 
115  // transform T_ifar from years into sec
116  T_ifar*=(365.*24.*3600.);
117 
118  // XDQF structure used for internal's computations
119  dqfile* XDQF = new dqfile[nVDQF];
120 
121  // read injection file types
122  char imdc_set[NMDC_MAX][128]; // injection set
123  size_t imdc_type[NMDC_MAX]; // injection type
124  char imdc_name[NMDC_MAX][128]; // injection name
125  double imdc_flow[NMDC_MAX]; // injection low frequencies
126  double imdc_fhigh[NMDC_MAX]; // injection high frequencies
127  double imdc_fcentral[NMDC_MAX]; // injection low frequencies
128  double imdc_fbandwidth[NMDC_MAX]; // injection high frequencies
129  size_t imdc_index[NMDC_MAX]; // type reference array
130  size_t imdc_iset[NMDC_MAX]; // injection set index
131  size_t imdc_tset[NMDC_MAX]; // injection set type index
132 
133  int ninj=ReadInjType(mdc_inj_file,NMDC_MAX,imdc_set,imdc_type,
134  imdc_name,imdc_fcentral,imdc_fbandwidth);
135  if(ninj==0) {
136  cout << endl;
137  cout << "cwb_report_sim.C : Error - no injection types or bad format" << endl;
138  cout << "mdc injection file list : " << mdc_inj_file << endl;
139  cout << "format must be : mdc_set mdc_type mdc_name mdc_fcentral mdc_fbandwidth" << endl;
140  cout << "process terminated !!!" << endl;
141  exit(1);
142  }
143 
144  for(int i=0; i<NMDC_MAX; i++) {
145  imdc_flow[i] = imdc_fcentral[i]-imdc_fbandwidth[i];
146  if(imdc_flow[i]<fLow) imdc_flow[i]=fLow;
147  if(imdc_flow[i]>fHigh) imdc_flow[i]=fLow;
148  imdc_fhigh[i] = imdc_fcentral[i]+imdc_fbandwidth[i];
149  if(imdc_fhigh[i]<fLow) imdc_fhigh[i]=fHigh;
150  if(imdc_fhigh[i]>fHigh) imdc_fhigh[i]=fHigh;
151  }
152 
153  for(int i=0; i<NMDC_MAX; i++) imdc_index[i] = NMDC_MAX;
154  for(int j=0;j<ninj;j++) imdc_index[imdc_type[j]]=j;
155  for(int j=0;j<ninj;j++) {
156  cout << j << " " << imdc_index[j] << endl;
157  if(imdc_index[j]>=ninj) {
158  cout << endl;
159  cout << "cwb_report_sim.C : Error - mdc type must be < num max type inj = " << ninj << endl;
160  cout << "check mdc_type injection file list : " << mdc_inj_file << endl;
161  cout << "format : mdc_set mdc_type mdc_name mdc_fcentral mdc_fbandwidth" << endl;
162  cout << "process terminated !!!" << endl;
163  exit(1);
164  }
165  }
166 
168  int nset=0;
169  for(int i=0;i<ninj;i++) {
170  bool bnew=true;
171  for(int j=0;j<nset;j++) if(imdc_set[i]==imdc_set_name[j]) bnew=false;
172  if(bnew) imdc_set_name[nset++]=imdc_set[i];
173  }
174  cout << "nset : " << nset << endl;
175 
176  for(int i=0;i<nset;i++) {
177  for(int j=0;j<ninj;j++) if(imdc_set[j]==imdc_set_name[i]) imdc_iset[j]=i;
178  }
179 
180  for(int i=0;i<ninj;i++) {
181  for(int j=0;j<nset;j++) if(imdc_set[i]==imdc_set_name[j]) imdc_tset[imdc_type[i]]=j;
182  }
183 
184  for(int i=0;i<ninj;i++) {
185  cout << i << " " << imdc_name[i] << " " << imdc_set[i] << " " << imdc_iset[i]
186  << " " << imdc_tset[i] << " " << imdc_type[i] << " " << imdc_index[i] << endl;
187  }
188 
189  // compute efficiency vs threshold for each mdc type (used for ROC)
190  TString pp_eff_vs_thr_mode = CWB::Toolbox::getParameter(pp_eff_vs_thr,"--mode");
191  if((pp_eff_vs_thr_mode!="DISABLED")&&(pp_eff_vs_thr_mode!="disabled")) {
192 
193  TString pp_eff_vs_thr_eff = CWB::Toolbox::getParameter(pp_eff_vs_thr,"--eff");
194  int pp_eff = 50;
195  if(pp_eff_vs_thr_eff.IsFloat()) pp_eff = pp_eff_vs_thr_eff.Atoi();
196  if(pp_eff<0) pp_eff=0;
197  if(pp_eff>100) pp_eff=100;
198 
199  TChain sim("waveburst");
200  TChain mdc("mdc");
201  sim.Add(sim_file_name);
202  mdc.Add(mdc_file_name);
203 
204  char fname[1024];
205  wavearray<double> factorXX(ninj); factorXX=0;
206 
207  // if mode=FILE_NAME -> read factorXX from custom input file
208  if((pp_eff_vs_thr_mode!="AUTO")&&(pp_eff_vs_thr_mode!="auto")) {
209  sprintf(fname,"%s",pp_eff_vs_thr_mode.Data());
210  //cout << fname << endl;
211  FILE* fp = fopen(fname,"r");
212  if(fp==NULL) {
213  cout << "cwb_report_sim.C - Error opening file : " << fname << endl;
214  gSystem->Exit(1);
215  }
216  char xmdc_name[256];
218  float xfactors;
219  for(int i=0; i<ninj; i++) {
220  fscanf(fp,"%s %d %f",xmdc_name, &xmdc_type, &xfactors);
221  cout << i << " " << xmdc_name <<" "<< xmdc_type <<" "<< xfactors << endl;
222  for(int j=0;j<ninj;j++) {
223  if(TString(xmdc_name).Contains(imdc_name[j])) {factorXX[j]=xfactors;strcpy(imdc_name[j],xmdc_name);}
224  if(TString(imdc_name[j]).Contains(xmdc_name)) {factorXX[j]=xfactors;strcpy(imdc_name[j],xmdc_name);}
225  }
226  }
227  fclose(fp);
228  // check if input parameters are consistent to the current ones
229  for(int i=0; i<ninj; i++) {
230  if(factorXX[i]==0) {
231  cout << "cwb_report_sim.C - missing factor for : " << imdc_name[i] << endl << endl;
232  gSystem->Exit(1);
233  }
234  }
235  }
236 
237  for(int i=0; i<ninj; i++) {
238 
239  int nmdc,nsim;
240  char sim_cuts[1024];
241  char mdc_cuts[1024];
242  char fac_cuts[1024];
243  char rho_cuts[1024];
244 
245  // if mode=AUTO -> select the nearest factor to %XX efficiency
246  if((pp_eff_vs_thr_mode=="AUTO")||(pp_eff_vs_thr_mode=="auto")) {
247 
248  double effXX=0;
249  for(int k=0;k<nfactor;k++) {
250  sprintf(rho_cuts,"rho[%d]>%f",pp_irho,T_cut);
251  sprintf(fac_cuts,"abs(factor-%f)<EPSILON*%f",factors[k],factors[k]);
252  if(pp_merge_types) {
253  sprintf(sim_cuts,"%s && %s && %s",ch2,fac_cuts,rho_cuts);
254  } else {
255  sprintf(mdc_cuts,"type[0]==%d && %s",(int)(imdc_type[i]+1),fac_cuts);
256  sprintf(sim_cuts,"%s && type[1]==%lu && %s && %s",ch2,imdc_type[i]+1,fac_cuts,rho_cuts);
257  }
258  //cout << "mdc_cuts " << mdc_cuts << endl;
259  //cout << "sim_cuts " << sim_cuts << endl;
260  mdc.Draw("Entry$",mdc_cuts,"goff");
261  nmdc = mdc.GetSelectedRows();
262  sim.Draw("Entry$",sim_cuts,"goff");
263  nsim = sim.GetSelectedRows();
264  double xeff = double(nsim)/double(nmdc);
265  if(fabs(100*xeff-pp_eff)<fabs(100*effXX-pp_eff)) {effXX=xeff;factorXX[i]=factors[k];}
266  //cout << "factor : " << factors[k] << " eff : " << nsim << "/" << nmdc << " % " << xeff << endl;
267  }
268  //cout << "factorXX : " << factorXX[i] << endl;
269  }
270 
271  cout << i << "\tCompute efficiency vs threshold @ factor : "
272  << factorXX[i] << "\tmdc : " << imdc_name[i] << endl;
273 
274  // compute mdc injections @ factorXX
275  sprintf(fac_cuts,"abs(factor-%f)<EPSILON*%f",factorXX[i],factorXX[i]);
276  if(pp_merge_types) {
277  } else {
278  sprintf(mdc_cuts,"type[0]==%d && %s",(int)(imdc_type[i]+1),fac_cuts);
279  }
280  //cout << "mdc_cuts " << mdc_cuts << endl;
281  mdc.Draw("Entry$",mdc_cuts,"goff");
282  nmdc = mdc.GetSelectedRows();
283  //cout << "mdc size : " << nmdc << endl;
284 
285  // get the minimum rho for the efficiency computation
286  float rho_min=0;
287  TString pp_eff_vs_thr_rho_min = CWB::Toolbox::getParameter(pp_eff_vs_thr,"--rho_min");
288  if(pp_eff_vs_thr_rho_min.IsFloat()) rho_min = pp_eff_vs_thr_rho_min.Atof();
289 
290  // compute efficiency vs threshold @ factorXX
291  sprintf(fname,"%s/eff_%d_threshold_%s.txt",netdir,pp_eff,imdc_name[i]);
292  cout << fname << endl;
293  ofstream fout;
294  fout.open(fname, ios::out);
295  if (!fout.good()) {cout << "Error Opening File : " << fname << endl;exit(1);}
296  int rho_size=0;
297  double drho = (pp_rho_max-pp_rho_min)/pp_rho_bin;
298  for(int j=0; j<pp_rho_bin; j++) {
299  double rho = pp_rho_min+j*drho;
300  double xeff = 0;
301  if(rho>rho_min) {
302  if(pp_merge_types) {
303  sprintf(sim_cuts,"%s && %s && rho[%d]>%f", ch2,fac_cuts,pp_irho,rho);
304  } else {
305  sprintf(sim_cuts,"%s && type[1]==%lu && %s && rho[%d]>%f", ch2,imdc_type[i]+1,fac_cuts,pp_irho,rho);
306  }
307  //cout << "sim_cuts " << sim_cuts << endl;
308  sim.Draw("Entry$",sim_cuts,"goff");
309  nsim = sim.GetSelectedRows();
310  double xeff = double(nsim)/double(nmdc);
311  }
312  //cout << "rho : " << rho << " eff : " << nsim << "/" << nmdc << " % " << xeff << endl;
313  fout << rho << " " << xeff << endl;
314  }
315  fout.close();
316  }
317 
318  sprintf(fname,"%s/eff_%d_threshold_factors.txt",netdir,pp_eff);
319  cout << fname << endl;
320  FILE* fp = fopen(fname,"w");
321  if(fp==NULL) {
322  cout << "cwb_report_sim.C - Error opening file : " << fname << endl;
323  gSystem->Exit(1);
324  }
325  for(int i=0; i<ninj; i++) {
326  fprintf(fp,"%s %d %g\n",imdc_name[i], (int)imdc_type[i], factorXX[i]);
327  }
328  fclose(fp);
329 
331  pp_eff_vs_thr_quit.ToUpper();
332  if(pp_eff_vs_thr_quit=="TRUE") {
333  cout << "efficiency " << pp_eff << " vs threshold terminated, exit" << endl;
334  gSystem->Exit(1);
335  }
336  }
337 
338  char fname[4096];
339  sprintf(fname,"%s/fit_parameters_ALL.txt", netdir);
340  FILE* in_all = fopen(fname,"w");
341  sprintf(fname,"%s/evt_parameters_ALL.txt", netdir);
342  FILE* evt_all = fopen(fname,"w");
343 
344  for (int iset=0;iset<nset;iset++) {
345 
346  TChain sim("waveburst");
347  TChain mdc("mdc");
348  sim.Add(sim_file_name);
349  mdc.Add(mdc_file_name);
350  netevent ww(&sim,nIFO);
351  injection mm(&mdc,nIFO);
352 
353  // check vetoes
354  UChar_t VETO[100];
355  int nXDQF=0;
356  for(int i=0;i<nVDQF;i++) {
357  if((VDQF[i].cat!=CWB_CAT2)&&(VDQF[i].cat!=CWB_HVETO)&&(VDQF[i].cat!=CWB_CAT3)) continue;
358  char veto_name[256];sprintf(veto_name,"%s_%s",CWB_CAT_NAME[VDQF[i].cat].Data(),VDQF[i].ifo);
359  if(!CWB::Toolbox::isLeafInTree(ww.fChain,veto_name)) {
360  cout << "cwb_report_sim.C Error : Leaf " << veto_name
361  << " is not present in tree" << endl;
362  exit(1);
363  }
364  }
365 
366  // build XDQF structure used for internal's computations
367  for(int j=0;j<nVDQF;j++) {
368  if(VDQF[j].cat==CWB_CAT0) continue;
369  if(VDQF[j].cat==CWB_CAT1) continue;
370  bool bifo=false;
371  for(int i=0;i<nIFO;i++) if(TString(IFO[i]).CompareTo(VDQF[j].ifo)==0) bifo=true;
372  if(bifo) XDQF[nXDQF++]=VDQF[j];
373  }
374  for(int j=0;j<nXDQF;j++) {
375  cout << "XDQF[" << j << "] " << CWB_CAT_NAME[XDQF[j].cat] << "_" << XDQF[j].ifo << endl;
376  }
377 
378  // set veto branches
379  for(int j=0;j<nXDQF;j++) {
380  char veto_name[256];
381  sprintf(veto_name,"%s_%s",CWB_CAT_NAME[XDQF[j].cat].Data(),XDQF[j].ifo);
382  ww.fChain->SetBranchAddress(veto_name,&VETO[j]);
383  }
384 
385  // sigmoid fit function
386  double inf = simulation==2 ? log10(factors[0]) : -25;
387  double sup = simulation==2 ? log10(factors[nfactor-1]) : -19;
388 
389  if(simulation==1 && pp_factor2distance) {
390  inf = log10(pp_factor2distance/factors[nfactor-1]);
391  sup = log10(pp_factor2distance/factors[0]);
392  }
393 
394  TF1 *gfit=new TF1("logNfit",logNfit,pow(10.0,inf),pow(10.0,sup),5);
395  gfit->SetParameters((inf+sup)/2.,0.3,1.,1.);
396  gfit->SetParNames("hrss50","sigma","betam","betap");
397  gfit->FixParameter(4,pp_factor2distance);
398  gfit->SetParLimits(0,inf,sup);
399  if(simulation==1 && pp_factor2distance) {
400 // gfit->SetParLimits(1,0.05,10.);
401 // gfit->SetParLimits(2,0.05,3.);
402  } else if(simulation==2) {
403  gfit->SetParLimits(1,0.05,10.);
404  gfit->SetParLimits(2,0.05,3.);
405  } else {
406  gfit->SetParLimits(1,0.08,10.);
407  gfit->SetParLimits(2,0.00,3.);
408  }
409  gfit->SetParLimits(3,0.0,2.50);
410 
411  // legend pannel
412  TLegend *legend = new TLegend(0.53,0.17,0.99,0.7,"","brNDC");
413  legend->SetLineColor(1);
414  legend->SetTextSize(0.033);
415  legend->SetBorderSize(1);
416  legend->SetLineStyle(1);
417  legend->SetLineWidth(1);
418  legend->SetFillColor(0);
419  legend->SetFillStyle(1001);
420 
421  //double xcor,esnr,null,etot,ecor,asnr,acor,a2or, nill, rho;
422  double xcor,esnr,null,etot,asnr,acor,a2or, nill, rho;
423  double a,b,vED,enrg[5];
424  int j,n,m,k;
425  size_t indx;
426 
433 
434  bool save;
435 
436  int ntrg = sim.GetEntries();
437  int nmdc = mdc.GetEntries();
438 
439  cout<<" total injections: " << nmdc <<endl;
440 
441  for(int i=0; i<ninj+1; i++) {
442  if((i<ninj)&&(imdc_iset[i]!=iset)) continue; // skip unwanted injection types
443 
444  sprintf(fname,"hT%d",i);
445  hT[i] = new TH1F(fname,fname,250,-T_win,T_win);
446  hT[i]->SetTitleOffset(1.3,"Y");
447  hT[i]->GetXaxis()->SetTitle("detected-injected time, sec");
448  hT[i]->GetYaxis()->SetTitle("events");
449  sprintf(fname,"%s",imdc_name[i]);
450  hT[i]->SetTitle(fname);
451 
452  sprintf(fname,"hF%d",i);
453  hF[i] = new TH1F(fname,fname,512,imdc_flow[i],imdc_fhigh[i]);
454  hF[i]->SetTitleOffset(1.3,"Y");
455  if(i<ninj) hF[i]->GetXaxis()->SetTitle("frequency, Hz");
456  else hF[i]->GetXaxis()->SetTitle("detected-injected, Hz");
457  hF[i]->GetYaxis()->SetTitle("events");
458  sprintf(fname,"%s",imdc_name[i]);
459  hF[i]->SetTitle(fname);
460 
461  for(int j=0; j<nIFO; j++) {
462  sprintf(fname,"%s_hrss_%d",IFO[j],i);
463  HH[j][i] = new TH2F(fname,"",500,-23.,-19.,500,-23.,-19.);
464  HH[j][i]->SetTitleOffset(1.7,"Y");
465  HH[j][i]->SetTitleOffset(1.7,"Y");
466  HH[j][i]->GetXaxis()->SetTitle("injected log10(hrss)");
467  HH[j][i]->GetYaxis()->SetTitle("detected log10(hrss)");
468  HH[j][i]->SetStats(kFALSE);
469  sprintf(fname,"%s: %s",IFO[j],imdc_name[i]);
470  HH[j][i]->SetTitle(fname);
471  HH[j][i]->SetMarkerColor(2);
472  }
473  for(int j=0; j<nIFO; j++) {
474  sprintf(fname,"%s_nre_%d",IFO[j],i);
475  NRE[j][i] = new TH2F(fname,"",500,0.,7.,500,-3,1.);
476  NRE[j][i]->SetTitleOffset(1.7,"Y");
477  NRE[j][i]->SetTitleOffset(1.7,"Y");
478  NRE[j][i]->GetXaxis()->SetTitle("injected log10(snr^{2})");
479  NRE[j][i]->GetYaxis()->SetTitle("log10(normalized residual energy)");
480  NRE[j][i]->SetStats(kFALSE);
481  sprintf(fname,"%s: %s",IFO[j],imdc_name[i]);
482  NRE[j][i]->SetTitle(fname);
483  NRE[j][i]->SetMarkerColor(2);
484  }
485  }
486 
487  TH1F* hcor = new TH1F("hcor","",100,0,1.);
488  hcor->SetTitleOffset(1.3,"Y");
489  hcor->GetXaxis()->SetTitle("network correlation (ecor)");
490  hcor->GetYaxis()->SetTitle("events");
491  hcor->SetStats(kFALSE);
492 
493  TH1F* hcc = new TH1F("hcc","",100,0,1.);
494  hcc->SetTitleOffset(1.3,"Y");
495  hcc->GetXaxis()->SetTitle("network correlation");
496  hcc->GetYaxis()->SetTitle("events");
497  hcc->SetStats(kFALSE);
498 
499  TH1F* hrho = new TH1F("hrho","",500,0,10.);
500  hrho->SetTitleOffset(1.3,"Y");
501  hrho->GetXaxis()->SetTitle("log10(#rho^2)");
502  hrho->GetYaxis()->SetTitle("events");
503 
504  TH1F* eSNR = new TH1F("eSNR","",500,0,10.);
505  eSNR->SetTitleOffset(1.3,"Y");
506  eSNR->GetXaxis()->SetTitle("log10(SNR/det)");
507  eSNR->GetYaxis()->SetTitle("events");
508  eSNR->SetStats(kFALSE);
509 
510  TH2F* rhocc = new TH2F("rhocc","",100,0.,1.,500,0,10.);
511  rhocc->SetTitleOffset(1.3,"Y");
512  rhocc->GetXaxis()->SetTitle("network correlation");
513  rhocc->GetYaxis()->SetTitle("log10(rho^2)");
514  rhocc->SetStats(kFALSE);
515 
516  TH2F* skyc = new TH2F("skyc","",180,-180,180.,90,-90.,90.);
517  skyc->SetTitleOffset(1.3,"Y");
518  skyc->GetXaxis()->SetTitle("#Delta#phi, deg.");
519  skyc->GetYaxis()->SetTitle("#Delta#theta, deg.");
520  skyc->SetStats(kFALSE);
521 
522  TH1F* hpf = new TH1F("hpf","",100,0.,1.);
523  hpf->SetTitleOffset(1.3,"Y");
524  hpf->SetTitle("");
525  hpf->GetXaxis()->SetTitle("penalty factor");
526  hpf->GetYaxis()->SetTitle("events");
527 
528  TH1F* hvED = new TH1F("hvED","",200,0,2.);
529  hvED->SetTitleOffset(1.3,"Y");
530  hvED->SetTitle("");
531  hvED->GetXaxis()->SetTitle("hvED consistency");
532  hvED->GetYaxis()->SetTitle("events");
533 
534  TH2F* pf_cc = new TH2F("pf_cc","",100,0.,1.,100,0,1.);
535  pf_cc->SetTitleOffset(1.3,"Y");
536  pf_cc->GetXaxis()->SetTitle("network correlation");
537  pf_cc->GetYaxis()->SetTitle("penalty");
538  pf_cc->SetMarkerStyle(20);
539  pf_cc->SetMarkerColor(1);
540  pf_cc->SetMarkerSize(0.8);
541  pf_cc->SetStats(kFALSE);
542 
543  TH2F* pf_vED = new TH2F("pf_vED","",100,0.,1.,100,0,1.);
544  pf_vED->SetTitleOffset(1.3,"Y");
545  pf_vED->GetXaxis()->SetTitle("H1H2 consistency");
546  pf_vED->GetYaxis()->SetTitle("penalty");
547  pf_vED->SetMarkerStyle(20);
548  pf_vED->SetMarkerColor(1);
549  pf_vED->SetMarkerSize(0.8);
550  pf_vED->SetStats(kFALSE);
551 
552  TH2F* hrs1[nIFO];
553  TH1F* ifoT[nIFO];
554  TH2F* hrs2[nIFO];
555 
556  for(int i=0; i<nIFO; i++) {
557 
558  sprintf(fname,"ifoT%s",IFO[i]);
559  ifoT[i] = new TH1F(fname,"",250,-0.05,0.05);
560  ifoT[i]->SetTitleOffset(1.3,"Y");
561  ifoT[i]->GetXaxis()->SetTitle("detected-injected time, sec");
562  ifoT[i]->GetYaxis()->SetTitle("events");
563  ifoT[i]->SetTitle(IFO[i]);
564 
565  sprintf(fname,"hrs1%s",IFO[i]);
566  hrs1[i] = new TH2F(fname,"",500,-23.,-19.,500,-23.,-19.);
567  hrs1[i]->SetTitleOffset(1.3,"Y");
568  hrs1[i]->GetXaxis()->SetTitle("detected");
569  hrs1[i]->GetYaxis()->SetTitle("injected");
570  hrs1[i]->SetStats(kFALSE);
571  hrs1[i]->SetTitle(IFO[i]);
572  hrs1[i]->SetMarkerColor(2);
573 
574  sprintf(fname,"hrs2%s",IFO[i]);
575  hrs2[i] = new TH2F(fname,"",500,-23.,-19.,500,-23.,-19.);
576  hrs2[i]->SetTitleOffset(1.3,"Y");
577  hrs2[i]->SetMarkerColor(2);
578  hrs2[i]->SetStats(kFALSE);
579  }
580 
581  // init simulations=4 stuff
582  int nhrss=10;
583  vector<double> vhrss[NMDC_MAX]; for(int i=0;i<NMDC_MAX;i++) vhrss[i].resize(nhrss+1);
584  wavearray<double>* mhrss[NMDC_MAX]; for(int i=0;i<NMDC_MAX;i++) mhrss[i] = new wavearray<double>[nhrss];
585  if(simulation==4) {
586 
587  // loop over injection tree : compute min/max injected hrss
588  wavearray<double> hrss_min(NMDC_MAX); for(int i=0;i<NMDC_MAX;i++) hrss_min[i]=1e20;
589  wavearray<double> hrss_max(NMDC_MAX); for(int i=0;i<NMDC_MAX;i++) hrss_max[i]=0.;
590  for(int i=0; i<nmdc; i++) {
591  mm.GetEntry(i);
592  if(pp_merge_types) {
593  indx=0;
594  } else {
595  if(imdc_tset[mm.type-1] != iset) continue; // skip unwanted injections
596  indx = imdc_index[mm.type-1];
597  }
598  if(mm.strain<hrss_min[indx]) if(mm.strain>0) hrss_min[indx]=mm.strain;
599  if(mm.strain>hrss_max[indx]) hrss_max[indx]=mm.strain;
600  }
601  for(int i=0;i<NMDC_MAX;i++) {
602  sMDC[i].resize(nhrss);
603  sMDC[i]=0.;
604  if(hrss_min[i]==1e20) continue;
605  if(hrss_max[i]==0) continue;
606  vhrss[i][0]=hrss_min[i];
607  vhrss[i][nhrss]=hrss_max[i];
608  double fhrss=exp(log(vhrss[i][nhrss]/vhrss[i][0])/nhrss);
609  for(int j=1;j<=nhrss;j++) vhrss[i][j]=fhrss*vhrss[i][j-1];
610  for(int j=0;j<nhrss;j++) sMDC[i][j]=(vhrss[i][j+1]+vhrss[i][j])/2.;
611  }
612  for(int j=0;j<nhrss;j++) for(int k=0; k<NMDC_MAX; k++) {nMDC[k].append(1.);}
613  }
614 
615  // loop over injection tree
616  for(int i=0; i<nmdc; i++) {
617 
618  mm.GetEntry(i);
619  if(pp_merge_types) {
620  indx=0;
621  } else {
622  if(imdc_tset[mm.type-1] != iset) continue; // skip unwanted injections
623  indx = imdc_index[mm.type-1];
624  }
625  save = true;
626 
627  n = sMDC[0].size();
628  for(int j=0; j<n; j++) {
629  switch(simulation) {
630  case 1: // factors are hrss multipliers
631  if(pp_factor2distance) {
632  if(fabs(sMDC[0].data[j]-mm.factor)<EPSILON*mm.factor) {
633  save = false; nMDC[indx].data[j]+=1.; j=n;
634  }
635  } else {
636  if(fabs(sMDC[0].data[j]-mm.strain)<0.1*mm.strain) { // WARNING DOUBLE HRSS
637  save = false; nMDC[indx].data[j]+=1.; j=n;
638  }
639  }
640  break;
641  case 2: // factors are snr
642  if(fabs(sMDC[0].data[j]-mm.factor)<EPSILON*mm.factor) {
643  save = false; nMDC[indx].data[j]+=1.; j=n;
644  }
645  break;
646  case 3: // factors are time shift
647  case 4: // nfactor is number of retries
648  if(mm.strain>vhrss[indx][j] && mm.strain<=vhrss[indx][j+1]) {
649  nMDC[indx].data[j]+=1.;
650  mhrss[indx][j].append(mm.strain);
651  j=n;
652  }
653  break;
654  }
655  }
656  // simulation=4 is already performed within the previous for loop
657  if(save && (simulation!=4)) {
658  switch(simulation) {
659  case 1:
660  if(pp_factor2distance) {
661  for(int k=0; k<NMDC_MAX; k++) sMDC[k].append(mm.factor);
662  } else {
663  for(int k=0; k<NMDC_MAX; k++) sMDC[k].append(mm.strain);
664  }
665  break;
666  case 2:
667  for(int k=0; k<NMDC_MAX; k++) sMDC[k].append(mm.factor);
668  break;
669  case 3:
670  case 4:
671  break;
672  }
673  for(int k=0; k<NMDC_MAX; k++) {nMDC[k].append(0.);}
674  nMDC[indx].data[nMDC[k].size()-1]+=1.;
675  }
676  }
677  if(simulation==1 && sMDC[0].size()>nfactor) {
678  cout << "cwb_report_sim.C Error : number of detected strains " << sMDC[0].size()
679  << " is greater of nfactor declared in the user_parameters.C : " << nfactor << endl;
680  bool answer = CWB::Toolbox::question("do you want to ignore this warning ? ");
681  if(!answer) exit(1);
682  }
683 
684  // for simulation==4 -> compute sMDC
685  if(simulation==4) {
686  for(int k=0; k<NMDC_MAX; k++) {
687  if(sMDC[k].size()==0) {delete [] mhrss[k];continue;}
688  // compute sMDC using median50
689  for(int i=0;i<nhrss;i++) {
690  int K = mhrss[k][i].size();
691  int* hrss_index = new int[K];
692  if(K>0) TMath::Sort(K,mhrss[k][i].data,hrss_index,kFALSE);
693  //if(K>0) cout << "XDEB " << i << " " << mhrss[k][i].data[K/2] << endl;
694  if(K>0) sMDC[k][i] = mhrss[k][i].data[hrss_index[K/2]];
695  delete [] hrss_index;
696  mhrss[k][i].resize(0);
697  }
698 /*
699  // compute sMDC using weighing hrss with inj distribution
700  for(int i=0;i<nhrss;i++) {
701  int K = mhrss[k][i].size();
702  double A=0;
703  double B=0;
704  for(int j=0;j<K;j++) {
705  double X=mhrss[k][i].data[j];
706  A+=X;
707  B+=1;
708  }
709  if(K>0) sMDC[k][i] = A/B;
710  mhrss[k][i].resize(0);
711  }
712 */
713  delete [] mhrss[k];
714  }
715  }
716 
717  int* mdc_index[NMDC_MAX];
718  for(int k=0; k<NMDC_MAX; k++) {
719  if(sMDC[k].size()==0) continue;
720  mdc_index[k] = new int[sMDC[k].size()];
721  TMath::Sort((int)sMDC[k].size(),sMDC[k].data,mdc_index[k],kFALSE);
722  }
723 
724  n = sMDC[0].size();
725  for(int i=0; i<NMDC_MAX; i++){
726  nTRG[i].resize(n); nTRG[i]=0.;
727  err[i].resize(n); err[i]=0.;
728  e00[i].resize(n); e00[i]=0.;
729  eff[i].resize(n); eff[i]=0.;
730  }
731 
732  cout<<"total events: " << ntrg << endl;
733 
734  // check if ifar exist in the wave tree
735  TBranch* branch;
736  bool ifar_exists=false;
737  TIter next(ww.fChain->GetListOfBranches());
738  while ((branch=(TBranch*)next())) {
739  if(TString("ifar").CompareTo(branch->GetName())==0) ifar_exists=true;
740  }
741  float ifar=0;
742  if (ifar_exists) ww.fChain->SetBranchAddress("ifar",&ifar);
743 
744  // loop over trigger tree
745  for(int i=0; i<ntrg; i++) {
746 
747  ww.GetEntry(i);
748  if(ww.type[1]<1) continue;
749  if(pp_merge_types) {
750  } else {
751  if(imdc_tset[ww.type[1]-1] != iset) continue; // skip unwanted injections
752  }
753 
754  // check veto cuts
755  bool bveto=false;
756  for(int j=0;j<nXDQF;j++) {
757  if((XDQF[j].cat==CWB_CAT2)&&(!VETO[j])) bveto=true;
758  if((XDQF[j].cat==CWB_CAT3)&&(VETO[j])) bveto=true;
759  if((XDQF[j].cat==CWB_HVETO)&&(VETO[j])) bveto=true;
760  }
761  if(bveto) continue;
762 
763  vED = ww.neted[0]/ww.ecor;
764 
765  if (T_vED>0) { if(vED > T_vED) continue;}
766 
767  if (T_ifar>0) if(ifar_exists) {if(ifar < T_ifar) continue;}
768 
769  // frequencies user bud cut
770  bool bcut=false;
771  for(int j=0;j<nFCUT;j++) {
772  if((ww.frequency[0]>lowFCUT[j])&&(ww.frequency[0]<=highFCUT[j])) bcut=true;
773  }
774  if(bcut) continue;
775 
776  if(ww.ecor<T_acor) continue;
777  //if(ww.ecor<0) continue;
778 
779  if(fabs(ww.time[0]-ww.time[nIFO])>T_win) continue; // skip random coincidence
780  if(pp_merge_types) {
781  indx=0;
782  } else {
783  indx = imdc_index[ww.type[1]-1];
784  }
785 
786  null = nill = etot = 0.;
787  for(int j=0; j<nIFO; j++) {
788  null += ww.null[j];
789  nill += ww.nill[j];
790  enrg[j]= ww.snr[j]-ww.null[j];
791  etot += enrg[j];
792  }
793 
794  a2or = 1.e50;
795  for(int j=0; j<nIFO; j++) {
796  if(a2or > etot-enrg[j]) a2or = etot-enrg[j];
797  }
798  // if(a2or<0.) continue;
799 
800  acor = sqrt(ww.ECOR/nIFO);
801  //rho = sqrt(ww.ECOR*fabs(ww.netcc[0])/nIFO); // = rho[1]
802  rho = ww.rho[pp_irho];
803 
804  xcor = ww.netcc[pp_inetcc];
805 
806  hcor->Fill(ww.netcc[pp_inetcc]);
807  hcc->Fill(xcor);
808  rhocc->Fill(xcor,log10(rho*rho));
809  pf_cc->Fill(xcor,ww.penalty);
810 
811  if(xcor<T_cor) continue;
812 
813  pf_vED->Fill(vED,ww.penalty);
814  hvED->Fill(fabs(vED));
815  hpf->Fill(ww.penalty);
816 
817  if(ww.netcc[3] < T_scc) continue;
818  if(ww.penalty < T_pen) continue;
819  if (T_hrss>0) if (TMath::Abs((TMath::Log10(ww.hrss[i_hrss1])-TMath::Log10(ww.hrss[i_hrss2])))>T_hrss) continue;
820 
821  bool save=false;
822  if(rho > T_cut) save=true;
823  if (!save) continue;
824 
825  hrho->Fill(log10(rho*rho));
826  eSNR->Fill(log10(ww.likelihood/nIFO));
827 
828  a = ww.phi[0]-ww.phi[1];
829  if(a> 180) a = 360-a;
830  if(a< -180) a = -360-a;
831  b = ww.theta[0]-ww.theta[1];
832  if(b> 90) b = 180-b;
833  if(b< -90) b = -180-b;
834  skyc->Fill(a,b);
835 
836  for(int j=0; j<nIFO; j++) {
837  HH[j][ninj]->Fill(log10(ww.hrss[j+nIFO]),log10(ratio_hrss*ww.hrss[j]));
838  HH[j][indx]->Fill(log10(ww.hrss[j+nIFO]),log10(ratio_hrss*ww.hrss[j]));
839 
840  double nre = ww.iSNR[j] ? (ww.iSNR[j]+ww.oSNR[j]-2*ww.ioSNR[j])/ww.iSNR[j] : 10;
841  if(nre<=0) nre=10;
842  NRE[j][ninj]->Fill(log10(ww.iSNR[j]),log10(nre));
843  NRE[j][indx]->Fill(log10(ww.iSNR[j]),log10(nre));
844 
845  ifoT[j]->Fill(ww.time[j]-ww.time[j+nIFO]);
846  }
847 
848  hT[indx]->Fill(ww.time[0]-ww.time[nIFO]);
849  hF[indx]->Fill(float(ww.frequency[0]));
850  hT[ninj]->Fill(ww.time[0]-ww.time[nIFO]);
851  hF[ninj]->Fill(float(ww.frequency[0]-(imdc_flow[indx]+imdc_fhigh[indx])/2));
852 
853  n = sMDC[0].size();
854 
855  for(int j=0; j<n; j++) {
856  switch(simulation) {
857  case 1:
858  if(pp_factor2distance) {
859  if(fabs(sMDC[0].data[j]-ww.factor)<EPSILON*ww.factor) {
860  nTRG[indx].data[j]+=1.; j=n;
861  }
862  } else {
863  if(fabs(sMDC[0].data[j]-ww.strain[1])<0.1*ww.strain[1]) { //WARNING DOUBLE HRSS
864  nTRG[indx].data[j]+=1.; j=n;
865  }
866  }
867  break;
868  case 2:
869  if(fabs(sMDC[0].data[j]-ww.factor)<EPSILON*ww.factor) {
870  nTRG[indx].data[j]+=1.; j=n;
871  }
872  break;
873  case 3:
874  case 4:
875  if(ww.strain[1]>vhrss[indx][j] && ww.strain[1]<=vhrss[indx][j+1]) {
876  nTRG[indx].data[j]+=1.; j=n;
877  }
878  break;
879  }
880  }
881  }
882 
883  if(simulation==1 && pp_factor2distance) {
884  for(int k=0; k<NMDC_MAX; k++) for(int i=0;i<sMDC[k].size();i++) sMDC[k].data[i] = pp_factor2distance/sMDC[k].data[i];
885  }
886 
887  n = sMDC[0].size();
888  cout << "INJ HRSS NUMBER: " << n << endl;
889 
890  FILE* in;
891  char f_file[256];
892  for(int i=0; i<ninj; i++) {
893  if(imdc_iset[i]!=iset) continue; // skip unwanted injection types
894  sprintf(f_file,"%s/eff_%s.txt",netdir, imdc_name[i]);
895  in = fopen(f_file,"w");
896  if(in==NULL) {cout << "cwb_report_sim : Error opening file " << f_file << endl;exit(1);}
897  for(int k=0; k<n; k++){
898  int j=mdc_index[i][k];
899  if(nMDC[i].data[j] <= 0.) continue;
900  eff[i].data[j] = nTRG[i].data[j]/nMDC[i].data[j];
901  err[i].data[j] = eff[i].data[j]>1 ? 0.01 :
902  sqrt(eff[i].data[j]*(1-eff[i].data[j])/nMDC[i].data[j]);
903  fprintf(in,"%e %i %i %.3f\n", sMDC[i].data[j], (int)nTRG[i].data[j], (int)nMDC[i].data[j], eff[i].data[j]);
904  }
905  fclose(in);
906  }
907 
908  TCanvas *c1 = new TCanvas("c","C",0,0,800,800);
909  c1->SetBorderMode(0);
910  c1->SetFillColor(0);
911  c1->SetBorderSize(2);
912  c1->SetLogx(kFALSE);
913  c1->SetGridx();
914  c1->SetGridy();
915  c1->SetLeftMargin(0.137039);
916  c1->SetRightMargin(0.117039);
917  c1->SetTopMargin(0.0772727);
918  c1->SetBottomMargin(0.143939);
919  c1->ToggleEventStatus();
920 
921  for(int i=0; i<ninj; i++) {
922  if(imdc_iset[i]!=iset) continue; // skip unwanted injection types
923 
924  fprintf(evt_all,"%2d %s ", i,imdc_name[i]);
925 
926  c1->SetLogx(kFALSE);
927  c1->SetLogy();
928 
929  c1->Clear();
930  hF[i]->Draw("HIST");
931  sprintf(fname,"%s/f_%s.gif",netdir,imdc_name[i]);
932  fprintf(evt_all,"%3.2f %3.2f ", hF[i]->GetMean(), hF[i]->GetRMS());
933  cout<<fname<<endl;
934  c1->Update(); c1->SaveAs(fname);
935 
936  c1->Clear();
937  hT[i]->Draw("HIST");
938  sprintf(fname,"%s/t_%s.gif",netdir,imdc_name[i]);
939  fprintf(evt_all,"%3.6f %3.6f ", hT[i]->GetMean(), hT[i]->GetRMS());
940  c1->Update(); c1->SaveAs(fname);
941 
942  c1->SetLogx(kFALSE);
943  c1->SetLogy(kFALSE);
944  for(int j=0;j<nIFO;j++){
945  c1->Clear();
946  HH[j][i]->Draw("HIST");
947  sprintf(fname,"%s/hrss_%s_%s.gif",netdir,IFO[j],imdc_name[i]);
948  c1->Update(); c1->SaveAs(fname);
949 
950  c1->Clear();
951  NRE[j][i]->Draw();
952  sprintf(fname,"%s/nre_%s_%s.gif",netdir,IFO[j],imdc_name[i]);
953  c1->Update(); c1->SaveAs(fname);
954  }
955 
956  fprintf(evt_all,"\n");
957  }
958 
959  c1->Clear();
960  c1->SetLogy(kTRUE);
961  c1->SetLogx(kFALSE);
962  hcor->Draw("HIST");
963  sprintf(fname,"%s/netcor_%s.gif",netdir,imdc_set_name[iset].Data());
964  c1->Update(); c1->SaveAs(fname);
965  c1->SetLogy(kFALSE);
966 
967  c1->Clear();
968  c1->SetLogy(kTRUE);
969  c1->SetLogx(kFALSE);
970  hcc->Draw("HIST");
971  sprintf(fname,"%s/cc_%s.gif",netdir,imdc_set_name[iset].Data());
972  c1->Update(); c1->SaveAs(fname);
973  c1->SetLogy(kFALSE);
974 
975  c1->Clear();
976  c1->SetLogy(kTRUE);
977  hrho->Draw("HIST");
978  sprintf(fname,"%s/rho_%s.gif",netdir,imdc_set_name[iset].Data());
979  c1->Update(); c1->SaveAs(fname);
980 
981  c1->Clear();
982  hpf->Draw("HIST");
983  sprintf(fname,"%s/penalty_%s.gif",netdir,imdc_set_name[iset].Data());
984  c1->Update(); c1->SaveAs(fname);
985 
986  c1->Clear();
987  eSNR->Draw("HIST");
988  sprintf(fname,"%s/average_snr_%s.gif",netdir,imdc_set_name[iset].Data());
989  c1->Update(); c1->SaveAs(fname);
990  c1->SetLogy(kFALSE);
991 
992  c1->Clear();
993  c1->SetLogz(kTRUE);
994  rhocc->Draw("colz");
995  sprintf(fname,"%s/rho_cc_%s.gif",netdir,imdc_set_name[iset].Data());
996  c1->Update(); c1->SaveAs(fname);
997 
998  c1->Clear();
999  c1->SetLogz(kTRUE);
1000  pf_cc->Draw("colz");
1001  sprintf(fname,"%s/penalty_cc_%s.gif",netdir,imdc_set_name[iset].Data());
1002  c1->Update(); c1->SaveAs(fname);
1003 
1004  c1->Clear();
1005  c1->SetLogz(kTRUE);
1006  skyc->Draw("colz");
1007  sprintf(fname,"%s/coordinate_%s.gif",netdir,imdc_set_name[iset].Data());
1008  c1->Update(); c1->SaveAs(fname);
1009  c1->SetLogz(kFALSE);
1010 
1011  c1->Clear();
1012  c1->SetLogz(kTRUE);
1013  pf_vED->Draw("colz");
1014  sprintf(fname,"%s/penalty_vED_%s.gif",netdir,imdc_set_name[iset].Data());
1015  c1->Update(); c1->SaveAs(fname);
1016  c1->SetLogz(kFALSE);
1017 
1018  c1->Clear();
1019  c1->SetLogy(kTRUE);
1020  hvED->Draw("HIST");
1021  sprintf(fname,"%s/vED_%s.gif",netdir,imdc_set_name[iset].Data());
1022  c1->Update(); c1->SaveAs(fname);
1023  c1->SetLogy(kFALSE);
1024 
1025  // Efficiency
1026  if(c1) delete c1;
1027  c1 = new TCanvas("c","C",0,0,1000,800);
1028  c1->SetBorderMode(0);
1029  c1->SetFillColor(0);
1030  c1->SetBorderSize(2);
1031  c1->SetLogx(kFALSE);
1032  c1->SetGridx();
1033  c1->SetGridy();
1034  c1->SetRightMargin(0.0517039);
1035  c1->SetTopMargin(0.0772727);
1036  c1->SetBottomMargin(0.143939);
1037  c1->ToggleEventStatus();
1038 
1039  double chi2, hrss50, sigma, betam, betap, hrssEr;
1040 
1041  n = sMDC[0].size();
1042 
1043  sprintf(fname,"%s/fit_parameters_%s.txt", netdir,imdc_set_name[iset].Data());
1044  in = fopen(fname,"w");
1045 
1046  int iset_size=0; // iset size
1047  for(int i=0; i<ninj; i++) if(imdc_iset[i]==iset) iset_size++;
1048  double hleg = 0.18+iset_size*0.06;
1049  delete legend;
1050  if(pp_show_eff_fit_curve) legend = new TLegend(0.45,0.18,0.99,hleg,NULL,"brNDC");
1051  else legend = new TLegend(0.55,0.18,0.99,hleg,NULL,"brNDC");
1052 
1053  for(int i=0; i<ninj; i++) {
1054  if(imdc_iset[i]!=iset) continue; // skip unwanted injection types
1055 
1056  c1->Clear();
1057  c1->SetLogx();
1058  EFF[i]=new TGraphErrors(n,sMDC[i].data,eff[i].data,e00[i].data,err[i].data);
1059  if(simulation==1 && pp_factor2distance) EFF[i]->GetXaxis()->SetTitle("distance (Kpc)");
1060  else if(simulation==2) EFF[i]->GetXaxis()->SetTitle("snr");
1061  else EFF[i]->GetXaxis()->SetTitle("hrss, #frac{strain}{#sqrt{Hz}}");
1062  EFF[i]->GetYaxis()->SetTitle("Efficiency ");
1063  EFF[i]->GetXaxis()->SetTitleOffset(1.7);
1064  EFF[i]->GetXaxis()->SetLabelSize(0.04);
1065  EFF[i]->GetYaxis()->SetTitleOffset(1.3);
1066  EFF[i]->GetYaxis()->SetRangeUser(0,1);
1067  EFF[i]->GetYaxis()->SetLabelSize(0.04);
1068 
1069  //gfit->SetParameters(-21.,1.,1.,1.);
1070  //gfit->SetParNames("hrss50","sigma","betam","betap");
1071  gfit->SetLineColor(colors[i]);
1072  //gfit->SetParLimits(0,-22.,-19.);
1073  //gfit->SetParLimits(1,0.01,50.);
1074  //gfit->SetParLimits(2,0.01,50.);
1075  //gfit->SetParLimits(3,0.01,50.);
1076  gfit->SetNpx(100000);
1077  if(pp_show_eff_fit_curve) EFF[i]->Fit("logNfit"); else EFF[i]->Fit("logNfit","N");
1078  chi2=gfit->GetChisquare();
1079  hrss50=pow(10.,gfit->GetParameter(0));
1080  hrssEr=(pow(10.,gfit->GetParError(0))-1.)*hrss50;
1081  sigma=gfit->GetParameter(1);
1082  betam=gfit->GetParameter(2);
1083  betap=gfit->GetParameter(3);
1084 
1085  printf("%d %s %E %E +- %E %E %E %E\n",
1086  i,imdc_name[i],chi2,hrss50,hrssEr,sigma,betam,betap);
1087  fprintf(in,"%2d %9.3E %9.3E +- %9.3E %9.3E %9.3E %9.3E %s\n",
1088  i,chi2,hrss50,hrssEr,sigma,betam,betap,imdc_name[i]);
1089  fprintf(in_all,"%2d %9.3E %9.3E +- %9.3E %9.3E %9.3E %9.3E %s\n",
1090  i,chi2,hrss50,hrssEr,sigma,betam,betap,imdc_name[i]);
1091 
1092  sprintf(fname,"%s, hrss50=%5.2E", imdc_name[i],hrss50);
1093  EFF[i]->SetTitle(fname);
1094  //gStyle->SetOptStat(01);
1095  gfit->SetLineColor(colors[i]);
1096  EFF[i]->SetLineColor(colors[i]);
1097  EFF[i]->SetMarkerStyle(markers[i]);
1098  EFF[i]->SetMarkerColor(colors[i]);
1099  EFF[i]->SetMarkerSize(2);
1100 
1101  legend->SetBorderSize(1);
1102  legend->SetTextAlign(22);
1103  legend->SetTextFont(12);
1104  legend->SetLineColor(1);
1105  legend->SetLineStyle(1);
1106  legend->SetLineWidth(1);
1107  legend->SetFillColor(0);
1108  legend->SetFillStyle(1001);
1109  legend->SetTextSize(0.04);
1110  legend->SetLineColor(kBlack);
1111  legend->SetFillColor(kWhite);
1112 
1113  if(pp_show_eff_fit_curve) sprintf(fname,"%s, %5.2E",imdc_name[i], hrss50);
1114  else sprintf(fname,"%s",imdc_name[i]);
1115  legend->AddEntry(EFF[i], fname, "lp");
1116  if(pp_show_eff_fit_curve) EFF[i]->Draw("AP"); else EFF[i]->Draw("APL");
1117  sprintf(fname,"%s/%s.gif",netdir,imdc_name[i]);
1118  c1->SaveAs(fname);
1119  c1->SetLogx(kFALSE);
1120  c1->Clear();
1121  }
1122  fclose(in);
1123 
1124  char gname[512];
1125  sprintf(fname,"%s/eff_%s.eps", netdir,imdc_set_name[iset].Data());
1126  sprintf(gname,"%s/eff_%s.gif", netdir,imdc_set_name[iset].Data());
1127  TPostScript epsfile(fname,113);
1128 
1129  c1->Clear();
1130  if(simulation==2) c1->SetLogx(kFALSE); else c1->SetLogx();
1131  c1->SetLogy(kFALSE);
1132 
1133  char ptitle[256];
1134  bool first=true;
1135  TMultiGraph* mg=new TMultiGraph();
1136  sprintf(ptitle,"%s rho=%3.2f, cc=%3.2f",imdc_set_name[iset].Data(),T_cut,T_cor);
1137  mg->SetTitle(ptitle);
1138  double xmin=1.79769e+308;
1139  double xmax=0;
1140  for(int i=0;i<ninj;i++) {
1141  if(imdc_iset[i]!=iset) continue; // skip unwanted injection types
1142  mg->Add(EFF[i]);
1143  if(sMDC[i].data[mdc_index[i][0]]<xmin) xmin=sMDC[i].data[mdc_index[i][0]];
1144  if(sMDC[i].data[mdc_index[i][sMDC[i].size()-1]]>xmax) xmax=sMDC[i].data[mdc_index[i][sMDC[i].size()-1]];
1145  }
1146  if(pp_show_eff_fit_curve) mg->Draw("AP"); else mg->Draw("APL");
1147  if(simulation==1 && pp_factor2distance) mg->GetHistogram()->GetXaxis()->SetTitle("distance (Kpc)");
1148  else if(simulation==2) mg->GetHistogram()->GetXaxis()->SetTitle("snr");
1149  else mg->GetHistogram()->GetXaxis()->SetTitle("hrss, #frac{strain}{#sqrt{Hz}}");
1150  mg->GetHistogram()->GetYaxis()->SetTitle("Efficiency ");
1151  mg->GetHistogram()->GetXaxis()->SetTitleOffset(1.7);
1152  mg->GetHistogram()->GetXaxis()->SetLabelSize(0.04);
1153  mg->GetHistogram()->GetYaxis()->SetTitleOffset(1.3);
1154  mg->GetHistogram()->GetXaxis()->SetRangeUser(xmin,xmax);
1155  mg->GetHistogram()->GetYaxis()->SetRangeUser(0,1);
1156  mg->GetHistogram()->GetYaxis()->SetLabelSize(0.04);
1157  legend->Draw("SAME");
1158  c1->Update(); epsfile.Close();
1159  char cmd[1024];
1160  sprintf(cmd,"convert %s %s",fname,gname);cout<<cmd<<endl;
1161  gSystem->Exec(cmd);
1162 
1163  // delete histograms
1164  for (int i=0;i<ninj+1;i++) {
1165  if((i<ninj)&&(imdc_iset[i]!=iset)) continue; // skip unwanted injection types
1166  for(int j=0;j<nIFO;j++) if(HH[j][i]) delete HH[j][i];
1167  for(int j=0;j<nIFO;j++) if(NRE[j][i]) delete NRE[j][i];
1168  if(hT[i]) delete hT[i];
1169  if(hF[i]) delete hF[i];
1170  }
1171 
1172  delete hcor;
1173  delete hcc;
1174  delete hrho;
1175  delete eSNR;
1176  delete rhocc;
1177  delete skyc;
1178  delete hpf;
1179  delete hvED;
1180  delete pf_cc;
1181  delete pf_vED;
1182 
1183  for (int j=0;j<nIFO;j++) {
1184  delete hrs1[j];
1185  delete hrs2[j];
1186  delete ifoT[j];
1187  }
1188 
1189  if(simulation==4) {
1190  for(int k=0; k<NMDC_MAX; k++) {
1191  if(sMDC[k].size()==0) continue;
1192  delete [] mdc_index[k];
1193  }
1194  }
1195  for(int i=0;i<NMDC_MAX;i++) if(EFF[i]) {delete EFF[i];EFF[i]=NULL;}
1196  delete mg;
1197  }
1198 
1199  fclose(in_all);
1200  fclose(evt_all);
1201 
1202  exit(0);
1203 }
int i_hrss2
char ch2[2048]
size_t append(const wavearray< DataType_t > &)
Definition: wavearray.cc:793
double rho
double T_ifar
TChain sim("waveburst")
double T_pen
void Export(TString fname="")
Definition: config.cc:406
double fHigh
wavearray< double > a(hp.size())
TH2F * pf_cc
par [0] name
int n
Definition: cwb_net.C:28
dqfile VDQF[100]
double rho_min
TString("c")
int nset
Definition: cwb_mkeff.C:75
char ifo[32]
Definition: Toolbox.hh:84
double T_cor
double T_hrss
TH1F * hpf
float xfactors
ofstream out
Definition: cwb_merge.C:214
float ratio_hrss
int xmdc_type
UChar_t VETO[100]
TString mdc[4]
dqfile * XDQF
i pp_inetcc
Long_t size
Color_t colors[16]
int m
Definition: cwb_net.C:28
static TString CWB_CAT_NAME[14]
Definition: GToolbox.hh:21
int nVDQF
int j
Definition: cwb_net.C:28
i drho i
void Import(TString umacro="")
Definition: config.cc:352
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
int nmdc
size_t imdc_iset[NMDC_MAX]
Definition: cwb_mkeff.C:68
exit(0)
FILE * in_all
char ifo[NIFO_MAX][8]
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
TH1F * hF[NIFO_MAX+1]
nc append(pix)
#define nIFO
CWB_CAT cat
Definition: Toolbox.hh:86
virtual size_t size() const
Definition: wavearray.hh:145
double T_acor
int nXDQF
size_t imdc_index[NMDC_MAX]
Definition: cwb_mkeff.C:67
double vED
char mdc_inj_file[1024]
Definition: cwb_dump_inj.C:98
double pp_rho_min
static bool isLeafInTree(TTree *itree, TString leaf)
Definition: Toolbox.cc:5466
TCanvas * c1
char netdir[1024]
const int NIFO_MAX
Definition: wat.hh:22
x resize(N)
bool log
Definition: WaveMDC.C:41
int ninj
Definition: cwb_mkeff.C:70
printf("total live time: non-zero lags = %10.1f \, liveTot)
char fname[4096]
TIter next(twave->GetListOfBranches())
fclose(fp)
#define nMDC
double acor
int k
int i_hrss1
pp_rho_bin
double sigma
char imdc_name[NMDC_MAX][128]
Definition: cwb_mkeff.C:64
sprintf(fname,"%s/eff_%d_threshold_factors.txt", netdir, pp_eff)
TH2F * pf_vED
double pp_rho_max
static bool question(TString question)
Definition: Toolbox.cc:4808
WSeries< double > ww
Definition: Regression_H1.C:33
int ReadInjType(TString ifName, int ntype_max, char set[][128], size_t type[], char name[][128], double fcentral[], double fbandwidth[])
Definition: Toolfun.hh:816
char sim_file_name[1024]
char answer[256]
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:6727
ifstream in
double fLow
char IFO[NIFO_MAX][32]
double T_win
double fabs(const Complex &x)
Definition: numpy.cc:55
TString pp_eff_vs_thr_quit
double highFCUT[100]
static void mkDir(TString dir, bool question=false, bool remove=true)
Definition: Toolbox.cc:4714
TBranch * branch
TH1F * hvED
char cmd[1024]
strcpy(RunLabel, RUN_LABEL)
int nfactor
Definition: test_config1.C:83
double T_cut
double asnr
DataType_t * data
Definition: wavearray.hh:319
#define NMDC_MAX
int cat
size_t imdc_type[NMDC_MAX]
Definition: cwb_mkeff.C:63
char xmdc_name[256]
double T_scc
bool save
double T_vED
simulation
Definition: cwb_eced.C:26
char mdc_file_name[1024]
TString config
detectorParams detParms[4]
factors[0]
Definition: cwb_eced.C:27
TString * imdc_set_name
Definition: cwb_mkeff.C:74
virtual void resize(unsigned int)
Definition: wavearray.cc:463
double imdc_fcentral[NMDC_MAX]
Definition: cwb_mkeff.C:65
TMultiGraph * mg
Double_t logNfit(Double_t *x, Double_t *par)
Definition: Toolfun.hh:42
double frequency(int l)
Definition: wseries.cc:117
i drho pp_irho
double lowFCUT[100]
char imdc_set[NMDC_MAX][128]
Definition: cwb_mkeff.C:62
void SetSingleDetectorMode()
Definition: config.cc:1352
#define EPSILON
double xcor
TString pp_eff_vs_thr
double imdc_fbandwidth[NMDC_MAX]
Definition: cwb_mkeff.C:66
FILE * evt_all
TH2F * rhocc