-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathanalyzeHits.C
More file actions
399 lines (366 loc) · 9.89 KB
/
analyzeHits.C
File metadata and controls
399 lines (366 loc) · 9.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "ITSMFTSimulation/Hit.h"
#include "TOFSimulation/Detector.h"
#include "EMCALBase/Hit.h"
#include "DataFormatsTRD/Hit.h"
#include "FT0Simulation/Detector.h" // for Fit Hit
#include "DataFormatsFV0/Hit.h"
#include "HMPIDBase/Hit.h"
#include "TPCSimulation/Point.h"
#include "PHOSBase/Hit.h"
#include "DataFormatsFDD/Hit.h"
#include "MCHSimulation/Hit.h"
#include "MIDSimulation/Hit.h"
#include "DataFormatsCPV/Hit.h"
#include "DataFormatsZDC/Hit.h"
#include "DetectorsCommonDataFormats/DetectorNameConf.h"
#include "DataFormatsParameters/GRPObject.h"
#endif
TString gPrefix("");
template <typename Hit, typename Accumulator>
Accumulator analyse(TTree* tr, const char* brname)
{
Accumulator prop;
auto br = tr->GetBranch(brname);
if (!br) {
return prop;
}
auto entries = br->GetEntries();
std::vector<Hit>* hitvector = nullptr;
br->SetAddress(&hitvector);
for (int i = 0; i < entries; ++i) {
br->GetEntry(i);
for (auto& hit : *hitvector) {
prop.addHit(hit);
}
}
prop.normalize();
return prop;
};
struct HitStatsBase {
int NHits = 0;
double XAvg = 0.; // avg 1st moment
double YAvg = 0.;
double ZAvg = 0.;
double X2Avg = 0.; // avg 2nd moment
double Y2Avg = 0.;
double Z2Avg = 0.;
double EAvg = 0.; // average total energy
double E2Avg = 0.;
double TAvg = 0.; // average T
double T2Avg = 0.; // average T^2
void print() const
{
std::cout << NHits << " "
<< XAvg << " "
<< YAvg << " "
<< ZAvg << " "
<< X2Avg << " "
<< Y2Avg << " "
<< Z2Avg << " "
<< EAvg << " "
<< E2Avg << " "
<< TAvg << " "
<< T2Avg << "\n";
}
void normalize()
{
XAvg /= NHits;
YAvg /= NHits;
ZAvg /= NHits;
X2Avg /= NHits;
Y2Avg /= NHits;
Z2Avg /= NHits;
EAvg /= NHits;
E2Avg /= NHits;
TAvg /= NHits;
T2Avg /= NHits;
}
};
template <typename T>
struct HitStats : public HitStatsBase {
// adds a hit to the statistics
void addHit(T const& hit)
{
NHits++;
auto x = hit.GetX();
XAvg += x;
X2Avg += x * x;
auto y = hit.GetY();
YAvg += y;
Y2Avg += y * y;
auto z = hit.GetZ();
ZAvg += z;
Z2Avg += z * z;
auto e = hit.GetEnergyLoss();
EAvg += e;
E2Avg += e * e;
auto t = hit.GetTime();
TAvg += t;
T2Avg += t * t;
}
};
struct TRDHitStats : public HitStatsBase {
// adds a hit to the statistics
void addHit(o2::trd::Hit const& hit)
{
NHits++;
auto x = hit.GetX();
XAvg += x;
X2Avg += x * x;
auto y = hit.GetY();
YAvg += y;
Y2Avg += y * y;
auto z = hit.GetZ();
ZAvg += z;
Z2Avg += z * z;
auto e = hit.GetCharge();
EAvg += e;
E2Avg += e * e;
auto t = hit.GetTime();
TAvg += t;
T2Avg += t * t;
}
};
struct ITSHitStats : public HitStatsBase {
// adds a hit to the statistics
void addHit(o2::itsmft::Hit const& hit)
{
NHits++;
auto x = hit.GetStartX();
XAvg += x;
X2Avg += x * x;
auto y = hit.GetStartY();
YAvg += y;
Y2Avg += y * y;
auto z = hit.GetStartZ();
ZAvg += z;
Z2Avg += z * z;
auto e = hit.GetTotalEnergy();
EAvg += e;
E2Avg += e * e;
auto t = hit.GetTime();
TAvg += t;
T2Avg += t * t;
}
}; // end struct
struct TPCHitStats : public HitStatsBase {
// adds a hit to the statistics
void addHit(o2::tpc::HitGroup const& hitgroup)
{
for (int i = 0; i < hitgroup.getSize(); ++i) {
auto hit = hitgroup.getHit(i);
NHits++;
auto x = hit.GetX();
XAvg += x;
X2Avg += x * x;
auto y = hit.GetY();
YAvg += y;
Y2Avg += y * y;
auto z = hit.GetZ();
ZAvg += z;
Z2Avg += z * z;
auto e = hit.GetEnergyLoss();
EAvg += e;
E2Avg += e * e;
auto t = hit.GetTime();
TAvg += t;
T2Avg += t * t;
}
}
}; // end struct
// need a special version for TPC since loop over sectors
TPCHitStats analyseTPC(TTree* tr)
{
TPCHitStats prop;
for (int sector = 0; sector < 35; ++sector) {
std::stringstream brnamestr;
brnamestr << "TPCHitsShiftedSector" << sector;
auto br = tr->GetBranch(brnamestr.str().c_str());
if (!br) {
return prop;
}
auto entries = br->GetEntries();
std::vector<o2::tpc::HitGroup>* hitvector = nullptr;
br->SetAddress(&hitvector);
for (int i = 0; i < entries; ++i) {
br->GetEntry(i);
for (auto& hit : *hitvector) {
prop.addHit(hit);
}
}
}
prop.normalize();
return prop;
};
// do comparison for ITS
void analyzeITS(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::itsmft::Hit, ITSHitStats>(reftree, "ITSHit");
std::cout << gPrefix << " ITS ";
refresult.print();
}
// do comparison for TOF
void analyzeTOF(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::tof::HitType, HitStats<o2::tof::HitType>>(reftree, "TOFHit");
std::cout << gPrefix << " TOF ";
refresult.print();
}
// do comparison for EMC
void analyzeEMC(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::emcal::Hit, HitStats<o2::emcal::Hit>>(reftree, "EMCHit");
std::cout << gPrefix << " EMC ";
refresult.print();
}
// do comparison for TRD
// need a different version of TRDHitStats to retrieve the hit value
void analyzeTRD(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::trd::Hit, TRDHitStats>(reftree, "TRDHit");
std::cout << gPrefix << " TRD ";
refresult.print();
}
// do comparison for PHS
void analyzePHS(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::phos::Hit, HitStats<o2::phos::Hit>>(reftree, "PHSHit");
std::cout << gPrefix << " PHS ";
refresult.print();
}
void analyzeFT0(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::ft0::HitType, HitStats<o2::ft0::HitType>>(reftree, "FT0Hit");
std::cout << gPrefix << " FT0 ";
refresult.print();
}
void analyzeHMP(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::hmpid::HitType, HitStats<o2::hmpid::HitType>>(reftree, "HMPHit");
std::cout << gPrefix << " HMP ";
refresult.print();
}
void analyzeMFT(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::itsmft::Hit, ITSHitStats>(reftree, "MFTHit");
std::cout << gPrefix << " MFT ";
refresult.print();
}
void analyzeFDD(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::fdd::Hit, HitStats<o2::fdd::Hit>>(reftree, "FDDHit");
std::cout << gPrefix << " FDD ";
refresult.print();
}
void analyzeFV0(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::fv0::Hit, HitStats<o2::fv0::Hit>>(reftree, "FV0Hit");
std::cout << gPrefix << " FV0 ";
refresult.print();
}
void analyzeMCH(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::mch::Hit, HitStats<o2::mch::Hit>>(reftree, "MCHHit");
std::cout << gPrefix << " MCH ";
refresult.print();
}
void analyzeMID(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::mid::Hit, HitStats<o2::mid::Hit>>(reftree, "MIDHit");
std::cout << gPrefix << " MID ";
refresult.print();
}
void analyzeCPV(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::cpv::Hit, HitStats<o2::cpv::Hit>>(reftree, "CPVHit");
std::cout << gPrefix << " CPV ";
refresult.print();
}
void analyzeZDC(TTree* reftree)
{
if (!reftree)
return;
auto refresult = analyse<o2::zdc::Hit, HitStats<o2::zdc::Hit>>(reftree, "ZDCHit");
std::cout << gPrefix << " ZDC ";
refresult.print();
}
void analyzeTPC(TTree* reftree)
{
if (!reftree)
return;
// need to loop over sectors
auto refresult = analyseTPC(reftree);
std::cout << gPrefix << " TPC ";
refresult.print();
}
TTree* getHitTree(o2::parameters::GRPObject const* grp, const char* filebase, o2::detectors::DetID detid)
{
if (!grp->isDetReadOut(detid)) {
return nullptr;
}
std::string filename(o2::base::DetectorNameConf::getHitsFileName(detid, filebase).c_str());
// shamefully leaking memory as the TTree cannot live without the file...
TFile* file = new TFile(filename.c_str(), "OPEN");
auto t = (TTree*)file->Get("o2sim");
return t;
}
// Simple macro to get basic mean properties of simulated hits
// Used for instance to validate MC optimizations or to study
// the effect on the physics at the lowest level.
//
// A prefix (such as a parameter) can be given which will be prepended before each line of printout.
// This could be useful for plotting.
//
void analyzeHits(const char* filebase = "o2sim", const char* prefix = "")
{
gPrefix = prefix;
// READ GRP AND ITERATE OVER DETECTED PARTS
auto grp = o2::parameters::GRPObject::loadFrom(filebase);
// should correspond to the same number as defined in DetID
analyzeITS(getHitTree(grp, filebase, o2::detectors::DetID::ITS));
analyzeTPC(getHitTree(grp, filebase, o2::detectors::DetID::TPC));
analyzeMFT(getHitTree(grp, filebase, o2::detectors::DetID::MFT));
analyzeTOF(getHitTree(grp, filebase, o2::detectors::DetID::TOF));
analyzeEMC(getHitTree(grp, filebase, o2::detectors::DetID::EMC));
analyzeTRD(getHitTree(grp, filebase, o2::detectors::DetID::TRD));
analyzePHS(getHitTree(grp, filebase, o2::detectors::DetID::PHS));
analyzeCPV(getHitTree(grp, filebase, o2::detectors::DetID::CPV));
analyzeFT0(getHitTree(grp, filebase, o2::detectors::DetID::FT0));
analyzeFV0(getHitTree(grp, filebase, o2::detectors::DetID::FV0));
analyzeFDD(getHitTree(grp, filebase, o2::detectors::DetID::FDD));
analyzeHMP(getHitTree(grp, filebase, o2::detectors::DetID::HMP));
analyzeMCH(getHitTree(grp, filebase, o2::detectors::DetID::MCH));
analyzeMID(getHitTree(grp, filebase, o2::detectors::DetID::MID));
analyzeZDC(getHitTree(grp, filebase, o2::detectors::DetID::ZDC));
// analyzeACO(getHitTree(grp, filebase, o2::detectors::DetID::ACO));
}