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