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 {
69  (pixelTopology::Phase1::layerPairs[pid * 2] == 0) ==
70  (pid < 3 || pid == 13 || pid == 15 || pid == 16)); // to be 100% sure it's working, may be removed
71  return pixelTopology::Phase1::layerPairs[pid * 2] == 0;
72  }
73  };
74 
75  template <typename TrackerTraits>
76  struct CAParamsT<TrackerTraits, pixelTopology::isPhase2Topology<TrackerTraits>> : public CACommon {
77  const bool includeFarForwards_;
79  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startingLayerPair(int16_t pid) const {
80  return pid < 33; // in principle one could remove 5,6,7 23, 28 and 29
81  }
82 
84  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool startAt0(int16_t pid) const {
85  ALPAKA_ASSERT_ACC((pixelTopology::Phase2::layerPairs[pid * 2] == 0) == ((pid < 3) | (pid >= 23 && pid < 28)));
86  return pixelTopology::Phase2::layerPairs[pid * 2] == 0;
87  }
88  };
89 
90  //Full list of params = algo params + ca params + cell params + quality cuts
91  //Generic template
92  template <typename TrackerTraits, typename Enable = void>
93  struct ParamsT : public AlgoParams {
94  // one should define the params for its own pixelTopology
95  // not defining anything here
96  inline uint32_t nPairs() const { return 0; }
97  };
98 
99  template <typename TrackerTraits>
100  struct ParamsT<TrackerTraits, pixelTopology::isPhase1Topology<TrackerTraits>> : public AlgoParams {
101  using TT = TrackerTraits;
102  using QualityCuts = ::pixelTrack::QualityCutsT<TT>; //track quality cuts
103  using CellCuts = caPixelDoublets::CellCutsT<TT>; //cell building cuts
104  using CAParams = CAParamsT<TT>; //params to be used on device
105 
106  ParamsT(AlgoParams const& commonCuts,
107  CellCuts const& cellCuts,
108  QualityCuts const& cutsCuts,
109  CAParams const& caParams)
110  : AlgoParams(commonCuts), cellCuts_(cellCuts), qualityCuts_(cutsCuts), caParams_(caParams) {}
111 
113  const QualityCuts qualityCuts_{// polynomial coefficients for the pT-dependent chi2 cut
114  {0.68177776, 0.74609577, -0.08035491, 0.00315399},
115  // max pT used to determine the chi2 cut
116  10.,
117  // chi2 scale factor: 30 for broken line fit, 45 for Riemann fit
118  30.,
119  // regional cuts for triplets
120  {
121  0.3, // |Tip| < 0.3 cm
122  0.5, // pT > 0.5 GeV
123  12.0 // |Zip| < 12.0 cm
124  },
125  // regional cuts for quadruplets
126  {
127  0.5, // |Tip| < 0.5 cm
128  0.3, // pT > 0.3 GeV
129  12.0 // |Zip| < 12.0 cm
130  }};
133  inline uint32_t nPairs() const {
134  // take all layer pairs into account
135  uint32_t nActualPairs = TT::nPairs;
137  // exclude forward "jumping" layer pairs
138  nActualPairs = TT::nPairsForTriplets;
139  }
140  if (caParams_.minHitsPerNtuplet_ > 3) {
141  // for quadruplets, exclude all "jumping" layer pairs
142  nActualPairs = TT::nPairsForQuadruplets;
143  }
144 
145  return nActualPairs;
146  }
147 
148  }; // Params Phase1
149 
150  template <typename TrackerTraits>
151  struct ParamsT<TrackerTraits, pixelTopology::isPhase2Topology<TrackerTraits>> : public AlgoParams {
152  using TT = TrackerTraits;
156 
157  ParamsT(AlgoParams const& commonCuts,
158  CellCuts const& cellCuts,
159  QualityCuts const& qualityCuts,
160  CAParams const& caParams)
161  : AlgoParams(commonCuts), cellCuts_(cellCuts), qualityCuts_(qualityCuts), caParams_(caParams) {}
162 
163  // quality cuts
165  const QualityCuts qualityCuts_{5.0f, /*chi2*/ 0.9f, /* pT in Gev*/ 0.4f, /*zip in cm*/ 12.0f /*tip in cm*/};
167 
168  inline uint32_t nPairs() const {
169  // take all layer pairs into account
170  uint32_t nActualPairs = TT::nPairsMinimal;
171  if (caParams_.includeFarForwards_) {
172  // considera far forwards (> 11 & > 23)
173  nActualPairs = TT::nPairsFarForwards;
174  }
176  // include jumping forwards
178  }
179 
180  return nActualPairs;
181  }
182 
183  }; // Params Phase1
184 
185  // counters
186  struct Counters {
187  unsigned long long nEvents;
188  unsigned long long nHits;
189  unsigned long long nCells;
190  unsigned long long nTuples;
191  unsigned long long nFitTracks;
192  unsigned long long nLooseTracks;
193  unsigned long long nGoodTracks;
194  unsigned long long nUsedHits;
195  unsigned long long nDupHits;
196  unsigned long long nFishCells;
197  unsigned long long nKilledCells;
198  unsigned long long nEmptyCells;
199  unsigned long long nZeroTrackCells;
200  };
201 
203 
204  } // namespace caHitNtupletGenerator
205 
206  template <typename TTTraits>
208  public:
209  using TrackerTraits = TTTraits;
215 
219 
220  using HitToTuple = caStructures::template HitToTupleT<TrackerTraits>;
221  using TupleMultiplicity = caStructures::template TupleMultiplicityT<TrackerTraits>;
222  struct Testttt {
224  };
231 
233 
236 
237  CAHitNtupletGeneratorKernels(Params const& params, uint32_t nhits, uint32_t offsetBPIX2, Queue& queue);
238  ~CAHitNtupletGeneratorKernels() = default;
239 
241 
242  void launchKernels(const HitsConstView& hh, uint32_t offsetBPIX2, TkSoAView& track_view, Queue& queue);
243 
244  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, Queue& queue);
245 
246  void buildDoublets(const HitsConstView& hh, uint32_t offsetBPIX2, Queue& queue);
247 
248  static void printCounters();
249 
250  private:
251  // params
252  Params const& m_params;
254 
255  // workspace
273  };
274 
275 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
276 
277 #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
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
cms::alpakatools::device_buffer< Device, uint32_t[]> device_hitToTupleStorage_
static constexpr uint8_t const * layerPairs
typename reco::TrackSoA< TrackerTraits >::template Layout<>::View TrackSoAView
Definition: TracksSoA.h:45