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
6#include "GaudiKernel/EventContext.h"
12
13namespace DerivationFramework {
14
17{
18
19 ATH_MSG_DEBUG("Initializing " << name() << "...");
21 ATH_MSG_DEBUG("Retrieved tool " << m_mcTruthClassifier);
22
23 ATH_CHECK(m_electronContainer.initialize());
24 ATH_CHECK(m_truthContainer.initialize());
25
26 ATH_CHECK(m_truthPdgId.initialize());
27 //
31 ATH_CHECK(m_firstEgMotherPdgId.initialize());
32 //
36 ATH_CHECK(m_lastEgMotherPdgId.initialize());
37
38 ATH_MSG_DEBUG("Initialization successful");
39
40 return StatusCode::SUCCESS;
41}
42
43StatusCode
44BkgElectronClassification::addBranches(const EventContext& ctx) const
45{
46
49 ctx };
50
51 // Access for the already existing info
52 static const SG::AuxElement::Accessor<int> tT("truthType");
53 static const SG::AuxElement::Accessor<int> tO("truthOrigin");
54 static const SG::AuxElement::Accessor<
56 tPL("truthParticleLink");
57
58 // pdg iD
60 // first mother decorations
69 firstEgMotherTPL(m_firstEgMotherTruthParticleLink, ctx);
70
71 // last mother decorations
80 lastEgMotherTPL(m_lastEgMotherTruthParticleLink, ctx);
81 //
82
83 for (const xAOD::Electron* el : *electrons) {
84 tPdgID(*el) = 0;
85 if (tPL.isAvailable(*el) && tPL(*el).isValid()) {
86 tPdgID(*el) = (*tPL(*el))->pdgId();
87 }
88 // Use the Helpers for electron from electron or photon
89 // Add Extra Decoration from Egamma helpers in case of BkgElectron (Electron
90 // coming for a photon) Go back to the first/last electron/photon Generator
91 // mother and classify this one
92 // First the one entering the Geant, the first we meet on the way back
93 firstEgMotherTT(*el) = 0;
94 firstEgMotherTO(*el) = 0;
95 firstEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
96 firstEgMotherPdgID(*el) = 0;
97 const xAOD::TruthParticle* firstElTruth =
99
100 MCTruthPartClassifier::Info mcinfo(ctx);
101 if (firstElTruth) {
102 auto res = m_mcTruthClassifier->particleTruthClassifier(firstElTruth, &mcinfo);
103 firstEgMotherTT(*el) = res.first;
104 firstEgMotherTO(*el) = res.second;
105 firstEgMotherPdgID(*el) = firstElTruth->pdgId();
107 firstElTruth, *truthContainer, ctx);
108 firstEgMotherTPL(*el) = link;
109 }
110
111 // The last electron / photon we meet on the way back towards the Generator
112 // vertex
113 lastEgMotherTT(*el) = 0;
114 lastEgMotherTO(*el) = 0;
115 lastEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
116 lastEgMotherPdgID(*el) = 0;
117 const xAOD::TruthParticle* lastElTruth =
119
120 if (lastElTruth) {
121 auto res = m_mcTruthClassifier->particleTruthClassifier(lastElTruth, &mcinfo);
122 lastEgMotherTT(*el) = res.first;
123 lastEgMotherTO(*el) = res.second;
124 lastEgMotherPdgID(*el) = lastElTruth->pdgId();
126 lastElTruth, *truthContainer, ctx);
127 lastEgMotherTPL(*el) = link;
128 }
129 }
130 return StatusCode::SUCCESS;
131}
132}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
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_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
ToolHandle< IMCTruthClassifier > m_mcTruthClassifier
MCTruthClassifier.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
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.
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".