ATLAS Offline Software
TrackParticlexAODHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include <stdexcept>
9 
10 namespace xAOD {
11 
12  namespace TrackingHelpers {
14  if (!tp) {
15  throw std::runtime_error("Invalid TrackParticle pointer.");
16  }
17  SG::AuxElement::ConstAccessor< std::vector<float> > accDiag( "definingParametersCovMatrixDiag" );
18  SG::AuxElement::ConstAccessor< std::vector<float> > accOffDiag( "definingParametersCovMatrixOffDiag" );
19  if( !(accDiag.isAvailable( *tp ) && accOffDiag.isAvailable( *tp )) ) {
20  throw std::runtime_error("TrackParticle without covariance matrix for the defining parameters.");
21  }
22  }
23 
25  if (!tp) {
26  throw std::runtime_error("Invalid TrackParticle pointer.");
27  }
28  SG::AuxElement::ConstAccessor< std::vector<float> > accDiag( "definingParametersCovMatrixDiag" );
29  if( !(accDiag.isAvailable( *tp )) ) {
30  throw std::runtime_error("TrackParticle without diagonal covariance matrix elements for the defining parameters.");
31  }
32  }
33  }
34 
36  if (!tp) return false;
37  if( tp->definingParametersCovMatrixFilled() != xAOD::FullCovMatrixAvailable ) return false;
38  return true;
39  }
40 
41  namespace TrackingHelpers {
42  inline double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2) {
44  double d0 = tp->d0();
45  // elements in definingParametersCovMatrixDiagVec should be : sigma_d0^2, sigma_z0^2
46  double sigma_d0 = tp->definingParametersCovMatrixDiagVec().at(0);
47  if (sigma_d0<=0.) {
48  throw std::runtime_error("TrackParticle with zero or negative d0 uncertainty.");
49  }
50  return d0/sqrt(sigma_d0+d0_uncert_beam_spot_2);
51  }
52  }
53 
55  return d0significance(tp,0.);
56  }
57 
58  double TrackingHelpers::d0significance(const xAOD::TrackParticle *tp, double beam_sigma_x, double beam_sigma_y, double beam_sigma_xy) {
59  if (!checkBeamSpotSigma(beam_sigma_x, beam_sigma_y, beam_sigma_xy)) {
60  throw std::runtime_error("Beamspot covariance matrix is invalid.");
61  }
62  return d0significance(tp,d0UncertaintyBeamSpot2(tp->phi(),beam_sigma_x, beam_sigma_y, beam_sigma_xy));
63  }
64 
67  double z0 = tp->z0() + tp->vz();
68  if (vx) {
69  if (!checkPVReference(tp,vx)) {
70  throw std::runtime_error("Given primary vertex does not fulfil the requirements i.e. does not exist, or is too far away from the beam axis.");
71  }
72  z0 -= vx->z();
73  }
74  // elements in definingParametersCovMatrixVec should be : sigma_d0^2, sigma_z0^2
75  double sigma_z0 = tp->definingParametersCovMatrixDiagVec().at(1);
76  if (sigma_z0<=0.) {
77  throw std::runtime_error("TrackParticle with zero or negative z0 uncertainty.");
78  }
79  return z0/sqrt(sigma_z0);
80  }
81 
84  if (!hasValidCovQoverP(tp)) {
85  throw std::runtime_error("TrackParticle without covariance matrix for defining parameters or the covariance matrix is wrong dimensionality.");
86  }
87  if (std::abs(tp->qOverP())<0) {
88  throw std::runtime_error("q/p is zero");
89  }
90  return pTErr2Unsafe(tp);
91  }
92 
93 
94 }
95 
TrackParticlexAODHelpers.h
AuxStoreAccessorMacros.h
xAOD::TrackingHelpers::checkTPAndDefiningParamCovDiag
void checkTPAndDefiningParamCovDiag(const xAOD::TrackParticle *tp)
Definition: TrackParticlexAODHelpers.cxx:24
xAOD::TrackingHelpers::d0significance
double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2)
Definition: TrackParticlexAODHelpers.cxx:42
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
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
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::checkTPAndDefiningParamCov
void checkTPAndDefiningParamCov(const xAOD::TrackParticle *tp)
Definition: TrackParticlexAODHelpers.cxx:13
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
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
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::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AuxElement.h
Base class for elements of a container that can have aux data.