1 #ifndef RecoTracker_MkFitCore_standalone_attic_BestCands_h 2 #define RecoTracker_MkFitCore_standalone_attic_BestCands_h 23 template <
int MaxCandsPerSeed,
int BlockSize>
32 __device__ void update(
int itrack,
int cand_trIdx,
int cand_hitIdx,
int cand_nhits,
float cand_chi2);
48 const int tid,
const int cid,
int& my_trkIdx,
int& my_hitIdx,
int& my_nhits,
float& my_chi2);
54 template <
int M,
int B>
56 for (
auto j = 0;
j < M; ++
j) {
64 template <
int M,
int B>
66 if (cand_nhits <
nhits[0][itrack])
68 if (cand_chi2 >
chi2[0][itrack])
70 trkIdx[0][itrack] = cand_trIdx;
71 hitIdx[0][itrack] = cand_hitIdx;
72 nhits[0][itrack] = cand_nhits;
73 chi2[0][itrack] = cand_chi2;
75 heapify(itrack, 0, M);
78 template <
int M,
int B>
80 for (
int cid = 0; cid < M; cid++) {
81 printf(
">>>>> tid %d rowIdx %d hitIdx %d nhits %d chi2 %f\n",
90 template <
int M,
int B>
92 return (++
idx << 1) - 1;
95 template <
int M,
int B>
100 template <
int M,
int B>
102 return (
nhits[fst][icand_fst] >
nhits[snd][icand_snd]) ||
103 ((
nhits[fst][icand_fst] ==
nhits[snd][icand_snd]) && (
chi2[fst][icand_fst] <
chi2[snd][icand_snd]));
106 template <
int M,
int B>
108 swap_values(trkIdx[fst][icand_fst], trkIdx[snd][icand_snd]);
109 swap_values(hitIdx[fst][icand_fst], hitIdx[snd][icand_snd]);
114 template <
int M,
int B>
116 trkIdx[snd][icand_snd] = trkIdx[fst][icand_fst];
117 hitIdx[snd][icand_snd] = hitIdx[fst][icand_fst];
118 nhits[snd][icand_snd] =
nhits[fst][icand_fst];
119 chi2[snd][icand_snd] =
chi2[fst][icand_fst];
122 template <
int M,
int B>
126 while (
idx != smallest) {
127 if (idx < 0 || idx >= heap_size / 2)
131 if (heap_size > left(
idx) && better(icand, smallest, icand, left(
idx)))
132 smallest = left(
idx);
133 if (heap_size > right(
idx) && better(icand, smallest, icand, right(
idx)))
134 smallest = right(
idx);
136 if (smallest !=
idx) {
137 swap_nodes(icand, smallest, icand,
idx);
144 template <
int M,
int B>
146 int itrack =
iseed * M + icand;
151 heap_sort(itrack, M);
157 for (
int i = itrack + 1;
i < itrack + M; ++
i) {
158 for (
int j = 0;
j < M; ++
j) {
159 if (better(
i,
j, itrack, 0)) {
160 copy_node(
i,
j, itrack, 0);
161 heapify(itrack, 0, M);
167 heap_sort(itrack, M);
171 for (
int step = 2;
step <= Config::maxCandsPerSeed;
step <<= 1) {
173 heap_sort(itrack, M);
177 if (icand %
step == 0) {
178 int i = itrack +
step / 2;
179 if ((
i <
iseed * M + M) && (
i <
B) && (icand +
step / 2 < M)) {
180 for (
int j = 0;
j < M; ++
j) {
181 if (better(
i,
j, itrack, 0)) {
182 copy_node(
i,
j, itrack, 0);
183 heapify(itrack, 0, M);
194 heap_sort(itrack, M);
200 template <
int M,
int B>
202 int num_unsorted_elts = heap_size;
204 for (
int i = heap_size - 1;
i > 0; --
i) {
205 swap_nodes(icand, 0, icand,
i);
206 heapify(icand, 0, --num_unsorted_elts);
210 template <
int MaxCandsPerSeed,
int BlockSize>
212 const int tid,
const int cid,
int& my_trkIdx,
int& my_hitIdx,
int& my_nhits,
float& my_chi2) {
213 if (cid < MaxCandsPerSeed && tid <
BlockSize) {
214 my_trkIdx = trkIdx[cid][tid];
215 my_hitIdx = hitIdx[cid][tid];
216 my_nhits =
nhits[cid][tid];
217 my_chi2 =
chi2[cid][tid];
221 template <
int M,
int B>
224 for (
int i = 0;
i < M; ++
i) {
233 #endif // _BEST_CANDS_H_
__device__ void heap_sort(int icand, int heap_size)
constexpr int nhits_sentinel
float chi2[MaxCandsPerSeed][BlockSize]
__device__ void get_cand_info(const int tid, const int cid, int &my_trkIdx, int &my_hitIdx, int &my_nhits, float &my_chi2)
__device__ int left(int idx)
constexpr int hitIdx_sentinel
__device__ void swap_nodes(int icand_fst, int fst, int icand_snd, int snd)
__device__ void copy_node(int icand_fst, int fst, int icand_snd, int snd)
__device__ int count_valid_cands(int itrack)
int nhits[MaxCandsPerSeed][BlockSize]
__device__ int right(int idx)
__device__ bool better(int icand_fst, int fst, int icand_snd, int snd)
__device__ void swap_values(T &a, T &b)
__device__ void print_heap(const int tid)
__device__ void reset(int itrack)
__device__ void heapify(int itrack, int idx, int heap_size)
__device__ void merge_cands_for_seed(int iseed, int icand)
constexpr float chi2_sentinel
__device__ int get_nhits(const int tid, const int cid)
__device__ void update(int itrack, int cand_trIdx, int cand_hitIdx, int cand_nhits, float cand_chi2)
constexpr int trkIdx_sentinel
int trkIdx[MaxCandsPerSeed][BlockSize]
int hitIdx[MaxCandsPerSeed][BlockSize]