CMS 3D CMS Logo

fitVertices.h
Go to the documentation of this file.
1 #ifndef RecoPixelVertexing_PixelVertexFinding_gpuFitVertices_h
2 #define RecoPixelVertexing_PixelVertexFinding_gpuFitVertices_h
3 
4 #include <algorithm>
5 #include <cmath>
6 #include <cstdint>
7 #include <alpaka/alpaka.hpp>
10 
11 #include "vertexFinder.h"
12 
14  namespace vertexFinder {
15  template <typename TAcc>
16  ALPAKA_FN_ACC ALPAKA_FN_INLINE __attribute__((always_inline)) void fitVertices(
17  const TAcc& acc,
19  WsSoAView& pws,
20  float chi2Max // for outlier rejection
21  ) {
22  constexpr bool verbose = false; // in principle the compiler should optmize out if false
23 
24  auto& __restrict__ data = pdata;
25  auto& __restrict__ ws = pws;
26  auto nt = ws.ntrks();
27  float const* __restrict__ zt = ws.zt();
28  float const* __restrict__ ezt2 = ws.ezt2();
29  float* __restrict__ zv = data.zv();
30  float* __restrict__ wv = data.wv();
31  float* __restrict__ chi2 = data.chi2();
32  uint32_t& nvFinal = data.nvFinal();
33  uint32_t& nvIntermediate = ws.nvIntermediate();
34 
35  int32_t* __restrict__ nn = data.ndof();
36  int32_t* __restrict__ iv = ws.iv();
37 
40  auto foundClusters = nvFinal;
41 
42  // zero
44  zv[i] = 0;
45  wv[i] = 0;
46  chi2[i] = 0;
47  }
48 
49  // only for test
50  auto& noise = alpaka::declareSharedVar<int, __COUNTER__>(acc);
51 
52  if constexpr (verbose) {
54  noise = 0;
55  }
56  alpaka::syncBlockThreads(acc);
57 
58  // compute cluster location
59  for (auto i : cms::alpakatools::elements_with_stride(acc, nt)) {
60  if (iv[i] > 9990) {
61  if constexpr (verbose)
62  alpaka::atomicAdd(acc, &noise, 1, alpaka::hierarchy::Threads{});
63  continue;
64  }
65  ALPAKA_ASSERT_OFFLOAD(iv[i] >= 0);
67  auto w = 1.f / ezt2[i];
68  alpaka::atomicAdd(acc, &zv[iv[i]], zt[i] * w, alpaka::hierarchy::Threads{});
69  alpaka::atomicAdd(acc, &wv[iv[i]], w, alpaka::hierarchy::Threads{});
70  }
71 
72  alpaka::syncBlockThreads(acc);
73  // reuse nn
76  zv[i] /= wv[i];
77  nn[i] = -1; // ndof
78  }
79  alpaka::syncBlockThreads(acc);
80 
81  // compute chi2
82  for (auto i : cms::alpakatools::elements_with_stride(acc, nt)) {
83  if (iv[i] > 9990)
84  continue;
85 
86  auto c2 = zv[iv[i]] - zt[i];
87  c2 *= c2 / ezt2[i];
88  if (c2 > chi2Max) {
89  iv[i] = 9999;
90  continue;
91  }
94  }
95  alpaka::syncBlockThreads(acc);
96 
98  if (nn[i] > 0) {
99  wv[i] *= float(nn[i]) / chi2[i];
100  }
101  }
102  if constexpr (verbose) {
104  printf("found %d proto clusters ", foundClusters);
105  printf("and %d noise\n", noise);
106  }
107  }
108  }
109 
111  public:
112  template <typename TAcc>
113  ALPAKA_FN_ACC void operator()(const TAcc& acc,
115  WsSoAView pws,
116  float chi2Max // for outlier rejection
117  ) const {
118  fitVertices(acc, pdata, pws, chi2Max);
119  }
120  };
121  } // namespace vertexFinder
122 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
123 #endif // RecoPixelVertexing_PixelVertexFinding_plugins_gpuFitVertices_h
ALPAKA_FN_ACC constexpr bool once_per_block(TAcc const &acc)
Definition: workdivision.h:805
ALPAKA_FN_ACC ALPAKA_FN_INLINE void VtxSoAView & pdata
T w() const
fitVertices(pdata, pws, maxChi2ForFirstFit)
ALPAKA_FN_ACC ALPAKA_FN_INLINE void VtxSoAView WsSoAView & pws
std::vector< Block > Blocks
Definition: Block.h:99
double f[11][100]
::vertexFinder::PixelVertexWorkSpaceSoAView WsSoAView
T1 atomicAdd(T1 *a, T2 b)
Definition: cudaCompat.h:61
ALPAKA_FN_ACC ALPAKA_FN_INLINE void __attribute__((always_inline)) clusterTracksByDensity(const TAcc &acc
ALPAKA_FN_ACC ALPAKA_FN_INLINE VtxSoAView WsSoAView float chi2Max
Definition: fitVertices.h:21
ALPAKA_FN_ACC void operator()(const TAcc &acc, VtxSoAView pdata, WsSoAView pws, float chi2Max) const
Definition: fitVertices.h:113