ATLAS Offline Software
ClassifyAndCalculateHFAugmentation.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 // ClassifyAndCalculateHFAugmentation.cxx //
8 // Implementation file for class ClassifyAndCalculateHFAugmentation //
9 // Author: Adrian Berrocal Guardia <adrian.berrocal.guardia@cern.ch> //
10 // //
12 
13 // Header of the class ClassifyAndCalculateHFAugmentation.
14 
16 #include "StoreGate/ReadHandle.h"
18 
19 namespace DerivationFramework {
20 
21  /*
22  ---------------------------------------------------------------------------------------------------------------------------------------
23  ------------------------------------------------------------- Initialize -------------------------------------------------------------
24  ---------------------------------------------------------------------------------------------------------------------------------------
25  */
26 
28 
29  ATH_MSG_INFO("Initialize HF computation");
30 
31  ATH_MSG_INFO("Jets Container Name " << m_jetCollectionKey.key());
32  ATH_MSG_INFO("Truth Particles Container Name " << m_truthParticlesKey.key());
33  ATH_MSG_INFO("HF Classifier Name " << m_hfDecorKey.key());
34  ATH_MSG_INFO("Simple HF Classifier Name " << m_SimplehfDecorKey.key());
35  ATH_MSG_INFO("Jet Origin ID Decoration Name " << m_jetIDDecorationKey.key());
36  std::size_t pos = m_hfDecorKey.key().find(".");
37  if (pos != std::string::npos) { m_hfDecorationName = m_hfDecorKey.key().substr (pos+1); }
44 
45  // Retrieve the necessary tools
46  if(m_HFClassification_tool.retrieve().isFailure()){
47  ATH_MSG_ERROR("Unable to retrieve the tool " << m_HFClassification_tool);
48  return StatusCode::FAILURE;
49  }
50 
51  if(m_HadronOriginClassifier_Tool.retrieve().isFailure()){
52  ATH_MSG_ERROR("Unable to retrieve the tool " << m_HadronOriginClassifier_Tool);
53  return StatusCode::FAILURE;
54  }
55 
56  if(m_JetMatchingTool_Tool.retrieve().isFailure()){
57  ATH_MSG_ERROR("Unable to retrieve the tool " << m_JetMatchingTool_Tool);
58  return StatusCode::FAILURE;
59  }
60 
61  return StatusCode::SUCCESS;
62  }
63 
64  /*
65  ---------------------------------------------------------------------------------------------------------------------------------------
66  ------------------------------------------------------------- AddBranches -------------------------------------------------------------
67  ---------------------------------------------------------------------------------------------------------------------------------------
68  */
69 
71  {
72 
73 
74  // Retrieve the truth particle container
76  if (!truthParticlesHandle.isValid()) {
77  ATH_MSG_ERROR ("Could not retrieve TruthParticleContainer " << truthParticlesHandle.key());
78  return StatusCode::FAILURE;
79  }
80  const xAOD::TruthParticleContainer* xTruthParticleContainer = truthParticlesHandle.cptr();
81 
82  // Retrieve the jets container
84  if (!jetInputHandle.isValid()) {
85  ATH_MSG_ERROR ("Could not retrieve JetContainer " << jetInputHandle.key());
86  return StatusCode::FAILURE;
87  }
88  const xAOD::JetContainer* JetCollection = jetInputHandle.cptr();
89 
90  // Compute a map that associates the HF hadrons with their origin using the tool m_HadronOriginClassifier_Tool.
91  std::map<const xAOD::TruthParticle*, DerivationFramework::HadronOriginClassifier::HF_id> hadronMap = m_HadronOriginClassifier_Tool->GetOriginMap();
92 
93  // Create a map with a list of matched hadrons for each jet.
94  std::map<const xAOD::Jet*, std::vector<xAOD::TruthParticleContainer::const_iterator>> particleMatch = m_JetMatchingTool_Tool->matchHadronsToJets(xTruthParticleContainer, JetCollection);
95 
96  // Calculate the necessary information from the jets to compute the HF classifier.
97  m_HFClassification_tool->flagJets(JetCollection, particleMatch, hadronMap, m_hfDecorationName);
98 
99  // Compute the HF classifier and the simple HF classifier.
100  int hfclassif = m_HFClassification_tool->computeHFClassification(JetCollection, m_hfDecorationName);
101  int simpleclassif = m_HFClassification_tool->getSimpleClassification(hfclassif);
102 
103  // Retrieve EventInfo
104  SG::ReadHandle<xAOD::EventInfo> eventInfoHandle(m_eventInfoKey, ctx);
105  if (!eventInfoHandle.isValid()) {
106  ATH_MSG_ERROR ("Could not retrieve EventInfo " << eventInfoHandle.key());
107  return StatusCode::FAILURE;
108  }
109  const xAOD::EventInfo* EventInfo = eventInfoHandle.cptr();
110 
111  // Decorate EventInfo with the HF Classification and the simple version
112  SG::WriteDecorHandle<xAOD::EventInfo, int> decorator_HFClassification(m_hfDecorKey, ctx);
113  decorator_HFClassification(*EventInfo) = hfclassif;
114 
115  SG::WriteDecorHandle<xAOD::EventInfo, int> decorator_SimpleHFClassification(m_SimplehfDecorKey, ctx);
116  decorator_SimpleHFClassification(*EventInfo) = simpleclassif;
117 
118  // Decorate truth jets with origin ID
120  for (const auto jet : *JetCollection) {
121  int id = -999;
123  if(hfidAcc.isAvailable(*jet)){
124  id = hfidAcc(*jet);
125  }
126  jetIdDecorator(*jet) = id;
127  }
128 
129  return StatusCode::SUCCESS;
130  }
131 }
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_SimplehfDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_SimplehfDecorKey
Definition: ClassifyAndCalculateHFAugmentation.h:93
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
DerivationFramework::ClassifyAndCalculateHFAugmentation::initialize
virtual StatusCode initialize() override final
Definition: ClassifyAndCalculateHFAugmentation.cxx:27
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: ClassifyAndCalculateHFAugmentation.h:86
SG::ReadHandle< xAOD::TruthParticleContainer >
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_HadronOriginClassifier_Tool
PublicToolHandle< DerivationFramework::HadronOriginClassifier > m_HadronOriginClassifier_Tool
Definition: ClassifyAndCalculateHFAugmentation.h:103
SG::ConstAccessor< int >
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::ClassifyAndCalculateHFAugmentation::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: ClassifyAndCalculateHFAugmentation.cxx:70
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_HFClassification_tool
PublicToolHandle< DerivationFramework::ClassifyAndCalculateHFTool > m_HFClassification_tool
Definition: ClassifyAndCalculateHFAugmentation.h:102
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_jetCollectionKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetCollectionKey
Definition: ClassifyAndCalculateHFAugmentation.h:85
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ClassifyAndCalculateHFAugmentation.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_hfDecorationName
std::string m_hfDecorationName
Definition: ClassifyAndCalculateHFAugmentation.h:95
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_JetMatchingTool_Tool
PublicToolHandle< DerivationFramework::JetMatchingTool > m_JetMatchingTool_Tool
Definition: ClassifyAndCalculateHFAugmentation.h:101
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
JetCollection
Container for Jets
Definition: JetCollection.h:30
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
ReadHandle.h
Handle class for reading from StoreGate.
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_jetIDDecorationKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_jetIDDecorationKey
Definition: ClassifyAndCalculateHFAugmentation.h:94
EventInfo
Definition: EventInfo.py:1
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_truthParticlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticlesKey
Definition: ClassifyAndCalculateHFAugmentation.h:84
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_hfDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_hfDecorKey
Definition: ClassifyAndCalculateHFAugmentation.h:92