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 // cppcheck-suppress missingReturn; false positive
34 : ParametersCommon<DIM, T>(parameters, std::move(covariance), chargeDef) {}
36 // Helper protected ctor
37 template <int DIM, class T>
38 ParametersBase<DIM, T>::ParametersBase(
39 std::optional<AmgSymMatrix(DIM)>&& covariance)
40 // cppcheck-suppress missingReturn; false positive
41 : ParametersCommon<DIM, T>(std::move(covariance)) {}
43 // Protected Constructor with local arguments - persistency only
44 template <int DIM, class T>
45 ParametersBase<DIM, T>::ParametersBase(
46 const AmgVector(DIM) & parameters,
47 std::optional<AmgSymMatrix(DIM)>&& covariance)
48 : ParametersCommon<DIM, T>(parameters, std::move(covariance)) {}
51 template<int DIM, class T>
53 ParametersBase<DIM, T>::charge() const
55 return m_chargeDef.charge();
58 template<int DIM, class T>
60 ParametersBase<DIM, T>::position() const
65 template<int DIM, class T>
67 ParametersBase<DIM, T>::momentum() const
72 template <int DIM, class T>
73 double ParametersBase<DIM, T>::pT() const {
74 return momentum().perp();
77 template <int DIM, class T>
78 double ParametersBase<DIM, T>::eta() const {
79 return momentum().eta();
82 /** equality operator */
83 template <int DIM, class T>
84 bool ParametersBase<DIM, T>::operator==(
85 const ParametersBase<DIM, T>& rhs) const {
86 // tolerance for comparisons
87 constexpr double tolerance = 1e-8;
90 if (!this->parameters().isApprox(rhs.parameters(), tolerance)) {
95 if (((this->covariance() != nullptr) && (rhs.covariance() != nullptr) &&
96 !this->covariance()->isApprox(*rhs.covariance(), tolerance)) ||
97 (!this->covariance() !=
98 !rhs.covariance())) { // <-- this is: covariance()
99 // XOR pCast->covariance()
104 if (!this->position().isApprox(rhs.position(), tolerance)) {
109 if (!this->momentum().isApprox(rhs.momentum(), tolerance)) {
113 // compare charge definition
114 if (m_chargeDef != rhs.m_chargeDef) {
121 template <int DIM, class T>
122 MsgStream& ParametersBase<DIM, T>::dump(MsgStream& sl) const {
123 std::ostringstream output{};
129 template <int DIM, class T>
130 std::ostream& ParametersBase<DIM, T>::dump(std::ostream& sl) const {
131 const std::string nl{"\n"};
132 sl << std::setiosflags(std::ios::fixed);
133 sl << std::setprecision(7);
134 sl << " * TrackParameters on Surface" << nl;
135 sl << " * loc1 : " << this->parameters()[Trk::loc1] << nl;
136 sl << " * loc2 : " << this->parameters()[Trk::loc2] << nl;
137 sl << " * phi : " << this->parameters()[Trk::phi] << nl;
138 sl << " * Theta : " << this->parameters()[Trk::theta] << nl;
139 sl << " * q/p : " << this->parameters()[Trk::qOverP] << nl;
140 if (this->parameters().rows() > 5) {
141 sl << " * mass : " << this->parameters()[Trk::trkMass]
142 << " (extended parameters)" << nl;
144 sl << " * charge: " << this->charge() << nl;
145 sl << " * covariance matrix = " << this->covariance() << nl;
146 sl << " * corresponding global parameters:" << nl;
147 sl << " * position (x, y, z ) = (" << this->position().x() << ", "
148 << this->position().y() << ", " << this->position().z() << ")" << nl;
149 sl << " * momentum (px, py, pz) = (" << this->momentum().x() << ", "
150 << this->momentum().y() << ", " << this->momentum().z() << ")" << nl;
151 sl << std::setprecision(-1);
152 if (this->hasSurface()) {
153 sl << "associated surface:" << nl;
154 this->associatedSurface().dump(sl) << std::endl;
156 sl << "no associated surface" << std::endl;
162 template <int DIM, class T>
163 MsgStream& operator<<(MsgStream& sl, const Trk::ParametersBase<DIM, T>& p) {
167 template <int DIM, class T>
168 std::ostream& operator<<(std::ostream& sl,
169 const Trk::ParametersBase<DIM, T>& p) {
172 } // end of namespace Trk