ATLAS Offline Software
Loading...
Searching...
No Matches
TrackingDetails.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef XAODTRACKING_TRACKINGDETAILS_H
6#define XAODTRACKING_TRACKINGDETAILS_H
7
9#include "Math/Vector4D.h"
10#include <span>
11
12namespace xAOD
13{
15 {
36
38 using GenVecFourMom_t = ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >;
39
41 constexpr std::size_t COVMATRIX_OFFDIAG_VEC_COMPR_SIZE = 6;
42 constexpr std::array< std::pair<covMatrixIndex,covMatrixIndex>, COVMATRIX_OFFDIAG_VEC_COMPR_SIZE > covMatrixComprIndexPairs {{
45
46
47 [[nodiscard]] inline float charge (float qOverP) {
48 return (qOverP > 0) ? 1 : ((qOverP < 0) ? -1 : 0);
49 }
50
51
52 [[nodiscard]] inline GenVecFourMom_t genvecP4(float qOverP, float thetaT, float phiT, double m) {
53 using namespace std;
54 float p = 10.e6; // 10 TeV (default value for very high pt muons, with qOverP==0)
55 if (fabs(qOverP)>0.) p = 1/fabs(qOverP);
56 float sinTheta= sin(thetaT);
57 float px = p*sinTheta*cos(phiT);
58 float py = p*sinTheta*sin(phiT);
59 float pz = p*cos(thetaT);
60 return GenVecFourMom_t(px, py, pz, m);
61 }
62
63
64
65 [[nodiscard]] inline bool definingParametersCovMatrixOffDiagCompr(std::span< const float > covMatrixOffDiag) {
66
67 bool flag = false;
68 flag = (static_cast< int >(covMatrixOffDiag.size())==COVMATRIX_OFFDIAG_VEC_COMPR_SIZE);
69 return flag;
70 }
71
72
73
74 [[nodiscard]] inline xAOD::ParametersCovMatrix_t definingParametersCovMatrix( std::span< const float > covMatrixDiag, std::span< const float > covMatrixOffDiag, bool& valid ) {
75
76 // Set up the result matrix.
77 xAOD::ParametersCovMatrix_t cov;
78 cov.setZero();
79 valid = true;
80
81 // Set the diagonal elements of the matrix.
82 if( ( static_cast< int >( covMatrixDiag.size() ) == cov.rows() ) ) {
83
84 // Access the "raw" variable.
85 // Set the diagonal elements using the raw variable.
86 for( int i = 0; i < cov.rows(); ++i ) {
87 cov( i, i ) = covMatrixDiag[ i ];
88 }
89 } else {
90 valid = false;
91 // If the variable is not available/set, set the matrix to identity.
92 cov.setIdentity();
93 }
94
95 bool offDiagCompr = definingParametersCovMatrixOffDiagCompr(covMatrixOffDiag);
96
97 // Set the off-diagonal elements of the matrix.
98 if(!offDiagCompr){
99
100 if( ( static_cast< int >( covMatrixOffDiag.size() ) == ( ( ( cov.rows() - 1 ) * cov.rows() ) / 2 ) ) ) {
101
102 // Set the off-diagonal elements using the raw variable.
103 std::size_t vecIndex = 0;
104 for( int i = 1; i < cov.rows(); ++i ) {
105 for( int j = 0; j < i; ++j, ++vecIndex ) {
106 float offDiagCoeff = cov(i,i)>0 && cov(j,j)>0 ? covMatrixOffDiag[vecIndex]*sqrt(cov(i,i)*cov(j,j)) : 0;
107 cov.fillSymmetric( i, j, offDiagCoeff );
108 }
109 }
110 }
111
112 else valid = false;
113
114 }
115
116 else{ //Compressed case
117
118 if( ( static_cast< int >( covMatrixOffDiag.size() ) == COVMATRIX_OFFDIAG_VEC_COMPR_SIZE ) ) {
119 // Set the off-diagonal elements using the raw variable.
120
121 const auto& vecPairIndex = covMatrixComprIndexPairs;
122
123 for(unsigned int k=0; k<COVMATRIX_OFFDIAG_VEC_COMPR_SIZE; ++k){
124 std::pair<covMatrixIndex,covMatrixIndex> pairIndex = vecPairIndex[k];
125 covMatrixIndex i = pairIndex.first;
126 covMatrixIndex j = pairIndex.second;
127 float offDiagCoeff = cov(i,i)>0 && cov(j,j)>0 ? covMatrixOffDiag[k]*sqrt(cov(i,i)*cov(j,j)) : 0;
128 cov.fillSymmetric( i, j, offDiagCoeff );
129 }
130
131 }
132
133 else valid = false;
134
135 }
136
137
138 // Return the filled matrix.
139 return cov;
140
141 }
142 }
143}
144
145#endif
STL namespace.
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzM4D< double > > GenVecFourMom_t
Base 4 Momentum type for TrackParticle.
GenVecFourMom_t genvecP4(float qOverP, float thetaT, float phiT, double m)
bool definingParametersCovMatrixOffDiagCompr(std::span< const float > covMatrixOffDiag)
xAOD::ParametersCovMatrix_t definingParametersCovMatrix(std::span< const float > covMatrixDiag, std::span< const float > covMatrixOffDiag, bool &valid)
constexpr std::size_t COVMATRIX_OFFDIAG_VEC_COMPR_SIZE
constexpr std::array< std::pair< covMatrixIndex, covMatrixIndex >, COVMATRIX_OFFDIAG_VEC_COMPR_SIZE > covMatrixComprIndexPairs
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.