ATLAS Offline Software
TruthBinding.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // this file contains all ITruthBinding inline methods
6 
7 namespace ISF {
8  /** constructor setting all truth particle pointers to the given particle */
9  TruthBinding::TruthBinding(HepMC::GenParticlePtr allTruthP) :
10  m_truthParticle(allTruthP),
11  m_primaryGenParticle(allTruthP),
12  m_generationZeroGenParticle(allTruthP) { }
13 
14  /** constructor setting all truth particle pointers individually */
15  TruthBinding::TruthBinding(HepMC::GenParticlePtr truthP, HepMC::GenParticlePtr primaryTruthP, HepMC::GenParticlePtr genZeroTruthP) :
16  m_truthParticle(truthP),
17  m_primaryGenParticle(primaryTruthP),
18  m_generationZeroGenParticle(genZeroTruthP) { }
19 
20  /** destructor */
21  TruthBinding::~TruthBinding() = default;
22 
23  /** comparison operator */
24  bool TruthBinding::operator==(const TruthBinding& rhs) const {
25  return isEqual(rhs);
26  }
27 
28  /** check equality */
29  bool TruthBinding::isEqual(const TruthBinding& rhs) const {
30  bool pass = true;
31 
32  const auto rhsTruth = rhs.getCurrentGenParticle();
33  if (m_truthParticle && rhsTruth) {
34 #ifdef HEPMC3
35  pass &= (m_truthParticle == rhsTruth);
36 #else
37  pass &= *m_truthParticle == *rhsTruth;
38 #endif
39  } else {
40  return false;
41  }
42 
43  const auto rhsPrimary = rhs.getPrimaryGenParticle();
44  if (m_primaryGenParticle && rhsPrimary) {
45 #ifdef HEPMC3
46  pass &= (m_primaryGenParticle == rhsPrimary);
47 #else
48  pass &= *m_primaryGenParticle == *rhsPrimary;
49 #endif
50  } else {
51  return false;
52  }
53 
54  const auto rhsGenZero = rhs.getGenerationZeroGenParticle();
55  if (m_generationZeroGenParticle && rhsGenZero) {
56 #ifdef HEPMC3
57  pass &= (m_generationZeroGenParticle == rhsGenZero);
58 #else
59  pass &= *m_generationZeroGenParticle == *rhsGenZero;
60 #endif
61  } else {
62  return false;
63  }
64 
65  return pass;
66  }
67 
68  /** check identity */
69  bool TruthBinding::isIdent(const TruthBinding& rhs) const {
70  bool pass = true;
71  pass &= m_truthParticle == rhs.getCurrentGenParticle();
72  pass &= m_primaryGenParticle == rhs.getPrimaryGenParticle();
73  pass &= m_generationZeroGenParticle == rhs.getGenerationZeroGenParticle();
74  return pass;
75  }
76 
77  /** pointer to the particle in the simulation truth */
78  HepMC::GenParticlePtr TruthBinding::getCurrentGenParticle() { return m_truthParticle; }
79  HepMC::ConstGenParticlePtr TruthBinding::getCurrentGenParticle() const { return m_truthParticle; }
80  void TruthBinding::setCurrentGenParticle(HepMC::GenParticlePtr p) { m_truthParticle = p; }
81 
82  /** pointer to the primary particle in the simulation truth */
83  HepMC::GenParticlePtr TruthBinding::getPrimaryGenParticle() { return m_primaryGenParticle; }
84  HepMC::ConstGenParticlePtr TruthBinding::getPrimaryGenParticle() const { return m_primaryGenParticle; }
85 
86  /** pointer to the simulation truth particle before any regeneration (eg. brem) */
87  HepMC::GenParticlePtr TruthBinding::getGenerationZeroGenParticle() { return m_generationZeroGenParticle; }
88  HepMC::ConstGenParticlePtr TruthBinding::getGenerationZeroGenParticle() const { return m_generationZeroGenParticle; }
89  void TruthBinding::setGenerationZeroGenParticle(HepMC::GenParticlePtr p) { m_generationZeroGenParticle = p; }
90 
91  /** Create a TruthBinding for a child particle */
92  // Not const: otherwise it can trigger a thread-safety checker warning
93  // because the non-const m_primaryTruthParticle escapes.
94  TruthBinding* TruthBinding::childTruthBinding(HepMC::GenParticlePtr childP) {
95  return new TruthBinding(childP, m_primaryGenParticle, childP);
96  }
97 
98 } // end ISF namespace