ATLAS Offline Software
Loading...
Searching...
No Matches
PixeldEdxTrackParticleThinning.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// PixeldEdxTrackParticleThinning.cxx, (c) ATLAS Detector software
8
14#include <vector>
15#include <string>
16
18 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
19 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
20 150, 150, 150, 150, 150, 124.261, 111.448, 97.7357, 85.5616, 72.3294,
21 61.0017, 50.8592, 41.6827, 33.7413, 26.9884, 21.3822, 16.8352, 13.1081, 10.2368, 7.96723,
22 6.23636, 4.91757, 3.91519, 3.15519, 2.57768, 2.13622, 1.80524, 1.53102, 1.30677, 1.13582
23};
24
25// Constructor
27 const std::string& n,
28 const IInterface* p ) :
29 base_class(t, n, p)
30{}
31
32// Athena initialize and finalize
34{
35 ATH_MSG_DEBUG("initialize() ...");
36
37 //check xAOD::InDetTrackParticle collection
39 ATH_MSG_INFO("Using " << m_inDetParticlesKey << "as the source collection for inner detector track particles");
40 ATH_CHECK( m_vertexContainerKey.initialize() );
41 //check availability of xAOD::TrackStateValidation and xAOD::TrackMeasurementValidation containers
42
43 if (!m_selectionString.empty()) {
44 ATH_CHECK(initializeParser(m_selectionString));
45 }
46
47 m_counter.resize(50);
48 m_counter_picked.resize(50);
50
51 if( 0 == m_pTbins.size() ) {
52 for( size_t ip = 0; ip <= 50; ++ip ) {
53 m_pTbins.emplace_back( pow( 10, 2.0 + 0.04 * ip ) );
54 }
55 }
56
58
59 return StatusCode::SUCCESS;
60}
61
63{
64 ATH_MSG_DEBUG("finalize() ...");
65 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
66 ATH_CHECK( finalizeParser() );
67 return StatusCode::SUCCESS;
68}
69
70// The thinning itself
72{
73
74
75 // Retrieve main TrackParticle collection
78
79 // Check the event contains tracks
80 size_t nTracks = importedTrackParticles->size();
81 if (nTracks==0) return StatusCode::SUCCESS;
82
83 // Set up a mask with the same entries as the full TrackParticle collection
84 std::vector<bool> mask;
85 mask.assign(nTracks,false); // default: don't keep any tracks
86
87 std::lock_guard<std::mutex> lock(m_mutex);
88
89 m_ntot += nTracks;
90
91 // Execute the text parser and update the mask
92 if (m_parser) {
93 std::vector<int> entries = m_parser->evaluateAsVector();
94 unsigned int nEntries = entries.size();
95 // check the sizes are compatible
96 if (nTracks != nEntries ) {
97 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used ID TrackParticles?");
98 return StatusCode::FAILURE;
99 } else {
100 // set mask
101 for (unsigned int i=0; i<nTracks; ++i) if (entries[i]==1) mask[i]=true;
102 }
103 }
104
105 // Retrieve vertex collection
107 ATH_CHECK( primaryVertices.isValid() );
108
109 const xAOD::Vertex* priVtx = nullptr;
110
111 for( const auto* vtx : *primaryVertices ) {
112 if( vtx->vertexType() == xAOD::VxType::PriVtx ) {
113 priVtx = vtx;
114 break;
115 }
116 }
117
118 if( !priVtx ) return StatusCode::SUCCESS;
119
120 auto getBin = [&]( const double pT ) -> size_t {
121 for( size_t ip = 0; ip < m_pTbins.size()-1; ip++ ) {
122 if( pT > m_pTbins.at(ip) && pT < m_pTbins.at(ip+1) ) {
123 return ip;
124 }
125 }
126 return 0;
127 };
128
129 // Count the mask
130 for (size_t i=0; i<nTracks; ++i) {
131
132 const auto* trk = importedTrackParticles->at(i);
133
134 // Keep all tracks if IBL is overflow
135 if( trk->numberOfIBLOverflowsdEdx() > 0 ) {
136
137 mask.at(i) = true; ++m_npass; continue;
138
139 }
140
141
142 // Keep all track for pT above 10 GeV
143 if( std::abs( trk->pt() ) > m_unprescalePtCut ) {
144
145 mask.at(i) = true; ++m_npass; continue;
146
147 }
148
149 // Hereafter only low-pT and no-overflow tracks
150
151 // Keep only d0 significancd is small enough
152 if( std::abs( xAOD::TrackingHelpers::d0significance( trk ) ) > m_d0SignifCut ) {
153 continue;
154 }
155
156 // Keep only delta(z0) is less than 10 mm
157 if( std::abs( trk->z0() - priVtx->z() + trk->vz() ) > m_z0Cut ) {
158 continue;
159 }
160
161 // Reject forward low-pT tracks
162 if( std::abs( trk->eta() ) > m_etaCut ) {
163 continue;
164 }
165
166 // Prescaled track keeping
167 auto bin = getBin( std::abs( trk->pt() ) );
168
169 const auto preScale = static_cast<unsigned long long>( std::floor( m_preScales.at( bin ) * m_globalScale ) );
170 const auto preScale10 = std::max( static_cast<unsigned long long>( std::floor( m_preScales.at( bin ) * m_globalScale / 10. ) ), 1ull );
171
172 float dEdx { 0 };
173 trk->summaryValue( dEdx, xAOD::pixeldEdx );
174
175 // Increment the m_counter
176 m_counter.at(bin)++;
177
178 // Relatively higher dE/dx tracks
179 static const float dEdxThr { static_cast<float>(pow( 10, 0.1 )) };
180 if( dEdx > dEdxThr ) {
181
182 mask.at(i) = ( (m_counter.at(bin) % preScale10) == 0 );
183
184 // There are also tracks with dE/dx == -1.
185 } else if( dEdx > 0. ) {
186
187 mask.at(i) = ( (m_counter.at(bin) % preScale) == 0 );
188
189 } else {
190
191 mask.at(i) = false;
192
193 }
194
195 if( mask.back() ) { ++m_npass; m_counter_picked.at(bin)++; }
196
197 }
198
199 assert( importedTrackParticles->size() == mask.size() );
200
201 // Execute the thinning service based on the mask.
202 importedTrackParticles.keep (mask);
203
204 return StatusCode::SUCCESS;
205}
206
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
int getBin(double x, double min, double step, int clamp_max)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Handle for requesting thinning for a data object.
PixeldEdxTrackParticleThinning(const std::string &t, const std::string &n, const IInterface *p)
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
virtual StatusCode doThinning(const EventContext &ctx) const override
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetParticlesKey
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.
float z() const
Returns the z position.
double entries
Definition listroot.cxx:49
double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2)
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.
@ pixeldEdx
the dE/dx estimate, calculated using the pixel clusters [?