ATLAS Offline Software
Loading...
Searching...
No Matches
MCTCDecorationAlg.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
10
12
13#include <bitset>
14
15namespace CP
16{
17
18 StatusCode MCTCDecorationAlg ::
19 initialize ()
20 {
22 {
23 ANA_MSG_ERROR("Classification decoration name needs to be set");
24 return StatusCode::FAILURE;
25 }
26
27 m_classificationAccessor = std::make_unique<SG::ConstAccessor<unsigned int> > (m_classificationDecoration);
28
29 if (!m_isPromptDecoration.empty())
30 {
31 m_isPromptDecorator = std::make_unique<SG::Decorator<int> > (m_isPromptDecoration);
32 }
33 if (!m_fromHadronDecoration.empty())
34 {
35 m_fromHadronDecorator = std::make_unique<SG::Decorator<int> > (m_fromHadronDecoration);
36 }
37 if (!m_fromBSMDecoration.empty())
38 {
39 m_fromBSMDecorator = std::make_unique<SG::Decorator<int> > (m_fromBSMDecoration);
40 }
41 if (!m_fromTauDecoration.empty())
42 {
43 m_fromTauDecorator = std::make_unique<SG::Decorator<int> > (m_fromTauDecoration);
44 }
45
48 ANA_CHECK (m_systematicsList.initialize());
49
50 return StatusCode::SUCCESS;
51 }
52
53
54 StatusCode MCTCDecorationAlg ::
55 execute (const EventContext& ctx)
56 {
57 // bit of a hack, a set to hold particles that have already been classified
58 // so we don't overwrite them with the default -1 if a systematic variation
59 // doesn't pass the selection...
60 std::unordered_set<const xAOD::IParticle *> classified;
61
62 for (const auto& sys : m_systematicsList.systematicsVector())
63 {
64 const xAOD::IParticleContainer *particles{};
65 ANA_CHECK (m_particlesHandle.retrieve (particles, sys, ctx));
66 for (const xAOD::IParticle *particle : *particles)
67 {
68 if (m_preselection.getBool (*particle, sys))
69 {
70 // Check if xAOD::TruthParticle or if not if it has the TruthParticleLink
71 const xAOD::TruthParticle *truthParticle
72 = dynamic_cast<const xAOD::TruthParticle *> (particle);
73 if (truthParticle == nullptr)
74 {
75 // need to find the truth particle
76 truthParticle = xAOD::TruthHelpers::getTruthParticle(*particle);
77 }
78
79 // run only on leptons
80 if (truthParticle != nullptr && truthParticle->isLepton() && (truthParticle->status() == 1 || truthParticle->status() == 2))
81 {
82 unsigned int result{};
83 if (m_classificationAccessor->isAvailable(*truthParticle))
84 {
85 result = (*m_classificationAccessor)(*truthParticle);
86 }
87 else
88 {
89 ANA_MSG_ERROR ("MCTC Classification decoration not available.");
90 return StatusCode::FAILURE;
91 }
92
93 std::bitset<MCTruthPartClassifier::MCTC_bits::totalBits> bitset(result);
94 if (m_isPromptDecorator != nullptr)
95 {
96 (*m_isPromptDecorator)(*particle) = MCTruthPartClassifier::isPrompt(result, true) ? 1 : 0; // also accept 'unknown' with -1
97 }
98 if (m_fromHadronDecorator != nullptr)
99 {
100 (*m_fromHadronDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::hadron);
101 }
102 if (m_fromBSMDecorator != nullptr)
103 {
104 (*m_fromBSMDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::frombsm);
105 }
106 if (m_fromTauDecorator != nullptr)
107 {
108 (*m_fromTauDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::Tau);
109 }
110 classified.insert(particle);
111 continue;
112 }
113 }
114
115 if (classified.count(particle)) continue;
116 // defaults
117 if (m_isPromptDecorator != nullptr)
118 {
119 (*m_isPromptDecorator)(*particle) = -1;
120 }
121 if (m_fromHadronDecorator != nullptr)
122 {
123 (*m_fromHadronDecorator)(*particle) = -1;
124 }
125 if (m_fromBSMDecorator != nullptr)
126 {
127 (*m_fromBSMDecorator)(*particle) = -1;
128 }
129 if (m_fromTauDecorator != nullptr)
130 {
131 (*m_fromTauDecorator)(*particle) = -1;
132 }
133 }
134 }
135
136 return StatusCode::SUCCESS;
137 }
138
139} // namespace CP
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
SysReadHandle< xAOD::IParticleContainer > m_particlesHandle
the particle collection we run on
std::unique_ptr< const SG::Decorator< int > > m_fromHadronDecorator
the decorator for m_fromHadronDecoration
std::unique_ptr< const SG::ConstAccessor< unsigned int > > m_classificationAccessor
the accessor for m_classificationDecoration
std::unique_ptr< const SG::Decorator< int > > m_fromBSMDecorator
the decorator for m_fromBSMDecoration
std::unique_ptr< const SG::Decorator< int > > m_isPromptDecorator
the decorator for m_isPromptDecoration
std::unique_ptr< const SG::Decorator< int > > m_fromTauDecorator
the decorator for m_fromTauDecoration
Gaudi::Property< std::string > m_classificationDecoration
the decoration for the MCTC classification bitmask
SysListHandle m_systematicsList
the systematics list we run
Gaudi::Property< std::string > m_fromBSMDecoration
the decoration for the BSM origin
Gaudi::Property< std::string > m_isPromptDecoration
the decoration for the promptness
Gaudi::Property< std::string > m_fromTauDecoration
the decoration for the tau origin
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Gaudi::Property< std::string > m_fromHadronDecoration
the decoration for the hadronic origin
Class providing the definition of the 4-vector interface.
int status() const
Status code.
bool isLepton() const
Whether the particle is a lepton.
Select isolated Photons, Electrons and Muons.
int isPrompt(const unsigned int classify, bool allow_prompt_tau_decays=true)
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any).
TruthParticle_v1 TruthParticle
Typedef to implementation.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.