forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTreeReader.h
More file actions
586 lines (540 loc) · 25.2 KB
/
TreeReader.h
File metadata and controls
586 lines (540 loc) · 25.2 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#pragma once
#include <array>
#include <string>
#include <vector>
#include <TCanvas.h>
#include <TEfficiency.h>
#include <TFile.h>
#include <TTree.h>
struct RecoTrackInfo {
double eta;
double pt;
unsigned int nMajorityHits;
unsigned int nMeasurements;
};
struct ParticleInfo {
ULong64_t particleId = 0;
double eta = 0;
double p = 0;
double pt = 0;
UShort_t nHits = 0;
};
namespace {
inline std::uint64_t hashBarcodeComponents(std::uint32_t vertexPrimary,
std::uint32_t vertexSecondary,
std::uint32_t particle,
std::uint32_t generation,
std::uint32_t subParticle) {
auto hashCombine = [](std::uint64_t seed, std::uint64_t value) {
constexpr std::uint64_t kMagic = 0x9e3779b97f4a7c15ull;
seed ^= value + kMagic + (seed << 6) + (seed >> 2);
return seed;
};
std::uint64_t hash = 0xcbf29ce484222325ull;
hash = hashCombine(hash, vertexPrimary);
hash = hashCombine(hash, vertexSecondary);
hash = hashCombine(hash, particle);
hash = hashCombine(hash, generation);
hash = hashCombine(hash, subParticle);
return hash;
}
} // namespace
/// Helper for reading tree
///
struct TreeReader {
// The constructor
explicit TreeReader(TTree* tree_) : tree(tree_) {}
// Get entry
void getEntry(unsigned int i) const {
if (entryNumbers.size() > i) {
tree->GetEntry(entryNumbers[i]);
} else {
tree->GetEntry(i);
}
};
// The tree being read
TTree* tree = nullptr;
protected:
/// The entry numbers for accessing events in increased order (there could be
/// multiple entries corresponding to one event number)
std::vector<long long> entryNumbers = {};
};
/// Struct used for reading track states written out by the
/// RootTrackStatesWriter
///
struct TrackStatesReader : public TreeReader {
// Delete the default constructor
TrackStatesReader() = delete;
// The constructor
TrackStatesReader(TTree* tree_, bool sortEvents) : TreeReader(tree_) {
tree->SetBranchAddress("event_nr", &eventId);
tree->SetBranchAddress("eLOC0_prt", &LOC0_prt);
tree->SetBranchAddress("eLOC1_prt", &LOC1_prt);
tree->SetBranchAddress("ePHI_prt", &PHI_prt);
tree->SetBranchAddress("eTHETA_prt", &THETA_prt);
tree->SetBranchAddress("eQOP_prt", &QOP_prt);
tree->SetBranchAddress("eT_prt", &T_prt);
tree->SetBranchAddress("eLOC0_flt", &LOC0_flt);
tree->SetBranchAddress("eLOC1_flt", &LOC1_flt);
tree->SetBranchAddress("ePHI_flt", &PHI_flt);
tree->SetBranchAddress("eTHETA_flt", &THETA_flt);
tree->SetBranchAddress("eQOP_flt", &QOP_flt);
tree->SetBranchAddress("eT_flt", &T_flt);
tree->SetBranchAddress("eLOC0_smt", &LOC0_smt);
tree->SetBranchAddress("eLOC1_smt", &LOC1_smt);
tree->SetBranchAddress("ePHI_smt", &PHI_smt);
tree->SetBranchAddress("eTHETA_smt", &THETA_smt);
tree->SetBranchAddress("eQOP_smt", &QOP_smt);
tree->SetBranchAddress("eT_smt", &T_smt);
tree->SetBranchAddress("res_eLOC0_prt", &res_LOC0_prt);
tree->SetBranchAddress("res_eLOC1_prt", &res_LOC1_prt);
tree->SetBranchAddress("res_ePHI_prt", &res_PHI_prt);
tree->SetBranchAddress("res_eTHETA_prt", &res_THETA_prt);
tree->SetBranchAddress("res_eQOP_prt", &res_QOP_prt);
tree->SetBranchAddress("res_eT_prt", &res_T_prt);
tree->SetBranchAddress("res_eLOC0_flt", &res_LOC0_flt);
tree->SetBranchAddress("res_eLOC1_flt", &res_LOC1_flt);
tree->SetBranchAddress("res_ePHI_flt", &res_PHI_flt);
tree->SetBranchAddress("res_eTHETA_flt", &res_THETA_flt);
tree->SetBranchAddress("res_eQOP_flt", &res_QOP_flt);
tree->SetBranchAddress("res_eT_flt", &res_T_flt);
tree->SetBranchAddress("res_eLOC0_smt", &res_LOC0_smt);
tree->SetBranchAddress("res_eLOC1_smt", &res_LOC1_smt);
tree->SetBranchAddress("res_ePHI_smt", &res_PHI_smt);
tree->SetBranchAddress("res_eTHETA_smt", &res_THETA_smt);
tree->SetBranchAddress("res_eQOP_smt", &res_QOP_smt);
tree->SetBranchAddress("res_eT_smt", &res_T_smt);
tree->SetBranchAddress("pull_eLOC0_prt", &pull_LOC0_prt);
tree->SetBranchAddress("pull_eLOC1_prt", &pull_LOC1_prt);
tree->SetBranchAddress("pull_ePHI_prt", &pull_PHI_prt);
tree->SetBranchAddress("pull_eTHETA_prt", &pull_THETA_prt);
tree->SetBranchAddress("pull_eQOP_prt", &pull_QOP_prt);
tree->SetBranchAddress("pull_eT_prt", &pull_T_prt);
tree->SetBranchAddress("pull_eLOC0_flt", &pull_LOC0_flt);
tree->SetBranchAddress("pull_eLOC1_flt", &pull_LOC1_flt);
tree->SetBranchAddress("pull_ePHI_flt", &pull_PHI_flt);
tree->SetBranchAddress("pull_eTHETA_flt", &pull_THETA_flt);
tree->SetBranchAddress("pull_eQOP_flt", &pull_QOP_flt);
tree->SetBranchAddress("pull_eT_flt", &pull_T_flt);
tree->SetBranchAddress("pull_eLOC0_smt", &pull_LOC0_smt);
tree->SetBranchAddress("pull_eLOC1_smt", &pull_LOC1_smt);
tree->SetBranchAddress("pull_ePHI_smt", &pull_PHI_smt);
tree->SetBranchAddress("pull_eTHETA_smt", &pull_THETA_smt);
tree->SetBranchAddress("pull_eQOP_smt", &pull_QOP_smt);
tree->SetBranchAddress("pull_eT_smt", &pull_T_smt);
tree->SetBranchAddress("g_x_prt", &g_x_prt);
tree->SetBranchAddress("g_y_prt", &g_y_prt);
tree->SetBranchAddress("g_z_prt", &g_z_prt);
tree->SetBranchAddress("g_x_flt", &g_x_flt);
tree->SetBranchAddress("g_y_flt", &g_y_flt);
tree->SetBranchAddress("g_z_flt", &g_z_flt);
tree->SetBranchAddress("g_x_smt", &g_x_smt);
tree->SetBranchAddress("g_y_smt", &g_y_smt);
tree->SetBranchAddress("g_z_smt", &g_z_smt);
tree->SetBranchAddress("nStates", &nStates);
tree->SetBranchAddress("nMeasurements", &nMeasurements);
tree->SetBranchAddress("volume_id", &volume_id);
tree->SetBranchAddress("layer_id", &layer_id);
tree->SetBranchAddress("module_id", &module_id);
tree->SetBranchAddress("predicted", &predicted);
tree->SetBranchAddress("filtered", &filtered);
tree->SetBranchAddress("smoothed", &smoothed);
// It's not necessary if you just need to read one file, but please do it to
// synchronize events if multiple root files are read
if (sortEvents) {
tree->SetEstimate(tree->GetEntries() + 1);
entryNumbers.resize(tree->GetEntries());
tree->Draw("event_nr", "", "goff");
// Sort to get the entry numbers of the ordered events
TMath::Sort(tree->GetEntries(), tree->GetV1(), entryNumbers.data(),
false);
}
}
// The variables
std::uint32_t eventId = 0;
std::vector<float>* LOC0_prt =
new std::vector<float>; ///< predicted parameter local x
std::vector<float>* LOC1_prt =
new std::vector<float>; ///< predicted parameter local y
std::vector<float>* PHI_prt =
new std::vector<float>; ///< predicted parameter phi
std::vector<float>* THETA_prt =
new std::vector<float>; ///< predicted parameter theta
std::vector<float>* QOP_prt =
new std::vector<float>; ///< predicted parameter q/p
std::vector<float>* T_prt =
new std::vector<float>; ///< predicted parameter t
std::vector<float>* LOC0_flt =
new std::vector<float>; ///< filtered parameter local x
std::vector<float>* LOC1_flt =
new std::vector<float>; ///< filtered parameter local y
std::vector<float>* PHI_flt =
new std::vector<float>; ///< filtered parameter phi
std::vector<float>* THETA_flt =
new std::vector<float>; ///< filtered parameter theta
std::vector<float>* QOP_flt =
new std::vector<float>; ///< filtered parameter q/p
std::vector<float>* T_flt = new std::vector<float>; ///< filtered parameter t
std::vector<float>* LOC0_smt =
new std::vector<float>; ///< smoothed parameter local x
std::vector<float>* LOC1_smt =
new std::vector<float>; ///< smoothed parameter local y
std::vector<float>* PHI_smt =
new std::vector<float>; ///< smoothed parameter phi
std::vector<float>* THETA_smt =
new std::vector<float>; ///< smoothed parameter theta
std::vector<float>* QOP_smt =
new std::vector<float>; ///< smoothed parameter q/p
std::vector<float>* T_smt = new std::vector<float>; ///< smoothed parameter t
std::vector<float>* res_LOC0_prt =
new std::vector<float>; ///< residual of predicted parameter local x
std::vector<float>* res_LOC1_prt =
new std::vector<float>; ///< residual of predicted parameter local y
std::vector<float>* res_PHI_prt =
new std::vector<float>; ///< residual of predicted parameter phi
std::vector<float>* res_THETA_prt =
new std::vector<float>; ///< residual of predicted parameter theta
std::vector<float>* res_QOP_prt =
new std::vector<float>; ///< residual of predicted parameter q/p
std::vector<float>* res_T_prt =
new std::vector<float>; ///< residual of predicted parameter t
std::vector<float>* res_LOC0_flt =
new std::vector<float>; ///< residual of filtered parameter local x
std::vector<float>* res_LOC1_flt =
new std::vector<float>; ///< residual of filtered parameter local y
std::vector<float>* res_PHI_flt =
new std::vector<float>; ///< residual of filtered parameter phi
std::vector<float>* res_THETA_flt =
new std::vector<float>; ///< residual of filtered parameter theta
std::vector<float>* res_QOP_flt =
new std::vector<float>; ///< residual of filtered parameter q/p
std::vector<float>* res_T_flt =
new std::vector<float>; ///< residual of filtered parameter t
std::vector<float>* res_LOC0_smt =
new std::vector<float>; ///< residual of smoothed parameter local x
std::vector<float>* res_LOC1_smt =
new std::vector<float>; ///< residual of smoothed parameter local y
std::vector<float>* res_PHI_smt =
new std::vector<float>; ///< residual of smoothed parameter phi
std::vector<float>* res_THETA_smt =
new std::vector<float>; ///< residual of smoothed parameter theta
std::vector<float>* res_QOP_smt =
new std::vector<float>; ///< residual of smoothed parameter q/p
std::vector<float>* res_T_smt =
new std::vector<float>; ///< residual of smoothed parameter t
std::vector<float>* pull_LOC0_prt =
new std::vector<float>; ///< pull of predicted parameter local x
std::vector<float>* pull_LOC1_prt =
new std::vector<float>; ///< pull of predicted parameter local y
std::vector<float>* pull_PHI_prt =
new std::vector<float>; ///< pull of predicted parameter phi
std::vector<float>* pull_THETA_prt =
new std::vector<float>; ///< pull of predicted parameter theta
std::vector<float>* pull_QOP_prt =
new std::vector<float>; ///< pull of predicted parameter q/p
std::vector<float>* pull_T_prt =
new std::vector<float>; ///< pull of predicted parameter t
std::vector<float>* pull_LOC0_flt =
new std::vector<float>; ///< pull of filtered parameter local x
std::vector<float>* pull_LOC1_flt =
new std::vector<float>; ///< pull of filtered parameter local y
std::vector<float>* pull_PHI_flt =
new std::vector<float>; ///< pull of filtered parameter phi
std::vector<float>* pull_THETA_flt =
new std::vector<float>; ///< pull of filtered parameter theta
std::vector<float>* pull_QOP_flt =
new std::vector<float>; ///< pull of filtered parameter q/p
std::vector<float>* pull_T_flt =
new std::vector<float>; ///< pull of filtered parameter t
std::vector<float>* pull_LOC0_smt =
new std::vector<float>; ///< pull of smoothed parameter local x
std::vector<float>* pull_LOC1_smt =
new std::vector<float>; ///< pull of smoothed parameter local y
std::vector<float>* pull_PHI_smt =
new std::vector<float>; ///< pull of smoothed parameter phi
std::vector<float>* pull_THETA_smt =
new std::vector<float>; ///< pull of smoothed parameter theta
std::vector<float>* pull_QOP_smt =
new std::vector<float>; ///< pull of smoothed parameter q/p
std::vector<float>* pull_T_smt =
new std::vector<float>; ///< pull of smoothed parameter t
std::vector<float>* g_x_prt = new std::vector<float>;
std::vector<float>* g_y_prt = new std::vector<float>;
std::vector<float>* g_z_prt = new std::vector<float>;
std::vector<float>* g_x_flt = new std::vector<float>;
std::vector<float>* g_y_flt = new std::vector<float>;
std::vector<float>* g_z_flt = new std::vector<float>;
std::vector<float>* g_x_smt = new std::vector<float>;
std::vector<float>* g_y_smt = new std::vector<float>;
std::vector<float>* g_z_smt = new std::vector<float>;
std::vector<int>* volume_id = new std::vector<int>; ///< volume_id
std::vector<int>* layer_id = new std::vector<int>; ///< layer_id
std::vector<int>* module_id = new std::vector<int>; ///< module_id
std::vector<bool>* predicted = new std::vector<bool>; ///< prediction status
std::vector<bool>* filtered = new std::vector<bool>; ///< filtering status
std::vector<bool>* smoothed = new std::vector<bool>; ///< smoothing status
unsigned int nStates = 0, nMeasurements = 0;
};
/// Struct used for reading track summary info written out by the
/// RootTrackSummaryWriter
///
struct TrackSummaryReader : public TreeReader {
// Delete the default constructor
TrackSummaryReader() = delete;
// The constructor
TrackSummaryReader(TTree* tree_, bool sortEvents) : TreeReader(tree_) {
tree->SetBranchAddress("event_nr", &eventId);
tree->SetBranchAddress("nStates", &nStates);
tree->SetBranchAddress("nMeasurements", &nMeasurements);
tree->SetBranchAddress("nOutliers", &nOutliers);
tree->SetBranchAddress("nHoles", &nHoles);
tree->SetBranchAddress("chi2Sum", &chi2Sum);
tree->SetBranchAddress("measurementChi2", &measurementChi2);
tree->SetBranchAddress("NDF", &NDF);
tree->SetBranchAddress("measurementVolume", &measurementVolume);
tree->SetBranchAddress("measurementLayer", &measurementLayer);
tree->SetBranchAddress("outlierVolume", &outlierVolume);
tree->SetBranchAddress("outlierLayer", &outlierLayer);
tree->SetBranchAddress("nMajorityHits", &nMajorityHits);
tree->SetBranchAddress("nSharedHits", &nSharedHits);
if (tree->GetBranch("majorityParticleId") != nullptr) {
majorityParticleId =
new std::vector<std::vector<std::uint32_t>>;
tree->SetBranchAddress("majorityParticleId", &majorityParticleId);
hasCombinedMajorityParticleId = true;
} else {
majorityParticleVertexPrimary = new std::vector<std::uint32_t>;
majorityParticleVertexSecondary = new std::vector<std::uint32_t>;
majorityParticleParticle = new std::vector<std::uint32_t>;
majorityParticleGeneration = new std::vector<std::uint32_t>;
majorityParticleSubParticle = new std::vector<std::uint32_t>;
tree->SetBranchAddress("majorityParticleId_vertex_primary",
&majorityParticleVertexPrimary);
tree->SetBranchAddress("majorityParticleId_vertex_secondary",
&majorityParticleVertexSecondary);
tree->SetBranchAddress("majorityParticleId_particle",
&majorityParticleParticle);
tree->SetBranchAddress("majorityParticleId_generation",
&majorityParticleGeneration);
tree->SetBranchAddress("majorityParticleId_sub_particle",
&majorityParticleSubParticle);
}
tree->SetBranchAddress("hasFittedParams", &hasFittedParams);
tree->SetBranchAddress("t_theta", &t_theta);
tree->SetBranchAddress("t_phi", &t_phi);
tree->SetBranchAddress("t_eta", &t_eta);
tree->SetBranchAddress("t_p", &t_p);
tree->SetBranchAddress("t_pT", &t_pT);
tree->SetBranchAddress("t_d0", &t_d0);
tree->SetBranchAddress("t_z0", &t_z0);
tree->SetBranchAddress("t_charge", &t_charge);
tree->SetBranchAddress("t_time", &t_time);
tree->SetBranchAddress("eLOC0_fit", &eLOC0_fit);
tree->SetBranchAddress("eLOC1_fit", &eLOC1_fit);
tree->SetBranchAddress("ePHI_fit", &ePHI_fit);
tree->SetBranchAddress("eTHETA_fit", &eTHETA_fit);
tree->SetBranchAddress("eQOP_fit", &eQOP_fit);
tree->SetBranchAddress("eT_fit", &eT_fit);
tree->SetBranchAddress("err_eLOC0_fit", &err_eLOC0_fit);
tree->SetBranchAddress("err_eLOC1_fit", &err_eLOC1_fit);
tree->SetBranchAddress("err_ePHI_fit", &err_ePHI_fit);
tree->SetBranchAddress("err_eTHETA_fit", &err_eTHETA_fit);
tree->SetBranchAddress("err_eQOP_fit", &err_eQOP_fit);
tree->SetBranchAddress("err_eT_fit", &err_eT_fit);
// It's not necessary if you just need to read one file, but please do it to
// synchronize events if multiple root files are read
if (sortEvents) {
tree->SetEstimate(tree->GetEntries() + 1);
entryNumbers.resize(tree->GetEntries());
tree->Draw("event_nr", "", "goff");
// Sort to get the entry numbers of the ordered events
TMath::Sort(tree->GetEntries(), tree->GetV1(), entryNumbers.data(),
false);
}
}
// The variables
std::uint32_t eventId = 0;
std::vector<unsigned int>* nStates = new std::vector<unsigned int>;
std::vector<unsigned int>* nMeasurements = new std::vector<unsigned int>;
std::vector<unsigned int>* nOutliers = new std::vector<unsigned int>;
std::vector<unsigned int>* nHoles = new std::vector<unsigned int>;
std::vector<unsigned int>* nSharedHits = new std::vector<unsigned int>;
std::vector<float>* chi2Sum = new std::vector<float>;
std::vector<unsigned int>* NDF = new std::vector<unsigned int>;
std::vector<std::vector<double>>* measurementChi2 =
new std::vector<std::vector<double>>;
std::vector<std::vector<double>>* outlierChi2 =
new std::vector<std::vector<double>>;
std::vector<std::vector<double>>* measurementVolume =
new std::vector<std::vector<double>>;
std::vector<std::vector<double>>* measurementLayer =
new std::vector<std::vector<double>>;
std::vector<std::vector<double>>* outlierVolume =
new std::vector<std::vector<double>>;
std::vector<std::vector<double>>* outlierLayer =
new std::vector<std::vector<double>>;
std::vector<unsigned int>* nMajorityHits = new std::vector<unsigned int>;
std::vector<std::vector<std::uint32_t>>* majorityParticleId = nullptr;
std::vector<std::uint32_t>* majorityParticleVertexPrimary = nullptr;
std::vector<std::uint32_t>* majorityParticleVertexSecondary = nullptr;
std::vector<std::uint32_t>* majorityParticleParticle = nullptr;
std::vector<std::uint32_t>* majorityParticleGeneration = nullptr;
std::vector<std::uint32_t>* majorityParticleSubParticle = nullptr;
bool hasCombinedMajorityParticleId = false;
std::uint64_t majorityParticleHash(std::size_t idx) const {
if (hasCombinedMajorityParticleId && majorityParticleId != nullptr) {
const auto& components = majorityParticleId->at(idx);
auto comp = [&](std::size_t i) -> std::uint32_t {
return (components.size() > i) ? components[i] : 0u;
};
return hashBarcodeComponents(comp(0), comp(1), comp(2), comp(3), comp(4));
}
auto safeAt = [](const std::vector<std::uint32_t>* vec, std::size_t i) {
return (vec != nullptr && vec->size() > i) ? vec->at(i) : 0u;
};
return hashBarcodeComponents(safeAt(majorityParticleVertexPrimary, idx),
safeAt(majorityParticleVertexSecondary, idx),
safeAt(majorityParticleParticle, idx),
safeAt(majorityParticleGeneration, idx),
safeAt(majorityParticleSubParticle, idx));
}
std::vector<bool>* hasFittedParams = new std::vector<bool>;
// True parameters
std::vector<float>* t_d0 = new std::vector<float>;
std::vector<float>* t_z0 = new std::vector<float>;
std::vector<float>* t_phi = new std::vector<float>;
std::vector<float>* t_theta = new std::vector<float>;
std::vector<float>* t_eta = new std::vector<float>;
std::vector<float>* t_p = new std::vector<float>;
std::vector<float>* t_pT = new std::vector<float>;
std::vector<float>* t_time = new std::vector<float>;
std::vector<int>* t_charge = new std::vector<int>;
// Estimated parameters
std::vector<float>* eLOC0_fit = new std::vector<float>;
std::vector<float>* eLOC1_fit = new std::vector<float>;
std::vector<float>* ePHI_fit = new std::vector<float>;
std::vector<float>* eTHETA_fit = new std::vector<float>;
std::vector<float>* eQOP_fit = new std::vector<float>;
std::vector<float>* eT_fit = new std::vector<float>;
std::vector<float>* err_eLOC0_fit = new std::vector<float>;
std::vector<float>* err_eLOC1_fit = new std::vector<float>;
std::vector<float>* err_ePHI_fit = new std::vector<float>;
std::vector<float>* err_eTHETA_fit = new std::vector<float>;
std::vector<float>* err_eQOP_fit = new std::vector<float>;
std::vector<float>* err_eT_fit = new std::vector<float>;
};
/// Struct used for reading particles written out by the
/// RootTrackFinderNTupleWriter
///
struct ParticleReader : public TreeReader {
// Delete the default constructor
ParticleReader() = delete;
// The constructor
ParticleReader(TTree* tree_, bool sortEvents) : TreeReader(tree_) {
tree->SetBranchAddress("event_id", &eventId);
if (tree->GetBranch("particle_id") != nullptr) {
combinedParticleId = new std::vector<std::uint32_t>;
tree->SetBranchAddress("particle_id", &combinedParticleId);
hasCombinedParticleId = true;
} else {
tree->SetBranchAddress("particle_id_vertex_primary",
&particleVertexPrimary);
tree->SetBranchAddress("particle_id_vertex_secondary",
&particleVertexSecondary);
tree->SetBranchAddress("particle_id_particle", &particleParticle);
tree->SetBranchAddress("particle_id_generation", &particleGeneration);
tree->SetBranchAddress("particle_id_sub_particle",
&particleSubParticle);
}
tree->SetBranchAddress("particle_type", &particleType);
tree->SetBranchAddress("vx", &vx);
tree->SetBranchAddress("vy", &vy);
tree->SetBranchAddress("vz", &vz);
tree->SetBranchAddress("vt", &vt);
tree->SetBranchAddress("px", &px);
tree->SetBranchAddress("py", &py);
tree->SetBranchAddress("pz", &pz);
tree->SetBranchAddress("m", &m);
tree->SetBranchAddress("q", &q);
tree->SetBranchAddress("nhits", &nHits);
tree->SetBranchAddress("ntracks", &nTracks);
tree->SetBranchAddress("ntracks_majority", &nTracksMajority);
// It's not necessary if you just need to read one file, but please do it to
// synchronize events if multiple root files are read
if (sortEvents) {
tree->SetEstimate(tree->GetEntries() + 1);
entryNumbers.resize(tree->GetEntries());
tree->Draw("event_id", "", "goff");
// Sort to get the entry numbers of the ordered events
TMath::Sort(tree->GetEntries(), tree->GetV1(), entryNumbers.data(),
false);
}
}
// Get all the particles with requested event id
std::vector<ParticleInfo> getParticles(
const std::uint32_t& eventNumber) const {
// Find the start entry and the batch size for this event
std::string eventNumberStr = std::to_string(eventNumber);
std::string findStartEntry = "event_id<" + eventNumberStr;
std::string findParticlesSize = "event_id==" + eventNumberStr;
std::size_t startEntry = tree->GetEntries(findStartEntry.c_str());
std::size_t nParticles = tree->GetEntries(findParticlesSize.c_str());
if (nParticles == 0) {
throw std::invalid_argument(
"No particles found. Please check the input file.");
}
std::vector<ParticleInfo> particles;
particles.reserve(nParticles);
for (unsigned int i = 0; i < nParticles; ++i) {
getEntry(startEntry + i);
auto pt = std::hypot(px, py);
auto p = std::hypot(pt, pz);
auto eta = std::atanh(pz / p * 1.);
std::uint32_t vp = particleVertexPrimary;
std::uint32_t vs = particleVertexSecondary;
std::uint32_t particle = particleParticle;
std::uint32_t generation = particleGeneration;
std::uint32_t subParticle = particleSubParticle;
if (hasCombinedParticleId && combinedParticleId != nullptr) {
auto comp = [&](std::size_t idx) -> std::uint32_t {
return (combinedParticleId->size() > idx) ? combinedParticleId->at(idx)
: 0u;
};
vp = comp(0);
vs = comp(1);
particle = comp(2);
generation = comp(3);
subParticle = comp(4);
}
const auto barcodeHash =
hashBarcodeComponents(vp, vs, particle, generation, subParticle);
particles.push_back({barcodeHash, eta, p, pt, nHits});
}
return particles;
}
// The variables
ULong64_t eventId = 0;
std::vector<std::uint32_t>* combinedParticleId = nullptr;
bool hasCombinedParticleId = false;
std::uint32_t particleVertexPrimary = 0;
std::uint32_t particleVertexSecondary = 0;
std::uint32_t particleParticle = 0;
std::uint32_t particleGeneration = 0;
std::uint32_t particleSubParticle = 0;
Int_t particleType = 0;
float vx = 0, vy = 0, vz = 0;
float vt = 0;
float px = 0, py = 0, pz = 0;
float m = 0;
float q = 0;
UShort_t nHits = 0;
UShort_t nTracks = 0;
UShort_t nTracksMajority = 0;
};