ATLAS Offline Software
ClassifyAndCalculateHFAugmentation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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  ------------------------------------------------------- Constructor/Destructor --------------------------------------------------------
24  ---------------------------------------------------------------------------------------------------------------------------------------
25  */
26 
27  ClassifyAndCalculateHFAugmentation::ClassifyAndCalculateHFAugmentation(const std::string& t, const std::string& n, const IInterface* p) :
28  AthAlgTool(t,n,p), // Athena tool.
29  m_JetMatchingTool_Tool(""), // Hadron-jet matching tool.
30  m_HFClassification_tool(""), // HF classifier tool.
31  m_HadronOriginClassifier_Tool("") // HF hadron origin tool.
32  {
33  declareInterface<DerivationFramework::IAugmentationTool>(this);
34 
35  // Declare a set of tool properties to set them exertanally:
36  // -m_HFClassification_tool: The tool to compute the HF classifier.
37  // -m_HadronOriginClassifier_Tool: The tool to determine the origin of the HF hadrons.
38  // -m_JetMatchingTool_Tool: The tool to match the hadrons with the jets.
39 
40  declareProperty("ClassifyAndComputeHFtool", m_HFClassification_tool);
41  declareProperty("HadronOriginClassifierTool", m_HadronOriginClassifier_Tool);
42  declareProperty("JetMatchingTool", m_JetMatchingTool_Tool);
43  }
44 
46 
47  /*
48  ---------------------------------------------------------------------------------------------------------------------------------------
49  --------------------------------------------------------- Initialize/Finalize ---------------------------------------------------------
50  ---------------------------------------------------------------------------------------------------------------------------------------
51  */
52 
54 
55  ATH_MSG_INFO("Initialize HF computation");
56 
57  ATH_MSG_INFO("Jets Container Name " << m_jetCollectionKey.key());
58  ATH_MSG_INFO("Truth Particles Container Name " << m_truthParticlesKey.key());
59  ATH_MSG_INFO("HF Classifier Name " << m_hfDecorationName);
60  ATH_MSG_INFO("Simple HF Classifier Name " << m_SimplehfDecorationName);
61 
63  ATH_CHECK( m_jetCollectionKey.initialize() );
69 
70  // Retrieve the necessary tools
71  if(m_HFClassification_tool.retrieve().isFailure()){
72  ATH_MSG_ERROR("Unable to retrieve the tool " << m_HFClassification_tool);
73  return StatusCode::FAILURE;
74  }
75 
76  if(m_HadronOriginClassifier_Tool.retrieve().isFailure()){
77  ATH_MSG_ERROR("Unable to retrieve the tool " << m_HadronOriginClassifier_Tool);
78  return StatusCode::FAILURE;
79  }
80 
81  if(m_JetMatchingTool_Tool.retrieve().isFailure()){
82  ATH_MSG_ERROR("Unable to retrieve the tool " << m_JetMatchingTool_Tool);
83  return StatusCode::FAILURE;
84  }
85 
86  return StatusCode::SUCCESS;
87  }
88 
90  return StatusCode::SUCCESS;
91  }
92 
93  /*
94  ---------------------------------------------------------------------------------------------------------------------------------------
95  ------------------------------------------------------------- AddBranches -------------------------------------------------------------
96  ---------------------------------------------------------------------------------------------------------------------------------------
97  */
98 
100  {
101 
102  const EventContext& ctx = Gaudi::Hive::currentContext();
103 
104  // Retrieve the truth particle container
106  if (!truthParticlesHandle.isValid()) {
107  ATH_MSG_ERROR ("Could not retrieve TruthParticleContainer " << truthParticlesHandle.key());
108  return StatusCode::FAILURE;
109  }
110  const xAOD::TruthParticleContainer* xTruthParticleContainer = truthParticlesHandle.cptr();
111 
112  // Retrieve the jets container
114  if (!jetInputHandle.isValid()) {
115  ATH_MSG_ERROR ("Could not retrieve JetContainer " << jetInputHandle.key());
116  return StatusCode::FAILURE;
117  }
118  const xAOD::JetContainer* JetCollection = jetInputHandle.cptr();
119 
120  // Compute a map that associates the HF hadrons with their origin using the tool m_HadronOriginClassifier_Tool.
121  std::map<const xAOD::TruthParticle*, DerivationFramework::HadronOriginClassifier::HF_id> hadronMap = m_HadronOriginClassifier_Tool->GetOriginMap();
122 
123  // Create a map with a list of matched hadrons for each jet.
124  std::map<const xAOD::Jet*, std::vector<xAOD::TruthParticleContainer::const_iterator>> particleMatch = m_JetMatchingTool_Tool->matchHadronsToJets(xTruthParticleContainer, JetCollection);
125 
126  // Calculate the necessary information from the jets to compute the HF classifier.
127  m_HFClassification_tool->flagJets(JetCollection, particleMatch, hadronMap, m_hfDecorationName);
128 
129  // Compute the HF classifier and the simple HF classifier.
130  int hfclassif = m_HFClassification_tool->computeHFClassification(JetCollection, m_hfDecorationName);
131  int simpleclassif = m_HFClassification_tool->getSimpleClassification(hfclassif);
132 
133  // Retrieve EventInfo
134  SG::ReadHandle<xAOD::EventInfo> eventInfoHandle(m_eventInfoKey, ctx);
135  if (!eventInfoHandle.isValid()) {
136  ATH_MSG_ERROR ("Could not retrieve EventInfo " << eventInfoHandle.key());
137  return StatusCode::FAILURE;
138  }
139  const xAOD::EventInfo* EventInfo = eventInfoHandle.cptr();
140 
141  // Decorate EventInfo with the HF Classification and the simple version
142  SG::WriteDecorHandle<xAOD::EventInfo, int> decorator_HFClassification(m_hfDecorKey, ctx);
143  decorator_HFClassification(*EventInfo) = hfclassif;
144 
145  SG::WriteDecorHandle<xAOD::EventInfo, int> decorator_SimpleHFClassification(m_SimplehfDecorKey, ctx);
146  decorator_SimpleHFClassification(*EventInfo) = simpleclassif;
147 
148  return StatusCode::SUCCESS;
149  }
150 }
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_SimplehfDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_SimplehfDecorKey
Definition: ClassifyAndCalculateHFAugmentation.h:97
DerivationFramework::ClassifyAndCalculateHFAugmentation::addBranches
virtual StatusCode addBranches() const override
Pass the thinning service
Definition: ClassifyAndCalculateHFAugmentation.cxx:99
DerivationFramework::ClassifyAndCalculateHFAugmentation::~ClassifyAndCalculateHFAugmentation
~ClassifyAndCalculateHFAugmentation()
Definition: ClassifyAndCalculateHFAugmentation.cxx:45
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_JetMatchingTool_Tool
ToolHandle< DerivationFramework::JetMatchingTool > m_JetMatchingTool_Tool
Definition: ClassifyAndCalculateHFAugmentation.h:111
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: ClassifyAndCalculateHFAugmentation.h:94
SG::WriteDecorHandleKey::assign
virtual StatusCode assign(const std::string &sgkey) override
Change the key of the object to which we're referring.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::ClassifyAndCalculateHFAugmentation::ClassifyAndCalculateHFAugmentation
ClassifyAndCalculateHFAugmentation(const std::string &t, const std::string &n, const IInterface *p)
Definition: ClassifyAndCalculateHFAugmentation.cxx:27
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_HFClassification_tool
ToolHandle< DerivationFramework::ClassifyAndCalculateHFTool > m_HFClassification_tool
Definition: ClassifyAndCalculateHFAugmentation.h:112
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_HadronOriginClassifier_Tool
ToolHandle< DerivationFramework::HadronOriginClassifier > m_HadronOriginClassifier_Tool
Definition: ClassifyAndCalculateHFAugmentation.h:113
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
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:93
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_hfDecorationName
Gaudi::Property< std::string > m_hfDecorationName
Definition: ClassifyAndCalculateHFAugmentation.h:103
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
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:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework::ClassifyAndCalculateHFAugmentation::finalize
virtual StatusCode finalize() override
Definition: ClassifyAndCalculateHFAugmentation.cxx:89
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:42
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
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
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_SimplehfDecorationName
Gaudi::Property< std::string > m_SimplehfDecorationName
Definition: ClassifyAndCalculateHFAugmentation.h:104
ReadHandle.h
Handle class for reading from StoreGate.
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_truthParticlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticlesKey
Definition: ClassifyAndCalculateHFAugmentation.h:92
DerivationFramework::ClassifyAndCalculateHFAugmentation::m_hfDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_hfDecorKey
Definition: ClassifyAndCalculateHFAugmentation.h:96
DerivationFramework::ClassifyAndCalculateHFAugmentation::initialize
virtual StatusCode initialize() override
Definition: ClassifyAndCalculateHFAugmentation.cxx:53