Skip to content

Commit e7da788

Browse files
committed
ITS: redefine lines label
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 1b9ceb7 commit e7da788

2 files changed

Lines changed: 62 additions & 62 deletions

File tree

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Tracklet.h

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ namespace o2::its
2929
{
3030

3131
struct Tracklet final {
32-
GPUhdi() Tracklet();
32+
GPUhdDefault() Tracklet() = default;
3333
GPUhdi() Tracklet(const int, const int, const Cluster&, const Cluster&, short rof0, short rof1);
3434
GPUhdi() Tracklet(const int, const int, float tanL, float phi, short rof0, short rof1);
35-
GPUhdi() bool operator==(const Tracklet&) const;
36-
GPUhdi() bool operator!=(const Tracklet&) const;
35+
GPUhdDefault() bool operator==(const Tracklet&) const = default;
3736
GPUhdi() unsigned char isEmpty() const
3837
{
3938
return firstClusterIndex < 0 || secondClusterIndex < 0;
@@ -52,21 +51,15 @@ struct Tracklet final {
5251
}
5352
#endif
5453

55-
int firstClusterIndex;
56-
int secondClusterIndex;
57-
float tanLambda;
58-
float phi;
59-
short rof[2];
54+
int firstClusterIndex{-1};
55+
int secondClusterIndex{-1};
56+
float tanLambda{-999};
57+
float phi{-999};
58+
short rof[2] = {-1, -1};
6059

6160
ClassDefNV(Tracklet, 1);
6261
};
6362

64-
GPUhdi() Tracklet::Tracklet() : firstClusterIndex{-1}, secondClusterIndex{-1}, tanLambda{0.0f}, phi{0.0f}
65-
{
66-
rof[0] = -1;
67-
rof[1] = -1;
68-
}
69-
7063
GPUhdi() Tracklet::Tracklet(const int firstClusterOrderingIndex, const int secondClusterOrderingIndex,
7164
const Cluster& firstCluster, const Cluster& secondCluster, short rof0 = -1, short rof1 = -1)
7265
: firstClusterIndex{firstClusterOrderingIndex},
@@ -90,24 +83,6 @@ GPUhdi() Tracklet::Tracklet(const int idx0, const int idx1, float tanL, float ph
9083
// Nothing to do
9184
}
9285

93-
GPUhdi() bool Tracklet::operator==(const Tracklet& rhs) const
94-
{
95-
return this->firstClusterIndex == rhs.firstClusterIndex &&
96-
this->secondClusterIndex == rhs.secondClusterIndex &&
97-
this->tanLambda == rhs.tanLambda &&
98-
this->phi == rhs.phi &&
99-
this->rof[0] == rhs.rof[0] &&
100-
this->rof[1] == rhs.rof[1];
101-
}
102-
103-
GPUhdi() bool Tracklet::operator!=(const Tracklet& rhs) const
104-
{
105-
return this->firstClusterIndex != rhs.firstClusterIndex ||
106-
this->secondClusterIndex != rhs.secondClusterIndex ||
107-
this->tanLambda != rhs.tanLambda ||
108-
this->phi != rhs.phi;
109-
}
110-
11186
GPUhdi() unsigned char Tracklet::operator<(const Tracklet& t) const
11287
{
11388
if (isEmpty()) {

Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,16 @@ void trackleterKernelHost(
9999
void trackletSelectionKernelHost(
100100
const gsl::span<const Cluster> clusters0, // 0
101101
const gsl::span<const Cluster> clusters1, // 1
102-
gsl::span<unsigned char> usedClusters0, // Layer 0
103-
gsl::span<unsigned char> usedClusters2, // Layer 2
102+
gsl::span<uint8_t> usedClusters0, // Layer 0
103+
gsl::span<uint8_t> usedClusters2, // Layer 2
104104
const gsl::span<const Tracklet>& tracklets01,
105105
const gsl::span<const Tracklet>& tracklets12,
106-
bounded_vector<uint8_t>& usedTracklets,
106+
bounded_vector<bool>& usedTracklets01,
107107
const gsl::span<int> foundTracklets01,
108108
const gsl::span<int> foundTracklets12,
109109
bounded_vector<Line>& lines,
110-
const gsl::span<const o2::MCCompLabel>& trackletLabels,
110+
const gsl::span<const o2::MCCompLabel>& trackletLabels0,
111+
const gsl::span<const o2::MCCompLabel>& trackletLabels1,
111112
bounded_vector<o2::MCCompLabel>& linesLabels,
112113
const short pivotRofId,
113114
const short targetRofId,
@@ -127,13 +128,24 @@ void trackletSelectionKernelHost(
127128
}
128129
const float deltaTanLambda{o2::gpu::GPUCommonMath::Abs(tracklet01.tanLambda - tracklet12.tanLambda)};
129130
const float deltaPhi{o2::gpu::GPUCommonMath::Abs(math_utils::smallestAngleDifference(tracklet01.phi, tracklet12.phi))};
130-
if (!usedTracklets[iTracklet01] && deltaTanLambda < tanLambdaCut && deltaPhi < phiCut && validTracklets != maxTracklets) {
131-
usedClusters0[tracklet01.firstClusterIndex] = true;
132-
usedClusters2[tracklet12.secondClusterIndex] = true;
133-
usedTracklets[iTracklet01] = true;
131+
if (!usedTracklets01[iTracklet01] && deltaTanLambda < tanLambdaCut && deltaPhi < phiCut && validTracklets != maxTracklets) {
132+
++usedClusters0[tracklet01.firstClusterIndex];
133+
++usedClusters2[tracklet12.secondClusterIndex];
134+
usedTracklets01[iTracklet01] = true;
134135
lines.emplace_back(tracklet01, clusters0.data(), clusters1.data());
135-
if (!trackletLabels.empty()) {
136-
linesLabels.emplace_back(trackletLabels[iTracklet01]);
136+
if (!trackletLabels0.empty() && !trackletLabels1.empty()) {
137+
const auto& lbl0 = trackletLabels0[iTracklet01];
138+
const auto& lbl1 = trackletLabels1[iTracklet12];
139+
if (lbl0 == lbl1) {
140+
// both lines come from the same particle, fake or unset
141+
linesLabels.emplace_back(lbl0);
142+
} else if (lbl0.getSourceID() == lbl1.getSourceID() && lbl0.getEventID() == lbl1.getEventID()) {
143+
// both lines come at least from the same source and event
144+
linesLabels.emplace_back(o2::MCCompLabel::maxTrackID(), lbl0.getEventID(), lbl0.getSourceID(), true);
145+
} else {
146+
// in this case we leave the label unset
147+
linesLabels.emplace_back();
148+
}
137149
}
138150
++validTracklets;
139151
}
@@ -268,26 +280,38 @@ void VertexerTraits::computeTracklets(const int iteration)
268280
});
269281
});
270282

271-
/// Create tracklets labels for L0-L1, information is as flat as in tracklets vector (no rofId)
283+
/// Create tracklets labels for L0-L1 + L1-L2, information is as flat as in tracklets vector (no rofId)
272284
if (mTimeFrame->hasMCinformation()) {
273-
for (const auto& trk : mTimeFrame->getTracklets()[0]) {
274-
o2::MCCompLabel label;
275-
if (!trk.isEmpty()) {
276-
int sortedId0{mTimeFrame->getSortedIndex(trk.rof[0], 0, trk.firstClusterIndex)};
277-
int sortedId1{mTimeFrame->getSortedIndex(trk.rof[1], 1, trk.secondClusterIndex)};
278-
for (const auto& lab0 : mTimeFrame->getClusterLabels(0, mTimeFrame->getClusters()[0][sortedId0].clusterId)) {
279-
for (const auto& lab1 : mTimeFrame->getClusterLabels(1, mTimeFrame->getClusters()[1][sortedId1].clusterId)) {
280-
if (lab0 == lab1 && lab0.isValid()) {
281-
label = lab0;
282-
break;
285+
for (int iLayer{0}; iLayer < 2; ++iLayer) {
286+
const auto& tracklets = mTimeFrame->getTracklets()[iLayer];
287+
auto& labels = mTimeFrame->getTrackletsLabel(iLayer);
288+
labels.clear();
289+
labels.reserve(mTimeFrame->getTracklets()[iLayer].size());
290+
mTaskArena->execute([&]() {
291+
tbb::parallel_for(
292+
tbb::blocked_range<size_t>(0, tracklets.size()),
293+
[&](const tbb::blocked_range<size_t>& Tracklets) {
294+
for (size_t idx = Tracklets.begin(); idx != Tracklets.end(); ++idx) {
295+
const auto& trk = tracklets[idx];
296+
o2::MCCompLabel label;
297+
if (!trk.isEmpty()) {
298+
const int sortedId0{mTimeFrame->getSortedIndex(trk.rof[0], iLayer, trk.firstClusterIndex)};
299+
const int sortedId1{mTimeFrame->getSortedIndex(trk.rof[1], iLayer + 1, trk.secondClusterIndex)};
300+
const auto& lbl0 = mTimeFrame->getClusterLabels(iLayer, mTimeFrame->getClusters()[iLayer][sortedId0].clusterId)[0];
301+
const auto& lbl1 = mTimeFrame->getClusterLabels(iLayer + 1, mTimeFrame->getClusters()[iLayer + 1][sortedId1].clusterId)[0];
302+
if (lbl0 == lbl1) {
303+
// both clusters of the tracklet are from the same particle, fake or unset
304+
label = lbl0;
305+
} else if (lbl0.getSourceID() == lbl1.getSourceID() && lbl0.getEventID() == lbl1.getEventID()) {
306+
// both clusters come at least from the same source and event
307+
label = o2::MCCompLabel(o2::MCCompLabel::maxTrackID(), lbl0.getEventID(), lbl0.getSourceID(), true);
308+
}
309+
// otherwise we leave it unset
310+
}
311+
labels[idx] = label;
283312
}
284-
}
285-
if (label.isValid()) {
286-
break;
287-
}
288-
}
289-
}
290-
mTimeFrame->getTrackletsLabel(0).emplace_back(label);
313+
});
314+
});
291315
}
292316
}
293317

@@ -346,7 +370,7 @@ void VertexerTraits::computeTrackletMatching(const int iteration)
346370
continue;
347371
}
348372
mTimeFrame->getLines(pivotRofId).reserve(mTimeFrame->getNTrackletsCluster(pivotRofId, 0).size());
349-
bounded_vector<uint8_t> usedTracklets(mTimeFrame->getFoundTracklets(pivotRofId, 0).size(), false, mMemoryPool.get());
373+
bounded_vector<bool> usedTracklets01(mTimeFrame->getFoundTracklets(pivotRofId, 0).size(), false, mMemoryPool.get());
350374
short startROF{std::max((short)0, static_cast<short>(pivotRofId - mVrtParams[iteration].deltaRof))};
351375
short endROF{std::min(static_cast<short>(mTimeFrame->getNrof()), static_cast<short>(pivotRofId + mVrtParams[iteration].deltaRof + 1))};
352376
for (short targetRofId = startROF; targetRofId < endROF; ++targetRofId) {
@@ -357,11 +381,12 @@ void VertexerTraits::computeTrackletMatching(const int iteration)
357381
mTimeFrame->getUsedClustersROF(targetRofId, 2),
358382
mTimeFrame->getFoundTracklets(pivotRofId, 0),
359383
mTimeFrame->getFoundTracklets(pivotRofId, 1),
360-
usedTracklets,
384+
usedTracklets01,
361385
mTimeFrame->getNTrackletsCluster(pivotRofId, 0),
362386
mTimeFrame->getNTrackletsCluster(pivotRofId, 1),
363387
mTimeFrame->getLines(pivotRofId),
364388
mTimeFrame->getLabelsFoundTracklets(pivotRofId, 0),
389+
mTimeFrame->getLabelsFoundTracklets(pivotRofId, 1),
365390
mTimeFrame->getLinesLabel(pivotRofId),
366391
pivotRofId,
367392
targetRofId,

0 commit comments

Comments
 (0)