ATLAS Offline Software
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 
7 namespace DerivationFramework {
8 
10  const std::string& n,
11  const IInterface* p) :
12  base_class(t,n,p)
13  {
14  }
15 
17 {
19  ATH_CHECK(m_vertexContainerName.initialize());
22 
23  CHECK(m_trkSelTool_pp.retrieve());
24  CHECK(m_trkSelTool_hi_loose.retrieve());
25  CHECK(m_trkSelTool_hi_tight.retrieve());
26 
27  return StatusCode::SUCCESS;
28 }
29 
30 
32  const EventContext& ctx = Gaudi::Hive::currentContext();
33 
34  // Get Primary vertex
36  if(!vertices.isValid()) {
37  ATH_MSG_ERROR ("Couldn't retrieve VertexContainer with key " << m_vertexContainerName.key());
38  return StatusCode::FAILURE;
39  }
40  const xAOD::Vertex* pv(0);
41  for (const xAOD::Vertex* vx : *vertices) {
42  if (vx->vertexType() == xAOD::VxType::PriVtx) {
43  pv = vx;
44  break;
45  }
46  }
47 
48  // Get the track container
50  if(!tracks.isValid()) {
51  ATH_MSG_ERROR ("Couldn't retrieve TrackParticleContainer with key " << m_trackParticlesName.key());
52  return StatusCode::FAILURE;
53  }
54 
55  // Decorator
57 
58  // Get track quality this is what we're adding
59  for(const auto* track:*tracks) {
60  if(pv) decorator(*track) =GetTrackQualityNew(track,pv);
61  else decorator(*track) = 0;
62  }
63 
64  return StatusCode::SUCCESS;
65 }
66 
67 
69 
70  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_hits("numberOfSCTHits");
71  int n_sct_hits = acc_n_sct_hits(*track);
72 
73 
74  float d0 = track->d0();
75  float z0_wrtPV= track->z0()+track->vz()-pv->z();
76  float theta = track->theta();
77 
78  //-------------------------------------------------------------------------------------------------
79  bool pass_min_bias=false;
80  if (m_trkSelTool_pp->accept(*track, pv)) pass_min_bias=true;
81  //-------------------------------------------------------------------------------------------------
82  //-------------------------------------------------------------------------------------------------
83  bool pass_hi_loose=false;
84  if (m_trkSelTool_hi_loose->accept(*track, pv)) pass_hi_loose=true;
85  //-------------------------------------------------------------------------------------------------
86  //-------------------------------------------------------------------------------------------------
87  bool pass_hi_loose_additional_SCT_hit=true;
88  if(!pass_hi_loose || n_sct_hits<7) pass_hi_loose_additional_SCT_hit=false;
89  //-------------------------------------------------------------------------------------------------
90  //-------------------------------------------------------------------------------------------------
91  bool pass_hi_loose_tight_d0_z0=true;
92  if(!pass_hi_loose || fabs(d0)>1.0 || fabs(z0_wrtPV*sin(theta))>1.0) pass_hi_loose_tight_d0_z0=false;
93  //-------------------------------------------------------------------------------------------------
94  //-------------------------------------------------------------------------------------------------
95  bool pass_hi_loose_tighter_d0_z0=true;
96  if(!pass_hi_loose || fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_loose_tighter_d0_z0=false;
97  //-------------------------------------------------------------------------------------------------
98  //-------------------------------------------------------------------------------------------------
99  bool pass_hi_tight=false;
100  if (m_trkSelTool_hi_tight->accept(*track, pv)) pass_hi_tight=true;
101  //-------------------------------------------------------------------------------------------------
102  //-------------------------------------------------------------------------------------------------
103  bool pass_hi_tight_loose_d0_z0=true;
104  if(pass_hi_tight==false){
105  const auto& taccept = m_trkSelTool_hi_tight->getAcceptInfo();
106  asg::AcceptData acceptData(&taccept);
107  static const auto d0Index = taccept.getCutPosition("D0");
108  static const auto z0Index = taccept.getCutPosition("Z0SinTheta");
109  static const auto nCuts = taccept.getNCuts();
110  auto cutBitset = acceptData.getCutResultBitSet();
111  cutBitset |= (1 << d0Index) | (1 << z0Index);
112  if(cutBitset.count() != nCuts ) pass_hi_tight_loose_d0_z0=false;
113  if(fabs(d0)>1.5 || fabs(z0_wrtPV*sin(theta))>1.5) pass_hi_tight_loose_d0_z0=false;
114  }
115  //-------------------------------------------------------------------------------------------------
116  //-------------------------------------------------------------------------------------------------
117  bool pass_hi_tight_tighter_d0_z0=true;
118  if(!pass_hi_tight || fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_tight_tighter_d0_z0=false;
119  //-------------------------------------------------------------------------------------------------
120 
121  unsigned short quality =0;
122  if(pass_min_bias ) quality+=PP_MIN_BIAS;
123  if(pass_hi_loose ) quality+=HI_LOOSE;
124  if(pass_hi_loose_additional_SCT_hit) quality+=HI_LOOSE_7SCT_HITS;
125  if(pass_hi_loose_tight_d0_z0 ) quality+=HI_LOOSE_TIGHT_D0_Z0;
126  if(pass_hi_loose_tighter_d0_z0 ) quality+=HI_LOOSE_TIGHTER_D0_Z0;
127  if(pass_hi_tight_loose_d0_z0 ) quality+=HI_TIGHT_LOOSE_D0_Z0;
128  if(pass_hi_tight ) quality+=HI_TIGHT;
129  if(pass_hi_tight_tighter_d0_z0 ) quality+=HI_TIGHT_TIGHTER_D0_Z0;
130  return quality;
131 }
132 
133 
134 
136  //-------------------------------------------------------------------------------------------------
137  float pt = track->pt();
138  float eta = track->eta();
139  //float phi = track->phi();
140 
141 
142  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_Ipix_hits("numberOfInnermostPixelLayerHits");
143  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_Ipix_expected("expectInnermostPixelLayerHit");
144  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_NIpix_hits("numberOfNextToInnermostPixelLayerHits");
145  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_NIpix_expected("expectNextToInnermostPixelLayerHit");
146  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_hits("numberOfSCTHits");
147  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_pix_hits("numberOfPixelHits");
148  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_holes("numberOfSCTHoles");
149  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_sct_dead("numberOfSCTDeadSensors");
150  static const SG::AuxElement::ConstAccessor<unsigned char> acc_n_pix_dead("numberOfPixelDeadSensors");
151 
152  int n_Ipix_hits = acc_n_Ipix_hits(*track);
153  int n_Ipix_expected = acc_n_Ipix_expected(*track);
154  int n_NIpix_hits = acc_n_NIpix_hits(*track);
155  int n_NIpix_expected = acc_n_NIpix_expected(*track);
156  int n_sct_hits = acc_n_sct_hits(*track);
157  int n_pix_hits = acc_n_pix_hits(*track);
158  int n_sct_holes = acc_n_sct_holes(*track);
159  int n_sct_dead = acc_n_sct_dead(*track);
160  int n_pix_dead = acc_n_pix_dead(*track);
161 
162 
163  float chi2=track->chiSquared();
164  float ndof=track->numberDoF();
165 
166  float d0 = track->d0();
167  float z0_wrtPV= track->z0()+track->vz()-z_vtx;
168  float theta = track->theta();
169  //-------------------------------------------------------------------------------------------------
170 
171 
172  //-------------------------------------------------------------------------------------------------
173  bool pass_min_bias=true;
174  {
175  if(fabs(eta)>2.5) pass_min_bias=false;
176  if(n_Ipix_expected>0){
177  if (n_Ipix_hits==0) pass_min_bias=false;
178  }
179  else{
180  if(n_NIpix_expected>0 && n_NIpix_hits==0) pass_min_bias=false;
181  }
182 
183  int n_sct=n_sct_hits+n_sct_dead;
184  if (pt<=300) {if (n_sct <2) pass_min_bias=false;}
185  else if(pt<=400) {if (n_sct <4) pass_min_bias=false;}
186  else if(pt> 400) {if (n_sct <6) pass_min_bias=false;}
187 
188  int n_pix=n_pix_hits+n_pix_dead;
189  if(n_pix<=0) pass_min_bias=false;
190 
191  if(fabs(d0)>1.5) pass_min_bias=false;
192  if(fabs(z0_wrtPV*sin(theta))>1.5) pass_min_bias=false;
193 
194  if(pt>10000 && TMath::Prob(chi2,ndof)<=0.01) pass_min_bias=false;
195  //if(n_sct_holes>1 || n_pix_holes>0) continue;
196  //if(n_pix_hits<3 || n_sct_hits<8) continue;
197  }
198  //-------------------------------------------------------------------------------------------------
199 
200 
201 
202  //-------------------------------------------------------------------------------------------------
203  bool pass_hi_loose=true;
204  {
205  if(fabs(eta)>2.5) pass_hi_loose=false;
206  if(n_Ipix_expected>0){
207  if (n_Ipix_hits==0) pass_hi_loose=false;
208  }
209  else{
210  if(n_NIpix_expected>0 && n_NIpix_hits==0) pass_hi_loose=false;
211  }
212 
213  if(n_pix_hits==0) pass_hi_loose=false;
214  if(n_sct_hits< 6) pass_hi_loose=false;
215  if(pt>10000 && TMath::Prob(chi2,ndof)<=0.01) pass_hi_loose=false;
216  if(fabs(d0) >1.5) pass_hi_loose=false;
217  if(fabs(z0_wrtPV*sin(theta))>1.5) pass_hi_loose=false;
218  }
219  //-------------------------------------------------------------------------------------------------
220 
221 
222 
223  //-------------------------------------------------------------------------------------------------
224  bool pass_hi_loose_additional_SCT_hit=true;
225  if(!pass_hi_loose) pass_hi_loose_additional_SCT_hit=false;
226  else{
227  if(n_sct_hits<7) pass_hi_loose_additional_SCT_hit=false;
228  }
229  //-------------------------------------------------------------------------------------------------
230 
231 
232 
233  //-------------------------------------------------------------------------------------------------
234  bool pass_hi_loose_tight_d0_z0=true;
235  if(!pass_hi_loose || fabs(d0)>1.0 || fabs(z0_wrtPV*sin(theta))>1.0) pass_hi_loose_tight_d0_z0=false;
236  //-------------------------------------------------------------------------------------------------
237 
238 
239 
240  //-------------------------------------------------------------------------------------------------
241  bool pass_hi_loose_tighter_d0_z0=true;
242  if(!pass_hi_loose || fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_loose_tighter_d0_z0=false;
243  //-------------------------------------------------------------------------------------------------
244 
245 
246 
247  //-------------------------------------------------------------------------------------------------
248  bool pass_hi_tight_loose_d0_z0=true;
249  if(!pass_hi_loose) pass_hi_tight_loose_d0_z0=false;
250  else{
251  if(n_pix_hits <2 ) pass_hi_tight_loose_d0_z0=false;
252  if(n_sct_hits <8 ) pass_hi_tight_loose_d0_z0=false;
253  if(n_sct_holes>1 ) pass_hi_tight_loose_d0_z0=false;
254  if(ndof==0) pass_hi_tight_loose_d0_z0=false;
255  else if(chi2/ndof>6) pass_hi_tight_loose_d0_z0=false;
256  }
257  //-------------------------------------------------------------------------------------------------
258 
259 
260 
261  //-------------------------------------------------------------------------------------------------
262  bool pass_hi_tight=true;
263  if(!pass_hi_loose) pass_hi_tight=false;
264  else{
265  if(n_pix_hits <2 ) pass_hi_tight=false;
266  if(n_sct_hits <8 ) pass_hi_tight=false;
267  if(n_sct_holes>1 ) pass_hi_tight=false;
268  if(fabs(d0) >1.0) pass_hi_tight=false;
269  if(fabs(z0_wrtPV*sin(theta))>1.0) pass_hi_tight=false;
270  if(ndof==0) pass_hi_tight=false;
271  else if(chi2/ndof>6) pass_hi_tight=false;
272  }
273  //-------------------------------------------------------------------------------------------------
274 
275 
276 
277  //-------------------------------------------------------------------------------------------------
278  bool pass_hi_tight_tighter_d0_z0=true;
279  if(!pass_hi_tight) pass_hi_tight_tighter_d0_z0=false;
280  else{
281  if(fabs(d0)>0.5 || fabs(z0_wrtPV*sin(theta))>0.5) pass_hi_tight_tighter_d0_z0=false;
282  }
283  //-------------------------------------------------------------------------------------------------
284 
285 
286 
287 
288 
289  unsigned short quality =0;
290  if(pass_min_bias ) quality+=PP_MIN_BIAS;
291  if(pass_hi_loose ) quality+=HI_LOOSE;
292  if(pass_hi_loose_additional_SCT_hit) quality+=HI_LOOSE_7SCT_HITS;
293  if(pass_hi_loose_tight_d0_z0 ) quality+=HI_LOOSE_TIGHT_D0_Z0;
294  if(pass_hi_loose_tighter_d0_z0 ) quality+=HI_LOOSE_TIGHTER_D0_Z0;
295  if(pass_hi_tight_loose_d0_z0 ) quality+=HI_TIGHT_LOOSE_D0_Z0;
296  if(pass_hi_tight ) quality+=HI_TIGHT;
297  if(pass_hi_tight_tighter_d0_z0 ) quality+=HI_TIGHT_TIGHTER_D0_Z0;
298  return quality;
299 }
300 
301 }
IDTPM::ndof
float ndof(const U &p)
Definition: TrackParametersHelper.h:134
DerivationFramework::HITrackQualityAugmentationTool::HI_TIGHT
@ HI_TIGHT
Definition: HITrackQualityAugmentationTool.h:35
DerivationFramework::HITrackQualityAugmentationTool::HI_LOOSE_7SCT_HITS
@ HI_LOOSE_7SCT_HITS
Definition: HITrackQualityAugmentationTool.h:31
DerivationFramework::HITrackQualityAugmentationTool::m_decorator
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_decorator
Definition: HITrackQualityAugmentationTool.h:51
HITrackQualityAugmentationTool.h
DerivationFramework::HITrackQualityAugmentationTool::m_trkSelTool_pp
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_pp
Definition: HITrackQualityAugmentationTool.h:53
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
test_pyathena.pt
pt
Definition: test_pyathena.py:11
DerivationFramework::HITrackQualityAugmentationTool::HI_LOOSE_TIGHTER_D0_Z0
@ HI_LOOSE_TIGHTER_D0_Z0
Definition: HITrackQualityAugmentationTool.h:33
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::HITrackQualityAugmentationTool::HI_TIGHT_TIGHTER_D0_Z0
@ HI_TIGHT_TIGHTER_D0_Z0
Definition: HITrackQualityAugmentationTool.h:36
DerivationFramework::HITrackQualityAugmentationTool::m_trkSelTool_hi_loose
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_hi_loose
Definition: HITrackQualityAugmentationTool.h:54
asg::AcceptData::getCutResultBitSet
const std::bitset< NBITS > & getCutResultBitSet() const
Get the cut result bitset.
Definition: AcceptData.h:112
DerivationFramework::HITrackQualityAugmentationTool::GetTrackQuality
unsigned short GetTrackQuality(const xAOD::TrackParticle *track, float z_vtx) const
Definition: HITrackQualityAugmentationTool.cxx:135
DerivationFramework::HITrackQualityAugmentationTool::addBranches
virtual StatusCode addBranches() const override
Definition: HITrackQualityAugmentationTool.cxx:31
DerivationFramework::HITrackQualityAugmentationTool::m_trkSelTool_hi_tight
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_hi_tight
Definition: HITrackQualityAugmentationTool.h:55
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
DerivationFramework::HITrackQualityAugmentationTool::HITrackQualityAugmentationTool
HITrackQualityAugmentationTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: HITrackQualityAugmentationTool.cxx:9
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:727
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:525
TRT::Track::d0
@ d0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:62
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework::HITrackQualityAugmentationTool::PP_MIN_BIAS
@ PP_MIN_BIAS
Definition: HITrackQualityAugmentationTool.h:28
DerivationFramework::HITrackQualityAugmentationTool::m_trackParticlesName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticlesName
Definition: HITrackQualityAugmentationTool.h:48
DerivationFramework::HITrackQualityAugmentationTool::HI_LOOSE_TIGHT_D0_Z0
@ HI_LOOSE_TIGHT_D0_Z0
Definition: HITrackQualityAugmentationTool.h:32
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DerivationFramework::HITrackQualityAugmentationTool::HI_LOOSE
@ HI_LOOSE
Definition: HITrackQualityAugmentationTool.h:30
DerivationFramework::HITrackQualityAugmentationTool::HI_TIGHT_LOOSE_D0_Z0
@ HI_TIGHT_LOOSE_D0_Z0
Definition: HITrackQualityAugmentationTool.h:37
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
python.TrackLeptonConfig.quality
quality
Definition: TrackLeptonConfig.py:16
python.changerun.pv
pv
Definition: changerun.py:79
DerivationFramework::HITrackQualityAugmentationTool::GetTrackQualityNew
unsigned short GetTrackQualityNew(const xAOD::TrackParticle *track, const xAOD::Vertex *pv) const
Definition: HITrackQualityAugmentationTool.cxx:68
DerivationFramework::HITrackQualityAugmentationTool::m_vertexContainerName
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerName
Definition: HITrackQualityAugmentationTool.h:49
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
asg::AcceptData
Definition: AcceptData.h:30
DerivationFramework::HITrackQualityAugmentationTool::initialize
virtual StatusCode initialize() override
Definition: HITrackQualityAugmentationTool.cxx:16