Logo coherent WaveBurst  
Library Reference Guide
Logo
variability.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato, Sergey Klimenko
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 
20 #include "variability.hh"
21 #include "TH2.h"
22 #include "TStyle.h"
23 #include "TCanvas.h"
24 
25 ClassImp(variability) // used by THtml doc
26 
28 {
29  fChain= NULL;
30  fCurrent= a.fCurrent;
31  nevent= a.nevent;
32  ifo= a.ifo;
33  value= a.value;
34  time= a.time;
35  gps= a.gps;
36  return *this;
37 }
38 
39 // Set branch addresses
40 void variability::Init(TTree *tree)
41 {
42  if (tree == 0) return;
43  fChain = tree;
44  fCurrent = -1;
45  fChain->SetMakeClass(1);
46 
47  fChain->SetBranchAddress("nevent",&nevent);
48  fChain->SetBranchAddress("ifo",&ifo);
49  fChain->SetBranchAddress("value",&value);
50  fChain->SetBranchAddress("time",&time);
51  fChain->SetBranchAddress("gps",&gps);
52 
53  Notify();
54 }
55 
56 
57 //++++++++++++++++++++++++++++++++++++++++++++++
58 // set noise variability tree
59 //++++++++++++++++++++++++++++++++++++++++++++++
61 {
62  TTree* waveTree = new TTree("variability","variability");
63 
64  //==================================
65  // Define trigger tree
66  //==================================
67 
68  waveTree->Branch("nevent", &nevent, "nevent/I");
69  waveTree->Branch("ifo", &ifo, "ifo/I");
70  waveTree->Branch("value", &value, "value/F");
71  waveTree->Branch("time", &time, "time/D");
72  waveTree->Branch("gps", &gps, "gps/D");
73 
74  return waveTree;
75 }
76 
77 
78 //++++++++++++++++++++++++++++++++++++++++++++++++++++
79 // dump noise variability into tree
80 //++++++++++++++++++++++++++++++++++++++++++++++++++++
81 void variability::output(TTree* waveTree, wavearray<float>* p, int ifo_var, double t_var)
82 {
83  size_t i;
84  size_t n = p->size();
85  double rate_var = p->rate();
86  size_t m = size_t(t_var*rate_var+0.5); // time offset
87 
88  this->gps = p->start();
89 
90  if(m>n || !n) return;
91 
92 //Fill tree
93 
94  for(i=m; i<n-m; i++){
95  this->nevent= i;
96  this->ifo= ifo_var;
97  this->value= p->data[i];
98  this->time= this->gps + i/rate_var;
99  waveTree->Fill();
100  }
101 }
102 
103 
104 
106 {
107  // Called when loading a new file.
108  // Get branch pointers.
109  b_nevent = fChain->GetBranch("nevent");
110  b_ifo = fChain->GetBranch("ifo");
111  b_value = fChain->GetBranch("value");
112  b_time = fChain->GetBranch("time");
113  return kTRUE;
114 }
115 
117 {
118  if (!fChain) return 0;
119  return fChain->GetEntry(entry);
120 };
121 
123 {
124 // Print contents of entry.
125 // If entry is not specified, print current entry
126  if (!fChain) return;
127  fChain->Show(entry);
128 }
129 
130 /*
131 Int_t variability::LoadTree(Int_t entry)
132 {
133 // Set the environment to read one entry
134  if (!fChain) return -5;
135  Int_t centry = fChain->LoadTree(entry);
136  if (centry < 0) return centry;
137  if (fChain->IsA() != TChain::Class()) return centry;
138  TChain *chain = (TChain*)fChain;
139  if (chain->GetTreeNumber() != fCurrent) {
140  fCurrent = chain->GetTreeNumber();
141  Notify();
142  }
143  return centry;
144 }
145 
146 Int_t variability::Cut(Int_t entry)
147 {
148 // This function may be called from Loop.
149 // returns 1 if entry is accepted.
150 // returns -1 otherwise.
151  return 1;
152 }
153 
154 void variability::Loop()
155 {
156 // In a ROOT session, you can do:
157 // Root > .L variability.C
158 // Root > variability t
159 // Root > t.GetEntry(12); // Fill t data members with entry number 12
160 // Root > t.Show(); // Show values of entry 12
161 // Root > t.Show(16); // Read and show values of entry 16
162 // Root > t.Loop(); // Loop on all entries
163 //
164 
165 // This is the loop skeleton where:
166 // jentry is the global entry number in the chain
167 // ientry is the entry number in the current Tree
168 // Note that the argument to GetEntry must be:
169 // jentry for TChain::GetEntry
170 // ientry for TTree::GetEntry and TBranch::GetEntry
171 //
172 // To read only selected branches, Insert statements like:
173 // METHOD1:
174 // fChain->SetBranchStatus("*",0); // disable all branches
175 // fChain->SetBranchStatus("branchname",1); // activate branchname
176 // METHOD2: replace line
177 // fChain->GetEntry(jentry); //read all branches
178 //by b_branchname->GetEntry(ientry); //read only this branch
179  if (fChain == 0) return;
180 
181  Int_t nentries = Int_t(fChain->GetEntriesFast());
182 
183  Int_t nbytes = 0, nb = 0;
184  for (Int_t jentry=0; jentry<nentries;jentry++) {
185  Int_t ientry = LoadTree(jentry);
186  if (ientry < 0) break;
187  nb = fChain->GetEntry(jentry); nbytes += nb;
188  // if (Cut(ientry) < 0) continue;
189  }
190 }
191 */
192 
193 
194 
195 
196 
197 
198 
199 
TTree * tree
Definition: TimeSortTree.C:20
TTree * setTree()
Definition: variability.cc:60
par [0] value
virtual void rate(double r)
Definition: wavearray.hh:141
wavearray< double > a(hp.size())
int n
Definition: cwb_net.C:28
TBranch * b_ifo
Definition: variability.hh:53
TTree * fChain
Definition: variability.hh:38
int m
Definition: cwb_net.C:28
virtual void start(double s)
Definition: wavearray.hh:137
i drho i
TBranch * b_nevent
Definition: variability.hh:52
Double_t gps
Definition: variability.hh:48
char ifo[NIFO_MAX][8]
virtual size_t size() const
Definition: wavearray.hh:145
Int_t GetEntry(Int_t)
Definition: variability.cc:116
TBranch * b_value
Definition: variability.hh:54
Int_t fCurrent
pointer to the analyzed TTree or TChain
Definition: variability.hh:39
double * entry
Definition: cwb_setcuts.C:224
Int_t nevent
current Tree number in a TChain
Definition: variability.hh:44
void Show(Int_t entry=-1)
Definition: variability.cc:122
double gps
Double_t time
Definition: variability.hh:47
void Init(TTree *)
Definition: variability.cc:40
TBranch * b_time
Definition: variability.hh:55
Float_t value
Definition: variability.hh:46
DataType_t * data
Definition: wavearray.hh:319
void output(TTree *, wavearray< float > *, int=0, double=0.)
Definition: variability.cc:81
Bool_t Notify()
Definition: variability.cc:105