ATLAS Offline Software
Loading...
Searching...
No Matches
PatternTrackParameters.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// PatternTrackParameters.cxx , (c) ATLAS Detector software
8
9
17#include <iostream>
18#include <iomanip>
19#include <sstream>
20
22// Conversion Trk::PatternTrackParameters to Trk::TrackParameters
24
25std::unique_ptr<Trk::TrackParameters>
27{
28 std::optional<AmgSymMatrix(5)> e = std::nullopt;
29 if (covariance && m_covariance != std::nullopt) {
30 e = AmgSymMatrix(5)(*m_covariance);
31 }
32 const AmgVector(5)& p = m_parameters;
33 return m_surface ? m_surface->createUniqueTrackParameters(
34 p[0], p[1], p[2], p[3], p[4], std::move(e))
35 : nullptr;
36}
37
39// Conversion Trk::TrackParameters to Trk::PatternTrackParameters
41
43
44 if (!T) {
45 return false;
46 }
47 if (!T->hasSurface()) {
48 return false;
49 }
50
51 m_surface.reset(T->associatedSurface().isFree() ? T->associatedSurface().clone() : &T->associatedSurface());
52
53 m_parameters = T->parameters();
54
55 const AmgSymMatrix(5)* C = T->covariance();
56
57 if(C) {
58 if (m_covariance == std::nullopt) {
59 m_covariance.emplace();
60 }
61
62 for (std::size_t i = 0; i < 5; i++) {
63 for (std::size_t j = 0; j <= i; j++) {
64 m_covariance->fillSymmetric(i, j, (*C)(i, j));
65 }
66 }
67 }
68 else {
69 m_covariance.reset();
70 }
71
72 return true;
73}
74
76// Global position of simple track parameters
78
83
85// Overload of << operator std::ostream
87
88std::ostream& Trk::operator <<
89 (std::ostream& sl,const Trk::PatternTrackParameters& se)
90{
91 return se.dump(sl);
92}
93
94MsgStream& Trk::operator <<
95(MsgStream& sl, const Trk::PatternTrackParameters& se)
96{
97 return se.dump(sl);
98}
99
101// Put track parameters information in a string representation
103
104std::string
106 std::stringstream ss;
107 const Trk::Surface* s = m_surface.get();
108 const AmgVector(5)& P = m_parameters;
109 const std::string name{s?s->name():""};
110 const std::string N("\n");
111 ss << "Track parameters for " << name << " surface " << N;
112 ss.unsetf(std::ios::fixed);
113 ss.setf (std::ios::showpos);
114 ss.setf (std::ios::scientific);
115 if (m_covariance != std::nullopt) {
116 const AmgSymMatrix(5) & V = *m_covariance;
117 ss << std::setprecision(4) <<
118 P[ 0]<<" |"<<V(0, 0) << N;
119 ss << std::setprecision(4) <<
120 P[ 1]<<" |"<<V(0, 1)<<" "<<V(1, 1) << N;
121 ss << std::setprecision(4) <<
122 P[ 2]<<" |"<<V(0, 2)<<" "<<V(1, 2)<<" "<<V(2, 2) << N;
123 ss << std::setprecision(4) <<
124 P[ 3]<<" |"<<V(0, 3)<<" "<<V(1, 3)<<" "<<V(2, 3)<<" "<<V(3, 3) << N;
125 ss << std::setprecision(4) <<
126 P[ 4]<<" |"<<V(0, 4)<<" "<<V(1, 4)<<" "<<V(2, 4)<<" "<<V(3, 4)<<" "<<V(4, 4) << N;
127 }
128 else {
129 ss << std::setprecision(4) << P[ 0] << " |" << N;
130 ss << std::setprecision(4) << P[ 1] << " |" << N;
131 ss << std::setprecision(4) << P[ 2] << " |" << N;
132 ss << std::setprecision(4) << P[ 3] << " |" << N;
133 ss << std::setprecision(4) << P[ 4] << " |" << N;
134 }
135 return ss.str();
136}
137
138
140// Print track parameters information
142
143std::ostream& Trk::PatternTrackParameters::dump( std::ostream& out ) const
144{
145 out<<to_string();
146 return out;
147}
148
150// Print track parameters information
152
153MsgStream& Trk::PatternTrackParameters::dump(MsgStream& out) const
154{
155 out<<to_string();
156 return out;
157}
158
160// Protected methods
162
164// Global position for track parameters on plane
166
168(const Trk::PlaneSurface* su) const
169{
170 const Amg::Transform3D& T = su->transform();
171 double Ax[3] = {T(0,0),T(1,0),T(2,0)};
172 double Ay[3] = {T(0,1),T(1,1),T(2,1)};
173
174 Amg::Vector3D gp (m_parameters[0]*Ax[0]+m_parameters[1]*Ay[0]+T(0,3),
175 m_parameters[0]*Ax[1]+m_parameters[1]*Ay[1]+T(1,3),
176 m_parameters[0]*Ax[2]+m_parameters[1]*Ay[2]+T(2,3));
177 return gp;
178}
179
181// Global position for track parameters on straight line
183
185(const Trk::StraightLineSurface* su) const
186{
187 const Amg::Transform3D& T = su->transform();
188 double A[3] = {T(0,2),T(1,2),T(2,2)};
189
190 double Sf;
191 double Cf; sincos(m_parameters[2],&Sf,&Cf);
192 double Se;
193 double Ce; sincos(m_parameters[3],&Se,&Ce);
194
195 double P3 = Cf*Se;
196 double P4 = Sf*Se;
197 double P5 = Ce;
198 double Bx = A[1]*P5-A[2]*P4;
199 double By = A[2]*P3-A[0]*P5;
200 double Bz = A[0]*P4-A[1]*P3;
201 double Bn = 1./std::sqrt(Bx*Bx+By*By+Bz*Bz); Bx*=Bn; By*=Bn; Bz*=Bn;
202
204 (m_parameters[1]*A[0]+Bx*m_parameters[0]+T(0,3),
205 m_parameters[1]*A[1]+By*m_parameters[0]+T(1,3),
206 m_parameters[1]*A[2]+Bz*m_parameters[0]+T(2,3));
207 return gp;
208}
209
211// Global position for track parameters on disck
213
215(const Trk::DiscSurface* su) const
216{
217 const Amg::Transform3D& T = su->transform();
218 double Ax[3] = {T(0,0),T(1,0),T(2,0)};
219 double Ay[3] = {T(0,1),T(1,1),T(2,1)};
220
221 double Sf;
222 double Cf; sincos(m_parameters[1],&Sf,&Cf);
223
224 double d0 = Cf*Ax[0]+Sf*Ay[0];
225 double d1 = Cf*Ax[1]+Sf*Ay[1];
226 double d2 = Cf*Ax[2]+Sf*Ay[2];
227
229 (m_parameters[0]*d0+T(0,3),
230 m_parameters[0]*d1+T(1,3),
231 m_parameters[0]*d2+T(2,3));
232 return gp;
233}
234
236// Global position for track parameters on cylinder
238
240(const Trk::CylinderSurface* su) const
241{
242 const Amg::Transform3D& T = su->transform();
243 double Ax[3] = {T(0,0),T(1,0),T(2,0)};
244 double Ay[3] = {T(0,1),T(1,1),T(2,1)};
245 double Az[3] = {T(0,2),T(1,2),T(2,2)};
246
247 double R = su->bounds().r();
248 double fr = m_parameters[0]/R;
249
250 double Sf;
251 double Cf; sincos(fr,&Sf,&Cf);
252
254 (R*(Cf*Ax[0]+Sf*Ay[0])+m_parameters[1]*Az[0]+T(0,3),
255 R*(Cf*Ax[1]+Sf*Ay[1])+m_parameters[1]*Az[1]+T(1,3),
256 R*(Cf*Ax[2]+Sf*Ay[2])+m_parameters[1]*Az[2]+T(2,3));
257 return gp;
258}
259
261// Global position for track parameters on perigee
263
265(const Trk::PerigeeSurface* su) const
266{
267 const Amg::Transform3D& T = su->transform();
268 double A[3] = {T(0,2),T(1,2),T(2,2)};
269
270 double Sf;
271 double Cf; sincos(m_parameters[2],&Sf,&Cf);
272 double Se;
273 double Ce; sincos(m_parameters[3],&Se,&Ce);
274
275 double P3 = Cf*Se;
276 double P4 = Sf*Se;
277 double P5 = Ce;
278 double Bx = A[1]*P5-A[2]*P4;
279 double By = A[2]*P3-A[0]*P5;
280 double Bz = A[0]*P4-A[1]*P3;
281 double Bn = 1./std::sqrt(Bx*Bx+By*By+Bz*Bz); Bx*=Bn; By*=Bn; Bz*=Bn;
282
284 (m_parameters[1]*A[0]+Bx*m_parameters[0]+T(0,3),
285 m_parameters[1]*A[1]+By*m_parameters[0]+T(1,3),
286 m_parameters[1]*A[2]+Bz*m_parameters[0]+T(2,3));
287 return gp;
288}
289
291// Global position for track parameters on cone
293
295(const Trk::ConeSurface* su) const
296{
297 const Amg::Transform3D& T = su->transform();
298 double Ax[3] = {T(0,0),T(1,0),T(2,0)};
299 double Ay[3] = {T(0,1),T(1,1),T(2,1)};
300 double Az[3] = {T(0,2),T(1,2),T(2,2)};
301
302 double r = m_parameters[1]*su->bounds().tanAlpha();
303 double Sf;
304 double Cf; sincos((m_parameters[0]/r),&Sf,&Cf);
305 double xl = r*Cf;
306 double yl = r*Sf;
307
308
310 (Ax[0]*xl+Ay[0]*yl+Az[0]*m_parameters[1]+T(0,3),
311 Ax[1]*xl+Ay[1]*yl+Az[1]*m_parameters[1]+T(1,3),
312 Ax[2]*xl+Ay[2]*yl+Az[2]*m_parameters[1]+T(2,3));
313 return gp;
314}
315
317// Initiate track parameters
319
322{
323
324 int n = E.rows(); if(n<=0 || n>2) { return false;
325}
326
327 if (Tp.m_covariance != std::nullopt) {
328 if (m_covariance == std::nullopt) {
329 m_covariance = AmgSymMatrix(5)(*Tp.m_covariance);
330 } else {
331 *m_covariance = *Tp.m_covariance;
332 }
333 } else {
334 if (m_covariance == std::nullopt) {
335 m_covariance.emplace();
336 }
337 }
338
339 m_parameters[0] = P (0);
340
341 m_covariance->fillSymmetric(0, 0, E(0,0));
342
343 if(n==2) {
344 m_parameters[ 1] = P(1);
345 m_covariance->fillSymmetric(0, 1, E(1,0));
346 m_covariance->fillSymmetric(1, 1, E(1,1));
347 }
348 else {
349 m_parameters[ 1] = Tp.m_parameters[ 1];
350 }
351 m_parameters[ 2] = Tp.m_parameters[ 2];
352 m_parameters[ 3] = Tp.m_parameters[ 3];
353 m_parameters[ 4] = Tp.m_parameters[ 4];
354
355 if (Tp.m_surface != nullptr) {
356 m_surface.reset(Tp.m_surface->isFree() ? Tp.m_surface->clone() : Tp.m_surface.get());
357 } else {
358 m_surface.reset(nullptr);
359 }
360
361 return true;
362}
363
365// Change direction of the parameters
367
369{
370 constexpr double pi = M_PI;
371 constexpr double pi2 = 2.*M_PI; //NB CLHEP also defines pi and pi2 constants.
372
373 m_parameters[ 2] = m_parameters[2]-pi;
374 m_parameters[ 3] = pi-m_parameters[3];
375 m_parameters[ 4] = -m_parameters[4] ;
376
377 if (m_parameters[2] < -pi) {
378 m_parameters[2] += pi2;
379 }
380
381 if ((m_surface->type() != Trk::SurfaceType::Line) &&
383
384 if (m_covariance == std::nullopt) {
385 return;
386 }
387
388 m_covariance->fillSymmetric(0, 3, -(*m_covariance)(0, 3));
389 m_covariance->fillSymmetric(1, 3, -(*m_covariance)(1, 3));
390 m_covariance->fillSymmetric(2, 3, -(*m_covariance)(2, 3));
391 m_covariance->fillSymmetric(0, 4, -(*m_covariance)(0, 4));
392 m_covariance->fillSymmetric(1, 4, -(*m_covariance)(1, 4));
393 m_covariance->fillSymmetric(2, 4, -(*m_covariance)(2, 4));
394
395 return;
396 }
397
398 m_parameters[ 0] = -m_parameters[ 0];
399
400
401 if(m_covariance == std::nullopt) {
402 return;
403 }
404
405 m_covariance->fillSymmetric(0, 1, -(*m_covariance)(0, 1));
406 m_covariance->fillSymmetric(0, 2, -(*m_covariance)(0, 2));
407 m_covariance->fillSymmetric(1, 3, -(*m_covariance)(1, 3));
408 m_covariance->fillSymmetric(2, 3, -(*m_covariance)(2, 3));
409 m_covariance->fillSymmetric(1, 4, -(*m_covariance)(1, 4));
410 m_covariance->fillSymmetric(2, 4, -(*m_covariance)(2, 4));
411}
412
414 if (!m_surface) {
415 return {0, 0, 0};
416 }
417 switch ( m_surface->type()){
419 return localToGlobal(static_cast<const Trk::PlaneSurface*>(m_surface.get()));
420 break;
422 return localToGlobal(static_cast<const Trk::StraightLineSurface*>(m_surface.get()));
423 break;
425 return localToGlobal(static_cast<const Trk::DiscSurface*>(m_surface.get()));
426 break;
428 return localToGlobal(static_cast<const Trk::CylinderSurface*>(m_surface.get()));
429 break;
431 return localToGlobal(static_cast<const Trk::PerigeeSurface*>(m_surface.get()));
432 break;
434 return localToGlobal(static_cast<const Trk::ConeSurface*>(m_surface.get()));
435 break;
436 default:
437 return {0, 0, 0};
438 }
439}
440
442 double p = absoluteMomentum();
443 double Sf = std::sin(m_parameters[2]), Cf = std::cos(m_parameters[2]);
444 double Se = std::sin(m_parameters[3]), Ce = std::cos(m_parameters[3]);
445 return {p * Se * Cf, p * Se * Sf, p * Ce};
446}
447
#define M_PI
#define AmgSymMatrix(dim)
#define AmgVector(rows)
static std::string to_string(const std::vector< T > &v)
static Double_t ss
static Double_t Tp(Double_t *t, Double_t *par)
static Double_t P(Double_t *tt, Double_t *par)
#define pi
double tanAlpha() const
This method returns the average phi.
Class for a conical surface in the ATLAS detector.
Definition ConeSurface.h:51
virtual const ConeBounds & bounds() const override final
This method returns the ConeBounds by reference (NoBounds is not possible for cone)
virtual double r() const override final
This method returns the radius.
Class for a CylinderSurface in the ATLAS detector.
virtual const CylinderBounds & bounds() const override final
This method returns the CylinderBounds by reference (NoBounds is not possible for cylinder)
Class for a DiscSurface in the ATLAS detector.
Definition DiscSurface.h:54
The base class for neutral and charged Track parameters.
bool production(const TrackParameters *)
double absoluteMomentum() const
Amg::Vector3D calculateMomentum(void) const
std::ostream & dump(std::ostream &) const
SurfaceUniquePtrT< const Surface > m_surface
Amg::Vector3D localToGlobal(const PlaneSurface *) const
Amg::Vector3D calculatePosition(void) const
bool initiate(PatternTrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &)
std::unique_ptr< TrackParameters > convert(bool) const
Class describing the Line to which the Perigee refers to.
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
Abstract Base Class for tracking surfaces.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
int r
Definition globals.cxx:22
struct color C
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
@ d0
Definition ParamDefs.h:63
hold the test vectors and ease the comparison