ATLAS Offline Software
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 
25 std::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 
80 {
81  return calculatePosition();
82 }
83 
85 // Overload of << operator std::ostream
87 
88 std::ostream& Trk::operator <<
89  (std::ostream& sl,const Trk::PatternTrackParameters& se)
90 {
91  return se.dump(sl);
92 }
93 
94 MsgStream& 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 
104 std::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 
143 std::ostream& Trk::PatternTrackParameters::dump( std::ostream& out ) const
144 {
145  out<<to_string();
146  return out;
147 }
148 
150 // Print track parameters information
152 
153 MsgStream& 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 
203  Amg::Vector3D gp
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 
228  Amg::Vector3D gp
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 
253  Amg::Vector3D gp
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 
283  Amg::Vector3D gp
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 
309  Amg::Vector3D gp
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) &&
382  (m_surface->type() != Trk::SurfaceType::Perigee)) {
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 
Trk::ParametersCommon::AmgVector
const AmgVector(DIM) &parameters() const
Access methods for the parameters.
Trk::PatternTrackParameters::localToGlobal
Amg::Vector3D localToGlobal(const PlaneSurface *) const
Definition: PatternTrackParameters.cxx:168
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:676
Trk::ParametersCommon::m_covariance
std::optional< AmgSymMatrix(DIM)> m_covariance
charge definition for this track
Definition: ParametersCommon.h:147
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
StraightLineSurface.h
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
PerigeeSurface.h
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
DMTest::P
P_v1 P
Definition: P.h:23
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
python.PhysicalConstants.pi2
float pi2
Definition: PhysicalConstants.py:52
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::ParametersCommon::AmgSymMatrix
const AmgSymMatrix(DIM) *covariance() const
Access method for the covariance matrix - returns nullptr if no covariance matrix is given.
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
Trk::CylinderSurface::bounds
virtual const CylinderBounds & bounds() const override final
This method returns the CylinderBounds by reference (NoBounds is not possible for cylinder)
Trk::PatternTrackParameters::convert
std::unique_ptr< TrackParameters > convert(bool) const
Definition: PatternTrackParameters.cxx:26
Trk::DiscSurface
Definition: DiscSurface.h:54
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
keylayer_zslicemap.se
se
Definition: keylayer_zslicemap.py:194
Trk::PatternTrackParameters::m_surface
SurfaceUniquePtrT< const Surface > m_surface
Definition: PatternTrackParameters.h:88
Trk::ConeSurface::bounds
virtual const ConeBounds & bounds() const override final
This method returns the ConeBounds by reference (NoBounds is not possible for cone)
pi
#define pi
Definition: TileMuonFitter.cxx:65
Trk::PatternTrackParameters::calculateMomentum
Amg::Vector3D calculateMomentum(void) const
Definition: PatternTrackParameters.cxx:441
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
A
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ConeSurface.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
Trk::PatternTrackParameters::dump
std::ostream & dump(std::ostream &) const
Definition: PatternTrackParameters.cxx:143
Trk::PatternTrackParameters::changeDirection
void changeDirection()
Definition: PatternTrackParameters.cxx:368
Trk::CylinderSurface
Definition: CylinderSurface.h:55
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
CylinderSurface.h
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::SurfaceType::Cone
@ Cone
Trk::PatternTrackParameters::calculatePosition
Amg::Vector3D calculatePosition(void) const
Definition: PatternTrackParameters.cxx:413
Trk::ConeBounds::tanAlpha
double tanAlpha() const
This method returns the average phi.
Trk::SurfaceType::Perigee
@ Perigee
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Trk::d0
@ d0
Definition: ParamDefs.h:63
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Trk::PatternTrackParameters::initiate
bool initiate(PatternTrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &)
Definition: PatternTrackParameters.cxx:321
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Trk::PatternTrackParameters
Definition: PatternTrackParameters.h:32
PlaneSurface.h
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
Trk::SurfaceType::Disc
@ Disc
Trk::SurfaceType::Cylinder
@ Cylinder
DiscSurface.h
Trk::ConeSurface
Definition: ConeSurface.h:51
PatternTrackParameters.h
Trk::PatternTrackParameters::production
bool production(const TrackParameters *)
Definition: PatternTrackParameters.cxx:42
Trk::SurfaceType::Plane
@ Plane
Trk::PatternTrackParameters::to_string
std::string to_string() const
Definition: PatternTrackParameters.cxx:105
Trk::PatternTrackParameters::position
Amg::Vector3D position() const
Definition: PatternTrackParameters.cxx:79
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Trk::SurfaceType::Line
@ Line
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
grepfile.fr
fr
Definition: grepfile.py:32
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
Trk::CylinderBounds::r
virtual double r() const override final
This method returns the radius.