ATLAS Offline Software
MuJetOverlapTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // System includes
6 #include <typeinfo>
7 
8 // Framework includes
11 
12 // Local includes
16 
17 namespace
18 {
20  const double GeV = 1e3;
21 }
22 
23 namespace ORUtils
24 {
25 
26  //---------------------------------------------------------------------------
27  // Constructor
28  //---------------------------------------------------------------------------
31  {
32  declareProperty("BJetLabel", m_bJetLabel = "",
33  "Input b-jet flag. Disabled by default.");
34  declareProperty("NumJetTrk", m_numJetTrk = 3,
35  "Min number of jet tracks to keep jet and remove muon");
36  declareProperty("ApplyRelPt", m_applyRelPt = false,
37  "Toggle mu/jet relative PT requirements to prioritize jet");
38  declareProperty("MuJetPtRatio", m_muJetPtRatio = 0.5,
39  "Mu/jet PT ratio threshold to remove a jet");
40  declareProperty("MuJetTrkPtRatio", m_muJetTrkPtRatio = 0.7,
41  "Mu/jetTrk PT ratio threshold to remove a jet");
42  declareProperty("JetNumTrackDecoration", m_jetNumTrkDec = "",
43  "User-defined decoration for jet numTrack");
44  declareProperty("JetSumTrackPTDecoration", m_jetSumTrkPtDec = "",
45  "User-defined decoration for jet sumTrackPT");
46  declareProperty("UseGhostAssociation", m_useGhostAssociation = true,
47  "Activate ghost-association mapping for jet removals");
48  declareProperty("InnerDR", m_innerDR = 0.2,
49  "Flat inner cone for removing jets");
50  declareProperty("OuterDR", m_outerDR = 0.4,
51  "Flat outer cone for removing muons");
52  declareProperty("UseSlidingDR", m_useSlidingDR = false,
53  "Enables sliding dR outer cone = c1 + c2/MuPt");
54  declareProperty("SlidingDRC1", m_slidingDRC1 = 0.04,
55  "The constant offset for sliding dR");
56  declareProperty("SlidingDRC2", m_slidingDRC2 = 10.*GeV,
57  "The inverse muon pt factor for sliding dR");
58  declareProperty("SlidingDRMaxCone", m_slidingDRMaxCone = 0.4,
59  "Maximum allowed size of sliding dR cone");
60  declareProperty("UseRapidity", m_useRapidity = true,
61  "Calculate delta-R using rapidity");
62  declareProperty("PVContainerName", m_PVContName = "PrimaryVertices",
63  "PV Container to use");
64  }
65 
66  //---------------------------------------------------------------------------
67  // Initialize
68  //---------------------------------------------------------------------------
70  {
71  // Initialize the b-jet helper
72  if(!m_bJetLabel.empty()) {
73  ATH_MSG_DEBUG("Configuring btag-aware OR with btag label: " << m_bJetLabel);
74  m_bJetHelper = std::make_unique<BJetHelper>(m_bJetLabel);
75  }
76 
77  // Initialize the matcher for the 'inner' cone.
79  ATH_MSG_DEBUG("Configuring ghost association + dR matching for jet-mu OR "
80  "with inner cone size " << m_innerDR);
81  m_dRMatchCone1 = std::make_unique<MuJetGhostDRMatcher>(m_innerDR, m_useRapidity);
82  }
83  else {
84  ATH_MSG_DEBUG("Configuring mu-jet inner cone size " << m_innerDR);
85  m_dRMatchCone1 = std::make_unique<DeltaRMatcher>(m_innerDR, m_useRapidity);
86  }
87 
88  // Use sliding dR or flat dR for the 'outer' cone.
89  if(m_useSlidingDR) {
90  ATH_MSG_DEBUG("Configuring sliding outer cone for mu-jet OR with " <<
91  "constants C1 = " << m_slidingDRC1 << ", C2 = " <<
92  m_slidingDRC2 << ", MaxCone = " << m_slidingDRMaxCone);
94  std::make_unique<SlidingDeltaRMatcher>
96  }
97  else {
98  ATH_MSG_DEBUG("Configuring mu-jet outer cone size " << m_outerDR);
99  m_dRMatchCone2 = std::make_unique<DeltaRMatcher>(m_outerDR, m_useRapidity);
100  }
101 
102  // Additional config printouts
103  ATH_MSG_DEBUG("Mu-jet matching config: NumJetTrk " << m_numJetTrk <<
104  " ApplyRelPt " << m_applyRelPt <<
105  " MuJetPtRatio " << m_muJetPtRatio <<
106  " MuJetTrkPtRatio " << m_muJetTrkPtRatio);
107  if(!m_jetNumTrkDec.empty()) {
108  ATH_MSG_DEBUG("Using user-defined JetNumTrackDecoration " << m_jetNumTrkDec);
109  }
110  if(!m_jetSumTrkPtDec.empty()) {
111  ATH_MSG_DEBUG("Using user-defined JetSumTrackPTDecoration " << m_jetSumTrkPtDec);
112  }
113 
114  return StatusCode::SUCCESS;
115  }
116 
117  //---------------------------------------------------------------------------
118  // Identify overlaps
119  //---------------------------------------------------------------------------
122  const xAOD::IParticleContainer& cont2) const
123  {
124  // Check the container types
125  if(typeid(cont1) != typeid(xAOD::MuonContainer) &&
126  typeid(cont1) != typeid(ConstDataVector<xAOD::MuonContainer>)) {
127  ATH_MSG_ERROR("First container arg is not of type MuonContainer!");
128  return StatusCode::FAILURE;
129  }
130  if(typeid(cont2) != typeid(xAOD::JetContainer) &&
131  typeid(cont2) != typeid(ConstDataVector<xAOD::JetContainer>)) {
132  ATH_MSG_ERROR("Second container arg is not of type JetContainer!");
133  return StatusCode::FAILURE;
134  }
135  ATH_CHECK( findOverlaps(static_cast<const xAOD::MuonContainer&>(cont1),
136  static_cast<const xAOD::JetContainer&>(cont2)) );
137  return StatusCode::SUCCESS;
138  }
139 
140  //---------------------------------------------------------------------------
141  // Identify overlaps
142  //---------------------------------------------------------------------------
145  const xAOD::JetContainer& jets) const
146  {
147  ATH_MSG_DEBUG("Removing overlapping muons and jets");
148 
149  // Initialize output decorations if necessary
150  m_decHelper->initializeDecorations(muons);
151  m_decHelper->initializeDecorations(jets);
152 
153  // Retrieve the primary vertex for later reference
154  size_t vtxIdx = 0;
155  if(m_jetNumTrkDec.empty() && m_jetSumTrkPtDec.empty()) {
156  auto vtx = getPrimVtx();
157  ATH_CHECK(vtx != nullptr);
158  vtxIdx = vtx->index();
159  }
160 
161  // Remove suspicious jets that overlap with muons.
162  for(const auto muon : muons){
163  if(!m_decHelper->isSurvivingObject(*muon)) continue;
164 
165  for(const auto jet : jets){
166  if(!m_decHelper->isSurvivingObject(*jet)) continue;
167 
168  // Don't reject user-defined b-tagged jets
169  if(m_bJetHelper && m_bJetHelper->isBJet(*jet)) continue;
170 
171  // Get the number of tracks and the sumPT of those tracks
172  int nTrk = getNumTracks(*jet, vtxIdx);
173  float sumTrkPt = getSumTrackPt(*jet, vtxIdx);
174 
175  // Don't reject jets with high track multiplicity and
176  // high relative PT ratio
177  bool highNumTrk = nTrk >= m_numJetTrk;
178  bool highRelPt = false;
179 
180  if (sumTrkPt < FLT_MIN){
181  highRelPt = (muon->pt()/jet->pt() < m_muJetPtRatio);
182  }
183  else{
184  highRelPt = (muon->pt()/jet->pt() < m_muJetPtRatio ||
185  muon->pt()/sumTrkPt < m_muJetTrkPtRatio);
186  }
187 
188  if(highNumTrk && (!m_applyRelPt || highRelPt)) continue;
189 
190  if(m_dRMatchCone1->objectsMatch(*muon, *jet)){
192  }
193  }
194  }
195 
196  // Remove muons from remaining overlapping jets
197  for(const auto jet : jets){
198  if(!m_decHelper->isSurvivingObject(*jet)) continue;
199 
200  for(const auto muon : muons){
201  if(!m_decHelper->isSurvivingObject(*muon)) continue;
202 
203  if(m_dRMatchCone2->objectsMatch(*muon, *jet)){
205  }
206  }
207  }
208 
209  return StatusCode::SUCCESS;
210  }
211 
212  //---------------------------------------------------------------------------
213  // Retrieve the primary vertex
214  //---------------------------------------------------------------------------
216  {
217  const xAOD::VertexContainer* vertices = nullptr;
218  if(evtStore()->retrieve(vertices, m_PVContName).isSuccess()) {
219  for(auto vtx : *vertices) {
220  if(vtx->vertexType() == xAOD::VxType::PriVtx)
221  return vtx;
222  }
223  }
224  else {
225  ATH_MSG_WARNING("Failed to retrieve " << m_PVContName);
226  }
227  // No PV found. We cannot execute the OR recommendations.
228  ATH_MSG_FATAL("No primary vertex in the PrimaryVertices container!");
229  return nullptr;
230  }
231 
232  //---------------------------------------------------------------------------
233  // Get the number of tracks in a jet
234  //---------------------------------------------------------------------------
235  int MuJetOverlapTool::getNumTracks(const xAOD::Jet& jet, size_t vtxIdx) const
236  {
237  // Use the user decoration if configured
238  if(!m_jetNumTrkDec.empty()) {
240  return jetNumTrkAcc(jet);
241  }
242  static const SG::ConstAccessor< std::vector<int> > acc("NumTrkPt500");
243  return acc(jet)[vtxIdx];
244  }
245 
246  //---------------------------------------------------------------------------
247  // Get the sum track pt of a jet
248  //---------------------------------------------------------------------------
249  float MuJetOverlapTool::getSumTrackPt(const xAOD::Jet& jet, size_t vtxIdx) const
250  {
251  // Use the user decoration if configured
252  if(!m_jetSumTrkPtDec.empty()) {
254  return jetSumTrkPtAcc(jet);
255  }
256  static const SG::ConstAccessor< std::vector<float> > acc("SumPtTrkPt500");
257  return acc(jet)[vtxIdx];
258  }
259 
260 } // namespace ORUtils
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ORUtils::MuJetOverlapTool::getPrimVtx
const xAOD::Vertex * getPrimVtx() const
Retrieve the primary vertex used to count jet tracks.
Definition: MuJetOverlapTool.cxx:215
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
MuJetOverlapTool.h
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:18
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ORUtils::MuJetOverlapTool::m_jetNumTrkDec
std::string m_jetNumTrkDec
Optional user decoration for jet numTrack of type 'int'.
Definition: MuJetOverlapTool.h:122
ORUtils::MuJetOverlapTool::getSumTrackPt
float getSumTrackPt(const xAOD::Jet &jet, size_t vtxIdx) const
Get the sum trk pt in a jet w.r.t. requested vertex.
Definition: MuJetOverlapTool.cxx:249
ORUtils::MuJetOverlapTool::m_bJetLabel
std::string m_bJetLabel
Input jet decoration which labels a bjet.
Definition: MuJetOverlapTool.h:109
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
ORUtils::MuJetOverlapTool::m_slidingDRC1
double m_slidingDRC1
C1, the constant offset in sliding dR.
Definition: MuJetOverlapTool.h:138
ORUtils::MuJetOverlapTool::getNumTracks
int getNumTracks(const xAOD::Jet &jet, size_t vtxIdx) const
Get the number of tracks in a jet w.r.t. requested vertex.
Definition: MuJetOverlapTool.cxx:235
ORUtils::MuJetOverlapTool::m_innerDR
float m_innerDR
Inner dR cone within which jets get removed.
Definition: MuJetOverlapTool.h:130
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
MuJetGhostDRMatcher.h
SG::ConstAccessor< int >
ORUtils
Definition: AltMuJetOverlapTool.h:20
ORUtils::MuJetOverlapTool::m_numJetTrk
int m_numJetTrk
Minimum number of jet tracks to prioritize the jet.
Definition: MuJetOverlapTool.h:112
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ORUtils::MuJetOverlapTool::m_useGhostAssociation
bool m_useGhostAssociation
Use ghost association in matching to remove jets.
Definition: MuJetOverlapTool.h:127
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
ORUtils::MuJetOverlapTool::m_muJetPtRatio
float m_muJetPtRatio
PT ratio threshold for vetoing the jet.
Definition: MuJetOverlapTool.h:117
ORUtils::BaseOverlapTool
Common base class tool for overlap tools.
Definition: BaseOverlapTool.h:38
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
ORUtils::MuJetOverlapTool::m_muJetTrkPtRatio
float m_muJetTrkPtRatio
PT ratio threshold for vetoing the jet. Uses sum of jet track PT.
Definition: MuJetOverlapTool.h:119
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
ORUtils::BaseOverlapTool::m_decHelper
std::unique_ptr< OverlapDecorationHelper > m_decHelper
Helper for handling input/output decorations.
Definition: BaseOverlapTool.h:95
ORUtils::MuJetOverlapTool::m_slidingDRMaxCone
double m_slidingDRMaxCone
MaxCone, the upper limit of the sliding cone.
Definition: MuJetOverlapTool.h:142
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ORUtils::MuJetOverlapTool::m_dRMatchCone1
std::unique_ptr< IParticleAssociator > m_dRMatchCone1
Delta-R matcher for the inner cone.
Definition: MuJetOverlapTool.h:159
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DeltaRMatcher.h
ORUtils::MuJetOverlapTool::m_slidingDRC2
double m_slidingDRC2
C1, the inverse pt factor in sliding dR.
Definition: MuJetOverlapTool.h:140
ORUtils::MuJetOverlapTool::MuJetOverlapTool
MuJetOverlapTool(const std::string &name)
Create proper constructor for Athena.
Definition: MuJetOverlapTool.cxx:29
ORUtils::MuJetOverlapTool::m_PVContName
std::string m_PVContName
PV Container to use.
Definition: MuJetOverlapTool.h:148
ORUtils::MuJetOverlapTool::m_bJetHelper
std::unique_ptr< BJetHelper > m_bJetHelper
BJet helper.
Definition: MuJetOverlapTool.h:156
ORUtils::MuJetOverlapTool::m_useSlidingDR
bool m_useSlidingDR
Toggle sliding dR overlap removal for removing muons.
Definition: MuJetOverlapTool.h:136
ORUtils::MuJetOverlapTool::m_applyRelPt
bool m_applyRelPt
Toggle PT ratio criteria TODO: rename to m_applyPtRatio.
Definition: MuJetOverlapTool.h:115
ORUtils::BaseOverlapTool::handleOverlap
virtual StatusCode handleOverlap(const xAOD::IParticle *testParticle, const xAOD::IParticle *refParticle) const
Common helper method to handle an overlap result.
Definition: BaseOverlapTool.cxx:64
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
ORUtils::MuJetOverlapTool::initializeDerived
virtual StatusCode initializeDerived() override
Initialize the tool.
Definition: MuJetOverlapTool.cxx:69
ORUtils::MuJetOverlapTool::m_outerDR
float m_outerDR
Outer dR cone within which muons get removed.
Definition: MuJetOverlapTool.h:133
ORUtils::MuJetOverlapTool::m_useRapidity
bool m_useRapidity
Calculate deltaR using rapidity.
Definition: MuJetOverlapTool.h:145
ORUtils::MuJetOverlapTool::m_dRMatchCone2
std::unique_ptr< IParticleAssociator > m_dRMatchCone2
Delta-R matcher for the outer cone.
Definition: MuJetOverlapTool.h:161
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
ORUtils::MuJetOverlapTool::findOverlaps
virtual StatusCode findOverlaps(const xAOD::IParticleContainer &cont1, const xAOD::IParticleContainer &cont2) const override
Identify overlapping muons and jets.
Definition: MuJetOverlapTool.cxx:121
ORUtils::MuJetOverlapTool::m_jetSumTrkPtDec
std::string m_jetSumTrkPtDec
Optional user decoration for jet sumTrackPT of type 'float'.
Definition: MuJetOverlapTool.h:124