Skip to content

Commit 1f1bf16

Browse files
authored
Clusterer will prioritize labels with lower trackIndex (#15782)
The HIP may produce a large number of delta electrons (e.g. a magnetic monopole typically produces a few 10K deltas in the barrel). Since we limit the number of saved MC labels per ITS/MFT cluster to `Clusterer::MaxLabels` (=10), in a large cluster receiving contributions from both the HIP and its delta rays, the HIP label might not be saved if MaxLabels delta electrons contributing to the same cluster have already been accounted for (the order is quasi-random). To minimize the chance of such label loss, assuming that the track ID of the HIP is smaller than those of its delta rays, when there is no free slot left in the label buffer, the new label (e.g. that of the HIP) will replace the label with the largest track ID already present in the buffer.
1 parent f7f295b commit 1f1bf16

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ void Clusterer::ClustererThread::process(uint16_t chip, uint16_t nChips, CompClu
170170
if (stats.empty() || stats.back().firstChip + stats.back().nChips != chip) { // there is a jump, register new block
171171
stats.emplace_back(ThreadStat{.firstChip = chip, .nChips = 0, .firstClus = uint32_t(compClusPtr->size()), .firstPatt = patternsPtr ? uint32_t(patternsPtr->size()) : 0, .nClus = 0, .nPatt = 0});
172172
}
173+
173174
for (int ic = 0; ic < nChips; ic++) {
174175
auto* curChipData = parent->mFiredChipsPtr[chip + ic];
175176
auto chipID = curChipData->getChipID();
@@ -316,7 +317,7 @@ void Clusterer::ClustererThread::finishChipSingleHitFast(uint32_t hit, ChipPixel
316317
int nlab = 0;
317318
fetchMCLabels(curChipData->getStartID() + hit, labelsDigPtr, nlab);
318319
auto cnt = compClusPtr->size();
319-
for (int i = nlab; i--;) {
320+
for (int i = 0; i < nlab; i++) {
320321
labelsClusPtr->addElement(cnt, labelsBuff[i]);
321322
}
322323
}
@@ -436,20 +437,27 @@ void Clusterer::ClustererThread::updateChip(const ChipPixelData* curChipData, ui
436437
void Clusterer::ClustererThread::fetchMCLabels(int digID, const ConstMCTruth* labelsDig, int& nfilled)
437438
{
438439
// transfer MC labels to cluster
439-
if (nfilled >= MaxLabels) {
440-
return;
441-
}
442-
const auto& lbls = labelsDig->getLabels(digID);
443-
for (int i = lbls.size(); i--;) {
444-
int ic = nfilled;
445-
for (; ic--;) { // check if the label is already present
446-
if (labelsBuff[ic] == lbls[i]) {
447-
return; // label is found, do nothing
440+
auto sortBuffer = [this]() { std::sort(this->labelsBuff.begin(), this->labelsBuff.end(), [](Label const& a, Label const& b) { return a.getTrackID() < b.getTrackID(); }); };
441+
for (const auto& l : labelsDig->getLabels(digID)) {
442+
bool skip = false;
443+
for (int ic = 0; ic < nfilled; ic++) { // check if the label is already present
444+
if (labelsBuff[ic] == l) {
445+
skip = true;
446+
break;
448447
}
449448
}
450-
labelsBuff[nfilled++] = lbls[i];
451-
if (nfilled >= MaxLabels) {
452-
break;
449+
if (!skip) { // are there still slots to add it?
450+
if (nfilled < MaxLabels) {
451+
labelsBuff[nfilled++] = l;
452+
if (nfilled == MaxLabels) { // we filled the buffer, sort labels in the trackID increasing order, to increase chances of not losing more primary at next filling
453+
sortBuffer();
454+
}
455+
} else { // buffer is full and sorted in trackID increasing order, substitute the old highest track ID if it is higher than the new label
456+
if (labelsBuff.back().getTrackID() > l.getTrackID()) {
457+
labelsBuff.back() = l; // substitute and re-sort
458+
sortBuffer();
459+
}
460+
}
453461
}
454462
}
455463
//

0 commit comments

Comments
 (0)