Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:21:58

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Local include(s).
0011 #include "traccc/definitions/qualifiers.hpp"
0012 #include "traccc/edm/track_parameters.hpp"
0013 
0014 // Detray include(s).
0015 #include <detray/definitions/algebra.hpp>
0016 
0017 // VecMem include(s).
0018 #include <vecmem/edm/container.hpp>
0019 
0020 // System include(s).
0021 #include <concepts>
0022 #include <cstdint>
0023 #include <ostream>
0024 
0025 namespace traccc::edm {
0026 
0027 /// Interface for the @c traccc::edm::track_state_collection type.
0028 ///
0029 /// It provides the API that users would interact with, while using the
0030 /// columns/arrays of the SoA containers, or the variables of the AoS proxies
0031 /// created on top of the SoA containers.
0032 ///
0033 template <typename BASE>
0034 class track_state : public BASE {
0035  public:
0036   /// @name Functions inherited from the base class
0037   /// @{
0038 
0039   /// Inherit the base class's constructor(s)
0040   using BASE::BASE;
0041   /// Inherit the base class's assignment operator(s).
0042   using BASE::operator=;
0043 
0044   /// @}
0045 
0046   /// @name Constants
0047   /// @{
0048 
0049   /// @c is_hole bit in the state word
0050   static constexpr std::uint8_t IS_HOLE_MASK = 0x01;
0051   /// @c is_smoothed bit in the state word
0052   static constexpr std::uint8_t IS_SMOOTHED_MASK = 0x02;
0053 
0054   /// @}
0055 
0056   /// @name Track State Information
0057   /// @{
0058 
0059   /// The "state word" of the track (non-const)
0060   ///
0061   /// @return A (non-const) vector of unsigned integers
0062   ///
0063   TRACCC_HOST_DEVICE
0064   auto& state() { return BASE::template get<0>(); }
0065   /// The "state word" of the track (const)
0066   ///
0067   /// @return A (const) vector of unsigned integers
0068   ///
0069   TRACCC_HOST_DEVICE
0070   const auto& state() const { return BASE::template get<0>(); }
0071 
0072   /// Chi^2 of the fitered parameters (non-const)
0073   ///
0074   /// @return A (non-const) vector of scalar values
0075   ///
0076   TRACCC_HOST_DEVICE
0077   auto& filtered_chi2() { return BASE::template get<1>(); }
0078   /// Chi^2 of the filtered parameters (const)
0079   ///
0080   /// @return A (const) vector of scalar values
0081   ///
0082   TRACCC_HOST_DEVICE
0083   const auto& filtered_chi2() const { return BASE::template get<1>(); }
0084 
0085   /// Chi^2 of the smoothed parameters (non-const)
0086   ///
0087   /// @return A (non-const) vector of scalar values
0088   ///
0089   TRACCC_HOST_DEVICE
0090   auto& smoothed_chi2() { return BASE::template get<2>(); }
0091   /// Chi^2 of the smoothed parameters (const)
0092   ///
0093   /// @return A (const) vector of scalar values
0094   ///
0095   TRACCC_HOST_DEVICE
0096   const auto& smoothed_chi2() const { return BASE::template get<2>(); }
0097 
0098   /// Chi^2 of the backward parameters (non-const)
0099   ///
0100   /// @return A (non-const) vector of scalar values
0101   ///
0102   TRACCC_HOST_DEVICE
0103   auto& backward_chi2() { return BASE::template get<3>(); }
0104   /// Chi^2 of the backward parameters (const)
0105   ///
0106   /// @return A (const) vector of scalar values
0107   ///
0108   TRACCC_HOST_DEVICE
0109   const auto& backward_chi2() const { return BASE::template get<3>(); }
0110 
0111   /// The filtered parameters of the track on the surface (non-const)
0112   ///
0113   /// @return A (non-const) vector of bound track parameters
0114   ///
0115   TRACCC_HOST_DEVICE
0116   auto& filtered_params() { return BASE::template get<4>(); }
0117   /// The filtered parameters of the track on the surface (const)
0118   ///
0119   /// @return A (const) vector of bound track parameters
0120   ///
0121   TRACCC_HOST_DEVICE
0122   const auto& filtered_params() const { return BASE::template get<4>(); }
0123 
0124   /// The smoothed parameters of the track on the surface (non-const)
0125   ///
0126   /// @return A (non-const) vector of bound track parameters
0127   ///
0128   TRACCC_HOST_DEVICE
0129   auto& smoothed_params() { return BASE::template get<5>(); }
0130   /// The smoothed parameters of the track on the surface (const)
0131   ///
0132   /// @return A (const) vector of bound track parameters
0133   ///
0134   TRACCC_HOST_DEVICE
0135   const auto& smoothed_params() const { return BASE::template get<5>(); }
0136 
0137   /// The index of the track's measurement on the current surface (non-const)
0138   ///
0139   /// @return A (non-const) vector of unsigned integers
0140   ///
0141   TRACCC_HOST_DEVICE
0142   auto& measurement_index() { return BASE::template get<6>(); }
0143   /// The index of the track's measurement on the current surface (const)
0144   ///
0145   /// @return A (const) vector of unsigned integers
0146   ///
0147   TRACCC_HOST_DEVICE
0148   const auto& measurement_index() const { return BASE::template get<6>(); }
0149 
0150   /// @}
0151 
0152   /// @name Utility functions
0153   /// @{
0154 
0155   /// Check if the track state is on a hole
0156   ///
0157   /// @note This function must only be used on proxy objects, not on
0158   ///       containers!
0159   ///
0160   /// @return @c true if the track state is on a hole, @c false otherwise
0161   ///
0162   TRACCC_HOST_DEVICE
0163   bool is_hole() const;
0164   /// Set the track state to be on a hole
0165   ///
0166   /// @note This function must only be used on proxy objects, not on
0167   ///       containers!
0168   ///
0169   /// @param value The value to set
0170   ///
0171   TRACCC_HOST_DEVICE
0172   void set_hole(bool value = true);
0173 
0174   /// Check if the track state is smoothed
0175   ///
0176   /// @note This function must only be used on proxy objects, not on
0177   ///       containers!
0178   ///
0179   /// @return @c true if the track state is smoothed, @c false otherwise
0180   ///
0181   TRACCC_HOST_DEVICE
0182   bool is_smoothed() const;
0183   /// Set the track state to be smoothed
0184   ///
0185   /// @note This function must only be used on proxy objects, not on
0186   ///       containers!
0187   ///
0188   /// @param value The value to set
0189   ///
0190   TRACCC_HOST_DEVICE
0191   void set_smoothed(bool value = true);
0192 
0193   /// @}
0194 
0195  private:
0196   /// @returns a string stream that prints the track state details
0197   TRACCC_HOST
0198   friend std::ostream& operator<<(std::ostream& os, const track_state& s) {
0199     os << "hole: " << std::boolalpha << s.is_hole() << std::endl;
0200     os << "smoothed: " << s.is_smoothed() << std::noboolalpha << std::endl;
0201     if (!s.is_hole()) {
0202       os << "measurement index: " << s.measurement_index() << std::endl;
0203     }
0204 
0205     os << "filtered: chi2 (fw) = " << s.filtered_chi2()
0206        << ", chi2 (bw) = " << s.backward_chi2() << "\n"
0207        << s.filtered_params() << std::endl;
0208 
0209     if (s.is_smoothed()) {
0210       os << "smoothed: chi2 = " << s.smoothed_chi2() << "\n"
0211          << s.smoothed_params() << std::endl;
0212     }
0213 
0214     return os;
0215   }
0216 
0217 };  // class track_state
0218 
0219 /// SoA container describing the fit states of tracks on specific measurements
0220 ///
0221 /// @tparam ALGEBRA The algebra type used to describe the tracks
0222 ///
0223 template <detray::concepts::algebra ALGEBRA>
0224 using track_state_collection = vecmem::edm::container<
0225     track_state,
0226     // state
0227     vecmem::edm::type::vector<std::uint8_t>,
0228     // filtered_chi2
0229     vecmem::edm::type::vector<detray::dscalar<ALGEBRA>>,
0230     // smoothed_chi2
0231     vecmem::edm::type::vector<detray::dscalar<ALGEBRA>>,
0232     // backward_chi2
0233     vecmem::edm::type::vector<detray::dscalar<ALGEBRA>>,
0234     // filtered_params
0235     vecmem::edm::type::vector<bound_track_parameters<ALGEBRA>>,
0236     // smoothed_params
0237     vecmem::edm::type::vector<bound_track_parameters<ALGEBRA>>,
0238     // measurement_index
0239     vecmem::edm::type::vector<unsigned int>>;
0240 
0241 }  // namespace traccc::edm
0242 
0243 // Include the implementation.
0244 #include "traccc/edm/impl/track_state_collection.ipp"