Skip to content

Commit f53522e

Browse files
authored
Upgrades: clusterer will prioritize labels with lower trackIndex (#15783)
Extending PR15782 to upgrade classes which replicated the cluster label building from the ITS: 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 5e3d5e5 commit f53522e

4 files changed

Lines changed: 56 additions & 41 deletions

File tree

Detectors/Upgrades/ALICE3/IOTOF/reconstruction/src/Clusterer.cxx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void Clusterer::ClustererThread::finishChipSingleHitFast(gsl::span<const Digit>
160160
int nlab = 0;
161161
fetchMCLabels(digitIdx, labelsDigPtr, nlab);
162162
const auto cnt = static_cast<uint32_t>(clusters.size());
163-
for (int i = nlab; i--;) {
163+
for (int i = 0; i < nlab; i++) {
164164
labels.addElement(cnt, labelsBuff[i]);
165165
}
166166
}
@@ -182,23 +182,28 @@ void Clusterer::ClustererThread::finishChipSingleHitFast(gsl::span<const Digit>
182182
//__________________________________________________
183183
void Clusterer::ClustererThread::fetchMCLabels(uint32_t digID, const ConstDigitTruth* labelsDig, int& nfilled)
184184
{
185-
if (nfilled >= MaxLabels) {
186-
return;
187-
}
188185
if (!labelsDig || digID >= labelsDig->getIndexedSize()) {
189186
return;
190187
}
191-
const auto& lbls = labelsDig->getLabels(digID);
192-
for (int i = lbls.size(); i--;) {
193-
int ic = nfilled;
194-
for (; ic--;) {
195-
if (labelsBuff[ic] == lbls[i]) {
196-
return; // already present
188+
auto sortBuffer = [this]() { std::sort(this->labelsBuff.begin(), this->labelsBuff.end(), [](Label const& a, Label const& b) { return a.getTrackID() < b.getTrackID(); }); };
189+
for (const auto& label : labelsDig->getLabels(digID)) {
190+
bool skip = false;
191+
for (int ic = 0; ic < nfilled; ic++) {
192+
if (labelsBuff[ic] == label) {
193+
skip = true;
194+
break;
197195
}
198196
}
199-
labelsBuff[nfilled++] = lbls[i];
200-
if (nfilled >= MaxLabels) {
201-
break;
197+
if (!skip) {
198+
if (nfilled < MaxLabels) {
199+
labelsBuff[nfilled++] = label;
200+
if (nfilled == MaxLabels) {
201+
sortBuffer();
202+
}
203+
} else if (labelsBuff.back().getTrackID() > label.getTrackID()) {
204+
labelsBuff.back() = label;
205+
sortBuffer();
206+
}
202207
}
203208
}
204209
}

Detectors/Upgrades/ALICE3/TRKFT3/common/reconstruction/src/Clusterer.cxx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ void Clusterer<DetID>::ClustererThread::finishChipSingleHitFast(gsl::span<const
372372
int nlab = 0;
373373
fetchMCLabels(hit, labelsDigPtr, nlab);
374374
const auto cnt = static_cast<uint32_t>(clusters.size());
375-
for (int i = nlab; i--;) {
375+
for (int i = 0; i < nlab; i++) {
376376
labels.addElement(cnt, labelsBuff[i]);
377377
}
378378
}
@@ -404,7 +404,7 @@ void Clusterer<DetID>::ClustererThread::streamCluster(const BBox& bbox,
404404
{
405405
if (doLabels) {
406406
const auto cnt = static_cast<uint32_t>(clusters.size());
407-
for (int i = nlab; i--;) {
407+
for (int i = 0; i < nlab; i++) {
408408
labels.addElement(cnt, labelsBuff[i]); // accumulate in thread-local buffer
409409
}
410410
}
@@ -438,23 +438,28 @@ void Clusterer<DetID>::ClustererThread::streamCluster(const BBox& bbox,
438438
template <int DetID>
439439
void Clusterer<DetID>::ClustererThread::fetchMCLabels(uint32_t digID, const ConstDigitTruth* labelsDig, int& nfilled)
440440
{
441-
if (nfilled >= MaxLabels) {
442-
return;
443-
}
444441
if (!labelsDig || digID >= labelsDig->getIndexedSize()) {
445442
return;
446443
}
447-
const auto& lbls = labelsDig->getLabels(digID);
448-
for (int i = lbls.size(); i--;) {
449-
int ic = nfilled;
450-
for (; ic--;) {
451-
if (labelsBuff[ic] == lbls[i]) {
452-
return; // already present
444+
auto sortBuffer = [this]() { std::sort(this->labelsBuff.begin(), this->labelsBuff.end(), [](Label const& a, Label const& b) { return a.getTrackID() < b.getTrackID(); }); };
445+
for (const auto& label : labelsDig->getLabels(digID)) {
446+
bool skip = false;
447+
for (int ic = 0; ic < nfilled; ic++) {
448+
if (labelsBuff[ic] == label) {
449+
skip = true;
450+
break;
453451
}
454452
}
455-
labelsBuff[nfilled++] = lbls[i];
456-
if (nfilled >= MaxLabels) {
457-
break;
453+
if (!skip) {
454+
if (nfilled < MaxLabels) {
455+
labelsBuff[nfilled++] = label;
456+
if (nfilled == MaxLabels) {
457+
sortBuffer();
458+
}
459+
} else if (labelsBuff.back().getTrackID() > label.getTrackID()) {
460+
labelsBuff.back() = label;
461+
sortBuffer();
462+
}
458463
}
459464
}
460465
}

Detectors/Upgrades/ITS3/reconstruction/include/ITS3Reconstruction/Clusterer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void Clusterer::streamCluster(const std::vector<PixelData>& pixbuf, const std::a
283283
{
284284
if (labelsClusPtr && lblBuff) { // MC labels were requested
285285
auto cnt = compClusPtr->size();
286-
for (int i = nlab; i--;) {
286+
for (int i = 0; i < nlab; i++) {
287287
labelsClusPtr->addElement(cnt, (*lblBuff)[i]);
288288
}
289289
}

Detectors/Upgrades/ITS3/reconstruction/src/Clusterer.cxx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void Clusterer::ClustererThread::finishChipSingleHitFast(uint32_t hit, ChipPixel
318318
int nlab = 0;
319319
fetchMCLabels(curChipData->getStartID() + hit, labelsDigPtr, nlab);
320320
auto cnt = compClusPtr->size();
321-
for (int i = nlab; i--;) {
321+
for (int i = 0; i < nlab; i++) {
322322
labelsClusPtr->addElement(cnt, labelsBuff[i]);
323323
}
324324
}
@@ -454,20 +454,25 @@ void Clusterer::ClustererThread::updateChip(const ChipPixelData* curChipData, ui
454454
void Clusterer::ClustererThread::fetchMCLabels(int digID, const ConstMCTruth* labelsDig, int& nfilled)
455455
{
456456
// transfer MC labels to cluster
457-
if (nfilled >= MaxLabels) {
458-
return;
459-
}
460-
const auto& lbls = labelsDig->getLabels(digID);
461-
for (int i = lbls.size(); i--;) {
462-
int ic = nfilled;
463-
for (; ic--;) { // check if the label is already present
464-
if (labelsBuff[ic] == lbls[i]) {
465-
return; // label is found, do nothing
457+
auto sortBuffer = [this]() { std::sort(this->labelsBuff.begin(), this->labelsBuff.end(), [](Label const& a, Label const& b) { return a.getTrackID() < b.getTrackID(); }); };
458+
for (const auto& label : labelsDig->getLabels(digID)) {
459+
bool skip = false;
460+
for (int ic = 0; ic < nfilled; ic++) { // check if the label is already present
461+
if (labelsBuff[ic] == label) {
462+
skip = true;
463+
break;
466464
}
467465
}
468-
labelsBuff[nfilled++] = lbls[i];
469-
if (nfilled >= MaxLabels) {
470-
break;
466+
if (!skip) { // are there still slots to add it?
467+
if (nfilled < MaxLabels) {
468+
labelsBuff[nfilled++] = label;
469+
if (nfilled == MaxLabels) { // we filled the buffer, sort labels in the trackID increasing order
470+
sortBuffer();
471+
}
472+
} else if (labelsBuff.back().getTrackID() > label.getTrackID()) {
473+
labelsBuff.back() = label;
474+
sortBuffer();
475+
}
471476
}
472477
}
473478
//

0 commit comments

Comments
 (0)