ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkEGamma
src
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
5
#include "
DerivationFrameworkEGamma/BkgElectronClassification.h
"
6
#include "
StoreGate/ReadDecorHandle.h
"
7
#include "GaudiKernel/EventContext.h"
8
#include "
MCTruthClassifier/IMCTruthClassifier.h
"
9
#include "
xAODEgamma/EgammaTruthxAODHelpers.h
"
10
#include "
xAODEgamma/Electron.h
"
11
#include "
xAODTruth/TruthParticle.h
"
12
#include "
TruthUtils/MagicNumbers.h
"
13
14
namespace
DerivationFramework
{
15
16
StatusCode
17
BkgElectronClassification::initialize
()
18
{
19
20
ATH_MSG_DEBUG
(
"Initializing "
<< name() <<
"..."
);
21
ATH_CHECK
(
m_mcTruthClassifier
.retrieve());
22
ATH_MSG_DEBUG
(
"Retrieved tool "
<<
m_mcTruthClassifier
);
23
24
ATH_CHECK
(
m_electronContainer
.initialize());
25
ATH_CHECK
(
m_truthContainer
.initialize());
26
ATH_CHECK
(
m_electronTruthParticleLink
.initialize());
27
ATH_CHECK
(
m_truthPdgId
.initialize());
28
//
29
ATH_CHECK
(
m_firstEgMotherTruthType
.initialize());
30
ATH_CHECK
(
m_firstEgMotherTruthOrigin
.initialize());
31
ATH_CHECK
(
m_firstEgMotherTruthClassification
.initialize());
32
ATH_CHECK
(
m_firstEgMotherTruthParticleLink
.initialize());
33
ATH_CHECK
(
m_firstEgMotherPdgId
.initialize());
34
//
35
ATH_CHECK
(
m_lastEgMotherTruthType
.initialize());
36
ATH_CHECK
(
m_lastEgMotherTruthOrigin
.initialize());
37
ATH_CHECK
(
m_lastEgMotherTruthClassification
.initialize());
38
ATH_CHECK
(
m_lastEgMotherTruthParticleLink
.initialize());
39
ATH_CHECK
(
m_lastEgMotherPdgId
.initialize());
40
41
ATH_MSG_DEBUG
(
"Initialization successful"
);
42
43
return
StatusCode::SUCCESS;
44
}
45
46
StatusCode
47
BkgElectronClassification::addBranches
(
const
EventContext& ctx)
const
48
{
49
50
SG::ReadHandle<xAOD::ElectronContainer>
electrons{
m_electronContainer
, ctx };
51
SG::ReadHandle<xAOD::TruthParticleContainer>
truthContainer{
m_truthContainer
,
52
ctx };
53
54
// Access for the pre-existing decoration
55
SG::ReadDecorHandle
<
xAOD::ElectronContainer
,
56
ElementLink<xAOD::TruthParticleContainer>
>
57
tPL{
m_electronTruthParticleLink
, ctx };
58
59
// pdg iD
60
SG::WriteDecorHandle<xAOD::ElectronContainer, int>
tPdgID(
m_truthPdgId
, ctx);
61
// first mother decorations
62
SG::WriteDecorHandle<xAOD::ElectronContainer, int>
firstEgMotherTT(
63
m_firstEgMotherTruthType
, ctx);
64
SG::WriteDecorHandle<xAOD::ElectronContainer, int>
firstEgMotherTO(
65
m_firstEgMotherTruthOrigin
, ctx);
66
SG::WriteDecorHandle<xAOD::ElectronContainer, unsigned int>
firstEgMotherTC(
67
m_firstEgMotherTruthClassification
, ctx);
68
SG::WriteDecorHandle<xAOD::ElectronContainer, int>
firstEgMotherPdgID(
69
m_firstEgMotherPdgId
, ctx);
70
SG::WriteDecorHandle
<
xAOD::ElectronContainer
,
71
ElementLink<xAOD::TruthParticleContainer>
>
72
firstEgMotherTPL(
m_firstEgMotherTruthParticleLink
, ctx);
73
74
// last mother decorations
75
SG::WriteDecorHandle<xAOD::ElectronContainer, int>
lastEgMotherTT(
76
m_lastEgMotherTruthType
, ctx);
77
SG::WriteDecorHandle<xAOD::ElectronContainer, int>
lastEgMotherTO(
78
m_lastEgMotherTruthOrigin
, ctx);
79
SG::WriteDecorHandle<xAOD::ElectronContainer, unsigned int>
lastEgMotherTC(
80
m_lastEgMotherTruthClassification
, ctx);
81
SG::WriteDecorHandle<xAOD::ElectronContainer, int>
lastEgMotherPdgID(
82
m_lastEgMotherPdgId
, ctx);
83
SG::WriteDecorHandle
<
xAOD::ElectronContainer
,
84
ElementLink<xAOD::TruthParticleContainer>
>
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 =
104
xAOD::EgammaHelpers::getBkgElectronMother
(el,
false
);
105
106
if
(firstElTruth) {
107
auto
res
=
m_mcTruthClassifier
->particleTruthClassifier(firstElTruth, ctx);
108
firstEgMotherTT(*el) =
res
.first;
109
firstEgMotherTO(*el) =
res
.second;
110
firstEgMotherTC(*el) = std::get<0>(
MCTruthPartClassifier::defOrigOfParticle
(firstElTruth));
// See AGENE-2351
111
firstEgMotherPdgID(*el) = firstElTruth->
pdgId
();
112
ElementLink<xAOD::TruthParticleContainer>
link(
113
firstElTruth, *truthContainer, ctx);
114
firstEgMotherTPL(*el) = link;
115
}
116
117
// The last electron / photon we meet on the way back towards the Generator
118
// vertex
119
lastEgMotherTT(*el) = 0;
120
lastEgMotherTO(*el) = 0;
121
lastEgMotherTC(*el) = 0;
122
lastEgMotherTPL(*el) =
ElementLink<xAOD::TruthParticleContainer>
();
123
lastEgMotherPdgID(*el) = 0;
124
const
xAOD::TruthParticle
* lastElTruth =
125
xAOD::EgammaHelpers::getBkgElectronMother
(el);
126
127
if
(lastElTruth) {
128
auto
res
=
m_mcTruthClassifier
->particleTruthClassifier(lastElTruth, ctx);
129
lastEgMotherTT(*el) =
res
.first;
130
lastEgMotherTO(*el) =
res
.second;
131
lastEgMotherTC(*el) = std::get<0>(
MCTruthPartClassifier::defOrigOfParticle
(lastElTruth));
// See AGENE-2351
132
lastEgMotherPdgID(*el) = lastElTruth->
pdgId
();
133
ElementLink<xAOD::TruthParticleContainer>
link(
134
lastElTruth, *truthContainer, ctx);
135
lastEgMotherTPL(*el) = link;
136
}
137
}
138
return
StatusCode::SUCCESS;
139
}
140
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
BkgElectronClassification.h
EgammaTruthxAODHelpers.h
Electron.h
TruthParticle.h
IMCTruthClassifier.h
res
std::pair< std::vector< unsigned int >, bool > res
Definition
JetGroupProductTest.cxx:11
MagicNumbers.h
ReadDecorHandle.h
Handle class for reading a decoration on an object.
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthOrigin
Definition
BkgElectronClassification.h:80
DerivationFramework::BkgElectronClassification::m_electronContainer
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronContainer
input electron container
Definition
BkgElectronClassification.h:42
DerivationFramework::BkgElectronClassification::m_truthPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_truthPdgId
Definition
BkgElectronClassification.h:62
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthParticleLink
Definition
BkgElectronClassification.h:85
DerivationFramework::BkgElectronClassification::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition
BkgElectronClassification.cxx:47
DerivationFramework::BkgElectronClassification::m_truthContainer
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthContainer
Input truth particle container.
Definition
BkgElectronClassification.h:53
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthClassification
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthClassification
Definition
BkgElectronClassification.h:82
DerivationFramework::BkgElectronClassification::m_firstEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherPdgId
Definition
BkgElectronClassification.h:76
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthType
Definition
BkgElectronClassification.h:64
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthOrigin
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthOrigin
Definition
BkgElectronClassification.h:66
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthParticleLink
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthParticleLink
Definition
BkgElectronClassification.h:71
DerivationFramework::BkgElectronClassification::m_lastEgMotherTruthType
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherTruthType
Definition
BkgElectronClassification.h:78
DerivationFramework::BkgElectronClassification::m_lastEgMotherPdgId
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lastEgMotherPdgId
Definition
BkgElectronClassification.h:90
DerivationFramework::BkgElectronClassification::m_electronTruthParticleLink
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_electronTruthParticleLink
Definition
BkgElectronClassification.h:49
DerivationFramework::BkgElectronClassification::m_mcTruthClassifier
ToolHandle< IMCTruthClassifier > m_mcTruthClassifier
MCTruthClassifier.
Definition
BkgElectronClassification.h:34
DerivationFramework::BkgElectronClassification::initialize
virtual StatusCode initialize() override final
Definition
BkgElectronClassification.cxx:17
DerivationFramework::BkgElectronClassification::m_firstEgMotherTruthClassification
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_firstEgMotherTruthClassification
Definition
BkgElectronClassification.h:68
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition
StoreGate/StoreGate/ReadDecorHandle.h:94
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
DerivationFramework
THE reconstruction tool.
Definition
CascadeTools.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MCTruthPartClassifier::defOrigOfParticle
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
Definition
TruthClassifiers.h:149
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
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
Generated on
for ATLAS Offline Software by
1.17.0