Skip to content

Commit 353895c

Browse files
martenoleshahor02
authored andcommitted
Remove duplicate labels for tracklets
1 parent d5cd151 commit 353895c

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

Detectors/TRD/workflow/src/TRDTrapSimulatorSpec.cxx

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,30 @@ void TRDDPLTrapSimulatorTask::run(o2::framework::ProcessingContext& pc)
247247
nTrackletsInTrigRec += nTrackletsOut;
248248
auto digitCountOut = mTrapSimulator[iTrap].getTrackletDigitCount();
249249
auto digitIndicesOut = mTrapSimulator[iTrap].getTrackletDigitIndices();
250-
std::vector<o2::MCCompLabel> trackletLabels;
251-
int currDigitIndex = 0;
250+
int currDigitIndex = 0; // count the total number of digits which are associated to tracklets for this TRAP
251+
int trkltIdxStart = trapTrackletsAccum.size();
252252
for (int iTrklt = 0; iTrklt < nTrackletsOut; ++iTrklt) {
253-
for (int iDigitIndex = currDigitIndex; iDigitIndex < digitCountOut[iTrklt]; ++iDigitIndex) {
254-
trackletMCLabels.addElements(trapTrackletsAccum.size() + iTrklt, digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]));
253+
int tmp = currDigitIndex;
254+
for (int iDigitIndex = tmp; iDigitIndex < tmp + digitCountOut[iTrklt]; ++iDigitIndex) {
255+
if (iDigitIndex == tmp) {
256+
// for the first digit composing the tracklet we don't need to check for duplicate labels
257+
trackletMCLabels.addElements(trkltIdxStart + iTrklt, digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]));
258+
} else {
259+
auto currentLabels = trackletMCLabels.getLabels(trkltIdxStart + iTrklt);
260+
auto newLabels = digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]);
261+
for (const auto& newLabel : newLabels) {
262+
bool isAlreadyIn = false;
263+
for (const auto& currLabel : currentLabels) {
264+
if (currLabel.compare(newLabel)) {
265+
isAlreadyIn = true;
266+
}
267+
}
268+
if (!isAlreadyIn) {
269+
trackletMCLabels.addElement(trkltIdxStart + iTrklt, newLabel);
270+
}
271+
}
272+
}
273+
++currDigitIndex;
255274
}
256275
}
257276
trapTrackletsAccum.insert(trapTrackletsAccum.end(), trackletsOut.begin(), trackletsOut.end());
@@ -296,11 +315,30 @@ void TRDDPLTrapSimulatorTask::run(o2::framework::ProcessingContext& pc)
296315
nTrackletsInTrigRec += nTrackletsOut;
297316
auto digitCountOut = mTrapSimulator[iTrap].getTrackletDigitCount();
298317
auto digitIndicesOut = mTrapSimulator[iTrap].getTrackletDigitIndices();
299-
std::vector<o2::MCCompLabel> trackletLabels;
300-
int currDigitIndex = 0;
318+
int currDigitIndex = 0; // count the total number of digits which are associated to tracklets for this TRAP
319+
int trkltIdxStart = trapTrackletsAccum.size();
301320
for (int iTrklt = 0; iTrklt < nTrackletsOut; ++iTrklt) {
302-
for (int iDigitIndex = currDigitIndex; iDigitIndex < digitCountOut[iTrklt]; ++iDigitIndex) {
303-
trackletMCLabels.addElements(trapTrackletsAccum.size() + iTrklt, digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]));
321+
int tmp = currDigitIndex;
322+
for (int iDigitIndex = tmp; iDigitIndex < tmp + digitCountOut[iTrklt]; ++iDigitIndex) {
323+
if (iDigitIndex == tmp) {
324+
// for the first digit composing the tracklet we don't need to check for duplicate labels
325+
trackletMCLabels.addElements(trkltIdxStart + iTrklt, digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]));
326+
} else {
327+
auto currentLabels = trackletMCLabels.getLabels(trkltIdxStart + iTrklt);
328+
auto newLabels = digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]);
329+
for (const auto& newLabel : newLabels) {
330+
bool isAlreadyIn = false;
331+
for (const auto& currLabel : currentLabels) {
332+
if (currLabel.compare(newLabel)) {
333+
isAlreadyIn = true;
334+
}
335+
}
336+
if (!isAlreadyIn) {
337+
trackletMCLabels.addElement(trkltIdxStart + iTrklt, newLabel);
338+
}
339+
}
340+
}
341+
++currDigitIndex;
304342
}
305343
}
306344
trapTrackletsAccum.insert(trapTrackletsAccum.end(), mTrapSimulator[iTrap].getTrackletArray64().begin(), mTrapSimulator[iTrap].getTrackletArray64().end());

0 commit comments

Comments
 (0)