ATLAS Offline Software
Loading...
Searching...
No Matches
BkgElectronClassification.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "GaudiKernel/EventContext.h"
10#include "xAODEgamma/Electron.h"
14
15namespace DerivationFramework {
16
19{
20
21 ATH_MSG_DEBUG("Initializing " << name() << "...");
23 ATH_MSG_DEBUG("Retrieved tool " << m_mcTruthClassifier);
24
25 ATH_CHECK(m_electronContainer.initialize());
26 ATH_CHECK(m_truthContainer.initialize());
28 ATH_CHECK(m_truthPdgId.initialize());
29 //
34 ATH_CHECK(m_firstEgMotherPdgId.initialize());
35 //
40 ATH_CHECK(m_lastEgMotherPdgId.initialize());
41
42 ATH_MSG_DEBUG("Initialization successful");
43
44 return StatusCode::SUCCESS;
45}
46
47StatusCode
48BkgElectronClassification::addBranches(const EventContext& ctx) const
49{
50
53 ctx };
54
55 // Access for the pre-existing decoration
59
60 // pdg iD
62 // first mother decorations
73 firstEgMotherTPL(m_firstEgMotherTruthParticleLink, ctx);
74
75 // last mother decorations
86 lastEgMotherTPL(m_lastEgMotherTruthParticleLink, ctx);
87 //
88
89 for (const xAOD::Electron* el : *electrons) {
90 tPdgID(*el) = 0;
91 if (tPL.isPresent() && tPL(*el).isValid()) {
92 const xAOD::TruthParticle* truthEl = *tPL(*el);
93 tPdgID(*el) = truthEl->pdgId();
94 // Parents can be removed by truth thinning in e.g cases of Geant4 produced LRT electrons
95 // throw a warning in these cases so this is transparent
96 if (MC::isElectron(truthEl)) {
97 for (size_t p = 0; p < truthEl->nParents(); ++p) {
98 if (!truthEl->parent(p)) {
99 ATH_MSG_WARNING("Unresolvable truth parent link (ancestry removed by "
100 << "truth thinning) for truth electron with pt "
101 << truthEl->pt() << " MeV");
102 break;
103 }
104 }
105 }
106 }
107 // Use the Helpers for electron from electron or photon
108 // Add Extra Decoration from Egamma helpers in case of BkgElectron (Electron
109 // coming for a photon) Go back to the first/last electron/photon Generator
110 // mother and classify this one
111 // First the one entering the Geant4, the first we meet on the way back
112 firstEgMotherTT(*el) = 0;
113 firstEgMotherTO(*el) = 0;
114 firstEgMotherTC(*el) = 0;
115 firstEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
116 firstEgMotherPdgID(*el) = 0;
117 const xAOD::TruthParticle* firstElTruth =
119
120 if (firstElTruth) {
121 auto res = m_mcTruthClassifier->particleTruthClassifier(firstElTruth, ctx);
122 firstEgMotherTT(*el) = res.first;
123 firstEgMotherTO(*el) = res.second;
124 firstEgMotherTC(*el) = std::get<0>(MCTruthPartClassifier::defOrigOfParticle(firstElTruth)); // See AGENE-2351
125 firstEgMotherPdgID(*el) = firstElTruth->pdgId();
127 firstElTruth, *truthContainer, ctx);
128 firstEgMotherTPL(*el) = link;
129 }
130
131 // The last electron / photon we meet on the way back towards the Generator
132 // vertex
133 lastEgMotherTT(*el) = 0;
134 lastEgMotherTO(*el) = 0;
135 lastEgMotherTC(*el) = 0;
136 lastEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
137 lastEgMotherPdgID(*el) = 0;
138 const xAOD::TruthParticle* lastElTruth =
140
141 if (lastElTruth) {
142 auto res = m_mcTruthClassifier->particleTruthClassifier(lastElTruth, ctx);
143 lastEgMotherTT(*el) = res.first;
144 lastEgMotherTO(*el) = res.second;
145 lastEgMotherTC(*el) = std::get<0>(MCTruthPartClassifier::defOrigOfParticle(lastElTruth)); // See AGENE-2351
146 lastEgMotherPdgID(*el) = lastElTruth->pdgId();
148 lastElTruth, *truthContainer, ctx);
149 lastEgMotherTPL(*el) = link;
150 }
151 }
152 return StatusCode::SUCCESS;
153}
154}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
ATLAS-specific HepMC functions.
std::pair< std::vector< unsigned int >, bool > res
Handle class for reading a decoration on an object.
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthOrigin
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronContainer
input electron container
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_truthPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthParticleLink
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthContainer
Input truth particle container.
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthClassification
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherPdgId
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_electronTruthParticleLink
ToolHandle< IMCTruthClassifier > m_mcTruthClassifier
MCTruthClassifier.
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthClassification
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
int pdgId() const
PDG ID code.
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
size_t nParents() const
Number of parents of this particle.
THE reconstruction tool.
::StatusCode StatusCode
StatusCode definition for legacy code.
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
Classify a particle into a bit-word (see MCTC_bits).
bool isElectron(const T &p)
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.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
Electron_v1 Electron
Definition of the current "egamma version".
Definition Electron.h:17