ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
12
13#include <algorithm>
14#include <optional>
15
16namespace CP {
17
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 }
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
57 const auto it =
58 std::ranges::find(partDef.sParticleType, m_checkTypeName.value());
59 if (it == partDef.sParticleType.end()) {
61 "checkType = "
62 << m_checkTypeName.value()
63 << " is not a valid MCTruthPartClassifier::ParticleType string!");
64 return StatusCode::FAILURE;
65 } else {
67 std::distance(partDef.sParticleType.begin(), it));
68 }
69
70 return StatusCode::SUCCESS;
71}
72
73StatusCode ParticleLevelIsolationAlg::execute(const EventContext &ctx) const {
74
76
77 // accessors
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
94 m_decIsolatedKey, 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 {
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) =
127 } else {
129 "Truth particle is missing the decoration: "
130 "classifierParticleOrigin.");
131 return StatusCode::FAILURE;
132 }
133 }
134 return StatusCode::SUCCESS;
135}
136
137} // namespace CP
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_MSG_WARNING(xmsg,...)
Macro printing warning messages.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
MCTruthPartClassifier::ParticleType m_checkType
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_decNotTauOriginKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_classifierOriginKey
Gaudi::Property< float > m_isolationCut
Gaudi::Property< std::string > m_notTauOrigin
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_isoVarKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_decIsolatedKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_classifierTypeKey
virtual StatusCode execute(const EventContext &ctx) const final
Gaudi::Property< std::string > m_isolated
Gaudi::Property< std::string > m_checkTypeName
Gaudi::Property< std::string > m_isolationVariable
Handle class for reading a decoration on an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
Handle class for adding a decoration to an object.
Select isolated Photons, Electrons and Muons.
std::vector< std::string > sParticleType
the vector of particle types