1818#include < oneapi/tbb/parallel_sort.h>
1919
2020#include < algorithm>
21+ #include < cstddef>
2122#include < iterator>
2223#include < limits>
2324#include < ranges>
4041#include " ITStracking/BoundedAllocator.h"
4142#include " ITStracking/IndexTableUtils.h"
4243#include " ITStracking/Tracklet.h"
44+ #include " ITStracking/Utils.h"
4345#include " ReconstructionDataFormats/Track.h"
4446
4547// / optimization output
@@ -58,7 +60,7 @@ namespace o2::its
5860{
5961namespace
6062{
61- utils::TreeStreamRedirector* sDBGOut {nullptr };
63+ o2:: utils::TreeStreamRedirector* sDBGOut {nullptr };
6264}
6365
6466struct PassMode {
@@ -570,8 +572,9 @@ void TrackerTraits<NLayers>::findCellSeeds(const int iteration)
570572 int rof = mTimeFrame ->getClusterROF (i, cls[i]);
571573 int rofStartBC = mTimeFrame ->getROFOverlapTableView ().getLayer (i).getROFStartInBC (rof);
572574 int rofEndBC = mTimeFrame ->getROFOverlapTableView ().getLayer (i).getROFEndInBC (rof);
573- startBC = o2::gpu::CAMath::Min (startBC, rofStartBC);
574- endBC = o2::gpu::CAMath::Max (endBC, rofEndBC);
575+ // if the start/end of the cluster is after/before the current bracket need to enlarge
576+ startBC = (rofStartBC <= startBC) ? rofStartBC : o2::gpu::CAMath::Max (startBC, rofStartBC);
577+ endBC = (rofEndBC >= endBC) ? rofEndBC : o2::gpu::CAMath::Min (endBC, rofEndBC);
575578 }
576579 if (endBC - startBC < 0 ) { // this should not happen
577580 ltracks[iCell].markDead ();
@@ -946,10 +949,10 @@ void TrackerTraits<NLayers>::processNeighbours(int iteration, int iLayer, int iL
946949 if (neighbourCell.getSecondTrackletIndex () != currentCell.getFirstTrackletIndex ()) {
947950 continue ;
948951 }
949- if (mTimeFrame -> isClusterUsed (iLayer - 1 , neighbourCell.getFirstClusterIndex () )) {
952+ if (currentCell. getLevel () - 1 != neighbourCell.getLevel ( )) {
950953 continue ;
951954 }
952- if (currentCell. getLevel () - 1 != neighbourCell.getLevel ( )) {
955+ if (mTimeFrame -> isClusterUsed (iLayer - 1 , neighbourCell.getFirstClusterIndex () )) {
953956 continue ;
954957 }
955958
@@ -1143,15 +1146,17 @@ void TrackerTraits<NLayers>::findRoads(const int iteration)
11431146 }
11441147
11451148 deepVectorClear (trackSeeds);
1149+ // sort tracks in quality (accounting for 1. length; 2. chi2)
1150+ // needed since then tracks with shared clusters can be marked/discarded
11461151 tbb::parallel_sort (tracks.begin (), tracks.end (), [](const auto & a, const auto & b) {
1147- return a.getChi2 () < b. getChi2 ( );
1152+ return a.isBetter (b );
11481153 });
11491154 });
11501155
11511156 for (auto & track : tracks) {
11521157 int nShared = 0 ;
11531158 bool isFirstShared{false };
1154- int firstLayer{- 1 }, firstCluster{- 1 };
1159+ int firstLayer{constants::UnusedIndex }, firstCluster{constants::UnusedIndex };
11551160 for (int iLayer{0 }; iLayer < mRecoParams [iteration].params .NLayers ; ++iLayer) {
11561161 if (track.getClusterIndex (iLayer) == constants::UnusedIndex) {
11571162 continue ;
@@ -1172,20 +1177,32 @@ void TrackerTraits<NLayers>::findRoads(const int iteration)
11721177
11731178 // here we can do the calculation of the time bracket simply
11741179 // by checkig in which rofs the clusters are
1175- int bcStart{0 }, bcEnd{std::numeric_limits<int >::max ()};
1180+ std::array<utils::Bracket, NLayers> brackets;
1181+ brackets.fill (utils::InvalidBracket);
11761182 for (int iLayer{0 }; iLayer < mRecoParams [iteration].params .NLayers ; ++iLayer) {
11771183 if (track.getClusterIndex (iLayer) == constants::UnusedIndex) {
11781184 continue ;
11791185 }
1180- mTimeFrame ->markUsedCluster (iLayer, track.getClusterIndex (iLayer));
11811186 int currentROF = mTimeFrame ->getClusterROF (iLayer, track.getClusterIndex (iLayer));
1182- int bcClsSta = mTimeFrame ->getROFOverlapTableView ().getLayer (iLayer).getROFStartInBC (currentROF);
1183- int bcClsEnd = mTimeFrame ->getROFOverlapTableView ().getLayer (iLayer).getROFEndInBC (currentROF);
1184- bcStart = std::max (bcStart, bcClsSta);
1185- bcEnd = std::min (bcEnd, bcClsEnd);
1187+ // need to account for the imposed delay
1188+ int bcClsSta = mTimeFrame ->getROFOverlapTableView ().getLayer (iLayer).getROFStartInBC (currentROF, true );
1189+ int bcClsEnd = mTimeFrame ->getROFOverlapTableView ().getLayer (iLayer).getROFEndInBC (currentROF, true );
1190+ brackets[iLayer] = utils::Bracket{bcClsSta, bcClsEnd};
1191+ LOGP (debug, " \t lay:{} bcClsSta={} bcClsEnd={}" , iLayer, bcClsSta, bcClsEnd);
1192+ }
1193+ const auto best = utils::computeSmallestBracket (brackets);
1194+ if (best == utils::InvalidBracket) {
1195+ continue ; // track has an impossible span, discard
1196+ }
1197+ // mark used clusters for the next iteration
1198+ for (int iLayer{0 }; iLayer < mRecoParams [iteration].params .NLayers ; ++iLayer) {
1199+ if (track.getClusterIndex (iLayer) == constants::UnusedIndex) {
1200+ continue ;
1201+ }
1202+ mTimeFrame ->markUsedCluster (iLayer, track.getClusterIndex (iLayer));
11861203 }
1187- track.getTimeStamp ().setTimeStamp (bcStart );
1188- track.getTimeStamp ().setTimeStampError (bcEnd - bcStart + 1 );
1204+ track.getTimeStamp ().setTimeStamp (best. first );
1205+ track.getTimeStamp ().setTimeStampError (best. second - best. first + 1 );
11891206 track.setUserField (0 );
11901207 track.getParamOut ().setUserField (0 );
11911208 mTimeFrame ->getTracks ().emplace_back (track);
0 commit comments