ATLAS Offline Software
Loading...
Searching...
No Matches
MCTCDecorationAlg.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
10
12
13
14namespace CP
15{
16
17 MCTCDecorationAlg ::
18 MCTCDecorationAlg (const std::string& name,
19 ISvcLocator* pSvcLocator)
20 : AnaAlgorithm (name, pSvcLocator)
21 {
22 }
23
24
25 StatusCode MCTCDecorationAlg ::
26 initialize ()
27 {
29 {
30 ANA_MSG_ERROR("Classification decoration name needs to be set");
31 return StatusCode::FAILURE;
32 }
33
34 m_classificationAccessor = std::make_unique<SG::ConstAccessor<unsigned int> > (m_classificationDecoration);
35
36 if (!m_isPromptDecoration.empty())
37 {
38 m_isPromptDecorator = std::make_unique<SG::Decorator<int> > (m_isPromptDecoration);
39 }
40 if (!m_fromHadronDecoration.empty())
41 {
42 m_fromHadronDecorator = std::make_unique<SG::Decorator<int> > (m_fromHadronDecoration);
43 }
44 if (!m_fromBSMDecoration.empty())
45 {
46 m_fromBSMDecorator = std::make_unique<SG::Decorator<int> > (m_fromBSMDecoration);
47 }
48 if (!m_fromTauDecoration.empty())
49 {
50 m_fromTauDecorator = std::make_unique<SG::Decorator<int> > (m_fromTauDecoration);
51 }
52
55 ANA_CHECK (m_systematicsList.initialize());
56
57 return StatusCode::SUCCESS;
58 }
59
60
61 StatusCode MCTCDecorationAlg ::
62 execute ()
63 {
64 for (const auto& sys : m_systematicsList.systematicsVector())
65 {
66 const xAOD::IParticleContainer *particles{};
67 ANA_CHECK (m_particlesHandle.retrieve (particles, sys));
68 for (const xAOD::IParticle *particle : *particles)
69 {
70 if (m_preselection.getBool (*particle, sys))
71 {
72 // Check if xAOD::TruthParticle or if not if it has the TruthParticleLink
73 const xAOD::TruthParticle *truthParticle
74 = dynamic_cast<const xAOD::TruthParticle *> (particle);
75 if (truthParticle == nullptr)
76 {
77 // need to find the truth particle
78 truthParticle = xAOD::TruthHelpers::getTruthParticle(*particle);
79 }
80
81 // run only on leptons
82 if (truthParticle != nullptr && truthParticle->isLepton() && (truthParticle->status() == 1 || truthParticle->status() == 2))
83 {
84 unsigned int result{};
85 if (m_classificationAccessor->isAvailable(*truthParticle))
86 {
87 result = (*m_classificationAccessor)(*truthParticle);
88 }
89 else
90 {
91 ANA_MSG_ERROR ("MCTC Classification decoration not available.");
92 return StatusCode::FAILURE;
93 }
94
95 std::bitset<MCTruthPartClassifier::MCTC_bits::totalBits> bitset(result);
96 if (m_isPromptDecorator != nullptr)
97 {
98 (*m_isPromptDecorator)(*particle) = MCTruthPartClassifier::isPrompt(result, true) ? 1 : 0; // also accept 'unknown' with -1
99 }
100 if (m_fromHadronDecorator != nullptr)
101 {
102 (*m_fromHadronDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::hadron);
103 }
104 if (m_fromBSMDecorator != nullptr)
105 {
106 (*m_fromBSMDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::frombsm);
107 }
108 if (m_fromTauDecorator != nullptr)
109 {
110 (*m_fromTauDecorator)(*particle) = bitset.test(MCTruthPartClassifier::MCTC_bits::Tau);
111 }
112 continue;
113 }
114 }
115
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_fromHadDecoration
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
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
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.