Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:07:28

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   constexpr Derived& derived() { return static_cast<Derived&>(*this); }
0040   constexpr const Derived& derived() const {
0041     return static_cast<const Derived&>(*this);
0042   }
0043 
0044  public:
0045   /// Index type used for referencing track states.
0046   using IndexType = index_t;
0047 
0048   /// Get the tip index, i.e. the entry point into the track state container.
0049   IndexType tipIndex() const {
0050     return derived().template component<IndexType, detail_tp::kTipIndexKey>();
0051   }
0052 
0053   /// Get a mutable reference to the tip index.
0054   IndexType& tipIndex()
0055     requires(!read_only)
0056   {
0057     return derived().template component<IndexType, detail_tp::kTipIndexKey>();
0058   }
0059 
0060   /// Get the stem index, i.e. the innermost track state in the track.
0061   IndexType stemIndex() const {
0062     return derived().template component<IndexType, detail_tp::kStemIndexKey>();
0063   }
0064 
0065   /// Get a mutable reference to the stem index.
0066   IndexType& stemIndex()
0067     requires(!read_only)
0068   {
0069     return derived().template component<IndexType, detail_tp::kStemIndexKey>();
0070   }
0071 
0072   /// Return the number of measurements assigned to this track.
0073   unsigned int nMeasurements() const {
0074     return derived()
0075         .template component<unsigned int, detail_tp::kMeasurementsKey>();
0076   }
0077 
0078   /// Return a mutable reference to the number of measurements.
0079   unsigned int& nMeasurements()
0080     requires(!read_only)
0081   {
0082     return derived()
0083         .template component<unsigned int, detail_tp::kMeasurementsKey>();
0084   }
0085 
0086   /// Return the number of holes on this track.
0087   unsigned int nHoles() const {
0088     return derived().template component<unsigned int, detail_tp::kHolesKey>();
0089   }
0090 
0091   /// Return a mutable reference to the number of holes.
0092   unsigned int& nHoles()
0093     requires(!read_only)
0094   {
0095     return derived().template component<unsigned int, detail_tp::kHolesKey>();
0096   }
0097 
0098   /// Return the number of outliers for this track.
0099   unsigned int nOutliers() const {
0100     return derived()
0101         .template component<unsigned int, detail_tp::kOutliersKey>();
0102   }
0103 
0104   /// Return a mutable reference to the number of outliers.
0105   unsigned int& nOutliers()
0106     requires(!read_only)
0107   {
0108     return derived()
0109         .template component<unsigned int, detail_tp::kOutliersKey>();
0110   }
0111 
0112   /// Return the number of shared hits for this track.
0113   unsigned int nSharedHits() const {
0114     return derived()
0115         .template component<unsigned int, detail_tp::kSharedHitsKey>();
0116   }
0117 
0118   /// Return a mutable reference to the number of shared hits.
0119   unsigned int& nSharedHits()
0120     requires(!read_only)
0121   {
0122     return derived()
0123         .template component<unsigned int, detail_tp::kSharedHitsKey>();
0124   }
0125 
0126   /// Return the local chi-squared contribution.
0127   float chi2() const {
0128     return derived().template component<float, detail_tp::kChi2Key>();
0129   }
0130 
0131   /// Return a mutable reference to the local chi-squared contribution.
0132   float& chi2()
0133     requires(!read_only)
0134   {
0135     return derived().template component<float, detail_tp::kChi2Key>();
0136   }
0137 
0138   /// Return the number of degrees of freedom.
0139   unsigned int nDoF() const {
0140     return derived().template component<unsigned int, detail_tp::kNdfKey>();
0141   }
0142 
0143   /// Return a mutable reference to the number of degrees of freedom.
0144   unsigned int& nDoF()
0145     requires(!read_only)
0146   {
0147     return derived().template component<unsigned int, detail_tp::kNdfKey>();
0148   }
0149 
0150   /// Access the theta parameter of the track at the reference surface
0151   /// @return The theta parameter
0152   double theta() const { return derived().parameters()[eBoundTheta]; }
0153 
0154   /// Access the phi parameter of the track at the reference surface
0155   /// @return The phi parameter
0156   double phi() const { return derived().parameters()[eBoundPhi]; }
0157 
0158   /// Access the loc0 parameter of the track at the reference surface
0159   /// @return The loc0 parameter
0160   double loc0() const { return derived().parameters()[eBoundLoc0]; }
0161 
0162   /// Access the loc1 parameter of the track at the reference surface
0163   /// @return The loc1 parameter
0164   double loc1() const { return derived().parameters()[eBoundLoc1]; }
0165 
0166   /// Access the time parameter of the track at the reference surface
0167   /// @return The time parameter
0168   double time() const { return derived().parameters()[eBoundTime]; }
0169 
0170   /// Access the q/p (curvature) parameter of the track at the reference surface
0171   /// @return The q/p parameter
0172   double qOverP() const { return derived().parameters()[eBoundQOverP]; }
0173 
0174   /// Get the charge
0175   /// @return The charge value
0176   double charge() const {
0177     return derived().particleHypothesis().extractCharge(qOverP());
0178   }
0179 
0180   /// Get the absolute momentum
0181   /// @return The absolute momentum value
0182   double absoluteMomentum() const {
0183     return derived().particleHypothesis().extractMomentum(qOverP());
0184   }
0185 
0186   /// Get the transverse momentum
0187   /// @return The transverse momentum value
0188   double transverseMomentum() const {
0189     return std::sin(derived().theta()) * derived().absoluteMomentum();
0190   }
0191 
0192   /// Get a unit vector along the track direction at the reference surface
0193   /// @return The direction unit vector
0194   Vector3 direction() const {
0195     return makeDirectionFromPhiTheta(derived().phi(), derived().theta());
0196   }
0197 
0198   /// Get the global momentum vector
0199   /// @return the global momentum vector
0200   Vector3 momentum() const {
0201     return derived().absoluteMomentum() * derived().direction();
0202   }
0203 
0204   /// Get the four-momentum vector: (px, py, pz, e)
0205   /// @return the four-momentum vector
0206   Vector4 fourMomentum() const {
0207     Vector4 p4 = Vector4::Zero();
0208 
0209     Vector3 p3 = derived().momentum();
0210     p4[eMom0] = p3[eMom0];
0211     p4[eMom1] = p3[eMom1];
0212     p4[eMom2] = p3[eMom2];
0213 
0214     float m = derived().particleHypothesis().mass();
0215     p4[eEnergy] = std::sqrt(m * m + p3.squaredNorm());
0216 
0217     return p4;
0218   }
0219 };
0220 
0221 }  // namespace Acts