Skip to content

Commit a201ecd

Browse files
committed
ITS: clear tracklets after cell finding
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 08f8150 commit a201ecd

1 file changed

Lines changed: 47 additions & 25 deletions

File tree

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

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <algorithm>
1717
#include <iterator>
1818
#include <ranges>
19+
#include <cmath>
1920
#include <type_traits>
2021

2122
#include <oneapi/tbb/blocked_range.h>
@@ -33,8 +34,6 @@
3334
#include "ITStracking/Tracklet.h"
3435
#include "ReconstructionDataFormats/Track.h"
3536

36-
using o2::base::PropagatorF;
37-
3837
namespace o2::its
3938
{
4039

@@ -207,7 +206,7 @@ void TrackerTraits<NLayers>::computeLayerTracklets(const int iteration, int iVer
207206
tbb::parallel_for(0, mTrkParams[iteration].TrackletsPerRoad(), [&](const int iLayer) {
208207
/// Sort tracklets
209208
auto& trkl{mTimeFrame->getTracklets()[iLayer]};
210-
tbb::parallel_sort(trkl.begin(), trkl.end(), [](const Tracklet& a, const Tracklet& b) -> bool {
209+
std::sort(trkl.begin(), trkl.end(), [](const Tracklet& a, const Tracklet& b) -> bool {
211210
if (a.firstClusterIndex != b.firstClusterIndex) {
212211
return a.firstClusterIndex < b.firstClusterIndex;
213212
}
@@ -346,10 +345,14 @@ void TrackerTraits<NLayers>::computeLayerCells(const int iteration)
346345
return foundCells;
347346
};
348347

349-
tbb::parallel_for(0, mTrkParams[iteration].CellsPerRoad(), [&](const int iLayer) {
348+
for (int iLayer = 0; iLayer < mTrkParams[iteration].CellsPerRoad(); ++iLayer) {
350349
if (mTimeFrame->getTracklets()[iLayer + 1].empty() ||
351350
mTimeFrame->getTracklets()[iLayer].empty()) {
352-
return;
351+
if (iLayer < mTrkParams[iteration].TrackletsPerRoad()) {
352+
deepVectorClear(mTimeFrame->getTracklets()[iLayer]);
353+
deepVectorClear(mTimeFrame->getTrackletsLabel(iLayer));
354+
}
355+
continue;
353356
}
354357

355358
auto& layerCells = mTimeFrame->getCells()[iLayer];
@@ -368,7 +371,14 @@ void TrackerTraits<NLayers>::computeLayerCells(const int iteration)
368371
std::exclusive_scan(perTrackletCount.begin(), perTrackletCount.end(), perTrackletCount.begin(), 0);
369372
auto totalCells{perTrackletCount.back()};
370373
if (totalCells == 0) {
371-
return;
374+
if (iLayer > 0) {
375+
auto& lut = mTimeFrame->getCellsLookupTable()[iLayer - 1];
376+
lut.resize(currentLayerTrackletsNum + 1);
377+
std::fill(lut.begin(), lut.end(), 0);
378+
}
379+
deepVectorClear(mTimeFrame->getTracklets()[iLayer]);
380+
deepVectorClear(mTimeFrame->getTrackletsLabel(iLayer));
381+
continue;
372382
}
373383
layerCells.resize(totalCells);
374384

@@ -386,20 +396,28 @@ void TrackerTraits<NLayers>::computeLayerCells(const int iteration)
386396
lut.resize(currentLayerTrackletsNum + 1);
387397
std::copy_n(perTrackletCount.begin(), currentLayerTrackletsNum + 1, lut.begin());
388398
}
389-
});
390399

391-
/// Create cells labels
392-
if (mTimeFrame->hasMCinformation() && mTrkParams[iteration].createArtefactLabels) {
393-
tbb::parallel_for(0, mTrkParams[iteration].CellsPerRoad(), [&](const int iLayer) {
394-
mTimeFrame->getCellsLabel(iLayer).reserve(mTimeFrame->getCells()[iLayer].size());
395-
for (const auto& cell : mTimeFrame->getCells()[iLayer]) {
400+
if (mTimeFrame->hasMCinformation() && mTrkParams[iteration].createArtefactLabels) {
401+
auto& labels = mTimeFrame->getCellsLabel(iLayer);
402+
labels.reserve(layerCells.size());
403+
for (const auto& cell : layerCells) {
396404
MCCompLabel currentLab{mTimeFrame->getTrackletsLabel(iLayer)[cell.getFirstTrackletIndex()]};
397405
MCCompLabel nextLab{mTimeFrame->getTrackletsLabel(iLayer + 1)[cell.getSecondTrackletIndex()]};
398-
mTimeFrame->getCellsLabel(iLayer).emplace_back(currentLab == nextLab ? currentLab : MCCompLabel());
406+
labels.emplace_back(currentLab == nextLab ? currentLab : MCCompLabel());
399407
}
400-
});
408+
}
409+
410+
// Once layer i cells are built and labelled, the corresponding tracklet artefacts are no longer needed.
411+
deepVectorClear(mTimeFrame->getTracklets()[iLayer]);
412+
deepVectorClear(mTimeFrame->getTrackletsLabel(iLayer));
401413
}
402414
});
415+
416+
// Clear the trailing tracklet artefacts that are not consumed as the first leg of a cell.
417+
for (int iLayer = mTrkParams[iteration].CellsPerRoad(); iLayer < mTrkParams[iteration].TrackletsPerRoad(); ++iLayer) {
418+
deepVectorClear(mTimeFrame->getTracklets()[iLayer]);
419+
deepVectorClear(mTimeFrame->getTrackletsLabel(iLayer));
420+
}
403421
}
404422

405423
template <int NLayers>
@@ -509,6 +527,9 @@ void TrackerTraits<NLayers>::findCellsNeighbours(const int iteration)
509527
}
510528
mTimeFrame->getCells()[iLayer + 1][cellIdx].setLevel(maxLvl);
511529
}
530+
531+
// clear cells LUT
532+
deepVectorClear(mTimeFrame->getCellsLookupTable()[iLayer]);
512533
}
513534
});
514535
}
@@ -752,11 +773,13 @@ void TrackerTraits<NLayers>::findRoads(const int iteration)
752773
}
753774

754775
deepVectorClear(trackSeeds);
755-
tbb::parallel_sort(tracks.begin(), tracks.end(), [](const auto& a, const auto& b) {
756-
return a.getChi2() < b.getChi2();
757-
});
758776
});
759777

778+
std::sort(tracks.begin(), tracks.end(), [](const auto& a, const auto& b) {
779+
return a.getChi2() < b.getChi2();
780+
});
781+
782+
mTimeFrame->getTracks().reserve(mTimeFrame->getTracks().size() + tracks.size());
760783
const float smallestROFHalf = mTimeFrame->getROFOverlapTableView().getClockLayer().mROFLength * 0.5f;
761784
for (auto& track : tracks) {
762785
int nShared = 0;
@@ -803,7 +826,6 @@ void TrackerTraits<NLayers>::findRoads(const int iteration)
803826
if (track.getTimeStamp().getTimeStampError() > smallestROFHalf) {
804827
track.getTimeStamp().setTimeStampError(smallestROFHalf);
805828
}
806-
807829
track.setUserField(0);
808830
track.getParamOut().setUserField(0);
809831
mTimeFrame->getTracks().emplace_back(track);
@@ -885,7 +907,7 @@ bool TrackerTraits<NLayers>::fitTrack(TrackITSExt& track, int start, int end, in
885907
}
886908
nCl++;
887909
}
888-
return std::abs(track.getQ2Pt()) < maxQoverPt && track.getChi2() < chi2ndfcut * (nCl * 2 - 5);
910+
return std::abs(track.getQ2Pt()) < maxQoverPt && track.getChi2() < chi2ndfcut * (float)((nCl * 2) - 5);
889911
}
890912

891913
// create a new seed either from the existing track inner param or reseed from the edgepointd and cluster in the middle
@@ -936,17 +958,17 @@ track::TrackParCov TrackerTraits<NLayers>::buildTrackSeed(const Cluster& cluster
936958
{
937959
const float sign = reverse ? -1.f : 1.f;
938960

939-
float ca, sa;
961+
float ca = NAN, sa = NAN;
940962
o2::gpu::CAMath::SinCos(tf3.alphaTrackingFrame, sa, ca);
941963

942-
const float x1 = cluster1.xCoordinate * ca + cluster1.yCoordinate * sa;
943-
const float y1 = -cluster1.xCoordinate * sa + cluster1.yCoordinate * ca;
944-
const float x2 = cluster2.xCoordinate * ca + cluster2.yCoordinate * sa;
945-
const float y2 = -cluster2.xCoordinate * sa + cluster2.yCoordinate * ca;
964+
const float x1 = (cluster1.xCoordinate * ca) + (cluster1.yCoordinate * sa);
965+
const float y1 = (-cluster1.xCoordinate * sa) + (cluster1.yCoordinate * ca);
966+
const float x2 = (cluster2.xCoordinate * ca) + (cluster2.yCoordinate * sa);
967+
const float y2 = (-cluster2.xCoordinate * sa) + (cluster2.yCoordinate * ca);
946968
const float x3 = tf3.xTrackingFrame;
947969
const float y3 = tf3.positionTrackingFrame[0];
948970

949-
float snp, q2pt, q2pt2;
971+
float snp = NAN, q2pt = NAN, q2pt2 = NAN;
950972
if (mIsZeroField) {
951973
const float dx = x3 - x1;
952974
const float dy = y3 - y1;

0 commit comments

Comments
 (0)