ATLAS Offline Software
Loading...
Searching...
No Matches
TauTruthDecorationsAlg.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
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
34 for (const auto& decorationName : m_doubleDecorations) {
35 auto [it, added] = m_doubleWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<double>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
36 ANA_CHECK(it->second.initialize());
37 // register output decoration type for output algorithms
38 // note that even though we read a double we write it as a float
39 SG::ConstAccessor<float> (it->second.key().substr (it->second.key().find_last_of(".") + 1));
40 }
41 for (const auto& decorationName : m_floatDecorations) {
42 auto [it, added] = m_floatWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<float>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
43 ANA_CHECK(it->second.initialize());
44 // register output decoration type for output algorithms
45 SG::ConstAccessor<float> (it->second.key().substr (it->second.key().find_last_of(".") + 1));
46 }
47 for (const auto& decorationName : m_intDecorations) {
48 auto [it, added] = m_intWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<int>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
49 ANA_CHECK(it->second.initialize());
50 // register output decoration type for output algorithms
51 SG::ConstAccessor<int> (it->second.key().substr (it->second.key().find_last_of(".") + 1));
52 }
53 for (const auto& decorationName : m_unsignedIntDecorations) {
54 auto [it, added] = m_unsignedIntWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<unsigned int>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
55 ANA_CHECK(it->second.initialize());
56 // register output decoration type for output algorithms
57 SG::ConstAccessor<unsigned int> (it->second.key().substr (it->second.key().find_last_of(".") + 1));
58 }
59 for (const auto& decorationName : m_charDecorations) {
60 auto [it, added] = m_charWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<char>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
61 ANA_CHECK(it->second.initialize());
62 // register output decoration type for output algorithms
63 SG::ConstAccessor<char> (it->second.key().substr (it->second.key().find_last_of(".") + 1));
64 }
65
66 if (m_truthDecayModeKey.contHandleKey().key() == m_truthDecayModeKey.key()) {
68 }
69 if (m_truthParticleTypeKey.contHandleKey().key() == m_truthParticleTypeKey.key()) {
71 }
72 if (m_partonTruthLabelIDKey.contHandleKey().key() == m_partonTruthLabelIDKey.key()) {
74 }
75 ANA_CHECK(m_truthDecayModeKey.initialize());
78
79 // register output decoration type for output algorithms
80 // TO CHECK: should these be of type `float`???
81 SG::ConstAccessor<float> (m_truthDecayModeKey.key().substr (m_truthDecayModeKey.key().find_last_of(".") + 1));
82 SG::ConstAccessor<float> (m_truthParticleTypeKey.key().substr (m_truthParticleTypeKey.key().find_last_of(".") + 1));
83 SG::ConstAccessor<float> (m_partonTruthLabelIDKey.key().substr (m_partonTruthLabelIDKey.key().find_last_of(".") + 1));
84
85 ANA_CHECK(m_truthDecayModeKey.initialize());
88
89 return StatusCode::SUCCESS;
90 }
91
92
93
94 StatusCode TauTruthDecorationsAlg ::
95 execute (const EventContext &ctx) const
96 {
98
99 std::unordered_map<SG::ConstAccessor<double> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>> doubleWriteHandles;
100 std::unordered_map<SG::ConstAccessor<float> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>> floatWriteHandles;
101 std::unordered_map<SG::ConstAccessor<int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, int>> intWriteHandles;
102 std::unordered_map<SG::ConstAccessor<unsigned int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>> unsignedIntWriteHandles;
103 std::unordered_map<SG::ConstAccessor<char> *, SG::WriteDecorHandle<xAOD::TauJetContainer, char>> charWriteHandles;
104 for (auto &[acc, writeHandleKey] : m_doubleWriteHandleKeys) {
105 doubleWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
106 }
107 for (auto &[acc, writeHandleKey] : m_floatWriteHandleKeys) {
108 floatWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
109 }
110 for (auto &[acc, writeHandleKey] : m_intWriteHandleKeys) {
111 intWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, int>(writeHandleKey, ctx));
112 }
113 for (auto &[acc, writeHandleKey] : m_unsignedIntWriteHandleKeys) {
114 unsignedIntWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>(writeHandleKey, ctx));
115 }
116 for (auto &[acc, writeHandleKey] : m_charWriteHandleKeys) {
117 charWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, char>(writeHandleKey, ctx));
118 }
119
123
124 //
125 for (const xAOD::TauJet *tau : *taus){
127 //ensure _each tau_ is decorated with something, even if truthParticle is nullptr
128 //
129 //some cruft to get from the unordered map to the underlying type of the handles
130 //T::mapped_type::accessor_t::element_type will be int, float, char etc
131 auto decorateWithNumber = [&truthParticle, &tau]<typename T>(T & writeHandles, T::mapped_type::accessor_t::element_type v)->void{
132 for (auto& [acc, writeHandle] : writeHandles) {
133 if ((!truthParticle) or (!acc->isAvailable(*truthParticle)) ) {
134 writeHandle(*tau) = v;
135 } else {
136 writeHandle(*tau) = (*acc)(*truthParticle);
137 }
138 }
139 };
140 decorateWithNumber(doubleWriteHandles, -999.f);
141 decorateWithNumber(floatWriteHandles, -999.f);
142 decorateWithNumber(intWriteHandles, 0);
143 decorateWithNumber(unsignedIntWriteHandles, 0);
144 decorateWithNumber(charWriteHandles, 0);
145
146 truthDecayModeHandle(*tau) = truthParticle ? TauAnalysisTools::getTruthDecayMode(*truthParticle) : xAOD::TauJetParameters::Mode_Error;
147 truthParticleTypeHandle(*tau) = static_cast<int>(TauAnalysisTools::getTruthParticleType(*tau));
148
149 static const SG::ConstAccessor<int> acc_PartonTruthLabelID("PartonTruthLabelID");
150 const xAOD::Jet *truthJet = xAOD::TauHelpers::getLink<xAOD::Jet>(tau, "truthJetLink");
151 if (truthJet != nullptr) {
152 partonTruthLabelIDHandle(*tau) = acc_PartonTruthLabelID(*truthJet);
153 }
154 }
155
156 return StatusCode::SUCCESS;
157 }
158}
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::unordered_map< std::unique_ptr< SG::ConstAccessor< double > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_doubleWriteHandleKeys
SG::ReadHandleKey< xAOD::TauJetContainer > m_tausKey
the tau collection we run on
std::unordered_map< std::unique_ptr< SG::ConstAccessor< float > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_floatWriteHandleKeys
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::unordered_map< std::unique_ptr< SG::ConstAccessor< int > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_intWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::ConstAccessor< char > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_charWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::ConstAccessor< unsigned int > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_unsignedIntWriteHandleKeys
Gaudi::Property< std::vector< std::string > > m_intDecorations
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_truthDecayModeKey
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.
TruthMatchedParticleType getTruthParticleType(const xAOD::TauJet &xTau)
return TauJet match type
xAOD::TauJetParameters::DecayMode getTruthDecayMode(const xAOD::TruthParticle &xTruthTau)
Get the Truth Decay Mode from TruthTau particle.
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".
TruthParticle_v1 TruthParticle
Typedef to implementation.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.