CMS 3D CMS Logo

CAHitNtupletGeneratorKernels.h
Go to the documentation of this file.
1 #ifndef RecoTracker_PixelSeeding_plugins_alpaka_CAHitNtupletGeneratorKernels_h
2 #define RecoTracker_PixelSeeding_plugins_alpaka_CAHitNtupletGeneratorKernels_h
3 
4 //#define GPU_DEBUG
5 //#define DUMP_GPU_TK_TUPLES
6 
7 #include <cstdint>
8 
9 #include <alpaka/alpaka.hpp>
10 
19 
20 #include "CACell.h"
21 #include "CAPixelDoublets.h"
22 #include "CAStructures.h"
23 
26 
27  //Configuration params common to all topologies, for the algorithms
28  struct AlgoParams {
29  const uint32_t minHitsForSharingCut_;
30  const bool useRiemannFit_;
31  const bool fitNas4_;
33  const bool earlyFishbone_;
34  const bool lateFishbone_;
35  const bool doStats_;
36  const bool doSharedHitCut_;
37  const bool dupPassThrough_;
39  };
40 
41  //CAParams
42  struct CACommon {
43  const uint32_t maxNumberOfDoublets_;
44  const uint32_t minHitsPerNtuplet_;
45  const float ptmin_;
46  const float CAThetaCutBarrel_;
47  const float CAThetaCutForward_;
48  const float hardCurvCut_;
49  const float dcaCutInnerTriplet_;
50  const float dcaCutOuterTriplet_;
51  };
52 
53  template <typename TrackerTraits, typename Enable = void>
54  struct CAParamsT : public CACommon {
55  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startingLayerPair(int16_t pid) const { return false; };
56  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startAt0(int16_t pid) const { return false; };
57  };
58 
59  template <typename TrackerTraits>
60  struct CAParamsT<TrackerTraits, pixelTopology::isPhase1Topology<TrackerTraits>> : public CACommon {
62  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startingLayerPair(int16_t pid) const {
63  return minHitsPerNtuplet_ > 3 ? pid < 3 : pid < 8 || pid > 12;
64  }
65 
67  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startAt0(int16_t pid) const {
68  assert((pixelTopology::Phase1::layerPairs[pid * 2] == 0) ==
69  (pid < 3 || pid == 13 || pid == 15 || pid == 16)); // to be 100% sure it's working, may be removed
70  return pixelTopology::Phase1::layerPairs[pid * 2] == 0;
71  }
72  };
73 
74  template <typename TrackerTraits>
75  struct CAParamsT<TrackerTraits, pixelTopology::isPhase2Topology<TrackerTraits>> : public CACommon {
76  const bool includeFarForwards_;
78  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startingLayerPair(int16_t pid) const {
79  return pid < 33; // in principle one could remove 5,6,7 23, 28 and 29
80  }
81 
83  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startAt0(int16_t pid) const {
84  assert((pixelTopology::Phase2::layerPairs[pid * 2] == 0) == ((pid < 3) | (pid >= 23 && pid < 28)));
85  return pixelTopology::Phase2::layerPairs[pid * 2] == 0;
86  }
87  };
88 
89  //Full list of params = algo params + ca params + cell params + quality cuts
90  //Generic template
91  template <typename TrackerTraits, typename Enable = void>
92  struct ParamsT : public AlgoParams {
93  // one should define the params for its own pixelTopology
94  // not defining anything here
95  inline uint32_t nPairs() const { return 0; }
96  };
97 
98  template <typename TrackerTraits>
99  struct ParamsT<TrackerTraits, pixelTopology::isPhase1Topology<TrackerTraits>> : public AlgoParams {
100  using TT = TrackerTraits;
101  using QualityCuts = ::pixelTrack::QualityCutsT<TT>; //track quality cuts
102  using CellCuts = caPixelDoublets::CellCutsT<TT>; //cell building cuts
103  using CAParams = CAParamsT<TT>; //params to be used on device
104 
105  ParamsT(AlgoParams const& commonCuts,
106  CellCuts const& cellCuts,
107  QualityCuts const& cutsCuts,
108  CAParams const& caParams)
109  : AlgoParams(commonCuts), cellCuts_(cellCuts), qualityCuts_(cutsCuts), caParams_(caParams) {}
110 
112  const QualityCuts qualityCuts_{// polynomial coefficients for the pT-dependent chi2 cut
113  {0.68177776, 0.74609577, -0.08035491, 0.00315399},
114  // max pT used to determine the chi2 cut
115  10.,
116  // chi2 scale factor: 30 for broken line fit, 45 for Riemann fit
117  30.,
118  // regional cuts for triplets
119  {
120  0.3, // |Tip| < 0.3 cm
121  0.5, // pT > 0.5 GeV
122  12.0 // |Zip| < 12.0 cm
123  },
124  // regional cuts for quadruplets
125  {
126  0.5, // |Tip| < 0.5 cm
127  0.3, // pT > 0.3 GeV
128  12.0 // |Zip| < 12.0 cm
129  }};
132  inline uint32_t nPairs() const {
133  // take all layer pairs into account
134  uint32_t nActualPairs = TT::nPairs;
136  // exclude forward "jumping" layer pairs
137  nActualPairs = TT::nPairsForTriplets;
138  }
139  if (caParams_.minHitsPerNtuplet_ > 3) {
140  // for quadruplets, exclude all "jumping" layer pairs
141  nActualPairs = TT::nPairsForQuadruplets;
142  }
143 
144  return nActualPairs;
145  }
146 
147  }; // Params Phase1
148 
149  template <typename TrackerTraits>
150  struct ParamsT<TrackerTraits, pixelTopology::isPhase2Topology<TrackerTraits>> : public AlgoParams {
151  using TT = TrackerTraits;
155 
156  ParamsT(AlgoParams const& commonCuts,
157  CellCuts const& cellCuts,
158  QualityCuts const& qualityCuts,
159  CAParams const& caParams)
160  : AlgoParams(commonCuts), cellCuts_(cellCuts), qualityCuts_(qualityCuts), caParams_(caParams) {}
161 
162  // quality cuts
164  const QualityCuts qualityCuts_{5.0f, /*chi2*/ 0.9f, /* pT in Gev*/ 0.4f, /*zip in cm*/ 12.0f /*tip in cm*/};
166 
167  inline uint32_t nPairs() const {
168  // take all layer pairs into account
169  uint32_t nActualPairs = TT::nPairsMinimal;
170  if (caParams_.includeFarForwards_) {
171  // considera far forwards (> 11 & > 23)
172  nActualPairs = TT::nPairsFarForwards;
173  }
175  // include jumping forwards
177  }
178 
179  return nActualPairs;
180  }
181 
182  }; // Params Phase1
183 
184  // counters
185  struct Counters {
186  unsigned long long nEvents;
187  unsigned long long nHits;
188  unsigned long long nCells;
189  unsigned long long nTuples;
190  unsigned long long nFitTracks;
191  unsigned long long nLooseTracks;
192  unsigned long long nGoodTracks;
193  unsigned long long nUsedHits;
194  unsigned long long nDupHits;
195  unsigned long long nFishCells;
196  unsigned long long nKilledCells;
197  unsigned long long nEmptyCells;
198  unsigned long long nZeroTrackCells;
199  };
200 
202 
203  } // namespace caHitNtupletGenerator
204 
205  template <typename TTTraits>
207  public:
208  using TrackerTraits = TTTraits;
214 
218 
219  using HitToTuple = caStructures::template HitToTupleT<TrackerTraits>;
220  using TupleMultiplicity = caStructures::template TupleMultiplicityT<TrackerTraits>;
221  struct Testttt {
223  };
230 
232 
235 
236  CAHitNtupletGeneratorKernels(Params const& params, uint32_t nhits, uint32_t offsetBPIX2, Queue& queue);
237  ~CAHitNtupletGeneratorKernels() = default;
238 
240 
241  void launchKernels(const HitsConstView& hh, uint32_t offsetBPIX2, TkSoAView& track_view, Queue& queue);
242 
243  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, Queue& queue);
244 
245  void buildDoublets(const HitsConstView& hh, uint32_t offsetBPIX2, Queue& queue);
246 
247  static void printCounters();
248 
249  private:
250  // params
251  Params const& m_params;
253 
254  // workspace
270  };
271 
272 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
273 
274 #endif // RecoTracker_PixelSeeding_plugins_alpaka_CAHitNtupletGeneratorKernels_h
caStructures::template TupleMultiplicityT< TrackerTraits > TupleMultiplicity
cms::alpakatools::device_buffer< Device, cms::alpakatools::AtomicPairCounter::DoubleWord[]> device_storage_
cms::alpakatools::device_buffer< Device, CACell[]> device_theCells_
cms::alpakatools::device_buffer< Device, HitToTuple > device_hitToTuple_
CAHitNtupletGeneratorKernels(Params const &params, uint32_t nhits, uint32_t offsetBPIX2, Queue &queue)
typename std::enable_if< std::is_base_of< Phase2, T >::value >::type isPhase2Topology
caStructures::template HitToTupleT< TrackerTraits > HitToTuple
assert(be >=bs)
typename detail::view_type< TDev, T >::type device_view
Definition: memory.h:257
typename reco::TrackSoA< TrackerTraits >::HitContainer HitContainer
ParamsT(AlgoParams const &commonCuts, CellCuts const &cellCuts, QualityCuts const &cutsCuts, CAParams const &caParams)
cms::alpakatools::device_buffer< Device, OuterHitOfCellContainer[]> device_isOuterHitOfCell_
cms::alpakatools::device_buffer< Device, OuterHitOfCell > isOuterHitOfCell_
cms::alpakatools::device_buffer< Device, CellTracksVector > device_theCellTracks_
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
typename std::enable_if< std::is_base_of< Phase1, T >::value >::type isPhase1Topology
uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > OuterHitOfCell< TrackerTraits > int nActualPairs
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > hh
cms::alpakatools::device_view< Device, uint32_t > device_nCells_
typename CACellT< TrackerTraits >::HitsConstView HitsConstView
Definition: CAFishbone.h:34
cms::alpakatools::device_buffer< Device, unsigned char[]> cellStorage_
void buildDoublets(const HitsConstView &hh, uint32_t offsetBPIX2, Queue &queue)
cms::alpakatools::device_buffer< Device, CellCuts > device_cellCuts_
ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startingLayerPair(int16_t pid) const
typename TrackingRecHitSoA< TrackerTraits >::template TrackingRecHitSoALayout<>::ConstView TrackingRecHitSoAConstView
void launchKernels(const HitsConstView &hh, uint32_t offsetBPIX2, TkSoAView &track_view, Queue &queue)
cms::alpakatools::device_buffer< Device, Counters > counters_
typename TrackingRecHitSoA< TrackerTraits >::template TrackingRecHitSoALayout<>::View TrackingRecHitSoAView
cms::alpakatools::device_buffer< Device, TupleMultiplicity > device_tupleMultiplicity_
ParamsT(AlgoParams const &commonCuts, CellCuts const &cellCuts, QualityCuts const &qualityCuts, CAParams const &caParams)
cms::alpakatools::device_buffer< Device, CellNeighborsVector > device_theCellNeighbors_
typename detail::buffer_type< TDev, T >::type device_buffer
Definition: memory.h:177
void classifyTuples(const HitsConstView &hh, TkSoAView &track_view, Queue &queue)
static constexpr uint8_t const * layerPairs
ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startAt0(int16_t pid) const
static constexpr uint8_t const * layerPairs
typename reco::TrackSoA< TrackerTraits >::template Layout<>::View TrackSoAView
Definition: TracksSoA.h:45