Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
garana
garana
Accessors
TreeManager.cxx
Go to the documentation of this file.
1
/*
2
* TreeManager.cxx
3
*
4
* Created on: Feb 9, 2021
5
* Author: chilgenb
6
*/
7
8
#include "
garana/Accessors/TreeManager.h
"
9
#include <iostream>
10
11
using namespace
garana
;
12
using namespace
std
;
13
14
TreeManager::TreeManager
(
const
string
& infilename) :
//, bool onGen=1, bool onG4=1, bool onDet=0, bool onReco=1, bool onDis=0) :
15
fInFileName(infilename),
16
fOnGen(true),
17
fOnG4(true),
18
fOnDet(false),
19
fOnRec(true),
20
fOnDis(false)
21
{
22
23
//fInFileName = infilename;
24
Init
();
25
CheckEntries
();
26
27
}
28
29
void
TreeManager::Init
() {
30
31
//open file for reading
32
try
{
33
fInFile
=
new
TFile(
fInFileName
.c_str(),
"READ"
);
34
if
(!
fInFile
)
35
throw
fInFileName
;
36
}
37
catch
(
std::string
&
fname
){
38
std::cerr <<
"TreeManager::Init: unable to find the file, "
39
<<
fInFileName
<<
'\n'
;
40
}
41
42
// headerTree
43
TTree* header = (TTree*)
fInFile
->FindObjectAny(
"headerTree"
);
44
try
{
45
if
(!header)
46
throw
header;
47
}
48
catch
(TTree*
t
){
49
std::cerr <<
"TreeManager::Init: "
50
<<
"No HeaderTree found in input file, "
<<
fInFile
51
<<
'\n'
;
52
}
53
54
cout <<
"found header Tree"
<<
endl
;
55
56
fHeaderTree
=
new
HeaderTree
(header);
57
fTreeType
= *(
fHeaderTree
->
TreeType
());
58
59
/// genTree
60
TTree*
gen
=
nullptr
;
61
try
{
62
gen = (TTree*)
fInFile
->FindObjectAny(
genName
.c_str());
63
if
(!gen)
64
throw
gen
;
65
}
66
catch
(TTree* t){
67
std::cerr <<
"TreeManager::Init: "
68
<<
"No GenTree found in input file, "
<<
fInFile
69
<<
'\n'
;
70
}
71
72
if
(
fTreeType
==
"structured"
){
//structured tree
73
fStructGenTree
=
new
StructuredGenTree
(gen);
74
}
75
else
{
//flat tree
76
fFlatGenTree
=
new
FlatGenTree
(gen);
77
}
78
79
cout <<
"found genTree"
<<
endl
;
80
81
/// g4Tree ///
82
TTree*
g4
=
nullptr
;
83
try
{
84
g4 = (TTree*)
fInFile
->FindObjectAny(
g4Name
.c_str());
85
if
(!g4)
86
throw
g4
;
87
}
88
catch
(TTree* t){
89
std::cerr <<
"TreeManager::Init: "
90
<<
"No G4Tree found in input file, "
<<
fInFile
91
<<
'\n'
;
92
}
93
94
if
(
fTreeType
==
"structured"
){
//structured tree
95
fStructG4Tree
=
new
StructuredG4Tree
(g4);
96
}
97
else
{
//flat tree
98
fFlatG4Tree
=
new
FlatG4Tree
(g4);
99
}
100
cout <<
"found g4Tree"
<<
endl
;
101
102
/// recoTree ///
103
TTree*
reco
=
nullptr
;
104
try
{
105
reco = (TTree*)
fInFile
->FindObjectAny(
recoName
.c_str());
106
if
(!reco)
107
throw
reco;
108
}
109
catch
(TTree* t){
110
std::cerr <<
"TreeManager::Init: "
111
<<
"No RecoTree found in input file, "
<<
fInFile
112
<<
'\n'
;
113
}
114
115
if
(
fTreeType
==
"structured"
){
//structured tree
116
fStructRecoTree
=
new
StructuredRecoTree
(reco);
117
}
118
else
{
//flat tree
119
fFlatRecoTree
=
new
FlatRecoTree
(reco);
120
}
121
122
cout <<
"found recoTree"
<<
endl
;
123
124
cout <<
"at end of Init()"
<<
endl
;
125
126
}
// Init()
127
128
HeaderTree
*
TreeManager::GetHeaderTree
()
const
{
129
130
return
fHeaderTree
;
131
132
}
133
134
GenTree
*
TreeManager::GetGenTree
()
const
{
135
136
try
{
137
if
(!
fStructGenTree
&& !
fFlatGenTree
)
138
throw
fStructGenTree
;
139
if
(!
fStructGenTree
){
140
return
fFlatGenTree
;
141
}
142
else
{
143
return
fStructGenTree
;
144
}
145
}
146
catch
(
StructuredGenTree
*
e
){
147
std::cerr <<
"TreeManager::GenTree: no structured genTree or flat genTree found!"
<<
std::endl
;
148
}
149
150
return
nullptr
;
151
152
}
//GetGenTree()
153
154
G4Tree
*
TreeManager::GetG4Tree
()
const
{
155
156
try
{
157
if
(!
fStructG4Tree
&& !
fFlatG4Tree
)
158
throw
fStructG4Tree
;
159
if
(!
fStructG4Tree
){
160
return
fFlatG4Tree
;
161
}
162
else
{
163
return
fStructG4Tree
;
164
}
165
}
166
catch
(
StructuredGenTree
*
e
){
167
std::cerr <<
"TreeManager::G4Tree: no structured g4Tree or flat g4Tree found!"
<<
std::endl
;
168
}
169
170
return
nullptr
;
171
172
}
//GetGenTree()
173
174
DetTree
*
TreeManager::GetDetTree
()
const
{
175
176
try
{
177
if
(!
fStructDetTree
&& !
fFlatDetTree
)
178
throw
fStructDetTree
;
179
if
(!
fStructDetTree
){
180
return
fFlatDetTree
;
181
}
182
else
{
183
return
fStructDetTree
;
184
}
185
}
186
catch
(
StructuredDetTree
*
e
){
187
std::cerr <<
"TreeManager::DetTree: no structured detTree or flat detTree found!"
<<
std::endl
;
188
}
189
190
return
nullptr
;
191
192
}
//GetGenTree()
193
194
RecoTree
*
TreeManager::GetRecoTree
()
const
{
195
196
try
{
197
if
(!
fStructRecoTree
&& !
fFlatRecoTree
)
198
throw
fStructRecoTree
;
199
if
(!
fStructRecoTree
){
200
return
fFlatRecoTree
;
201
}
202
else
{
203
return
fStructRecoTree
;
204
}
205
}
206
catch
(
StructuredRecoTree
*
e
){
207
cerr <<
"TreeManager::RecoTree: no structured recoTree or flat recoTree found!"
<<
endl
;
208
}
209
210
return
nullptr
;
211
212
}
//GetGenTree()
213
214
DisplayTree
*
TreeManager::GetDisplayTree
()
const
{
215
216
try
{
217
if
(!
fStructDisplayTree
&& !
fFlatDisplayTree
)
218
throw
fStructDisplayTree
;
219
if
(!
fStructDisplayTree
){
220
return
fFlatDisplayTree
;
221
}
222
else
{
223
return
fStructDisplayTree
;
224
}
225
}
226
catch
(
StructuredDisplayTree
*
e
){
227
cerr <<
"TreeManager::DisplayTree: no structured displayTree or flat displayTree found!"
<<
endl
;
228
}
229
230
return
nullptr
;
231
232
}
//GetGenTree()
233
234
235
void
TreeManager::GetEntry
(
const
UInt_t& ientry){
236
237
if
(
fOnGen
) {
238
if
(
fStructGenTree
)
fStructGenTree
->
GetEntry
(ientry);
239
else
if
(
fFlatGenTree
)
fFlatGenTree
->
GetEntry
(ientry);
240
}
241
if
(
fOnG4
) {
242
if
(
fStructG4Tree
)
fStructG4Tree
->
GetEntry
(ientry);
243
else
if
(
fFlatG4Tree
)
fFlatG4Tree
->
GetEntry
(ientry);
244
}
245
if
(
fOnDet
) {
246
if
(
fStructDetTree
)
fStructDetTree
->
GetEntry
(ientry);
247
else
if
(
fFlatDetTree
)
fFlatDetTree
->
GetEntry
(ientry);
248
}
249
if
(
fOnRec
) {
250
if
(
fStructRecoTree
)
fStructRecoTree
->
GetEntry
(ientry);
251
else
if
(
fFlatRecoTree
)
fFlatRecoTree
->
GetEntry
(ientry);
252
}
253
254
// probably don't want to include display tree
255
}
256
257
bool
TreeManager::CheckEntries
() {
258
259
vector<UInt_t>
ns
;
260
if
(
fOnGen
) {
261
if
(
fStructGenTree
) ns.push_back(
fStructGenTree
->
NEntries
());
262
else
if
(
fFlatGenTree
) ns.push_back(
fFlatGenTree
->
NEntries
());
263
}
264
if
(
fOnG4
) {
265
if
(
fStructG4Tree
) ns.push_back(
fStructG4Tree
->
NEntries
());
266
else
if
(
fFlatG4Tree
) ns.push_back(
fFlatG4Tree
->
NEntries
());
267
}
268
if
(
fOnDet
) {
269
if
(
fStructDetTree
) ns.push_back(
fStructDetTree
->
NEntries
());
270
else
if
(
fFlatDetTree
) ns.push_back(
fFlatDetTree
->
NEntries
());
271
}
272
if
(
fOnRec
) {
273
if
(
fStructRecoTree
) ns.push_back(
fStructRecoTree
->
NEntries
());
274
else
if
(
fFlatRecoTree
) ns.push_back(
fFlatRecoTree
->
NEntries
());
275
}
276
277
try
{
278
for
(
size_t
i=1; i<ns.size(); i++){
279
if
(ns[0]!=ns[i])
280
throw
ns[0];
281
}
282
}
283
catch
(Int_t
n
){
284
cerr <<
"number of entries differs between trees!"
<<
endl
;
285
return
false
;
286
}
287
288
fNEntries
= ns[0];
289
return
true
;
290
}
garana::TreeManager::GetDisplayTree
DisplayTree * GetDisplayTree() const
Definition:
TreeManager.cxx:214
garana::TreeManager::fStructRecoTree
StructuredRecoTree * fStructRecoTree
Definition:
TreeManager.h:95
garana::TreeManager::fFlatGenTree
FlatGenTree * fFlatGenTree
Definition:
TreeManager.h:98
garana::DisplayTree
Definition:
DisplayTree.h:15
garana
Definition:
FlatDetTree.h:15
string
std::string string
Definition:
nybbler.cc:12
garana::StructuredDisplayTree
Definition:
StructuredDisplayTree.h:17
garana::FlatRecoTree
Definition:
FlatRecoTree.h:18
garana::TreeManager::fInFileName
string fInFileName
Definition:
TreeManager.h:79
std
STL namespace.
garana::TreeManager::fOnRec
bool fOnRec
Definition:
TreeManager.h:87
garana::StructuredGenTree
Definition:
StructuredGenTree.h:13
garana::TreeManager::fFlatDisplayTree
FlatDisplayTree * fFlatDisplayTree
Definition:
TreeManager.h:102
wirecell.sigproc.paper.noise.fname
fname
Definition:
noise.py:68
garana::RecoTree
Definition:
RecoTree.h:21
garana::G4Tree
Definition:
G4Tree.h:17
garana::TreeManager::TreeManager
TreeManager()
Definition:
TreeManager.h:42
garana::TreeManager::fNEntries
UInt_t fNEntries
Definition:
TreeManager.h:82
garana::DetTree
Definition:
DetTree.h:19
garana::TreeManager::fStructDisplayTree
StructuredDisplayTree * fStructDisplayTree
Definition:
TreeManager.h:96
garana::TreeManager::fStructGenTree
StructuredGenTree * fStructGenTree
Definition:
TreeManager.h:92
garana::TreeManager::fStructDetTree
StructuredDetTree * fStructDetTree
Definition:
TreeManager.h:94
e
const double e
Definition:
gUpMuFluxGen.cxx:165
garana::FlatG4Tree
Definition:
FlatG4Tree.h:19
garana::HeaderTree::TreeType
const std::string *const TreeType() const
Definition:
HeaderTree.cxx:32
cet::n
std::void_t< T > n
Definition:
metaprogramming.h:28
reco_momentum_tuples.t
t
Definition:
reco_momentum_tuples.py:25
garana::StructuredG4Tree
Definition:
StructuredG4Tree.h:18
garana::TreeManager::CheckEntries
bool CheckEntries()
Definition:
TreeManager.cxx:257
garana::FlatGenTree::GetEntry
void GetEntry(const UInt_t &ientry) override
Definition:
FlatGenTree.cxx:39
demo.gen
gen
Definition:
demo.py:24
garana::TreeManager::fTreeType
string fTreeType
Definition:
TreeManager.h:81
garana::TreeManager::fFlatG4Tree
FlatG4Tree * fFlatG4Tree
Definition:
TreeManager.h:99
garana::TreeManager::fFlatRecoTree
FlatRecoTree * fFlatRecoTree
Definition:
TreeManager.h:101
garana::TreeManager::fFlatDetTree
FlatDetTree * fFlatDetTree
Definition:
TreeManager.h:100
garana::TreeManager::fOnG4
bool fOnG4
Definition:
TreeManager.h:85
garana::TreeManager::Init
void Init()
Definition:
TreeManager.cxx:29
TreeManager.h
garana::StructuredDetTree
Definition:
StructuredDetTree.h:21
garana::TreeManager::fInFile
TFile * fInFile
Definition:
TreeManager.h:80
garana::TreeManager::GetHeaderTree
HeaderTree * GetHeaderTree() const
Definition:
TreeManager.cxx:128
garana::TreeManager::GetDetTree
DetTree * GetDetTree() const
Definition:
TreeManager.cxx:174
garana::TreeManager::fStructG4Tree
StructuredG4Tree * fStructG4Tree
Definition:
TreeManager.h:93
garana::FlatG4Tree::GetEntry
void GetEntry(const UInt_t &ientry) override
Definition:
FlatG4Tree.cxx:38
garana::TreeManager::GetG4Tree
G4Tree * GetG4Tree() const
Definition:
TreeManager.cxx:154
reco
garana::HeaderTree
Definition:
HeaderTree.h:16
garana::TreeManager::recoName
const string recoName
Definition:
TreeManager.h:71
garana::TreeManager::GetRecoTree
RecoTree * GetRecoTree() const
Definition:
TreeManager.cxx:194
garana::TreeManager::genName
const string genName
Definition:
TreeManager.h:68
garana::GenTree
Definition:
GenTree.h:8
garana::TreeManager::fHeaderTree
HeaderTree * fHeaderTree
Definition:
TreeManager.h:90
garana::TreeReader::GetEntry
virtual void GetEntry(const UInt_t &ientry)
Definition:
TreeReader.cxx:39
garana::TreeManager::fOnDet
bool fOnDet
Definition:
TreeManager.h:86
garana::TreeManager::GetGenTree
GenTree * GetGenTree() const
Definition:
TreeManager.cxx:134
garana::TreeManager::fOnGen
bool fOnGen
Definition:
TreeManager.h:84
garana::TreeManager::g4Name
const string g4Name
Definition:
TreeManager.h:69
ns
QAsciiDict< Entry > ns
Definition:
tclscanner.cpp:1147
garana::TreeManager::GetEntry
void GetEntry(const UInt_t &ientry)
Definition:
TreeManager.cxx:235
garana::FlatGenTree
Definition:
FlatGenTree.h:20
garana::TreeReader::NEntries
size_t NEntries() const
Definition:
TreeReader.cxx:35
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
garana::StructuredRecoTree
Definition:
StructuredRecoTree.h:18
tracks.g4
g4
Definition:
tracks.py:87
Generated by
1.8.11