ATLAS Offline Software
PatternTrackParameters.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 namespace Trk {
6 
7 inline PatternTrackParameters::PatternTrackParameters()
8  : ParametersCommon<5, Trk::Charged>() {
9  m_parameters.setZero();
10 }
11 
12 inline PatternTrackParameters::PatternTrackParameters(
13  const PatternTrackParameters& P)
14  : PatternTrackParameters() {
15  *this = P;
16 }
17 
18 inline PatternTrackParameters& PatternTrackParameters::operator=(
19  const PatternTrackParameters& P) {
20  if (&P != this) {
21  if (P.m_surface != nullptr) {
22  m_surface.reset(P.m_surface->isFree() ? P.m_surface->clone()
23  : P.m_surface.get());
24  } else {
25  m_surface.reset(nullptr);
26  }
27 
28  m_parameters = P.m_parameters;
29 
30  if (P.m_covariance != std::nullopt) {
31  if (m_covariance == std::nullopt) {
32  m_covariance = AmgSymMatrix(5)(*P.m_covariance);
33  } else {
34  *m_covariance = *P.m_covariance;
35  }
36  }
37  }
38 
39  return (*this);
40 }
41 
42 inline void PatternTrackParameters::setParameters(const Surface* s,
43  const double* p) {
44  m_surface.reset(s && s->isFree() ? s->clone() : s);
45  m_parameters[0] = p[0];
46  m_parameters[1] = p[1];
47  m_parameters[2] = p[2];
48  m_parameters[3] = p[3];
49  m_parameters[4] = p[4];
50  m_covariance.reset();
51 }
52 
53 inline void PatternTrackParameters::setCovariance(const double* c) {
54  if (m_covariance == std::nullopt) {
55  m_covariance.emplace();
56  }
57 
58  m_covariance->fillSymmetric(0, 0, c[0]);
59  m_covariance->fillSymmetric(0, 1, c[1]);
60  m_covariance->fillSymmetric(1, 1, c[2]);
61  m_covariance->fillSymmetric(0, 2, c[3]);
62  m_covariance->fillSymmetric(1, 2, c[4]);
63  m_covariance->fillSymmetric(2, 2, c[5]);
64  m_covariance->fillSymmetric(0, 3, c[6]);
65  m_covariance->fillSymmetric(1, 3, c[7]);
66  m_covariance->fillSymmetric(2, 3, c[8]);
67  m_covariance->fillSymmetric(3, 3, c[9]);
68  m_covariance->fillSymmetric(0, 4, c[10]);
69  m_covariance->fillSymmetric(1, 4, c[11]);
70  m_covariance->fillSymmetric(2, 4, c[12]);
71  m_covariance->fillSymmetric(3, 4, c[13]);
72  m_covariance->fillSymmetric(4, 4, c[14]);
73 }
74 
75 inline void PatternTrackParameters::setParametersWithCovariance(
76  const Surface* s, const double* p, const double* c) {
77  m_surface.reset(s && s->isFree() ? s->clone() : s);
78  m_parameters[0] = p[0];
79  m_parameters[1] = p[1];
80  m_parameters[2] = p[2];
81  m_parameters[3] = p[3];
82  m_parameters[4] = p[4];
83  setCovariance(c);
84 }
85 
86 inline void PatternTrackParameters::setParametersWithCovariance(
87  const Surface* s, const double* p, const AmgSymMatrix(5) & c) {
88  double C[15] = {c(0, 0), c(1, 0), c(1, 1), c(2, 0), c(2, 1),
89  c(2, 2), c(3, 0), c(3, 1), c(3, 2), c(3, 3),
90  c(4, 0), c(4, 1), c(4, 2), c(4, 3), c(4, 4)};
91  setParametersWithCovariance(s, p, C);
92 }
93 
94 inline void PatternTrackParameters::diagonalization(double D) {
95  if (m_covariance == std::nullopt) {
96  return;
97  }
98 
99  m_covariance->fillSymmetric(0, 1, 0);
100  m_covariance->fillSymmetric(0, 2, 0);
101  m_covariance->fillSymmetric(1, 2, 0);
102  m_covariance->fillSymmetric(0, 3, 0);
103  m_covariance->fillSymmetric(1, 3, 0);
104  m_covariance->fillSymmetric(2, 3, 0);
105  m_covariance->fillSymmetric(0, 4, 0);
106  m_covariance->fillSymmetric(1, 4, 0);
107  m_covariance->fillSymmetric(2, 4, 0);
108  m_covariance->fillSymmetric(3, 4, 0);
109 
110  (*m_covariance)(0, 0) *= D;
111  (*m_covariance)(1, 1) *= D;
112  (*m_covariance)(2, 2) *= D;
113  (*m_covariance)(3, 3) *= D;
114  (*m_covariance)(4, 4) *= D;
115 }
116 
117 inline void PatternTrackParameters::addNoise(const NoiseOnSurface& N,
118  PropDirection D) {
119  if (m_covariance != std::nullopt) {
120  (*m_covariance)(2, 2) += N.covarianceAzim();
121  (*m_covariance)(3, 3) += N.covariancePola();
122  (*m_covariance)(4, 4) += N.covarianceIMom();
123  }
124 
125  if (D > 0) {
126  N.correctionIMom() > 1. ? m_parameters[4] *= N.correctionIMom()
127  : m_parameters[4] /= N.correctionIMom();
128  } else {
129  N.correctionIMom() > 1. ? m_parameters[4] /= N.correctionIMom()
130  : m_parameters[4] *= N.correctionIMom();
131  }
132 }
133 
134 inline void PatternTrackParameters::removeNoise(const NoiseOnSurface& N,
135  PropDirection D) {
136  if (m_covariance != std::nullopt) {
137  (*m_covariance)(2, 2) -= N.covarianceAzim();
138  (*m_covariance)(3, 3) -= N.covariancePola();
139  (*m_covariance)(4, 4) -= N.covarianceIMom();
140  }
141 
142  if (D > 0) {
143  N.correctionIMom() > 1. ? m_parameters[4] /= N.correctionIMom()
144  : m_parameters[4] *= N.correctionIMom();
145  } else {
146  N.correctionIMom() > 1. ? m_parameters[4] *= N.correctionIMom()
147  : m_parameters[4] /= N.correctionIMom();
148  }
149 }
150 
151 inline double PatternTrackParameters::charge() const {
152  if (m_parameters[4] > 0.0) {
153  return 1.0;
154  } else {
155  return -1.0;
156  }
157 }
158 
159 inline double PatternTrackParameters::sinPhi() const {
160  return std::sin(m_parameters[2]);
161 }
162 
163 inline double PatternTrackParameters::cosPhi() const {
164  return std::cos(m_parameters[2]);
165 }
166 
167 inline double PatternTrackParameters::sinTheta() const {
168  return std::sin(m_parameters[3]);
169 }
170 
171 inline double PatternTrackParameters::cosTheta() const {
172  return std::cos(m_parameters[3]);
173 }
174 
175 inline double PatternTrackParameters::cotTheta() const {
176  return (1. / std::tan(m_parameters[3]));
177 }
178 
179 inline Amg::Vector3D PatternTrackParameters::momentum() const {
180  return calculateMomentum();
181 }
182 
183 inline double PatternTrackParameters::absoluteMomentum() const {
184  return m_parameters[4] != 0. ? 1. / std::abs(m_parameters[4]) : 10e9;
185 }
186 
187 inline double PatternTrackParameters::transverseMomentum() const {
188  double p = absoluteMomentum();
189  double Se = std::sin(m_parameters[3]);
190  return p * Se;
191 }
192 
193 inline const Surface& PatternTrackParameters::associatedSurface() const {
194  return *m_surface;
195 }
196 
197 inline bool PatternTrackParameters::hasSurface() const {
198  return m_surface != nullptr;
199 }
200 
201 inline Amg::RotationMatrix3D PatternTrackParameters::measurementFrame() const {
202  return associatedSurface().measurementFrame(this->position(),
203  this->momentum());
204 }
205 
206 inline PatternTrackParameters* PatternTrackParameters::clone() const {
207  return new PatternTrackParameters(*this);
208 }
209 
210 inline constexpr ParametersType PatternTrackParameters::type() const {
211  return Pattern;
212 }
213 
214 inline SurfaceType PatternTrackParameters::surfaceType() const {
215  return m_surface->type();
216 }
217 
218 inline void PatternTrackParameters::updateParametersHelper(const AmgVector(5) & params) {
219  m_parameters = params;
220 }
221 } // end namespace Trk