CMS 3D CMS Logo

TracksSoA.h
Go to the documentation of this file.
1 #ifndef DataFormats_TrackSoA_interface_TracksSoA_h
2 #define DataFormats_TrackSoA_interface_TracksSoA_h
3 
4 #include <alpaka/alpaka.hpp>
5 
6 #include <Eigen/Core>
7 
12 
13 namespace reco {
14 
15  template <typename TrackerTraits>
16  struct TrackSoA {
17  static constexpr int32_t S = TrackerTraits::maxNumberOfTuples;
18  static constexpr int32_t H = TrackerTraits::avgHitsPerTrack;
19  // Aliases in order to not confuse the GENERATE_SOA_LAYOUT
20  // macro with weird colons and angled brackets.
21  using Vector5f = Eigen::Matrix<float, 5, 1>;
22  using Vector15f = Eigen::Matrix<float, 15, 1>;
24 
25  using hindex_type = uint32_t;
26 
28 
31  SOA_COLUMN(float, chi2),
32  SOA_COLUMN(int8_t, nLayers),
33  SOA_COLUMN(float, eta),
34  SOA_COLUMN(float, pt),
35  // state at the beam spot: {phi, tip, 1/pt, cotan(theta), zip}
37  SOA_EIGEN_COLUMN(Vector15f, covariance),
38  SOA_SCALAR(int, nTracks),
39  SOA_SCALAR(HitContainer, hitIndices),
40  SOA_SCALAR(HitContainer, detIndices))
41  };
42 
43  template <typename TrackerTraits>
44  using TrackLayout = typename reco::TrackSoA<TrackerTraits>::template Layout<>;
45  template <typename TrackerTraits>
47  template <typename TrackerTraits>
48  using TrackSoAConstView = typename reco::TrackSoA<TrackerTraits>::template Layout<>::ConstView;
49 
50  /* Implement a type trait to identify the specialisations of TrackSoAConstView<TrackerTraits>
51  *
52  * This is done explicitly for all possible pixel topologies, because we did not find a way
53  * to use template deduction with a partial specialisation.
54  */
55  template <typename T>
56  struct IsTrackSoAConstView : std::false_type {};
57  template <>
58  struct IsTrackSoAConstView<TrackSoAConstView<pixelTopology::Phase1>> : std::true_type {};
59  template <>
60  struct IsTrackSoAConstView<TrackSoAView<pixelTopology::Phase1>> : std::true_type {};
61  template <>
62  struct IsTrackSoAConstView<TrackSoAConstView<pixelTopology::Phase2>> : std::true_type {};
63  template <>
64  struct IsTrackSoAConstView<TrackSoAView<pixelTopology::Phase2>> : std::true_type {};
65  template <>
66  struct IsTrackSoAConstView<TrackSoAConstView<pixelTopology::HIonPhase1>> : std::true_type {};
67  template <>
68  struct IsTrackSoAConstView<TrackSoAView<pixelTopology::HIonPhase1>> : std::true_type {};
69 
70  template <typename T>
72 
73  template <typename ConstView, typename = std::enable_if_t<isTrackSoAConstView<ConstView>>>
74  ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float charge(ConstView const& tracks, int32_t i) {
75  //was: std::copysign(1.f, tracks[i].state()(2)). Will be constexpr with C++23
76  float v = tracks[i].state()(2);
77  return float((0.0f < v) - (v < 0.0f));
78  }
79 
80  template <typename ConstView, typename = std::enable_if_t<isTrackSoAConstView<ConstView>>>
81  ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float phi(ConstView const& tracks, int32_t i) {
82  return tracks[i].state()(0);
83  }
84 
85  template <typename ConstView, typename = std::enable_if_t<isTrackSoAConstView<ConstView>>>
86  ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float tip(ConstView const& tracks, int32_t i) {
87  return tracks[i].state()(1);
88  }
89 
90  template <typename ConstView, typename = std::enable_if_t<isTrackSoAConstView<ConstView>>>
91  ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const& tracks, int32_t i) {
92  return tracks[i].state()(4);
93  }
94 
95  template <typename ConstView, typename = std::enable_if_t<isTrackSoAConstView<ConstView>>>
96  ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr bool isTriplet(ConstView const& tracks, int32_t i) {
97  return tracks[i].nLayers() == 3;
98  }
99 
100 } // namespace reco
101 
102 #endif // DataFormats_TrackSoA_interface_TracksSoA_h
Eigen::Matrix< float, 15, 1 > Vector15f
Definition: TracksSoA.h:22
static constexpr int32_t H
Definition: TracksSoA.h:18
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
constexpr bool isTrackSoAConstView
Definition: TracksSoA.h:70
Eigen::Matrix< float, 5, 1 > Vector5f
Definition: TracksSoA.h:21
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float charge(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:73
typename reco::TrackSoA< TrackerTraits >::template Layout<> TrackLayout
Definition: TracksSoA.h:43
string quality
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float tip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:85
#define GENERATE_SOA_LAYOUT(CLASS,...)
Definition: SoALayout.h:431
#define SOA_SCALAR(TYPE, NAME)
Definition: SoACommon.h:563
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float phi(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:80
double f[11][100]
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr bool isTriplet(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:95
uint32_t hindex_type
Definition: TracksSoA.h:25
typename reco::TrackSoA< TrackerTraits >::template Layout<>::ConstView TrackSoAConstView
Definition: TracksSoA.h:47
fixed size matrix
#define SOA_EIGEN_COLUMN(TYPE, NAME)
Definition: SoACommon.h:565
#define SOA_COLUMN(TYPE, NAME)
Definition: SoACommon.h:564
typename reco::TrackSoA< TrackerTraits >::template Layout<>::View TrackSoAView
Definition: TracksSoA.h:45