ATLAS Offline Software
Loading...
Searching...
No Matches
HITrackQualityAugmentationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7namespace DerivationFramework {
8
10{
11 ATH_CHECK(m_trackParticlesName.initialize());
12 ATH_CHECK(m_vertexContainerName.initialize());
13 ATH_CHECK(m_eventInfoKey.initialize());
14
15 m_decorator = m_trackParticlesName.key() + "." + m_decorator.key();
16 ATH_CHECK(m_decorator.initialize());
17
19 ATH_CHECK(m_chi2Decorator.initialize());
20
23
25 ATH_CHECK(m_covD0Decorator.initialize());
26
28 ATH_CHECK(m_covZ0Decorator.initialize());
29
31 ATH_CHECK(m_covThetaDecorator.initialize());
32
33 CHECK(m_trkSelTool_pp.retrieve());
34 CHECK(m_trkSelTool_hi_loose.retrieve());
35 CHECK(m_trkSelTool_hi_tight.retrieve());
36
37 if (!m_trkToLeptonPVTool.empty()) {
38 CHECK(m_trkToLeptonPVTool.retrieve());
39 }
40
41 return StatusCode::SUCCESS;
42}
43
44
45StatusCode HITrackQualityAugmentationTool::addBranches(const EventContext& ctx) const{
46
47 // Get Primary vertex
49 if(!vertices.isValid()) {
50 ATH_MSG_ERROR ("Couldn't retrieve VertexContainer with key " << m_vertexContainerName.key());
51 return StatusCode::FAILURE;
52 }
53 const xAOD::Vertex* pv(0);
54 for (const xAOD::Vertex* vx : *vertices) {
55 if (vx->vertexType() == xAOD::VxType::PriVtx) {
56 pv = vx;
57 break;
58 }
59 }
60
61 // Get EventInfo
63 if(!eventInfo.isValid()) {
64 ATH_MSG_ERROR ("Couldn't retrieve EventInfo with key " << m_eventInfoKey.key());
65 return StatusCode::FAILURE;
66 }
67
68 // Get the track container
70 if(!tracks.isValid()) {
71 ATH_MSG_ERROR ("Couldn't retrieve TrackParticleContainer with key " << m_trackParticlesName.key());
72 return StatusCode::FAILURE;
73 }
74
75 // Decorators
82
83 // Get track quality and chi2 to PV
84 for(const auto* track:*tracks) {
85 if(pv) {
86 decorator(*track) = GetTrackQualityNew(track,pv);
87
88 // Check if track is associated with the primary vertex
89 bool isFromPV = false;
90 int vertexIndex = -1;
91
92 // Find which vertex this track is associated with
93 for (size_t ivx = 0; ivx < vertices->size(); ++ivx) {
94 const xAOD::Vertex* vx = (*vertices)[ivx];
95 const std::vector<ElementLink<xAOD::TrackParticleContainer>>& trkLinks = vx->trackParticleLinks();
96
97 for (const auto& trkLink : trkLinks) {
98 if (trkLink.isValid() && *trkLink == track) {
99 vertexIndex = static_cast<int>(ivx);
100 if (vx->vertexType() == xAOD::VxType::PriVtx) {
101 isFromPV = true;
102 }
103 break;
104 }
105 }
106 if (vertexIndex >= 0) break;
107 }
108
109 vertexIndexDecorator(*track) = vertexIndex;
110
111 // Calculate chi2 to PV only for non-PV tracks
112 float chi2ToPV = -999.0; // Default for PV tracks
113 if (!isFromPV && !m_trkToLeptonPVTool.empty()) {
114 std::unique_ptr<xAOD::Vertex> fittedVertex = m_trkToLeptonPVTool->matchTrkToPV(track, pv, eventInfo.cptr());
115 if (fittedVertex) {
116 chi2ToPV = fittedVertex->chiSquared();
117 } else {
118 chi2ToPV = -1.0; // Fit failed for non-PV track
119 }
120 }
121 chi2Decorator(*track) = chi2ToPV;
122
123 // Extract covariance matrix diagonal elements
124 float covD0 = -999.0;
125 float covZ0 = -999.0;
126 float covTheta = -999.0;
127 try {
128 auto covMatrix = track->definingParametersCovMatrix();
129 covD0 = covMatrix(0, 0); // d0 variance
130 covZ0 = covMatrix(1, 1); // z0 variance
131 covTheta = covMatrix(3, 3); // theta variance
132 } catch (...) {
133 // Covariance matrix not available - keep default -999.0
134 }
135 covD0Decorator(*track) = covD0;
136 covZ0Decorator(*track) = covZ0;
137 covThetaDecorator(*track) = covTheta;
138 }
139 else {
140 decorator(*track) = 0;
141 chi2Decorator(*track) = -1.0;
142 vertexIndexDecorator(*track) = -1;
143 covD0Decorator(*track) = -999.0;
144 covZ0Decorator(*track) = -999.0;
145 covThetaDecorator(*track) = -999.0;
146 }
147 }
148
149 return StatusCode::SUCCESS;
150}
151
152
154
155 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_hits("numberOfSCTHits");
156 int n_sct_hits = acc_n_sct_hits(*track);
157
158
159 float d0 = track->d0();
160 float z0_wrtPV= track->z0()+track->vz()-pv->z();
161 float theta = track->theta();
162
163 //-------------------------------------------------------------------------------------------------
164 bool pass_min_bias=false;
165 if (m_trkSelTool_pp->accept(*track, pv)) pass_min_bias=true;
166 //-------------------------------------------------------------------------------------------------
167 //-------------------------------------------------------------------------------------------------
168 bool pass_hi_loose=false;
169 if (m_trkSelTool_hi_loose->accept(*track, pv)) pass_hi_loose=true;
170 //-------------------------------------------------------------------------------------------------
171 //-------------------------------------------------------------------------------------------------
172 bool pass_hi_loose_additional_SCT_hit=true;
173 if(!pass_hi_loose || n_sct_hits<7) pass_hi_loose_additional_SCT_hit=false;
174 //-------------------------------------------------------------------------------------------------
175 //-------------------------------------------------------------------------------------------------
176 bool pass_hi_loose_tight_d0_z0=true;
177 if(!pass_hi_loose || fabs(d0)>1.0 || fabs(z0_wrtPV*sin(theta))>1.0) pass_hi_loose_tight_d0_z0=false;
178 //-------------------------------------------------------------------------------------------------
179 //-------------------------------------------------------------------------------------------------
180 bool pass_hi_loose_tighter_d0_z0=true;
181 if(!pass_hi_loose || fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_loose_tighter_d0_z0=false;
182 //-------------------------------------------------------------------------------------------------
183 //-------------------------------------------------------------------------------------------------
184 bool pass_hi_tight=false;
185 if (m_trkSelTool_hi_tight->accept(*track, pv)) pass_hi_tight=true;
186 //-------------------------------------------------------------------------------------------------
187 //-------------------------------------------------------------------------------------------------
188 bool pass_hi_tight_loose_d0_z0=true;
189 if(pass_hi_tight==false){
190 const auto& taccept = m_trkSelTool_hi_tight->getAcceptInfo();
191 asg::AcceptData acceptData(&taccept);
192 static const auto d0Index = taccept.getCutPosition("D0");
193 static const auto z0Index = taccept.getCutPosition("Z0SinTheta");
194 static const auto nCuts = taccept.getNCuts();
195 auto cutBitset = acceptData.getCutResultBitSet();
196 cutBitset |= (1 << d0Index) | (1 << z0Index);
197 if(cutBitset.count() != nCuts ) pass_hi_tight_loose_d0_z0=false;
198 if(fabs(d0)>1.5 || fabs(z0_wrtPV*sin(theta))>1.5) pass_hi_tight_loose_d0_z0=false;
199 }
200 //-------------------------------------------------------------------------------------------------
201 //-------------------------------------------------------------------------------------------------
202 bool pass_hi_tight_tighter_d0_z0=true;
203 if(!pass_hi_tight || fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_tight_tighter_d0_z0=false;
204 //-------------------------------------------------------------------------------------------------
205
206 unsigned short quality =0;
207 if(pass_min_bias ) quality+=PP_MIN_BIAS;
208 if(pass_hi_loose ) quality+=HI_LOOSE;
209 if(pass_hi_loose_additional_SCT_hit) quality+=HI_LOOSE_7SCT_HITS;
210 if(pass_hi_loose_tight_d0_z0 ) quality+=HI_LOOSE_TIGHT_D0_Z0;
211 if(pass_hi_loose_tighter_d0_z0 ) quality+=HI_LOOSE_TIGHTER_D0_Z0;
212 if(pass_hi_tight_loose_d0_z0 ) quality+=HI_TIGHT_LOOSE_D0_Z0;
213 if(pass_hi_tight ) quality+=HI_TIGHT;
214 if(pass_hi_tight_tighter_d0_z0 ) quality+=HI_TIGHT_TIGHTER_D0_Z0;
215 return quality;
216}
217
218
219
220unsigned short HITrackQualityAugmentationTool::GetTrackQuality(const xAOD::TrackParticle* track,float z_vtx) const {
221 //-------------------------------------------------------------------------------------------------
222 float pt = track->pt();
223 float eta = track->eta();
224 //float phi = track->phi();
225
226
227 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_Ipix_hits("numberOfInnermostPixelLayerHits");
228 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_Ipix_expected("expectInnermostPixelLayerHit");
229 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_NIpix_hits("numberOfNextToInnermostPixelLayerHits");
230 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_NIpix_expected("expectNextToInnermostPixelLayerHit");
231 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_hits("numberOfSCTHits");
232 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_pix_hits("numberOfPixelHits");
233 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_holes("numberOfSCTHoles");
234 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_dead("numberOfSCTDeadSensors");
235 static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_pix_dead("numberOfPixelDeadSensors");
236
237 int n_Ipix_hits = acc_n_Ipix_hits(*track);
238 int n_Ipix_expected = acc_n_Ipix_expected(*track);
239 int n_NIpix_hits = acc_n_NIpix_hits(*track);
240 int n_NIpix_expected = acc_n_NIpix_expected(*track);
241 int n_sct_hits = acc_n_sct_hits(*track);
242 int n_pix_hits = acc_n_pix_hits(*track);
243 int n_sct_holes = acc_n_sct_holes(*track);
244 int n_sct_dead = acc_n_sct_dead(*track);
245 int n_pix_dead = acc_n_pix_dead(*track);
246
247
248 float chi2=track->chiSquared();
249 float ndof=track->numberDoF();
250
251 float d0 = track->d0();
252 float z0_wrtPV= track->z0()+track->vz()-z_vtx;
253 float theta = track->theta();
254 //-------------------------------------------------------------------------------------------------
255
256
257 //-------------------------------------------------------------------------------------------------
258 bool pass_min_bias=true;
259 {
260 if(fabs(eta)>2.5) pass_min_bias=false;
261 if(n_Ipix_expected>0){
262 if (n_Ipix_hits==0) pass_min_bias=false;
263 }
264 else{
265 if(n_NIpix_expected>0 && n_NIpix_hits==0) pass_min_bias=false;
266 }
267
268 int n_sct=n_sct_hits+n_sct_dead;
269 if (pt<=300) {if (n_sct <2) pass_min_bias=false;}
270 else if(pt<=400) {if (n_sct <4) pass_min_bias=false;}
271 else if(pt> 400) {if (n_sct <6) pass_min_bias=false;}
272
273 int n_pix=n_pix_hits+n_pix_dead;
274 if(n_pix<=0) pass_min_bias=false;
275
276 if(fabs(d0)>1.5) pass_min_bias=false;
277 if(fabs(z0_wrtPV*sin(theta))>1.5) pass_min_bias=false;
278
279 if(pt>10000 && TMath::Prob(chi2,ndof)<=0.01) pass_min_bias=false;
280 //if(n_sct_holes>1 || n_pix_holes>0) continue;
281 //if(n_pix_hits<3 || n_sct_hits<8) continue;
282 }
283 //-------------------------------------------------------------------------------------------------
284
285
286
287 //-------------------------------------------------------------------------------------------------
288 bool pass_hi_loose=true;
289 {
290 if(fabs(eta)>2.5) pass_hi_loose=false;
291 if(n_Ipix_expected>0){
292 if (n_Ipix_hits==0) pass_hi_loose=false;
293 }
294 else{
295 if(n_NIpix_expected>0 && n_NIpix_hits==0) pass_hi_loose=false;
296 }
297
298 if(n_pix_hits==0) pass_hi_loose=false;
299 if(n_sct_hits< 6) pass_hi_loose=false;
300 if(pt>10000 && TMath::Prob(chi2,ndof)<=0.01) pass_hi_loose=false;
301 if(fabs(d0) >1.5) pass_hi_loose=false;
302 if(fabs(z0_wrtPV*sin(theta))>1.5) pass_hi_loose=false;
303 }
304 //-------------------------------------------------------------------------------------------------
305
306
307
308 //-------------------------------------------------------------------------------------------------
309 bool pass_hi_loose_additional_SCT_hit=true;
310 if(!pass_hi_loose) pass_hi_loose_additional_SCT_hit=false;
311 else{
312 if(n_sct_hits<7) pass_hi_loose_additional_SCT_hit=false;
313 }
314 //-------------------------------------------------------------------------------------------------
315
316
317
318 //-------------------------------------------------------------------------------------------------
319 bool pass_hi_loose_tight_d0_z0=true;
320 if(!pass_hi_loose || fabs(d0)>1.0 || fabs(z0_wrtPV*sin(theta))>1.0) pass_hi_loose_tight_d0_z0=false;
321 //-------------------------------------------------------------------------------------------------
322
323
324
325 //-------------------------------------------------------------------------------------------------
326 bool pass_hi_loose_tighter_d0_z0=true;
327 if(!pass_hi_loose || fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_loose_tighter_d0_z0=false;
328 //-------------------------------------------------------------------------------------------------
329
330
331
332 //-------------------------------------------------------------------------------------------------
333 bool pass_hi_tight_loose_d0_z0=true;
334 if(!pass_hi_loose) pass_hi_tight_loose_d0_z0=false;
335 else{
336 if(n_pix_hits <2 ) pass_hi_tight_loose_d0_z0=false;
337 if(n_sct_hits <8 ) pass_hi_tight_loose_d0_z0=false;
338 if(n_sct_holes>1 ) pass_hi_tight_loose_d0_z0=false;
339 if(ndof==0) pass_hi_tight_loose_d0_z0=false;
340 else if(chi2/ndof>6) pass_hi_tight_loose_d0_z0=false;
341 }
342 //-------------------------------------------------------------------------------------------------
343
344
345
346 //-------------------------------------------------------------------------------------------------
347 bool pass_hi_tight=true;
348 if(!pass_hi_loose) pass_hi_tight=false;
349 else{
350 if(n_pix_hits <2 ) pass_hi_tight=false;
351 if(n_sct_hits <8 ) pass_hi_tight=false;
352 if(n_sct_holes>1 ) pass_hi_tight=false;
353 if(fabs(d0) >1.0) pass_hi_tight=false;
354 if(fabs(z0_wrtPV*sin(theta))>1.0) pass_hi_tight=false;
355 if(ndof==0) pass_hi_tight=false;
356 else if(chi2/ndof>6) pass_hi_tight=false;
357 }
358 //-------------------------------------------------------------------------------------------------
359
360
361
362 //-------------------------------------------------------------------------------------------------
363 bool pass_hi_tight_tighter_d0_z0=true;
364 if(!pass_hi_tight) pass_hi_tight_tighter_d0_z0=false;
365 else{
366 if(fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_tight_tighter_d0_z0=false;
367 }
368 //-------------------------------------------------------------------------------------------------
369
370
371
372
373
374 unsigned short quality =0;
375 if(pass_min_bias ) quality+=PP_MIN_BIAS;
376 if(pass_hi_loose ) quality+=HI_LOOSE;
377 if(pass_hi_loose_additional_SCT_hit) quality+=HI_LOOSE_7SCT_HITS;
378 if(pass_hi_loose_tight_d0_z0 ) quality+=HI_LOOSE_TIGHT_D0_Z0;
379 if(pass_hi_loose_tighter_d0_z0 ) quality+=HI_LOOSE_TIGHTER_D0_Z0;
380 if(pass_hi_tight_loose_d0_z0 ) quality+=HI_TIGHT_LOOSE_D0_Z0;
381 if(pass_hi_tight ) quality+=HI_TIGHT;
382 if(pass_hi_tight_tighter_d0_z0 ) quality+=HI_TIGHT_TIGHTER_D0_Z0;
383 return quality;
384}
385
386}
Scalar eta() const
pseudorapidity method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define CHECK(...)
Evaluate an expression and check for errors.
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_hi_tight
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_covD0Decorator
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_chi2Decorator
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerName
unsigned short GetTrackQuality(const xAOD::TrackParticle *track, float z_vtx) const
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_decorator
virtual StatusCode addBranches(const EventContext &ctx) const override final
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_pp
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_hi_loose
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_vertexIndexDecorator
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_covZ0Decorator
unsigned short GetTrackQualityNew(const xAOD::TrackParticle *track, const xAOD::Vertex *pv) const
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_covThetaDecorator
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticlesName
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Handle class for adding a decoration to an object.
const std::bitset< NBITS > & getCutResultBitSet() const
Get the cut result bitset.
Definition AcceptData.h:112
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
VxType::VertexType vertexType() const
The type of the vertex.
double chi2(TH1 *h0, TH1 *h1)
THE reconstruction tool.
@ PriVtx
Primary vertex.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.