Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
livetime.cc
Go to the documentation of this file.
1 #include "livetime.hh"
2 #include "TH2.h"
3 #include "TStyle.h"
4 #include "TCanvas.h"
5 
6 ClassImp(livetime) // used by THtml doc
7 
8 livetime& livetime::operator=(livetime& a)
9 {
10  this->fChain= NULL;
11  this->fCurrent= a.fCurrent;
12  this->run= a.run;
13  this->gps= a.gps;
14  this->live= a.live;
15  this->lag[NIFO_MAX+1]= a.lag[NIFO_MAX+1];
16  this->slag[NIFO_MAX+1]= a.slag[NIFO_MAX+1];
17  for(size_t n=0; n<(NIFO_MAX+1); n++) {
18  this->lag[n]= a.lag[n];
19  this->slag[n]= a.slag[n];
20  }
21  for(size_t n=0; n<NIFO_MAX; n++) {
22  this->start[n]= a.start[n];
23  this->stop[n]= a.stop[n];
24  }
25  return *this;
26 }
27 
28 // Set branch addresses
29 void livetime::Init(TTree *tree)
30 {
31  if (tree == 0) return;
32  fChain = tree;
33  fCurrent = -1;
34  fChain->SetMakeClass(1);
35 
36  fChain->SetBranchAddress("run",&(this->run));
37  fChain->SetBranchAddress("gps",&(this->gps));
38  fChain->SetBranchAddress("live",&(this->live));
39  fChain->SetBranchAddress("lag",(this->lag));
40  fChain->SetBranchAddress("slag",(this->slag));
41  fChain->SetBranchAddress("start",(this->start));
42  fChain->SetBranchAddress("stop",(this->stop));
43 
44  Notify();
45 }
46 
48 {
49  if (!lag) lag= (Float_t*)malloc((NIFO_MAX+1)*sizeof(Int_t));
50  else lag= (Float_t*)realloc(lag,(NIFO_MAX+1)*sizeof(Int_t));
51  if (!slag) slag= (Float_t*)malloc((NIFO_MAX+1)*sizeof(Int_t));
52  else slag= (Float_t*)realloc(slag,(NIFO_MAX+1)*sizeof(Int_t));
53  if (!start) start= (Double_t*)malloc((NIFO_MAX)*sizeof(Double_t));
54  else start= (Double_t*)realloc(start,(NIFO_MAX)*sizeof(Double_t));
55  if (!stop) stop= (Double_t*)malloc((NIFO_MAX)*sizeof(Double_t));
56  else stop= (Double_t*)realloc(start,(NIFO_MAX)*sizeof(Double_t));
57  return;
58 }
59 
60 //++++++++++++++++++++++++++++++++++++++++++++++
61 // set noise livetime tree
62 //++++++++++++++++++++++++++++++++++++++++++++++
64 {
65  TTree* waveTree = new TTree("liveTime","liveTime");
66 
67  //==================================
68  // Define livetime tree
69  //==================================
70 
71  char clag[16];sprintf(clag,"lag[%d]/F",NIFO_MAX+1);
72  char cslag[16];sprintf(cslag,"slag[%d]/F",NIFO_MAX+1);
73  char cstart[16];sprintf(cstart,"start[%d]/D",NIFO_MAX);
74  char cstop[16];sprintf(cstop,"stop[%d]/D",NIFO_MAX);
75 
76  waveTree->Branch("run", &(this->run), "run/I");
77  waveTree->Branch("gps", &(this->gps), "gps/D");
78  waveTree->Branch("live", &(this->live), "live/D");
79  waveTree->Branch("lag", (this->lag), clag);
80  waveTree->Branch("slag", (this->slag), cslag);
81  waveTree->Branch("start", (this->start), cstart);
82  waveTree->Branch("stop", (this->stop), cstop);
83 
84  return waveTree;
85 }
86 
87 
88 //++++++++++++++++++++++++++++++++++++++++++++++++++++
89 // dump livetime into tree
90 //++++++++++++++++++++++++++++++++++++++++++++++++++++
91 void livetime::output(TTree* waveTree, network* net, float* slag, vector<waveSegment> detSegs)
92 {
93  size_t n,m;
94  size_t M = net->ifoListSize();
95  if(!M) return;
96 
97  // add detectors to tree user info
98 // if(waveTree!=NULL) for(m=0;m<M;m++) waveTree->GetUserInfo()->Add(net->getifo(m));
99 
100 //Fill tree
101  for(m=0; m<(NIFO_MAX+1); m++) {
102  this->lag[m] = -1;
103  this->slag[m] = -1;
104  }
105  for(m=0; m<NIFO_MAX; m++) {
106  this->start[m] = 0;
107  this->stop[m] = 0;
108  }
109  for(m=0; m<detSegs.size(); m++) {
110  this->start[m] = detSegs[m].start;
111  this->stop[m] = detSegs[m].stop;
112  }
113  this->run = net->nRun;
114  this->gps = net->getifo(0)->getTFmap()->start();
115 
116  if(slag!=NULL) for(m=0; m<M+1; m++) this->slag[m] = slag[m];
117 
118  for(n=0; n<net->nLag; n++){ // loop on time lags
119 
120  this->live = net->getliveTime(n);
121 
122  for(m=0; m<NIFO_MAX; m++){ // loop on detectors
123  if(m<M) {
124  this->lag[m] = net->getifo(m)->lagShift.data[n];
125  }
126  }
127  this->lag[M] = net->getwc(n)->shift;
128  waveTree->Fill();
129  }
130 }
131 
132 
133 
135 {
136  // Called when loading a new file.
137  // Get branch pointers.
138  b_run = fChain->GetBranch("run");
139  b_gps = fChain->GetBranch("gps");
140  b_live = fChain->GetBranch("live");
141  b_lag = fChain->GetBranch("lag");
142  b_slag = fChain->GetBranch("slag");
143  b_start= fChain->GetBranch("start");
144  b_stop = fChain->GetBranch("stop");
145  return kTRUE;
146 }
147 
149 {
150  if (!fChain) return 0;
151  return fChain->GetEntry(entry);
152 };
153 
155 {
156 // Print contents of entry.
157 // If entry is not specified, print current entry
158  if (!fChain) return;
159  fChain->Show(entry);
160 }
161 
162 
163 /*
164 Int_t livetime::LoadTree(Int_t entry)
165 {
166 // Set the environment to read one entry
167  if (!fChain) return -5;
168  Int_t centry = fChain->LoadTree(entry);
169  if (centry < 0) return centry;
170  if (fChain->IsA() != TChain::Class()) return centry;
171  TChain *chain = (TChain*)fChain;
172  if (chain->GetTreeNumber() != fCurrent) {
173  fCurrent = chain->GetTreeNumber();
174  Notify();
175  }
176  return centry;
177 }
178 
179 Int_t livetime::Cut(Int_t entry)
180 {
181 // This function may be called from Loop.
182 // returns 1 if entry is accepted.
183 // returns -1 otherwise.
184  return 1;
185 }
186 
187 void livetime::Loop()
188 {
189 // In a ROOT session, you can do:
190 // Root > .L livetime.C
191 // Root > livetime t
192 // Root > t.GetEntry(12); // Fill t data members with entry number 12
193 // Root > t.Show(); // Show rmss of entry 12
194 // Root > t.Show(16); // Read and show values of entry 16
195 // Root > t.Loop(); // Loop on all entries
196 //
197 
198 // This is the loop skeleton where:
199 // jentry is the global entry number in the chain
200 // ientry is the entry number in the current Tree
201 // Note that the argument to GetEntry must be:
202 // jentry for TChain::GetEntry
203 // ientry for TTree::GetEntry and TBranch::GetEntry
204 //
205 // To read only selected branches, Insert statements like:
206 // METHOD1:
207 // fChain->SetBranchStatus("*",0); // disable all branches
208 // fChain->SetBranchStatus("branchname",1); // activate branchname
209 // METHOD2: replace line
210 // fChain->GetEntry(jentry); //read all branches
211 //by b_branchname->GetEntry(ientry); //read only this branch
212  if (fChain == 0) return;
213 
214  Int_t nentries = Int_t(fChain->GetEntriesFast());
215 
216  Int_t nbytes = 0, nb = 0;
217  for (Int_t jentry=0; jentry<nentries;jentry++) {
218  Int_t ientry = LoadTree(jentry);
219  if (ientry < 0) break;
220  nb = fChain->GetEntry(jentry); nbytes += nb;
221  // if (Cut(ientry) < 0) continue;
222  }
223 }
224 */
TTree * tree
Definition: TimeSortTree.C:20
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
void Init(TTree *)
Definition: livetime.cc:29
size_t nLag
Definition: network.hh:555
TString live
CWB run(runID)
wavearray< double > a(hp.size())
int n
Definition: cwb_net.C:10
TBranch * b_live
Definition: livetime.hh:42
Double_t * start
time slag [sec]
Definition: livetime.hh:35
size_t nRun
Definition: network.hh:554
double getliveTime(size_t n)
Definition: network.hh:410
Double_t gps
Definition: livetime.hh:31
TBranch * b_start
Definition: livetime.hh:45
#define M
Definition: UniqSLagsList.C:3
int m
Definition: cwb_net.C:10
virtual void start(double s)
Definition: wavearray.hh:119
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:413
Int_t fCurrent
pointer to the analyzed TTree or TChain
Definition: livetime.hh:25
Double_t live
Definition: livetime.hh:32
double shift
Definition: netcluster.hh:364
Int_t run
current Tree number in a TChain
Definition: livetime.hh:30
TTree * fChain
Definition: livetime.hh:24
TBranch * b_gps
Definition: livetime.hh:41
const int NIFO_MAX
Definition: wat.hh:4
Float_t * lag
Definition: livetime.hh:33
TBranch * b_lag
Definition: livetime.hh:43
void allocate()
Definition: livetime.cc:47
void output(TTree *waveTree, network *net, float *slag=NULL, vector< waveSegment > detSegs=DEFAULT_WAVESEGMENT)
Definition: livetime.cc:91
wavearray< double > lagShift
Definition: detector.hh:351
double * entry
Definition: cwb_setcuts.C:206
Int_t GetEntry(Int_t)
Definition: livetime.cc:148
vector< waveSegment > detSegs
Definition: cwb_net.C:175
Bool_t Notify()
Definition: livetime.cc:134
double gps
Double_t * stop
array of gps start time segment for each detector
Definition: livetime.hh:36
WSeries< double > * getTFmap()
param: no parameters
Definition: detector.hh:161
Definition: Toolbox.hh:81
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:421
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
DataType_t * data
Definition: wavearray.hh:301
TTree * setTree()
Definition: livetime.cc:63
void Show(Int_t entry=-1)
Definition: livetime.cc:154
TBranch * b_run
array of gps stop time segment for each detector
Definition: livetime.hh:40
TBranch * b_slag
Definition: livetime.hh:44
TBranch * b_stop
Definition: livetime.hh:46