ATLAS Offline Software
Loading...
Searching...
No Matches
TauTruthDecorationsAlg.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
8
9//
10// includes
11//
12
14
19
20//
21// method implementations
22//
23
24
25
26namespace CP
27{
28
29 StatusCode TauTruthDecorationsAlg ::
30 initialize ()
31 {
32 ANA_CHECK(m_tausKey.initialize());
33
35 for (const auto& decorationName : m_doubleDecorations) {
36 auto& key = m_doubleWriteHandleKeys.emplace_back(SG::ConstAccessor<double>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName)).second;
37 ANA_CHECK(key.initialize());
38 // register output decoration type for output algorithms
39 // note that even though we read a double we write it as a float
40 SG::ConstAccessor<float> (key.key().substr (key.key().find_last_of(".") + 1));
41 }
43 for (const auto& decorationName : m_floatDecorations) {
44 auto& key = m_floatWriteHandleKeys.emplace_back(SG::ConstAccessor<float>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName)).second;
45 ANA_CHECK(key.initialize());
46 // register output decoration type for output algorithms
47 SG::ConstAccessor<float> (key.key().substr (key.key().find_last_of(".") + 1));
48 }
50 for (const auto& decorationName : m_intDecorations) {
51 auto& key = m_intWriteHandleKeys.emplace_back(SG::ConstAccessor<int>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName)).second;
52 ANA_CHECK(key.initialize());
53 // register output decoration type for output algorithms
54 SG::ConstAccessor<int> (key.key().substr (key.key().find_last_of(".") + 1));
55 }
57 for (const auto& decorationName : m_unsignedIntDecorations) {
58 auto& key = m_unsignedIntWriteHandleKeys.emplace_back(SG::ConstAccessor<unsigned int>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName)).second;
59 ANA_CHECK(key.initialize());
60 // register output decoration type for output algorithms
61 SG::ConstAccessor<unsigned int> (key.key().substr (key.key().find_last_of(".") + 1));
62 }
64 for (const auto& decorationName : m_charDecorations) {
65 auto& key = m_charWriteHandleKeys.emplace_back(SG::ConstAccessor<char>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName)).second;
66 ANA_CHECK(key.initialize());
67 // register output decoration type for output algorithms
68 SG::ConstAccessor<char> (key.key().substr (key.key().find_last_of(".") + 1));
69 }
70
71 if (m_truthDecayModeKey.contHandleKey().key() == m_truthDecayModeKey.key()) {
73 }
74 if (m_truthParticleTypeKey.contHandleKey().key() == m_truthParticleTypeKey.key()) {
76 }
77 if (m_partonTruthLabelIDKey.contHandleKey().key() == m_partonTruthLabelIDKey.key()) {
79 }
80 ANA_CHECK(m_truthDecayModeKey.initialize());
83
84 // register output decoration type for output algorithms
85 SG::ConstAccessor<int> (m_truthDecayModeKey.key().substr (m_truthDecayModeKey.key().find_last_of(".") + 1));
86 SG::ConstAccessor<int> (m_truthParticleTypeKey.key().substr (m_truthParticleTypeKey.key().find_last_of(".") + 1));
87 SG::ConstAccessor<int> (m_partonTruthLabelIDKey.key().substr (m_partonTruthLabelIDKey.key().find_last_of(".") + 1));
88
89 return StatusCode::SUCCESS;
90 }
91
92
93
94 StatusCode TauTruthDecorationsAlg ::
95 execute (const EventContext &ctx) const
96 {
98
99 std::vector<std::pair<const SG::ConstAccessor<double> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>>> doubleWriteHandles;
100 std::vector<std::pair<const SG::ConstAccessor<float> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>>> floatWriteHandles;
101 std::vector<std::pair<const SG::ConstAccessor<int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, int>>> intWriteHandles;
102 std::vector<std::pair<const SG::ConstAccessor<unsigned int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>>> unsignedIntWriteHandles;
103 std::vector<std::pair<const SG::ConstAccessor<char> *, SG::WriteDecorHandle<xAOD::TauJetContainer, char>>> charWriteHandles;
104 doubleWriteHandles.reserve(m_doubleWriteHandleKeys.size());
105 for (const auto &[acc, writeHandleKey] : m_doubleWriteHandleKeys) {
106 doubleWriteHandles.emplace_back(&acc, SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
107 }
108 floatWriteHandles.reserve(m_floatWriteHandleKeys.size());
109 for (const auto &[acc, writeHandleKey] : m_floatWriteHandleKeys) {
110 floatWriteHandles.emplace_back(&acc, SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
111 }
112 intWriteHandles.reserve(m_intWriteHandleKeys.size());
113 for (const auto &[acc, writeHandleKey] : m_intWriteHandleKeys) {
114 intWriteHandles.emplace_back(&acc, SG::WriteDecorHandle<xAOD::TauJetContainer, int>(writeHandleKey, ctx));
115 }
116 unsignedIntWriteHandles.reserve(m_unsignedIntWriteHandleKeys.size());
117 for (const auto &[acc, writeHandleKey] : m_unsignedIntWriteHandleKeys) {
118 unsignedIntWriteHandles.emplace_back(&acc, SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>(writeHandleKey, ctx));
119 }
120 charWriteHandles.reserve(m_charWriteHandleKeys.size());
121 for (const auto &[acc, writeHandleKey] : m_charWriteHandleKeys) {
122 charWriteHandles.emplace_back(&acc, SG::WriteDecorHandle<xAOD::TauJetContainer, char>(writeHandleKey, ctx));
123 }
124
128
129 //
130 for (const xAOD::TauJet *tau : *taus){
132 //ensure _each tau_ is decorated with something, even if truthParticle is nullptr
133 auto decorateWithNumber = [&truthParticle, &tau](auto & writeHandles, auto v)->void{
134 for (auto& [acc, writeHandle] : writeHandles) {
135 if ((!truthParticle) or (!acc->isAvailable(*truthParticle)) ) {
136 writeHandle(*tau) = v;
137 } else {
138 writeHandle(*tau) = (*acc)(*truthParticle);
139 }
140 }
141 };
142 decorateWithNumber(doubleWriteHandles, -999.f);
143 decorateWithNumber(floatWriteHandles, -999.f);
144 decorateWithNumber(intWriteHandles, 0);
145 decorateWithNumber(unsignedIntWriteHandles, 0);
146 decorateWithNumber(charWriteHandles, 0);
147
148 truthDecayModeHandle(*tau) = truthParticle ? TauAnalysisTools::getTruthDecayMode(*truthParticle) : xAOD::TauJetParameters::Mode_Error;
149 truthParticleTypeHandle(*tau) = static_cast<int>(TauAnalysisTools::getTruthParticleType(*tau));
150 //coverity[UNNECESSARY_STRING_COPY:FALSE]
151 static const SG::ConstAccessor<int> acc_PartonTruthLabelID("PartonTruthLabelID");
152 const xAOD::Jet *truthJet = xAOD::TauHelpers::getLink<xAOD::Jet>(tau, "truthJetLink");
153 if (truthJet != nullptr) {
154 partonTruthLabelIDHandle(*tau) = acc_PartonTruthLabelID(*truthJet);
155 } else {
156 partonTruthLabelIDHandle(*tau) = -999;
157 }
158 }
159
160 return StatusCode::SUCCESS;
161 }
162}
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
#define ANA_CHECK(EXP)
check whether the given expression was successful
static Double_t taus
std::vector< std::pair< SG::ConstAccessor< char >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > > m_charWriteHandleKeys
SG::ReadHandleKey< xAOD::TauJetContainer > m_tausKey
the tau collection we run on
std::vector< std::pair< SG::ConstAccessor< int >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > > m_intWriteHandleKeys
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_partonTruthLabelIDKey
Gaudi::Property< std::vector< std::string > > m_unsignedIntDecorations
Gaudi::Property< std::vector< std::string > > m_doubleDecorations
the decoration for the tau scale factor
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_truthParticleTypeKey
std::vector< std::pair< SG::ConstAccessor< float >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > > m_floatWriteHandleKeys
Gaudi::Property< std::vector< std::string > > m_intDecorations
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_truthDecayModeKey
std::vector< std::pair< SG::ConstAccessor< double >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > > m_doubleWriteHandleKeys
std::vector< std::pair< SG::ConstAccessor< unsigned int >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > > m_unsignedIntWriteHandleKeys
Gaudi::Property< std::vector< std::string > > m_charDecorations
Gaudi::Property< std::vector< std::string > > m_floatDecorations
Gaudi::Property< std::string > m_prefix
Helper class to provide constant type-safe access to aux data.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Handle class for adding a decoration to an object.
Select isolated Photons, Electrons and Muons.
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle *, bool debug=false)
return the truthParticle associated to the given IParticle (if any)
const T * getLink(const xAOD::IParticle *, const std::string &, bool debug=false)
Jet_v1 Jet
Definition of the current "jet version".
TauJet_v3 TauJet
Definition of the current "tau version".
Definition TauJet.h:17
TruthParticle_v1 TruthParticle
Typedef to implementation.
static const SG::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.