ATLAS Offline Software
Loading...
Searching...
No Matches
AltMuJetOverlapTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// System includes
6#include <typeinfo>
7#include <limits>
8
9// Framework includes
13
14// Local includes
17
18namespace
19{
21 const double GeV = 1e3; // FIXME local unit definition!!
22}
23
24namespace ORUtils
25{
26
27 //---------------------------------------------------------------------------
28 // Constructor
29 //---------------------------------------------------------------------------
31 : BaseOverlapTool(name)
32 {
33 declareProperty("BJetLabel", m_bJetLabel = "",
34 "Input b-jet flag. Disabled by default.");
35 // Disabled by default
36 declareProperty("NumJetTrk", m_numJetTrk = std::numeric_limits<int>::max(),
37 "Min number of jet tracks to keep jet and remove muon");
38 // Disabled by default
39 declareProperty("MuJetPtRatio", m_muJetPtRatio = 0.,
40 "Max PT ratio to keep jet and remove muon");
41 declareProperty("InnerDR", m_innerDR = 0.2,
42 "Inner cone for removing jets");
43 declareProperty("SlidingDRC1", m_slidingDRC1 = 0.04,
44 "The constant offset for sliding dR");
45 declareProperty("SlidingDRC2", m_slidingDRC2 = 10.*GeV,
46 "The inverse muon pt factor for sliding dR");
47 declareProperty("SlidingDRMaxCone",
48 m_slidingDRMaxCone = std::numeric_limits<double>::max(),
49 "Maximum allowed size of sliding dR cone");
50 declareProperty("UseRapidity", m_useRapidity = true,
51 "Calculate delta-R using rapidity");
52 declareProperty("PVContainerName", m_PVContName = "PrimaryVertices",
53 "PV Container to use");
54 }
55
56 //---------------------------------------------------------------------------
57 // Initialize
58 //---------------------------------------------------------------------------
60 {
61 // Initialize the b-jet helper
62 if(!m_bJetLabel.empty())
63 resetAccessor (m_accessors->m_bJetAcc, *m_accessors, m_bJetLabel);
64
65 // Initialize the inner cone dR matcher
67 std::make_unique<DeltaRMatcher> (m_innerDR, m_useRapidity);
69 addSubtool(*m_dRMatchCone1);
70 // Initialize the sliding dR matcher
72 std::make_unique<SlidingDeltaRMatcher>
75 addSubtool(*m_dRMatchCone2);
76
77 resetAccessor (m_accessors->m_vtxContainerAcc, *m_accessors, m_PVContName, {.addMTDependency = true});
78
79 return StatusCode::SUCCESS;
80 }
81
82 //---------------------------------------------------------------------------
83 // Identify overlaps
84 //---------------------------------------------------------------------------
88 columnar::EventContextId eventContext) const
89 {
90 // Check the container types
91 ATH_CHECK (checkForXAODContainer<xAOD::MuonContainer>(cont1, "First container arg is not of type MuonContainer!"));
92 ATH_CHECK (checkForXAODContainer<xAOD::JetContainer>(cont2, "Second container arg is not of type JetContainer!"));
93
94 ATH_CHECK( internalFindOverlaps(cont1, cont2, eventContext));
95 return StatusCode::SUCCESS;
96 }
97
98 //---------------------------------------------------------------------------
99 // Identify overlaps
100 //---------------------------------------------------------------------------
104 columnar::EventContextId eventContext) const
105 {
106 ATH_MSG_DEBUG("Removing overlapping muons and jets");
107 auto& acc = *m_accessors;
108
109 // Initialize output decorations if necessary
112
113 // Remove jets that overlap with muons in first cone.
114 for(const auto muon : muons){
115 if(!isSurvivingObject(muon)) continue;
116
117 for(const auto jet : jets){
118 if(!isSurvivingObject(jet)) continue;
119 // User-defined jet criteria include b-tagging,
120 // numTrack, and the mu/jet PT ratio
121 if(!m_bJetLabel.empty() && acc.m_bJetAcc(jet)) continue;
122 if(getNumTracks(jet, eventContext) >= m_numJetTrk) continue;
123 float ptRatio = muon(acc.m_muonPtAcc) / jet(acc.m_jetPtAcc);
124 if(ptRatio < m_muJetPtRatio) continue;
125
126 if(m_dRMatchCone1->objectsMatch(jet, muon)){
127 ATH_CHECK( handleOverlap(jet, muon) );
128 }
129 }
130 }
131
132 // Remove muons from remaining overlapping jets
133 for(const auto jet : jets){
134 if(!isSurvivingObject(jet)) continue;
135
136 for(const auto muon : muons){
137 if(!isSurvivingObject(muon)) continue;
138
139 if(m_dRMatchCone2->objectsMatch(muon, jet)){
140 ATH_CHECK( handleOverlap(muon, jet) );
141 }
142 }
143 }
144
145 return StatusCode::SUCCESS;
146 }
147
148 //---------------------------------------------------------------------------
149 // Retrieve the primary vertex
150 //---------------------------------------------------------------------------
152 {
153 auto& acc = *m_accessors;
154 if (!acc.m_vtxContainerAcc.isAvailable(eventContext)) {
155 ATH_MSG_WARNING("Primary vertex container is not available");
156 return -1;
157 }
158 auto vertices = acc.m_vtxContainerAcc(eventContext);
159 for(auto vtx : vertices) {
160 if(vtx(acc.m_vertexTypeAcc) == xAOD::VxType::PriVtx)
161 return vertices.getIndexInRange(vtx);
162 }
163 ATH_MSG_WARNING("No primary vertex found");
164 return -1;
165 }
166
167 //---------------------------------------------------------------------------
168 // Retrieve the primary vertex
169 //---------------------------------------------------------------------------
171 {
172 // Find the primary vertex
173 auto& acc = *m_accessors;
174 auto vtx = getPrimVtxIndex(eventContext);
175 if(vtx == -1) return -1;
176 return acc.m_numTrkPt500Acc(jet)[vtx];
177 }
178
179} // namespace ORUtils
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
DataVector adapter that acts like it holds const pointers.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual StatusCode initializeDerived() override
Initialize the tool.
virtual StatusCode internalFindOverlaps(columnar::Particle1Range muons, columnar::Particle2Range jets, columnar::EventContextId eventContext) const
Identify overlapping muons and jets.
double m_slidingDRC1
Outer cone C1, the constant offset in sliding dR.
float m_muJetPtRatio
Maximum ratio of mu/jet PT to keep an overlapping jet.
double m_slidingDRC2
Outer cone C2, the inverse pt factor in sliding dR.
std::unique_ptr< IParticleAssociator > m_dRMatchCone2
Delta-R matcher for the outer cone.
AltMuJetOverlapTool(const std::string &name)
Create proper constructor for Athena.
std::string m_bJetLabel
Input jet decoration which labels a bjet.
int m_numJetTrk
Minimum number of tracks to keep an overlapping jet.
virtual StatusCode findOverlaps(columnar::Particle1Range cont1, columnar::Particle2Range cont2, columnar::EventContextId eventContext) const override
Identify overlapping muons and jets.
float m_innerDR
Inner dR cone within which jets get removed.
int getPrimVtxIndex(columnar::EventContextId eventContext) const
Retrieve the primary vertex used to count jet tracks.
double m_slidingDRMaxCone
MaxCone, the upper limit of the sliding cone.
std::unique_ptr< IParticleAssociator > m_dRMatchCone1
Delta-R matcher for the inner cone.
bool m_useRapidity
Calculate deltaR using rapidity.
int getNumTracks(columnar::Particle2Id jet, columnar::EventContextId eventContext) const
Helper method to get the number of tracks in a jet w.r.t.
std::string m_PVContName
PV Container to use.
std::unique_ptr< Accessors > m_accessors
void initializeDecorations(columnar::Particle1Range container) const
BaseOverlapTool(const std::string &name)
Create proper constructor for Athena.
StatusCode handleOverlap(const columnar::ObjectId< CI1, CM > &testParticle, const columnar::ObjectId< CI2, CM > &refParticle) const
Common helper method to handle an overlap result.
bool isSurvivingObject(columnar::Particle1Id obj) const
StatusCode checkForXAODContainer(columnar::ObjectRange< CI, CM > cont, std::string_view message) const
check whether the container is of the right type
ObjectId< ContainerId::particle2 > Particle2Id
Definition ParticleDef.h:54
ObjectId< ContainerId::eventContext > EventContextId
ObjectRange< ContainerId::particle2 > Particle2Range
Definition ParticleDef.h:53
ObjectRange< ContainerId::particle1 > Particle1Range
Definition ParticleDef.h:47
@ Jet
The object is a jet.
Definition ObjectType.h:40
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ PriVtx
Primary vertex.