ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SingleTrackParameters.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SingleTrackParameters.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 #include <type_traits>
16 
17 namespace Acts {
18 
34 template <class ChargePolicy>
38  "ChargePolicy must either be 'Acts::ChargedPolicy' or "
39  "'Acts::NeutralPolicy");
40 
41  public:
42  // public typedef's
43 
46 
49 
51  virtual ~SingleTrackParameters() = default;
52 
56  Vector3D position() const { return m_vPosition; }
57 
61  Vector3D momentum() const { return m_vMomentum; }
62 
67  bool operator==(const SingleTrackParameters& rhs) const {
68  auto casted = dynamic_cast<decltype(this)>(&rhs);
69  if (!casted) {
70  return false;
71  }
72 
73  return (m_oChargePolicy == casted->m_oChargePolicy &&
74  m_oParameters == casted->m_oParameters &&
75  m_vPosition == casted->m_vPosition &&
76  m_vMomentum == casted->m_vMomentum);
77  }
78 
82  double charge() const { return m_oChargePolicy.getCharge(); }
83 
87  double time() const { return get<ParDef::eT>(); }
88 
93  const FullParameterSet& getParameterSet() const { return m_oParameters; }
94 
99  virtual const Surface& referenceSurface() const = 0;
100 
109  const std::optional<CovMatrix_t>& covariance() const {
110  return getParameterSet().getCovariance();
111  }
112 
118  ParVector_t parameters() const { return getParameterSet().getParameters(); }
119 
127  template <ParID_t par>
128  ParValue_t get() const {
129  return getParameterSet().template getParameter<par>();
130  }
131 
137  template <ParID_t par>
139  return getParameterSet().template getUncertainty<par>();
140  }
141 
143  double pT() const { return VectorHelpers::perp(momentum()); }
144 
146  double eta() const { return VectorHelpers::eta(momentum()); }
147 
148  FullParameterSet& getParameterSet() { return m_oParameters; }
149 
157  friend std::ostream& operator<<(std::ostream& out,
158  const SingleTrackParameters& stp) {
159  stp.print(out);
160  return out;
161  }
162 
163  protected:
170  template <typename T = ChargePolicy,
172  SingleTrackParameters(std::optional<CovMatrix_t> cov,
173  const ParVector_t& parValues, const Vector3D& position,
174  const Vector3D& momentum)
175  : m_oChargePolicy(
176  detail::coordinate_transformation::parameters2charge(parValues)),
177  m_oParameters(std::move(cov), parValues),
178  m_vPosition(position),
179  m_vMomentum(momentum) {}
180 
187  template <typename T = ChargePolicy,
189  SingleTrackParameters(std::optional<CovMatrix_t> cov,
190  const ParVector_t& parValues, const Vector3D& position,
191  const Vector3D& momentum)
192  : m_oChargePolicy(),
193  m_oParameters(std::move(cov), parValues),
194  m_vPosition(position),
195  m_vMomentum(momentum) {}
196 
199  default;
200 
203 
209  // check for self-assignment
210  if (this != &rhs) {
213  m_vPosition = rhs.m_vPosition;
214  m_vMomentum = rhs.m_vMomentum;
215  }
216 
217  return *this;
218  }
219 
225  // check for self-assignment
226  if (this != &rhs) {
227  m_oChargePolicy = std::move(rhs.m_oChargePolicy);
228  m_oParameters = std::move(rhs.m_oParameters);
229  m_vPosition = std::move(rhs.m_vPosition);
230  m_vMomentum = std::move(rhs.m_vMomentum);
231  }
232 
233  return *this;
234  }
235 
244  template <typename T>
246  const T& /*unused*/) {
247  m_vMomentum = detail::coordinate_transformation::parameters2globalMomentum(
248  getParameterSet().getParameters());
249  }
250 
256  const local_parameter& /*unused*/) {
257  m_vPosition = detail::coordinate_transformation::parameters2globalPosition(
258  gctx, getParameterSet().getParameters(), this->referenceSurface());
259  }
260 
264  std::ostream& print(std::ostream& sl) const {
265  // set stream output format
266  auto old_precision = sl.precision(7);
267  auto old_flags = sl.setf(std::ios::fixed);
268 
269  sl << " * TrackParameters: ";
270  sl << parameters().transpose() << std::endl;
271  sl << " * charge: " << charge() << std::endl;
272  if (covariance()) {
273  sl << " * covariance matrix:\n" << *covariance() << std::endl;
274  } else {
275  sl << " * covariance matrix:\nnull" << std::endl;
276  }
277  sl << " * corresponding global parameters:" << std::endl;
278  sl << " * position (x y z) = (" << position().transpose() << ")"
279  << std::endl;
280  sl << " * momentum (px py pz) = (" << momentum().transpose() << ")"
281  << std::endl;
282 
283  // reset stream format
284  sl.precision(old_precision);
285  sl.setf(old_flags);
286 
287  return sl;
288  }
289 
290  ChargePolicy m_oChargePolicy;
291 
292  FullParameterSet m_oParameters;
293 
296 };
297 } // namespace Acts