ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
BaseTruthEval.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file BaseTruthEval.cc
1
#include "
BaseTruthEval.h
"
2
3
#include <
g4main/PHG4Hit.h
>
4
#include <
g4main/PHG4Particle.h
>
5
#include <
g4main/PHG4Shower.h
>
6
#include <
g4main/PHG4TruthInfoContainer.h
>
7
#include <
g4main/PHG4VtxPoint.h
>
8
9
#include <
phool/getClass.h
>
10
#include <
phool/phool.h
>
11
12
#include <cassert>
13
#include <cstdlib>
14
#include <iostream>
15
#include <utility>
16
17
using namespace
std;
18
19
BaseTruthEval::BaseTruthEval
(
PHCompositeNode
* topNode)
20
: m_TruthInfo(nullptr)
21
, m_Strict(
false
)
22
, m_Verbosity(0)
23
, m_Errors(0)
24
{
25
get_node_pointers
(topNode);
26
}
27
28
BaseTruthEval::~BaseTruthEval
()
29
{
30
if
(
m_Verbosity
> 0)
31
{
32
if
((
m_Errors
> 0) || (
m_Verbosity
> 1))
33
{
34
cout <<
"BaseTruthEval::~BaseTruthEval() - Error Count: "
<<
m_Errors
<< endl;
35
}
36
}
37
}
38
39
void
BaseTruthEval::next_event
(
PHCompositeNode
* topNode)
40
{
41
get_node_pointers
(topNode);
42
}
43
44
int
BaseTruthEval::get_embed
(
PHG4Particle
*
particle
)
45
{
46
if
(!
has_reduced_node_pointers
())
47
{
48
++
m_Errors
;
49
return
0;
50
}
51
52
if
(
m_Strict
)
53
{
54
assert(particle);
55
}
56
else
if
(!particle)
57
{
58
++
m_Errors
;
59
return
0;
60
}
61
62
// if (!is_primary(particle)) return 0;
63
// allow the secondary particles to be tagged with its embedding ID of tis primary particle
64
65
PHG4Particle
* primary =
get_primary_particle
(particle);
66
if
(
m_Strict
)
67
{
68
assert(primary);
69
}
70
else
if
(!primary)
71
{
72
++
m_Errors
;
73
return
0;
74
}
75
76
return
m_TruthInfo
->
isEmbeded
(primary->
get_track_id
());
77
}
78
79
PHG4VtxPoint
*
BaseTruthEval::get_vertex
(
PHG4Particle
*
particle
)
80
{
81
if
(!
has_reduced_node_pointers
())
82
{
83
++
m_Errors
;
84
return
nullptr
;
85
}
86
87
if
(
m_Strict
)
88
{
89
assert(particle);
90
}
91
else
if
(!particle)
92
{
93
++
m_Errors
;
94
return
nullptr
;
95
}
96
97
PHG4VtxPoint
* vtx =
m_TruthInfo
->
GetVtx
(particle->
get_vtx_id
());
98
if
(
m_Strict
)
99
{
100
assert(vtx);
101
}
102
else
if
(!vtx)
103
{
104
m_Errors
++;
105
}
106
107
return
vtx;
108
}
109
110
bool
BaseTruthEval::is_primary
(
PHG4Shower
* shower)
111
{
112
if
(!
has_reduced_node_pointers
())
113
{
114
++
m_Errors
;
115
return
false
;
116
}
117
118
if
(
m_Strict
)
119
{
120
assert(shower);
121
}
122
else
if
(!shower)
123
{
124
++
m_Errors
;
125
return
false
;
126
}
127
128
bool
is_primary
=
false
;
129
if
(shower->
get_parent_shower_id
() == 0)
130
{
131
is_primary =
true
;
132
}
133
134
return
is_primary
;
135
}
136
137
bool
BaseTruthEval::is_primary
(
PHG4Particle
*
particle
)
138
{
139
if
(!
has_reduced_node_pointers
())
140
{
141
++
m_Errors
;
142
return
false
;
143
}
144
145
if
(
m_Strict
)
146
{
147
assert(particle);
148
}
149
else
if
(!particle)
150
{
151
++
m_Errors
;
152
return
false
;
153
}
154
155
bool
is_primary
=
false
;
156
if
(particle->
get_parent_id
() == 0)
157
{
158
is_primary =
true
;
159
}
160
161
return
is_primary
;
162
}
163
164
PHG4Shower
*
BaseTruthEval::get_primary_shower
(
PHG4Shower
* shower)
165
{
166
if
(!
has_reduced_node_pointers
())
167
{
168
++
m_Errors
;
169
return
nullptr
;
170
}
171
172
if
(
m_Strict
)
173
{
174
assert(shower);
175
}
176
else
if
(!shower)
177
{
178
++
m_Errors
;
179
return
nullptr
;
180
}
181
182
if
(
is_primary
(shower))
return
shower;
183
184
while
(!
is_primary
(shower))
185
{
186
shower =
m_TruthInfo
->
GetShower
(shower->
get_parent_shower_id
());
187
188
if
(
m_Strict
)
189
{
190
assert(shower);
191
}
192
else
if
(!shower)
193
{
194
++
m_Errors
;
195
break
;
196
}
197
}
198
199
return
shower;
200
}
201
202
PHG4Shower
*
BaseTruthEval::get_primary_shower
(
PHG4Particle
*
particle
)
203
{
204
if
(!
has_reduced_node_pointers
())
205
{
206
++
m_Errors
;
207
return
nullptr
;
208
}
209
210
if
(
m_Strict
)
211
{
212
assert(particle);
213
}
214
else
if
(!particle)
215
{
216
++
m_Errors
;
217
return
nullptr
;
218
}
219
220
if
(!
is_primary
(particle)) particle =
get_primary_particle
(particle);
221
222
PHG4Shower
* returnval =
nullptr
;
223
224
PHG4TruthInfoContainer::ShowerRange
range =
m_TruthInfo
->
GetPrimaryShowerRange
();
225
for
(
PHG4TruthInfoContainer::ShowerIterator
iter = range.first;
226
iter != range.second;
227
++iter)
228
{
229
PHG4Shower
* shower = iter->second;
230
if
(shower->
get_parent_particle_id
() == particle->
get_track_id
())
231
{
232
returnval = shower;
233
break
;
234
}
235
}
236
237
return
returnval;
238
}
239
240
PHG4Particle
*
BaseTruthEval::get_primary_particle
(
PHG4Particle
*
particle
)
241
{
242
if
(!
has_reduced_node_pointers
())
243
{
244
++
m_Errors
;
245
return
nullptr
;
246
}
247
248
if
(
m_Strict
)
249
{
250
assert(particle);
251
}
252
else
if
(!particle)
253
{
254
++
m_Errors
;
255
return
nullptr
;
256
}
257
258
if
(
is_primary
(particle))
return
particle
;
259
260
PHG4Particle
* returnval =
m_TruthInfo
->
GetPrimaryParticle
(particle->
get_primary_id
());
261
262
if
(
m_Strict
)
263
{
264
assert(returnval);
265
}
266
else
if
(!returnval)
267
{
268
++
m_Errors
;
269
}
270
271
return
returnval;
272
}
273
274
PHG4Particle
*
BaseTruthEval::get_primary_particle
(
PHG4Shower
* shower)
275
{
276
if
(!
has_reduced_node_pointers
())
277
{
278
++
m_Errors
;
279
return
nullptr
;
280
}
281
282
if
(
m_Strict
)
283
{
284
assert(shower);
285
}
286
else
if
(!shower)
287
{
288
++
m_Errors
;
289
return
nullptr
;
290
}
291
292
PHG4Particle
* parent_particle =
m_TruthInfo
->
GetParticle
(shower->
get_parent_particle_id
());
293
294
if
(
m_Strict
)
295
{
296
assert(parent_particle);
297
}
298
else
if
(!parent_particle)
299
{
300
++
m_Errors
;
301
return
nullptr
;
302
}
303
304
PHG4Particle
* primary_particle =
get_primary_particle
(parent_particle);
305
306
if
(
m_Strict
)
307
{
308
assert(primary_particle);
309
}
310
else
if
(!primary_particle)
311
{
312
++
m_Errors
;
313
return
nullptr
;
314
}
315
316
return
primary_particle;
317
}
318
319
std::set<PHG4Shower*>
BaseTruthEval::all_secondary_showers
(
PHG4Shower
* shower)
320
{
321
if
(!
has_reduced_node_pointers
())
322
{
323
++
m_Errors
;
324
return
std::set<PHG4Shower*>();
325
}
326
327
if
(
m_Strict
)
328
{
329
assert(shower);
330
}
331
else
if
(!shower)
332
{
333
++
m_Errors
;
334
return
std::set<PHG4Shower*>();
335
}
336
337
std::set<PHG4Shower*> subshowers;
338
339
PHG4TruthInfoContainer::ShowerRange
range =
m_TruthInfo
->
GetSecondaryShowerRange
();
340
for
(
PHG4TruthInfoContainer::ShowerIterator
iter = range.first;
341
iter != range.second;
342
++iter)
343
{
344
PHG4Shower
* shower = iter->second;
345
346
if
(
m_Strict
)
347
{
348
assert(shower);
349
}
350
else
if
(!shower)
351
{
352
++
m_Errors
;
353
}
354
355
if
(shower)
356
{
357
if
(shower->
get_parent_shower_id
() == shower->
get_id
())
358
{
359
subshowers.insert(shower);
360
}
361
}
362
}
363
364
return
subshowers;
365
}
366
367
bool
BaseTruthEval::are_same_shower
(
PHG4Shower
*
s1
,
PHG4Shower
* s2)
368
{
369
if
(!
has_reduced_node_pointers
())
370
{
371
++
m_Errors
;
372
return
false
;
373
}
374
375
if
(
m_Strict
)
376
{
377
assert(s1);
378
assert(s2);
379
}
380
else
if
(!s1 || !s2)
381
{
382
++
m_Errors
;
383
return
false
;
384
}
385
386
if
(s1->
get_id
() == s2->
get_id
())
return
true
;
387
return
false
;
388
}
389
390
bool
BaseTruthEval::are_same_particle
(
PHG4Particle
* p1,
PHG4Particle
* p2)
391
{
392
if
(!
has_reduced_node_pointers
())
393
{
394
++
m_Errors
;
395
return
false
;
396
}
397
398
if
(
m_Strict
)
399
{
400
assert(p1);
401
assert(p2);
402
}
403
else
if
(!p1 || !p2)
404
{
405
++
m_Errors
;
406
return
false
;
407
}
408
409
if
(p1->
get_track_id
() == p2->
get_track_id
())
return
true
;
410
return
false
;
411
}
412
413
bool
BaseTruthEval::are_same_vertex
(
PHG4VtxPoint
* vtx1,
PHG4VtxPoint
* vtx2)
414
{
415
if
(!
has_reduced_node_pointers
())
416
{
417
++
m_Errors
;
418
return
false
;
419
}
420
421
if
(
m_Strict
)
422
{
423
assert(vtx1);
424
assert(vtx2);
425
}
426
else
if
(!vtx1 || !vtx2)
427
{
428
++
m_Errors
;
429
return
false
;
430
}
431
432
if
(vtx1->
get_id
() == vtx2->
get_id
())
return
true
;
433
return
false
;
434
}
435
436
PHG4Particle
*
BaseTruthEval::get_particle
(
PHG4Hit
* g4hit)
437
{
438
if
(!
has_reduced_node_pointers
())
439
{
440
++
m_Errors
;
441
return
nullptr
;
442
}
443
444
if
(
m_Strict
)
445
{
446
assert(g4hit);
447
}
448
else
if
(!g4hit)
449
{
450
++
m_Errors
;
451
return
nullptr
;
452
}
453
454
PHG4Particle
*
particle
=
m_TruthInfo
->
GetParticle
(g4hit->
get_trkid
());
455
if
(
m_Strict
)
456
{
457
assert(particle);
458
}
459
else
if
(!particle)
460
{
461
++
m_Errors
;
462
}
463
464
return
particle
;
465
}
466
467
PHG4Shower
*
BaseTruthEval::get_primary_shower
(
PHG4Hit
* g4hit)
468
{
469
if
(!
has_reduced_node_pointers
())
470
{
471
++
m_Errors
;
472
return
nullptr
;
473
}
474
475
if
(
m_Strict
)
476
{
477
assert(g4hit);
478
}
479
else
if
(!g4hit)
480
{
481
++
m_Errors
;
482
return
nullptr
;
483
}
484
485
PHG4Shower
* shower =
m_TruthInfo
->
GetShower
(g4hit->
get_shower_id
());
486
if
(
m_Strict
)
487
{
488
assert(shower);
489
}
490
else
if
(!shower)
491
{
492
++
m_Errors
;
493
}
494
495
return
shower;
496
}
497
498
PHG4Particle
*
BaseTruthEval::get_primary_particle
(
PHG4Hit
* g4hit)
499
{
500
if
(!
has_reduced_node_pointers
())
501
{
502
++
m_Errors
;
503
return
nullptr
;
504
}
505
506
if
(
m_Strict
)
507
{
508
assert(g4hit);
509
}
510
else
if
(!g4hit)
511
{
512
++
m_Errors
;
513
return
nullptr
;
514
}
515
516
PHG4Particle
*
particle
=
get_particle
(g4hit);
517
PHG4Particle
* primary =
get_primary_particle
(particle);
518
519
if
(
m_Strict
)
520
{
521
assert(primary);
522
}
523
else
if
(!primary)
524
{
525
++
m_Errors
;
526
}
527
528
return
primary;
529
}
530
531
PHG4Particle
*
BaseTruthEval::get_particle
(
const
int
trackid)
532
{
533
return
m_TruthInfo
->
GetParticle
(trackid);
534
}
535
536
bool
BaseTruthEval::is_g4hit_from_primary_shower
(
PHG4Hit
* g4hit,
PHG4Shower
* shower)
537
{
538
if
(!
has_reduced_node_pointers
())
539
{
540
++
m_Errors
;
541
return
false
;
542
}
543
544
if
(
m_Strict
)
545
{
546
assert(g4hit);
547
assert(shower);
548
}
549
else
if
(!g4hit || !shower)
550
{
551
++
m_Errors
;
552
return
false
;
553
}
554
555
if
(g4hit->
get_shower_id
() == shower->
get_id
())
556
{
557
return
true
;
558
}
559
560
return
false
;
561
}
562
563
bool
BaseTruthEval::is_g4hit_from_particle
(
PHG4Hit
* g4hit,
PHG4Particle
*
particle
)
564
{
565
if
(!
has_reduced_node_pointers
())
566
{
567
++
m_Errors
;
568
return
false
;
569
}
570
571
if
(
m_Strict
)
572
{
573
assert(g4hit);
574
assert(particle);
575
}
576
else
if
(!g4hit || !particle)
577
{
578
++
m_Errors
;
579
return
false
;
580
}
581
582
if
(g4hit->
get_trkid
() == particle->
get_track_id
())
583
{
584
return
true
;
585
}
586
587
return
false
;
588
}
589
590
void
BaseTruthEval::get_node_pointers
(
PHCompositeNode
* topNode)
591
{
592
m_TruthInfo
= findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo"
);
593
if
(!
m_TruthInfo
)
594
{
595
cerr <<
PHWHERE
<<
" ERROR: Can't find G4TruthInfo"
<< endl;
596
exit
(-1);
597
}
598
599
return
;
600
}
601
602
bool
BaseTruthEval::has_reduced_node_pointers
()
603
{
604
if
(
m_Strict
)
605
assert(
m_TruthInfo
);
606
else
if
(!
m_TruthInfo
)
607
return
false
;
608
609
return
true
;
610
}
coresoftware
blob
master
simulation
g4simulation
g4eval
BaseTruthEval.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:42
using
1.8.2 with
ECCE GitHub integration