Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 = nullptr;
110  for (size_t p = 0; p < truthel->nParents(); ++p) {
111  if ( !MC::isPhoton(truthel->parent(p)) && !MC::isElectron(truthel->parent(p)) ) return vec;
112  parent = truthel->parent(p); //AV: note, here is an ambiguity for the case of multiple parents.
113  }
114 
115  if (!parent) return vec;
116  vec.push_back(parent); //push in the parent as the second entry
117 
118  //Loop over the generations
119  while (parent->nParents() &&
120  (HepMC::is_simulation_particle(parent) || allTheWayBack)) {
121  //Find the next parent
122  const xAOD::TruthParticle* tmp = nullptr;
123  //You want to see an electron or a photon
124  for (size_t p = 0; p < parent->nParents(); ++p) {
125  if (MC::isPhoton(parent->parent(p)) || MC::isElectron(parent->parent(p))) tmp = parent->parent(p); //AV: note some ambiguity for multiple parents passing the selection
126  }
127  if (tmp) {
128  parent = tmp;
129  } else { // if we do not see any more electron and photons we stop
130  break;
131  }
132  vec.push_back(parent); //push in the parent
133  }
134  return vec;
135 }
136 const xAOD::TruthParticle*
138  const bool allTheWayBack/*=true*/){
139  const xAOD::TruthParticle *truthel =
141  return getBkgElectronMother(truthel,allTheWayBack);
142 }
143 
144 const xAOD::TruthParticle*
146  const bool allTheWayBack/*=true*/) {
147  std::vector<const xAOD::TruthParticle*> vec =
148  xAOD::EgammaHelpers::getBkgElectronLineage(truthel,allTheWayBack);
149  if (!vec.empty()) {
150  return vec.back();
151  }
152  return nullptr;
153 }
154 
155 
156 std::vector<const xAOD::TruthParticle*>
158  const bool allTheWayBack/*=true*/) {
160  return getBkgElectronLineage(truthel,allTheWayBack);
161 }
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:9
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:137
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
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
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
xAOD::TruthParticle_v1::parent
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition: TruthParticle_v1.cxx:131
Electron.h
TruthParticle.h
PhotonContainer.h
EgammaTruthxAODHelpers.h
HepMCHelpers.h