@@ -636,6 +636,9 @@ void TrackerTraits<nLayers>::findRoads(const int iteration)
636636
637637 for (int startLevel{mTrkParams [iteration].CellsPerRoad ()}; startLevel >= mTrkParams [iteration].CellMinimumLevel (); --startLevel) {
638638 CA_DEBUGGER (std::cout << " \t > Processing level " << startLevel << std::endl);
639+ auto seedFilter = [&](const CellSeed& seed) {
640+ return seed.getQ2Pt () <= 1 .e3 && seed.getChi2 () <= mTrkParams [0 ].MaxChi2NDF * ((startLevel + 2 ) * 2 - 5 );
641+ };
639642 bounded_vector<CellSeed> trackSeeds (mMemoryPool .get ());
640643 for (int startLayer{mTrkParams [iteration].CellsPerRoad () - 1 }; startLayer >= startLevel - 1 ; --startLayer) {
641644 if ((mTrkParams [iteration].StartLayerMask & (1 << (startLayer + 2 ))) == 0 ) {
@@ -655,29 +658,26 @@ void TrackerTraits<nLayers>::findRoads(const int iteration)
655658 deepVectorClear (updatedCellId); // / tame the memory peaks
656659 processNeighbours (iLayer, --level, lastCellSeed, lastCellId, updatedCellSeed, updatedCellId);
657660 }
658- std::copy_if (updatedCellSeed.begin (), updatedCellSeed.end (), std::back_inserter (trackSeeds), [&](const CellSeed& seed) {
659- return seed.getQ2Pt () <= 1 .e3 && seed.getChi2 () <= mTrkParams [0 ].MaxChi2NDF * ((startLevel + 2 ) * 2 - 5 );
660- });
661+ deepVectorClear (lastCellId); // / tame the memory peaks
662+ deepVectorClear (lastCellSeed); // / tame the memory peaks
663+
664+ if (!updatedCellSeed.empty ()) {
665+ trackSeeds.reserve (trackSeeds.size () + std::count_if (updatedCellSeed.begin (), updatedCellSeed.end (), seedFilter));
666+ std::copy_if (updatedCellSeed.begin (), updatedCellSeed.end (), std::back_inserter (trackSeeds), seedFilter);
667+ }
661668 }
662669
663670 if (trackSeeds.empty ()) {
664671 continue ;
665672 }
666673
667674 bounded_vector<TrackITSExt> tracks (mMemoryPool .get ());
668- tracks.reserve (trackSeeds.size ());
669675 mTaskArena .execute ([&] {
670- tbb::combinable<bounded_vector<TrackITSExt>> locTracksData ([&] {
671- return bounded_vector<TrackITSExt>(mMemoryPool .get ());
672- });
673-
676+ bounded_vector<int > perSeedCount (trackSeeds.size () + 1 , 0 , mMemoryPool .get ());
674677 tbb::parallel_for (
675678 tbb::blocked_range<size_t >(size_t (0 ), trackSeeds.size ()),
676679 [&](const tbb::blocked_range<size_t >& Seeds) {
677680 for (int iSeed = Seeds.begin (); iSeed < Seeds.end (); ++iSeed) {
678- auto & localTracks = locTracksData.local ();
679- localTracks.reserve (Seeds.size ());
680-
681681 const CellSeed& seed{trackSeeds[iSeed]};
682682 TrackITSExt temporaryTrack{seed};
683683 temporaryTrack.resetCovariance ();
@@ -697,15 +697,43 @@ void TrackerTraits<nLayers>::findRoads(const int iteration)
697697 if (!fitSuccess || temporaryTrack.getPt () < mTrkParams [iteration].MinPt [mTrkParams [iteration].NLayers - temporaryTrack.getNClusters ()]) {
698698 continue ;
699699 }
700- localTracks. push_back (temporaryTrack) ;
700+ ++perSeedCount[iSeed] ;
701701 }
702702 });
703+ std::exclusive_scan (perSeedCount.begin (), perSeedCount.end (), perSeedCount.begin (), 0 );
704+ auto totalTracks{perSeedCount.back ()};
705+ if (totalTracks == 0 ) {
706+ return ;
707+ }
708+ tracks.resize (totalTracks);
703709
704- locTracksData.combine_each ([&](const bounded_vector<TrackITSExt>& localTracks) {
705- tracks.insert (tracks.end (), localTracks.begin (), localTracks.end ());
706- });
707- tracks.shrink_to_fit ();
710+ tbb::parallel_for (
711+ tbb::blocked_range<int >(0 , (int )trackSeeds.size ()),
712+ [&](const tbb::blocked_range<int >& Seeds) {
713+ for (int iSeed = Seeds.begin (); iSeed < Seeds.end (); ++iSeed) {
714+ if (perSeedCount[iSeed] == perSeedCount[iSeed + 1 ]) {
715+ continue ;
716+ }
717+ const CellSeed& seed{trackSeeds[iSeed]};
718+ auto & trk = tracks[perSeedCount[iSeed]] = TrackITSExt (seed);
719+ trk.resetCovariance ();
720+ trk.setChi2 (0 );
721+ for (int iL{0 }; iL < 7 ; ++iL) {
722+ trk.setExternalClusterIndex (iL, seed.getCluster (iL), seed.getCluster (iL) != constants::its::UnusedIndex);
723+ }
724+
725+ bool fitSuccess = fitTrack (trk, 0 , mTrkParams [0 ].NLayers , 1 , mTrkParams [0 ].MaxChi2ClusterAttachment , mTrkParams [0 ].MaxChi2NDF );
726+ if (!fitSuccess) {
727+ continue ;
728+ }
729+ trk.getParamOut () = trk.getParamIn ();
730+ trk.resetCovariance ();
731+ trk.setChi2 (0 );
732+ fitTrack (trk, mTrkParams [0 ].NLayers - 1 , -1 , -1 , mTrkParams [0 ].MaxChi2ClusterAttachment , mTrkParams [0 ].MaxChi2NDF , 50 .f );
733+ }
734+ });
708735
736+ deepVectorClear (trackSeeds);
709737 tbb::parallel_sort (tracks.begin (), tracks.end (), [](const auto & a, const auto & b) {
710738 return a.getChi2 () < b.getChi2 ();
711739 });
0 commit comments