Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  base_class(t,n,p)
17  {
18  declareProperty("TrackSelectionTool_pp" ,m_trkSelTool_pp );
19  declareProperty("TrackSelectionTool_hi_loose",m_trkSelTool_hi_loose);
20  declareProperty("TrackSelectionTool_hi_tight",m_trkSelTool_hi_tight);
21  }
22 
23 
24 
26  // Set up the decorators
27  SG::AuxElement::Decorator<unsigned short> decorator("TrackQuality");
28 
29  // Get Primary vertex
30  const xAOD::VertexContainer* vertices = evtStore()->retrieve< const xAOD::VertexContainer >("PrimaryVertices");
31  if(!vertices) {
32  ATH_MSG_ERROR ("Couldn't retrieve VertexContainer with key PrimaryVertices");
33  return StatusCode::FAILURE;
34  }
35  const xAOD::Vertex* pv(0);
36  for (const xAOD::Vertex* vx : *vertices) {
37  if (vx->vertexType() == xAOD::VxType::PriVtx) {
38  pv = vx;
39  break;
40  }
41  }
42 
43  //commented out, not used and generates compiler warning
44  //float z_vtx=0;
45  //if(pv) z_vtx=pv->z();
46 
47 
48  // Get the track container
49  const xAOD::TrackParticleContainer* tracks = evtStore()->retrieve< const xAOD::TrackParticleContainer >("InDetTrackParticles");
50  if(!tracks) {
51  ATH_MSG_ERROR ("Couldn't retrieve TrackParticleContainer with key InDetTrackParticles");
52  return StatusCode::FAILURE;
53  }
54 
55 
56  // Get track quality this is what we're adding
57  for(const auto* track:*tracks) {
58  //for (xAOD::TrackParticleContainer::const_iterator trackIt=tracks->begin(); trackIt!=tracks->end(); ++trackIt)
59  //std::cout<<GetTrackQuality(*trackIt,z_vtx)<<std::endl;
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 
135 unsigned short HITrackQualityAugmentationTool::GetTrackQuality(const xAOD::TrackParticle* track,float z_vtx) const {
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:33
DerivationFramework::HITrackQualityAugmentationTool::HI_LOOSE_7SCT_HITS
@ HI_LOOSE_7SCT_HITS
Definition: HITrackQualityAugmentationTool.h:29
HITrackQualityAugmentationTool.h
DerivationFramework::HITrackQualityAugmentationTool::m_trkSelTool_pp
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_pp
Definition: HITrackQualityAugmentationTool.h:43
DerivationFramework::HITrackQualityAugmentationTool::addBranches
virtual StatusCode addBranches() const
Definition: HITrackQualityAugmentationTool.cxx:25
test_pyathena.pt
pt
Definition: test_pyathena.py:11
DerivationFramework::HITrackQualityAugmentationTool::HI_LOOSE_TIGHTER_D0_Z0
@ HI_LOOSE_TIGHTER_D0_Z0
Definition: HITrackQualityAugmentationTool.h:31
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::HI_TIGHT_TIGHTER_D0_Z0
@ HI_TIGHT_TIGHTER_D0_Z0
Definition: HITrackQualityAugmentationTool.h:34
DerivationFramework::HITrackQualityAugmentationTool::m_trkSelTool_hi_loose
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_hi_loose
Definition: HITrackQualityAugmentationTool.h:44
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::m_trkSelTool_hi_tight
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool_hi_tight
Definition: HITrackQualityAugmentationTool.h:45
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: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
DerivationFramework::HITrackQualityAugmentationTool::PP_MIN_BIAS
@ PP_MIN_BIAS
Definition: HITrackQualityAugmentationTool.h:26
DerivationFramework::HITrackQualityAugmentationTool::HI_LOOSE_TIGHT_D0_Z0
@ HI_LOOSE_TIGHT_D0_Z0
Definition: HITrackQualityAugmentationTool.h:30
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
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
VertexContainer.h
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:81
DerivationFramework::HITrackQualityAugmentationTool::GetTrackQualityNew
unsigned short GetTrackQualityNew(const xAOD::TrackParticle *track, const xAOD::Vertex *pv) const
Definition: HITrackQualityAugmentationTool.cxx:68
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
TrackParticleContainer.h