ATLAS Offline Software
BkgElectronClassification.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
16  const std::string& n,
17  const IInterface* p)
18  : base_class(t, n, p)
19 {
20 
21 }
22 
25 {
26 
27  ATH_MSG_DEBUG("Initializing " << name() << "...");
28  ATH_CHECK(m_mcTruthClassifier.retrieve());
29  ATH_MSG_DEBUG("Retrieved tool " << m_mcTruthClassifier);
30 
33 
34  const std::string baseName = m_electronContainer.key();
35  m_truthPdgId = baseName + ".truthPdgId";
36  //
37  m_firstEgMotherTruthType = baseName + ".firstEgMotherTruthType";
38  m_firstEgMotherTruthOrigin = baseName + ".firstEgMotherTruthOrigin";
40  baseName + ".firstEgMotherTruthParticleLink";
41  m_firstEgMotherPdgId = baseName + ".firstEgMotherPdgId";
42  //
43  m_lastEgMotherTruthType = baseName + ".lastEgMotherTruthType";
44  m_lastEgMotherTruthOrigin = baseName + ".lastEgMotherTruthOrigin";
45  m_lastEgMotherTruthParticleLink = baseName + ".lastEgMotherTruthParticleLink";
46  m_lastEgMotherPdgId = baseName + ".lastEgMotherPdgId";
47 
49  //
54  //
59 
60  ATH_MSG_DEBUG("Initialization successful");
61 
62  return StatusCode::SUCCESS;
63 }
64 
67 {
68 
69  const EventContext& ctx = Gaudi::Hive::currentContext();
72  ctx };
73 
74  // Access for the already existing info
75  static const SG::AuxElement::Accessor<int> tT("truthType");
76  static const SG::AuxElement::Accessor<int> tO("truthOrigin");
77  static const SG::AuxElement::Accessor<
79  tPL("truthParticleLink");
80 
81  // pdg iD
83  // first mother decorations
92  firstEgMotherTPL(m_firstEgMotherTruthParticleLink, ctx);
93 
94  // last mother decorations
100  m_lastEgMotherPdgId, ctx);
103  lastEgMotherTPL(m_lastEgMotherTruthParticleLink, ctx);
104  //
105 
106  for (const xAOD::Electron* el : *electrons) {
107  tPdgID(*el) = 0;
108  if (tPL.isAvailable(*el) && tPL(*el).isValid()) {
109  tPdgID(*el) = (*tPL(*el))->pdgId();
110  }
111  // Use the Helpers for electron from electron or photon
112  // Add Extra Decoration from Egamma helpers in case of BkgElectron (Electron
113  // coming for a photon) Go back to the first/last electron/photon Generator
114  // mother and classify this one
115  // First the one entering the Geant, the first we meet on the way back
116  firstEgMotherTT(*el) = 0;
117  firstEgMotherTO(*el) = 0;
118  firstEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
119  firstEgMotherPdgID(*el) = 0;
120  const xAOD::TruthParticle* firstElTruth =
122 
123  MCTruthPartClassifier::Info mcinfo(ctx);
124  if (firstElTruth) {
125  auto res = m_mcTruthClassifier->particleTruthClassifier(firstElTruth, &mcinfo);
126  firstEgMotherTT(*el) = res.first;
127  firstEgMotherTO(*el) = res.second;
128  firstEgMotherPdgID(*el) = firstElTruth->pdgId();
130  firstElTruth, *truthContainer, ctx);
131  firstEgMotherTPL(*el) = link;
132  }
133 
134  // The last electron / photon we meet on the way back towards the Generator
135  // vertex
136  lastEgMotherTT(*el) = 0;
137  lastEgMotherTO(*el) = 0;
138  lastEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
139  lastEgMotherPdgID(*el) = 0;
140  const xAOD::TruthParticle* lastElTruth =
142 
143  if (lastElTruth) {
144  auto res = m_mcTruthClassifier->particleTruthClassifier(lastElTruth, &mcinfo);
145  lastEgMotherTT(*el) = res.first;
146  lastEgMotherTO(*el) = res.second;
147  lastEgMotherPdgID(*el) = lastElTruth->pdgId();
149  lastElTruth, *truthContainer, ctx);
150  lastEgMotherTPL(*el) = link;
151  }
152  }
153  return StatusCode::SUCCESS;
154 }
155 }
DerivationFramework::BkgElectronClassification::m_lastEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherPdgId
Definition: BkgElectronClassification.h:82
DerivationFramework::BkgElectronClassification::m_truthContainer
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthContainer
Input truth particle container.
Definition: BkgElectronClassification.h:50
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthType
Definition: BkgElectronClassification.h:62
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:64
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthOrigin
Definition: BkgElectronClassification.h:75
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthParticleLink
Definition: BkgElectronClassification.h:66
DerivationFramework::BkgElectronClassification::m_electronContainer
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronContainer
input electron container
Definition: BkgElectronClassification.h:43
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthType
Definition: BkgElectronClassification.h:73
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:71
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
IMCTruthClassifier.h
DerivationFramework::BkgElectronClassification::m_truthPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_truthPdgId
Definition: BkgElectronClassification.h:60
beamspotman.n
n
Definition: beamspotman.py:729
DerivationFramework::BkgElectronClassification::initialize
virtual StatusCode initialize() override final
Definition: BkgElectronClassification.cxx:24
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
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
DerivationFramework::BkgElectronClassification::addBranches
virtual StatusCode addBranches() const override final
Definition: BkgElectronClassification.cxx:66
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
DerivationFramework::BkgElectronClassification::BkgElectronClassification
BkgElectronClassification(const std::string &t, const std::string &n, const IInterface *p)
Definition: BkgElectronClassification.cxx:15
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:35
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthParticleLink
Definition: BkgElectronClassification.h:77
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