2525#include " ITStracking/TrackingConfigParam.h"
2626
2727#include < iostream>
28+ #include < numeric>
2829
2930namespace
3031{
@@ -214,34 +215,34 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
214215template <int nLayers>
215216void 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 ());
219- const int stride = trkParam. ZBins * trkParam. PhiBins + 1 ;
221+ bounded_vector<int > clsPerBin (numBins , 0 , mMemoryPool .get ());
222+ bounded_vector< int > lutPerBin (numBins, 0 , mMemoryPool . get ()) ;
220223 for (int rof{0 }; rof < mNrof ; ++rof) {
221224 if ((int )mMultiplicityCutMask .size () == mNrof && !mMultiplicityCutMask [rof]) {
222225 continue ;
223226 }
224- for (int iLayer{0 }; iLayer < std::min (trkParam.NLayers , maxLayers); ++iLayer) {
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 ())};
227230 auto * tableBase = mIndexTables [iLayer].data () + rof * stride;
228231
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,17 +253,13 @@ 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 ;
@@ -272,7 +269,7 @@ void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, con
272269 std::fill_n (tableBase + clsPerBin.size (), stride - clsPerBin.size (), clustersNum);
273270
274271 std::fill (clsPerBin.begin (), clsPerBin.end (), 0 );
275- deepVectorClear ( cHelper);
272+ cHelper. clear ( );
276273 }
277274 }
278275}
0 commit comments