ATLAS Offline Software
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"
9 #include "xAODEgamma/Electron.h"
12 
13 namespace DerivationFramework {
14 
17 {
18 
19  ATH_MSG_DEBUG("Initializing " << name() << "...");
20  ATH_CHECK(m_mcTruthClassifier.retrieve());
21  ATH_MSG_DEBUG("Retrieved tool " << m_mcTruthClassifier);
22 
25 
27  //
32  //
37 
38  ATH_MSG_DEBUG("Initialization successful");
39 
40  return StatusCode::SUCCESS;
41 }
42 
44 BkgElectronClassification::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
77  m_lastEgMotherPdgId, ctx);
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 }
DerivationFramework::BkgElectronClassification::m_lastEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherPdgId
Definition: BkgElectronClassification.h:80
DerivationFramework::BkgElectronClassification::m_truthContainer
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthContainer
Input truth particle container.
Definition: BkgElectronClassification.h:49
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthType
Definition: BkgElectronClassification.h:60
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthOrigin
Definition: BkgElectronClassification.h:62
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthOrigin
Definition: BkgElectronClassification.h:73
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthParticleLink
Definition: BkgElectronClassification.h:64
DerivationFramework::BkgElectronClassification::m_electronContainer
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronContainer
input electron container
Definition: BkgElectronClassification.h:42
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthType
Definition: BkgElectronClassification.h:71
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
DerivationFramework::BkgElectronClassification::m_firstEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherPdgId
Definition: BkgElectronClassification.h:69
IMCTruthClassifier.h
DerivationFramework::BkgElectronClassification::m_truthPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_truthPdgId
Definition: BkgElectronClassification.h:58
DerivationFramework::BkgElectronClassification::initialize
virtual StatusCode initialize() override final
Definition: BkgElectronClassification.cxx:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:11
DerivationFramework::BkgElectronClassification::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: BkgElectronClassification.cxx:44
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.getProblemFolderFromLogs.el
dictionary el
Definition: getProblemFolderFromLogs.py:54
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
MagicNumbers.h
runIDPVM.pdgId
pdgId
Definition: runIDPVM.py:91
xAOD::Electron_v1
Definition: Electron_v1.h:34
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
DerivationFramework::BkgElectronClassification::m_mcTruthClassifier
ToolHandle< IMCTruthClassifier > m_mcTruthClassifier
MCTruthClassifier.
Definition: BkgElectronClassification.h:34
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthParticleLink
Definition: BkgElectronClassification.h:75
BkgElectronClassification.h
Electron.h
TruthParticle.h
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
MCTruthPartClassifier::Info
Definition: IMCTruthClassifier.h:49
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
EgammaTruthxAODHelpers.h