2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 ///////////////////////////////////////////////////////////////////
6 // ParametersBase.icc, (c) ATLAS Detector software
7 ///////////////////////////////////////////////////////////////////
10 #include "GaudiKernel/MsgStream.h"
12 #include "TrkEventPrimitives/ParamDefs.h"
23 int sgn(const T& val) {
24 return (val > 0) - (val < 0);
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)
35 // cppcheck-suppress missingReturn; false positive
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))
44 // cppcheck-suppress missingReturn; false positive
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))
54 // cppcheck-suppress missingReturn; false positive
58 template<int DIM, class T>
60 ParametersBase<DIM, T>::charge() const
62 return m_chargeDef.charge();
65 template<int DIM, class T>
67 ParametersBase<DIM, T>::position() const
72 template<int DIM, class T>
74 ParametersBase<DIM, T>::momentum() const
79 template <int DIM, class T>
80 double ParametersBase<DIM, T>::pT() const {
81 return momentum().perp();
84 template <int DIM, class T>
85 double ParametersBase<DIM, T>::eta() const {
86 return momentum().eta();
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;
97 if (!this->parameters().isApprox(rhs.parameters(), tolerance)) {
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()
111 if (!this->position().isApprox(rhs.position(), tolerance)) {
116 if (!this->momentum().isApprox(rhs.momentum(), tolerance)) {
120 // compare charge definition
121 if (m_chargeDef != rhs.m_chargeDef) {
128 template <int DIM, class T>
129 MsgStream& ParametersBase<DIM, T>::dump(MsgStream& sl) const {
130 std::ostringstream output{};
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;
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;
163 sl << "no associated surface" << std::endl;
169 template <int DIM, class T>
170 MsgStream& operator<<(MsgStream& sl, const Trk::ParametersBase<DIM, T>& p) {
174 template <int DIM, class T>
175 std::ostream& operator<<(std::ostream& sl,
176 const Trk::ParametersBase<DIM, T>& p) {
179 } // end of namespace Trk