Logo coherent WaveBurst  
Library Reference Guide
Logo
Toolfun.hh
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 #ifndef TOOLFUN_HH
19 #define TOOLFUN_HH
20 
21 #include "TGlobal.h"
22 
23 #ifdef _USE_LAL
24 #include <lal/LALConfig.h>
25 #include <lal/LALVCSInfoHeader.h>
26 #endif
27 
28 #ifdef _USE_EBBH
29 #include "cvode/cvode.h"
30 #endif
31 
32 //_______________________________________________________________________________________
33 inline Double_t PoissonIFunction(Double_t* x, Double_t* par) {
34 //
35 // Int Poisson Function
36 //
37 
38  return par[0]*TMath::PoissonI(x[0],par[1]);
39 }
40 
41 //_______________________________________________________________________________________
42 inline Double_t logNfit(Double_t *x, Double_t *par) {
43 //
44 // log normal function used for efficiency curves fits
45 //
46 
47  double y = (log10(x[0])-par[0]);
48  if(par[4]) y=-y;
49  double s = y<0 ? par[1]*exp(y*par[2]) : par[1]*exp(y*par[3]);
50 
51  if(y>0) {
52  if(par[3]>1./y) {s = par[1]*par[3]*exp(1.); y = 1.;}
53  y = s>0 ? fabs(y/s) : 100.;
54  return 1-TMath::Erfc(y)/2;
55  }
56 
57  if(y<0) {
58  y = s>0 ? fabs(y/s) : 100.;
59  return TMath::Erfc(y)/2;
60  }
61  return 0.5;
62 }
63 
64 //_______________________________________________________________________________________
65 inline int DrawMDC(TString sel="", TString cut="", TString opt="") {
66 //
67 // Draw mdc wavetree
68 // Input parameters are the same as TTree::Draw
69 //
70 
71  TTree* tree = (TTree *) gROOT->FindObject("mdc");
72  if(tree) {
73  if(sel!="") tree->Draw(sel,cut,opt);
74  else tree->StartViewer();
75  } else {cout << "DrawMDC : mdc tree not found !!!" << endl;return 0;}
76  return (Int_t)tree->GetSelectedRows();
77 }
78 
79 //_______________________________________________________________________________________
80 inline int DrawWAVE(TString sel="", TString cut="", TString opt="") {
81 //
82 // Draw wave wavetree
83 // Input parameters are the same as TTree::Draw
84 //
85 
86  TTree* tree = (TTree *) gROOT->FindObject("waveburst");
87  if(tree) {
88  if(sel!="") tree->Draw(sel,cut,opt);
89  else tree->StartViewer();
90  } else {cout << "DrawWAVE : waveburst tree not found !!!" << endl;return 0;}
91  return (Int_t)tree->GetSelectedRows();
92 }
93 
94 //_______________________________________________________________________________________
95 inline int DrawLIVE(TString sel="", TString cut="", TString opt="") {
96 //
97 // Draw liveTime
98 // Input parameters are the same as TTree::Draw
99 //
100 
101  TTree* tree = (TTree *) gROOT->FindObject("liveTime");
102  if(tree) {
103  if(sel!="") tree->Draw(sel,cut,opt);
104  else tree->StartViewer();
105  } else {cout << "DrawLIVE : liveTime tree not found !!!" << endl;return 0;}
106  return (Int_t)tree->GetSelectedRows();
107 }
108 
109 //_______________________________________________________________________________________
110 inline int ScanMDC(TString sel="", TString cut="", TString opt="") {
111 //
112 // Scan mdc wavetree
113 // Input parameters are the same as TTree::Draw
114 //
115 
116  TTree* tree = (TTree *) gROOT->FindObject("mdc");
117  if(tree) {
118  if(sel!="") tree->Scan(sel,cut,opt);
119  else tree->StartViewer();
120  } else {cout << "ScanMDC : mdc tree not found !!!" << endl;return 0;}
121  return (Int_t)tree->GetSelectedRows();
122 }
123 
124 //_______________________________________________________________________________________
125 inline int ScanWAVE(TString sel="", TString cut="", TString opt="") {
126 //
127 // Scan wave wavetree
128 // Input parameters are the same as TTree::Draw
129 //
130 
131  TTree* tree = (TTree *) gROOT->FindObject("waveburst");
132  if(tree) {
133  if(sel!="") tree->Scan(sel,cut,opt);
134  else tree->StartViewer();
135  } else {cout << "ScanWAVE : waveburst tree not found !!!" << endl;return 0;}
136  return (Int_t)tree->GetSelectedRows();
137 }
138 
139 //_______________________________________________________________________________________
140 inline int ScanLIVE(TString sel="", TString cut="", TString opt="") {
141 //
142 // Scan liveTime
143 // Input parameters are the same as TTree::Draw
144 //
145 
146  TTree* tree = (TTree *) gROOT->FindObject("liveTime");
147  if(tree) {
148  if(sel!="") tree->Scan(sel,cut,opt);
149  else tree->StartViewer();
150  } else {cout << "ScanLIVE : liveTime tree not found !!!" << endl;return 0;}
151  return (Int_t)tree->GetSelectedRows();
152 }
153 
154 //_______________________________________________________________________________________
155 inline int PrintMDC() {
156 //
157 // Print mdc tree
158 //
159 
160  TTree* tree = (TTree *) gROOT->FindObject("mdc");
161  if(tree) tree->Print();
162  else {cout << "PrintMDC : mdc tree not found !!!" << endl;return 0;}
163  return (Int_t)tree->GetEntries();
164 }
165 
166 //_______________________________________________________________________________________
167 inline int PrintWAVE() {
168 //
169 // Print wave tree
170 //
171 
172  TTree* tree = (TTree *) gROOT->FindObject("waveburst");
173  if(tree) tree->Print();
174  else {cout << "PrintWAVE : waveburst tree not found !!!" << endl;return 0;}
175  return (Int_t)tree->GetEntries();
176 }
177 
178 //_______________________________________________________________________________________
179 inline int PrintLIVE() {
180 //
181 // Print live tree
182 //
183 
184  TTree* tree = (TTree *) gROOT->FindObject("liveTime");
185  if(tree) tree->Print();
186  else {cout << "PrintLIVE : liveTime tree not found !!!" << endl;return 0;}
187  return (Int_t)tree->GetEntries();
188 }
189 
190 //_______________________________________________________________________________________
191 inline TTree* GetMDC() {
192 //
193 // Get mdc tree pointer
194 //
195 
196  return (TTree *) gROOT->FindObject("mdc");
197 }
198 
199 //_______________________________________________________________________________________
200 inline TTree* GetWAVE() {
201 //
202 // Get wave tree pointer
203 //
204 
205  return (TTree *) gROOT->FindObject("waveburst");
206 }
207 
208 //_______________________________________________________________________________________
209 inline TTree* GetLIVE() {
210 //
211 // Get live tree pointer
212 //
213 
214  return (TTree *) gROOT->FindObject("liveTime");
215 }
216 
217 //_______________________________________________________________________________________
218 inline TString GetFileLabel(TTree* tree, int run, int lag, int slag, double segEdge, TString psfix) {
219 //
220 // return a label
221 // label = "START_STOP_psfix_slagSLAG_lagLAG_1_jobRUN"
222 //
223 
224  char cut[1024];
225  sprintf(cut,"run==%i",run);
226  char draw[256];
227  sprintf(draw,"start[0]-left[0]:stop[0]+right[0]");
228  tree->Draw(draw,cut,"goff");
229  if (tree->GetSelectedRows()==0) {cout <<"GetFileLabel : No events" << endl; exit(1);}
230  double* segstart=tree->GetV1();
231  double* segstop=tree->GetV2();
232  char label[1024];
233  int start = TMath::Nint(segstart[0])+segEdge;
234  int stop = TMath::Nint(segstop[0])-TMath::Nint(segstart[0])-2*segEdge;
235  sprintf(label,"%i_%i_%s_slag%i_lag%i_%i_job%i",
236  start,stop, psfix.Data(),slag,lag,1,run);
237  return label;
238 }
239 
240 //_______________________________________________________________________________________
241 inline void GetProcInfo(TString str="") {
242 //
243 // return pocess infos
244 // Ex : virtual : 279 (mb) rss : 44 (mb)
245 //
246 
247  gSystem->Exec("date");
248  TString s;
249  FILE *f = fopen(Form("/proc/%d/statm", gSystem->GetPid()), "r");
250  s.Gets(f);
251  Long_t total, rss;
252  sscanf(s.Data(), "%ld %ld", &total, &rss);
253  cout << str.Data() << " virtual : " << total * 4 / 1024
254  << " (mb) rss : " << rss * 4 / 1024 << " (mb)" << endl;
255  fclose(f);
256  return;
257 }
258 
259 //_______________________________________________________________________________________
260 inline double GetStart(TTree* tree, int nifo, int run, float rho,
261  double time0, double time1, TString analysis, int irho) {
262 //
263 //
264 //
265 
266  char cut[1024];
267  sprintf(cut,"run==%i && abs(rho[%d]-%f)<0.001 && abs(time[0]-%f)<0.0001 && abs(time[1]-%f)<0.0001",
268  run,irho,rho,time0,time1);
269  char draw[256];
270  sprintf(draw,"start[%i]",nifo);
271  tree->Draw(draw,cut,"goff");
272  if (tree->GetSelectedRows()>1) {
273  cout << "GetStart : Too many events @ the same time : " << tree->GetSelectedRows() << endl;
274  cout << cut << endl;
275  exit(1);
276  }
277  if (tree->GetSelectedRows()==0) {cout <<"GetStart : No events" << endl; exit(1);}
278  double* start=tree->GetV1();
279  return start[0];
280 }
281 
282 //_______________________________________________________________________________________
283 inline TString GetString(TTree* tree, int run, int lag, TString psfix) {
284 //
285 //
286 //
287 
288  char cut[1024];
289  sprintf(cut,"run==%i",run);
290  char draw[256];
291  sprintf(draw,"start[0]-left[0]:stop[0]+right[0]");
292  tree->Draw(draw,cut,"goff");
293  double* segstart=tree->GetV1();
294  double* segstop=tree->GetV2();
295  char s[1024];
296  sprintf(s,"%i_%i_%s_%i_id%i",TMath::Nint(segstart[0])+8,
297  TMath::Nint(segstop[0])-TMath::Nint(segstart[0])-16,psfix.Data(),lag,run);
298  TString st(s);
299  return st;
300 }
301 
302 //_______________________________________________________________________________________
303 inline void CheckAnalysis() {
304 //
305 // check consistency of analysis CINT variable with the environment CWB_ANALYSIS
306 //
307 
308  // import analysis value from CINT
309  char analysis[8];
310  TGlobal* global = gROOT->GetGlobal("analysis",true);
311  //if(global!=NULL) analysis = *(char*)global->GetAddress();
312  if(global!=NULL) {
313  memcpy((void*)&analysis,(void*)global->GetAddress(),sizeof(analysis)*sizeof(char));
314  } else {cout << "CheckAnalysis : analysis is not defined !!!" << endl;exit(1);}
315 
316  if(gSystem->Getenv("CWB_ANALYSIS")!=NULL) {
317  if(TString(analysis)!=TString(gSystem->Getenv("CWB_ANALYSIS"))) {
318  cout << endl;
319  cout << "Error : analysis=" << analysis;
320  cout << " is inconsistent with the environment CWB_ANALYSIS="
321  << gSystem->Getenv("CWB_ANALYSIS") << endl;
322  cout << " check analysis parameter in user_parameters.C" << endl;
323  cout << " check CWB_ANALYSIS env in watenv setup" << endl;
324  cout << " use 'cwb_setpipe [1G/1g/1,2G/2g/2]' command to switch analysis type [1G/2G]" << endl;
325  cout << endl;
326  gSystem->Exit(1);
327  }
328  } else {
329  cout << "" << endl;
330  cout << "CWB_ANALYSIS env not defined in watenv setup" << endl;
331  cout << "" << endl;
332  cout << " - add in watenv setup the following statement" << endl;
333  cout << "" << endl;
334  cout << " setenv CWB_ANALYSIS '1G' # 1G analysis " << endl;
335  cout << " or" << endl;
336  cout << " setenv CWB_ANALYSIS '2G' # 2G analysis " << endl;
337  cout << "" << endl;
338  cout << " - use 'cwb_setpipe [1G/1g/1,2G/2g/2]' command to switch analysis type [1G/2G]" << endl;
339  cout << "" << endl;
340  gSystem->Exit(1);
341  }
342 }
343 
344 //_______________________________________________________________________________________
345 inline TString GetGitInfos(TString option="path", TString igit_path="$CWB_CONFIG") {
346 //
347 // Get git version infos
348 //
349 //
350 // input option : diff,tag,branch,tag
351 // igit_path : input git path, default env variable=$CWB_CONFIG
352 //
353 // output s : return git version infos
354 //
355 
356  char git_path[1024] = "";
357  if(igit_path.BeginsWith("$")) { // get enviromantal variable
358  igit_path.ReplaceAll("$","");
359  if(gSystem->Getenv(igit_path.Data())!=NULL) {
360  strcpy(git_path,gSystem->Getenv(igit_path.Data()));
361  }
362  } else {
363  strcpy(git_path,igit_path.Data());
364  }
365 
366  if(option=="path") return git_path;
367 
368  if(TString(git_path)=="") return "";
369 
370  // Check if path exists
371  Long_t id,size=0,flags,mt;
372  int estat = gSystem->GetPathInfo(git_path,&id,&size,&flags,&mt);
373  if(estat!=0) return "";
374 
375  char cmd[1024];
376 
377  if(option=="diff") {
378  sprintf(cmd,"git -C %s diff HEAD", git_path);
379  }
380 
381  if(option=="hash") {
382  sprintf(cmd,"git -C %s rev-parse HEAD", git_path);
383  }
384 
385  if(option=="branch") {
386  sprintf(cmd,"git -C %s branch -l | grep '*'", git_path);
387  }
388 
389  if(option=="tag") {
390  sprintf(cmd,"git -C %s tag -l --points-at HEAD", git_path);
391  }
392 
393  if(option=="url") {
394  sprintf(cmd,"git -C %s config --get remote.origin.url", git_path);
395  }
396 
397  // redirect stderr to /dev/null to getrid of messages produced by cmd
398  fpos_t poserr; fflush(stderr); fgetpos(stderr, &poserr);
399  int fderr = dup(fileno(stderr)); freopen("/dev/null", "w", stderr);
400  // redirect stdout to /dev/null to getrid of messages produced by cmd
401  fpos_t posout; fflush(stdout); fgetpos(stdout, &posout);
402  int fdout = dup(fileno(stdout)); freopen("/dev/null", "w", stdout);
403 
404  int the_err = gSystem->Exec(cmd);
405 
406  // restore the stderr output
407  fflush(stderr); dup2(fderr, fileno(stderr)); close(fderr);
408  clearerr(stderr); fsetpos(stderr, &poserr);
409  // restore the stdout output
410  fflush(stdout); dup2(fdout, fileno(stdout)); close(fdout);
411  clearerr(stdout); fsetpos(stdout, &posout);
412 
413 
414  if(the_err==0) {
415  TString the_output = gSystem->GetFromPipe(cmd);
416  if(option=="branch") {
417  the_output.ReplaceAll("*","");
418  the_output.ReplaceAll(" ","");
419  if(the_output=="(nobranch)") the_output="";
420  }
421  return the_output;
422  }
423 
424  return "";
425 }
426 
427 //_______________________________________________________________________________________
428 inline void PrintLogoCWB(TString LALVersion="", TString cwb_library_path="$HOME_WAT", TString cwb_config_path="$CWB_CONFIG") {
429 //
430 // Print CWB logo
431 //
432 
433  // check operative system
434  // ------------------------------------------------------------------------------------
435  TString OS = "";
436  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
437  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
438 
439  char line[256];
440  TString sline;
441  const char *root_version = gROOT->GetVersion();
442  cout << endl;
443  cout << " ****************************************************************************" << endl;
444  cout << " * *" << endl;
445  cout << " * W E L C O M E to C W B *" << endl;
446  cout << " * *" << endl;
447  // print WAT version
448  sprintf(line," * cWB Version %s (XIFO=%s)",watversion('s'),watversion('i'));
449  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
450 
451  // print library GIT branch
452  //TString wat_branch = GetGitInfos("branch",cwb_library_path);
453  //TString wat_tag = GetGitInfos("tag",cwb_library_path);
454  //TString wat_diff = GetGitInfos("diff",cwb_library_path);
455  TString wat_branch = watversion('b');
456  TString wat_tag = watversion('g');
457  TString wat_diff = "";
458  if(wat_branch!="") {
459  if(wat_diff!="") wat_branch=wat_branch+"/M";
460  sprintf(line," * Branch %s",wat_branch.Data());
461  } else if(wat_tag!="") {
462  if(wat_diff!="") wat_branch=wat_branch+"/M";
463  sprintf(line," * Tag %s",wat_tag.Data());
464  } else {
465  sprintf(line," * %s","Undefined");
466  }
467  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
468 
469  // print library GIT hash
470  //sprintf(line," * Hash %s",GetGitInfos("hash",cwb_library_path).Data());
471  sprintf(line," * Hash %s",watversion('r'));
472  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
473  sprintf(line," * Short Hash %s",watversion('R'));
474  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
475  cout << " * *" << endl;
476 
477  // print LAL version
478  if(LALVersion!="") {
479  sprintf(line," * LAL Branch %s",LALVersion.Data());
480  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
481  }
482 
483  // FRAMELIB_VERSION is not defined in Darwin OS (to be checked)
484  if(OS=="Linux") {
485  sprintf(line," * FRLIB Version %2.2f",FRAMELIB_VERSION);
486  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
487  }
488 
489  // print CVODE version
490  if(WAT::USE_EBBH()) {
491 #ifdef SUNDIALS_PACKAGE_VERSION // SUNDIALS_PACKAGE_VERSION = 2.7.0
492  sprintf(line," * CVODE Version %s",SUNDIALS_PACKAGE_VERSION);
493  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
494 #endif
495 #ifdef SUNDIALS_VERSION // SUNDIALS_VERSION >= 3.2.1
496  sprintf(line," * CVODE Version %s",SUNDIALS_VERSION);
497  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
498 #endif
499  }
500  cout << " * *" << endl;
501 
502  // print ROOT version
503  sprintf(line," * Based on ROOT %s",root_version);
504  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
505 
506  cout << " * *" << endl;
507  if(WAT::USE_ROOT6()) cout << " * ROOT6 ENABLED *" << endl;
508  if(WAT::USE_CPP11()) cout << " * CP11 ENABLED *" << endl;
509  if(WAT::USE_ICC()) cout << " * ICC ENABLED *" << endl;
510  if(!WAT::USE_LAL()) cout << " * LAL DISABLED *" << endl;
511  if(!WAT::USE_HEALPIX()) cout << " * HEALPix DISABLED *" << endl;
512  if(!WAT::USE_EBBH()) cout << " * EBBH DISABLED *" << endl;
513 
514  if(gSystem->Getenv("_USE_PEGASUS")!=NULL)
515  cout << " * PEGASUS ENABLED *" << endl;
516  if(gSystem->Getenv("_USE_LSF")!=NULL)
517  cout << " * LSF ENABLED *" << endl;
518  if(gSystem->Getenv("_USE_OSG")!=NULL)
519  cout << " * OSG ENABLED *" << endl;
520 #if (WAT_VERSION_DEVEL != 0)
521  cout << " * *" << endl;
522  sprintf(line," * DEVELOPMENT VERSION : %d",WAT_VERSION_DEVEL);
523  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
524 #endif
525  cout << " * *" << endl;
526 
527  // print config GIT branch
528  TString cfg_branch = GetGitInfos("branch",cwb_config_path);
529  TString cfg_tag = GetGitInfos("tag",cwb_config_path);
530  TString cfg_diff = GetGitInfos("diff",cwb_config_path);
531  bool cfg_status = true;
532  if(cfg_branch!="") {
533  if(cfg_diff!="") cfg_branch=cfg_branch+"/M";
534  sprintf(line," * CONFIG Branch %s",cfg_branch.Data());
535  } else if(cfg_tag!="") {
536  if(cfg_diff!="") cfg_branch=cfg_branch+"/M";
537  sprintf(line," * CONFIG Tag %s",cfg_tag.Data());
538  } else {
539  sprintf(line," * CONFIG %s","Undefined");
540  cfg_status = false;
541  }
542  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
543 
544  // print config GIT hash
545  if(cfg_status) {
546  sprintf(line," * Hash %s",GetGitInfos("hash",cwb_config_path).Data());
547  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
548  }
549 
550  // print data config GIT branch
551  TString cwb_data_path = gSystem->ExpandPathName(cwb_config_path+"/DATA");
552  TString data_branch = GetGitInfos("branch",cwb_data_path);
553  TString data_tag = GetGitInfos("tag",cwb_data_path);
554  TString data_diff = GetGitInfos("diff",cwb_data_path);
555  bool data_status = true;
556 
557  char data_name[1024];
558  int len;
559  if ((len = readlink(cwb_data_path.Data(), data_name, sizeof(data_name)-1)) != -1) data_name[len] = '\0';
560 
561  if(data_branch!="") {
562  if(data_diff!="") data_branch=data_branch+"/M";
563  if(data_branch==cfg_branch) { // default config DATA
564  sprintf(line," * DATA Branch %s",data_name);
565  } else {
566  sprintf(line," * DATA Branch %s",data_branch.Data());
567  }
568  } else if(data_tag!="") {
569  if(data_diff!="") data_branch=data_branch+"/M";
570  if(data_tag==cfg_tag) { // default config DATA
571  sprintf(line," * DATA Tag %s",data_name);
572  } else {
573  sprintf(line," * DATA Tag %s",data_tag.Data());
574  }
575  } else {
576  sprintf(line," * DATA %s","UNDEFINED");
577  data_status = false;
578  }
579  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
580 
581  // print data config GIT hash
582  if(data_status) {
583  sprintf(line," * Hash %s",GetGitInfos("hash",cwb_data_path).Data());
584  sline=line;sline.Resize(80);sline+="*";cout<<sline<<endl;
585  }
586 
587  cout << " * *" << endl;
588  cout << " ****************************************************************************" << endl;
589  cout << endl;
590  cout << watversion('x') << endl;
591  cout << " Compiled on " << watversion('k') << " "
592  << watversion('m') << " " << watversion('n') << endl;
593  cout << " " << watversion('t') << endl;
594  cout << endl;
595 
596  return;
597 }
598 
599 //_______________________________________________________________________________________
600 inline int Draw(TChain& rf, string par, string cut, string opt)
601 { return rf.Draw(par.c_str(),cut.c_str(),opt.c_str()); }
602 
603 //_______________________________________________________________________________________
604 inline int Draw(TTree& rf, string par, string cut, string opt)
605 { return rf.Draw(par.c_str(),cut.c_str(),opt.c_str()); }
606 
607 //_______________________________________________________________________________________
608 inline TCanvas* DRAW(TChain& rf, string par, string cut, string opt, int iX=600, int iY=600){
609  TCanvas *c1 = new TCanvas("c","C",0,0,iX,iY);
610  c1->SetBorderMode(0);
611  c1->SetFillColor(0);
612  c1->SetBorderSize(2);
613  c1->SetGridx();
614  c1->SetGridy();
615  c1->SetRightMargin(0.1517039);
616  c1->SetTopMargin(0.0772727);
617  c1->SetBottomMargin(0.103939);
618  rf.Draw(par.c_str(),cut.c_str(),opt.c_str());
619  return c1;
620 }
621 
622 //_______________________________________________________________________________________
623 inline TCanvas* Draw(TH1F* h, int iX=600, int iY=600){
624 
625  TCanvas *c1 = new TCanvas("c","C",0,0,iX,iY);
626  c1->SetBorderMode(0);
627  c1->SetFillColor(0);
628  c1->SetBorderSize(2);
629  c1->SetGridx();
630  c1->SetGridy();
631  c1->SetRightMargin(0.1517039);
632  c1->SetTopMargin(0.0772727);
633  c1->SetBottomMargin(0.103939);
634  h->Draw();
635 
636  return c1;
637 }
638 
639 //_______________________________________________________________________________________
640 inline TCanvas* Draw(TH2F* h, char* opt, int iX=600, int iY=600){
641 
642  TCanvas *c1 = new TCanvas("c","C",0,0,iX,iY);
643  c1->SetBorderMode(0);
644  c1->SetFillColor(0);
645  c1->SetBorderSize(2);
646  c1->SetLogx(kFALSE);
647  c1->SetGridx();
648  c1->SetGridy();
649  c1->SetRightMargin(0.1517039);
650  c1->SetTopMargin(0.0772727);
651  c1->SetBottomMargin(0.103939);
652  h->Draw(opt);
653 
654  return c1;
655 }
656 
657 //_______________________________________________________________________________________
658 inline TCanvas* Draw(TH1F** h, int n=1, int m=0, int iX=600, int iY=600){
659 
660  TCanvas *c1 = new TCanvas("c","C",0,0,iX,iY);
661  c1->SetBorderMode(0);
662  c1->SetFillColor(0);
663  c1->SetBorderSize(2);
664  c1->SetLogx(kFALSE);
665  c1->SetGridx();
666  c1->SetGridy();
667  c1->SetRightMargin(0.1517039);
668  c1->SetTopMargin(0.0772727);
669  c1->SetBottomMargin(0.103939);
670 
671  int i=0;
672  if(!m) {
673  (*(h+i))->Draw();
674  for(i=1; i<n; i++) (*(h+i))->Draw("same");
675  }
676  else {
677  c1->Divide(m,n);
678  for(int i=0; i<n*m; i++) { c1->cd(i+1); (*(h+i))->Draw(); }
679  }
680  return c1;
681 }
682 
683 //_______________________________________________________________________________________
684 inline TCanvas* Draw(TH2F** h, char* opt, int n=1, int m=0, int iX=600, int iY=600){
685 
686  TCanvas *c1 = new TCanvas("c","C",0,0,iX,iY);
687  c1->SetBorderMode(0);
688  c1->SetFillColor(0);
689  c1->SetBorderSize(2);
690  c1->SetLogx(kFALSE);
691  c1->SetGridx();
692  c1->SetGridy();
693  c1->SetRightMargin(0.1517039);
694  c1->SetTopMargin(0.0772727);
695  c1->SetBottomMargin(0.103939);
696 
697  if(!m) {
698  (*h)->Draw(opt);
699  for(int i=1; i<n; i++) (*(h+i))->Draw("same");
700  }
701  else {
702  c1->Divide(m,n);
703  for(int i=0; i<n*m; i++) { c1->cd(i+1); (*(h+i))->Draw(opt); }
704  }
705  return c1;
706 }
707 
708 //_______________________________________________________________________________________
709 inline TCanvas* Draw(TGraphErrors** h, char* opt, int n=1, int m=0, int iX=600, int iY=600){
710 
711  TCanvas *c1 = new TCanvas("c","C",0,0,iX,iY);
712  c1->SetBorderMode(0);
713  c1->SetFillColor(0);
714  c1->SetBorderSize(2);
715  c1->SetLogx(kFALSE);
716  c1->SetGridx();
717  c1->SetGridy();
718  c1->SetRightMargin(0.1517039);
719  c1->SetTopMargin(0.0772727);
720  c1->SetBottomMargin(0.103939);
721 
722  if(!m) {
723  (*h)->Draw(opt);
724  for(int i=1; i<n; i++) (*(h+i))->Draw("P");
725  }
726  else {
727  c1->Divide(m,n);
728  for(int i=0; i<n*m; i++) { c1->cd(i+1); (*(h+i))->Draw(opt); }
729  }
730  return c1;
731 }
732 
733 //_______________________________________________________________________________________
734 inline TCanvas* Draw(TGraph** h, char* opt, int n=1, int m=0, int iX=600, int iY=600){
735 
736  TCanvas *c1 = new TCanvas("c","C",0,0,iX,iY);
737  c1->SetBorderMode(0);
738  c1->SetFillColor(0);
739  c1->SetBorderSize(2);
740  c1->SetLogx(kFALSE);
741  c1->SetGridx();
742  c1->SetGridy();
743  c1->SetRightMargin(0.1517039);
744  c1->SetTopMargin(0.0772727);
745  c1->SetBottomMargin(0.103939);
746 
747  if(!m) {
748  (*h)->Draw(opt);
749  for(int i=1; i<n; i++) (*(h+i))->Draw("P");
750  }
751  else {
752  c1->Divide(m,n);
753  for(int i=0; i<n*m; i++) { c1->cd(i+1); (*(h+i))->Draw(opt); }
754  }
755  return c1;
756 }
757 
758 //_______________________________________________________________________________________
759 inline double GetLiveTime(TString fliveName, int SLAG, int LAG, int& nlags) {
760 //
761 // return live time in sec read from live.txt file produced in the background report
762 //
763 // input fliveName : livetime file name
764 // SLAG : select LAG, SLAG<0 -> any slag
765 // LAG : select LAG, LAG<0 -> any lag
766 //
767 // output nlags : return the selected lags
768 //
769 // examples : LAG=0,SLAG=0 -> select zero LAG live time
770 // : LAG=-1,SLAG=-1 -> select all LAG,SLAG
771 // : LAG=1,SLAG=-1 -> select LAG=-1 and all SLAG
772 //
773 // livetime format : slag=SLAG lag=LAG L1:slag= 0.00 lag= 0.00 ... live=2145137.00
774 //
775 
776  double livetime=0.;
777  nlags=0;
778 
779  ifstream inliv(fliveName);
780  if (!inliv.good()) {cout << "GetLiveTime : Error Opening File : " << fliveName << endl;exit(1);}
781 
782  char line[1024];
783  while(1) {
784  // read line
785  inliv.getline(line,256);
786  if (!inliv.good()) break;
787  TString Oliv(line);
788  TObjArray* token = TString(Oliv).Tokenize(TString('='));
789  // skip nonzero livetime line
790  if(Oliv.Contains("nonzero")) continue;
791  // check line format
792  if(!TString(line).Contains("slag=")) {cout<<"GetLiveTime : Bad line format : "<<line<<endl<<endl;exit(1);}
793  if(!TString(line).Contains("lag=")) {cout<<"GetLiveTime : Bad line format : "<<line<<endl<<endl;exit(1);}
794  if(!TString(line).Contains("live=")) {cout<<"GetLiveTime : Bad line format : "<<line<<endl<<endl;exit(1);}
795  // last token contains livetime
796  TObjString* tok=(TObjString*)token->At(token->GetEntries()-1);
797  token = TString(Oliv).Tokenize(TString(' '));
798  // get slag number
799  TObjString* tokslag=(TObjString*)token->At(0);
800  int slag=TString(tokslag->GetString()).ReplaceAll("slag=","").Atoi();
801  // get lag number
802  TObjString* toklag=(TObjString*)token->At(1);
803  int lag=TString(toklag->GetString()).ReplaceAll("lag=","").Atoi();
804  // get livetime with lag=LAG & slag=SLAG
805  if((lag==LAG||LAG<0) && (slag==SLAG||SLAG<0)) {
806  livetime+=TString(tok->GetString()).Atof();
807  nlags++;
808  }
809  }
810  inliv.close();
811 
812  return livetime;
813 }
814 
815 //_______________________________________________________________________________________
816 inline int ReadInjType(TString ifName, int ntype_max, char set[][128], size_t type[],
817  char name[][128], double fcentral[], double fbandwidth[]) {
818 //
819 // Read the user defined injection types file : ifName
820 //
821 // ifName // list mdc types file name (ascii)
822 // format : set type name fcentral fbandwidth
823 // ntype_max // max number of mdc types
824 // set[NMDC_MAX][128]; // injection set
825 // type[NMDC_MAX]; // injection type
826 // name[NMDC_MAX][128]; // injection name
827 // fcentral[NMDC_MAX]; // injection central frequencies
828 // fbandwidth[NMDC_MAX]; // injection bandwidth frequencies
829 
830  // open injection file list mdc types
831  ifstream in;
832  cout << "inj file: " << ifName << endl;
833  in.open(ifName.Data(),ios::in);
834  if (!in.good()) {cout << "ReadMdcType : Error Opening File : " << ifName << endl;exit(1);}
835 
836  int ninj=0;
837  char str[1024];
838  int fpos=0;
839  while (1) {
840  fpos=in.tellg();
841  in.getline(str,1024);
842  if (!in.good() && strlen(str)!=0) {
843  cout << endl;
844  cout << "ReadMdcType : Error Reading File : " << ifName << endl;
845  cout << "at line : \"" << str << "\"" << endl;
846  cout << "check if new line is defined at the end of the string" << endl;
847  exit(1);
848  }
849  if (!in.good()) break;
850  if((str[0] == '#')||(str[0] == ' ')||(str[0] == 0)) continue;
851  in.seekg(fpos, ios::beg);
852 
853  in >> set[ninj] >> type[ninj] >> name[ninj]
854  >> fcentral[ninj] >> fbandwidth[ninj];
855 
856  fpos=in.tellg();
857  in.seekg(fpos+1, ios::beg);
858 
859  if (!in.good()) break;
860  cout << " " << set[ninj] << " " << type[ninj] << " " << name[ninj]
861  << " " << fcentral[ninj] << " " << fbandwidth[ninj] << endl;
862  ninj++;
863  if(ninj>=ntype_max) {
864  cout << "ReadMdcType : Error - max allowed injection types must be < "
865  << ntype_max << endl;
866  exit(1);
867  }
868  }
869  in.close();
870 
871  return ninj;
872 }
873 
874 //_______________________________________________________________________________________
875 inline void MakePlotsHtmlTable(ofstream* out, TString title, TString png1, TString png2="") {
876 //
877 // macro used to generate a table with 2 plots in html code
878 //
879 // out : pinter to the output streamer
880 // title : table title
881 // png1 : path of first png file name
882 // png2 : path of second png file name
883 //
884 // if png2="" then only one plot is showed
885 //
886 
887  int psize = 960;
888  if(png2.IsDigit()) {
889  psize=png2.Atoi();
890  png2="";
891  } else {
892  psize = png2=="" ? 960 : 480;
893  }
894 
895  *out << "<br></td></tr></table>" << endl;
896  *out << endl;
897  *out << "<div align=\"center\"><font color=\"red\"><h2>"<<title<<"</h2></font></div>" << endl;
898 
899  *out << "<p><table summary=\"\"><tr align=\"left\"><td valign=\"top\" width=\"50%\"> \
900  <div align=\"center\"><ul><br/>" << endl;
901  *out << "<a class=\"image\" title=\""<<png1<<"\">" << endl;
902  *out << "<img src=\""<<png1<<"\" onerror=\"this.style.visibility = 'hidden'\" width=\""<<psize<<"\"> </a>" << endl;
903  *out << "</br></ul><br><br>" << endl;
904  *out << endl;
905  if(png2=="") return;
906  *out << "</div>" << endl;
907  *out << "<p></td><td valign=\"top\" width=\"50%\"><div align=\"center\"><ul><br/>" << endl;
908  *out << "<a class=\"image\" title=\""<<png2<<"\">" << endl;
909  *out << "<img src=\""<<png2<<"\" onerror=\"this.style.visibility = 'hidden'\" width=\""<<psize<<"\"> </a>" << endl;
910  *out << "</br></ul><br><br>" << endl;
911  *out << endl;
912  *out << "</div>" << endl;
913 }
914 
915 //_______________________________________________________________________________________
916 inline void MakePlotsHtmlCellTable(ofstream* out, TString title, TString png1, TString subtitle1="", TString png2="", TString subtitle2="") {
917 //
918 // macro used to generate a cell with a table with 2 plots in html code
919 //
920 // out : pointer to the output streamer
921 // title : table title
922 // subtitle1 : title for cell 1
923 // png1 : path of first png file name
924 // subtitle2 : title for cell 2
925 // png2 : path of second png file name
926 //
927 // if png2="" then only one plot is showed
928 //
929 
930  int h = 380;
931  *out << "<font color=\"red\" style=\"font-weight:bold;\"><center><p><h3>"<< title << "</h3><p><center></font>" << endl;
932  *out << "<p>" << endl;
933  *out << endl;
934  *out << "<table cellspacing=\"0\" cellpadding=\"6\" border=\"0\" align=\"center\" width=\"1100\">" << endl;
935  *out << "<tr>" << endl;
936  *out << "<th>" << subtitle1 << "</th>" << endl;
937  *out << "<th>" << subtitle2 << "</th>" << endl;
938  *out << "</tr>" << endl;
939  *out << "<tr>" << endl;
940  *out << "<td align=\"center\"><a target=\"_parent\" href=\""<< png1 <<"\"><img src=\""<< png1 << "\" height=" << h <<"></a></td>";
941  if(png2=="") return;
942  *out << "<td align=\"center\"><a target=\"_parent\" href=\""<< png2 <<"\"><img src=\""<< png2 << "\" height=" << h <<"></a></td>";
943  *out << "</tr>" << endl;
944  *out << "</table>" << endl;
945  *out << "<br><br>" << endl;
946 }
947 //_______________________________________________________________________________________
948 inline double GetPrecision(int cluster_size_threshold=0, int healpix_order=0) {
949 //
950 // set $CWB_PARAMETERS_FILE precision variable
951 // is used in network::likelihoodWP to reduce the computational time of big clusters
952 // cluster_size_threshold is the threshold
953 // healpix_order is the healpix_orser skymap used when cluster_size is greater
954 // of cluster_size_threshold*resolution levels
955 
956  if(cluster_size_threshold>=65536) {
957  cout << "GetPrecision Error : cluster_size_threshold must be < 65536" << endl;
958  exit(-1);
959  };
960  if(healpix_order<0) {
961  cout << "GetPrecision Error : healpix_order must be >= 0" << endl;
962  exit(-1);
963  };
964  double precision = cluster_size_threshold+65536*healpix_order;
965 
966  return precision;
967 }
968 
969 //_______________________________________________________________________________________
971 //
972 // Add entry rho to the ifar statistic
973 // is used in a compiled version for the pp report to speed up the computation
974 
975  for(int j=0; j<Xfar->size(); j++) {
976  Xfar->data[j] = far_rho_min+j*far_drho;
977  if(rho > Xfar->data[j]) {Yfar->data[j] += 1.;}
978  }
979 }
980 
981 //_______________________________________________________________________________________
982 #ifdef _USE_LAL
983 inline TString GetLALVersion(TString option="") {
984 //
985 // return LAL version (if LAL is not enabled in mdc an empty string is returned)
986 //
987 //
988 // Input: option - lalVersion,lalVersionMajor,lalVersionMinor,lalVersionMicro,
989 // lalVersionDevel,lalBuildDate,lalConfigureArgs,lalConfigureDate
990 
991  if(option=="lalVersion") return LAL_VERSION;
992  if(option=="lalVersionMajor") {char s[32];sprintf(s,"%d",LAL_VERSION_MAJOR); return s;}
993  if(option=="lalVersionMinor") {char s[32];sprintf(s,"%d",LAL_VERSION_MINOR); return s;}
994  if(option=="lalVersionMicro") {char s[32];sprintf(s,"%d",LAL_VERSION_MICRO); return s;}
995  if(option=="lalVersionDevel") {char s[32];sprintf(s,"%d",LAL_VERSION_DEVEL); return s;}
996 
997  TString date = LAL_VCS_DATE;
998  date.Remove(date.Index(' '),date.Sizeof());
999  TString vcs_branch = TString(LAL_VCS_BRANCH)+" ("+date+")";
1000 
1001  return vcs_branch;
1002 }
1003 #else
1004 inline TString GetLALVersion(TString options="") {return "";}
1005 #endif
1006 
1007 #endif
TTree * GetWAVE()
Definition: Toolfun.hh:200
TTree * tree
Definition: TimeSortTree.C:20
wavearray< double > Yfar(far_rho_bin)
double rho
TString GetLALVersion(TString options="")
Definition: Toolfun.hh:1004
TString GetGitInfos(TString option="path", TString igit_path="$CWB_CONFIG")
Definition: Toolfun.hh:345
void MakePlotsHtmlTable(ofstream *out, TString title, TString png1, TString png2="")
Definition: Toolfun.hh:875
Double_t PoissonIFunction(Double_t *x, Double_t *par)
Definition: Toolfun.hh:33
double time1
CWB run(runID)
TString opt
double far_drho
bool USE_EBBH()
Definition: wat.hh:45
par [0] name
int DrawWAVE(TString sel="", TString cut="", TString opt="")
Definition: Toolfun.hh:80
int n
Definition: cwb_net.C:28
float far_rho_min
char * watversion(char c='s')
Definition: watversion.hh:21
TString("c")
wavearray< double > Xfar(far_rho_bin)
ofstream out
Definition: cwb_merge.C:214
double GetLiveTime(TString fliveName, int SLAG, int LAG, int &nlags)
Definition: Toolfun.hh:759
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1) *itime+ifreq;double time=itime *dT;double freq=(ifreq >0) ? ifreq *dF :dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
void AddRho2FAR(double rho, wavearray< double > *Xfar, wavearray< double > *Yfar, double far_rho_min, double far_drho)
Definition: Toolfun.hh:970
double GetStart(TTree *tree, int nifo, int run, float rho, double time0, double time1, TString analysis, int irho)
Definition: Toolfun.hh:260
Long_t flags
int ScanWAVE(TString sel="", TString cut="", TString opt="")
Definition: Toolfun.hh:125
Long_t size
int m
Definition: cwb_net.C:28
double segEdge
Definition: test_config1.C:49
int j
Definition: cwb_net.C:28
i drho i
int Draw(TChain &rf, string par, string cut, string opt)
Definition: Toolfun.hh:600
#define WAT_VERSION_DEVEL
Definition: watversion.hh:13
bool USE_ROOT6()
Definition: wat.hh:52
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
bool USE_ICC()
Definition: wat.hh:66
TString GetFileLabel(TTree *tree, int run, int lag, int slag, double segEdge, TString psfix)
Definition: Toolfun.hh:218
bool USE_CPP11()
Definition: wat.hh:59
virtual size_t size() const
Definition: wavearray.hh:145
TCanvas * DRAW(TChain &rf, string par, string cut, string opt, int iX=600, int iY=600)
Definition: Toolfun.hh:608
char str[1024]
TGlobal * global
Definition: config.cc:23
wavearray< double > h
Definition: Regression_H1.C:25
double GetPrecision(int cluster_size_threshold=0, int healpix_order=0)
Definition: Toolfun.hh:948
TCanvas * c1
TTree * GetMDC()
Definition: Toolfun.hh:191
TString label
Definition: MergeTrees.C:21
int ninj
Definition: cwb_mkeff.C:70
char cut[512]
double time0
int PrintWAVE()
Definition: Toolfun.hh:167
double precision
int ScanMDC(TString sel="", TString cut="", TString opt="")
Definition: Toolfun.hh:110
TString sel("slag[1]:slag[2]")
TObjArray * token
vector< mdcpar > par
void MakePlotsHtmlCellTable(ofstream *out, TString title, TString png1, TString subtitle1="", TString png2="", TString subtitle2="")
Definition: Toolfun.hh:916
int ScanLIVE(TString sel="", TString cut="", TString opt="")
Definition: Toolfun.hh:140
bool USE_HEALPIX()
Definition: wat.hh:31
TString GetString(TTree *tree, int run, int lag, TString psfix)
Definition: Toolfun.hh:283
int PrintMDC()
Definition: Toolfun.hh:155
int ReadInjType(TString ifName, int ntype_max, char set[][128], size_t type[], char name[][128], double fcentral[], double fbandwidth[])
Definition: Toolfun.hh:816
s s
Definition: cwb_net.C:155
float irho
char options[256]
int nifo
char title[256]
Definition: SSeriesExample.C:1
void CheckAnalysis()
Definition: Toolfun.hh:303
condor_log_dir ReplaceAll("X_HOME", uhome.Data())
ifstream in
double fabs(const Complex &x)
Definition: numpy.cc:55
int PrintLIVE()
Definition: Toolfun.hh:179
char cmd[1024]
int estat
strcpy(RunLabel, RUN_LABEL)
TString OS
Definition: cwb_rootlogon.C:25
Definition: Toolbox.hh:99
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
Long_t mt
DataType_t * data
Definition: wavearray.hh:319
TTree * GetLIVE()
Definition: Toolfun.hh:209
Long_t id
void PrintLogoCWB(TString LALVersion="", TString cwb_library_path="$HOME_WAT", TString cwb_config_path="$CWB_CONFIG")
Definition: Toolfun.hh:428
int DrawLIVE(TString sel="", TString cut="", TString opt="")
Definition: Toolfun.hh:95
in close()
char line[1024]
fclose(ftrig)
wavearray< double > y
Definition: Test10.C:31
Double_t logNfit(Double_t *x, Double_t *par)
Definition: Toolfun.hh:42
void GetProcInfo(TString str="")
Definition: Toolfun.hh:241
exit(0)
bool USE_LAL()
Definition: wat.hh:38
int DrawMDC(TString sel="", TString cut="", TString opt="")
Definition: Toolfun.hh:65