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