1313// / \brief
1414// /
1515
16+ #include < numeric>
17+ #include < sstream>
18+
19+ #include " Framework/Logger.h"
1620#include " ITStracking/TimeFrame.h"
1721#include " ITStracking/MathUtils.h"
1822#include " DataFormatsITSMFT/Cluster.h"
2428#include " ITStracking/BoundedAllocator.h"
2529#include " ITStracking/TrackingConfigParam.h"
2630
27- #include < iostream>
28-
2931namespace
3032{
3133struct ClusterHelper {
@@ -53,7 +55,7 @@ TimeFrame<nLayers>::TimeFrame()
5355template <int nLayers>
5456TimeFrame<nLayers>::~TimeFrame ()
5557{
56- resetVectors ();
58+ wipe ();
5759}
5860
5961template <int nLayers>
@@ -214,34 +216,34 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
214216template <int nLayers>
215217void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, const int maxLayers)
216218{
219+ const int numBins{trkParam.PhiBins * trkParam.ZBins };
220+ const int stride{numBins + 1 };
217221 bounded_vector<ClusterHelper> cHelper (mMemoryPool .get ());
218- bounded_vector<int > clsPerBin (trkParam.PhiBins * trkParam.ZBins , 0 , mMemoryPool .get ());
222+ bounded_vector<int > clsPerBin (numBins, 0 , mMemoryPool .get ());
223+ bounded_vector<int > lutPerBin (numBins, 0 , mMemoryPool .get ());
219224 for (int rof{0 }; rof < mNrof ; ++rof) {
220225 if ((int )mMultiplicityCutMask .size () == mNrof && !mMultiplicityCutMask [rof]) {
221226 continue ;
222227 }
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)};
228+ for (int iLayer{0 }, stopLayer = std::min (trkParam.NLayers , maxLayers); iLayer < stopLayer; ++iLayer) {
229+ const auto & unsortedClusters{getUnsortedClustersOnLayer (rof, iLayer)};
226230 const int clustersNum{static_cast <int >(unsortedClusters.size ())};
231+ auto * tableBase = mIndexTables [iLayer].data () + rof * stride;
227232
228- deepVectorClear (cHelper);
229233 cHelper.resize (clustersNum);
230234
231235 for (int iCluster{0 }; iCluster < clustersNum; ++iCluster) {
232-
233236 const Cluster& c = unsortedClusters[iCluster];
234237 ClusterHelper& h = cHelper[iCluster];
235- float x = c.xCoordinate - mBeamPos [0 ];
236- float y = c.yCoordinate - mBeamPos [1 ];
237- const float & z = c.zCoordinate ;
238+
239+ const float x = c.xCoordinate - mBeamPos [0 ];
240+ const float y = c.yCoordinate - mBeamPos [1 ];
241+ const float z = c.zCoordinate ;
242+
238243 float phi = math_utils::computePhi (x, y);
239244 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 ;
245+ if (zBin < 0 || zBin >= trkParam.ZBins ) {
246+ zBin = std::clamp (zBin, 0 , trkParam.ZBins - 1 );
245247 mBogusClusters [iLayer]++;
246248 }
247249 int bin = mIndexTableUtils .getBinIndex (zBin, mIndexTableUtils .getPhiBinIndex (phi));
@@ -252,28 +254,23 @@ void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, con
252254 h.bin = bin;
253255 h.ind = clsPerBin[bin]++;
254256 }
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- }
257+ std::exclusive_scan (clsPerBin.begin (), clsPerBin.end (), lutPerBin.begin (), 0 );
260258
261259 auto clusters2beSorted{getClustersOnLayer (rof, iLayer)};
262260 for (int iCluster{0 }; iCluster < clustersNum; ++iCluster) {
263261 const ClusterHelper& h = cHelper[iCluster];
264-
265262 Cluster& c = clusters2beSorted[lutPerBin[h.bin ] + h.ind ];
263+
266264 c = unsortedClusters[iCluster];
267265 c.phi = h.phi ;
268266 c.radius = h.r ;
269267 c.indexTableBinIndex = h.bin ;
270268 }
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- }
269+ std::copy_n (lutPerBin.data (), clsPerBin.size (), tableBase);
270+ std::fill_n (tableBase + clsPerBin.size (), stride - clsPerBin.size (), clustersNum);
271+
272+ std::fill (clsPerBin.begin (), clsPerBin.end (), 0 );
273+ cHelper.clear ();
277274 }
278275 }
279276}
@@ -351,7 +348,7 @@ void TimeFrame<nLayers>::initialise(const int iteration, const TrackingParameter
351348 mPhiCuts .resize (mClusters .size () - 1 , 0 .f );
352349
353350 float oneOverR{0 .001f * 0 .3f * std::abs (mBz ) / trkParam.TrackletMinPt };
354- for (unsigned int iLayer{0 }; iLayer < mClusters . size () ; ++iLayer) {
351+ for (unsigned int iLayer{0 }; iLayer < nLayers ; ++iLayer) {
355352 mMSangles [iLayer] = math_utils::MSangle (0 .14f , trkParam.TrackletMinPt , trkParam.LayerxX0 [iLayer]);
356353 mPositionResolution [iLayer] = o2::gpu::CAMath::Sqrt (0 .5f * (trkParam.SystErrorZ2 [iLayer] + trkParam.SystErrorY2 [iLayer]) + trkParam.LayerResolution [iLayer] * trkParam.LayerResolution [iLayer]);
357354 if (iLayer < mClusters .size () - 1 ) {
@@ -441,14 +438,14 @@ void TimeFrame<nLayers>::checkTrackletLUTs()
441438 auto & trk = getTracklets ()[iLayer][iTracklet];
442439 int currentId{trk.firstClusterIndex };
443440 if (currentId < prev) {
444- std::cout << " First Cluster Index not increasing monotonically on L:T:ID:Prev " << iLayer << " \t " << iTracklet << " \t " << currentId << " \t " << prev << std::endl ;
441+ LOG (info) << " First Cluster Index not increasing monotonically on L:T:ID:Prev " << iLayer << " \t " << iTracklet << " \t " << currentId << " \t " << prev;
445442 } else if (currentId == prev) {
446443 count++;
447444 } else {
448445 if (iLayer > 0 ) {
449446 auto & lut{getTrackletsLookupTable ()[iLayer - 1 ]};
450447 if (count != lut[prev + 1 ] - lut[prev]) {
451- std::cout << " LUT count broken " << iLayer - 1 << " \t " << prev << " \t " << count << " \t " << lut[prev + 1 ] << " \t " << lut[prev] << std::endl ;
448+ LOG (info) << " LUT count broken " << iLayer - 1 << " \t " << prev << " \t " << count << " \t " << lut[prev + 1 ] << " \t " << lut[prev];
452449 }
453450 }
454451 count = 1 ;
@@ -457,7 +454,7 @@ void TimeFrame<nLayers>::checkTrackletLUTs()
457454 if (iLayer > 0 ) {
458455 auto & lut{getTrackletsLookupTable ()[iLayer - 1 ]};
459456 if (iTracklet >= (uint32_t )(lut[currentId + 1 ]) || iTracklet < (uint32_t )(lut[currentId])) {
460- std::cout << " LUT broken: " << iLayer - 1 << " \t " << currentId << " \t " << iTracklet << std::endl ;
457+ LOG (info) << " LUT broken: " << iLayer - 1 << " \t " << currentId << " \t " << iTracklet;
461458 }
462459 }
463460 }
@@ -495,25 +492,25 @@ void TimeFrame<nLayers>::resetTracklets()
495492template <int nLayers>
496493void TimeFrame<nLayers>::printTrackletLUTonLayer(int i)
497494{
498- std::cout << " --------" << std::endl
499- << " Tracklet LUT " << i << std::endl ;
495+ LOG (info) << " -------- Tracklet LUT " << i;
496+ std::stringstream s ;
500497 for (int j : mTrackletsLookupTable [i]) {
501- std::cout << j << " \t " ;
498+ s << j << " \t " ;
502499 }
503- std::cout << " \n -------- " << std::endl
504- << std::endl ;
500+ LOG (info) << s. str ();
501+ LOG (info) << " -------- " ;
505502}
506503
507504template <int nLayers>
508505void TimeFrame<nLayers>::printCellLUTonLayer(int i)
509506{
510- std::cout << " --------" << std::endl
511- << " Cell LUT " << i << std::endl ;
507+ LOG (info) << " -------- Cell LUT " << i;
508+ std::stringstream s ;
512509 for (int j : mCellsLookupTable [i]) {
513- std::cout << j << " \t " ;
510+ s << j << " \t " ;
514511 }
515- std::cout << " \n -------- " << std::endl
516- << std::endl ;
512+ LOG (info) << s. str ();
513+ LOG (info) << " -------- " ;
517514}
518515
519516template <int nLayers>
@@ -535,56 +532,58 @@ void TimeFrame<nLayers>::printCellLUTs()
535532template <int nLayers>
536533void TimeFrame<nLayers>::printVertices()
537534{
538- std::cout << " Vertices in ROF (nROF = " << mNrof << " , lut size = " << mROFramesPV .size () << " )" << std::endl ;
535+ LOG (info) << " Vertices in ROF (nROF = " << mNrof << " , lut size = " << mROFramesPV .size () << " )" ;
539536 for (unsigned int iR{0 }; iR < mROFramesPV .size (); ++iR) {
540- std::cout << mROFramesPV [iR] << " \t " ;
537+ LOG (info) << mROFramesPV [iR] << " \t " ;
541538 }
542- std::cout << " \n\n Vertices:" << std::endl ;
539+ LOG (info) << " \n\n Vertices:" ;
543540 for (unsigned int iV{0 }; iV < mPrimaryVertices .size (); ++iV) {
544- std::cout << mPrimaryVertices [iV].getX () << " \t " << mPrimaryVertices [iV].getY () << " \t " << mPrimaryVertices [iV].getZ () << std::endl ;
541+ LOG (info) << mPrimaryVertices [iV].getX () << " \t " << mPrimaryVertices [iV].getY () << " \t " << mPrimaryVertices [iV].getZ ();
545542 }
546- std::cout << " --------" << std::endl ;
543+ LOG (info) << " --------" ;
547544}
548545
549546template <int nLayers>
550547void TimeFrame<nLayers>::printROFoffsets()
551548{
552- std::cout << " --------" << std::endl ;
549+ LOG (info) << " --------" ;
553550 for (unsigned int iLayer{0 }; iLayer < mROFramesClusters .size (); ++iLayer) {
554- std::cout << " Layer " << iLayer << std::endl;
551+ LOG (info) << " Layer " << iLayer;
552+ std::stringstream s;
555553 for (auto value : mROFramesClusters [iLayer]) {
556- std::cout << value << " \t " ;
554+ s << value << " \t " ;
557555 }
558- std::cout << std::endl ;
556+ LOG (info) << s. str () ;
559557 }
560558}
561559
562560template <int nLayers>
563561void TimeFrame<nLayers>::printNClsPerROF()
564562{
565- std::cout << " --------" << std::endl ;
563+ LOG (info) << " --------" ;
566564 for (unsigned int iLayer{0 }; iLayer < mNClustersPerROF .size (); ++iLayer) {
567- std::cout << " Layer " << iLayer << std::endl;
565+ LOG (info) << " Layer " << iLayer;
566+ std::stringstream s;
568567 for (auto & value : mNClustersPerROF [iLayer]) {
569- std::cout << value << " \t " ;
568+ s << value << " \t " ;
570569 }
571- std::cout << std::endl ;
570+ LOG (info) << s. str () ;
572571 }
573572}
574573
575574template <int nLayers>
576575void TimeFrame<nLayers>::printSliceInfo(const int startROF, const int sliceSize)
577576{
578- std::cout << " Dumping slice of " << sliceSize << " rofs:" << std::endl ;
577+ LOG (info) << " Dumping slice of " << sliceSize << " rofs:" ;
579578 for (int iROF{startROF}; iROF < startROF + sliceSize; ++iROF) {
580- std::cout << " ROF " << iROF << " dump:" << std::endl ;
579+ LOG (info) << " ROF " << iROF << " dump:" ;
581580 for (unsigned int iLayer{0 }; iLayer < mClusters .size (); ++iLayer) {
582- std::cout << " Layer " << iLayer << " has: " << getClustersOnLayer (iROF, iLayer).size () << " clusters." << std::endl ;
581+ LOG (info) << " Layer " << iLayer << " has: " << getClustersOnLayer (iROF, iLayer).size () << " clusters." ;
583582 }
584- std::cout << " Number of seeding vertices: " << getPrimaryVertices (iROF).size () << std::endl ;
583+ LOG (info) << " Number of seeding vertices: " << getPrimaryVertices (iROF).size ();
585584 int iVertex{0 };
586585 for (auto & v : getPrimaryVertices (iROF)) {
587- std::cout << " \t vertex " << iVertex++ << " : x=" << v.getX () << " " << " y=" << v.getY () << " z=" << v.getZ () << " has " << v.getNContributors () << " contributors." << std::endl ;
586+ LOG (info) << " \t vertex " << iVertex++ << " : x=" << v.getX () << " " << " y=" << v.getY () << " z=" << v.getZ () << " has " << v.getNContributors () << " contributors." ;
588587 }
589588 }
590589}
@@ -645,8 +644,6 @@ void TimeFrame<nLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource>& p
645644 initVectors (mTracks );
646645 initVectors (mTracklets );
647646 initVectors (mCells );
648- initVectors (mCellSeeds );
649- initVectors (mCellSeedsChi2 );
650647 initVectors (mCellsNeighbours );
651648 initVectors (mCellsLookupTable );
652649}
@@ -658,8 +655,6 @@ void TimeFrame<nLayers>::wipe()
658655 deepVectorClear (mTracks );
659656 deepVectorClear (mTracklets );
660657 deepVectorClear (mCells );
661- deepVectorClear (mCellSeeds );
662- deepVectorClear (mCellSeedsChi2 );
663658 deepVectorClear (mRoads );
664659 deepVectorClear (mCellsNeighbours );
665660 deepVectorClear (mCellsLookupTable );
@@ -687,6 +682,7 @@ void TimeFrame<nLayers>::wipe()
687682 deepVectorClear (mPValphaX );
688683 deepVectorClear (mBogusClusters );
689684 deepVectorClear (mTrackletsIndexROF );
685+ deepVectorClear (mPrimaryVertices );
690686}
691687
692688template class TimeFrame <7 >;
0 commit comments