EIC Software
 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>
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 
20  : m_TruthInfo(nullptr)
21  , m_Strict(false)
22  , m_Verbosity(0)
23  , m_Errors(0)
24 {
25  get_node_pointers(topNode);
26 }
27 
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 
40 {
41  get_node_pointers(topNode);
42 }
43 
45 {
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 
80 {
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 
111 {
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 
138 {
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 
165 {
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 
203 {
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 
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 
241 {
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 
275 {
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 {
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 
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 
368 {
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 
391 {
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 
414 {
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 
437 {
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 
455  if (m_Strict)
456  {
457  assert(particle);
458  }
459  else if (!particle)
460  {
461  ++m_Errors;
462  }
463 
464  return particle;
465 }
466 
468 {
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 
499 {
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 
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 
532 {
533  return m_TruthInfo->GetParticle(trackid);
534 }
535 
537 {
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 
564 {
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 
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 
603 {
604  if (m_Strict)
605  assert(m_TruthInfo);
606  else if (!m_TruthInfo)
607  return false;
608 
609  return true;
610 }