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  : AthAlgTool(t, n, p)
19 {
20 
21  declareInterface<DerivationFramework::IAugmentationTool>(this);
22 }
23 
26 {
27 
28  ATH_MSG_DEBUG("Initializing " << name() << "...");
29  ATH_CHECK(m_mcTruthClassifier.retrieve());
30  ATH_MSG_DEBUG("Retrieved tool " << m_mcTruthClassifier);
31 
34 
35  const std::string baseName = m_electronContainer.key();
36  m_truthPdgId = baseName + ".truthPdgId";
37  //
38  m_firstEgMotherTruthType = baseName + ".firstEgMotherTruthType";
39  m_firstEgMotherTruthOrigin = baseName + ".firstEgMotherTruthOrigin";
41  baseName + ".firstEgMotherTruthParticleLink";
42  m_firstEgMotherPdgId = baseName + ".firstEgMotherPdgId";
43  //
44  m_lastEgMotherTruthType = baseName + ".lastEgMotherTruthType";
45  m_lastEgMotherTruthOrigin = baseName + ".lastEgMotherTruthOrigin";
46  m_lastEgMotherTruthParticleLink = baseName + ".lastEgMotherTruthParticleLink";
47  m_lastEgMotherPdgId = baseName + ".lastEgMotherPdgId";
48 
50  //
55  //
60 
61  ATH_MSG_DEBUG("Initialization successful");
62 
63  return StatusCode::SUCCESS;
64 }
65 
68 {
69 
70  const EventContext& ctx = Gaudi::Hive::currentContext();
73  ctx };
74 
75  // Access for the already existing info
76  static const SG::AuxElement::Accessor<int> tT("truthType");
77  static const SG::AuxElement::Accessor<int> tO("truthOrigin");
78  static const SG::AuxElement::Accessor<
80  tPL("truthParticleLink");
81 
82  // pdg iD
84  // first mother decorations
93  firstEgMotherTPL(m_firstEgMotherTruthParticleLink, ctx);
94 
95  // last mother decorations
101  m_lastEgMotherPdgId, ctx);
104  lastEgMotherTPL(m_lastEgMotherTruthParticleLink, ctx);
105  //
106 
107  for (const xAOD::Electron* el : *electrons) {
108  tPdgID(*el) = 0;
109  if (tPL.isAvailable(*el) && tPL(*el).isValid()) {
110  tPdgID(*el) = (*tPL(*el))->pdgId();
111  }
112  // Use the Helpers for electron from electron or photon
113  // Add Extra Decoration from Egamma helpers in case of BkgElectron (Electron
114  // coming for a photon) Go back to the first/last electron/photon Generator
115  // mother and classify this one
116  // First the one entering the Geant, the first we meet on the way back
117  firstEgMotherTT(*el) = 0;
118  firstEgMotherTO(*el) = 0;
119  firstEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
120  firstEgMotherPdgID(*el) = 0;
121  const xAOD::TruthParticle* firstElTruth =
123 
124  MCTruthPartClassifier::Info mcinfo(ctx);
125  if (firstElTruth) {
126  auto res =
127  m_mcTruthClassifier->particleTruthClassifier(firstElTruth, &mcinfo);
128  firstEgMotherTT(*el) = res.first;
129  firstEgMotherTO(*el) = res.second;
130  firstEgMotherPdgID(*el) = firstElTruth->pdgId();
132  firstElTruth, *truthContainer, ctx);
133  firstEgMotherTPL(*el) = link;
134  }
135 
136  // The last electron / photon we meet on the way back towards the Generator
137  // vertex
138  lastEgMotherTT(*el) = 0;
139  lastEgMotherTO(*el) = 0;
140  lastEgMotherTPL(*el) = ElementLink<xAOD::TruthParticleContainer>();
141  lastEgMotherPdgID(*el) = 0;
142  const xAOD::TruthParticle* lastElTruth =
144 
145  if (lastElTruth) {
146  auto res =
147  m_mcTruthClassifier->particleTruthClassifier(lastElTruth, &mcinfo);
148  lastEgMotherTT(*el) = res.first;
149  lastEgMotherTO(*el) = res.second;
150  lastEgMotherPdgID(*el) = lastElTruth->pdgId();
152  lastElTruth, *truthContainer, ctx);
153  lastEgMotherTPL(*el) = link;
154  }
155  }
156  return StatusCode::SUCCESS;
157 }
158 }
DerivationFramework::BkgElectronClassification::m_lastEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherPdgId
Definition: BkgElectronClassification.h:84
DerivationFramework::BkgElectronClassification::m_truthContainer
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthContainer
Input truth particle container.
Definition: BkgElectronClassification.h:52
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthType
Definition: BkgElectronClassification.h:64
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthOrigin
Definition: BkgElectronClassification.h:66
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthOrigin
Definition: BkgElectronClassification.h:77
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthParticleLink
Definition: BkgElectronClassification.h:68
DerivationFramework::BkgElectronClassification::m_electronContainer
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronContainer
input electron container
Definition: BkgElectronClassification.h:45
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:75
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
xAOD::EgammaHelpers::getBkgElectronMother
const xAOD::TruthParticle * getBkgElectronMother(const xAOD::Electron *el, const bool allTheWayBack=true)
Helper wrapper function for calling the function below that accepts truth input.
Definition: EgammaTruthxAODHelpers.cxx:91
DerivationFramework::BkgElectronClassification::m_firstEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherPdgId
Definition: BkgElectronClassification.h:73
IMCTruthClassifier.h
DerivationFramework::BkgElectronClassification::m_truthPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_truthPdgId
Definition: BkgElectronClassification.h:62
beamspotman.n
n
Definition: beamspotman.py:731
DerivationFramework::BkgElectronClassification::initialize
virtual StatusCode initialize() override final
Definition: BkgElectronClassification.cxx:25
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:41
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
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
Pass the thinning service
Definition: BkgElectronClassification.cxx:67
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:192
MagicNumbers.h
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:37
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthParticleLink
Definition: BkgElectronClassification.h:79
BkgElectronClassification.h
Electron.h
AthAlgTool
Definition: AthAlgTool.h:26
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