ATLAS Offline Software
Loading...
Searching...
No Matches
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
10namespace 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 double z0 = tp->z0() + tp->vz();
85 double sintheta = sin(tp->theta());
86 // elements in definingParametersCovMatrixVec should be : sigma_d0^2, sigma_z0^2
87 double sigma_z0 = tp->definingParametersCovMatrixDiagVec().at(1);
88 if (vx) z0 -= vx->z();
89 double costheta = cos(tp->theta());
90 double sigma_theta = tp->definingParametersCovMatrixDiagVec().at(3);
91 double sigma_z0sintheta = sigma_z0 * sintheta * sintheta + z0 * z0 * costheta * costheta * sigma_theta;
92 if (sigma_z0sintheta <= 0.) {
93 throw std::runtime_error("TrackParticle with zero or negative z0sintheta uncertainty.");
94 }
95 sigma_z0sintheta = sqrt(sigma_z0sintheta);
96 return z0 * sintheta / sigma_z0sintheta;
97
98 }
99
102 if (!hasValidCovQoverP(tp)) {
103 throw std::runtime_error("TrackParticle without covariance matrix for defining parameters or the covariance matrix is wrong dimensionality.");
104 }
105 if (std::abs(tp->qOverP())<0) {
106 throw std::runtime_error("q/p is zero");
107 }
108 return pTErr2Unsafe(tp);
109 }
110
111
112}
113
Base class for elements of a container that can have aux data.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
float z() const
Returns the z position.
double z0significance(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx=NULL)
Get the impact parameter significance of a track particle in the z direction.
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.
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.
double z0sinthetasignificance(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx=NULL)
Get the impact parameter significance of a track particle in the z direction, including the sin(theta...
void checkTPAndDefiningParamCovDiag(const xAOD::TrackParticle *tp)
double pTErr2(const xAOD::TrackParticle *tp)
compute the uncertainty of pt squared.
bool hasValidCovQoverP(const xAOD::TrackParticle *tp)
return true if the covariance matrix of the defining parameters is set, has enough elements and the q...
bool hasValidCov(const xAOD::TrackParticle *tp)
Check whether the given track particle is valid and has a covariance matrix of the defining parameter...
double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2)
bool checkBeamSpotSigma(double beam_sigma_x, double beam_sigma_y, double beam_sigma_xy)
check that the beamspot covariance matrix is valid
void checkTPAndDefiningParamCov(const xAOD::TrackParticle *tp)
double pTErr2Unsafe(const xAOD::TrackParticle *tp)
compute the uncertainty of pt squared.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
static const xAOD::ParametersCovMatrixFilled_t FullCovMatrixAvailable
Object representing a fully available covariance matrix.