Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericFreeTrackParameters.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GenericFreeTrackParameters.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-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 <optional>
21 #include <type_traits>
22 
23 namespace Acts {
24 
31 template <class particle_hypothesis_t>
33  public:
34  using Scalar = ActsScalar;
37  using ParticleHypothesis = particle_hypothesis_t;
38 
51  std::optional<CovarianceMatrix> cov,
53  : m_params(params),
54  m_cov(std::move(cov)),
55  m_particleHypothesis(std::move(particleHypothesis)) {}
56 
66  Scalar qOverP, std::optional<CovarianceMatrix> cov,
68  : m_params(FreeVector::Zero()),
69  m_cov(std::move(cov)),
70  m_particleHypothesis(std::move(particleHypothesis)) {
71  auto dir = makeDirectionFromPhiTheta(phi, theta);
72  m_params[eFreePos0] = pos4[ePos0];
73  m_params[eFreePos1] = pos4[ePos1];
74  m_params[eFreePos2] = pos4[ePos2];
75  m_params[eFreeTime] = pos4[eTime];
76  m_params[eFreeDir0] = dir[eMom0];
77  m_params[eFreeDir1] = dir[eMom1];
78  m_params[eFreeDir2] = dir[eMom2];
80  }
81 
83  template <typename other_particle_hypothesis_t>
87  other.particleHypothesis(),
88  other.covariance()) {}
89 
91  template <typename other_track_parameter_t>
93  const other_track_parameter_t& other) {
94  static_assert(
95  Concepts::FreeTrackParametersConcept<other_track_parameter_t>);
96 
98  other.parameters(), other.particleHypothesis(), other.covariance());
99  }
100 
102  GenericFreeTrackParameters() = delete;
105  ~GenericFreeTrackParameters() = default;
107  default;
109 
111  const ParametersVector& parameters() const { return m_params; }
113  const std::optional<CovarianceMatrix>& covariance() const { return m_cov; }
114 
118  template <FreeIndices kIndex>
119  Scalar get() const {
120  return m_params[kIndex];
121  }
122 
125  Vector4 pos4;
126  pos4[ePos0] = m_params[eFreePos0];
127  pos4[ePos1] = m_params[eFreePos1];
128  pos4[ePos2] = m_params[eFreePos2];
129  pos4[eTime] = m_params[eFreeTime];
130  return pos4;
131  }
133  Vector3 position() const { return m_params.segment<3>(eFreePos0); }
135  Scalar time() const { return m_params[eFreeTime]; }
136 
138  Scalar phi() const { return phi(direction()); }
140  Scalar theta() const { return theta(direction()); }
142  Scalar qOverP() const { return m_params[eFreeQOverP]; }
143 
145  Vector3 direction() const {
146  return m_params.segment<3>(eFreeDir0).normalized();
147  }
150  return m_particleHypothesis.extractMomentum(m_params[eFreeQOverP]);
151  }
154  // direction vector w/ arbitrary normalization can be parametrized as
155  // [f*sin(theta)*cos(phi), f*sin(theta)*sin(phi), f*cos(theta)]
156  // w/ f,sin(theta) positive, the transverse magnitude is then
157  // sqrt(f^2*sin^2(theta)) = f*sin(theta)
158  Scalar transverseMagnitude =
159  std::hypot(m_params[eFreeDir0], m_params[eFreeDir1]);
160  // absolute magnitude is f by construction
161  Scalar magnitude = std::hypot(transverseMagnitude, m_params[eFreeDir2]);
162  // such that we can extract sin(theta) = f*sin(theta) / f
163  return (transverseMagnitude / magnitude) * absoluteMomentum();
164  }
166  Vector3 momentum() const { return absoluteMomentum() * direction(); }
167 
169  Scalar charge() const {
170  return m_particleHypothesis.extractCharge(get<eFreeQOverP>());
171  }
172 
175  return m_particleHypothesis;
176  }
177 
178  private:
180  std::optional<FreeSquareMatrix> m_cov;
181  // TODO use [[no_unique_address]] once we switch to C++20
183 
185  friend std::ostream& operator<<(std::ostream& os,
188  os, tp.parameters(),
189  tp.covariance().has_value() ? &tp.covariance().value() : nullptr);
190  return os;
191  }
192 };
193 
194 } // namespace Acts