ATLAS Offline Software
Loading...
Searching...
No Matches
InDetHardScatterSelectionTool.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// Local include(s):
6#include <memory>
7
8// FrameWork include(s):
12
13// EDM include(s):
16
17// Tool include(s)
21// Helper classes
22namespace {
24 class SumPt2 : public Sum {
25 public:
26 virtual float add(const float a, const float b, const float, const float) const override final {
27 return a + (b * b);
28 }
29 };
30 class SumPt : public Sum {
31 public:
32 virtual float add(const float a, const float b, const float, const float ) const override final {
33 return a + b;
34 }
35 };
36 class SumPtw : public Sum {
37 public:
38 virtual float add(const float a, const float b, const float jet_pt, const float mindR ) const override final {
39 return a + (b * b * jet_pt *jet_pt )/(mindR+0.0001);
40 }
41 };
42} // end: namespace
43
44// Constructor
48
49// Destructor
51= default;
52
53// Initialize
55{
56 // Print configuration
57 ATH_MSG_DEBUG("Initializing " << name() << "...");
58 ATH_MSG_DEBUG("Using RedoHardScatter: " << m_redoHardScatter);
59 ATH_MSG_DEBUG("Using SelectionMode: " << m_mode);
60 ATH_MSG_DEBUG("Using TrackSelectionTool: " << m_trkSelectTool);
61 ATH_MSG_DEBUG("Using ReturnDeco: " << m_returnDeco);
62 ATH_MSG_DEBUG("Using HardScatterLinkDeco: " << m_hardScatterDecoKey);
63 ATH_MSG_DEBUG("Using VertexContainer: " << m_vtxContKey);
64 ATH_MSG_DEBUG("Using JetContainer: " << m_jetContKey);
65
67 ATH_MSG_ERROR("RedoHardScatter and ReturnDeco cannot both be set to true.");
68 return StatusCode::FAILURE;
69 }
70
71 // If we are re-doing the hardscatter
73 ATH_MSG_DEBUG("Setting the hard scatter strategy to: " << m_mode);
74
75 // Determine how we will sum the track pt
76 switch (m_mode) {
78 m_sum = std::make_unique<::SumPt2>();
79 break;
80 }
82 m_sum = std::make_unique<::SumPt>();
83 break;
84 }
86 m_sum = std::make_unique<::SumPtw>();
87 break;
88 }
90 break;
91 }
92 default: {
93 ATH_MSG_ERROR("Unknown running mode : " << m_mode);
94 return StatusCode::FAILURE;
95 }
96 }
97
98 // Fetch our InDetTrackSelectionTool
99 if (m_redoHardScatter && !m_trkSelectTool.empty()) {
100 m_doTrkSelection = true;
101 ATH_CHECK(m_trkSelectTool.retrieve());
102 }
103
104 }
105
106 // Initialize our EventInfo container and decoration reads
107 ATH_CHECK(m_evtInfoKey.initialize());
109
110 // Initialize our vertex container read
111 ATH_CHECK(m_vtxContKey.initialize());
112
113 // Initialize our jet container read if it is non empty
114 ATH_CHECK(m_jetContKey.initialize(!m_jetContKey.empty()));
115
116 // Initialize the GNN score handle if relevant mode is selected
118
119 return StatusCode::SUCCESS;
120}
121
122// Finalize
124{
125 ATH_MSG_DEBUG("Finalizing " << name() << "...");
126
127 // Release our tool
129
130 return StatusCode::SUCCESS;
131}
132
134{
135 ATH_MSG_DEBUG("In getHardScatter(...) for " << name() << "...");
136
137 const EventContext& ctx = Gaudi::Hive::currentContext();
138
139 // If we are simply returning a decoration on the EventInfo:
140 if (m_returnDeco) {
142 if (!evtInfo.isValid()) {
143 ATH_MSG_ERROR("Could not open event info, returning nullptr!");
144 return nullptr;
145 }
147 const ElementLink<xAOD::VertexContainer>& vtxLink = hardScatterDeco(*evtInfo);
148 if (!vtxLink.isValid()) {
149 ATH_MSG_ERROR("Hardscatter vertex link is not valid, returning nullptr!");
150 return nullptr;
151 }
152 return *vtxLink;
153 }
154 //::get the jet container if the mode of HS selection is sumptw
155 const xAOD::JetContainer* jetCont{nullptr};
157 //::First get the jet containers
159 if (!jetContHandle.isValid()){
160 ATH_MSG_ERROR ("HardScatterSelectionTool configured to use jet collection "<<m_jetContKey.key()<<", but collection is not found!");
161 }
162 jetCont = jetContHandle.cptr();
163 }
164
165 float maxsum = -999.0;
166 float max_gnn_score = -999.0;
167 const xAOD::Vertex* hardscatter = nullptr;
168 for (const auto *const vtx : *vtxCont) {
169 float sum = 0.;
170 // If we are redoing the hardscatter determination:
171 if (m_redoHardScatter) {
173 for (const auto& trkLink : vtx->trackParticleLinks()) {
174 if (!trkLink.isValid()) continue;
175 if (m_doTrkSelection && !static_cast<bool>(m_trkSelectTool->accept(**trkLink, vtx))) continue;
176 if ( (*trkLink)->pt() >m_trkMaxPt) continue;
177 float jetPt=0.0;
178 float minDr=10.0;
179
180 for (const xAOD::Jet* jet : *jetCont) {
181 if (jet->pt() < m_jetMinPt) {continue;} //skip jets below pT threshold
182 float DR = xAOD::P4Helpers::deltaR(*trkLink, jet);
183 if(DR<minDr) {
184 minDr = DR;
185 jetPt = jet->pt();
186 }
187 }
188 if(minDr <= m_jetTrkMaxDr){//check if jet is within dR 1.
189 sum = m_sum->add(sum, (*trkLink)->pt(),jetPt,minDr );
190 }
191 }
192 if (sum > maxsum) {
193 maxsum = sum;
194 hardscatter = vtx;
195 }
196 }
199 float gnn_score = acc_gnn(*vtx);
200 if (gnn_score > max_gnn_score) {
201 max_gnn_score = gnn_score;
202 hardscatter = vtx;
203 }
204 }
205 //::keeping Matt's (old) method for sumpt & sumpt2
206 else {
207 for (const auto& trkLink : vtx->trackParticleLinks()) {
208 if (trkLink.isValid()) {
209 if (m_doTrkSelection && !static_cast<bool>(m_trkSelectTool->accept(**trkLink, vtx))) continue;
210 sum = m_sum->add(sum, (*trkLink)->pt(),0.,0.);
211 }
212 }
213 if (sum > maxsum) {
214 maxsum = sum;
215 hardscatter = vtx;
216 }
217 }
218 }
219 // Else, return the PV:
220 else {
221 if (vtx->vertexType() == xAOD::VxType::PriVtx) {
222 hardscatter = vtx;
223 break;
224 }
225 }
226 }
227
228 return hardscatter;
229}
230
232{
233 const EventContext& ctx = Gaudi::Hive::currentContext();
235 if (!vtxCont.isValid()) {
236 ATH_MSG_ERROR("Could not open primary vertex container, returning nullptr!");
237 return nullptr;
238 }
239 return getHardScatter(vtxCont.get());
240}
241
243{
244 ATH_MSG_DEBUG("In getHardScatterLink(...) for " << name() << "...");
245
246 const EventContext& ctx = Gaudi::Hive::currentContext();
247
248 // Get our hardscatter vertex
249 const xAOD::Vertex* hardscatter = getHardScatter(vtxCont);
250
251 // Create our element link
253 if (hardscatter) {
254 hardscatterLink.toContainedElement(*vtxCont, hardscatter, ctx);
255 }
256
257 return hardscatterLink;
258}
259
261{
262 const EventContext& ctx = Gaudi::Hive::currentContext();
264 if (!vtxCont.isValid()) {
265 ATH_MSG_ERROR("Could not open primary vertex container, returning empty ElementLink!");
266 return {};
267 }
268 return getHardScatterLink(vtxCont.get());
269}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
static Double_t a
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelectTool
SG::ReadHandleKey< xAOD::JetContainer > m_jetContKey
const xAOD::Vertex * getHardScatter() const override
SG::ReadDecorHandleKey< xAOD::VertexContainer > m_gnnScoreKey
xAOD::EventInfo ReadDecorHandleKey
InDetHardScatterSelectionTool(const std::string &name)
Constructor.
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxContKey
bool m_doTrkSelection
A flag which will be true if an InDetTrackSelectionTool was provided.
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
xAOD::EventInfo ReadHandleKey
virtual StatusCode finalize() override
Function finalizing the tool.
SG::ReadDecorHandleKey< xAOD::EventInfo > m_hardScatterDecoKey
std::unique_ptr< Sum > m_sum
A helper class which either sums pt2 or pt or ptw.
virtual StatusCode initialize() override
Function initialising the tool.
ElementLink< xAOD::VertexContainer > getHardScatterLink() const override
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
@ PriVtx
Primary vertex.
Jet_v1 Jet
Definition of the current "jet version".
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".