Skip to content

Commit 18ea114

Browse files
committed
ITSMFT: fix clusterizer merge correctly connected pixels
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 7331b97 commit 18ea114

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/Clusterer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ class Clusterer
171171
curr[row] = lastIndex; // store index of the new precluster in the current column buffer
172172
}
173173

174+
///< find canoncial root by path-halving, compresses lookup for idx otf
175+
int findRoot(int idx)
176+
{
177+
int root = idx;
178+
while (preClusterIndices[root] != root) { // root finding
179+
root = preClusterIndices[root];
180+
}
181+
while (preClusterIndices[idx] != root) { // path compression
182+
int parent = preClusterIndices[idx];
183+
preClusterIndices[idx] = root;
184+
idx = parent;
185+
}
186+
return root;
187+
}
188+
174189
void fetchMCLabels(int digID, const ConstMCTruth* labelsDig, int& nfilled);
175190
void initChip(const ChipPixelData* curChipData, uint32_t first);
176191
void updateChip(const ChipPixelData* curChipData, uint32_t ip);

Detectors/ITSMFT/common/reconstruction/src/Clusterer.cxx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,17 @@ void Clusterer::process(int nThreads, PixelReader& reader, CompClusCont* compClu
133133
if (stat.firstChip == chid) {
134134
thrStatIdx[ith]++;
135135
chid += stat.nChips; // next chip to look
136-
const auto clbeg = mThreads[ith]->compClusters.begin() + stat.firstClus;
137-
auto szold = compClus->size();
138-
compClus->insert(compClus->end(), clbeg, clbeg + stat.nClus);
139-
if (patterns) {
140-
const auto ptbeg = mThreads[ith]->patterns.begin() + stat.firstPatt;
141-
patterns->insert(patterns->end(), ptbeg, ptbeg + stat.nPatt);
142-
}
143-
if (labelsCl) {
144-
labelsCl->mergeAtBack(mThreads[ith]->labels, stat.firstClus, stat.nClus);
136+
if (stat.nClus > 0) {
137+
const auto clbeg = mThreads[ith]->compClusters.begin() + stat.firstClus;
138+
auto szold = compClus->size();
139+
compClus->insert(compClus->end(), clbeg, clbeg + stat.nClus);
140+
if (patterns) {
141+
const auto ptbeg = mThreads[ith]->patterns.begin() + stat.firstPatt;
142+
patterns->insert(patterns->end(), ptbeg, ptbeg + stat.nPatt);
143+
}
144+
if (labelsCl) {
145+
labelsCl->mergeAtBack(mThreads[ith]->labels, stat.firstClus, stat.nClus);
146+
}
145147
}
146148
}
147149
}
@@ -214,6 +216,14 @@ void Clusterer::ClustererThread::finishChip(ChipPixelData* curChipData, CompClus
214216
PatternCont* patternsPtr, const ConstMCTruth* labelsDigPtr, MCTruth* labelsClusPtr)
215217
{
216218
const auto& pixData = curChipData->getData();
219+
220+
// normalize all precluster indices to their roots
221+
for (int i = 0; i < preClusterIndices.size(); ++i) {
222+
if (preClusterIndices[i] >= 0) {
223+
preClusterIndices[i] = findRoot(i);
224+
}
225+
}
226+
217227
for (int i1 = 0; i1 < preClusterHeads.size(); ++i1) {
218228
auto ci = preClusterIndices[i1];
219229
if (ci < 0) {
@@ -379,11 +389,13 @@ void Clusterer::ClustererThread::updateChip(const ChipPixelData* curChipData, ui
379389
}
380390

381391
Bool_t orphan = true;
392+
int currPreClusterIdx = -1;
382393

383394
if (noLeftCol) { // check only the row above
384395
if (curr[row - 1] >= 0) {
385396
expandPreCluster(ip, row, curr[row - 1]); // attach to the precluster of the previous row
386-
return;
397+
currPreClusterIdx = curr[row - 1];
398+
orphan = false;
387399
}
388400
} else {
389401
#ifdef _ALLOW_DIAGONAL_ALPIDE_CLUSTERS_
@@ -397,14 +409,20 @@ void Clusterer::ClustererThread::updateChip(const ChipPixelData* curChipData, ui
397409
}
398410
if (orphan) {
399411
expandPreCluster(ip, row, pci); // attach to the adjascent precluster
412+
currPreClusterIdx = pci;
400413
orphan = false;
401414
continue;
402415
}
403-
// reassign precluster index to smallest one
404-
if (preClusterIndices[pci] < preClusterIndices[curr[row]]) {
405-
preClusterIndices[curr[row]] = preClusterIndices[pci];
406-
} else {
407-
preClusterIndices[pci] = preClusterIndices[curr[row]];
416+
// merge the roots of both preclusters
417+
int root1 = findRoot(pci);
418+
int root2 = findRoot(currPreClusterIdx);
419+
if (root1 != root2) {
420+
// point to higher index to lower index for consistency
421+
if (root1 < root2) {
422+
preClusterIndices[root2] = root1;
423+
} else {
424+
preClusterIndices[root1] = root2;
425+
}
408426
}
409427
}
410428
}

0 commit comments

Comments
 (0)