ATLAS Offline Software
Loading...
Searching...
No Matches
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
10#include "xAODJet/Jet.h"
11
12#include <memory>
13#include <vector>
14#include <set>
15#include <iomanip>
16
17namespace 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
38StatusCode
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
54double
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.;
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual double estimateSignalCompatibility(const xAOD::Vertex &vertex) const override final
WeightCalculator.
Gaudi::Property< bool > m_doSumPt2Selection
Flag to Set SumPt^2 not SumPt as selection criteria.
JetRestrictedSumPtVertexWeightCalculator(const std::string &t, const std::string &n, const IInterface *p)
constructor
std::unique_ptr< SG::AuxElement::Decorator< float > > m_decPlainSumPt
ToolHandle< xAOD::ITrackParticlesInConeTool > m_tracksInCone
::StatusCode StatusCode
StatusCode definition for legacy code.
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
Jet_v1 Jet
Definition of the current "jet version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".