ATLAS Offline Software
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 
26 namespace CP
27 {
28 
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) {
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());
65  ANA_CHECK(m_truthParticleTypeKey.initialize());
66  ANA_CHECK(m_partonTruthLabelIDKey.initialize());
67 
68  ANA_CHECK(m_truthDecayModeKey.initialize());
69  ANA_CHECK(m_truthParticleTypeKey.initialize());
70  ANA_CHECK(m_partonTruthLabelIDKey.initialize());
71 
72  return StatusCode::SUCCESS;
73  }
74 
75 
76 
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){
109  const xAOD::TruthParticle* truthParticle = xAOD::TauHelpers::getTruthParticle(tau);
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 }
CP::TauTruthDecorationsAlg::m_doubleWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::ConstAccessor< double > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_doubleWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:44
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
CP::TauTruthDecorationsAlg::m_truthDecayModeKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_truthDecayModeKey
Definition: TauTruthDecorationsAlg.h:50
TauAnalysisTools::getTruthDecayMode
xAOD::TauJetParameters::DecayMode getTruthDecayMode(const xAOD::TruthParticle &xTruthTau)
Get the Truth Decay Mode from TruthTau particle.
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:224
CP::TauTruthDecorationsAlg::m_doubleDecorations
Gaudi::Property< std::vector< std::string > > m_doubleDecorations
the decoration for the tau scale factor
Definition: TauTruthDecorationsAlg.h:36
CP::TauTruthDecorationsAlg::m_unsignedIntDecorations
Gaudi::Property< std::vector< std::string > > m_unsignedIntDecorations
Definition: TauTruthDecorationsAlg.h:39
CP::TauTruthDecorationsAlg::m_prefix
Gaudi::Property< std::string > m_prefix
Definition: TauTruthDecorationsAlg.h:41
CP::TauTruthDecorationsAlg::m_unsignedIntWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::ConstAccessor< unsigned int > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_unsignedIntWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:47
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CP::TauTruthDecorationsAlg::initialize
StatusCode initialize() override
Definition: TauTruthDecorationsAlg.cxx:30
TruthParticleContainer.h
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CP::TauTruthDecorationsAlg::m_truthParticleTypeKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_truthParticleTypeKey
Definition: TauTruthDecorationsAlg.h:52
CP::TauTruthDecorationsAlg::m_floatWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::ConstAccessor< float > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_floatWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:45
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SG::ConstAccessor< double >
CP::TauTruthDecorationsAlg::m_charWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::ConstAccessor< char > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_charWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:48
CP::TauTruthDecorationsAlg::m_floatDecorations
Gaudi::Property< std::vector< std::string > > m_floatDecorations
Definition: TauTruthDecorationsAlg.h:37
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
CP::TauTruthDecorationsAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: TauTruthDecorationsAlg.cxx:78
xAOD::TauHelpers::getTruthParticle
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle *, bool debug=false)
return the truthParticle associated to the given IParticle (if any)
Definition: TauxAODHelpers.cxx:10
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
CP::TauTruthDecorationsAlg::m_intDecorations
Gaudi::Property< std::vector< std::string > > m_intDecorations
Definition: TauTruthDecorationsAlg.h:38
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
hist_file_dump.f
f
Definition: hist_file_dump.py:140
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ReadHandle.h
Handle class for reading from StoreGate.
CP::TauTruthDecorationsAlg::m_intWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::ConstAccessor< int > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_intWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:46
python.PyAthena.v
v
Definition: PyAthena.py:154
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
CP::TauTruthDecorationsAlg::m_tausKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_tausKey
the tau collection we run on
Definition: TauTruthDecorationsAlg.h:32
TauTruthDecorationsAlg.h
CP::TauTruthDecorationsAlg::m_partonTruthLabelIDKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_partonTruthLabelIDKey
Definition: TauTruthDecorationsAlg.h:55
TauAnalysisTools::getTruthParticleType
TruthMatchedParticleType getTruthParticleType(const xAOD::TauJet &xTau)
return TauJet match type
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:494
xAOD::TauJetParameters::Mode_Error
@ Mode_Error
Definition: TauDefs.h:393
HelperFunctions.h
CP::TauTruthDecorationsAlg::m_charDecorations
Gaudi::Property< std::vector< std::string > > m_charDecorations
Definition: TauTruthDecorationsAlg.h:40