Logo coherent WaveBurst  
Config Reference Guide
Logo
CreateExclusiveLiveTimeFile.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 // this macro converts the standard livetime tree to the exclusive livetime tree
20 // only the zero lag leaf 'live' is updated
21 //
22 
23 #define APPLY_EXCLUSIVE_LIVETIME_ONLY_TO_ZL // update only zero lag
24 
25 void CreateExclusiveLiveTimeFile(TString merge_label,TString searchDir_name, TString esegList_name, TString run, TString olabel) {
26 //
27 // searchDir_name: input search dir name (BURST, BURST_BBH, BURST_IMBHB, BURST_HF, BURST_LD)
28 // esegList_name: input exclusive segment list (must be the list for zero lag)
29 // run: input run (O1,O2,O3a,O3b)
30 // olabel: output label used for the output livetime tree file name .root -> .olabel.root
31 //
32 
33  // input exclusive segment list
34  TString esegList_path = TString::Format("%s/DATA/%s/DATA/%s/OBSTIME/%s/%s",cwb_config_env,run.Data(),calibVer.Data(),searchDir_name.Data(),esegList_name.Data());
35  CWB::Toolbox::checkFile(esegList_path);
36  cout << esegList_path << endl;
37 
38  // input livetime tree file name
39  TString ifName = TString::Format("merge/live_%s.%s.root",data_label,merge_label.Data());
40  CWB::Toolbox::checkFile(ifName);
41  cout << ifName << endl;
42 
43  // output livetime tree file name
44  TString ofName = TString::Format("merge/live_%s.%s.%s.root",data_label,merge_label.Data(),olabel.Data());
45  cout << ofName << endl;
46 
47  vector<waveSegment> esegList = CWB::Toolbox::readSegments(esegList_path); // read exclusive segments
48 
49  // open input livetime tree
50  TFile *iroot = TFile::Open(ifName);
51  if(iroot==NULL) {cout << "CreateExclusiveLiveTimeFile : input root file not found !!!" << endl;exit(1);}
52 
53  TTree* itree = (TTree *) gROOT->FindObject("liveTime");
54  if(itree==NULL) {cout << "CreateExclusiveLiveTimeFile : liveTime tree not found !!!" << endl;exit(1);}
55 
56  int ientries = (int)itree->GetEntries();
57  cout << "livetime entries = " << ientries << endl;
58 
59  double ilive;
60  itree->SetBranchAddress("live", &ilive);
61 
62  double* istart = new double[NIFO_MAX];
63  itree->SetBranchAddress("start", istart);
64 
65  double* istop = new double[NIFO_MAX];
66  itree->SetBranchAddress("stop", istop);
67 
68  float* ilag = new float[NIFO_MAX+1];
69  itree->SetBranchAddress("lag", ilag);
70 
71  float* islag = new float[NIFO_MAX+1];
72  itree->SetBranchAddress("slag", islag);
73 
74  //open new file to store the output livetime Tree
75  TFile oroot(ofName,"recreate");
76  //Create an empty clone of the original tree
77  TTree *otree = (TTree*)itree->CloneTree(0);
78 
79  double olive;
80  otree->SetBranchAddress("live", &olive);
81 
82  waveSegment SEG;
83  vector<waveSegment> osegList;
84 
85  double ilive_time=0.;
86  double olive_time=0.;
87  for (Int_t i=0;i<ientries;i++) {
88  if(i%100000==0) cout << i << " / " << ientries << endl;
89  itree->GetEntry(i);
90 
91 #ifdef APPLY_EXCLUSIVE_LIVETIME_ONLY_TO_ZL
92  if(ilag[nIFO]==0 && islag[nIFO]==0) { // zero lag entries
93 #endif
94  // get range segment for this job intersecting with cat1 list (cat1List)
95  SEG.start = istart[0];
96  SEG.stop = istop[0];
97  osegList.clear();
98  osegList.push_back(SEG);
99  osegList = CWB::Toolbox::mergeSegLists(esegList,osegList); // merge exclusive segments list & input job time range
100  olive=CWB::Toolbox::getTimeSegList(osegList);
101 
102  ilive_time+=ilive;
103  olive_time+=olive;
104 #ifdef APPLY_EXCLUSIVE_LIVETIME_ONLY_TO_ZL
105  } else {
106  olive=ilive;
107  }
108 #endif
109 
110  otree->Fill();
111  }
112  otree->Write();
113  oroot.Close();
114  iroot->Close();
115 
116  cout << "ilivetime zero lag : " << ilive_time << " sec\t" << ilive_time/(24*3600.) << " days" << endl;
117  cout << "olivetime zero lag : " << olive_time << " sec\t" << olive_time/(24*3600.) << " days" << endl;
118 
119  exit(0);
120 }
void CreateExclusiveLiveTimeFile(TString merge_label, TString searchDir_name, TString esegList_name, TString run, TString olabel)
nIFO
TString calibVer
string run
Definition: cWB_conf.py:6