ATLAS Offline Software
TrackParticlexAODHelpers.h
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // $Id: $
8 #ifndef XAOD_TRACKPARTICLEXAODHELPERS_H
9 #define XAOD_TRACKPARTICLEXAODHELPERS_H
10 
12 #include "xAODTracking/Vertex.h"
13 #include <cmath>
14 
15 
16 namespace xAOD {
17 
18  namespace TrackingHelpers {
20  inline
21  double sqr(double a) { return a*a; }
22 
27  double d0significance(const xAOD::TrackParticle *tp);
28 
34  inline
36  double d0 = tp->d0();
37  // elements in definingParametersCovMatrixDiagVec should be : sigma_d0^2, sigma_z0^2
38  double sigma_d0 = std::sqrt( tp->definingParametersCovMatrixDiagVec()[0] );
39  return d0/sigma_d0;
40  }
41 
48  inline
49  double d0UncertaintyBeamSpot2(double track_phi0, double beam_sigma_x,double beam_sigma_y, double beam_sigma_xy) {
50  double sin_phi = sin(track_phi0);
51  double cos_phi = cos(track_phi0);
52  double d0_uncert2= sin_phi * ( sin_phi * sqr(beam_sigma_x)
53  -cos_phi * beam_sigma_xy)
54  +cos_phi * ( cos_phi * sqr(beam_sigma_y)
55  -sin_phi * beam_sigma_xy);
56  return d0_uncert2;
57  }
58 
59 
67  double d0significance(const xAOD::TrackParticle *tp, double beam_sigma_x, double beam_sigma_y, double beam_sigma_xy);
68 
77  // In case beam_sigma_xy is larger than the square of beam_sigma_x and the square of beam_sigma_y the result is undefined.
79  inline
80  double d0significanceUnsafe(const xAOD::TrackParticle *tp, double beam_sigma_x,double beam_sigma_y, double beam_sigma_xy) {
81  double d0 = tp->d0();
82  double sigma_d0 = std::sqrt( tp->definingParametersCovMatrixDiagVec()[0] + d0UncertaintyBeamSpot2(tp->phi(),beam_sigma_x, beam_sigma_y, beam_sigma_xy) );
83  return d0/sigma_d0;
84  }
85 
94  double z0significance(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx=NULL);
95 
100  inline
102  double z0 = tp->z0() + tp->vz();
103  double sigma_z0 = std::sqrt( tp->definingParametersCovMatrixDiagVec()[1] );
104  return z0/sigma_z0;
105  }
106 
116  inline
118  // use z0 relative to the given primary vertex.
119  double z0 = tp->z0() + tp->vz() - vx->z();
120 
121  double sigma_z0 = std::sqrt( tp->definingParametersCovMatrixDiagVec()[1] );
122  return z0/sigma_z0;
123  }
124 
125 
128  bool hasValidCov(const xAOD::TrackParticle *tp);
129 
132  inline
134  if (hasValidCov(tp)) {
135  if (tp->definingParametersCovMatrixDiagVec()[0]>0.) {
136  return true;
137  }
138  }
139  return false;
140  }
141 
144  inline
146  if (hasValidCov(tp)) {
147  if ( tp->definingParametersCovMatrixDiagVec()[1] > 0. ) {
148  return true;
149  }
150  }
151  return false;
152  }
153 
156  inline
158  if (hasValidCov(tp)) {
159  if ( ( tp->definingParametersCovMatrixDiagVec()[0] > 0. )
160  && ( tp->definingParametersCovMatrixDiagVec()[1] > 0. ) ) {
161  return true;
162  }
163  }
164  return false;
165  }
166 
167 
175  inline
176  bool checkPVReference(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx, const double max_pv_dxy_sqr=0.5*0.5) {
177  if (hasValidCovD0(tp) && vx) {
178  return std::abs( sqr(vx->x())+ sqr(vx->y())) < max_pv_dxy_sqr * tp->definingParametersCovMatrixDiagVec()[0];
179  }
180  return false;
181  }
182 
188  inline
189  bool checkBeamSpotSigma(double beam_sigma_x,double beam_sigma_y, double beam_sigma_xy) {
190  return sqr(beam_sigma_x)+sqr(beam_sigma_y)>=2*std::abs(beam_sigma_xy);
191  }
192 
196  double pTErr2(const xAOD::TrackParticle *tp);
197 
201  inline
202  double pTErr(const xAOD::TrackParticle *tp) {
203  return sqrt( pTErr2(tp) );
204  }
205 
206 
210  inline
212 
213  // / d \2 / d \2 d d
214  // pt_err^2 =| ------ (pt) *sigma_q/p | + | -------- pt * sigma_theta | + ----- pt ------- pt * sigma_theta_qp
215  // \ d q/p / \ d theta / d qp d theta
216 
217  // d / d pt 2 d pt \ / d pt \2
218  // = ------ (pt) * | ----- sigma_q/p + ------- * sigma_theta_qp | + | ------- * sigma_theta |
219  // d q/p \ d q/p d theta / \ d theta /
220 
221  // d pt
222  // ------ pt = - -------------
223  // d q/p fabs(qOverP)
224 
225  // d pt
226  // ------- pt = -----------
227  // d theta tan(theta)
228 
229  double pt = tp->pt();
230  double diff_qp = - pt / std::abs(tp->qOverP());
231 
232  double diff_theta = pt / tan( tp->theta() );
233 
234  // since 1/tan (thata) defined for all floats 0..M_PI, don't have to protect :
235  //
236  // double diff_theta = ( std::abs(tp->theta()-M_PI_2) > std::numeric_limits<float>::epsilon() * 2
237  // ? pt / tan( tp->theta() )
238  // : 0 )
239 
240  auto cov = tp->definingParametersCovMatrix();
241  // elements in definingParametersCovMatrix should be : 0: sigma_d0^2,
242  // 1: sigma_d0_z0, sigma_z0^2,
243  // 3: sigma_d0_phi, sigma_z0_phi, sigma_phi^2
244  // 6: sigma_d0_th, sigma_z0_th, sigma_phi_th, sigma_th^2
245  // 10: sigma_d0_qp, sigma_z0_qp, sigma_phi_qp, sigma_th_qp, sigma_qp^2
246 
247  double pt_err2 = diff_qp * (diff_qp * cov(4, 4) + diff_theta * cov(3, 4) ) + sqr(diff_theta) * cov(3, 3);
248  return pt_err2;
249  }
250 
254  inline
256  return sqrt(pTErr2Unsafe(tp));
257  }
258 
261  inline
263  if (hasValidCov(tp)) {
264  if (std::abs(tp->qOverP())>0.) {
265  return true;
266  }
267  }
268  return false;
269  }
270 
271  }// TrackParticleHelpers
272 
273 } // namespace xAOD
274 
275 #endif // XAOD_TRACKPARTICLEXAODHELPERS_H
xAOD::Vertex_v1::x
float x() const
Returns the x position.
xAOD::TrackingHelpers::pTErr
double pTErr(const xAOD::TrackParticle *tp)
compute the uncertainty of pt.
Definition: TrackParticlexAODHelpers.h:202
xAOD::TrackingHelpers::hasValidCovZ0
bool hasValidCovZ0(const xAOD::TrackParticle *tp)
Check whether the given track particle is valid and has a valid z0 uncertainty.
Definition: TrackParticlexAODHelpers.h:145
xAOD::TrackingHelpers::d0significance
double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2)
Definition: TrackParticlexAODHelpers.cxx:42
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
xAOD::TrackingHelpers::hasValidCovD0andZ0
bool hasValidCovD0andZ0(const xAOD::TrackParticle *tp)
Check whether the given track particle is valid and has a valid d0 and z0 uncertainty.
Definition: TrackParticlexAODHelpers.h:157
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::pt
setRcore setEtHad setFside pt
Definition: TrigPhoton_v1.cxx:106
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
xAOD::TrackingHelpers::hasValidCov
bool hasValidCov(const xAOD::TrackParticle *tp)
Check whether the given track particle is valid and has a covariance matrix of the defining parameter...
Definition: TrackParticlexAODHelpers.cxx:35
xAOD::TrackingHelpers::d0UncertaintyBeamSpot2
double d0UncertaintyBeamSpot2(double track_phi0, double beam_sigma_x, double beam_sigma_y, double beam_sigma_xy)
calculate the squared d0 uncertainty component due to the size of the beam spot.
Definition: TrackParticlexAODHelpers.h:49
xAOD::TrackingHelpers::checkBeamSpotSigma
bool checkBeamSpotSigma(double beam_sigma_x, double beam_sigma_y, double beam_sigma_xy)
check that the beamspot covariance matrix is valid
Definition: TrackParticlexAODHelpers.h:189
xAOD::TrackingHelpers::hasValidCovQoverP
bool hasValidCovQoverP(const xAOD::TrackParticle *tp)
return true if the covariance matrix of the defining parameters is set, has enough elements and the q...
Definition: TrackParticlexAODHelpers.h:262
xAOD::TrackingHelpers::z0significance
double z0significance(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx=NULL)
Get the impact parameter significance of a track particle in the z direction.
Definition: TrackParticlexAODHelpers.cxx:65
xAOD::TrackingHelpers::pTErr2Unsafe
double pTErr2Unsafe(const xAOD::TrackParticle *tp)
compute the uncertainty of pt squared.
Definition: TrackParticlexAODHelpers.h:211
xAOD::TrackingHelpers::pTErr2
double pTErr2(const xAOD::TrackParticle *tp)
compute the uncertainty of pt squared.
Definition: TrackParticlexAODHelpers.cxx:82
TRT::Track::d0
@ d0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:62
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
xAOD::Vertex_v1::z
float z() const
Returns the z position.
TRT::Track::z0
@ z0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:63
Vertex.h
xAOD::TrackingHelpers::hasValidCovD0
bool hasValidCovD0(const xAOD::TrackParticle *tp)
Check whether the given track particle is valid and has a valid d0 uncertainty.
Definition: TrackParticlexAODHelpers.h:133
xAOD::TrackingHelpers::z0significanceUnsafe
double z0significanceUnsafe(const xAOD::TrackParticle *tp)
Unsafe version of z0significance.
Definition: TrackParticlexAODHelpers.h:101
xAOD::TrackingHelpers::checkPVReference
bool checkPVReference(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx, const double max_pv_dxy_sqr=0.5 *0.5)
test whether the given primary vertex has a significant displacement in r-phi wrt.
Definition: TrackParticlexAODHelpers.h:176
xAOD::TrackingHelpers::sqr
double sqr(double a)
convenience method to calculate the square of a value.
Definition: TrackParticlexAODHelpers.h:21
TrackParticle.h
xAOD::TrackingHelpers::pTErrUnsafe
double pTErrUnsafe(const xAOD::TrackParticle *tp)
compute the uncertainty of pt.
Definition: TrackParticlexAODHelpers.h:255
a
TList * a
Definition: liststreamerinfos.cxx:10
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::TrackingHelpers::d0significanceUnsafe
double d0significanceUnsafe(const xAOD::TrackParticle *tp)
Unsafe version of d0significance.
Definition: TrackParticlexAODHelpers.h:35
xAOD::Vertex_v1::y
float y() const
Returns the y position.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36