Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
InDetHardScatterSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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
22 namespace {
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
46  asg::AsgTool(name)
47 {}
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_hardScatterDeco.toString());
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
72  if (m_redoHardScatter) {
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) {
77  case InDet::InDetHardScatterSelectionTool::Mode::SumPt2: {
78  m_sum = std::make_unique<::SumPt2>();
79  break;
80  }
81  case InDet::InDetHardScatterSelectionTool::Mode::SumPt: {
82  m_sum = std::make_unique<::SumPt>();
83  break;
84  }
85  case InDet::InDetHardScatterSelectionTool::Mode::SumPtw: {
86  m_sum = std::make_unique<::SumPtw>();
87  break;
88  }
89  case InDet::InDetHardScatterSelectionTool::Mode::HSGN2: {
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  // If we are returning a decoration
107  else if (m_returnDeco) {
108  if (m_hardScatterDeco.empty()) {
109  ATH_MSG_ERROR("Hardscatter vertex decoration cannot be empty!");
110  return StatusCode::FAILURE;
111  }
112  }
113 
114  // Initialize our EventInfo container and decoration reads
118 
119  // Initialize our vertex container read
120  ATH_CHECK(m_vtxContKey.initialize());
121 
122  // Initialize our jet container read if it is non empty
124 
125  // Initialize the GNN score handle if relevant mode is selected
126  ATH_CHECK(m_gnnScoreKey.initialize(m_mode == InDet::InDetHardScatterSelectionTool::Mode::HSGN2));
127 
128  return StatusCode::SUCCESS;
129 }
130 
131 // Finalize
133 {
134  ATH_MSG_DEBUG("Finalizing " << name() << "...");
135 
136  // Release our tool
137  if (m_redoHardScatter && !m_trkSelectTool.empty()) ATH_CHECK(m_trkSelectTool.release());
138 
139  return StatusCode::SUCCESS;
140 }
141 
143 {
144  ATH_MSG_DEBUG("In getHardScatter(...) for " << name() << "...");
145 
146  const EventContext& ctx = Gaudi::Hive::currentContext();
147 
148  // If we are simply returning a decoration on the EventInfo:
149  if (m_returnDeco) {
151  if (!evtInfo.isValid()) {
152  ATH_MSG_ERROR("Could not open event info, returning nullptr!");
153  return nullptr;
154  }
156  const ElementLink<xAOD::VertexContainer>& vtxLink = hardScatterDeco(*evtInfo);
157  if (!vtxLink.isValid()) {
158  ATH_MSG_ERROR("Hardscatter vertex link is not valid, returning nullptr!");
159  return nullptr;
160  }
161  return *vtxLink;
162  }
163  //::get the jet container if the mode of HS selection is sumptw
164  const xAOD::JetContainer* jetCont{nullptr};
165  if ( m_mode == InDet::InDetHardScatterSelectionTool::Mode::SumPtw ){
166  //::First get the jet containers
168  if (!jetContHandle.isValid()){
169  ATH_MSG_ERROR ("HardScatterSelectionTool configured to use jet collection "<<m_jetContKey.key()<<", but collection is not found!");
170  }
171  jetCont = jetContHandle.cptr();
172  }
173 
174  float maxsum = -999.0;
175  float max_gnn_score = -999.0;
176  const xAOD::Vertex* hardscatter = nullptr;
177  for (const auto *const vtx : *vtxCont) {
178  float sum = 0.;
179  // If we are redoing the hardscatter determination:
180  if (m_redoHardScatter) {
181  if ( m_mode == InDet::InDetHardScatterSelectionTool::Mode::SumPtw ){
182  for (const auto& trkLink : vtx->trackParticleLinks()) {
183  if (!trkLink.isValid()) continue;
184  if (m_doTrkSelection && !static_cast<bool>(m_trkSelectTool->accept(**trkLink, vtx))) continue;
185  if ( (*trkLink)->pt() >m_trkMaxPt) continue;
186  float jetPt=0.0;
187  float minDr=10.0;
188 
189  for (const xAOD::Jet* jet : *jetCont) {
190  if (jet->pt() < m_jetMinPt) {continue;} //skip jets below pT threshold
191  float DR = xAOD::P4Helpers::deltaR(*trkLink, jet);
192  if(DR<minDr) {
193  minDr = DR;
194  jetPt = jet->pt();
195  }
196  }
197  if(minDr <= m_jetTrkMaxDr){//check if jet is within dR 1.
198  sum = m_sum->add(sum, (*trkLink)->pt(),jetPt,minDr );
199  }
200  }
201  if (sum > maxsum) {
202  maxsum = sum;
203  hardscatter = vtx;
204  }
205  }
206  else if ( m_mode == InDet::InDetHardScatterSelectionTool::Mode::HSGN2 ) {
208  float gnn_score = acc_gnn(*vtx);
209  if (gnn_score > max_gnn_score) {
210  max_gnn_score = gnn_score;
211  hardscatter = vtx;
212  }
213  }
214  //::keeping Matt's (old) method for sumpt & sumpt2
215  else {
216  for (const auto& trkLink : vtx->trackParticleLinks()) {
217  if (trkLink.isValid()) {
218  if (m_doTrkSelection && !static_cast<bool>(m_trkSelectTool->accept(**trkLink, vtx))) continue;
219  sum = m_sum->add(sum, (*trkLink)->pt(),0.,0.);
220  }
221  }
222  if (sum > maxsum) {
223  maxsum = sum;
224  hardscatter = vtx;
225  }
226  }
227  }
228  // Else, return the PV:
229  else {
230  if (vtx->vertexType() == xAOD::VxType::PriVtx) {
231  hardscatter = vtx;
232  break;
233  }
234  }
235  }
236 
237  return hardscatter;
238 }
239 
241 {
242  const EventContext& ctx = Gaudi::Hive::currentContext();
244  if (!vtxCont.isValid()) {
245  ATH_MSG_ERROR("Could not open primary vertex container, returning nullptr!");
246  return nullptr;
247  }
248  return getHardScatter(vtxCont.get());
249 }
250 
252 {
253  ATH_MSG_DEBUG("In getHardScatterLink(...) for " << name() << "...");
254 
255  const EventContext& ctx = Gaudi::Hive::currentContext();
256 
257  // Get our hardscatter vertex
258  const xAOD::Vertex* hardscatter = getHardScatter(vtxCont);
259 
260  // Create our element link
261  ElementLink<xAOD::VertexContainer> hardscatterLink;
262  if (hardscatter) {
263  hardscatterLink.toContainedElement(*vtxCont, hardscatter, ctx);
264  }
265 
266  return hardscatterLink;
267 }
268 
270 {
271  const EventContext& ctx = Gaudi::Hive::currentContext();
273  if (!vtxCont.isValid()) {
274  ATH_MSG_ERROR("Could not open primary vertex container, returning empty ElementLink!");
275  return {};
276  }
277  return getHardScatterLink(vtxCont.get());
278 }
InDet::InDetHardScatterSelectionTool::getHardScatterLink
ElementLink< xAOD::VertexContainer > getHardScatterLink() const override
Definition: InDetHardScatterSelectionTool.cxx:269
InDet::InDetHardScatterSelectionTool::m_hardScatterDecoKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_hardScatterDecoKey
The decoration name of the ElementLink to the hardscatter vertex (applied to xAOD::EventInfo)
Definition: InDetHardScatterSelectionTool.h:148
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
InDetHardScatterSelectionTool.h
InDet::InDetHardScatterSelectionTool::m_jetContKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContKey
Definition: InDetHardScatterSelectionTool.h:136
CurrentContext.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
InDet::InDetHardScatterSelectionTool::~InDetHardScatterSelectionTool
~InDetHardScatterSelectionTool()
Destructor.
asg
Definition: DataHandleTestTool.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDet::InDetHardScatterSelectionTool::m_trkMaxPt
FloatProperty m_trkMaxPt
Definition: InDetHardScatterSelectionTool.h:145
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
InDet::InDetHardScatterSelectionTool::m_jetMinPt
FloatProperty m_jetMinPt
Definition: InDetHardScatterSelectionTool.h:143
InDet::InDetHardScatterSelectionTool::getHardScatter
const xAOD::Vertex * getHardScatter() const override
Definition: InDetHardScatterSelectionTool.cxx:240
InDet::InDetHardScatterSelectionTool::m_redoHardScatter
BooleanProperty m_redoHardScatter
Definition: InDetHardScatterSelectionTool.h:138
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDet::InDetHardScatterSelectionTool::m_doTrkSelection
bool m_doTrkSelection
A flag which will be true if an InDetTrackSelectionTool was provided.
Definition: InDetHardScatterSelectionTool.h:131
InDet::InDetHardScatterSelectionTool::m_mode
IntegerProperty m_mode
Definition: InDetHardScatterSelectionTool.h:139
InDet::InDetHardScatterSelectionTool::finalize
virtual StatusCode finalize() override
Function finalizing the tool.
Definition: InDetHardScatterSelectionTool.cxx:132
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
InDet::InDetHardScatterSelectionTool::m_vtxContKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxContKey
Definition: InDetHardScatterSelectionTool.h:135
InDet::InDetHardScatterSelectionTool::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
xAOD::EventInfo ReadHandleKey
Definition: InDetHardScatterSelectionTool.h:134
InDet::InDetHardScatterSelectionTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: InDetHardScatterSelectionTool.cxx:54
InDet::InDetHardScatterSelectionTool::m_returnDeco
BooleanProperty m_returnDeco
Definition: InDetHardScatterSelectionTool.h:141
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::InDetHardScatterSelectionTool::InDetHardScatterSelectionTool
InDetHardScatterSelectionTool(const std::string &name)
Constructor.
Definition: InDetHardScatterSelectionTool.cxx:45
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
IInDetTrackSelectionTool.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::InDetHardScatterSelectionTool::Sum
Definition: InDetHardScatterSelectionTool.h:71
InDet::InDetHardScatterSelectionTool::m_hardScatterDeco
StringProperty m_hardScatterDeco
Definition: InDetHardScatterSelectionTool.h:142
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ReadHandle.h
Handle class for reading from StoreGate.
InDet::InDetHardScatterSelectionTool::m_trkSelectTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelectTool
Definition: InDetHardScatterSelectionTool.h:140
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
VertexContainer.h
a
TList * a
Definition: liststreamerinfos.cxx:10
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
InDet::InDetHardScatterSelectionTool::m_sum
std::unique_ptr< Sum > m_sum
A helper class which either sums pt2 or pt or ptw.
Definition: InDetHardScatterSelectionTool.h:128
ReadDecorHandle.h
Handle class for reading a decoration on an object.
InDet::InDetHardScatterSelectionTool::m_gnnScoreKey
SG::ReadDecorHandleKey< xAOD::VertexContainer > m_gnnScoreKey
xAOD::EventInfo ReadDecorHandleKey
Definition: InDetHardScatterSelectionTool.h:151
TrackParticleContainer.h
InDet::InDetHardScatterSelectionTool::m_jetTrkMaxDr
FloatProperty m_jetTrkMaxDr
Definition: InDetHardScatterSelectionTool.h:144