2525#include " ITStracking/TrackingConfigParam.h"
2626
2727#include < iostream>
28+ #include < numeric>
2829
2930namespace
3031{
@@ -226,34 +227,34 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
226227template <int nLayers>
227228void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, const int maxLayers)
228229{
230+ const int numBins{trkParam.PhiBins * trkParam.ZBins };
231+ const int stride{numBins + 1 };
229232 bounded_vector<ClusterHelper> cHelper (mMemoryPool .get ());
230- bounded_vector<int > clsPerBin (trkParam.PhiBins * trkParam.ZBins , 0 , mMemoryPool .get ());
233+ bounded_vector<int > clsPerBin (numBins, 0 , mMemoryPool .get ());
234+ bounded_vector<int > lutPerBin (numBins, 0 , mMemoryPool .get ());
231235 for (int rof{0 }; rof < mNrof ; ++rof) {
232236 if ((int )mMultiplicityCutMask .size () == mNrof && !mMultiplicityCutMask [rof]) {
233237 continue ;
234238 }
235- for (int iLayer{0 }; iLayer < std::min (trkParam.NLayers , maxLayers); ++iLayer) {
236- std::fill (clsPerBin.begin (), clsPerBin.end (), 0 );
237- const auto unsortedClusters{getUnsortedClustersOnLayer (rof, iLayer)};
239+ for (int iLayer{0 }, stopLayer = std::min (trkParam.NLayers , maxLayers); iLayer < stopLayer; ++iLayer) {
240+ const auto & unsortedClusters{getUnsortedClustersOnLayer (rof, iLayer)};
238241 const int clustersNum{static_cast <int >(unsortedClusters.size ())};
242+ auto * tableBase = mIndexTables [iLayer].data () + rof * stride;
239243
240- deepVectorClear (cHelper);
241244 cHelper.resize (clustersNum);
242245
243246 for (int iCluster{0 }; iCluster < clustersNum; ++iCluster) {
244-
245247 const Cluster& c = unsortedClusters[iCluster];
246248 ClusterHelper& h = cHelper[iCluster];
247- float x = c.xCoordinate - mBeamPos [0 ];
248- float y = c.yCoordinate - mBeamPos [1 ];
249- const float & z = c.zCoordinate ;
249+
250+ const float x = c.xCoordinate - mBeamPos [0 ];
251+ const float y = c.yCoordinate - mBeamPos [1 ];
252+ const float z = c.zCoordinate ;
253+
250254 float phi = math_utils::computePhi (x, y);
251255 int zBin{mIndexTableUtils .getZBinIndex (iLayer, z)};
252- if (zBin < 0 ) {
253- zBin = 0 ;
254- mBogusClusters [iLayer]++;
255- } else if (zBin >= trkParam.ZBins ) {
256- zBin = trkParam.ZBins - 1 ;
256+ if (zBin < 0 || zBin >= trkParam.ZBins ) {
257+ zBin = std::clamp (zBin, 0 , trkParam.ZBins - 1 );
257258 mBogusClusters [iLayer]++;
258259 }
259260 int bin = mIndexTableUtils .getBinIndex (zBin, mIndexTableUtils .getPhiBinIndex (phi));
@@ -264,28 +265,23 @@ void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, con
264265 h.bin = bin;
265266 h.ind = clsPerBin[bin]++;
266267 }
267- bounded_vector<int > lutPerBin (clsPerBin.size (), 0 , mMemoryPool .get ());
268- lutPerBin[0 ] = 0 ;
269- for (unsigned int iB{1 }; iB < lutPerBin.size (); ++iB) {
270- lutPerBin[iB] = lutPerBin[iB - 1 ] + clsPerBin[iB - 1 ];
271- }
268+ std::exclusive_scan (clsPerBin.begin (), clsPerBin.end (), lutPerBin.begin (), 0 );
272269
273270 auto clusters2beSorted{getClustersOnLayer (rof, iLayer)};
274271 for (int iCluster{0 }; iCluster < clustersNum; ++iCluster) {
275272 const ClusterHelper& h = cHelper[iCluster];
276-
277273 Cluster& c = clusters2beSorted[lutPerBin[h.bin ] + h.ind ];
274+
278275 c = unsortedClusters[iCluster];
279276 c.phi = h.phi ;
280277 c.radius = h.r ;
281278 c.indexTableBinIndex = h.bin ;
282279 }
283- for (int iB{0 }; iB < (int )clsPerBin.size (); ++iB) {
284- mIndexTables [iLayer][rof * (trkParam.ZBins * trkParam.PhiBins + 1 ) + iB] = lutPerBin[iB];
285- }
286- for (auto iB{clsPerBin.size ()}; iB < (trkParam.ZBins * trkParam.PhiBins + 1 ); iB++) {
287- mIndexTables [iLayer][rof * (trkParam.ZBins * trkParam.PhiBins + 1 ) + iB] = clustersNum;
288- }
280+ std::copy_n (lutPerBin.data (), clsPerBin.size (), tableBase);
281+ std::fill_n (tableBase + clsPerBin.size (), stride - clsPerBin.size (), clustersNum);
282+
283+ std::fill (clsPerBin.begin (), clsPerBin.end (), 0 );
284+ cHelper.clear ();
289285 }
290286 }
291287}
0 commit comments