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  }
25 
27  }
28 
29  /*
30  ---------------------------------------------------------------------------------------------------------------------------------------
31  --------------------------------------------------------- Initialize/Finalize ---------------------------------------------------------
32  ---------------------------------------------------------------------------------------------------------------------------------------
33  */
34 
36 
37  ATH_MSG_INFO("Initialize");
38 
39  // Print the cuts.
40 
41  ATH_MSG_INFO("Cut on the pt of the jets: " << m_jetPtCut);
42  ATH_MSG_INFO("Cut on the eta of the jets: " << m_jetEtaCut);
43  ATH_MSG_INFO("Cut for deltaR to consider a match: " << m_drCut);
44 
45  return StatusCode::SUCCESS;
46  }
47 
49  return StatusCode::SUCCESS;
50  }
51 
52  /*
53  --------------------------------------------------------------------------------------------------------------------------------------
54  ---------------------------------------------------------- Hadron Matching ----------------------------------------------------------
55  --------------------------------------------------------------------------------------------------------------------------------------
56  */
57 
58  std::map<const xAOD::Jet*, std::vector<xAOD::TruthParticleContainer::const_iterator>> JetMatchingTool::matchHadronsToJets(const xAOD::TruthParticleContainer* hadrons, const xAOD::JetContainer* jets) const{
59 
60  // NOTE (not from Adria): The matching is unique for hadrons but not for jets
61  // Need to cut on jets before matching, not for hadrons where we can do it later.
62  // However, the current HFClassification is matching hadrons to the closest jet before the cuts and then cut on jets later - was this studied
63 
64  // Declare a map variable to store the list of truth particles that are matched to each jet.
65 
66  std::map<const xAOD::Jet*, std::vector<xAOD::TruthParticleContainer::const_iterator>> particleMatch;
67 
68  // Match each truth particle to a jet.
69  // Use a for to go through the truth particles.
70 
72 
73  // Create a jet object to store the closest one to the truth particle that is being considered.
74 
75  const xAOD::Jet* holder = nullptr;
76 
77  // Define a variable to store the smallest deltaR between the jets and the hadron.
78 
79  float drmin=999999;
80 
81  // Use a for to go through the jets.
82 
83  for(const xAOD::Jet* jet : *jets){
84 
85  // Check if cuts are applied on jets.
86 
87  if(m_jetPtCut>0 || m_jetEtaCut>=0){
88 
89  // In this case, cuts should be applied.
90  // The jet is not considered if the cuts are not satisfied.
91 
92  if(jet->p4().Pt()<m_jetPtCut) continue;
93  if(fabs(jet->p4().Eta())>m_jetEtaCut) continue;
94  }
95 
96  // Compute deltaR between the jet and the hadron and check if it is smaller than drmin.
97  // If it is smaller, save the jet in holder and dr in drmin.
98 
99  float dr = jet->p4().DeltaR((*hadron)->p4());
100 
101  if(dr<drmin){
102  drmin=dr;
103  holder=jet;
104  }
105 
106  }
107 
108  // If the smallest drmin is smaller than drcut, then the truth particle is matched to the jet holder.
109  // Hence, save truth particle in particleMatch to the position that corresponds to jet holder.
110 
111  if(drmin<m_drCut){
112  particleMatch[holder].push_back(hadron);
113  }
114 
115  }
116 
117  // Return the map particleMatch
118 
119  return particleMatch;
120  }
121 
122 }
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:58
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
python.plotting.G4DebuggerConfig.hadrons
list hadrons
Definition: G4DebuggerConfig.py:24
DerivationFramework::JetMatchingTool::initialize
virtual StatusCode initialize() override
Definition: JetMatchingTool.cxx:35
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:111
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::JetMatchingTool::m_jetEtaCut
Gaudi::Property< float > m_jetEtaCut
Definition: JetMatchingTool.h:79
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
beamspotman.n
n
Definition: beamspotman.py:729
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:78
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::JetMatchingTool::~JetMatchingTool
virtual ~JetMatchingTool()
Definition: JetMatchingTool.cxx:26
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetMatchingTool.h
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::JetMatchingTool::finalize
virtual StatusCode finalize() override
Definition: JetMatchingTool.cxx:48
DerivationFramework::JetMatchingTool::m_drCut
Gaudi::Property< float > m_drCut
Definition: JetMatchingTool.h:80