ATLAS Offline Software
JetRestrictedSumPtVertexWeightCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
9 #include "xAODTracking/Vertex.h"
10 #include "xAODJet/Jet.h"
11 
12 #include <memory>
13 #include <vector>
14 #include <set>
15 #include <iomanip>
16 
17 namespace Trk {
18 
21 {
22  // We definitely need a jet collection for the track selection
23  if(m_jetContKey.empty()) {
24  ATH_MSG_ERROR("No jet collection provided for selecting tracks!");
25  return StatusCode::FAILURE;
26  } else {
27  ATH_CHECK(m_jetContKey.initialize());
28  }
29  ATH_CHECK(m_tracksInCone.retrieve());
30 
31  if(!m_plainSumPtKey.empty()) {
32  m_decPlainSumPt = std::make_unique<SG::AuxElement::Decorator<float> >(m_plainSumPtKey);
33  }
34 
35  return StatusCode::SUCCESS;
36 } // end of initialize method
37 
40 {
41  return StatusCode::SUCCESS;
42 }
43 
44 // class constructor implementation
46  const std::string& t,
47  const std::string& n,
48  const IInterface* p)
49  : AthAlgTool(t, n, p)
50 {
51  declareInterface<IVertexWeightCalculator>(this);
52 }
53 
54 double
56  const xAOD::Vertex& vertex) const
57 {
58  //::First get the jet containers
60  if (!jetContHandle.isValid()){
61  ATH_MSG_ERROR ("HardScatterSelectionTool configured to use jet collection "<<m_jetContKey.key()<<", but collection is not found!");
62  }
63  const xAOD::JetContainer* jetCont{jetContHandle.cptr()};
64 
65  // Retrieve tracks within jet cone (cached lookup)
66  // Add to a set for comparison later
67  std::set<const xAOD::TrackParticle*> tracks_in_jets;
68  for(const xAOD::Jet* jet : *jetCont) {
69  std::vector<const xAOD::TrackParticle*> tracks_in_this_jet;
70  m_tracksInCone->particlesInCone( jet->eta(), jet->phi(), m_cone_dR, tracks_in_this_jet );
71  tracks_in_jets.insert(tracks_in_this_jet.begin(),tracks_in_this_jet.end());
72  }
73  ATH_MSG_VERBOSE("Collected " << tracks_in_jets.size() << " tracks in " << jetCont->size() << " jets");
74 
75  size_t n_selected_tracks{0};
76  double total_pt{0.}, jet_only_pt{0.};
77  ATH_MSG_DEBUG("Estimating vertex sorting score from "
78  << vertex.nTrackParticles() << " tracks at vertex.");
79  for (const auto& elTrackParticle : vertex.trackParticleLinks()) {
80 
81  if (not elTrackParticle.isValid()) {
83  "No valid link to tracks in xAOD::Vertex object. Skipping track for "
84  "signal compatibility (may be serious).");
85  continue;
86  }
87 
88  const Trk::Perigee& perigee =
89  (*elTrackParticle.cptr())->perigeeParameters();
90  float increment = 0.;
91  if (m_doSumPt2Selection) {
92  increment = std::pow(1. / perigee.parameters()[Trk::qOverP] *
93  sin(perigee.parameters()[Trk::theta]) / 1000.,
94  2);
95  } else {
96  increment = std::fabs(1. / perigee.parameters()[Trk::qOverP]) *
97  sin(perigee.parameters()[Trk::theta]) / 1000.;
98  }
99  total_pt += increment;
100 
101  if(tracks_in_jets.contains(*elTrackParticle)) {
102  ATH_MSG_VERBOSE("Accepted track with index " << (*elTrackParticle)->index() << " in jet vicinity.");
103  ++n_selected_tracks;
104  jet_only_pt += increment;
105  }
106 
107  }
108  ATH_MSG_DEBUG("Counted " << n_selected_tracks << "/" << vertex.nTrackParticles()
109  << " towards vertex sumpt " << std::setprecision(3) << jet_only_pt << " (unrestricted sum: " << total_pt << ")");
110 
111  if(m_decPlainSumPt!=nullptr) {
112  (*m_decPlainSumPt)(vertex) = total_pt;
113  }
114 
115  if(jetCont->empty()){
116  ATH_MSG_DEBUG("No jets found in this event, fall back to unrestricted sum");
117  jet_only_pt = total_pt;
118  }
119  return jet_only_pt;
120 }
121 
122 }
123 
Trk::JetRestrictedSumPtVertexWeightCalculator::m_cone_dR
Gaudi::Property< float > m_cone_dR
Definition: JetRestrictedSumPtVertexWeightCalculator.h:64
Jet.h
TrackParameters.h
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
Trk::JetRestrictedSumPtVertexWeightCalculator::m_decPlainSumPt
std::unique_ptr< SG::AuxElement::Decorator< float > > m_decPlainSumPt
Definition: JetRestrictedSumPtVertexWeightCalculator.h:69
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
JetRestrictedSumPtVertexWeightCalculator.h
Trk::JetRestrictedSumPtVertexWeightCalculator::m_doSumPt2Selection
Gaudi::Property< bool > m_doSumPt2Selection
Flag to Set SumPt^2 not SumPt as selection criteria.
Definition: JetRestrictedSumPtVertexWeightCalculator.h:63
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::JetRestrictedSumPtVertexWeightCalculator::JetRestrictedSumPtVertexWeightCalculator
JetRestrictedSumPtVertexWeightCalculator(const std::string &t, const std::string &n, const IInterface *p)
constructor
Definition: JetRestrictedSumPtVertexWeightCalculator.cxx:45
beamspotman.n
n
Definition: beamspotman.py:731
Trk::theta
@ theta
Definition: ParamDefs.h:66
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
Trk::JetRestrictedSumPtVertexWeightCalculator::estimateSignalCompatibility
virtual double estimateSignalCompatibility(const xAOD::Vertex &vertex) const override final
WeightCalculator.
Definition: JetRestrictedSumPtVertexWeightCalculator.cxx:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Vertex.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::JetRestrictedSumPtVertexWeightCalculator::m_jetContKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContKey
Definition: JetRestrictedSumPtVertexWeightCalculator.h:67
Trk::perigeeParameters
@ perigeeParameters
Definition: MeasurementType.h:19
Trk::JetRestrictedSumPtVertexWeightCalculator::m_tracksInCone
ToolHandle< xAOD::ITrackParticlesInConeTool > m_tracksInCone
Definition: JetRestrictedSumPtVertexWeightCalculator.h:66
TrackParticle.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::JetRestrictedSumPtVertexWeightCalculator::m_plainSumPtKey
Gaudi::Property< std::string > m_plainSumPtKey
Definition: JetRestrictedSumPtVertexWeightCalculator.h:68
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:67
Trk::JetRestrictedSumPtVertexWeightCalculator::initialize
virtual StatusCode initialize() override
Definition: JetRestrictedSumPtVertexWeightCalculator.cxx:20
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
AthAlgTool
Definition: AthAlgTool.h:26
Trk::JetRestrictedSumPtVertexWeightCalculator::finalize
virtual StatusCode finalize() override
Definition: JetRestrictedSumPtVertexWeightCalculator.cxx:39