ATLAS Offline Software
Loading...
Searching...
No Matches
BkgElectronClassification.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "GaudiKernel/EventContext.h"
10#include "xAODEgamma/Electron.h"
13
14namespace DerivationFramework {
15
18{
19
20 ATH_MSG_DEBUG("Initializing " << name() << "...");
22 ATH_MSG_DEBUG("Retrieved tool " << m_mcTruthClassifier);
23
24 ATH_CHECK(m_electronContainer.initialize());
25 ATH_CHECK(m_truthContainer.initialize());
27 ATH_CHECK(m_truthPdgId.initialize());
28 //
33 ATH_CHECK(m_firstEgMotherPdgId.initialize());
34 //
39 ATH_CHECK(m_lastEgMotherPdgId.initialize());
40
41 ATH_MSG_DEBUG("Initialization successful");
42
43 return StatusCode::SUCCESS;
44}
45
46StatusCode
47BkgElectronClassification::addBranches(const EventContext& ctx) const
48{
49
52 ctx };
53
54 // Access for the pre-existing decoration
58
59 // pdg iD
61 // first mother decorations
72 firstEgMotherTPL(m_firstEgMotherTruthParticleLink, ctx);
73
74 // last mother decorations
85 lastEgMotherTPL(m_lastEgMotherTruthParticleLink, ctx);
86 //
87
88 for (const xAOD::Electron* el : *electrons) {
89 tPdgID(*el) = 0;
90 if (tPL.isPresent() && tPL(*el).isValid()) {
91 tPdgID(*el) = (*tPL(*el))->pdgId();
92 }
93 // Use the Helpers for electron from electron or photon
94 // Add Extra Decoration from Egamma helpers in case of BkgElectron (Electron
95 // coming for a photon) Go back to the first/last electron/photon Generator
96 // mother and classify this one
97 // First the one entering the Geant4, the first we meet on the way back
98 firstEgMotherTT(*el) = 0;
99 firstEgMotherTO(*el) = 0;
100 firstEgMotherTC(*el) = 0;
101 firstEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
102 firstEgMotherPdgID(*el) = 0;
103 const xAOD::TruthParticle* firstElTruth =
105
106 MCTruthPartClassifier::Info mcinfo(ctx);
107 if (firstElTruth) {
108 auto res = m_mcTruthClassifier->particleTruthClassifier(firstElTruth, &mcinfo);
109 firstEgMotherTT(*el) = res.first;
110 firstEgMotherTO(*el) = res.second;
111 firstEgMotherTC(*el) = std::get<0>(MCTruthPartClassifier::defOrigOfParticle(firstElTruth)); // See AGENE-2351
112 firstEgMotherPdgID(*el) = firstElTruth->pdgId();
114 firstElTruth, *truthContainer, ctx);
115 firstEgMotherTPL(*el) = link;
116 }
117
118 // The last electron / photon we meet on the way back towards the Generator
119 // vertex
120 lastEgMotherTT(*el) = 0;
121 lastEgMotherTO(*el) = 0;
122 lastEgMotherTC(*el) = 0;
123 lastEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
124 lastEgMotherPdgID(*el) = 0;
125 const xAOD::TruthParticle* lastElTruth =
127
128 if (lastElTruth) {
129 auto res = m_mcTruthClassifier->particleTruthClassifier(lastElTruth, &mcinfo);
130 lastEgMotherTT(*el) = res.first;
131 lastEgMotherTO(*el) = res.second;
132 lastEgMotherTC(*el) = std::get<0>(MCTruthPartClassifier::defOrigOfParticle(lastElTruth)); // See AGENE-2351
133 lastEgMotherPdgID(*el) = lastElTruth->pdgId();
135 lastElTruth, *truthContainer, ctx);
136 lastEgMotherTPL(*el) = link;
137 }
138 }
139 return StatusCode::SUCCESS;
140}
141}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
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.
THE reconstruction tool.
::StatusCode StatusCode
StatusCode definition for legacy code.
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
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".