ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
TruthParticleLevelAnalysisAlgorithms
Root
ParticleLevelIsolationAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
#include "
TruthParticleLevelAnalysisAlgorithms/ParticleLevelIsolationAlg.h
"
8
9
#include <
AsgDataHandles/ReadDecorHandle.h
>
10
#include <
AsgDataHandles/ReadHandle.h
>
11
#include <
AsgDataHandles/WriteDecorHandle.h
>
12
13
#include <algorithm>
14
#include <optional>
15
16
namespace
CP
{
17
18
StatusCode
ParticleLevelIsolationAlg::initialize
() {
19
20
ANA_CHECK
(
m_particlesKey
.initialize());
21
22
if
(
m_isolated
.value().empty()) {
23
ANA_MSG_ERROR
(
"isolation decoration name is empty!"
);
24
return
StatusCode::FAILURE;
25
}
26
if
(
m_notTauOrigin
.value().empty()) {
27
ANA_MSG_ERROR
(
"notTauOrigin decoration name is empty!"
);
28
return
StatusCode::FAILURE;
29
}
30
31
// decorators
32
if
(!
m_decIsolatedKey
.key().empty()) {
33
ANA_MSG_WARNING
(
"isolatedDecorKey is set internally and will be overwritten"
);
34
}
35
m_decIsolatedKey
=
m_particlesKey
.key() +
"."
+
m_isolated
.value();
36
ANA_CHECK
(
m_decIsolatedKey
.initialize());
37
if
(!
m_decNotTauOriginKey
.key().empty()) {
38
ANA_MSG_WARNING
(
"notTauOriginDecorKey is set internally and will be overwritten"
);
39
}
40
m_decNotTauOriginKey
=
m_particlesKey
.key() +
"."
+
m_notTauOrigin
.value();
41
ANA_CHECK
(
m_decNotTauOriginKey
.initialize());
42
43
// accessors
44
if
(!
m_isolationVariable
.value().empty()) {
45
if
(!
m_isoVarKey
.key().empty()) {
46
ANA_MSG_WARNING
(
"isoVarDecorKey is set internally and will be overwritten"
);
47
}
48
m_isoVarKey
=
m_particlesKey
.key() +
"."
+
m_isolationVariable
.value();
49
}
50
ANA_CHECK
(
m_isoVarKey
.initialize(!
m_isolationVariable
.value().empty()));
51
52
ANA_CHECK
(
m_classifierTypeKey
.initialize());
53
ANA_CHECK
(
m_classifierOriginKey
.initialize());
54
55
// set up MCTruthClassifier comparisons
56
MCTruthPartClassifier::ParticleDef
partDef;
57
const
auto
it =
58
std::ranges::find(partDef.
sParticleType
,
m_checkTypeName
.value());
59
if
(it == partDef.
sParticleType
.end()) {
60
ANA_MSG_ERROR
(
61
"checkType = "
62
<<
m_checkTypeName
.value()
63
<<
" is not a valid MCTruthPartClassifier::ParticleType string!"
);
64
return
StatusCode::FAILURE;
65
}
else
{
66
m_checkType
=
static_cast<
MCTruthPartClassifier::ParticleType
>
(
67
std::distance(partDef.
sParticleType
.begin(), it));
68
}
69
70
return
StatusCode::SUCCESS;
71
}
72
73
StatusCode
ParticleLevelIsolationAlg::execute
(
const
EventContext &ctx)
const
{
74
75
SG::ReadHandle<xAOD::TruthParticleContainer>
particles(
m_particlesKey
, ctx);
76
77
// accessors
78
SG::ReadDecorHandle<xAOD::TruthParticleContainer, unsigned int>
acc_type(
79
m_classifierTypeKey
, ctx);
80
SG::ReadDecorHandle<xAOD::TruthParticleContainer, unsigned int>
acc_orig(
81
m_classifierOriginKey
, ctx);
82
std::optional<SG::ReadDecorHandle<xAOD::TruthParticleContainer, float>>
83
acc_isoVar;
84
if
(!
m_isoVarKey
.empty())
85
acc_isoVar.emplace(
m_isoVarKey
, ctx);
86
87
// decoration availability is a property of the whole container
88
const
bool
hasType = acc_type.
isAvailable
();
89
const
bool
hasOrig = acc_orig.
isAvailable
();
90
const
bool
hasIsoVar = acc_isoVar && acc_isoVar->isAvailable();
91
92
// decorators
93
SG::WriteDecorHandle<xAOD::TruthParticleContainer, char>
dec_isolated(
94
m_decIsolatedKey
, ctx);
95
SG::WriteDecorHandle<xAOD::TruthParticleContainer, char>
dec_notTauOrigin(
96
m_decNotTauOriginKey
, ctx);
97
98
for
(
const
auto
* particle : *particles) {
99
100
// check the particle is isolated
101
if
(hasType) {
102
bool
isolation = acc_type(*particle) ==
m_checkType
;
103
// check further custom isolation cuts
104
if
(acc_isoVar && isolation) {
105
if
(hasIsoVar) {
106
// treat particles without a valid pT as not isolated
107
isolation = particle->pt() > 0 &&
108
(*acc_isoVar)(*particle) / particle->pt() <
109
m_isolationCut
.value();
110
}
else
{
111
ANA_MSG_ERROR
(
"Truth particle is missing the decoration: "
112
<<
m_isolationVariable
.value() <<
"."
);
113
return
StatusCode::FAILURE;
114
}
115
}
116
dec_isolated(*particle) = isolation;
117
}
else
{
118
ANA_MSG_ERROR
(
119
"Truth particle is missing the decoration: classifierParticleType."
);
120
return
StatusCode::FAILURE;
121
}
122
123
// check the particle doesn't come from a tau decay
124
if
(hasOrig) {
125
dec_notTauOrigin(*particle) =
126
acc_orig(*particle) !=
MCTruthPartClassifier::ParticleOrigin::TauLep
;
127
}
else
{
128
ANA_MSG_ERROR
(
129
"Truth particle is missing the decoration: "
130
"classifierParticleOrigin."
);
131
return
StatusCode::FAILURE;
132
}
133
}
134
return
StatusCode::SUCCESS;
135
}
136
137
}
// namespace CP
ReadDecorHandle.h
Handle class for reading a decoration on an object.
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:295
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:325
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg,...)
Macro printing warning messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:293
ParticleLevelIsolationAlg.h
CP::ParticleLevelIsolationAlg::m_particlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
Definition
ParticleLevelIsolationAlg.h:29
CP::ParticleLevelIsolationAlg::m_checkType
MCTruthPartClassifier::ParticleType m_checkType
Definition
ParticleLevelIsolationAlg.h:45
CP::ParticleLevelIsolationAlg::m_decNotTauOriginKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_decNotTauOriginKey
Definition
ParticleLevelIsolationAlg.h:48
CP::ParticleLevelIsolationAlg::m_classifierOriginKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_classifierOriginKey
Definition
ParticleLevelIsolationAlg.h:55
CP::ParticleLevelIsolationAlg::m_isolationCut
Gaudi::Property< float > m_isolationCut
Definition
ParticleLevelIsolationAlg.h:42
CP::ParticleLevelIsolationAlg::m_notTauOrigin
Gaudi::Property< std::string > m_notTauOrigin
Definition
ParticleLevelIsolationAlg.h:33
CP::ParticleLevelIsolationAlg::m_isoVarKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_isoVarKey
Definition
ParticleLevelIsolationAlg.h:50
CP::ParticleLevelIsolationAlg::m_decIsolatedKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_decIsolatedKey
Definition
ParticleLevelIsolationAlg.h:46
CP::ParticleLevelIsolationAlg::m_classifierTypeKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_classifierTypeKey
Definition
ParticleLevelIsolationAlg.h:52
CP::ParticleLevelIsolationAlg::initialize
virtual StatusCode initialize() final
Definition
ParticleLevelIsolationAlg.cxx:18
CP::ParticleLevelIsolationAlg::execute
virtual StatusCode execute(const EventContext &ctx) const final
Definition
ParticleLevelIsolationAlg.cxx:73
CP::ParticleLevelIsolationAlg::m_isolated
Gaudi::Property< std::string > m_isolated
Definition
ParticleLevelIsolationAlg.h:31
CP::ParticleLevelIsolationAlg::m_checkTypeName
Gaudi::Property< std::string > m_checkTypeName
Definition
ParticleLevelIsolationAlg.h:36
CP::ParticleLevelIsolationAlg::m_isolationVariable
Gaudi::Property< std::string > m_isolationVariable
Definition
ParticleLevelIsolationAlg.h:39
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition
StoreGate/StoreGate/ReadDecorHandle.h:94
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:66
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
MCTruthPartClassifier::TauLep
@ TauLep
Definition
TruthClasses.h:65
MCTruthPartClassifier::ParticleType
ParticleType
Definition
TruthClasses.h:10
MCTruthPartClassifier::ParticleDef
Definition
TruthClasses.h:124
MCTruthPartClassifier::ParticleDef::sParticleType
std::vector< std::string > sParticleType
the vector of particle types
Definition
TruthClasses.h:126
Generated on
for ATLAS Offline Software by
1.17.0