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  }
63 
64  //---------------------------------------------------------------------------
65  // Initialize
66  //---------------------------------------------------------------------------
68  {
69  // Initialize the b-jet helper
70  if(!m_bJetLabel.empty()) {
71  ATH_MSG_DEBUG("Configuring btag-aware OR with btag label: " << m_bJetLabel);
72  m_bJetHelper = std::make_unique<BJetHelper>(m_bJetLabel);
73  }
74 
75  // Initialize the matcher for the 'inner' cone.
77  ATH_MSG_DEBUG("Configuring ghost association + dR matching for jet-mu OR "
78  "with inner cone size " << m_innerDR);
79  m_dRMatchCone1 = std::make_unique<MuJetGhostDRMatcher>(m_innerDR, m_useRapidity);
80  }
81  else {
82  ATH_MSG_DEBUG("Configuring mu-jet inner cone size " << m_innerDR);
83  m_dRMatchCone1 = std::make_unique<DeltaRMatcher>(m_innerDR, m_useRapidity);
84  }
85 
86  // Use sliding dR or flat dR for the 'outer' cone.
87  if(m_useSlidingDR) {
88  ATH_MSG_DEBUG("Configuring sliding outer cone for mu-jet OR with " <<
89  "constants C1 = " << m_slidingDRC1 << ", C2 = " <<
90  m_slidingDRC2 << ", MaxCone = " << m_slidingDRMaxCone);
92  std::make_unique<SlidingDeltaRMatcher>
94  }
95  else {
96  ATH_MSG_DEBUG("Configuring mu-jet outer cone size " << m_outerDR);
97  m_dRMatchCone2 = std::make_unique<DeltaRMatcher>(m_outerDR, m_useRapidity);
98  }
99 
100  // Additional config printouts
101  ATH_MSG_DEBUG("Mu-jet matching config: NumJetTrk " << m_numJetTrk <<
102  " ApplyRelPt " << m_applyRelPt <<
103  " MuJetPtRatio " << m_muJetPtRatio <<
104  " MuJetTrkPtRatio " << m_muJetTrkPtRatio);
105  if(!m_jetNumTrkDec.empty()) {
106  ATH_MSG_DEBUG("Using user-defined JetNumTrackDecoration " << m_jetNumTrkDec);
107  }
108  if(!m_jetSumTrkPtDec.empty()) {
109  ATH_MSG_DEBUG("Using user-defined JetSumTrackPTDecoration " << m_jetSumTrkPtDec);
110  }
111 
112  return StatusCode::SUCCESS;
113  }
114 
115  //---------------------------------------------------------------------------
116  // Identify overlaps
117  //---------------------------------------------------------------------------
120  const xAOD::IParticleContainer& cont2) const
121  {
122  // Check the container types
123  if(typeid(cont1) != typeid(xAOD::MuonContainer) &&
124  typeid(cont1) != typeid(ConstDataVector<xAOD::MuonContainer>)) {
125  ATH_MSG_ERROR("First container arg is not of type MuonContainer!");
126  return StatusCode::FAILURE;
127  }
128  if(typeid(cont2) != typeid(xAOD::JetContainer) &&
129  typeid(cont2) != typeid(ConstDataVector<xAOD::JetContainer>)) {
130  ATH_MSG_ERROR("Second container arg is not of type JetContainer!");
131  return StatusCode::FAILURE;
132  }
133  ATH_CHECK( findOverlaps(static_cast<const xAOD::MuonContainer&>(cont1),
134  static_cast<const xAOD::JetContainer&>(cont2)) );
135  return StatusCode::SUCCESS;
136  }
137 
138  //---------------------------------------------------------------------------
139  // Identify overlaps
140  //---------------------------------------------------------------------------
143  const xAOD::JetContainer& jets) const
144  {
145  ATH_MSG_DEBUG("Removing overlapping muons and jets");
146 
147  // Initialize output decorations if necessary
148  m_decHelper->initializeDecorations(muons);
149  m_decHelper->initializeDecorations(jets);
150 
151  // Retrieve the primary vertex for later reference
152  size_t vtxIdx = 0;
153  if(m_jetNumTrkDec.empty() && m_jetSumTrkPtDec.empty()) {
154  auto vtx = getPrimVtx();
155  ATH_CHECK(vtx != nullptr);
156  vtxIdx = vtx->index();
157  }
158 
159  // Remove suspicious jets that overlap with muons.
160  for(const auto muon : muons){
161  if(!m_decHelper->isSurvivingObject(*muon)) continue;
162 
163  for(const auto jet : jets){
164  if(!m_decHelper->isSurvivingObject(*jet)) continue;
165 
166  // Don't reject user-defined b-tagged jets
167  if(m_bJetHelper && m_bJetHelper->isBJet(*jet)) continue;
168 
169  // Get the number of tracks and the sumPT of those tracks
170  int nTrk = getNumTracks(*jet, vtxIdx);
171  float sumTrkPt = getSumTrackPt(*jet, vtxIdx);
172 
173  // Don't reject jets with high track multiplicity and
174  // high relative PT ratio
175  bool highNumTrk = nTrk >= m_numJetTrk;
176  bool highRelPt = false;
177 
178  if (sumTrkPt < FLT_MIN){
179  highRelPt = (muon->pt()/jet->pt() < m_muJetPtRatio);
180  }
181  else{
182  highRelPt = (muon->pt()/jet->pt() < m_muJetPtRatio ||
183  muon->pt()/sumTrkPt < m_muJetTrkPtRatio);
184  }
185 
186  if(highNumTrk && (!m_applyRelPt || highRelPt)) continue;
187 
188  if(m_dRMatchCone1->objectsMatch(*muon, *jet)){
190  }
191  }
192  }
193 
194  // Remove muons from remaining overlapping jets
195  for(const auto jet : jets){
196  if(!m_decHelper->isSurvivingObject(*jet)) continue;
197 
198  for(const auto muon : muons){
199  if(!m_decHelper->isSurvivingObject(*muon)) continue;
200 
201  if(m_dRMatchCone2->objectsMatch(*muon, *jet)){
203  }
204  }
205  }
206 
207  return StatusCode::SUCCESS;
208  }
209 
210  //---------------------------------------------------------------------------
211  // Retrieve the primary vertex
212  //---------------------------------------------------------------------------
214  {
215  const char* contName = "PrimaryVertices";
216  const xAOD::VertexContainer* vertices = nullptr;
217  if(evtStore()->retrieve(vertices, contName).isSuccess()) {
218  for(auto vtx : *vertices) {
219  if(vtx->vertexType() == xAOD::VxType::PriVtx)
220  return vtx;
221  }
222  }
223  else {
224  ATH_MSG_WARNING("Failed to retrieve " << contName);
225  }
226  // No PV found. We cannot execute the OR recommendations.
227  ATH_MSG_FATAL("No primary vertex in the PrimaryVertices container!");
228  return nullptr;
229  }
230 
231  //---------------------------------------------------------------------------
232  // Get the number of tracks in a jet
233  //---------------------------------------------------------------------------
234  int MuJetOverlapTool::getNumTracks(const xAOD::Jet& jet, size_t vtxIdx) const
235  {
236  // Use the user decoration if configured
237  if(!m_jetNumTrkDec.empty()) {
239  return jetNumTrkAcc(jet);
240  }
241  static const SG::ConstAccessor< std::vector<int> > acc("NumTrkPt500");
242  return acc(jet)[vtxIdx];
243  }
244 
245  //---------------------------------------------------------------------------
246  // Get the sum track pt of a jet
247  //---------------------------------------------------------------------------
248  float MuJetOverlapTool::getSumTrackPt(const xAOD::Jet& jet, size_t vtxIdx) const
249  {
250  // Use the user decoration if configured
251  if(!m_jetSumTrkPtDec.empty()) {
253  return jetSumTrkPtAcc(jet);
254  }
255  static const SG::ConstAccessor< std::vector<float> > acc("SumPtTrkPt500");
256  return acc(jet)[vtxIdx];
257  }
258 
259 } // 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:213
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
MuJetOverlapTool.h
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:248
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:234
ORUtils::MuJetOverlapTool::m_innerDR
float m_innerDR
Inner dR cone within which jets get removed.
Definition: MuJetOverlapTool.h:130
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
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:571
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:581
ORUtils::MuJetOverlapTool::m_dRMatchCone1
std::unique_ptr< IParticleAssociator > m_dRMatchCone1
Delta-R matcher for the inner cone.
Definition: MuJetOverlapTool.h:156
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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_bJetHelper
std::unique_ptr< BJetHelper > m_bJetHelper
BJet helper.
Definition: MuJetOverlapTool.h:153
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:67
ORUtils::MuJetOverlapTool::m_outerDR
float m_outerDR
Outer dR cone within which muons get removed.
Definition: MuJetOverlapTool.h:133
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
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:158
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:119
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
ORUtils::MuJetOverlapTool::m_jetSumTrkPtDec
std::string m_jetSumTrkPtDec
Optional user decoration for jet sumTrackPT of type 'float'.
Definition: MuJetOverlapTool.h:124