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 }
38 for (const auto& decorationName : m_floatDecorations) {
39 auto [it, added] = m_floatWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<float>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
40 ANA_CHECK(it->second.initialize());
41 }
42 for (const auto& decorationName : m_intDecorations) {
43 auto [it, added] = m_intWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<int>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
44 ANA_CHECK(it->second.initialize());
45 }
46 for (const auto& decorationName : m_unsignedIntDecorations) {
47 auto [it, added] = m_unsignedIntWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<unsigned int>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
48 ANA_CHECK(it->second.initialize());
49 }
50 for (const auto& decorationName : m_charDecorations) {
51 auto [it, added] = m_charWriteHandleKeys.emplace(std::make_unique<SG::ConstAccessor<char>>(decorationName), SG::WriteDecorHandleKey<xAOD::TauJetContainer>(m_tausKey.key() + "." + m_prefix + decorationName));
52 ANA_CHECK(it->second.initialize());
53 }
54
55 if (m_truthDecayModeKey.contHandleKey().key() == m_truthDecayModeKey.key()) {
57 }
58 if (m_truthParticleTypeKey.contHandleKey().key() == m_truthParticleTypeKey.key()) {
60 }
61 if (m_partonTruthLabelIDKey.contHandleKey().key() == m_partonTruthLabelIDKey.key()) {
63 }
64 ANA_CHECK(m_truthDecayModeKey.initialize());
67
68 ANA_CHECK(m_truthDecayModeKey.initialize());
71
72 return StatusCode::SUCCESS;
73 }
74
75
76
77 StatusCode TauTruthDecorationsAlg ::
78 execute (const EventContext &ctx) const
79 {
81
82 std::unordered_map<SG::ConstAccessor<double> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>> doubleWriteHandles;
83 std::unordered_map<SG::ConstAccessor<float> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>> floatWriteHandles;
84 std::unordered_map<SG::ConstAccessor<int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, int>> intWriteHandles;
85 std::unordered_map<SG::ConstAccessor<unsigned int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>> unsignedIntWriteHandles;
86 std::unordered_map<SG::ConstAccessor<char> *, SG::WriteDecorHandle<xAOD::TauJetContainer, char>> charWriteHandles;
87 for (auto &[acc, writeHandleKey] : m_doubleWriteHandleKeys) {
88 doubleWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
89 }
90 for (auto &[acc, writeHandleKey] : m_floatWriteHandleKeys) {
91 floatWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
92 }
93 for (auto &[acc, writeHandleKey] : m_intWriteHandleKeys) {
94 intWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, int>(writeHandleKey, ctx));
95 }
96 for (auto &[acc, writeHandleKey] : m_unsignedIntWriteHandleKeys) {
97 unsignedIntWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>(writeHandleKey, ctx));
98 }
99 for (auto &[acc, writeHandleKey] : m_charWriteHandleKeys) {
100 charWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, char>(writeHandleKey, ctx));
101 }
102
106
107 //
108 for (const xAOD::TauJet *tau : *taus){
110 //ensure _each tau_ is decorated with something, even if truthParticle is nullptr
111 //
112 //some cruft to get from the unordered map to the underlying type of the handles
113 //T::mapped_type::accessor_t::element_type will be int, float, char etc
114 auto decorateWithNumber = [&truthParticle, &tau]<typename T>(T & writeHandles, T::mapped_type::accessor_t::element_type v)->void{
115 for (auto& [acc, writeHandle] : writeHandles) {
116 if ((!truthParticle) or (!acc->isAvailable(*truthParticle)) ) {
117 writeHandle(*tau) = v;
118 } else {
119 writeHandle(*tau) = (*acc)(*truthParticle);
120 }
121 }
122 };
123 decorateWithNumber(doubleWriteHandles, -999.f);
124 decorateWithNumber(floatWriteHandles, -999.f);
125 decorateWithNumber(intWriteHandles, 0);
126 decorateWithNumber(unsignedIntWriteHandles, 0);
127 decorateWithNumber(charWriteHandles, 0);
128
129 truthDecayModeHandle(*tau) = truthParticle ? TauAnalysisTools::getTruthDecayMode(*truthParticle) : xAOD::TauJetParameters::Mode_Error;
130 truthParticleTypeHandle(*tau) = static_cast<int>(TauAnalysisTools::getTruthParticleType(*tau));
131
132 static const SG::ConstAccessor<int> acc_PartonTruthLabelID("PartonTruthLabelID");
133 const xAOD::Jet *truthJet = xAOD::TauHelpers::getLink<xAOD::Jet>(tau, "truthJetLink");
134 if (truthJet != nullptr) {
135 partonTruthLabelIDHandle(*tau) = acc_PartonTruthLabelID(*truthJet);
136 }
137 }
138
139 return StatusCode::SUCCESS;
140 }
141}
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.