Skip to content

Commit 820462b

Browse files
committed
ITS: rework prepareClusters
1 parent 9162647 commit 820462b

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "ITStracking/TrackingConfigParam.h"
2626

2727
#include <iostream>
28+
#include <numeric>
2829

2930
namespace
3031
{
@@ -214,34 +215,34 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
214215
template <int nLayers>
215216
void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, const int maxLayers)
216217
{
218+
const int numBins{trkParam.PhiBins * trkParam.ZBins};
219+
const int stride{numBins + 1};
217220
bounded_vector<ClusterHelper> cHelper(mMemoryPool.get());
218-
bounded_vector<int> clsPerBin(trkParam.PhiBins * trkParam.ZBins, 0, mMemoryPool.get());
221+
bounded_vector<int> clsPerBin(numBins, 0, mMemoryPool.get());
222+
bounded_vector<int> lutPerBin(numBins, 0, mMemoryPool.get());
219223
for (int rof{0}; rof < mNrof; ++rof) {
220224
if ((int)mMultiplicityCutMask.size() == mNrof && !mMultiplicityCutMask[rof]) {
221225
continue;
222226
}
223-
for (int iLayer{0}; iLayer < std::min(trkParam.NLayers, maxLayers); ++iLayer) {
224-
std::fill(clsPerBin.begin(), clsPerBin.end(), 0);
225-
const auto unsortedClusters{getUnsortedClustersOnLayer(rof, iLayer)};
227+
for (int iLayer{0}, stopLayer = std::min(trkParam.NLayers, maxLayers); iLayer < stopLayer; ++iLayer) {
228+
const auto& unsortedClusters{getUnsortedClustersOnLayer(rof, iLayer)};
226229
const int clustersNum{static_cast<int>(unsortedClusters.size())};
230+
auto* tableBase = mIndexTables[iLayer].data() + rof * stride;
227231

228-
deepVectorClear(cHelper);
229232
cHelper.resize(clustersNum);
230233

231234
for (int iCluster{0}; iCluster < clustersNum; ++iCluster) {
232-
233235
const Cluster& c = unsortedClusters[iCluster];
234236
ClusterHelper& h = cHelper[iCluster];
235-
float x = c.xCoordinate - mBeamPos[0];
236-
float y = c.yCoordinate - mBeamPos[1];
237-
const float& z = c.zCoordinate;
237+
238+
const float x = c.xCoordinate - mBeamPos[0];
239+
const float y = c.yCoordinate - mBeamPos[1];
240+
const float z = c.zCoordinate;
241+
238242
float phi = math_utils::computePhi(x, y);
239243
int zBin{mIndexTableUtils.getZBinIndex(iLayer, z)};
240-
if (zBin < 0) {
241-
zBin = 0;
242-
mBogusClusters[iLayer]++;
243-
} else if (zBin >= trkParam.ZBins) {
244-
zBin = trkParam.ZBins - 1;
244+
if (zBin < 0 || zBin >= trkParam.ZBins) {
245+
zBin = std::clamp(zBin, 0, trkParam.ZBins - 1);
245246
mBogusClusters[iLayer]++;
246247
}
247248
int bin = mIndexTableUtils.getBinIndex(zBin, mIndexTableUtils.getPhiBinIndex(phi));
@@ -252,28 +253,23 @@ void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, con
252253
h.bin = bin;
253254
h.ind = clsPerBin[bin]++;
254255
}
255-
bounded_vector<int> lutPerBin(clsPerBin.size(), 0, mMemoryPool.get());
256-
lutPerBin[0] = 0;
257-
for (unsigned int iB{1}; iB < lutPerBin.size(); ++iB) {
258-
lutPerBin[iB] = lutPerBin[iB - 1] + clsPerBin[iB - 1];
259-
}
256+
std::exclusive_scan(clsPerBin.begin(), clsPerBin.end(), lutPerBin.begin(), 0);
260257

261258
auto clusters2beSorted{getClustersOnLayer(rof, iLayer)};
262259
for (int iCluster{0}; iCluster < clustersNum; ++iCluster) {
263260
const ClusterHelper& h = cHelper[iCluster];
264-
265261
Cluster& c = clusters2beSorted[lutPerBin[h.bin] + h.ind];
262+
266263
c = unsortedClusters[iCluster];
267264
c.phi = h.phi;
268265
c.radius = h.r;
269266
c.indexTableBinIndex = h.bin;
270267
}
271-
for (int iB{0}; iB < (int)clsPerBin.size(); ++iB) {
272-
mIndexTables[iLayer][rof * (trkParam.ZBins * trkParam.PhiBins + 1) + iB] = lutPerBin[iB];
273-
}
274-
for (auto iB{clsPerBin.size()}; iB < (trkParam.ZBins * trkParam.PhiBins + 1); iB++) {
275-
mIndexTables[iLayer][rof * (trkParam.ZBins * trkParam.PhiBins + 1) + iB] = clustersNum;
276-
}
268+
std::copy_n(lutPerBin.data(), clsPerBin.size(), tableBase);
269+
std::fill_n(tableBase + clsPerBin.size(), stride - clsPerBin.size(), clustersNum);
270+
271+
std::fill(clsPerBin.begin(), clsPerBin.end(), 0);
272+
cHelper.clear();
277273
}
278274
}
279275
}

0 commit comments

Comments
 (0)