Skip to content

Commit 4ba3efa

Browse files
committed
ITS: add hash function over clidx
1 parent bfbf945 commit 4ba3efa

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS

DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,33 @@ class TrackITSExt : public TrackITS
210210
return mIndex;
211211
}
212212

213+
#ifndef GPUCA_GPUCODE
214+
// build order-independent hash via the external cluster idx (unique within a TF) for the selected layers
215+
// cluster indices are either sorted inward or outward
216+
size_t hash(uint16_t layerMask = 0xFFFF, bool inward = true) const noexcept
217+
{
218+
size_t h1 = 0, h2 = 0;
219+
int from = (int)getLastClusterLayer(), to = -1, step = -1;
220+
if (inward) {
221+
from = (int)getFirstClusterLayer();
222+
to = MaxClusters;
223+
step = 1;
224+
}
225+
// clusters are stored continously but they do not necesarrily correspond to the layers
226+
for (int layer = from, slot{0}; layer != to; layer += step) {
227+
if (hasHitOnLayer(layer)) {
228+
int idx = mIndex[slot++];
229+
if (layerMask & (uint16_t(1) << layer)) {
230+
size_t v = std::hash<int>{}(idx);
231+
h1 ^= v;
232+
h2 += v * 0x9e3779b97f4a7c15ULL; // boost's hash_combine
233+
}
234+
}
235+
}
236+
return h1 ^ (h2 << 1);
237+
}
238+
#endif
239+
213240
private:
214241
std::array<int, MaxClusters> mIndex = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; ///< Indices of associated clusters
215242
ClassDefNV(TrackITSExt, 3);

0 commit comments

Comments
 (0)