ATLAS Offline Software
EgammaTruthxAODHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "xAODEgamma/Egamma.h"
7 #include "xAODEgamma/Photon.h"
8 #include "xAODEgamma/Electron.h"
15 
18 
19 // ==================================================================
20 
28  recoElectronLinkAcc( "recoElectronLink" );
29 
30 const xAOD::Electron*
32 
33  if( ! recoElectronLinkAcc.isAvailable( *particle ) ) {
34  return nullptr;
35  }
37  recoElectronLinkAcc( *particle );
38  if( ! link.isValid() ) {
39  return nullptr;
40  }
41  return *link;
42 }
43 
51  recoPhotonLinkAcc( "recoPhotonLink" );
52 
53 const xAOD::Photon*
55 
56  if( ! recoPhotonLinkAcc.isAvailable( *particle ) ) {
57  return nullptr;
58  }
60  recoPhotonLinkAcc( *particle );
61  if( ! link.isValid() ) {
62  return nullptr;
63  }
64  return *link;
65 }
66 // ==================================================================
67 
68 //Is the object matched to a true converted photon with R < maxRadius
69 bool xAOD::EgammaHelpers::isTrueConvertedPhoton(const xAOD::Photon* ph, float maxRadius /* = 800. */){
71  if (!truthPh) {return false;}
72  // In older versions egammaTruthParticles did not have a decay vertex associated
73  // so we look for the original truth particle
74  if (truthPh->hasDecayVtx()){
75  return isTrueConvertedPhoton(truthPh, maxRadius);
76  }
77  const xAOD::TruthParticle *orgTruthPh = xAOD::TruthHelpers::getTruthParticle(*truthPh);
78  if (!orgTruthPh){ return false;}
79  return xAOD::EgammaHelpers::isTrueConvertedPhoton(orgTruthPh, maxRadius);
80 }
81 
82 //Is the true object a converted photon with R < maxRadius
83 bool xAOD::EgammaHelpers::isTrueConvertedPhoton(const xAOD::TruthParticle* truthPh, float maxRadius /*= 800.*/){
84  return (MC::isPhoton(truthPh) && truthPh->hasDecayVtx()
85  && truthPh->decayVtx()->perp() < maxRadius);
86 }
87 
88 //Lineage methods
89 std::vector<const xAOD::TruthParticle*>
91  const bool allTheWayBack/*=true*/) {
92  std::vector<const xAOD::TruthParticle*> vec;
93  //Truth must exist and be an electron
94  if (!truthel || !MC::isElectron(truthel)){
95  return vec;
96  }
97  vec.push_back(truthel); //push its self back as first entry
98 
99  // The first parent has to exist
100  if (!truthel->nParents()) {
101  return vec;
102  }
103 
104  if (!HepMC::is_simulation_particle(truthel) && !allTheWayBack) {
105  return vec;
106  }
107 
108  //And has to be a photon or electron
109  const xAOD::TruthParticle* parent = truthel->parent();
110  if ( !MC::isPhoton(parent) && !MC::isElectron(parent) ) {
111  return vec;
112  }
113 
114  vec.push_back(parent); //push in the parent as the second entry
115 
116  //Loop over the generations
117  while (parent->nParents() &&
118  (HepMC::is_simulation_particle(parent) || allTheWayBack)) {
119  //Find the next parent
120  const xAOD::TruthParticle* tmp = parent->parent();
121  //You want to see an electron or a photon
122  if (MC::isPhoton(tmp) || MC::isElectron(tmp)) {
123  parent=tmp;
124  } else { // if we do not see any more electron and photons we stop
125  break;
126  }
127  vec.push_back(parent); //push in the parent
128  }
129  return vec;
130 }
131 
132 const xAOD::TruthParticle*
134  const bool allTheWayBack/*=true*/){
135  const xAOD::TruthParticle *truthel =
137  return getBkgElectronMother(truthel,allTheWayBack);
138 }
139 
140 const xAOD::TruthParticle*
142  const bool allTheWayBack/*=true*/) {
143  std::vector<const xAOD::TruthParticle*> vec =
144  xAOD::EgammaHelpers::getBkgElectronLineage(truthel,allTheWayBack);
145  if (!vec.empty()) {
146  return vec.back();
147  }
148  return nullptr;
149 }
150 
151 std::vector<const xAOD::TruthParticle*>
153  const bool allTheWayBack/*=true*/) {
155  return getBkgElectronLineage(truthel,allTheWayBack);
156 }
xAOD::TruthParticle_v1::parent
const TruthParticle_v1 * parent(size_t i=0) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition: TruthParticle_v1.cxx:131
xAOD::EgammaHelpers::getRecoPhoton
const xAOD::Photon * getRecoPhoton(const xAOD::TruthParticle *particle)
return the reco photon associated to the given TruthParticle (if any)
Definition: EgammaTruthxAODHelpers.cxx:54
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
xAOD::EgammaHelpers::getBkgElectronLineage
std::vector< const xAOD::TruthParticle * > getBkgElectronLineage(const xAOD::TruthParticle *truthel, const bool allTheWayBack=true)
Helper function for getting the truth lineage of an electron that is arising from material interactio...
Definition: EgammaTruthxAODHelpers.cxx:90
TruthParticleContainer.h
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
xAODTruthHelpers.h
xAOD::EgammaHelpers::getBkgElectronMother
const xAOD::TruthParticle * getBkgElectronMother(const xAOD::Electron *el, const bool allTheWayBack=true)
Helper wrapper function for calling the function above extracting the truth from a reco electron.
Definition: EgammaTruthxAODHelpers.cxx:133
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
Egamma.h
xAOD::TruthParticle_v1::hasDecayVtx
bool hasDecayVtx() const
Check for a decay vertex on this particle.
xAOD::TruthParticle_v1::nParents
size_t nParents() const
Number of parents of this particle.
Definition: TruthParticle_v1.cxx:122
ElectronContainer.h
HepMC::is_simulation_particle
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
Definition: MagicNumbers.h:355
Photon.h
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAOD::TruthVertex_v1::perp
float perp() const
Vertex transverse distance from the beam line.
Definition: TruthVertex_v1.cxx:163
test_pyathena.parent
parent
Definition: test_pyathena.py:15
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
TruthVertex.h
xAOD::TruthParticle_v1::decayVtx
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
xAOD::EgammaHelpers::isTrueConvertedPhoton
bool isTrueConvertedPhoton(const xAOD::Photon *ph, float maxRadius=800.)
is the object matched to a true converted photon with R < maxRadius
Definition: EgammaTruthxAODHelpers.cxx:69
MagicNumbers.h
xAOD::TruthHelpers::getTruthParticle
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any)
Definition: xAODTruthHelpers.cxx:25
xAOD::EgammaHelpers::getRecoElectron
const xAOD::Electron * getRecoElectron(const xAOD::TruthParticle *)
return the reco electron associated to the given TruthParticle (if any)
Definition: EgammaTruthxAODHelpers.cxx:31
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
Electron.h
TruthParticle.h
PhotonContainer.h
EgammaTruthxAODHelpers.h
HepMCHelpers.h