ATLAS Offline Software
JetMatchingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // JetMatchingTool.cxx //
8 // Implementation file for class JetMatchingTool //
9 // Author: Adrian Berrocal Guardia <adrian.berrocal.guardia@cern.ch> //
10 // //
12 
14 
15 namespace DerivationFramework{
16 
17  /*
18  ---------------------------------------------------------------------------------------------------------------------------------------
19  ------------------------------------------------------- Constructor/Destructor --------------------------------------------------------
20  ---------------------------------------------------------------------------------------------------------------------------------------
21  */
22 
23  JetMatchingTool::JetMatchingTool(const std::string& t, const std::string& n, const IInterface* p) : AthAlgTool(t,n,p){
24  declareInterface<DerivationFramework::JetMatchingTool>(this);
25  }
26 
28  }
29 
30  /*
31  ---------------------------------------------------------------------------------------------------------------------------------------
32  --------------------------------------------------------- Initialize/Finalize ---------------------------------------------------------
33  ---------------------------------------------------------------------------------------------------------------------------------------
34  */
35 
37 
38  ATH_MSG_INFO("Initialize");
39 
40  // Print the cuts.
41 
42  ATH_MSG_INFO("Cut on the pt of the jets: " << m_jetPtCut);
43  ATH_MSG_INFO("Cut on the eta of the jets: " << m_jetEtaCut);
44  ATH_MSG_INFO("Cut for deltaR to consider a match: " << m_drCut);
45 
46  return StatusCode::SUCCESS;
47  }
48 
50  return StatusCode::SUCCESS;
51  }
52 
53  /*
54  --------------------------------------------------------------------------------------------------------------------------------------
55  ---------------------------------------------------------- Hadron Matching ----------------------------------------------------------
56  --------------------------------------------------------------------------------------------------------------------------------------
57  */
58 
59  std::map<const xAOD::Jet*, std::vector<xAOD::TruthParticleContainer::const_iterator>> JetMatchingTool::matchHadronsToJets(const xAOD::TruthParticleContainer* hadrons, const xAOD::JetContainer* jets) const{
60 
61  // NOTE (not from Adria): The matching is unique for hadrons but not for jets
62  // Need to cut on jets before matching, not for hadrons where we can do it later.
63  // However, the current HFClassification is matching hadrons to the closest jet before the cuts and then cut on jets later - was this studied
64 
65  // Declare a map variable to store the list of truth particles that are matched to each jet.
66 
67  std::map<const xAOD::Jet*, std::vector<xAOD::TruthParticleContainer::const_iterator>> particleMatch;
68 
69  // Match each truth particle to a jet.
70  // Use a for to go through the truth particles.
71 
73 
74  // Create a jet object to store the closest one to the truth particle that is being considered.
75 
76  const xAOD::Jet* holder = nullptr;
77 
78  // Define a variable to store the smallest deltaR between the jets and the hadron.
79 
80  float drmin=999999;
81 
82  // Use a for to go through the jets.
83 
84  for(const xAOD::Jet* jet : *jets){
85 
86  // Check if cuts are applied on jets.
87 
88  if(m_jetPtCut>0 || m_jetEtaCut>=0){
89 
90  // In this case, cuts should be applied.
91  // The jet is not considered if the cuts are not satisfied.
92 
93  if(jet->p4().Pt()<m_jetPtCut) continue;
94  if(fabs(jet->p4().Eta())>m_jetEtaCut) continue;
95  }
96 
97  // Compute deltaR between the jet and the hadron and check if it is smaller than drmin.
98  // If it is smaller, save the jet in holder and dr in drmin.
99 
100  float dr = jet->p4().DeltaR((*hadron)->p4());
101 
102  if(dr<drmin){
103  drmin=dr;
104  holder=jet;
105  }
106 
107  }
108 
109  // If the smallest drmin is smaller than drcut, then the truth particle is matched to the jet holder.
110  // Hence, save truth particle in particleMatch to the position that corresponds to jet holder.
111 
112  if(drmin<m_drCut){
113  particleMatch[holder].push_back(hadron);
114  }
115 
116  }
117 
118  // Return the map particleMatch
119 
120  return particleMatch;
121  }
122 
123 }
DerivationFramework::JetMatchingTool::matchHadronsToJets
std::map< const xAOD::Jet *, std::vector< xAOD::TruthParticleContainer::const_iterator > > matchHadronsToJets(const xAOD::TruthParticleContainer *hadrons, const xAOD::JetContainer *jets) const
Definition: JetMatchingTool.cxx:59
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
MCTruthPartClassifier::hadron
@ hadron
Definition: TruthClassifiers.h:148
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::JetMatchingTool::initialize
virtual StatusCode initialize() override
Definition: JetMatchingTool.cxx:36
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::JetMatchingTool::m_jetEtaCut
Gaudi::Property< float > m_jetEtaCut
Definition: JetMatchingTool.h:83
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
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::JetMatchingTool::JetMatchingTool
JetMatchingTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: JetMatchingTool.cxx:23
DerivationFramework::JetMatchingTool::m_jetPtCut
Gaudi::Property< float > m_jetPtCut
Definition: JetMatchingTool.h:82
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::JetMatchingTool::~JetMatchingTool
virtual ~JetMatchingTool()
Definition: JetMatchingTool.cxx:27
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetMatchingTool.h
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::JetMatchingTool::finalize
virtual StatusCode finalize() override
Definition: JetMatchingTool.cxx:49
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
DerivationFramework::JetMatchingTool::m_drCut
Gaudi::Property< float > m_drCut
Definition: JetMatchingTool.h:84