Logo coherent WaveBurst  
Config Reference Guide
Logo
Make_PP_IFAR.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 
20 // ---------------------------------------------------------------------------------
21 // INFOS
22 // ---------------------------------------------------------------------------------
23 
24 // this macro produce the plot number of events in the observation period vs IFAR
25 
26 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 // The macro Make_PP_IFAR_GW151226_RATE.C is the standard macro in cWB config master.2.8 + add GW151226 event in O1 data
28 // set a superior limit @ GW170104 IFAR -> set a limit for BBH IFAR, ecluded BBH IFAR estimated as lower limits (IFAR_TAG)
29 // compute the index which contains the maximum common IFAR for rates -> limits the sim green plot (RATE_TAG)
30 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 
32 // input list chunk root files format
33 //
34 // wave_merged_root_file_name_with_ifar.root lag slag chunk chunkLabel
35 // Ex: K02,K03 open box
36 // wave_O2_K02_merged_root_file_name_with_ifar.root 0 0 2 K02
37 // wave_O2_K03_merged_root_file_name_with_ifar.root 0 0 3 K03
38 
39 // ---------------------------------------------------------------------------------
40 // HOW RUN THIS MACRO (EXAMPLES)
41 // ---------------------------------------------------------------------------------
42 
43 /*
44 
45 // uses a list of input root merged files generated by different chunks
46 root 'Make_PP_IFAR.C("pp_lag0_slag0_M2.lst", "--search=BurstLF:bin2 \\
47  --exit=1 --pfname=pp_plot_bin2_kall_lag0_slag0_M2.png")'
48 
49 // uses a single chunk root merged file
50 root 'Make_PP_IFAR.C("wave_merged_output_root_file.root", "--search=BurstLF:bin2 --lag=0 --slag=0 \\
51  --chunk=0 --exit=1 --pfname=pp_plot_bin2_kall_lag0_slag0_M2.png")'
52 
53 */
54 
55 #include "ReadChunkList.C"
56 
57 // ---------------------------------------------------------------------------------
58 // USER DEFINES : Default values used to initialize the user options input parameters
59 // ---------------------------------------------------------------------------------`
60 
61 #define PP_RUN "O3"
62 #define PP_SEARCH ""
63 
64 #define PP_NIFO 2
65 #define PP_LAG -1
66 #define PP_SLAG -1
67 #define PP_CHUNK -1
68 
69 #define PP_TRIALS 1
70 
71 #define PP_PFNAME ""
72 #define PP_ZL_STYLE "step"
73 #define PP_BELT_STYLE "continuos"
74 
75 #define PP_IFAR_MAX -1
76 #define PP_RHO_MIN 4.5
77 
78 #define PP_SFACTOR 1
79 
80 #define PP_BBH false
81 #define PP_EXIT true
82 
83 #define PP_GW151226_IFAR 0
84 #define PP_ZL_MAX_IFAR 0
85 
86 // ---------------------------------------------------------------------------------`
87 // DEFINES
88 // ---------------------------------------------------------------------------------`
89 
90 #define MAX_RUNS 3 // O1,O2,O3
91 
92 #define MAX_LIST_SIZE 100 // maximum number of input root files in the input file list
93 #define IFAR_NBIN 2000 // number of bins used for the computation of belts and background
94  // NOTE: if such value is low it introduces some discretization artifacts for low IFAR values
95 
96 //#define FAP0 0.1 // FAP used to define the first belt : SIGMA = 1.644
97 //#define FAP1 0.01 // FAP used to define the second belt : SIGMA = 2.575
98 //#define FAP2 0.001 // FAP used to define the third belt : SIGMA = 3.290
99 
100 //
101 // Probability = TMath::Erf(Sigma/sqrt(2))
102 // Sigma = TMath::ErfInverse(Probability)*sqrt(2)
103 
104 #define FAP0 (1.-0.682689) // FAP used to define the first belt : SIGMA = 1.
105 #define FAP1 (1.-0.954499) // FAP used to define the second belt : SIGMA = 2.
106 #define FAP2 (1.-0.997300) // FAP used to define the third belt : SIGMA = 3.
107 
108 #define DAY (24.*3600.)
109 #define YEAR (24.*3600.*365.)
110 
111 #define CHUNK_FILE_LIST "Chunk_List.txt"
112 #define CHUNK_MAX_SIZE 100
113 
114 //#define APPLY_MAX_SIM_IFAR // if enabled the detected & sim events are cut to the common superior limit
115 
116 //#define PLOT_FOREGROUND_NOBBH // plot ZL BBH && ZL NOBBH
117 
118 #define PA_FILE_LIST "Public_Alerts.lst"
119 
120 // ---------------------------------------------------------------------------------
121 // INPUT USER OPTIONS
122 // ---------------------------------------------------------------------------------
123 
124 struct uoptions {
125  TString run; // run type: allowed types are O1/O2/O1O2/O3
126  TString search; // search type: allowed types are BBH,BurstLF,BurstHF,BurstLD,IMBHB + bin1/bin2/...
127 
128  int nifo; // number of detectors
129  int lag; // lag -> used only when the input file name is a root file
130  int slag; // slag -> used only when the input file name is a root file
131  int chunk; // chunk -> used only when the input file name is a root file
132 
133  int trials; // trials factor
134 
135  TString pfname; // output plot file name, included the directory
136  TString zl_style; // zero lag plot style: step/marker -> zero lag is displayed with step/marker
137  TString belt_style; // belt plot style: step/continuos -> belts are displayed with step/continuos poisson distribution
138 
139  double ifar_max; // max ifar (year) used for plot, if =-1 then it is the maximum ifar from root files
140  double rho_min; // min rho[0/1] read from output root files
141 
142  double sfactor; // factor used to normalize the simulation events for the computation of astrophysical rates
143  // SIM_NEVT/=gOPT.sfactor
144  bool bbh; // if false the known bbh events are excluded from analysis
145  bool exit; // if true program exit ayt the end of the execution
146 
147  double gw151226_ifar; // GW151226 IFAR(YEARS): if > 0 the GW151226 event is added to the foreground (def=0, not added)
148  // This is a special option introduced for the GW151226 event which has been found only into the extended segments
149 
150  double zl_max_ifar; // It is used to set the maximum IFAR of foreground events (YEARS).
151  // The value to be used is the minimum common foreground IFAR for which the IFAR is well estimated
152  // The foreground with IFAR>zl_max_ifar is set to zl_max_ifar
153 };
154 
155 
156 // ---------------------------------------------------------------------------------
157 // Global Variables
158 // ---------------------------------------------------------------------------------
159 
160 // global User Options
161 
162 uoptions gOPT;
163 
164 // plot objects
165 
166 TCanvas* canvas;
167 TGraph* gr;
168 TGraph* grsim;
169 TGraph* grsimbkg;
170 TGraphAsymmErrors* egrsimbkg0;
171 TGraph* gr0;
172 TLegend* leg0;
173 TLegend* leg;
174 TMarker* marker;
175 TArrow* arrow;
176 TLatex *latex;
177 TGraphAsymmErrors* egr0;
178 TGraphAsymmErrors* egr1;
179 TGraphAsymmErrors* egr2;
180 
181 // wavearray used for plots
182 
183 wavearray<double> xIFAR;
184 wavearray<double> xFAR;
185 wavearray<double> bRATE;
186 wavearray<double> yBKG;
187 
188 wavearray<double> SIM_IFAR; // sorted ifar simulated events
189 wavearray<double> SIM_NEVT; // number of simulated events with ifar > SIM_IFAR[k]
190 wavearray<double> SIM_BKG_NEVT; // number of simulated events + expected from BKG with ifar > SIM_IFAR[k]
191 
192 // SIM+BKG FAP0 belts
193 wavearray<double> ySIM_BKG;
194 wavearray<double> exSIM_BKG_IFAR;
195 wavearray<double> xSIM_BKG_IFAR;
196 wavearray<double> eySIM_BKG_inf0;
197 wavearray<double> eySIM_BKG_sup0;
198 
199 wavearray<double> ZL_IFAR; // sorted ifar events
200 wavearray<double> ZL_NEVT; // number of events with ifar > ZL_IFAR[k]
201 wavearray<double> ZL_GPS; // event GPS time
202 
203 // FAP0/FAP1/FAP2 error belts
204 wavearray<double> exFAR;
205 wavearray<double> eyRATEinf0;
206 wavearray<double> eyRATEsup0;
207 wavearray<double> eyRATEinf1;
208 wavearray<double> eyRATEsup1;
209 wavearray<double> eyRATEinf2;
210 wavearray<double> eyRATEsup2;
211 
212 // O1 known BBH events
213 vector<TString> O1_BBH_NAME;
214 vector<double> O1_BBH_GPS;
215 
216 // O2 known BBH events
217 vector<TString> O2_BBH_NAME;
218 vector<double> O2_BBH_GPS;
219 
220 // O3 known BBH events
221 vector<TString> O3_BBH_NAME;
222 vector<double> O3_BBH_GPS;
223 
224 // chunks id,start,stop
229 
230 // ---------------------------------------------------------------------------------
231 // FUNCTIONS
232 // ---------------------------------------------------------------------------------
233 
234 void ResetUserOptions();
235 void ReadUserOptions(TString options);
236 void PrintUserOptions();
237 void DumpUserOptions();
238 
239 void InitBBH(); // init array Ox_BBH_NAME,Ox_BBH_GPS with known BBH events
240 TString GetNameBBH(double gps); // return the BBH name
241 double GetGPSBBH(TString name); // return the BBH GPS
242 TString GetCutBBH(); // return the cut string used to exclude BBH events from tree selection
243 int ReadPublicAlerts(); // read public alerts, implemented only for O3
244 
245 int GetChunkID(double gps, TString& run); // return chunk ID for a gine gps time
246 int GetPercentiles(double mu, double* q); // return percentiles in q for FAP0,FAP1,FAP2 (continuos)
247 int GetPoissonNsup(double mu, double fap); // return sup number expeted events of for a gine fap
248 int GetPoissonNinf(double mu, double fap); // return inf number expeted events of for a gine fap
249 int ReadFileList(TString ifName, TChain** live, TChain** wave, TChain** mdc, int* lag, int* slag, int* chunk, int* bin, TString* run); // read input root file list
250 void GetLiveTime(int nwave, TChain** live, int* lag, int* slag, int* bin, TString* run, double* liveZero, double* liveTot); // retun live time
251 
252 void MakePlot(TString title, double obsTime, double ifar_cmax); // make final IFAR plot
253 void DumpLoudest(double obsTime); // dump to ascii file the loudest zero lag event list
254 void DumpPeriod(double* obsTime);
255 void DumpBackground(); // Dumps Background & Belts in ASCII format
256 void DumpForeground(); // Dumps Foreground in ASCII format
257 void DumpSimulation(double ifar_cmax); // Dumps Simulation & Belts in ASCII format
258 
259 
260 void Make_PP_IFAR(TString ifName, TString options) {
261 
262  // -----------------------------------------------------
263  // Read Input Options
264  // -----------------------------------------------------
265 
269 
270  if((gOPT.run!="O1")&&(gOPT.run!="O2")&&(gOPT.run!="O1O2")&&(gOPT.run!="O3")) {
271  cout << "Make_PP_IFAR - Error : run option not allowed, must be O1/O2/O1O2/O3" << endl;
272  gSystem->Exit(1);
273  }
274 
275  TString SEARCH = gOPT.search;
276  if(gOPT.search.Contains(":")) SEARCH = gOPT.search(0,gOPT.search.Index(":",0));
277  if((SEARCH!="BBH")&&(SEARCH!="IMBHB")&&(SEARCH!="BurstLF")&&(SEARCH!="BurstHF")&&(SEARCH!="BurstLD")) {
278  cout << "Make_PP_IFAR - Error : search option not allowed, must be BBH/IMBHB/BurstLF/BurstHF/BurstLD + ':bin1/bin2/...'" << endl;
279  gSystem->Exit(1);
280  }
281 
282  if(gOPT.trials<=0) {
283  cout << "Make_PP_IFAR - Error : trials value not allowed, must be >0" << endl;
284  gSystem->Exit(1);
285  }
286 
287  if(gOPT.sfactor<=0) {
288  cout << "Make_PP_SFACTOR - Error : sfactor value not allowed, must be >0" << endl;
289  gSystem->Exit(1);
290  }
291 
292  if(gOPT.nifo!=2 && gOPT.nifo!=3) {
293  cout << "Make_PP_IFAR - Error : nifo value not allowed, must 2/3" << endl;
294  gSystem->Exit(1);
295  }
296 
297  if((gOPT.zl_style!="step")&&(gOPT.zl_style!="marker")) {
298  cout << "Make_PP_IFAR - Error : zl_style value not allowed, must be step/marker" << endl;
299  gSystem->Exit(1);
300  }
301 
302  if((gOPT.belt_style!="step")&&(gOPT.belt_style!="continuos")) {
303  cout << "Make_PP_IFAR - Error : belt_style value not allowed, must be step/continuos" << endl;
304  gSystem->Exit(1);
305  }
306 
307  // check if is a root file
308  TString fext = ifName(ifName.Last('.')+1,4);
309  if(fext=="root") {
310  if(gOPT.lag<0 || gOPT.slag<0 || gOPT.chunk<0) {
311  cout << "Make_PP_IFAR - Error : when input file ext=root lag,slag,chunk must be >=0" << endl;
312  gSystem->Exit(1);
313  }
314  }
315 
316  DumpUserOptions();
317 
318  if(gOPT.exit) gROOT->SetBatch(kTRUE); // NOTE: batch mode save plot with high quality !!!
319 
320  // initialize wavearray
321  xIFAR.resize(IFAR_NBIN);
322  xFAR.resize(IFAR_NBIN);
323  bRATE.resize(IFAR_NBIN);
324  yBKG.resize(IFAR_NBIN);
325 
326  exFAR.resize(IFAR_NBIN); exFAR=0;
327  eyRATEinf0.resize(IFAR_NBIN);
328  eyRATEsup0.resize(IFAR_NBIN);
329  eyRATEinf1.resize(IFAR_NBIN);
330  eyRATEsup1.resize(IFAR_NBIN);
331  eyRATEinf2.resize(IFAR_NBIN);
332  eyRATEsup2.resize(IFAR_NBIN);
333 
334  ySIM_BKG.resize(IFAR_NBIN);
336  xSIM_BKG_IFAR.resize(IFAR_NBIN);
337  eySIM_BKG_inf0.resize(IFAR_NBIN);
338  eySIM_BKG_sup0.resize(IFAR_NBIN);
339 
340  InitBBH(); // init known BBH
341 
342 
343  // -----------------------------------------------------
344  // Read Chunk start stop GPS times
345  // -----------------------------------------------------
346 
347  // get CWB_CONFIG
348  char cwb_config_env[1024] = "";
349  if(gSystem->Getenv("CWB_CONFIG")!=NULL) {
350  strcpy(cwb_config_env,TString(gSystem->Getenv("CWB_CONFIG")).Data());
351  }
352 
353  for(int n=0;n<MAX_RUNS;n++) {
354 
355  TString RUN;
356 
357  if(n==0 && gOPT.run.Contains("O1")) RUN="O1";
358  else
359  if(n==1 && gOPT.run.Contains("O2")) RUN="O2";
360  else
361  if(n==2 && gOPT.run.Contains("O3")) RUN="O3";
362  else continue;
363 
364  char chunk_file_list[1024];
365  sprintf(chunk_file_list,"%s/%s/CHUNKS/%s/%s",cwb_config_env,RUN.Data(),SEARCH.Data(),CHUNK_FILE_LIST);
366  cout << chunk_file_list << endl;
367 
368  cout << endl;
369  cout << "----------------------------------------------------------------------------------------------------" << endl;
370  cout << "chunk" << "\t\t" << "start" << "\t\t" << "stop" << "\t\t"
371  << " days\t\t" << "beg-date" << " - " << "end-date" << "\t" << "run" << endl;
372  cout << "----------------------------------------------------------------------------------------------------" << endl;
373  cout << endl;
374 
375  chunk_size[n] = ReadChunkList(chunk_file_list, chunk_id[n], chunk_start[n], chunk_stop[n]);
376 
377  cout << "----------------------------------------------------------------------------------------------------" << endl;
378  cout << endl;
379  }
380 
381  // -----------------------------------------------------
382  // open wave root trees
383  // -----------------------------------------------------
384 
385  int rho_id;
386  if(SEARCH=="BBH" || SEARCH=="IMBHB") rho_id=1;
387  else rho_id=0;
388 
389  TString run[MAX_LIST_SIZE];
390  int bin[MAX_LIST_SIZE];
391  int chunk[MAX_LIST_SIZE];
392  int lag[MAX_LIST_SIZE];
393  int slag[MAX_LIST_SIZE];
394 
395  TChain* live[MAX_LIST_SIZE];
396  for(int i=0;i<MAX_LIST_SIZE;i++) live[i] = new TChain("liveTime");
397 
398  TChain* wave[MAX_LIST_SIZE];
399  for(int i=0;i<MAX_LIST_SIZE;i++) wave[i] = new TChain("waveburst");
400 
401  TChain* mdc[MAX_LIST_SIZE];
402  for(int i=0;i<MAX_LIST_SIZE;i++) mdc[i] = new TChain("mdc");
403 
404  int nwave = 1;
405  if(fext=="root") {
406  chunk[0] = gOPT.chunk;
407  lag[0] = gOPT.lag;
408  slag[0] = gOPT.slag;
409  run[0] = gOPT.run;
410  bin[0] = 0;
411  TString fwave = ifName;
412  TString flive = ifName;
413  flive.ReplaceAll("wave_","live_");
414  wave[0]->Add(fwave);
415  live[0]->Add(flive);
416  wave[0]->SetTitle(fwave);
417  live[0]->SetTitle(flive);
418  } else {
419  // Read File List & Fill TChain
420  nwave = ReadFileList(ifName, live, wave, mdc, lag, slag, chunk, bin, run);
421  gOPT.lag = lag[0];
422  gOPT.slag = slag[0];
423  gOPT.chunk = chunk[0];
424  }
425  cout << endl;
426  if(nwave<=0) {
427  cout << "Make_PP_IFAR - Error : no files read from input list, check input list format" << endl;
428  gSystem->Exit(1);
429  }
430 
431  // check if slag and lag are consistent
432  int xlag=lag[0];
433  int xslag=slag[0];
434  for(int i=1;i<nwave;i++) {
435  if(bin[i]<0) continue; // simulation
436  if(lag[i]!=xlag || slag[i]!=xslag) {
437  cout << "Make_PP_IFAR - Error : lag,slag defined in input list root files are not consistent" << endl;
438  gSystem->Exit(1);
439  }
440  }
441 
442  // check duplicated entries
443  for(int i=0;i<nwave;i++) {
444  if(bin[i]<0) continue; // simulation
445  for(int j=0;j<nwave;j++) {
446  if(bin[j]<0) continue; // simulation
447  if((i!=j) && (lag[i]==lag[j] && slag[i]==slag[j] && chunk[i]==chunk[j] && bin[i]==bin[j] && TString(wave[i]->GetTitle())==TString(wave[j]->GetTitle()))) {
448  cout << "Make_PP_IFAR - Error : input file list contains duplicated entries for lag,slag,chunk,bin = "
449  << lag[i] << "," << slag[i] << "," << chunk[i] << "," << bin[i] << endl;
450  cout << " : "
451  << wave[i]->GetTitle() << endl;
452  gSystem->Exit(1);
453  }
454  }
455  }
456 
457  // check consistency bin1 bin2 entries
458  vector<int> vbin; // contains the list of unique bins
459  for(int i=0;i<nwave;i++) {
460  if(bin[i]<0) continue; // simulation
461  bool exist=false;
462  for(int j=0;j<vbin.size();j++) if(bin[i]==vbin[j]) exist=true;
463  if(!exist) vbin.push_back(bin[i]);
464  }
465  for(int i=0;i<nwave;i++) {
466  if(bin[i]<0) continue; // simulation
467  int nbins=1;
468  for(int j=0;j<nwave;j++) {
469  if(bin[j]<0) continue; // simulation
470  if((i!=j) && (lag[i]==lag[j] && slag[i]==slag[j] && chunk[i]==chunk[j])) {
471  for(int k=0;k<vbin.size();k++) if(bin[j]!=vbin[k]) nbins++;
472  }
473  }
474  if(nbins!=vbin.size()) {
475  cout << "Make_PP_IFAR - Error : input file list must contains all bins for each chunk: "
476  << wave[i]->GetTitle() << endl;
477  cout << " lag,slag,chunk,bin = "
478  << lag[i] << "," << slag[i] << "," << chunk[i] << "," << bin[i] << endl;
479  gSystem->Exit(1);
480  }
481  }
482 
483  // -----------------------------------------------------
484  // compute live time
485  // -----------------------------------------------------
486 
487  double liveTot[MAX_RUNS];
488  double liveZero[MAX_RUNS];
489  for(int n=0;n<MAX_RUNS;n++) {liveTot[n]=0;liveZero[n]=0;}
490 
491  GetLiveTime(nwave, live, lag, slag, bin, run, liveZero, liveTot);
492 
493  double obsTime=0;
494  for(int n=0;n<MAX_RUNS;n++) {
495 
496  obsTime+=liveTot[n]/gOPT.trials; // apply trials factor
497 
498  TString RUN;
499  if(n==0) RUN="O1";
500  if(n==1) RUN="O2";
501  if(n==2) RUN="O3";
502  printf("%s : total live time: non-zero lags = %10.1f sec, %10.2f days, %10.4f years \n\n",RUN.Data(),liveTot[n],liveTot[n]/DAY,liveTot[n]/YEAR);
503  }
504 
505  printf("%s : total observational time: non-zero lags = %10.1f sec, %10.2f days, %10.4f years \n\n",gOPT.run.Data(),obsTime,obsTime/DAY,obsTime/YEAR);
506 
507 
508  // =======================================================================
509  // DETECTED EVENTS STUFF
510  // =======================================================================
511 
512  // -----------------------------------------------------
513  // Get BBH cut string
514  // -----------------------------------------------------
515 
516  TString CutBBH = GetCutBBH();
517 
518  // -----------------------------------------------------
519  // compute min.max ifar in wave files
520  // -----------------------------------------------------
521 
522  double ifar_cmin = 0; // minimum common IFAR
523  double ifar_cmax = 1e100; // maximum common IFAR (used for rate plots) (RATE_TAG)
524  double ifar_max = 0;
525  double value;
526  for(int m=0;m<nwave;m++) {
527  if(bin[m]<0) continue; // simulation
528  int isize = (int)wave[m]->GetEntries();
529  wave[m]->SetEstimate(isize);
530  char cut[64]; sprintf(cut,"rho[%d]>%f",rho_id,gOPT.rho_min);
531  wave[m]->Draw("ifar",cut,"goff",isize);
532  double* ifar = wave[m]->GetV1();
533  int sel_entries = wave[m]->GetSelectedRows();
534  value = log10(TMath::MinElement(sel_entries,ifar));
535  if(fext=="root")
536  cout << "tMax events per year : " << (1./pow(10,value))*YEAR << endl;
537  else
538  cout << "chunk\t" << chunk[m] << "\tbin\t" << bin[m] << "\tMax events per year : " << (1./pow(10,value))*YEAR << endl;
539  if(value>ifar_cmin) ifar_cmin=value; // this condition is used to select the common IFAR inferior limit
540  value = log10(TMath::MaxElement(sel_entries,ifar));
541  if(value>ifar_max) ifar_max=value; // this condition is used to select the maximum IFAR limit
542  if(value<ifar_cmax) ifar_cmax=value; // this condition is used to select the common IFAR superior limit (RATE_TAG)
543  }
544 
545  cout << endl;
546  cout << "ifar_cmin : " << pow(10,ifar_cmin)/YEAR << " years" << endl;
547  cout << "ifar_cmax : " << pow(10,ifar_cmax)/YEAR << " years" << endl; // (RATE_TAG)
548  cout << "ifar_max : " << pow(10,ifar_max)/YEAR << " years" << endl;
549 
550  double inf = ifar_cmin;
551  double sup = TMath::Nint(ifar_max+0.5);
552 
553  TString Cuts="";
554 
555  // -----------------------------------------------------
556  // read zero ifar lag events
557  // -----------------------------------------------------
558 
559  char sel[1024];
560  char tmp[1024];
561  cout << endl;
562  vector<double> vIFAR;
563  vector<double> vGPS;
564  int nsel=0;
565  for(int m=0;m<nwave;m++) {
566  if(bin[m]<0) continue; // simulation
567  Cuts = CutBBH;
568  // ------------------------> APPLY TRIALS FACTOR !!!
569  sprintf(sel,"ifar/%d:time[0]",gOPT.trials);
570  sprintf(tmp,"ifar>%f",pow(10,ifar_cmin)*gOPT.trials);
571  if(lag[m]==-1 && slag[m]==-1) sprintf(tmp,"ifar>%f && lag[%d]!=0 && rho[%d]>%f",pow(10,ifar_cmin)*gOPT.trials,gOPT.nifo,rho_id,gOPT.rho_min);
572  if(lag[m]>= 0 && slag[m]==-1) sprintf(tmp,"ifar>%f && lag[%d]==%d && rho[%d]>%f",pow(10,ifar_cmin)*gOPT.trials,gOPT.nifo,lag[m],rho_id,gOPT.rho_min);
573  if(lag[m]>= 0 && slag[m]>= 0) sprintf(tmp,"ifar>%f && lag[%d]==%d && slag[%d]==%d && rho[%d]>%f",pow(10,ifar_cmin)*gOPT.trials,gOPT.nifo,lag[m],gOPT.nifo,slag[m],rho_id,gOPT.rho_min);
574  if(gOPT.bbh) {
575  Cuts = TString::Format("%s ",tmp);
576  } else {
577  Cuts += TString::Format(" && %s ",tmp);
578  }
579  cout << "CutBBH : " << Cuts << endl;
580  wave[m]->SetEstimate(wave[m]->GetEntries());
581  wave[m]->Draw(sel,Cuts.Data(),"goff");
582  nsel+= wave[m]->GetSelectedRows();
583  double* V1 = wave[m]->GetV1();
584  double* V2 = wave[m]->GetV2();
585  for(int k=0;k<wave[m]->GetSelectedRows();k++) {vIFAR.push_back(V1[k]);vGPS.push_back(V2[k]);}
586  }
587 
588  // IF gOPT.gw151226_ifar>0 -> ADD GW151226 Event !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
589  // This is a special option introduced for the GW151226 event which has been found only into the extended segments
590  if(gOPT.bbh && gOPT.gw151226_ifar>0) {
591  vIFAR.push_back(gOPT.gw151226_ifar*YEAR);vGPS.push_back(GetGPSBBH("GW151226"));
592  }
593 
594  // -----------------------------------------------------
595  // sort ifar zero lag events
596  // -----------------------------------------------------
597 
598  if(vIFAR.size()>0) {
599  int size = vIFAR.size();
600  int *index = new int[size];
601  double *IFAR = new double[size];
602  for(int k=0;k<size;k++) IFAR[k]=vIFAR[k];
603  TMath::Sort(size,IFAR,index,true);
604  if(gOPT.zl_style=="marker") {
605  ZL_GPS.resize(size);
606  ZL_IFAR.resize(size);
607  ZL_NEVT.resize(size);
608  for(int k=0;k<size;k++) { // invert the ifar order
609  ZL_GPS[size-k-1] = vGPS[index[k]]; // event GPS time
610  ZL_IFAR[size-k-1] = IFAR[index[k]]/YEAR; // sorted ifar events
611  ZL_NEVT[size-k-1] = k+1; // number of events with ifar > ZL_IFAR[k]
612  }
613  } else { // step
614  ZL_GPS.resize(2*size-1);
615  ZL_IFAR.resize(2*size-1);
616  ZL_NEVT.resize(2*size-1);
617  int n=0;
618  for(int k=size-1;k>=0;k--) { // invert the ifar order
619  ZL_GPS[n] = vGPS[index[k]]; // event GPS
620  ZL_IFAR[n] = IFAR[index[k]]/YEAR; // sorted ifar events
621  ZL_NEVT[n] = k+1; // number of events with ifar > ZL_IFAR[k]
622  n++;
623  if(n>=ZL_NEVT.size()-1) break;
624  // add point to make ZL STYLE STEPWISE
625  ZL_GPS[n] = ZL_GPS[n-1];
626  ZL_IFAR[n] = ZL_IFAR[n-1];
627  ZL_NEVT[n] = ZL_NEVT[n-1]-1;
628  n++;
629  }
630  }
631  delete [] index;
632  delete [] IFAR;
633  // The foreground with IFAR>zl_max_ifar is set to zl_max_ifar
634  if(gOPT.zl_max_ifar>0) {
635  for(int k=0;k<ZL_NEVT.size();k++) if(ZL_IFAR[k]>gOPT.zl_max_ifar) ZL_IFAR[k]=gOPT.zl_max_ifar;
636  }
637  }
638 
639  // adjust sup limit according to the loudest zero lag event
640  double loudest_zl_ifar_sec = ZL_NEVT.size()>0 ? ZL_IFAR[ZL_NEVT.size()-1]*YEAR : 0;
641  if(log10(loudest_zl_ifar_sec)>sup) sup=log10(loudest_zl_ifar_sec);
642  if(inf>0 && sup/inf<2) sup=2*inf;
643  else sup*=1.01;
644 
645  if(pow(10, inf)/YEAR>0.01) inf=log10(0.01*YEAR);
646 
647  if(gOPT.ifar_max>0) sup = log10(gOPT.ifar_max*YEAR);
648 
649  cout << endl;
650  cout << "ifar inf : " << pow(10, inf)/YEAR << " years" << endl;
651  cout << "ifar sup : " << pow(10, sup)/YEAR << " years" << endl;
652 
653  double difar_bin = (sup-inf)/IFAR_NBIN;
654 
655 
656  // =======================================================================
657  // SIMULATED EVENTS STUFF USED TO COMPUTE ASTROPHYSICAL RATES
658  // =======================================================================
659 
660  // -----------------------------------------------------
661  // read ifar simulated events
662  // -----------------------------------------------------
663 
664  double ifar_sim_min = 0;
665  double ifar_sim_max = 1.e20;
666 
667  while(!vIFAR.empty()) vIFAR.pop_back();
668  vIFAR.clear(); std::vector<double>().swap(vIFAR);
669  vector<int> vNINJ; // store injections per chunk in each event (used for normalization)
670 
671  cout << endl;
672  for(int m=0;m<nwave;m++) {
673  if(bin[m]>=0) continue; // select simulation root files
674 
675  int ninj = mdc[m]->GetEntries();
676  cout << run[m] << "\t" << chunk[m] << "\tmdc injected entries : " << ninj << endl;
677 
678  wave[m]->SetEstimate(wave[m]->GetEntries());
679  // ------------------------> APPLY TRIALS FACTOR !!!
680  sprintf(sel,"ifar/%d",gOPT.trials);
681  sprintf(tmp,"ifar>%f",pow(10,ifar_cmin)*gOPT.trials);
682  sprintf(tmp,"ifar>%f && rho[%d]>%f",pow(10,ifar_cmin)*gOPT.trials,rho_id,gOPT.rho_min);
683  Cuts = TString::Format("%s ",tmp);
684  wave[m]->Draw(sel,Cuts.Data(),"goff");
685  double* V1 = wave[m]->GetV1();
686  for(int k=0;k<wave[m]->GetSelectedRows();k++) {vIFAR.push_back(V1[k]);vNINJ.push_back(ninj);}
687  double efficiency = ninj>0 ? (double)wave[m]->GetSelectedRows()/(double)ninj : 0;
688  cout << run[m] << "\t" << chunk[m] << "\tselected wave sim detected entries : "
689  << wave[m]->GetSelectedRows() << "\tefficiency(%): " << int(100*efficiency) << "\tcumulative: " << vIFAR.size() << endl;
690  if(vIFAR.size()==0) continue;
691  int sel_entries = wave[m]->GetSelectedRows();
692  value = TMath::MinElement(sel_entries,V1);
693  //cout << "min sim IFAR per year : " << value/YEAR << endl;
694  if(value>ifar_sim_min) ifar_sim_min=value; // this condition is used to select the common sim IFAR inferior limit
695  value = TMath::MaxElement(sel_entries,V1);
696  //cout << "max sim IFAR per year : " << value/YEAR << endl;
697  if(value<ifar_sim_max) ifar_sim_max=value; // this condition is used to select the common sim IFAR superior limit
698  }
699 
700  if(vIFAR.size()>0) {
701  ifar_sim_min/=YEAR;
702  ifar_sim_max/=YEAR;
703 
704  cout << endl;
705  cout << "ifar_sim_min : " << ifar_sim_min << " years" << endl;
706  cout << "ifar_sim_max : " << ifar_sim_max << " years" << endl;
707  }
708 
709  // -----------------------------------------------------
710  // sort ifar simulated events
711  // -----------------------------------------------------
712 
713  if(vIFAR.size()>0) {
714  int size = vIFAR.size();
715  int *index = new int[size];
716  double *IFAR = new double[size];
717  for(int k=0;k<size;k++) IFAR[k]=vIFAR[k];
718  TMath::Sort(size,IFAR,index,true);
719  SIM_IFAR.resize(2*size-1);
720  SIM_NEVT.resize(2*size-1);
721  SIM_BKG_NEVT.resize(2*size-1);
722  int n=0;
723 // vector<double> vWEIGHT(size); // store weigths used for normalization
724 // vWEIGHT[0]=1./vNINJ[0];
725 // for(int k=1;k<size;k++) vWEIGHT[k]=vWEIGHT[k-1]+1./vNINJ[k-1]; // init weigths
726  for(int k=size-1;k>=0;k--) { // invert the ifar order
727  SIM_IFAR[n] = IFAR[index[k]]/YEAR; // sorted ifar simulated events
728 #ifdef APPLY_MAX_SIM_IFAR
729  if(SIM_IFAR[n]<ifar_sim_min) SIM_IFAR[n]=ifar_sim_min;
730  if(SIM_IFAR[n]>ifar_sim_max) SIM_IFAR[n]=ifar_sim_max;
731 #endif
732 // SIM_NEVT[n] = vWEIGHT[k]; // number of simulated events with ifar > SIM_IFAR[k]
733  SIM_NEVT[n] = k+1; // number of simulated events with ifar > SIM_IFAR[k]
734  n++;
735  if(n>=SIM_NEVT.size()-1) break;
736  // add point to make ZL STYLE STEPWISE
737  SIM_IFAR[n] = SIM_IFAR[n-1];
738  SIM_NEVT[n] = SIM_NEVT[n-1]-1;
739 // SIM_NEVT[n] = vWEIGHT[k-1];
740  n++;
741  }
742  delete [] index;
743  delete [] IFAR;
744  }
745  SIM_NEVT*=1./gOPT.sfactor; // expected events from astrophysical reates
746 // SIM_NEVT*=gOPT.sfactor; // expected events from astrophysical reates
747  for(int k=0;k<SIM_NEVT.size();k++) SIM_BKG_NEVT[k]=SIM_NEVT[k]+obsTime/(SIM_IFAR[k]*YEAR); // add expected from background
748 
749 #ifdef APPLY_MAX_SIM_IFAR
750  // set cut off of zero lag events according to the common sim IFAR inferior limit
751  if(SIM_NEVT.size()>0) {
752  for(int i=0;i<ZL_NEVT.size();i++) if(ZL_IFAR[i]>ifar_sim_max) ZL_IFAR[i]=ifar_sim_max;
753  }
754 #endif
755 
756  // -----------------------------------------------------
757  // make sim plot
758  // -----------------------------------------------------
759 
760  grsim=NULL;
761  grsimbkg=NULL;
762  if(SIM_NEVT.size()>0) {
763 
764 // (RATE_TAG)
765  // compute the index which contains the maximum common IFAR
766  int ifar_cmax_index=0;
767  for(int i=0;i<SIM_IFAR.size();i++) if(SIM_IFAR.data[i]<pow(10,ifar_cmax)/YEAR) ifar_cmax_index=i;
768 
769 // (RATE_TAG)
770  grsim = new TGraph(ifar_cmax_index,SIM_IFAR.data,SIM_NEVT.data); // expected events from astrophysical reates
771  grsimbkg = new TGraph(ifar_cmax_index,SIM_IFAR.data,SIM_BKG_NEVT.data); // expected events from astrophysical reates + expected from background
772  }
773 
774  // -----------------------------------------------------
775  // make sim belts at FAP0
776  // -----------------------------------------------------
777 
778  if(SIM_NEVT.size()>0) {
779  int M=0;
780  for(int n=0;n<IFAR_NBIN;n++) {
781  double x = inf+n*difar_bin;
782  if(x<(ifar_cmin-difar_bin) && x<inf) continue; // RATE_TAG
783  if(x>ifar_cmax) continue; // RATE_TAG
784  xSIM_BKG_IFAR[M] = pow(10,x)/YEAR;
785  if((xSIM_BKG_IFAR[M]<SIM_IFAR[0]) || (xSIM_BKG_IFAR[M]>SIM_IFAR[SIM_IFAR.size()-1])) continue;
786  double mu = grsimbkg->Eval(xSIM_BKG_IFAR[M]); // expected events in ZERO_LAG_TIME
787  ySIM_BKG[M]=mu;
788 
789  double q[6];
790  if(gOPT.belt_style=="continuos") GetPercentiles(mu, q);
791 
792  double nevt=0;
793  nevt = gOPT.belt_style=="continuos" ? q[3] : GetPoissonNsup(mu,FAP0/2.);
794  eySIM_BKG_sup0[M] = (nevt-mu);
795  nevt = gOPT.belt_style=="continuos" ? q[2] : GetPoissonNinf(mu,FAP0/2.);
796  eySIM_BKG_inf0[M] = (mu-nevt);
797  M++;
798  }
799  xSIM_BKG_IFAR.resize(M);
800  ySIM_BKG.resize(M);
801  eySIM_BKG_inf0.resize(M);
802  eySIM_BKG_sup0.resize(M);
803  }
804 
805 
806  // =======================================================================
807  // MAKE BELTS FOR EXPECTED BACKGROUND
808  // =======================================================================
809 
810  // -----------------------------------------------------
811  // make belts at FAP0,FAP1,FAP2
812  // -----------------------------------------------------
813 
814  if(gOPT.belt_style=="step") {
815  // add points to make BELT STYLE STEPWISE
816 
817  xIFAR.resize(2*IFAR_NBIN);
818  xFAR.resize(2*IFAR_NBIN);
819  bRATE.resize(2*IFAR_NBIN);
820  yBKG.resize(2*IFAR_NBIN);
821 
822  exFAR.resize(2*IFAR_NBIN); exFAR=0;
823  eyRATEinf0.resize(2*IFAR_NBIN);
824  eyRATEsup0.resize(2*IFAR_NBIN);
825  eyRATEinf1.resize(2*IFAR_NBIN);
826  eyRATEsup1.resize(2*IFAR_NBIN);
827  eyRATEinf2.resize(2*IFAR_NBIN);
828  eyRATEsup2.resize(2*IFAR_NBIN);
829  }
830 
831  cout << "Make_PP_IFAR.C - generate belts : be patient, it takes a while ..." << endl;
832  int N=0;
833  for(int n=0;n<IFAR_NBIN;n++) {
834  double x = inf+n*difar_bin;
835  //if(x<(ifar_cmin-difar_bin) || x>(ifar_max+2*difar_bin)) continue; // RATE_TAG
836  if(x<(ifar_cmin-difar_bin) && x<inf) continue; // RATE_TAG
837  xIFAR[N] = pow(10,x);
838  xFAR[N] = 1./xIFAR[N];
839  bRATE[N] = xFAR[N];
840  double mu = xFAR[N]*obsTime; // expected bakground events in ZERO_LAG_TIME
841 
842  double q[6];
843  if(gOPT.belt_style=="continuos") GetPercentiles(mu, q);
844 
845  yBKG[N] = gOPT.belt_style=="continuos" ? q[3] : GetPoissonNsup(mu,FAP0/2.);
846  eyRATEsup0[N] = (yBKG[N]-mu)/obsTime;
847  yBKG[N] = gOPT.belt_style=="continuos" ? q[2] : GetPoissonNinf(mu,FAP0/2.);
848  eyRATEinf0[N] = (mu-yBKG[N])/obsTime;
849  yBKG[N] = gOPT.belt_style=="continuos" ? q[4] : GetPoissonNsup(mu,FAP1/2.);
850  eyRATEsup1[N] = (yBKG[N]-mu)/obsTime;
851  yBKG[N] = gOPT.belt_style=="continuos" ? q[1] : GetPoissonNinf(mu,FAP1/2.);
852  eyRATEinf1[N] = (mu-yBKG[N])/obsTime;
853  yBKG[N] = gOPT.belt_style=="continuos" ? q[5] : GetPoissonNsup(mu,FAP2/2.);
854  eyRATEsup2[N] = (yBKG[N]-mu)/obsTime;
855  yBKG[N] = gOPT.belt_style=="continuos" ? q[0] : GetPoissonNinf(mu,FAP2/2.);
856  eyRATEinf2[N] = (mu-yBKG[N])/obsTime;
857 
858  N++;
859 
860  if(gOPT.belt_style=="step") { // add points to make BELT STYLE STEPWISE
861 
862  if(N>1) {
863 
864  xIFAR[N] = xIFAR[N-1];
865  xFAR[N] = xFAR[N-1];
866  bRATE[N] = bRATE[N-1];
867 
868  xIFAR[N-1] = xIFAR[N-2];
869  xFAR[N-1] = xFAR[N-2];
870  bRATE[N-1] = bRATE[N-2];
871 
872  yBKG[N-1] = mu;
873  yBKG[N] = mu;
874 
875  eyRATEsup0[N] = eyRATEsup0[N-1];
876  eyRATEinf0[N] = eyRATEinf0[N-1];
877  eyRATEsup1[N] = eyRATEsup1[N-1];
878  eyRATEinf1[N] = eyRATEinf1[N-1];
879  eyRATEsup2[N] = eyRATEsup2[N-1];
880  eyRATEinf2[N] = eyRATEinf2[N-1];
881 
882  N++;
883 
884  } else {
885  yBKG[N-1]=mu;
886  }
887  } else {
888  yBKG[N-1]=bRATE[N-1]*obsTime;
889  }
890  }
891  xIFAR.resize(N);
892  xFAR.resize(N);
893 
894  // normalize -> per SEC -> per YEAR
895  xFAR *=YEAR;
896  xIFAR*=1./YEAR;
897 
898  // compute number of events in the obsTime period
899  bRATE*=obsTime;
900  eyRATEsup0*=obsTime;
901  eyRATEinf0*=obsTime;
902  eyRATEsup1*=obsTime;
903  eyRATEinf1*=obsTime;
904  eyRATEsup2*=obsTime;
905  eyRATEinf2*=obsTime;
906 
907 
908  // -----------------------------------------------------
909  // print sigma belts
910  // -----------------------------------------------------
911 
912  double sigma[3];
913  sigma[0] = sqrt(2)*TMath::ErfcInverse(FAP0);
914  sigma[1] = sqrt(2)*TMath::ErfcInverse(FAP1);
915  sigma[2] = sqrt(2)*TMath::ErfcInverse(FAP2);
916 
917  cout << endl << "--------------------------------------------------------" << endl << endl;;
918  cout << "FAP = " << FAP0 << "\t -> SIGMA = " << sigma[0] << endl;
919  cout << "FAP = " << FAP1 << "\t -> SIGMA = " << sigma[1] << endl;
920  cout << "FAP = " << FAP2 << "\t -> SIGMA = " << sigma[2] << endl;
921  cout << endl << "--------------------------------------------------------" << endl << endl;;
922 
923 
924  // =======================================================================
925  // DUMP PLOTS AND ASCII FILES
926  // =======================================================================
927 
928  // -----------------------------------------------------
929  // Make Plot
930  // -----------------------------------------------------
931 
932  char title[1024];
933  if(gOPT.bbh) {
934  sprintf(title,"cWB %s (run=%s : lag=%d : slag=%d : included BBH)",gOPT.search.Data(),gOPT.run.Data(),gOPT.lag,gOPT.slag);
935  } else {
936  sprintf(title,"cWB %s (run=%s : lag=%d : slag=%d : excluded BBH)",gOPT.search.Data(),gOPT.run.Data(),gOPT.lag,gOPT.slag);
937  }
938 
939  sprintf(title,"");
940 
941  MakePlot(title, obsTime, ifar_cmax);
942 
943  // -----------------------------------------------------
944  // Dump Zero Lag Events to ascii file
945  // -----------------------------------------------------
946 
947  DumpPeriod(liveTot);
948  DumpLoudest(obsTime);
949  DumpBackground();
950  DumpForeground();
951  DumpSimulation(ifar_cmax);
952 
953  if(gOPT.exit && gOPT.pfname!="") exit(0);
954 }
955 
956 void MakePlot(TString title, double obsTime, double ifar_cmax) {
957 
958  canvas = new TCanvas("FAR", "FAR", 300,40, 800, 600);
959  canvas->SetGridx();
960  canvas->SetGridy();
961  canvas->SetLogx();
962  canvas->SetLogy();
963 // canvas->SetFrameBorderMode(0);
964 // canvas->SetFrameLineColor(17);
965 // canvas->SetFrameBorderMode(0);
966 
967  gr0 = new TGraph(xIFAR.size(),xIFAR.data,bRATE.data);
968  gr0->SetTitle(title);
969  gr0->Draw("LA3");
970  gr0->SetLineWidth(2);
971  gr0->SetLineStyle(1);
972  gr0->SetLineColor(kGray+2);
973  gr0->GetHistogram()->GetXaxis()->CenterTitle();
974  gr0->GetHistogram()->GetYaxis()->CenterTitle();
975  gr0->GetHistogram()->GetXaxis()->SetLabelOffset(0.0001);
976  gr0->GetHistogram()->GetXaxis()->SetTickLength(0.02);
977  gr0->GetHistogram()->GetXaxis()->SetLabelSize(0.035);
978  gr0->GetHistogram()->GetYaxis()->SetLabelSize(0.035);
979  gr0->GetHistogram()->GetXaxis()->SetTitleSize(0.035);
980  gr0->GetHistogram()->GetYaxis()->SetTitleSize(0.035);
981  gr0->GetHistogram()->GetXaxis()->SetTitleOffset(1.7);
982  gr0->GetHistogram()->GetYaxis()->SetTitleOffset(1.5);
983  gr0->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
984  gr0->GetHistogram()->GetYaxis()->SetTitleOffset(1.2);
985  gr0->GetHistogram()->GetXaxis()->SetAxisColor(17);
986  gr0->GetHistogram()->GetYaxis()->SetAxisColor(17);
987  canvas->RedrawAxis();
988  canvas->Update();
989 
990  // set axis ranges
991  if(xIFAR.size()>0) {
992  double ymin = 0.7;
993  double ymax = gr0->GetHistogram()->GetMaximum();
994  if(ZL_NEVT.size()>0) ymax=2*ZL_NEVT[0];
995  if(ymax/ymin<10) ymax=10*ymin;
996  //if(ymax>gr0->GetHistogram()->GetMaximum()) ymax=gr0->GetHistogram()->GetMaximum();
997  if(ymax<1) ymax=2;
998  gr0->GetHistogram()->GetYaxis()->SetRangeUser(ymin,ymax);
999  gr0->GetHistogram()->GetXaxis()->SetRangeUser(0.01,1e5);
1000  canvas->RedrawAxis();
1001  canvas->Update();
1002  if((xIFAR[0]>0) && (xIFAR[xIFAR.size()-1]/xIFAR[0])<10) {
1003  canvas->SetLogx(false);
1004  canvas->SetLogy(false);
1005  }
1006  } else {
1007  canvas->SetLogx(false);
1008  canvas->SetLogy(false);
1009  }
1010  gr0->GetHistogram()->GetXaxis()->SetTitle("Inverse False Alarm Rate (yr)");
1011  gr0->GetHistogram()->GetYaxis()->SetTitle("Cumulative Number of Events");
1012  gr0->GetHistogram()->GetXaxis()->SetLabelFont(132);
1013  gr0->GetHistogram()->GetYaxis()->SetLabelFont(132);
1014  gr0->GetHistogram()->GetXaxis()->SetTitleFont(132);
1015  gr0->GetHistogram()->GetYaxis()->SetTitleFont(132);
1016  gr0->GetHistogram()->GetXaxis()->SetTickLength(0);
1017 
1018  // Plot FAP2
1019  egr2 = new TGraphAsymmErrors(xIFAR.size(),xIFAR.data,yBKG.data,exFAR.data,exFAR.data,eyRATEinf2.data,eyRATEsup2.data);
1020  egr2->SetMarkerStyle(20);
1021  egr2->SetMarkerSize(0);
1022  egr2->SetLineColor(15);
1023  egr2->SetFillStyle(1001);
1024  egr2->SetFillColor(18); // light gray
1025  egr2->Draw("3SAME");
1026 
1027  // Plot FAP1
1028  egr1 = new TGraphAsymmErrors(xIFAR.size(),xIFAR.data,yBKG.data,exFAR.data,exFAR.data,eyRATEinf1.data,eyRATEsup1.data);
1029  egr1->SetMarkerStyle(20);
1030  egr1->SetMarkerSize(0);
1031  egr1->SetLineColor(15);
1032  egr1->SetFillStyle(1001);
1033  egr1->SetFillColor(17); // gray
1034  egr1->Draw("3SAME");
1035 
1036  // Plot FAP0
1037  egr0 = new TGraphAsymmErrors(xIFAR.size(),xIFAR.data,yBKG.data,exFAR.data,exFAR.data,eyRATEinf0.data,eyRATEsup0.data);
1038  egr0->SetMarkerStyle(20);
1039  egr0->SetMarkerSize(0);
1040  egr0->SetLineColor(15);
1041  egr0->SetFillStyle(1001);
1042  egr0->SetFillColor(16); // dark gray
1043  egr0->Draw("3SAME");
1044 
1045 // BEG TEST P-ASTRO
1046  // Plot Simulated
1047  if(grsimbkg!=NULL) {
1048 
1049  // compute the index which contains the maximum common IFAR (RATE_TAG)
1050  int ifar_cmax_index=0;
1051  for(int i=0;i<xSIM_BKG_IFAR.size();i++) if(xSIM_BKG_IFAR.data[i]<pow(10,ifar_cmax)/YEAR) ifar_cmax_index=i;
1052 
1053  // Plot sim FAP0
1054  egrsimbkg0 = new TGraphAsymmErrors(ifar_cmax_index,xSIM_BKG_IFAR.data,ySIM_BKG.data,exSIM_BKG_IFAR.data,exSIM_BKG_IFAR.data,eySIM_BKG_inf0.data,eySIM_BKG_sup0.data); // (RATE_TAG)
1055  egrsimbkg0->SetMarkerSize(0);
1056  egrsimbkg0->SetLineColor(15);
1057  egrsimbkg0->SetFillColorAlpha(kGreen, 0.1);
1058  egrsimbkg0->Draw("3SAME"); // belt
1059 
1060  grsim->SetLineColor(kGreen);
1061  grsim->SetLineWidth(1);
1062  grsim->SetMarkerSize(0);
1063  grsim->Draw("LSAME"); // expected signal from astrophysical rates
1064 
1065  grsimbkg->SetLineColor(kGreen+2);
1066  grsimbkg->SetLineWidth(1);
1067  grsimbkg->SetMarkerSize(0);
1068  grsimbkg->Draw("LSAME"); // expected signal from astrophysical rates + expected from backgrouns
1069  }
1070 // END TEST P-ASTRO
1071 
1072  // Plot Foreground
1073  if(ZL_NEVT.size()>0) {
1074  gr = new TGraph(ZL_NEVT.size(),ZL_IFAR.data,ZL_NEVT.data);
1075 //gr->SetLineStyle(2);
1076 //gr->SetLineWidth(2);
1077  gr->SetLineColor(kRed);
1078  gr->SetMarkerColor(kRed);
1079  gr->SetMarkerStyle(23);
1080  if(gOPT.zl_style=="marker") {
1081  gr->SetMarkerSize(0.4);
1082  gr->Draw("PSAME"); // marker
1083  } else {
1084  gr->SetMarkerSize(0);
1085  gr->Draw("SAME"); // stepwise
1086  }
1087  } else {
1088  gr = NULL;
1089  //canvas->SetLogy(false);
1090  }
1091 
1092 #ifdef PLOT_FOREGROUND_NOBBH
1093 
1094  wavearray<double> ZL_IFAR_NOBBH(ZL_NEVT.size()); // sorted ifar events
1095 
1096  // select event without known BBH
1097  int nobbh_size=0;
1098  for(int i=0;i<ZL_NEVT.size();i++) {
1099  if((GetNameBBH(ZL_GPS[i])=="")) ZL_IFAR_NOBBH[nobbh_size++]=ZL_IFAR[i];
1100  }
1101  if(ZL_IFAR_NOBBH[nobbh_size-1]==ZL_IFAR_NOBBH[nobbh_size-2]) nobbh_size-=1;
1102  ZL_IFAR_NOBBH.resize(nobbh_size);
1103  wavearray<double> ZL_NEVT_NOBBH(nobbh_size); // number of nobbh events with ifar > ZL_IFAR[k]
1104  for(int i=0;i<nobbh_size;i+=2) {
1105  ZL_NEVT_NOBBH[i]=(nobbh_size-i)/2+1;
1106  ZL_NEVT_NOBBH[i+1]=(nobbh_size-i)/2;
1107  }
1108  ZL_NEVT_NOBBH[0]=(nobbh_size)/2+1;
1109 
1110  // Plot Foreground no bbh
1111  TGraph* gr_nobbh;
1112  if(ZL_NEVT_NOBBH.size()>0) {
1113  gr_nobbh = new TGraph(ZL_NEVT_NOBBH.size(),ZL_IFAR_NOBBH.data,ZL_NEVT_NOBBH.data);
1114  //gr_nobbh->SetLineColor(kRed);
1115  //gr_nobbh->SetLineColor(kGreen+2);
1116  //gr_nobbh->SetLineColor(kOrange+7);
1117  gr_nobbh->SetLineColor(kBlack);
1118  gr_nobbh->SetLineWidth(1);
1119  gr_nobbh->SetLineStyle(3);
1120  gr_nobbh->SetMarkerColor(kRed);
1121  gr_nobbh->SetMarkerStyle(23);
1122  if(gOPT.zl_style=="marker") {
1123  gr_nobbh->SetMarkerSize(0.4);
1124  gr_nobbh->Draw("PSAME"); // marker
1125  } else {
1126  gr_nobbh->SetMarkerSize(0);
1127  gr_nobbh->Draw("SAME"); // stepwise
1128  }
1129  }
1130 
1131 #endif
1132 
1133  gr0->Draw("LSAME");
1134 
1135  // Plot blue marker & name for known BBH
1136  bool anyBBH=false;
1137  for(int i=0;i<ZL_NEVT.size();i++) {
1138  if((GetNameBBH(ZL_GPS[i])!="")&&(i%2==0)) {
1139  marker = new TMarker(ZL_IFAR[i],ZL_NEVT[i], 20);
1140  bool selected=false;
1141  if((GetNameBBH(ZL_GPS[i])=="GW150914")) selected=true;
1142  if((GetNameBBH(ZL_GPS[i])=="GW170814")) selected=true;
1143  if((GetNameBBH(ZL_GPS[i])=="GW170104")) selected=true;
1144  if((GetNameBBH(ZL_GPS[i])=="GW170608")) selected=true;
1145  if(selected) {
1146  arrow = new TArrow(ZL_IFAR[i],ZL_NEVT[i],ZL_IFAR[i]*1.5,ZL_NEVT[i],0.05,"|>");
1147  arrow->SetAngle(60);
1148  arrow->SetLineWidth(2);
1149  arrow->SetLineColor(kBlue);
1150  arrow->SetFillColor(kBlue);
1151  arrow->SetArrowSize(0.012);
1152  arrow->Draw();
1153  }
1154  marker->SetMarkerSize(1.2);
1155  marker->SetMarkerColor(kBlue);
1156  marker->Draw();
1157 
1158  latex = new TLatex(ZL_IFAR[i]*(4./3.),ZL_NEVT[i]*1.1, GetNameBBH(ZL_GPS[i]).Data());
1159  latex->SetTextFont(132);
1160  latex->SetTextSize(0.028);
1161  latex->SetTextColor(kBlack);
1162  latex->Draw();
1163 
1164  anyBBH=true;
1165  }
1166  }
1167  // if there no BBH events then a red marker is draw for loudest event
1168  if((!anyBBH)&&(ZL_NEVT.size()>0)&&(GetNameBBH(ZL_GPS[ZL_NEVT.size()-1])=="")) {
1169  marker = new TMarker(ZL_IFAR[ZL_NEVT.size()-1],ZL_NEVT[ZL_NEVT.size()-1], 23);
1170  marker->SetMarkerSize(1.2);
1171  marker->SetMarkerColor(kRed);
1172  marker->Draw();
1173  }
1174 
1175  // draw legend
1176 #ifdef PLOT_FOREGROUND_NOBBH
1177  leg = new TLegend(0.6,0.6,0.90,0.90,NULL,"brNDC");
1178 #else
1179  if(grsimbkg!=NULL) {
1180  leg = new TLegend(0.6,0.630,0.90,0.90,NULL,"brNDC");
1181  } else {
1182  leg = new TLegend(0.6,0.6,0.90,0.90,NULL,"brNDC");
1183  }
1184 #endif
1185 
1186  leg->SetBorderSize(1);
1187  leg->SetTextAlign(22);
1188  leg->SetTextFont(132);
1189  leg->SetLineColor(1);
1190  leg->SetLineStyle(1);
1191  leg->SetLineWidth(1);
1192  leg->SetFillColor(0);
1193  leg->SetFillStyle(1001);
1194  if(grsimbkg!=NULL) leg->SetTextSize(0.035); else leg->SetTextSize(0.035);
1195  leg->SetLineColor(kBlack);
1196  leg->SetFillColor(kWhite);
1197 
1198  char legLabel[64];
1199  sprintf(legLabel,"Foreground"); if(gr!=NULL) leg->AddEntry(gr,legLabel,"lp");
1200 #ifdef PLOT_FOREGROUND_NOBBH
1201  sprintf(legLabel,"Residual Foreground"); if(gr_nobbh!=NULL) leg->AddEntry(gr_nobbh,legLabel,"lp");
1202 #endif
1203  sprintf(legLabel,"Expected Background"); leg->AddEntry(gr0,legLabel,"lp");
1204  if(gOPT.bbh && anyBBH) leg->AddEntry(marker,"BBH Events","p");
1205  else if(ZL_NEVT.size()>0) leg->AddEntry(marker,"Loudest","p");
1206  if(grsimbkg!=NULL) {
1207  leg->AddEntry(grsim,"Signal Model","lp");;
1208  leg->AddEntry(grsimbkg,"Noise+Signal Model","lp");;
1209  } else {
1210  // add background belts labels
1211  leg->AddEntry(egr2,"< 3 #sigma","f");
1212  leg->AddEntry(egr1,"< 2 #sigma","f");
1213  leg->AddEntry(egr0,"< 1 #sigma","f");
1214  }
1215  leg->Draw();
1216 
1217  // fix frame lines color
1218 // double xmax = gr0->GetHistogram()->GetXaxis()->GetXmax();
1219 // double xmin = gr0->GetHistogram()->GetXaxis()->GetXmin();
1220  double xmax = pow(10,gPad->GetUxmax());
1221  double xmin = pow(10,gPad->GetUxmin());
1222  //double ymin = pow(10,gPad->GetUymin());
1223  double ymin = 0.0;
1224  double ymax = pow(10,gPad->GetUymax());
1225  cout << "xmin=" << xmin << " xmax=" << xmax << endl;
1226  cout << "ymin=" << ymin << " ymax=" << ymax << endl;
1227 
1228  TLine* frameLine[4];
1229  frameLine[0] = new TLine(xmin,ymin,xmax,ymin);
1230  frameLine[1] = new TLine(xmin,ymin,xmin,ymax);
1231  frameLine[2] = new TLine(xmax,ymin,xmax,ymax);
1232  frameLine[3] = new TLine(0.,ymax,xmax,ymax);
1233  for(int i=0;i<4;i++) frameLine[i]->Draw();
1234 
1235 
1236  // dump plot to disk
1237  if(gOPT.pfname) {
1238  char ofname[1024];
1239  TString PFNAME = gOPT.pfname(0,gOPT.pfname.Last('.'));
1240  if(gOPT.bbh) sprintf(ofname,"%s_bbh_plot.png",PFNAME.Data());
1241  else sprintf(ofname,"%s_nobbh_plot.png",PFNAME.Data());
1242  canvas->Print(ofname);
1243  if(gOPT.bbh) sprintf(ofname,"%s_bbh_plot.root",PFNAME.Data());
1244  else sprintf(ofname,"%s_nobbh_plot.root",PFNAME.Data());
1245  canvas->Print(ofname);
1246  if(gOPT.bbh) sprintf(ofname,"%s_bbh_plot.pdf",PFNAME.Data());
1247  else sprintf(ofname,"%s_nobbh_plot.pdf",PFNAME.Data());
1248  canvas->Print(ofname);
1249  }
1250 }
1251 
1252 int GetPercentiles(double mu, double* q) {
1253 
1254  double max = mu>10 ? 10*mu : 100;
1255 
1256  TF1 f("poisson","TMath::Poisson(x,[1])",0,max);
1257  f.SetParameter(1,mu);
1258  f.SetNpx(1000);
1259 
1260  double probSum[6] = {FAP2/2,FAP1/2,FAP0/2,1-FAP0/2,1-FAP1/2,1-FAP2/2};
1261  return f.GetQuantiles(6,q,probSum);
1262 }
1263 
1264 int GetPoissonNsup(double mu, double fap) {
1265 
1266  double FAP = 1.;
1267  for(int j=0;j<1000000;j++) {
1268  //FAP -= pow(mu,j)*exp(-mu)/TMath::Factorial(j);
1269  FAP -= TMath::PoissonI(j,mu);
1270  //cout << " N : " << j << " MU : " << mu << " FAP " << FAP << " fap : " << fap << endl;
1271  if(FAP<fap) return j==0 ? 0 : j+1;
1272  }
1273  return 0;
1274 }
1275 
1276 int GetPoissonNinf(double mu, double fap) {
1277 
1278  double FAP = 0.;
1279  for(int j=0;j<1000000;j++) {
1280  //FAP -= pow(mu,j)*exp(-mu)/TMath::Factorial(j);
1281  FAP += TMath::PoissonI(j,mu);
1282  //cout << " N : " << j << " MU : " << mu << " FAP " << FAP << " fap : " << fap << endl;
1283  if(FAP>fap) return j==0 ? 0 : j-1;
1284  }
1285  return 0;
1286 }
1287 
1288 int ReadFileList(TString ifName, TChain** live, TChain** wave, TChain** mdc, int* lag, int* slag, int* chunk, int* bin, TString* run) {
1289 
1290  // Read WAVE/LIVE file list
1291 
1292  ifstream in;
1293  in.open(ifName.Data(),ios::in);
1294  if (!in.good()) {cout << "ReadFileList Error Opening File : " << ifName.Data() << endl;exit(1);}
1295 
1296  int size=0;
1297  char str[1024];
1298  int fpos=0;
1299  while(true) {
1300  in.getline(str,1024);
1301  if (!in.good()) break;
1302  if(str[0] != '#') size++;
1303  }
1304  in.clear(ios::goodbit);
1305  in.seekg(0, ios::beg);
1306  if (size==0) {cout << "ReadFileList Error : File " << ifName.Data() << " is empty" << endl;exit(1);}
1307  if (size>MAX_LIST_SIZE) {cout << "ReadFileList Error : Files in " << ifName.Data() << " > " << MAX_LIST_SIZE << endl;exit(1);}
1308 
1309  char sfile[1024];
1310  int xlag,xslag,ichunk,ibin;
1311  char srun[256];
1312  int nwave=0;
1313  while(true) {
1314  fpos=in.tellg();
1315  in.getline(str,1024);
1316  if (!in.good()) break;
1317  if(str[0] == '#' || str[0]=='\0') continue;
1318  in.seekg(fpos, ios::beg);
1319  in >> sfile >> xlag >> xslag >> ichunk >> ibin >> srun;
1320  if(!in.good()) break;
1321  lag[nwave]=xlag;
1322  slag[nwave]=xslag;
1323  TString fwave = sfile;
1324  if(!CWB::Toolbox::isFileExisting(fwave)) {cout << "ReadFileList Error : File not exist : " << fwave << endl;exit(1);}
1325  wave[nwave]->Add(fwave);
1326  wave[nwave]->SetTitle(fwave);
1327  if(ibin>=0) { // ibin<=0/ibin>=0 -> simulation/background
1328  TString flive = sfile;
1329  flive.ReplaceAll("wave_","live_");
1330  if(!CWB::Toolbox::isFileExisting(flive)) {cout << "ReadFileList Error : File not exist : " << flive << endl;exit(1);}
1331  live[nwave]->Add(flive);
1332  live[nwave]->SetTitle(flive);
1333  } else { // simulation -> read mdc
1334  TString fmdc = sfile;
1335  fmdc.ReplaceAll("wave_","mdc_");
1336  if(!CWB::Toolbox::isFileExisting(fmdc)) {cout << "ReadFileList Error : File not exist : " << fmdc << endl;exit(1);}
1337  mdc[nwave]->Add(fmdc);
1338  mdc[nwave]->SetTitle(fmdc);
1339  }
1340  chunk[nwave]=ichunk;
1341  bin[nwave]=ibin;
1342  run[nwave]=srun;
1343  cout << nwave+1 << "\t" << fwave << "\t" << xlag << "\t" << xslag << "\t" << ichunk << "\t" << ibin << "\t" << srun << endl;
1344  nwave++;
1345  }
1346  in.close();
1347 
1348  return nwave;
1349 }
1350 
1351 void GetLiveTime(int nwave, TChain** live, int* lag, int* slag, int* bin, TString* run, double* liveZero, double* liveTot) {
1352 
1353  CWB::Toolbox TB;
1354 
1355  wavearray<double> Trun(500000); Trun = 0.;
1356  wavearray<double> Wlag[NIFO_MAX+1];
1357  wavearray<double> Wslag[NIFO_MAX+1];
1358  wavearray<double> Tdlag;
1359  wavearray<double> Tlag;
1360  wavearray<double> Rlag;
1361  wavearray<double> Elag;
1362  wavearray<double> Olag;
1363 
1364  cout << "Start CWB::Toolbox::getLiveTime : be patient, it takes a while ..." << endl;
1365  for(int m=0;m<nwave;m++) {
1366  if(bin[m]<0) continue; // simulation
1367  cout << "Compute liveTot : Read : " << live[m]->GetTitle() << endl;
1368  if(run[m]=="O1") liveTot[0]+=TB.getLiveTime(gOPT.nifo,*live[m],Trun,Wlag,Wslag,Tlag,Tdlag,lag[m],slag[m]);
1369  if(run[m]=="O2") liveTot[1]+=TB.getLiveTime(gOPT.nifo,*live[m],Trun,Wlag,Wslag,Tlag,Tdlag,lag[m],slag[m]);
1370  if(run[m]=="O3") liveTot[2]+=TB.getLiveTime(gOPT.nifo,*live[m],Trun,Wlag,Wslag,Tlag,Tdlag,lag[m],slag[m]);
1371  }
1372 
1373  // get live time zero (when is not included into Tlag array)
1374  for(int m=0;m<nwave;m++) {
1375  if(bin[m]<0) continue; // simulation
1376  if((lag[m]!=0)&&(slag[m]!=0)) {
1377  cout << "Compute liveZero : Read : " << live[m]->GetTitle() << endl;
1378  if(run[m]=="O1") liveZero[0]+=TB.getLiveTime(gOPT.nifo,*live[m],Trun,Wlag,Wslag,Tlag,Tdlag,0,0);
1379  if(run[m]=="O2") liveZero[1]+=TB.getLiveTime(gOPT.nifo,*live[m],Trun,Wlag,Wslag,Tlag,Tdlag,0,0);
1380  if(run[m]=="O3") liveZero[2]+=TB.getLiveTime(gOPT.nifo,*live[m],Trun,Wlag,Wslag,Tlag,Tdlag,0,0);
1381  //liveZero+=TB.getZeroLiveTime(gOPT.nifo,*live[m]); // crash in ATLAS ???
1382  if(run[m]=="O1") printf("live time: zero lags = %10.1f, %10.1f days \n",liveZero[0],liveZero[0]/DAY);
1383  if(run[m]=="O2") printf("live time: zero lags = %10.1f, %10.1f days \n",liveZero[1],liveZero[1]/DAY);
1384  if(run[m]=="O3") printf("live time: zero lags = %10.1f, %10.1f days \n",liveZero[2],liveZero[1]/DAY);
1385  }
1386  }
1387 }
1388 
1389 void InitBBH() {
1390 
1391 // ---------------------------------------------------------------------------------
1392 // INIT KNOWN O1,O2,O3 BBH
1393 // ---------------------------------------------------------------------------------
1394 
1395  // O1 known BBH events
1396  O1_BBH_NAME.resize(3);
1397  O1_BBH_GPS.resize(3);
1398 
1399  O1_BBH_NAME[0]="GW150914"; O1_BBH_GPS[0]=1126259462.40;
1400  O1_BBH_NAME[1]="LVT151012"; O1_BBH_GPS[1]=1128678900.55;
1401  O1_BBH_NAME[2]="GW151226"; O1_BBH_GPS[2]=1135136350.56;
1402 
1403  // O2 known BBH events
1404  O2_BBH_NAME.resize(7);
1405  O2_BBH_GPS.resize(7);
1406 
1407  O2_BBH_NAME[0]="GW170104"; O2_BBH_GPS[0]=1167559936.59;
1408  O2_BBH_NAME[1]="GW170608"; O2_BBH_GPS[1]=1180922494.38;
1409  O2_BBH_NAME[2]="GW170729"; O2_BBH_GPS[2]=1185389807.33;
1410  O2_BBH_NAME[3]="GW170809"; O2_BBH_GPS[3]=1186302519.73;
1411  O2_BBH_NAME[4]="GW170814"; O2_BBH_GPS[4]=1186741861.50;
1412  O2_BBH_NAME[5]="GW170818"; O2_BBH_GPS[5]=1187058327.07;
1413  O2_BBH_NAME[6]="GW170823"; O2_BBH_GPS[6]=1187529256.51;
1414 
1415  // O3 known BBH events
1416  ReadPublicAlerts();
1417 
1418 }
1419 
1420 TString GetCutBBH() {
1421 
1422  TString CutBBH="";
1423 
1424  if(gOPT.run.Contains("O1")) {
1425  CutBBH += TString::Format(" !(abs(time[0]-%f)<0.2) ",O1_BBH_GPS[0]);
1426  }
1427  if(gOPT.run.Contains("O1")) {
1428  for(int i=1;i<O1_BBH_GPS.size();i++) CutBBH += TString::Format("&& !(abs(time[0]-%f)<0.2) ",O1_BBH_GPS[i]);
1429  }
1430 
1431  if(gOPT.run=="O1O2") {
1432  CutBBH += TString::Format("&& !(abs(time[0]-%f)<0.2) ",O2_BBH_GPS[0]);
1433  } else if(gOPT.run=="O2") {
1434  CutBBH += TString::Format(" !(abs(time[0]-%f)<0.2) ",O2_BBH_GPS[0]);
1435  }
1436  if(gOPT.run.Contains("O2")) {
1437  for(int i=1;i<O2_BBH_GPS.size();i++) CutBBH += TString::Format("&& !(abs(time[0]-%f)<0.2) ",O2_BBH_GPS[i]);
1438  }
1439 
1440  if(gOPT.run.Contains("O3")) {
1441  CutBBH += TString::Format(" !(abs(time[0]-%f)<0.2) ",O3_BBH_GPS[0]);
1442  }
1443  if(gOPT.run.Contains("O3")) {
1444  for(int i=1;i<O3_BBH_GPS.size();i++) CutBBH += TString::Format("&& !(abs(time[0]-%f)<0.5) ",O3_BBH_GPS[i]);
1445  }
1446 
1447  return CutBBH;
1448 }
1449 
1450 TString GetNameBBH(double gps) {
1451 
1452  // known O1 BBH
1453  for(int i=0;i<O1_BBH_GPS.size();i++) if(fabs(gps-O1_BBH_GPS[i])<0.2) return O1_BBH_NAME[i];
1454 
1455  // known O2 BBH
1456  for(int i=0;i<O2_BBH_GPS.size();i++) if(fabs(gps-O2_BBH_GPS[i])<0.2) return O2_BBH_NAME[i];
1457 
1458  // known O3 BBH
1459  for(int i=0;i<O3_BBH_GPS.size();i++) if(fabs(gps-O3_BBH_GPS[i])<0.5) return O3_BBH_NAME[i];
1460 
1461  return "";
1462 }
1463 
1464 double GetGPSBBH(TString name) {
1465 
1466  // known O1 BBH
1467  for(int i=0;i<O1_BBH_NAME.size();i++) if(O1_BBH_NAME[i]==name) return O1_BBH_GPS[i];
1468 
1469  // known O2 BBH
1470  for(int i=0;i<O2_BBH_NAME.size();i++) if(O2_BBH_NAME[i]==name) return O2_BBH_GPS[i];
1471 
1472  // known O3 BBH
1473  for(int i=0;i<O3_BBH_NAME.size();i++) if(O3_BBH_NAME[i]==name) return O3_BBH_GPS[i];
1474 
1475  return 0;
1476 }
1477 
1479 
1480  gOPT.run = PP_RUN;
1481  gOPT.search = PP_SEARCH;
1482 
1483  gOPT.nifo = PP_NIFO;
1484  gOPT.lag = PP_LAG;
1485  gOPT.slag = PP_SLAG;
1486  gOPT.chunk = PP_CHUNK;
1487 
1488  gOPT.trials = PP_TRIALS;
1489 
1490  gOPT.pfname = PP_PFNAME;
1491  gOPT.zl_style = PP_ZL_STYLE;
1492  gOPT.belt_style = PP_BELT_STYLE;
1493 
1494  gOPT.ifar_max = PP_IFAR_MAX;
1495  gOPT.rho_min = PP_RHO_MIN;
1496 
1497  gOPT.sfactor = PP_SFACTOR;
1498 
1499  gOPT.bbh = PP_BBH;
1500  gOPT.exit = PP_EXIT;
1501 
1502  gOPT.gw151226_ifar = PP_GW151226_IFAR;
1503  gOPT.zl_max_ifar = PP_ZL_MAX_IFAR;
1504 }
1505 
1507 
1508  cout.precision(14);
1509 
1510  TString sexit = gOPT.exit?"true":"false";
1511  TString bbh = gOPT.bbh?"true":"false";
1512 
1513  cout << endl;
1514 
1515  cout << "-----------------------------------------" << endl;
1516  cout << "PP IFAR config options " << endl;
1517  cout << "-----------------------------------------" << endl << endl;
1518 
1519  cout << "PP_RUN " << gOPT.run << endl;
1520  cout << "PP_SEARCH " << gOPT.search << endl;
1521 
1522  cout << "PP_NIFO " << gOPT.nifo << endl;
1523  cout << "PP_LAG " << gOPT.lag << endl;
1524  cout << "PP_SLAG " << gOPT.slag << endl;
1525  cout << "PP_CHUNK " << gOPT.chunk << endl;
1526 
1527  cout << "PP_TRIALS " << gOPT.trials << endl;
1528 
1529  cout << "PP_PFNAME " << gOPT.pfname << endl;
1530  cout << "PP_ZL_STYLE " << gOPT.zl_style << endl;
1531  cout << "PP_BELT_STYLE " << gOPT.belt_style << endl;
1532 
1533  cout << "PP_IFAR_MAX " << gOPT.ifar_max << " yr"<< endl;
1534  cout << "PP_RHO_MIN " << gOPT.rho_min << endl;
1535 
1536  cout << "PP_SFACTOR " << gOPT.sfactor << endl;
1537 
1538  cout << "PP_BBH " << bbh << endl;
1539  cout << "PP_EXIT " << sexit << endl;
1540 
1541  cout << "PP_GW151226_IFAR " << gOPT.gw151226_ifar << endl;
1542  cout << "PP_ZL_MAX_IFAR " << gOPT.zl_max_ifar << endl;
1543 
1544  cout << endl;
1545 }
1546 
1547 void ReadUserOptions(TString options) {
1548 
1549  // get plugin options
1550 
1551  if(TString(options)!="") {
1552 
1553  //cout << "PP_IFAR options : " << options << endl;
1554  TObjArray* token = TString(options).Tokenize(TString(' '));
1555  for(int j=0;j<token->GetEntries();j++) {
1556 
1557  TObjString* tok = (TObjString*)token->At(j);
1558  TString stok = tok->GetString();
1559 
1560  if(stok.Contains("run=")) {
1561  TString pp_run=stok;
1562  pp_run.Remove(0,pp_run.Last('=')+1);
1563  gOPT.run=pp_run;
1564  }
1565 
1566  if(stok.Contains("search=")) {
1567  TString pp_search=stok;
1568  pp_search.Remove(0,pp_search.Last('=')+1);
1569  gOPT.search=pp_search;
1570  }
1571 
1572  if(stok.Contains("nifo=")) {
1573  TString pp_nifo=stok;
1574  pp_nifo.Remove(0,pp_nifo.Last('=')+1);
1575  if(pp_nifo.IsDigit()) gOPT.nifo=pp_nifo.Atoi();
1576  }
1577 
1578  if(stok.Contains("lag=") && !stok.Contains("slag=")) {
1579  TString pp_lag=stok;
1580  pp_lag.Remove(0,pp_lag.Last('=')+1);
1581  if(pp_lag.IsDigit()) gOPT.lag=pp_lag.Atoi();
1582  }
1583 
1584  if(stok.Contains("slag=")) {
1585  TString pp_slag=stok;
1586  pp_slag.Remove(0,pp_slag.Last('=')+1);
1587  if(pp_slag.IsDigit()) gOPT.slag=pp_slag.Atoi();
1588  }
1589 
1590  if(stok.Contains("chunk=")) {
1591  TString pp_chunk=stok;
1592  pp_chunk.Remove(0,pp_chunk.Last('=')+1);
1593  if(pp_chunk.IsDigit()) gOPT.chunk=pp_chunk.Atoi();
1594  }
1595 
1596  if(stok.Contains("trials=")) {
1597  TString pp_trials=stok;
1598  pp_trials.Remove(0,pp_trials.Last('=')+1);
1599  if(pp_trials.IsDigit()) gOPT.trials=pp_trials.Atoi();
1600  }
1601 
1602  if(stok.Contains("pfname=")) {
1603  TString pp_pfname=stok;
1604  pp_pfname.Remove(0,pp_pfname.Last('=')+1);
1605  gOPT.pfname=pp_pfname;
1606  }
1607 
1608  if(stok.Contains("zl_style=")) {
1609  TString pp_zl_style=stok;
1610  pp_zl_style.Remove(0,pp_zl_style.Last('=')+1);
1611  gOPT.zl_style=pp_zl_style;
1612  }
1613 
1614  if(stok.Contains("belt_style=")) {
1615  TString pp_belt_style=stok;
1616  pp_belt_style.Remove(0,pp_belt_style.Last('=')+1);
1617  gOPT.belt_style=pp_belt_style;
1618  }
1619 
1620  if(stok.Contains("ifar_max=")) {
1621  TString pp_ifar_max=stok;
1622  pp_ifar_max.Remove(0,pp_ifar_max.Last('=')+1);
1623  if(pp_ifar_max.IsFloat()) gOPT.ifar_max=pp_ifar_max.Atof();
1624  }
1625 
1626  if(stok.Contains("rho_min=")) {
1627  TString pp_rho_min=stok;
1628  pp_rho_min.Remove(0,pp_rho_min.Last('=')+1);
1629  if(pp_rho_min.IsFloat()) gOPT.rho_min=pp_rho_min.Atof();
1630  }
1631 
1632  if(stok.Contains("sfactor=")) {
1633  TString pp_sfactor=stok;
1634  pp_sfactor.Remove(0,pp_sfactor.Last('=')+1);
1635  if(pp_sfactor.IsFloat()) gOPT.sfactor=pp_sfactor.Atof();
1636  }
1637 
1638  if(stok.Contains("bbh=")) {
1639  TString pp_bbh=stok;
1640  pp_bbh.Remove(0,pp_bbh.Last('=')+1);
1641  if(pp_bbh=="true") gOPT.bbh=true;
1642  if(pp_bbh=="false") gOPT.bbh=false;
1643  }
1644 
1645  if(stok.Contains("exit=")) {
1646  TString pp_exit=stok;
1647  pp_exit.Remove(0,pp_exit.Last('=')+1);
1648  if(pp_exit=="true") gOPT.exit=true;
1649  if(pp_exit=="false") gOPT.exit=false;
1650  }
1651 
1652  if(stok.Contains("gw151226_ifar=")) {
1653  TString pp_gw151226_ifar=stok;
1654  pp_gw151226_ifar.Remove(0,pp_gw151226_ifar.Last('=')+1);
1655  if(pp_gw151226_ifar.IsFloat()) gOPT.gw151226_ifar=pp_gw151226_ifar.Atof();
1656  }
1657 
1658  if(stok.Contains("zl_max_ifar=")) {
1659  TString pp_zl_max_ifar=stok;
1660  pp_zl_max_ifar.Remove(0,pp_zl_max_ifar.Last('=')+1);
1661  if(pp_zl_max_ifar.IsFloat()) gOPT.zl_max_ifar=pp_zl_max_ifar.Atof();
1662  }
1663  }
1664  }
1665 }
1666 
1667 void DumpLoudest(double obsTime) {
1668 
1669  if(gOPT.pfname=="") return;
1670 
1671  char ofname[1024];
1672  TString PFNAME = gOPT.pfname(0,gOPT.pfname.Last('.'));
1673  if(gOPT.bbh) sprintf(ofname,"%s_bbh_loudest.txt",PFNAME.Data());
1674  else sprintf(ofname,"%s_nobbh_loudest.txt",PFNAME.Data());
1675 
1676  char sout[1024];
1677 
1678  ofstream out;
1679  out.open(ofname,ios::out);
1680  if (!out.good()) {cout << "Error Opening Output File : " << ofname << endl;exit(1);}
1681  cout << "Create Output File : " << ofname << endl;
1682  out.precision(19);
1683 
1684  // write header
1685  sprintf(sout,"%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s",
1686  4, "#run", 6, "chunk", 18, "gps_time", 10, "known.BBH", 16, "ifar(sec)", 16, "ifar(year)", 16, "obs_time(sec)",
1687  16, "obs_time(days)", 16, "expected", 10, "observed", 11, "cumul.FAP", 8, "sigma");
1688  out << sout << endl;
1689 
1690  // write data
1691  int observed=1;
1692  for (int i=ZL_IFAR.size()-1; i>=0; i--) {
1693 
1694  double expected = obsTime/(ZL_IFAR[i]*YEAR);
1695 
1696  // compute FAP
1697  double FAP = 1.;
1698  for(int j=0;j<observed;j++) {
1699  FAP -= TMath::PoissonI(j,expected);
1700  //cout << " N : " << j << " MU : " << expected << " fap : " << fap << endl;
1701  }
1702 
1703  // compute sigma
1704  double sigma = sqrt(2)*TMath::ErfcInverse(FAP);
1705 
1706  TString bbh_name = GetNameBBH(ZL_GPS[i]);
1707  if(bbh_name=="") bbh_name=".";
1708 
1709  TString run;
1710  int chunkID = GetChunkID(ZL_GPS[i],run);
1711 
1712  sprintf(sout,"%*s %*d %*.6f %*s %*.1f %*.4f %*f %*.1f %*.9f %*d %*.3e %*.2f",
1713  4, run.Data(), 6, chunkID, 18, ZL_GPS[i], 10, bbh_name.Data(), 16,
1714  ZL_IFAR[i]*YEAR, 16, ZL_IFAR[i], 16, obsTime,
1715  16, obsTime/DAY, 16, expected, 10, observed, 11, FAP, 8, sigma);
1716  if(gOPT.zl_style=="marker") {
1717  out << sout << endl;
1718  observed++;
1719  } else {
1720  if(i%2==0) {out << sout << endl; observed++;}
1721  }
1722  }
1723 
1724  out.close();
1725 }
1726 
1727 int GetChunkID(double gps, TString& run) {
1728 
1729  for(int n=0;n<MAX_RUNS;n++) {
1730  for(int i=0;i<chunk_size[n];i++) {
1731  if(gps>chunk_start[n][i] && gps<chunk_stop[n][i]) {
1732  if(n==0) run="O1";
1733  if(n==1) run="O2";
1734  if(n==2) run="O3";
1735  return chunk_id[n][i];
1736  }
1737  }
1738  }
1739 
1740  return -1;
1741 }
1742 
1743 void DumpPeriod(double* obsTime) {
1744 
1745  if(gOPT.pfname=="") return;
1746 
1747  char ofname[1024];
1748  TString PFNAME = gOPT.pfname(0,gOPT.pfname.Last('.'));
1749  if(gOPT.bbh) sprintf(ofname,"%s_bbh_period.txt",PFNAME.Data());
1750  else sprintf(ofname,"%s_nobbh_period.txt",PFNAME.Data());
1751 
1752  char sout[1024];
1753 
1754  ofstream out;
1755  out.open(ofname,ios::out);
1756  if (!out.good()) {cout << "Error Opening Output File : " << ofname << endl;exit(1);}
1757  cout << "Create Output File : " << ofname << endl;
1758  out.precision(19);
1759 
1760  // write header
1761  sprintf(sout,"%*s %*s %*s %*s %*s %*s %*s %*s",
1762  4, "#run", 20, "gps_start", 20, "date_start", 20, "gps_stop", 20, "date_stop", 20, "interval(days)", 20, "obs_time(sec)", 20, "obs_time(days)");
1763  out << sout << endl;
1764 
1765  for(int n=0;n<MAX_RUNS;n++) {
1766 
1767  TString RUN;
1768 
1769  if(n==0 && gOPT.run.Contains("O1")) RUN="O1";
1770  else
1771  if(n==1 && gOPT.run.Contains("O2")) RUN="O2";
1772  else
1773  if(n==2 && gOPT.run.Contains("O3")) RUN="O3";
1774  else continue;
1775 
1776  wat::Time beg_date(chunk_start[n][0]);
1777  wat::Time end_date(chunk_stop[n][chunk_size[n]-1]);
1778 
1779  double interval = (end_date.GetGPS()-beg_date.GetGPS())/DAY;
1780 
1781  TString sbeg_date = beg_date.GetDateString();sbeg_date.Resize(19);
1782  TString send_date = end_date.GetDateString();send_date.Resize(19);
1783 
1784  sbeg_date.ReplaceAll(" ","-");
1785  send_date.ReplaceAll(" ","-");
1786 
1787  sprintf(sout,"%*s %*.0d %*s %*.0d %*s %*.2f %*f %*.1f", 4, RUN.Data(), 20, beg_date.GetGPS(), 20, sbeg_date.Data(),
1788  20, end_date.GetGPS(), 20, send_date.Data(), 20, interval, 20, obsTime[n]/gOPT.trials, 20, obsTime[n]/DAY/gOPT.trials);
1789  out << sout << endl;
1790  }
1791 
1792  out.close();
1793 }
1794 
1796 
1797  if(gOPT.pfname=="") return;
1798 
1799  char ofname[1024];
1800  TString PFNAME = gOPT.pfname(0,gOPT.pfname.Last('.'));
1801  if(gOPT.bbh) sprintf(ofname,"%s_bbh_config.txt",PFNAME.Data());
1802  else sprintf(ofname,"%s_nobbh_config.txt",PFNAME.Data());
1803 
1804  ofstream out;
1805  out.open(ofname,ios::out);
1806  if(!out.good()) {cout << "DumpUserOptions : Error Opening File : " << ofname << endl;exit(1);}
1807  cout << "dump: " << ofname << endl;
1808 
1809  TString info="";
1810  TString tabs="\t\t\t\t";
1811 
1812  // cWB library
1813  char version[128];
1814  sprintf(version,"WAT Version : %s - SVN Revision : %s - Tag/Branch : %s",watversion('f'),watversion('r'),watversion('b'));
1815 
1816  // cWB config
1817 
1818  // get CWB_CONFIG
1819  char cwb_config_env[1024] = "";
1820  if(gSystem->Getenv("CWB_CONFIG")!=NULL) {
1821  strcpy(cwb_config_env,TString(gSystem->Getenv("CWB_CONFIG")).Data());
1822  }
1823  char cfg_version[256];
1824  TString cfg_branch = GetGitInfos("branch",cwb_config_env);
1825  TString cfg_tag = GetGitInfos("tag",cwb_config_env);
1826  TString cfg_diff = GetGitInfos("diff",cwb_config_env);
1827  if(cfg_branch!="") {
1828  if(cfg_diff!="") cfg_branch=cfg_branch+"/M";
1829  sprintf(cfg_version,"cWB Config Branch\t%s",cfg_branch.Data());
1830  } else if(cfg_tag!="") {
1831  if(cfg_diff!="") cfg_branch=cfg_branch+"/M";
1832  sprintf(cfg_version,"cWB Config Tag\t%s",cfg_tag.Data());
1833  } else {
1834  sprintf(cfg_version,"cWB Config\t%s","Undefined");
1835  }
1836 
1837  out << endl;
1838  out << "--------------------------------" << endl;
1839  out << "PP IFAR version " << endl;
1840  out << "--------------------------------" << endl;
1841  out << endl;
1842  out << version << endl;
1843  out << endl;
1844  out<< cfg_version <<endl;
1845  out<< "cWB Config Hash\t" << GetGitInfos("hash",cwb_config_env) <<endl;
1846  out << endl;
1847 
1848  out << "--------------------------------" << endl;
1849  out << "PP IFAR config options " << endl;
1850  out << "--------------------------------" << endl;
1851  out << endl;
1852 
1853  out << "pp_run " << gOPT.run << endl;
1854  info = "// run type: allowed types are O1/O2/O1O2/O3 (Default: O3)";
1855  out << tabs << info << endl << endl;
1856 
1857  out << "pp_search " << gOPT.search << endl;
1858  info = "// search type: allowed types are BBH,BurstLF,BurstHF,BurstLD,IMBHB + bin1/bin2/... (Default: none)";
1859  out << tabs << info << endl << endl;
1860 
1861  out << "pp_nifo " << gOPT.nifo << endl;
1862  info = "// number of detectors (Default: 2)";
1863  out << tabs << info << endl << endl;
1864 
1865  out << "pp_lag " << gOPT.lag << endl;
1866  info = "// lag -> used only when the input file name is a root file (Default: -1)";
1867  out << tabs << info << endl << endl;
1868 
1869  out << "pp_slag " << gOPT.slag << endl;
1870  info = "// slag -> used only when the input file name is a root file (Default: -1)";
1871  out << tabs << info << endl << endl;
1872 
1873  out << "pp_chunk " << gOPT.chunk << endl;
1874  info = "// chunk -> used only when the input file name is a root file (Default: -1)";
1875  out << tabs << info << endl << endl;
1876 
1877  out << "pp_trials " << gOPT.trials << endl;
1878  info = "// trials factor (Default: 1)";
1879  out << tabs << info << endl << endl;
1880 
1881  out << "pp_pfname " << gOPT.pfname << endl;
1882  info = "// output plot file name, included the directory (Default: none)";
1883  out << tabs << info << endl << endl;
1884 
1885  out << "pp_zl_style " << gOPT.zl_style << endl;
1886  info = "// zero lag plot style: step/marker -> zero lag is displayed with step/marker (Default: step)";
1887  out << tabs << info << endl << endl;
1888 
1889  out << "pp_belt_style " << gOPT.belt_style << endl;
1890  info = "// belt plot style: step/continous -> belts are displayed with step/continuos poisson distribution (Default: continuos)";
1891  out << tabs << info << endl << endl;
1892 
1893  out << "pp_ifar_max " << gOPT.ifar_max << endl;
1894  info = "// max ifar (year) used for plot, if =-1 then it is the maximum ifar from root files (Default: -1)";
1895  out << tabs << info << endl << endl;
1896 
1897  out << "pp_rho_min " << gOPT.rho_min << endl;
1898  info = "// min rho[0/1] read from output root files (Default: 4.5)";
1899  out << tabs << info << endl << endl;
1900 
1901  out << "pp_sfactor " << gOPT.sfactor << endl;
1902  info = "// factor used to normalize the simulation events for the computation of astrophysical rates (Default: 1)";
1903  out << tabs << info << endl << endl;
1904 
1905  out << "bbh " << gOPT.bbh << endl;
1906  info = "// false/true -> if false the known bbh events are excluded from analysis (Default: false)";
1907  out << tabs << info << endl << endl;
1908 
1909  out << "exit " << gOPT.exit << endl;
1910  info = "// false/true -> if true program exit ayt the end of the execution (Default: true)";
1911  out << tabs << info << endl << endl;
1912 
1913  out << "pp_gw151226_ifar " << gOPT.gw151226_ifar << endl;
1914  info = "// GW151226 IFAR(YEARS): if > 0 the GW151226 event is added to the foreground (Default: 0, not added)";
1915  out << tabs << info << endl << endl;
1916 
1917  out << "pp_zl_max_ifar " << gOPT.zl_max_ifar << endl;
1918  info = "// ZL_MAX_IFAR(YEARS): if > 0 all foreground with IFAR>zl_max_ifar is set to zl_max_ifar (Default: 0, not used)";
1919  out << tabs << info << endl << endl;
1920 
1921 }
1922 
1923 // Dumps Background & Belts in ASCII
1925 
1926  if(gOPT.pfname=="") return;
1927 
1928  char ofname[1024];
1929  TString PFNAME = gOPT.pfname(0,gOPT.pfname.Last('.'));
1930  if(gOPT.bbh) sprintf(ofname,"%s_bbh_background.txt",PFNAME.Data());
1931  else sprintf(ofname,"%s_nobbh_background.txt",PFNAME.Data());
1932 
1933  ofstream out;
1934  out.open(ofname,ios::out);
1935  if (!out.good()) {cout << "Error Opening Output File : " << ofname << endl;exit(1);}
1936  cout << "Create Output File : " << ofname << endl;
1937  out.precision(19);
1938 
1939  // write header
1940  out << "#background data : ifar(years), expected, lower_sigma1, lower_sigma2, lower_sigma3, upper_sigma1, upper_sigma2, upper_sigma3" << endl;
1941 
1942  for(int i=0;i<xIFAR.size();i++) {
1943 
1944  double med = bRATE[i];
1945 
1946  double l900 = yBKG[i]-eyRATEinf0[i];
1947  double u900 = yBKG[i]-eyRATEsup0[i];
1948 
1949  double l990 = yBKG[i]-eyRATEinf1[i];
1950  double u990 = yBKG[i]+eyRATEsup1[i];
1951 
1952  double l999 = yBKG[i]-eyRATEinf2[i];
1953  double u999 = yBKG[i]+eyRATEsup2[i];
1954 
1955  out << xIFAR[i] << " " << med
1956  << " " << l900 << " " << l990 << " " << l999
1957  << " " << u900 << " " << u990 << " " << u999
1958  << endl;
1959  }
1960 
1961  out.close();
1962 }
1963 
1964 // Dumps Foreground in ASCII format
1966 
1967  if(gOPT.pfname=="") return;
1968 
1969  char ofname[1024];
1970  TString PFNAME = gOPT.pfname(0,gOPT.pfname.Last('.'));
1971  if(gOPT.bbh) sprintf(ofname,"%s_bbh_foreground.txt",PFNAME.Data());
1972  else sprintf(ofname,"%s_nobbh_foreground.txt",PFNAME.Data());
1973 
1974  ofstream out;
1975  out.open(ofname,ios::out);
1976  if (!out.good()) {cout << "Error Opening Output File : " << ofname << endl;exit(1);}
1977  cout << "Create Output File : " << ofname << endl;
1978  out.precision(19);
1979 
1980  // write header
1981  out << "#foreground data : ifar(years), observed" << endl;
1982 
1983  for(int i=0;i<ZL_NEVT.size();i++) {
1984 
1985  out << ZL_IFAR[i] << " " << ZL_NEVT[i] << endl;
1986  }
1987 
1988  out.close();
1989 }
1990 
1991 // Dumps Simulation & Belts in ASCII format
1992 void DumpSimulation(double ifar_cmax) {
1993 
1994  if(SIM_NEVT.size()<=0) return;
1995  if(gOPT.pfname=="") return;
1996  if(xSIM_BKG_IFAR.size()<=0) return;
1997 
1998  char ofname[1024];
1999  TString PFNAME = gOPT.pfname(0,gOPT.pfname.Last('.'));
2000  if(gOPT.bbh) sprintf(ofname,"%s_bbh_simulation.txt",PFNAME.Data());
2001  else sprintf(ofname,"%s_nobbh_simulation.txt",PFNAME.Data());
2002 
2003  ofstream out;
2004  out.open(ofname,ios::out);
2005  if (!out.good()) {cout << "Error Opening Output File : " << ofname << endl;exit(1);}
2006  cout << "Create Output File : " << ofname << endl;
2007  out.precision(19);
2008 
2009  // write header
2010  out << "#simulation data : ifar(years), estimated+background, lower_90.0, upper_90.0" << endl;
2011 
2012  // compute the index which contains the maximum common IFAR (RATE_TAG)
2013  int ifar_cmax_index=0;
2014  for(int i=0;i<xSIM_BKG_IFAR.size();i++) if(xSIM_BKG_IFAR.data[i]<pow(10,ifar_cmax)/YEAR) ifar_cmax_index=i;
2015 
2016  for(int i=0;i<ifar_cmax_index;i++) {
2017 
2018  double med = xSIM_BKG_IFAR[i];
2019 
2020  double l90 = med-eySIM_BKG_inf0[i];
2021  double u90 = med+eySIM_BKG_sup0[i];
2022 
2023  out << SIM_IFAR[i] << " " << med << " " << l90 << " " << u90 << endl;
2024  }
2025 
2026  out.close();
2027 }
2028 
2030 
2031  if(gOPT.run!="O3") return 0; // this function is implemente only for O3
2032 
2033  // -----------------------------------------------------
2034  // Read Public Alerts Name & GPS times
2035  // -----------------------------------------------------
2036 
2037  // get CWB_CONFIG
2038  char cwb_config_env[1024] = "";
2039  if(gSystem->Getenv("CWB_CONFIG")!=NULL) {
2040  strcpy(cwb_config_env,TString(gSystem->Getenv("CWB_CONFIG")).Data());
2041  }
2042 
2043  char pa_file_list[1024];
2044  sprintf(pa_file_list,"%s/%s/PUBLIC_ALERTS/%s",cwb_config_env,gOPT.run.Data(),PA_FILE_LIST);
2045  cout << pa_file_list << endl;
2046 
2047  CWB::Toolbox::checkFile(pa_file_list);
2048 
2049  // Open chunk list
2050  ifstream in;
2051  in.open(pa_file_list,ios::in);
2052  if (!in.good()) {cout << "Error Opening File : " << pa_file_list << endl;exit(1);}
2053 
2054  int isize=0;
2055  char str[1024];
2056  int fpos=0;
2057  while(true) {
2058  in.getline(str,1024);
2059  if (!in.good()) break;
2060  if(str[0] != '#') isize++;
2061  }
2062  in.clear(ios::goodbit);
2063  in.seekg(0, ios::beg);
2064  if(isize==0) {cout << "Error : File " << pa_file_list << " is empty" << endl;exit(1);}
2065 
2066  // O3 known PA events
2067  if(gOPT.run=="O3") {
2068  O3_BBH_NAME.resize(isize);
2069  O3_BBH_GPS.resize(isize);
2070  }
2071 
2072  int k=0;
2073  char name[256];
2074  double time;
2075  while(true) {
2076  // IN -> S190326b 1237605877.39
2077  in >> name >> time;
2078  if(!in.good()) break;
2079  if(name[0]=='#') continue;
2080  wat::Time sdate(time);
2081 
2082  TString month[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
2083 
2084  // OUT -> S190326b - Mar 26 03:24
2085  char sout_txt[1024];
2086  sprintf(sout_txt,"%s - %s %02d %02d:%02d",name,
2087  month[sdate.GetMonth()-1].Data(),sdate.GetDay(),sdate.GetHour(),sdate.GetMinute());
2088 
2089  // O3 known PA events
2090  if(gOPT.run=="O3") {
2091  O3_BBH_NAME[k]=name;
2092  O3_BBH_GPS[k]=time;
2093  }
2094 
2095  //cout << sout_txt << endl;
2096 
2097  k++;
2098  }
2099  in.close();
2100 
2101  cout.precision(12);
2102  cout << endl;
2103  for(int i=0;i<k;i++) cout << O3_BBH_NAME[i] << "\t" << O3_BBH_GPS[i] << endl;
2104  cout << endl;
2105 
2106  return k;
2107 }
#define IFAR
Definition: MakePlotEgw.C:31
#define FAP2
Definition: Make_PP_IFAR.C:106
int GetPercentiles(double mu, double *q)
int ReadFileList(TString ifName, TChain **live, TChain **wave, TChain **mdc, int *lag, int *slag, int *chunk, int *bin, TString *run)
wavearray< double > eyRATEsup1
Definition: Make_PP_IFAR.C:208
TLegend * leg0
Definition: Make_PP_IFAR.C:172
int ReadPublicAlerts()
TGraph * gr0
Definition: Make_PP_IFAR.C:171
void InitBBH()
TMarker * marker
Definition: Make_PP_IFAR.C:174
#define PP_ZL_MAX_IFAR
Definition: Make_PP_IFAR.C:84
TCanvas * canvas
Definition: Make_PP_IFAR.C:166
int GetChunkID(double gps, TString &run)
#define IFAR_NBIN
Definition: Make_PP_IFAR.C:93
double GetGPSBBH(TString name)
wavearray< double > eyRATEsup2
Definition: Make_PP_IFAR.C:210
void DumpForeground()
wavearray< double > eyRATEinf2
Definition: Make_PP_IFAR.C:209
void MakePlot(TString title, double obsTime, double ifar_cmax)
Definition: Make_PP_IFAR.C:956
wavearray< double > eyRATEsup0
Definition: Make_PP_IFAR.C:206
double chunk_start[MAX_RUNS][CHUNK_MAX_SIZE]
Definition: Make_PP_IFAR.C:227
vector< double > O2_BBH_GPS
Definition: Make_PP_IFAR.C:218
TGraphAsymmErrors * egrsimbkg0
Definition: Make_PP_IFAR.C:170
void GetLiveTime(int nwave, TChain **live, int *lag, int *slag, int *bin, TString *run, double *liveZero, double *liveTot)
void DumpSimulation(double ifar_cmax)
void PrintUserOptions()
#define DAY
Definition: Make_PP_IFAR.C:108
#define MAX_LIST_SIZE
Definition: Make_PP_IFAR.C:92
#define PP_GW151226_IFAR
Definition: Make_PP_IFAR.C:83
#define PP_ZL_STYLE
Definition: Make_PP_IFAR.C:72
wavearray< double > xIFAR
Definition: Make_PP_IFAR.C:183
vector< TString > O2_BBH_NAME
Definition: Make_PP_IFAR.C:217
#define YEAR
Definition: Make_PP_IFAR.C:109
wavearray< double > ZL_GPS
Definition: Make_PP_IFAR.C:201
wavearray< double > SIM_NEVT
Definition: Make_PP_IFAR.C:189
int GetPoissonNsup(double mu, double fap)
wavearray< double > xFAR
Definition: Make_PP_IFAR.C:184
#define PP_PFNAME
Definition: Make_PP_IFAR.C:71
wavearray< double > ZL_IFAR
Definition: Make_PP_IFAR.C:199
void DumpUserOptions()
#define PP_LAG
Definition: Make_PP_IFAR.C:65
wavearray< double > eySIM_BKG_sup0
Definition: Make_PP_IFAR.C:197
void ReadUserOptions(TString options)
#define PP_SEARCH
Definition: Make_PP_IFAR.C:62
#define FAP1
Definition: Make_PP_IFAR.C:105
vector< TString > O3_BBH_NAME
Definition: Make_PP_IFAR.C:221
TLatex * latex
Definition: Make_PP_IFAR.C:176
#define PP_RUN
Definition: Make_PP_IFAR.C:61
#define PP_CHUNK
Definition: Make_PP_IFAR.C:67
wavearray< double > eyRATEinf0
Definition: Make_PP_IFAR.C:205
void Make_PP_IFAR(TString ifName, TString options)
Definition: Make_PP_IFAR.C:260
TGraph * grsimbkg
Definition: Make_PP_IFAR.C:169
#define PP_EXIT
Definition: Make_PP_IFAR.C:81
wavearray< double > ySIM_BKG
Definition: Make_PP_IFAR.C:193
wavearray< double > exSIM_BKG_IFAR
Definition: Make_PP_IFAR.C:194
void ResetUserOptions()
void DumpLoudest(double obsTime)
wavearray< double > SIM_IFAR
Definition: Make_PP_IFAR.C:188
TLegend * leg
Definition: Make_PP_IFAR.C:173
wavearray< double > ZL_NEVT
Definition: Make_PP_IFAR.C:200
void DumpBackground()
#define CHUNK_FILE_LIST
Definition: Make_PP_IFAR.C:111
wavearray< double > xSIM_BKG_IFAR
Definition: Make_PP_IFAR.C:195
vector< TString > O1_BBH_NAME
Definition: Make_PP_IFAR.C:213
TString GetCutBBH()
int chunk_id[MAX_RUNS][CHUNK_MAX_SIZE]
Definition: Make_PP_IFAR.C:226
TGraphAsymmErrors * egr1
Definition: Make_PP_IFAR.C:178
#define PA_FILE_LIST
Definition: Make_PP_IFAR.C:118
wavearray< double > SIM_BKG_NEVT
Definition: Make_PP_IFAR.C:190
#define CHUNK_MAX_SIZE
Definition: Make_PP_IFAR.C:112
TArrow * arrow
Definition: Make_PP_IFAR.C:175
vector< double > O3_BBH_GPS
Definition: Make_PP_IFAR.C:222
#define FAP0
Definition: Make_PP_IFAR.C:104
#define PP_NIFO
Definition: Make_PP_IFAR.C:64
TGraphAsymmErrors * egr0
Definition: Make_PP_IFAR.C:177
TGraphAsymmErrors * egr2
Definition: Make_PP_IFAR.C:179
TGraph * gr
Definition: Make_PP_IFAR.C:167
#define MAX_RUNS
Definition: Make_PP_IFAR.C:90
void DumpPeriod(double *obsTime)
#define PP_BBH
Definition: Make_PP_IFAR.C:80
wavearray< double > exFAR
Definition: Make_PP_IFAR.C:204
wavearray< double > eyRATEinf1
Definition: Make_PP_IFAR.C:207
wavearray< double > bRATE
Definition: Make_PP_IFAR.C:185
#define PP_BELT_STYLE
Definition: Make_PP_IFAR.C:73
wavearray< double > yBKG
Definition: Make_PP_IFAR.C:186
int GetPoissonNinf(double mu, double fap)
uoptions gOPT
Definition: Make_PP_IFAR.C:162
double chunk_stop[MAX_RUNS][CHUNK_MAX_SIZE]
Definition: Make_PP_IFAR.C:228
wavearray< double > eySIM_BKG_inf0
Definition: Make_PP_IFAR.C:196
int chunk_size[MAX_RUNS]
Definition: Make_PP_IFAR.C:225
#define PP_SFACTOR
Definition: Make_PP_IFAR.C:78
#define PP_SLAG
Definition: Make_PP_IFAR.C:66
#define PP_TRIALS
Definition: Make_PP_IFAR.C:69
#define PP_IFAR_MAX
Definition: Make_PP_IFAR.C:75
TString GetNameBBH(double gps)
#define PP_RHO_MIN
Definition: Make_PP_IFAR.C:76
vector< double > O1_BBH_GPS
Definition: Make_PP_IFAR.C:214
TGraph * grsim
Definition: Make_PP_IFAR.C:168
strcpy(analysis,"2G")
pp_rho_min
TString options
int ReadChunkList(TString ifile, int *chunk=NULL, double *start=NULL, double *stop=NULL)
Definition: ReadChunkList.C:22
shift breaksw case n
Definition: cwb_clchunk.csh:75
shift breaksw case M
shift breaksw case q
shift breaksw case m
par[0] name
par[0] value
string search
Definition: cWB_conf.py:63
string run
Definition: cWB_conf.py:6
string version
Definition: cWB_conf.py:159
string title
Definition: cWB_conf.py:15