EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SingleBoundTrackParameters.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SingleBoundTrackParameters.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2020 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 
16 
17 #include <cassert>
18 #include <cmath>
19 #include <memory>
20 #include <type_traits>
21 
22 namespace Acts {
23 
35 template <class charge_t>
37  public:
41 
54  SingleBoundTrackParameters(std::shared_ptr<const Surface> surface,
55  const ParametersVector& params, Scalar q,
56  std::optional<CovarianceMatrix> cov = std::nullopt)
57  : m_paramSet(std::move(cov), params),
58  m_surface(std::move(surface)),
59  m_chargeInterpreter(std::abs(q)) {
60  assert((0 <= (params[eBoundQOverP] * q)) and
61  "Inconsistent q/p and q signs");
62  assert(m_surface);
63  }
64 
73  template <typename T = charge_t,
74  std::enable_if_t<std::is_default_constructible_v<T>, int> = 0>
75  SingleBoundTrackParameters(std::shared_ptr<const Surface> surface,
76  const ParametersVector& params,
77  std::optional<CovarianceMatrix> cov = std::nullopt)
78  : m_paramSet(std::move(cov), params),
79  m_surface(std::move(surface)),
81  assert(m_surface);
82  }
83 
93  SingleBoundTrackParameters(std::shared_ptr<const Surface> surface,
94  const GeometryContext& geoCtx,
95  const Vector4D& pos4, const Vector3D& dir,
96  Scalar p, Scalar q,
97  std::optional<CovarianceMatrix> cov = std::nullopt)
98  : m_paramSet(std::move(cov),
100  pos4.segment<3>(ePos0), pos4[eTime], dir,
101  (q != Scalar(0)) ? (q / p) : (1 / p), *surface, geoCtx)),
102  m_surface(std::move(surface)),
103  m_chargeInterpreter(std::abs(q)) {
104  assert((0 <= p) and "Absolute momentum must be positive");
105  assert(m_surface);
106  }
107 
120  template <typename T = charge_t,
121  std::enable_if_t<std::is_default_constructible_v<T>, int> = 0>
122  SingleBoundTrackParameters(std::shared_ptr<const Surface> surface,
123  const GeometryContext& geoCtx,
124  const Vector4D& pos4, const Vector3D& dir,
125  Scalar qOverP,
126  std::optional<CovarianceMatrix> cov = std::nullopt)
127  : m_paramSet(std::move(cov), detail::transformFreeToBoundParameters(
128  pos4.segment<3>(ePos0), pos4[eTime], dir,
129  qOverP, *surface, geoCtx)),
130  m_surface(std::move(surface)),
132  assert(m_surface);
133  }
134 
135  // this class does not have a custom default constructor and thus should not
136  // provide any custom default cstors, dstor, or assignment. see ISOCPP C.20.
137 
141  ParametersVector parameters() const { return m_paramSet.getParameters(); }
143  const std::optional<CovarianceMatrix>& covariance() const {
144  return m_paramSet.getCovariance();
145  }
146 
150  template <BoundIndices kIndex>
151  Scalar get() const {
152  return m_paramSet.template getParameter<kIndex>();
153  }
159  template <BoundIndices kIndex>
160  Scalar uncertainty() const {
161  return m_paramSet.template getUncertainty<kIndex>();
162  }
163 
173  const Vector2D loc(get<eBoundLoc0>(), get<eBoundLoc1>());
174  const Vector3D dir =
175  makeDirectionUnitFromPhiTheta(get<eBoundPhi>(), get<eBoundTheta>());
176  Vector4D pos4;
177  pos4.segment<3>(ePos0) = m_surface->localToGlobal(geoCtx, loc, dir);
178  pos4[eTime] = get<eBoundTime>();
179  return pos4;
180  }
190  const Vector2D loc(get<eBoundLoc0>(), get<eBoundLoc1>());
191  const Vector3D dir =
192  makeDirectionUnitFromPhiTheta(get<eBoundPhi>(), get<eBoundTheta>());
193  return m_surface->localToGlobal(geoCtx, loc, dir);
194  }
196  Scalar time() const { return get<eBoundTime>(); }
197 
200  return makeDirectionUnitFromPhiTheta(get<eBoundPhi>(), get<eBoundTheta>());
201  }
204  return m_chargeInterpreter.extractMomentum(get<eBoundQOverP>());
205  }
208  return std::sin(get<eBoundTheta>()) * absoluteMomentum();
209  }
212 
214  constexpr Scalar charge() const {
215  return m_chargeInterpreter.extractCharge(get<eBoundQOverP>());
216  }
217 
219  const Surface& referenceSurface() const { return *m_surface; }
228  return m_surface->referenceFrame(geoCtx, position(geoCtx), momentum());
229  }
230 
231  private:
235  std::shared_ptr<const Surface> m_surface;
236  // TODO use [[no_unique_address]] once we switch to C++20
238 
240  friend bool operator==(const SingleBoundTrackParameters& lhs,
241  const SingleBoundTrackParameters& rhs) {
242  return (lhs.m_paramSet == rhs.m_paramSet) and
243  (lhs.m_surface == rhs.m_surface) and
245  }
247  friend bool operator!=(const SingleBoundTrackParameters& lhs,
248  const SingleBoundTrackParameters& rhs) {
249  return !(lhs == rhs);
250  }
252  friend std::ostream& operator<<(std::ostream& os,
253  const SingleBoundTrackParameters& tp) {
255  os, tp.referenceSurface(), tp.parameters(),
256  tp.covariance().has_value() ? &tp.covariance().value() : nullptr);
257  return os;
258  }
259 };
260 
261 } // namespace Acts