Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericBoundTrackParameters.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GenericBoundTrackParameters.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 
17 
18 #include <cassert>
19 #include <cmath>
20 #include <memory>
21 #include <type_traits>
22 
23 namespace Acts {
24 
36 template <class particle_hypothesis_t>
38  public:
39  using Scalar = ActsScalar;
42  using ParticleHypothesis = particle_hypothesis_t;
43 
56  GenericBoundTrackParameters(std::shared_ptr<const Surface> surface,
57  const ParametersVector& params,
58  std::optional<CovarianceMatrix> cov,
60  : m_params(params),
61  m_cov(std::move(cov)),
62  m_surface(std::move(surface)),
63  m_particleHypothesis(std::move(particleHypothesis)) {
66  }
67 
69  template <typename other_particle_hypothesis_t>
72  : GenericBoundTrackParameters(other.referenceSurface().getSharedPtr(),
73  other.parameters(), other.covariance(),
74  other.particleHypothesis()) {}
75 
91  std::shared_ptr<const Surface> surface, const GeometryContext& geoCtx,
92  const Vector4& pos4, const Vector3& dir, Scalar qOverP,
93  std::optional<CovarianceMatrix> cov,
97  pos4.segment<3>(ePos0), pos4[eTime], dir, qOverP, *surface, geoCtx,
98  tolerance);
99 
100  if (!bound.ok()) {
101  return bound.error();
102  }
103 
104  return GenericBoundTrackParameters{std::move(surface), std::move(*bound),
105  std::move(cov),
106  std::move(particleHypothesis)};
107  }
108 
110  GenericBoundTrackParameters() = delete;
113  ~GenericBoundTrackParameters() = default;
115  default;
117  default;
118 
122  const ParametersVector& parameters() const { return m_params; }
124  ActsVector<2> spatialImpactParameters() const { return m_params.head<2>(); }
127  ActsVector<3> ip;
128  ip.template head<2>() = m_params.template head<2>();
129  ip(2) = m_params(eBoundTime);
130  return ip;
131  }
132 
134  std::optional<CovarianceMatrix>& covariance() { return m_cov; }
136  const std::optional<CovarianceMatrix>& covariance() const { return m_cov; }
138  std::optional<ActsSquareMatrix<2>> spatialImpactParameterCovariance() const {
139  if (not m_cov.has_value()) {
140  return std::nullopt;
141  }
142 
143  return m_cov.value().template topLeftCorner<2, 2>();
144  }
145 
148  std::optional<ActsSquareMatrix<3>> impactParameterCovariance() const {
149  if (not m_cov.has_value()) {
150  return std::nullopt;
151  }
152 
153  ActsSquareMatrix<3> ipCov;
154  ipCov.template topLeftCorner<2, 2>() =
155  m_cov.value().template topLeftCorner<2, 2>();
156  ipCov.template block<2, 1>(0, 2) =
157  m_cov.value().template block<2, 1>(0, eBoundTime);
158  ipCov.template block<1, 2>(2, 0) =
159  m_cov.value().template block<1, 2>(eBoundTime, 0);
160  ipCov(2, 2) = m_cov.value()(eBoundTime, eBoundTime);
161  return ipCov;
162  }
163 
167  template <BoundIndices kIndex>
168  Scalar get() const {
169  return m_params[kIndex];
170  }
171 
173  Vector2 localPosition() const { return m_params.segment<2>(eBoundLoc0); }
184  Vector4 pos4;
185  pos4.segment<3>(ePos0) =
186  m_surface->localToGlobal(geoCtx, localPosition(), direction());
187  pos4[eTime] = m_params[eBoundTime];
188  return pos4;
189  }
200  return m_surface->localToGlobal(geoCtx, localPosition(), direction());
201  }
203  Scalar time() const { return m_params[eBoundTime]; }
204 
206  Scalar phi() const { return m_params[eBoundPhi]; }
208  Scalar theta() const { return m_params[eBoundTheta]; }
210  Scalar qOverP() const { return m_params[eBoundQOverP]; }
211 
214  Vector3 direction() const {
217  }
220  return m_particleHypothesis.extractMomentum(m_params[eBoundQOverP]);
221  }
224  return std::sin(m_params[eBoundTheta]) * absoluteMomentum();
225  }
227  Vector3 momentum() const { return absoluteMomentum() * direction(); }
228 
230  Scalar charge() const {
231  return m_particleHypothesis.extractCharge(get<eBoundQOverP>());
232  }
233 
236  return m_particleHypothesis;
237  }
238 
240  const Surface& referenceSurface() const { return *m_surface; }
250  return m_surface->referenceFrame(geoCtx, position(geoCtx), momentum());
251  }
252 
253  private:
255  std::optional<BoundSquareMatrix> m_cov;
257  std::shared_ptr<const Surface> m_surface;
258  // TODO use [[no_unique_address]] once we switch to C++20
260 
263  auto [phi, theta] =
267  }
268 
281  return (lhs.m_params == rhs.m_params) and (lhs.m_cov == rhs.m_cov) and
282  (lhs.m_surface == rhs.m_surface) and
284  }
288  return not(lhs == rhs);
289  }
291  friend std::ostream& operator<<(std::ostream& os,
294  os, tp.referenceSurface(), tp.parameters(),
295  tp.covariance().has_value() ? &tp.covariance().value() : nullptr);
296  return os;
297  }
298 };
299 
300 } // namespace Acts