Skip to content

Commit e1b5576

Browse files
committed
ITS: speedup line selection
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent ba0d932 commit e1b5576

6 files changed

Lines changed: 43 additions & 37 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ class SeedBase : public o2::track::TrackParCovF
6464
};
6565

6666
/// CellSeed: connections of three clusters
67-
class CellSeed final : public SeedBase<3>
67+
class CellSeed final : public SeedBase<constants::ClustersPerCell>
6868
{
69-
static constexpr int NStoredClusters = 3;
70-
using Base = SeedBase<NStoredClusters>;
69+
using Base = SeedBase<constants::ClustersPerCell>;
7170

7271
public:
7372
GPUhdDefault() CellSeed() = default;
@@ -98,7 +97,7 @@ class CellSeed final : public SeedBase<3>
9897
GPUhd() int getCluster(int layer) const
9998
{
10099
const int rel = layer - getInnerLayer();
101-
return (rel >= 0 && rel < NStoredClusters) ? this->clustersRaw()[rel] : constants::UnusedIndex;
100+
return (rel >= 0 && rel < constants::ClustersPerCell) ? this->clustersRaw()[rel] : constants::UnusedIndex;
102101
}
103102
};
104103

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include <array>
2020
#include <utility>
2121

22-
#include "GPUCommonDef.h"
23-
#include "GPUCommonDefAPI.h"
24-
2522
namespace o2::its::constants
2623
{
2724

@@ -30,12 +27,13 @@ constexpr float MB = KB * KB;
3027
constexpr float GB = MB * KB;
3128
constexpr bool DoTimeBenchmarks = true;
3229
constexpr bool SaveTimeBenchmarks = false;
33-
constexpr float Tolerance = 1e-12; // numerical tolerance
34-
constexpr int ClustersPerCell = 3;
35-
constexpr int UnusedIndex = -1;
36-
constexpr float Radl = 9.36f; // Radiation length of Si [cm]
37-
constexpr float Rho = 2.33f; // Density of Si [g/cm^3]
38-
constexpr int MaxIter = 4; // Max. supported iterations
30+
constexpr float Tolerance = 1e-12; // numerical tolerance
31+
constexpr int ClustersPerCell = 3; // number of clusters for a cell
32+
constexpr int UnusedIndex = -1; // global unused flag
33+
constexpr float Radl = 9.36f; // Radiation length of Si [cm]
34+
constexpr float Rho = 2.33f; // Density of Si [g/cm^3]
35+
constexpr int MaxIter = 4; // Max. supported iterations
36+
constexpr int MaxSelectedTrackletsPerCluster = 100; // vertexer: max lines per cluster
3937

4038
namespace helpers
4139
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ GPUhdi() float smallestAngleDifference(float a, float b)
8989
return o2::gpu::CAMath::Remainderf(b - a, o2::constants::math::TwoPI);
9090
}
9191

92+
GPUhdi() bool isPhiDifferenceBelow(const float phiA, const float phiB, const float phiCut)
93+
{
94+
const float deltaPhi = o2::gpu::CAMath::Abs(phiA - phiB);
95+
return deltaPhi < phiCut || deltaPhi > o2::constants::math::TwoPI - phiCut;
96+
}
97+
9298
GPUhdi() constexpr float Sq(float v)
9399
{
94100
return v * v;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
#include "ITStracking/Cell.h"
2727
#include "ITStracking/Cluster.h"
2828
#include "ITStracking/Configuration.h"
29-
#include "ITStracking/Constants.h"
3029
#include "ITStracking/ClusterLines.h"
31-
#include "ITStracking/Definitions.h"
3230
#include "ITStracking/Tracklet.h"
3331
#include "ITStracking/IndexTableUtils.h"
3432
#include "ITStracking/ExternalAllocator.h"
@@ -103,7 +101,7 @@ struct TimeFrame {
103101
void setBeamPosition(const float x, const float y, const float s2, const float base = 50.f, const float systematic = 0.f)
104102
{
105103
isBeamPositionOverridden = true;
106-
resetBeamXY(x, y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
104+
resetBeamXY(x, y, s2 / o2::gpu::CAMath::Sqrt((base * base) + systematic));
107105
}
108106

109107
float getBeamX() const { return mBeamPos[0]; }
@@ -249,7 +247,7 @@ struct TimeFrame {
249247

250248
// Propagator
251249
const o2::base::PropagatorImpl<float>* getDevicePropagator() const { return mPropagatorDevice; }
252-
virtual void setDevicePropagator(const o2::base::PropagatorImpl<float>*) {};
250+
virtual void setDevicePropagator(const o2::base::PropagatorImpl<float>* /*unused*/) {};
253251

254252
template <typename... T>
255253
void addClusterToLayer(int layer, T&&... args);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ void TrackerTraits<NLayers>::computeLayerTracklets(const int iteration, int iVer
150150
if (mTimeFrame->isClusterUsed(iLayer + 1, nextCluster.clusterId)) {
151151
continue;
152152
}
153-
const float deltaPhi = o2::gpu::CAMath::Abs(o2::math_utils::toPMPi(currentCluster.phi - nextCluster.phi));
154153
const float deltaZ = o2::gpu::CAMath::Abs((tanLambda * (nextCluster.radius - currentCluster.radius)) + currentCluster.zCoordinate - nextCluster.zCoordinate);
155154

156155
if (deltaZ / sigmaZ < mTrkParams[iteration].NSigmaCut &&
157-
((deltaPhi < mTimeFrame->getPhiCut(iLayer) || o2::gpu::GPUCommonMath::Abs(deltaPhi - o2::constants::math::TwoPI) < mTimeFrame->getPhiCut(iLayer)))) {
156+
math_utils::isPhiDifferenceBelow(currentCluster.phi, nextCluster.phi, mTimeFrame->getPhiCut(iLayer))) {
158157
const float phi{o2::gpu::CAMath::ATan2(currentCluster.yCoordinate - nextCluster.yCoordinate, currentCluster.xCoordinate - nextCluster.xCoordinate)};
159158
const float tanL = (currentCluster.zCoordinate - nextCluster.zCoordinate) / (currentCluster.radius - nextCluster.radius);
160159
if constexpr (decltype(Tag)::value == PassMode::OnePass::value) {

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace o2::its
3636
{
3737
namespace
3838
{
39+
3940
template <TrackletMode Mode, bool EvalRun, int NLayers>
4041
void trackleterKernelHost(
4142
const gsl::span<const Cluster>& clustersNextLayer, // 0 2
@@ -48,9 +49,9 @@ void trackleterKernelHost(
4849
const IndexTableUtils<NLayers>& utils,
4950
const TimeEstBC& timErr,
5051
gsl::span<int> rofFoundTrackletsOffsets,
51-
const int globalOffsetNextLayer = 0,
52-
const int globalOffsetCurrentLayer = 0,
53-
const int maxTrackletsPerCluster = static_cast<int>(2e3))
52+
const int globalOffsetNextLayer,
53+
const int globalOffsetCurrentLayer,
54+
const int maxTrackletsPerCluster)
5455
{
5556
const int PhiBins{utils.getNphiBins()};
5657
const int ZBins{utils.getNzBins()};
@@ -65,17 +66,17 @@ void trackleterKernelHost(
6566
phiBinsNum += PhiBins;
6667
}
6768
// loop on phi bins next layer
68-
for (int iPhiBin{selectedBinsRect.y}, iPhiCount{0}; iPhiCount < phiBinsNum; iPhiBin = ++iPhiBin == PhiBins ? 0 : iPhiBin, iPhiCount++) {
69+
for (int iPhiBin{selectedBinsRect.y}, iPhiCount{0}; iPhiCount < phiBinsNum && storedTracklets < maxTrackletsPerCluster; iPhiBin = ++iPhiBin == PhiBins ? 0 : iPhiBin, iPhiCount++) {
6970
const int firstBinIndex{utils.getBinIndex(selectedBinsRect.x, iPhiBin)};
7071
const int firstRowClusterIndex{indexTableNext[firstBinIndex]};
7172
const int maxRowClusterIndex{indexTableNext[firstBinIndex + ZBins]};
7273
// loop on clusters next layer
73-
for (int iNextLayerClusterIndex{firstRowClusterIndex}; iNextLayerClusterIndex < maxRowClusterIndex && iNextLayerClusterIndex < static_cast<int>(clustersNextLayer.size()); ++iNextLayerClusterIndex) {
74+
for (int iNextLayerClusterIndex{firstRowClusterIndex}; iNextLayerClusterIndex < maxRowClusterIndex && iNextLayerClusterIndex < static_cast<int>(clustersNextLayer.size()) && storedTracklets < maxTrackletsPerCluster; ++iNextLayerClusterIndex) {
7475
if (usedClustersNextLayer[iNextLayerClusterIndex]) {
7576
continue;
7677
}
7778
const Cluster& nextCluster{clustersNextLayer[iNextLayerClusterIndex]};
78-
if (o2::gpu::GPUCommonMath::Abs(math_utils::smallestAngleDifference(currentCluster.phi, nextCluster.phi)) < phiCut) {
79+
if (math_utils::isPhiDifferenceBelow(currentCluster.phi, nextCluster.phi, phiCut)) {
7980
if (storedTracklets < maxTrackletsPerCluster) {
8081
if constexpr (!EvalRun) {
8182
if constexpr (Mode == TrackletMode::Layer0Layer1) {
@@ -105,35 +106,39 @@ void trackletSelectionKernelHost(
105106
gsl::span<unsigned char> usedClusters2, // global layer 2 used clusters
106107
const gsl::span<const Tracklet>& tracklets01,
107108
const gsl::span<const Tracklet>& tracklets12,
108-
bounded_vector<bool>& usedTracklets,
109+
bounded_vector<uint8_t>& usedTracklets,
109110
const gsl::span<int> foundTracklets01,
110111
const gsl::span<int> foundTracklets12,
111112
bounded_vector<Line>& lines,
112113
const gsl::span<const o2::MCCompLabel>& trackletLabels,
113114
bounded_vector<o2::MCCompLabel>& linesLabels,
114115
const int nLayer1Clusters,
115-
const float tanLambdaCut = 0.025f,
116-
const float phiCut = 0.005f,
117-
const int maxTracklets = 100)
116+
const float tanLambdaCut,
117+
const float phiCut,
118+
const int maxTracklets)
118119
{
119120
int offset01{0}, offset12{0};
120121
for (int iCurrentLayerClusterIndex{0}; iCurrentLayerClusterIndex < nLayer1Clusters; ++iCurrentLayerClusterIndex) {
121122
int validTracklets{0};
122-
for (int iTracklet12{offset12}; iTracklet12 < offset12 + foundTracklets12[iCurrentLayerClusterIndex]; ++iTracklet12) {
123-
for (int iTracklet01{offset01}; iTracklet01 < offset01 + foundTracklets01[iCurrentLayerClusterIndex]; ++iTracklet01) {
123+
const int endTracklet01 = offset01 + foundTracklets01[iCurrentLayerClusterIndex];
124+
const int endTracklet12 = offset12 + foundTracklets12[iCurrentLayerClusterIndex];
125+
for (int iTracklet12{offset12}; iTracklet12 < endTracklet12 && validTracklets != maxTracklets; ++iTracklet12) {
126+
const auto& tracklet12{tracklets12[iTracklet12]};
127+
for (int iTracklet01{offset01}; iTracklet01 < endTracklet01 && validTracklets != maxTracklets; ++iTracklet01) {
124128
if (usedTracklets[iTracklet01]) {
125129
continue;
126130
}
127131

128132
const auto& tracklet01{tracklets01[iTracklet01]};
129-
const auto& tracklet12{tracklets12[iTracklet12]};
130133
if (!tracklet01.getTimeStamp().isCompatible(tracklet12.getTimeStamp())) {
131134
continue;
132135
}
133136

134137
const float deltaTanLambda{o2::gpu::GPUCommonMath::Abs(tracklet01.tanLambda - tracklet12.tanLambda)};
135-
const float deltaPhi{o2::gpu::GPUCommonMath::Abs(math_utils::smallestAngleDifference(tracklet01.phi, tracklet12.phi))};
136-
if (deltaTanLambda < tanLambdaCut && deltaPhi < phiCut && validTracklets != maxTracklets) {
138+
if (deltaTanLambda >= tanLambdaCut) {
139+
continue;
140+
}
141+
if (math_utils::isPhiDifferenceBelow(tracklet01.phi, tracklet12.phi, phiCut) && validTracklets != maxTracklets) {
137142
usedClusters0[tracklet01.firstClusterIndex] = 1;
138143
usedClusters2[tracklet12.secondClusterIndex] = 1;
139144
usedTracklets[iTracklet01] = true;
@@ -296,8 +301,8 @@ void VertexerTraits<NLayers>::computeTrackletMatching(const int iteration)
296301
if (mTimeFrame->getFoundTracklets(pivotRofId, 0).empty() || skipROF(iteration, pivotRofId)) {
297302
continue;
298303
}
299-
mTimeFrame->getLines(pivotRofId).reserve(mTimeFrame->getNTrackletsCluster(pivotRofId, 0).size());
300-
bounded_vector<bool> usedTracklets(mTimeFrame->getFoundTracklets(pivotRofId, 0).size(), false, mMemoryPool.get());
304+
mTimeFrame->getLines(pivotRofId).reserve(std::min(mTimeFrame->getFoundTracklets(pivotRofId, 0).size(), mTimeFrame->getNTrackletsCluster(pivotRofId, 0).size() * constants::MaxSelectedTrackletsPerCluster));
305+
bounded_vector<uint8_t> usedTracklets(mTimeFrame->getFoundTracklets(pivotRofId, 0).size(), 0, mMemoryPool.get());
301306
trackletSelectionKernelHost(
302307
mTimeFrame->getClusters()[0].data(),
303308
mTimeFrame->getClusters()[1].data(),
@@ -313,7 +318,8 @@ void VertexerTraits<NLayers>::computeTrackletMatching(const int iteration)
313318
mTimeFrame->getLinesLabel(pivotRofId),
314319
static_cast<int>(mTimeFrame->getClustersOnLayer(pivotRofId, 1).size()),
315320
mVrtParams[iteration].tanLambdaCut,
316-
mVrtParams[iteration].phiCut);
321+
mVrtParams[iteration].phiCut,
322+
constants::MaxSelectedTrackletsPerCluster);
317323
totalLines.local() += mTimeFrame->getLines(pivotRofId).size();
318324
}
319325
});

0 commit comments

Comments
 (0)