Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ParametersBase.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 ///////////////////////////////////////////////////////////////////
6 // ParametersBase.icc, (c) ATLAS Detector software
7 ///////////////////////////////////////////////////////////////////
8 
9 // Gaudi
10 #include "GaudiKernel/MsgStream.h"
11 // Trk
12 #include "TrkEventPrimitives/ParamDefs.h"
13 // STD
14 #include <iomanip>
15 #include <ostream>
16 #include <sstream>
17 #include <utility>
18 
19 namespace Trk {
20 
21 namespace {
22 template <typename T>
23 int sgn(const T& val) {
24  return (val > 0) - (val < 0);
25 }
26 } // namespace
27 
28 // Helper protected ctor*/
29 template <int DIM, class T>
30 ParametersBase<DIM, T>::ParametersBase(
31  const AmgVector(DIM) parameters,
32  std::optional<AmgSymMatrix(DIM)>&& covariance, const T chargeDef)
33  : ParametersCommon<DIM, T>(parameters, std::move(covariance), chargeDef)
34 {
35  // cppcheck-suppress missingReturn; false positive
36 }
37 
38 // Helper protected ctor
39 template <int DIM, class T>
40 ParametersBase<DIM, T>::ParametersBase(
41  std::optional<AmgSymMatrix(DIM)>&& covariance)
42  : ParametersCommon<DIM, T>(std::move(covariance))
43 {
44  // cppcheck-suppress missingReturn; false positive
45 }
46 
47 // Protected Constructor with local arguments - persistency only
48 template <int DIM, class T>
49 ParametersBase<DIM, T>::ParametersBase(
50  const AmgVector(DIM) & parameters,
51  std::optional<AmgSymMatrix(DIM)>&& covariance)
52  : ParametersCommon<DIM, T>(parameters, std::move(covariance))
53 {
54  // cppcheck-suppress missingReturn; false positive
55 }
56 
57 
58 template<int DIM, class T>
59 double
60 ParametersBase<DIM, T>::charge() const
61 {
62  return m_chargeDef.charge();
63 }
64 
65 template<int DIM, class T>
66 const Amg::Vector3D&
67 ParametersBase<DIM, T>::position() const
68 {
69  return m_position;
70 }
71 
72 template<int DIM, class T>
73 const Amg::Vector3D&
74 ParametersBase<DIM, T>::momentum() const
75 {
76  return m_momentum;
77 }
78 
79 template <int DIM, class T>
80 double ParametersBase<DIM, T>::pT() const {
81  return momentum().perp();
82 }
83 
84 template <int DIM, class T>
85 double ParametersBase<DIM, T>::eta() const {
86  return momentum().eta();
87 }
88 
89 /** equality operator */
90 template <int DIM, class T>
91 bool ParametersBase<DIM, T>::operator==(
92  const ParametersBase<DIM, T>& rhs) const {
93  // tolerance for comparisons
94  constexpr double tolerance = 1e-8;
95 
96  // compare parameters
97  if (!this->parameters().isApprox(rhs.parameters(), tolerance)) {
98  return false;
99  }
100 
101  // compare covariance
102  if (((this->covariance() != nullptr) && (rhs.covariance() != nullptr) &&
103  !this->covariance()->isApprox(*rhs.covariance(), tolerance)) ||
104  (!this->covariance() !=
105  !rhs.covariance())) { // <-- this is: covariance()
106  // XOR pCast->covariance()
107  return false;
108  }
109 
110  // compare position
111  if (!this->position().isApprox(rhs.position(), tolerance)) {
112  return false;
113  }
114 
115  // compare momentum
116  if (!this->momentum().isApprox(rhs.momentum(), tolerance)) {
117  return false;
118  }
119 
120  // compare charge definition
121  if (m_chargeDef != rhs.m_chargeDef) {
122  return false;
123  }
124 
125  return true;
126 }
127 
128 template <int DIM, class T>
129 MsgStream& ParametersBase<DIM, T>::dump(MsgStream& sl) const {
130  std::ostringstream output{};
131  dump(output);
132  sl << output.str();
133  return sl;
134 }
135 
136 template <int DIM, class T>
137 std::ostream& ParametersBase<DIM, T>::dump(std::ostream& sl) const {
138  const std::string nl{"\n"};
139  sl << std::setiosflags(std::ios::fixed);
140  sl << std::setprecision(7);
141  sl << " * TrackParameters on Surface" << nl;
142  sl << " * loc1 : " << this->parameters()[Trk::loc1] << nl;
143  sl << " * loc2 : " << this->parameters()[Trk::loc2] << nl;
144  sl << " * phi : " << this->parameters()[Trk::phi] << nl;
145  sl << " * Theta : " << this->parameters()[Trk::theta] << nl;
146  sl << " * q/p : " << this->parameters()[Trk::qOverP] << nl;
147  if (this->parameters().rows() > 5) {
148  sl << " * mass : " << this->parameters()[Trk::trkMass]
149  << " (extended parameters)" << nl;
150  }
151  sl << " * charge: " << this->charge() << nl;
152  sl << " * covariance matrix = " << this->covariance() << nl;
153  sl << " * corresponding global parameters:" << nl;
154  sl << " * position (x, y, z ) = (" << this->position().x() << ", "
155  << this->position().y() << ", " << this->position().z() << ")" << nl;
156  sl << " * momentum (px, py, pz) = (" << this->momentum().x() << ", "
157  << this->momentum().y() << ", " << this->momentum().z() << ")" << nl;
158  sl << std::setprecision(-1);
159  if (this->hasSurface()) {
160  sl << "associated surface:" << nl;
161  this->associatedSurface().dump(sl) << std::endl;
162  } else {
163  sl << "no associated surface" << std::endl;
164  }
165 
166  return sl;
167 }
168 
169 template <int DIM, class T>
170 MsgStream& operator<<(MsgStream& sl, const Trk::ParametersBase<DIM, T>& p) {
171  return p.dump(sl);
172 }
173 
174 template <int DIM, class T>
175 std::ostream& operator<<(std::ostream& sl,
176  const Trk::ParametersBase<DIM, T>& p) {
177  return p.dump(sl);
178 }
179 } // end of namespace Trk