Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
20 
21 //
22 // method implementations
23 //
24 
25 
26 
27 namespace CP
28 {
29 
31  initialize ()
32  {
33  ANA_CHECK(m_tausKey.initialize());
34 
35  for (const auto& decorationName : m_doubleDecorations) {
37  ANA_CHECK(it->second.initialize());
38  }
39  for (const auto& decorationName : m_floatDecorations) {
41  ANA_CHECK(it->second.initialize());
42  }
43  for (const auto& decorationName : m_intDecorations) {
45  ANA_CHECK(it->second.initialize());
46  }
47  for (const auto& decorationName : m_unsignedIntDecorations) {
49  ANA_CHECK(it->second.initialize());
50  }
51  for (const auto& decorationName : m_charDecorations) {
53  ANA_CHECK(it->second.initialize());
54  }
55 
56  if (m_truthDecayModeKey.contHandleKey().key() == m_truthDecayModeKey.key()) {
58  }
59  if (m_truthParticleTypeKey.contHandleKey().key() == m_truthParticleTypeKey.key()) {
61  }
62  if (m_partonTruthLabelIDKey.contHandleKey().key() == m_partonTruthLabelIDKey.key()) {
64  }
65  ANA_CHECK(m_truthDecayModeKey.initialize());
66  ANA_CHECK(m_truthParticleTypeKey.initialize());
67  ANA_CHECK(m_partonTruthLabelIDKey.initialize());
68 
69  ANA_CHECK(m_truthDecayModeKey.initialize());
70  ANA_CHECK(m_truthParticleTypeKey.initialize());
71  ANA_CHECK(m_partonTruthLabelIDKey.initialize());
72 
73  return StatusCode::SUCCESS;
74  }
75 
76 
77 
79  execute (const EventContext &ctx) const
80  {
82 
83  std::unordered_map<SG::AuxElement::ConstAccessor<double> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>> doubleWriteHandles;
84  std::unordered_map<SG::AuxElement::ConstAccessor<float> *, SG::WriteDecorHandle<xAOD::TauJetContainer, float>> floatWriteHandles;
85  std::unordered_map<SG::AuxElement::ConstAccessor<int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, int>> intWriteHandles;
86  std::unordered_map<SG::AuxElement::ConstAccessor<unsigned int> *, SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>> unsignedIntWriteHandles;
87  std::unordered_map<SG::AuxElement::ConstAccessor<char> *, SG::WriteDecorHandle<xAOD::TauJetContainer, char>> charWriteHandles;
88  for (auto &[acc, writeHandleKey] : m_doubleWriteHandleKeys) {
89  doubleWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
90  }
91  for (auto &[acc, writeHandleKey] : m_floatWriteHandleKeys) {
92  floatWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, float>(writeHandleKey, ctx));
93  }
94  for (auto &[acc, writeHandleKey] : m_intWriteHandleKeys) {
95  intWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, int>(writeHandleKey, ctx));
96  }
97  for (auto &[acc, writeHandleKey] : m_unsignedIntWriteHandleKeys) {
98  unsignedIntWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, unsigned int>(writeHandleKey, ctx));
99  }
100  for (auto &[acc, writeHandleKey] : m_charWriteHandleKeys) {
101  charWriteHandles.emplace(acc.get(), SG::WriteDecorHandle<xAOD::TauJetContainer, char>(writeHandleKey, ctx));
102  }
103 
107 
108  //
109  for (const xAOD::TauJet *tau : *taus){
110  const xAOD::TruthParticle* truthParticle = xAOD::TauHelpers::getTruthParticle(tau);
111  //ensure _each tau_ is decorated with something, even if truthParticle is nullptr
112  //
113  //some cruft to get from the unordered map to the underlying type of the handles
114  //T::mapped_type::accessor_t::element_type will be int, float, char etc
115  auto decorateWithNumber = [&truthParticle, &tau]<typename T>(T & writeHandles, T::mapped_type::accessor_t::element_type v)->void{
116  for (auto& [acc, writeHandle] : writeHandles) {
117  if ((!truthParticle) or (!acc->isAvailable(*truthParticle)) ) {
118  writeHandle(*tau) = v;
119  } else {
120  writeHandle(*tau) = (*acc)(*truthParticle);
121  }
122  }
123  };
124  decorateWithNumber(doubleWriteHandles, -999.f);
125  decorateWithNumber(floatWriteHandles, -999.f);
126  decorateWithNumber(intWriteHandles, 0);
127  decorateWithNumber(unsignedIntWriteHandles, 0);
128  decorateWithNumber(charWriteHandles, 0);
129 
130  truthDecayModeHandle(*tau) = truthParticle ? TauAnalysisTools::getTruthDecayMode(*truthParticle) : xAOD::TauJetParameters::Mode_Error;
131  truthParticleTypeHandle(*tau) = static_cast<int>(TauAnalysisTools::getTruthParticleType(*tau));
132 
133  static const SG::AuxElement::ConstAccessor<int> acc_PartonTruthLabelID("PartonTruthLabelID");
134  const xAOD::Jet *truthJet = xAOD::TauHelpers::getLink<xAOD::Jet>(tau, "truthJetLink");
135  if (truthJet != nullptr) {
136  partonTruthLabelIDHandle(*tau) = acc_PartonTruthLabelID(*truthJet);
137  }
138  }
139 
140  return StatusCode::SUCCESS;
141  }
142 }
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_charWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::AuxElement::ConstAccessor< char > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_charWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:48
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:223
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
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:31
TruthParticleContainer.h
CP::TauTruthDecorationsAlg::m_floatWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::AuxElement::ConstAccessor< float > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_floatWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:45
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CP::TauTruthDecorationsAlg::m_truthParticleTypeKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_truthParticleTypeKey
Definition: TauTruthDecorationsAlg.h:52
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
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:79
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:141
WriteDecorHandle.h
Handle class for adding a decoration to an object.
CP::TauTruthDecorationsAlg::m_doubleWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::AuxElement::ConstAccessor< double > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_doubleWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:44
ReadHandle.h
Handle class for reading from StoreGate.
CP::TauTruthDecorationsAlg::m_intWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::AuxElement::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:572
CP::TauTruthDecorationsAlg::m_unsignedIntWriteHandleKeys
std::unordered_map< std::unique_ptr< SG::AuxElement::ConstAccessor< unsigned int > >, SG::WriteDecorHandleKey< xAOD::TauJetContainer > > m_unsignedIntWriteHandleKeys
Definition: TauTruthDecorationsAlg.h:47
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
AuxElement.h
Base class for elements of a container that can have aux data.