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