CMS 3D CMS Logo

CAFishbone.h
Go to the documentation of this file.
1 #ifndef RecoTracker_PixelSeeding_plugins_alpaka_CAFishbone_h
2 #define RecoTracker_PixelSeeding_plugins_alpaka_CAFishbone_h
3 
4 #include <algorithm>
5 #include <cmath>
6 #include <cstdint>
7 #include <cstdio>
8 #include <limits>
9 
10 #include <alpaka/alpaka.hpp>
11 
17 
18 #include "CACell.h"
19 #include "CAStructures.h"
20 
22 
23  template <typename TrackerTraits>
25  template <typename TrackerTraits>
27  template <typename TrackerTraits>
29  template <typename TrackerTraits>
31  template <typename TrackerTraits>
33  template <typename TrackerTraits>
35 
36  template <typename TrackerTraits>
37  class CAFishbone {
38  public:
39  template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
40  ALPAKA_FN_ACC void operator()(TAcc const& acc,
43  uint32_t const* __restrict__ nCells,
45  int32_t nHits,
46  bool checkTrack) const {
48 
49  int32_t layer2Offset = isOuterHitOfCellWrap->offset;
50  // if there are no hits outside of the BPIX1, there is nothing to do
51  if (nHits <= layer2Offset)
52  return;
53 
54  auto const isOuterHitOfCell = isOuterHitOfCellWrap->container;
55 
56  float x[maxCellsPerHit], y[maxCellsPerHit], z[maxCellsPerHit], n[maxCellsPerHit];
57  uint32_t cc[maxCellsPerHit];
58  uint16_t d[maxCellsPerHit];
59  uint8_t l[maxCellsPerHit];
60 
61  // outermost parallel loop, using all grid elements along the slower dimension (Y or 0 in a 2D grid)
62  for (uint32_t idy : cms::alpakatools::uniform_elements_y(acc, nHits - layer2Offset)) {
63  auto const& vc = isOuterHitOfCell[idy];
64  auto size = vc.size();
65  if (size < 2)
66  continue;
67  // if alligned kill one of the two.
68  // in principle one could try to relax the cut (only in r-z?) for jumping-doublets
69  auto const& c0 = cells[vc[0]];
70  auto xo = c0.outer_x(hh);
71  auto yo = c0.outer_y(hh);
72  auto zo = c0.outer_z(hh);
73  auto sg = 0;
74  for (int32_t ic = 0; ic < size; ++ic) {
75  auto& ci = cells[vc[ic]];
76  if (ci.unused())
77  continue; // for triplets equivalent to next
78  if (checkTrack && ci.tracks().empty())
79  continue;
80  cc[sg] = vc[ic];
81  l[sg] = ci.layerPairId();
82  d[sg] = ci.inner_detIndex(hh);
83  x[sg] = ci.inner_x(hh) - xo;
84  y[sg] = ci.inner_y(hh) - yo;
85  z[sg] = ci.inner_z(hh) - zo;
86  n[sg] = x[sg] * x[sg] + y[sg] * y[sg] + z[sg] * z[sg];
87  ++sg;
88  }
89  if (sg < 2)
90  continue;
91 
92  // innermost parallel loop, using the block elements along the faster dimension (X or 1 in a 2D grid)
93  for (uint32_t ic : cms::alpakatools::independent_group_elements_x(acc, sg - 1)) {
94  auto& ci = cells[cc[ic]];
95  for (auto jc = ic + 1; (int)jc < sg; ++jc) {
96  auto& cj = cells[cc[jc]];
97  // must be different detectors (in the same layer)
98  // if (d[ic]==d[jc]) continue;
99  auto cos12 = x[ic] * x[jc] + y[ic] * y[jc] + z[ic] * z[jc];
100 
101  if (d[ic] != d[jc] && cos12 * cos12 >= 0.99999f * (n[ic] * n[jc])) {
102  // alligned: kill farthest (prefer consecutive layers)
103  // if same layer prefer farthest (longer level arm) and make space for intermediate hit
104  bool sameLayer = l[ic] == l[jc];
105  if (n[ic] > n[jc]) {
106  if (sameLayer) {
107  cj.kill(); // closest
108  ci.setFishbone(acc, cj.inner_hit_id(), cj.inner_z(hh), hh);
109  } else {
110  ci.kill(); // farthest
111  // break; // removed to improve reproducibility, keep it for reference and tests
112  }
113  } else {
114  if (!sameLayer) {
115  cj.kill(); // farthest
116  } else {
117  ci.kill(); // closest
118  cj.setFishbone(acc, ci.inner_hit_id(), ci.inner_z(hh), hh);
119  // break; // removed to improve reproducibility, keep it for reference and tests
120  }
121  }
122  }
123  } // cj
124  } // ci
125  } // hits
126  }
127  };
128 
129 } // namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets
130 
131 #endif // RecoTracker_PixelSeeding_plugins_alpaka_CAFishbone_h
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
GPUCACellT< TrackerTraits > uint32_t const *__restrict__ OuterHitOfCell< TrackerTraits > const isOuterHitOfCellWrap
Definition: gpuFishbone.h:34
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > * cells
ALPAKA_FN_ACC void operator()(TAcc const &acc, HitsConstView< TrackerTraits > hh, CACellT< TrackerTraits > *cells, uint32_t const *__restrict__ nCells, OuterHitOfCell< TrackerTraits > const *isOuterHitOfCellWrap, int32_t nHits, bool checkTrack) const
Definition: CAFishbone.h:40
ALPAKA_FN_ACC auto uniform_elements_y(TAcc const &acc, TArgs... args)
Definition: workdivision.h:344
double f[11][100]
ALPAKA_FN_ACC auto independent_group_elements_x(TAcc const &acc, TArgs... args)
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > hh
d
Definition: ztail.py:151
typename CACellT< TrackerTraits >::HitsConstView HitsConstView
Definition: CAFishbone.h:34
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t * nCells
float x
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
TrackingRecHitSoAConstView< TrackerTraits > HitsConstView
Definition: CACell.h:36
GPUCACellT< TrackerTraits > uint32_t const *__restrict__ OuterHitOfCell< TrackerTraits > const int32_t bool checkTrack
Definition: gpuFishbone.h:38
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > OuterHitOfCell< TrackerTraits > isOuterHitOfCell