ATLAS Offline Software
Loading...
Searching...
No Matches
HIJetTrackParticleThinningTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// HIJetTrackParticleThinningTool.cxx, (c) ATLAS Detector software
8
14
15// need to find this for the new version
17
18#include <vector>
19#include <string>
20
21namespace DerivationFramework
22{
24 const std::string& t,
25 const std::string& n,
26 const IInterface* p) :
27
28 base_class(t,n,p) {}
29
30 // Destructor
33
34 // Athena initialize and finalize
36
37 // Validate m_vertexScheme
38 if (m_vertexScheme != "sumPt2" && m_vertexScheme != "nTracks" ) {
39 ATH_MSG_ERROR("Invalid PrimaryVertexSelection: " << m_vertexScheme);
40 return StatusCode::FAILURE;
41 }
42
43 ATH_CHECK(m_vertexKey.initialize());
44 ATH_CHECK(m_jetKey.initialize());
45 ATH_CHECK(m_sumPt2Key.initialize(m_vertexScheme == "sumPt2"));
46 ATH_CHECK(m_trkSelTool.retrieve());
48 return StatusCode::SUCCESS;
49 }
50
52 ATH_CHECK(m_trkSelTool->finalize());
53 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass << " were retained.");
54 return StatusCode::SUCCESS;
55 }
56
57 // The thinning itself
58 StatusCode DerivationFramework::HIJetTrackParticleThinningTool::doThinning(const EventContext& ctx) const {
59
60 // Get TrackParticle collection
62
63 // Check event contains tracks, if none then thinning complete!
64 unsigned int nTracks = tracks->size();
65 if (nTracks==0) return StatusCode::SUCCESS;
66
67 // Set up a mask with same entires as full TrackParticle collection
68 std::vector<bool> mask(nTracks,false); // reject all tracks by default
69 m_ntot += nTracks;
70
71 // Define a primary vertex
72 const xAOD::Vertex *primary_vertex(nullptr);
73
74 // Retrieve vertex container
76 ATH_CHECK(vtxC.isValid());
77
78 // Retrieve jet containers
80 ATH_CHECK(importedJets.isValid());
81
82 // Variables for tracking best vertex based on scheme
83 float ptmax = 0.;
84 std::size_t ntrkmax = 0;
85
86 // Retrieve sumPt2 decoration
88 ATH_CHECK(sumPt2Handle.isValid());
89
90 // Iterate through vertices to find the primary vertex
91 for (const xAOD::Vertex* vertex : *vtxC) {
92 if (!vertex || vertex->vertexType() != xAOD::VxType::PriVtx) {
93 continue;
94 }
95
96 if (m_vertexScheme == "sumPt2") {
97 float sumPt = sumPt2Handle(*vertex);
98 if (sumPt > ptmax) {
99 ptmax = sumPt;
100 primary_vertex = vertex;
101 }
102 }
103 else {
104 std::size_t ntp = vertex->nTrackParticles();
105 if (ntp > ntrkmax) {
106 ntrkmax = ntp;
107 primary_vertex = vertex;
108 }
109 }
110 }
111
112 if (!primary_vertex) {
113 ATH_MSG_DEBUG("No primary vertex found.");
114 }
115
116 // Iterate through jets, get associated tracks, set mask if passing thinning
117 for (const auto *jet : *importedJets) {
118 std::vector<const xAOD::TrackParticle*> jetTracks;
119 bool haveJetTracks = jet->getAssociatedObjects(xAOD::JetAttribute::GhostTrack, jetTracks);
120 if ( !haveJetTracks ) { ATH_MSG_WARNING("Associated jet tracks not found!"); }
121 else {
122 for (auto & jetTrack : jetTracks) {
123 const xAOD::Vertex* vert_trk = primary_vertex;
124
125 asg::AcceptData acceptData = m_trkSelTool->accept(*jetTrack, vert_trk);
126 int index = jetTrack->index();
127 mask[index] = static_cast<bool>(acceptData);
128 }
129 }
130 }
131
132 // Count up mask contents
133 unsigned int n_pass=0;
134 for (unsigned int i=0; i<nTracks; ++i) {
135 if (mask[i]) ++n_pass;
136 }
137 m_npass += n_pass;
138
139 tracks.keep (mask);
140
141 return StatusCode::SUCCESS;
142 }
143}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle for requesting thinning for a data object.
HIJetTrackParticleThinningTool(const std::string &t, const std::string &n, const IInterface *p)
SG::ReadDecorHandleKey< xAOD::VertexContainer > m_sumPt2Key
virtual StatusCode doThinning(const EventContext &ctx) const override
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
double ptmax
THE reconstruction tool.
Definition index.py:1
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.