Logo coherent WaveBurst  
Library Reference Guide
Logo
GetIfoSegments.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 // Read livetime tree from input root file and produce segments.txt -> used for DetChar
20 //
21 // Example: root -l -b 'GetIfoSegments.C("merge/live_O3_K19_C01_LV_IMBHB_BKG_xrun1.M1.root",1,"K19_segments.txt")'
22 //
23 
24 void GetIfoSegments(TString liveFileName, int ifoID, TString ofile) {
25 //
26 // liveFileName : input livetime root file
27 // ifoID : detectior ID
28 // ofile : output file name
29 //
30 
31 // Read livetime ROOT file
32 
33  TFile *_file0 = TFile::Open(liveFileName);
34  TTree* tree = (TTree *) gROOT->FindObject("liveTime");
35  if(tree==NULL) {cout << "ScanLIVE : liveTime tree not found !!!" << endl;exit(1);}
36  int nentries = tree->GetEntries();
37  cout << endl << "in nentries = " << nentries << endl << endl;
38 
39  if(ifoID<0 || ifoID>=NIFO_MAX) {cout << "Error - input ifoID not correct, max available ID is: " << NIFO_MAX-1 << endl; exit(1);}
40 
41 // Read start/stop entries from livetime ROOT file
42 // and fill the vector segmnts list iseg
43 
44  int index=0;
46  vector<waveSegment> iseg;
47 
48  double* start = new double[NIFO_MAX];
49  tree->SetBranchAddress("start",start);
50  double* stop = new double[NIFO_MAX];
51  tree->SetBranchAddress("stop",stop);
52 
53  for(int i=0;i<nentries;i++) { // loop over the detected events
54  tree->GetEntry(i); // load entry #i
55  seg.index=index++; seg.start=start[ifoID]; seg.stop=stop[ifoID]; iseg.push_back(seg);
56  }
57 
58  // --------------------------------------------------------------
59  // merge segments
60  // --------------------------------------------------------------
61  vector<waveSegment> oseg = CWB::Toolbox::unionSegments(iseg);
62  cout << endl << "out size = " << oseg.size() << endl << endl;
63 
64 // cout << "List of output segments" << endl;
65 // for(int n=0;n<oseg.size();n++) cout << n << " " << oseg[n].start << " " << oseg[n].stop << endl;
66 
67  // --------------------------------------------------------------
68  // Write output file segment list
69  // --------------------------------------------------------------
70  ofstream out;
71  out.open(ofile.Data(),ios::out);
72  out.precision(16);
73  double liveTime=0.;
74  for(int n=0;n<oseg.size();n++) {
75  out << oseg[n].start << " " << oseg[n].stop << endl;
76  liveTime+=oseg[n].stop-oseg[n].start;
77  }
78  out.close();
79 
80  cout << endl << "out liveTime = " << liveTime << " (sec) " << liveTime/(24*3600.) << " (days) " << endl << endl;
81 
82  cout << "output file list : " << ofile << endl;
83 
84  exit(0);
85 }
char ofile[1024]
TTree * tree
Definition: TimeSortTree.C:20
double start
Definition: network.hh:55
Int_t nentries
Definition: TimeSortTree.C:24
int n
Definition: cwb_net.C:28
vector< waveSegment > oseg
TString("c")
ofstream out
Definition: cwb_merge.C:214
i drho i
static vector< waveSegment > unionSegments(vector< waveSegment > &ilist)
Definition: Toolbox.cc:119
const int NIFO_MAX
Definition: wat.hh:22
waveSegment seg
int index
Definition: network.hh:54
vector< waveSegment > iseg
void GetIfoSegments(TString liveFileName, int ifoID, TString ofile)
wavearray< int > index
double stop
Definition: network.hh:56
exit(0)