ATLAS Offline Software
Loading...
Searching...
No Matches
ParticleLevelIsolationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9namespace CP {
10
12
13 ANA_CHECK(m_particlesKey.initialize());
14
15 // decorators
17 std::make_unique<SG::Decorator<char>>(m_isolated.value());
19 std::make_unique<SG::Decorator<char>>(m_notTauOrigin.value());
20
21 // accessors
22 if (m_isolationVariable.value() != "") {
23 m_acc_isoVar = std::make_unique<SG::ConstAccessor<float>>(
24 m_isolationVariable.value());
25 }
26
27 // set up MCTruthClassifier comparisons
29 const auto it =
30 std::find(partDef.sParticleType.begin(), partDef.sParticleType.end(),
31 m_checkTypeName.value());
32 if (it == partDef.sParticleType.end()) {
34 "checkType = "
35 << m_checkTypeName.value()
36 << " is not a valid MCTruthPartClassifier::ParticleType string!");
37 return StatusCode::FAILURE;
38 } else {
40 std::distance(partDef.sParticleType.begin(), it));
41 }
42
43 return StatusCode::SUCCESS;
44}
45
46StatusCode ParticleLevelIsolationAlg::execute(const EventContext &ctx) const {
47
49
50 // accessors
51 static const SG::ConstAccessor<unsigned int> acc_type(
52 "classifierParticleType");
53 static const SG::ConstAccessor<unsigned int> acc_orig(
54 "classifierParticleOrigin");
55
56 // decorators
57 static const SG::Decorator<float> dec_charge("charge");
58
59 for (const auto* particle : *particles) {
60
61 // check the particle is isolated
62 if (acc_type.isAvailable(*particle)) {
63 bool isolation = acc_type(*particle) == m_checkType;
64 // check further custom isolation cuts
65 if (m_acc_isoVar && isolation) {
66 if ((*m_acc_isoVar).isAvailable(*particle)) {
67 isolation =
68 isolation && ((*m_acc_isoVar)(*particle) / particle->pt() <
69 m_isolationCut.value());
70 } else {
71 ANA_MSG_ERROR("Truth particle is missing the decoration: "
72 << m_isolationVariable.value() << ".");
73 return StatusCode::FAILURE;
74 }
75 }
76 (*m_dec_isolated)(*particle) = isolation;
77 } else {
79 "Truth particle is missing the decoration: classifierParticleType.");
80 return StatusCode::FAILURE;
81 }
82
83 // check the particle doesn't come from a tau decay
84 if (acc_orig.isAvailable(*particle)) {
85 (*m_dec_notTauOrigin)(*particle) =
86 acc_orig(*particle) != MCTruthPartClassifier::ParticleOrigin::TauLep;
87 } else {
89 "Truth particle is missing the decoration: "
90 "classifierParticleOrigin.");
91 return StatusCode::FAILURE;
92 }
93 }
94 return StatusCode::SUCCESS;
95}
96
97} // namespace CP
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
std::unique_ptr< const SG::ConstAccessor< float > > m_acc_isoVar
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
MCTruthPartClassifier::ParticleType m_checkType
std::unique_ptr< const SG::Decorator< char > > m_dec_notTauOrigin
Gaudi::Property< float > m_isolationCut
Gaudi::Property< std::string > m_notTauOrigin
std::unique_ptr< const SG::Decorator< char > > m_dec_isolated
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
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
Select isolated Photons, Electrons and Muons.
std::vector< std::string > sParticleType
the vector of particle types