Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-17 07:59:35

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Common.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Utilities/HashedString.hpp"
0014 
0015 namespace Acts {
0016 
0017 namespace detail_tp {
0018 inline constexpr HashedString kTipIndexKey = hashString("tipIndex");
0019 inline constexpr HashedString kStemIndexKey = hashString("stemIndex");
0020 inline constexpr HashedString kMeasurementsKey = hashString("nMeasurements");
0021 inline constexpr HashedString kHolesKey = hashString("nHoles");
0022 inline constexpr HashedString kOutliersKey = hashString("nOutliers");
0023 inline constexpr HashedString kSharedHitsKey = hashString("nSharedHits");
0024 inline constexpr HashedString kChi2Key = hashString("chi2");
0025 inline constexpr HashedString kNdfKey = hashString("ndf");
0026 inline constexpr HashedString kNextKey = hashString("next");
0027 }  // namespace detail_tp
0028 
0029 /// Common CRTP implementation shared by the various track proxy front-ends.
0030 /// The derived proxy only needs to expose the `component` helpers, while this
0031 /// base class wires up the commonly used convenience methods.
0032 ///
0033 /// @tparam Derived The proxy implementation inheriting from this base
0034 /// @tparam index_t The index type used by the proxy
0035 /// @tparam read_only Whether the proxy provides mutable access
0036 template <typename Derived, typename index_t, bool read_only>
0037 class TrackProxyCommon {
0038  protected:
0039   /// Cast to derived type
0040   /// @return Reference to the derived proxy
0041   constexpr Derived& derived() { return static_cast<Derived&>(*this); }
0042   /// Cast to derived type
0043   /// @return Const reference to the derived proxy
0044   constexpr const Derived& derived() const {
0045     return static_cast<const Derived&>(*this);
0046   }
0047 
0048  public:
0049   /// Index type used for referencing track states.
0050   using IndexType = index_t;
0051 
0052   /// Get the tip index, i.e. the entry point into the track state container.
0053   /// @return The tip index
0054   IndexType tipIndex() const {
0055     return derived().template component<IndexType, detail_tp::kTipIndexKey>();
0056   }
0057 
0058   /// Get a mutable reference to the tip index.
0059   /// @return Mutable reference to the tip index
0060   IndexType& tipIndex()
0061     requires(!read_only)
0062   {
0063     return derived().template component<IndexType, detail_tp::kTipIndexKey>();
0064   }
0065 
0066   /// Get the stem index, i.e. the innermost track state in the track.
0067   /// @return The stem index
0068   IndexType stemIndex() const {
0069     return derived().template component<IndexType, detail_tp::kStemIndexKey>();
0070   }
0071 
0072   /// Get a mutable reference to the stem index.
0073   /// @return Mutable reference to the stem index
0074   IndexType& stemIndex()
0075     requires(!read_only)
0076   {
0077     return derived().template component<IndexType, detail_tp::kStemIndexKey>();
0078   }
0079 
0080   /// Return the number of measurements assigned to this track.
0081   /// @return The number of measurements
0082   unsigned int nMeasurements() const {
0083     return derived()
0084         .template component<unsigned int, detail_tp::kMeasurementsKey>();
0085   }
0086 
0087   /// Return a mutable reference to the number of measurements.
0088   /// @return Mutable reference to the number of measurements
0089   unsigned int& nMeasurements()
0090     requires(!read_only)
0091   {
0092     return derived()
0093         .template component<unsigned int, detail_tp::kMeasurementsKey>();
0094   }
0095 
0096   /// Return the number of holes on this track.
0097   /// @return The number of holes
0098   unsigned int nHoles() const {
0099     return derived().template component<unsigned int, detail_tp::kHolesKey>();
0100   }
0101 
0102   /// Return a mutable reference to the number of holes.
0103   /// @return Mutable reference to the number of holes
0104   unsigned int& nHoles()
0105     requires(!read_only)
0106   {
0107     return derived().template component<unsigned int, detail_tp::kHolesKey>();
0108   }
0109 
0110   /// Return the number of outliers for this track.
0111   /// @return The number of outliers
0112   unsigned int nOutliers() const {
0113     return derived()
0114         .template component<unsigned int, detail_tp::kOutliersKey>();
0115   }
0116 
0117   /// Return a mutable reference to the number of outliers.
0118   /// @return Mutable reference to the number of outliers
0119   unsigned int& nOutliers()
0120     requires(!read_only)
0121   {
0122     return derived()
0123         .template component<unsigned int, detail_tp::kOutliersKey>();
0124   }
0125 
0126   /// Return the number of shared hits for this track.
0127   /// @return The number of shared hits
0128   unsigned int nSharedHits() const {
0129     return derived()
0130         .template component<unsigned int, detail_tp::kSharedHitsKey>();
0131   }
0132 
0133   /// Return a mutable reference to the number of shared hits.
0134   /// @return Mutable reference to the number of shared hits
0135   unsigned int& nSharedHits()
0136     requires(!read_only)
0137   {
0138     return derived()
0139         .template component<unsigned int, detail_tp::kSharedHitsKey>();
0140   }
0141 
0142   /// Return the local chi-squared contribution.
0143   /// @return The chi-squared value
0144   float chi2() const {
0145     return derived().template component<float, detail_tp::kChi2Key>();
0146   }
0147 
0148   /// Return a mutable reference to the local chi-squared contribution.
0149   /// @return Mutable reference to the chi-squared value
0150   float& chi2()
0151     requires(!read_only)
0152   {
0153     return derived().template component<float, detail_tp::kChi2Key>();
0154   }
0155 
0156   /// Return the number of degrees of freedom.
0157   /// @return The number of degrees of freedom
0158   unsigned int nDoF() const {
0159     return derived().template component<unsigned int, detail_tp::kNdfKey>();
0160   }
0161 
0162   /// Return a mutable reference to the number of degrees of freedom.
0163   /// @return Mutable reference to the number of degrees of freedom
0164   unsigned int& nDoF()
0165     requires(!read_only)
0166   {
0167     return derived().template component<unsigned int, detail_tp::kNdfKey>();
0168   }
0169 
0170   /// Access the theta parameter of the track at the reference surface
0171   /// @return The theta parameter
0172   double theta() const { return derived().parameters()[eBoundTheta]; }
0173 
0174   /// Access the phi parameter of the track at the reference surface
0175   /// @return The phi parameter
0176   double phi() const { return derived().parameters()[eBoundPhi]; }
0177 
0178   /// Access the loc0 parameter of the track at the reference surface
0179   /// @return The loc0 parameter
0180   double loc0() const { return derived().parameters()[eBoundLoc0]; }
0181 
0182   /// Access the loc1 parameter of the track at the reference surface
0183   /// @return The loc1 parameter
0184   double loc1() const { return derived().parameters()[eBoundLoc1]; }
0185 
0186   /// Access the time parameter of the track at the reference surface
0187   /// @return The time parameter
0188   double time() const { return derived().parameters()[eBoundTime]; }
0189 
0190   /// Access the q/p (curvature) parameter of the track at the reference surface
0191   /// @return The q/p parameter
0192   double qOverP() const { return derived().parameters()[eBoundQOverP]; }
0193 
0194   /// Get the charge
0195   /// @return The charge value
0196   double charge() const {
0197     return derived().particleHypothesis().extractCharge(qOverP());
0198   }
0199 
0200   /// Get the absolute momentum
0201   /// @return The absolute momentum value
0202   double absoluteMomentum() const {
0203     return derived().particleHypothesis().extractMomentum(qOverP());
0204   }
0205 
0206   /// Get the transverse momentum
0207   /// @return The transverse momentum value
0208   double transverseMomentum() const {
0209     return std::sin(derived().theta()) * derived().absoluteMomentum();
0210   }
0211 
0212   /// Get a unit vector along the track direction at the reference surface
0213   /// @return The direction unit vector
0214   Vector3 direction() const {
0215     return makeDirectionFromPhiTheta(derived().phi(), derived().theta());
0216   }
0217 
0218   /// Get the global momentum vector
0219   /// @return the global momentum vector
0220   Vector3 momentum() const {
0221     return derived().absoluteMomentum() * derived().direction();
0222   }
0223 
0224   /// Get the four-momentum vector: (px, py, pz, e)
0225   /// @return the four-momentum vector
0226   Vector4 fourMomentum() const {
0227     Vector4 p4 = Vector4::Zero();
0228 
0229     Vector3 p3 = derived().momentum();
0230     p4[eMom0] = p3[eMom0];
0231     p4[eMom1] = p3[eMom1];
0232     p4[eMom2] = p3[eMom2];
0233 
0234     float m = derived().particleHypothesis().mass();
0235     p4[eEnergy] = std::sqrt(m * m + p3.squaredNorm());
0236 
0237     return p4;
0238   }
0239 };
0240 
0241 }  // namespace Acts