@@ -99,15 +99,16 @@ void trackleterKernelHost(
9999void 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