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