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#include "GaudiKernel/ThreadLocalContext.h"
15
16// need to find this for the new version
18
19#include <vector>
20#include <string>
21
22namespace DerivationFramework
23{
25 const std::string& t,
26 const std::string& n,
27 const IInterface* p) :
28
29 base_class(t,n,p) {}
30
31 // Destructor
34
35 // Athena initialize and finalize
37
38 // Validate m_vertexScheme
39 if (m_vertexScheme != "sumPt2" && m_vertexScheme != "nTracks" ) {
40 ATH_MSG_ERROR("Invalid PrimaryVertexSelection: " << m_vertexScheme);
41 return StatusCode::FAILURE;
42 }
43
44 ATH_CHECK(m_vertexKey.initialize());
45 ATH_CHECK(m_jetKey.initialize());
46 ATH_CHECK(m_sumPt2Key.initialize(m_vertexScheme == "sumPt2"));
47 ATH_CHECK(m_trkSelTool.retrieve());
49 return StatusCode::SUCCESS;
50 }
51
53 ATH_CHECK(m_trkSelTool->finalize());
54 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass << " were retained.");
55 return StatusCode::SUCCESS;
56 }
57
58 // The thinning itself
60 // Get current event context
61 const EventContext& ctx = Gaudi::Hive::currentContext();
62
63 // Get TrackParticle collection
65
66 // Check event contains tracks, if none then thinning complete!
67 unsigned int nTracks = tracks->size();
68 if (nTracks==0) return StatusCode::SUCCESS;
69
70 // Set up a mask with same entires as full TrackParticle collection
71 std::vector<bool> mask(nTracks,false); // reject all tracks by default
72 m_ntot += nTracks;
73
74 // Define a primary vertex
75 const xAOD::Vertex *primary_vertex(nullptr);
76
77 // Retrieve vertex container
79 ATH_CHECK(vtxC.isValid());
80
81 // Retrieve jet containers
83 ATH_CHECK(importedJets.isValid());
84
85 // Variables for tracking best vertex based on scheme
86 float ptmax = 0.;
87 std::size_t ntrkmax = 0;
88
89 // Retrieve sumPt2 decoration
91 ATH_CHECK(sumPt2Handle.isValid());
92
93 // Iterate through vertices to find the primary vertex
94 for (const xAOD::Vertex* vertex : *vtxC) {
95 if (!vertex || vertex->vertexType() != xAOD::VxType::PriVtx) {
96 continue;
97 }
98
99 if (m_vertexScheme == "sumPt2") {
100 float sumPt = sumPt2Handle(*vertex);
101 if (sumPt > ptmax) {
102 ptmax = sumPt;
103 primary_vertex = vertex;
104 }
105 }
106 else {
107 std::size_t ntp = vertex->nTrackParticles();
108 if (ntp > ntrkmax) {
109 ntrkmax = ntp;
110 primary_vertex = vertex;
111 }
112 }
113 }
114
115 if (!primary_vertex) {
116 ATH_MSG_DEBUG("No primary vertex found.");
117 }
118
119 // Iterate through jets, get associated tracks, set mask if passing thinning
120 for (const auto *jet : *importedJets) {
121 std::vector<const xAOD::TrackParticle*> jetTracks;
122 bool haveJetTracks = jet->getAssociatedObjects(xAOD::JetAttribute::GhostTrack, jetTracks);
123 if ( !haveJetTracks ) { ATH_MSG_WARNING("Associated jet tracks not found!"); }
124 else {
125 for (auto & jetTrack : jetTracks) {
126 const xAOD::Vertex* vert_trk = primary_vertex;
127
128 asg::AcceptData acceptData = m_trkSelTool->accept(*jetTrack, vert_trk);
129 int index = jetTrack->index();
130 mask[index] = static_cast<bool>(acceptData);
131 }
132 }
133 }
134
135 // Count up mask contents
136 unsigned int n_pass=0;
137 for (unsigned int i=0; i<nTracks; ++i) {
138 if (mask[i]) ++n_pass;
139 }
140 m_npass += n_pass;
141
142 tracks.keep (mask);
143
144 return StatusCode::SUCCESS;
145 }
146}
#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
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.