41 LogFunc evalLog = [](
const std::string&) {};
44 mTraits->updateTrackingParameters(mTrkParams);
47 if (mTrkParams[0].PerPrimaryVertexProcessing) {
48 maxNvertices = mTimeFrame->getROFVertexLookupTableView().getMaxVerticesPerROF();
51 int iteration{0}, iVertex{0};
52 auto handleException = [&](
const auto& err) {
53 if (mTrkParams[iteration].MaxMemory == std::numeric_limits<size_t>::max()) {
54 LOGP(error,
"Allocation failed in {} in iteration {} iVtx={} ({:.2f} GB of host artefacts, no host limit set), check the detector status and/or the selections.",
55 StateNames[mCurStep], iteration, iVertex,
56 (
double)mTimeFrame->getArtefactsMemory() /
GB);
58 LOGP(error,
"Too much memory in {} in iteration {} iVtx={}: {:.2f} GB. Current limit is {:.2f} GB, check the detector status and/or the selections.",
59 StateNames[mCurStep], iteration, iVertex,
60 (
double)mTimeFrame->getArtefactsMemory() /
GB,
61 (
double)mTrkParams[iteration].MaxMemory /
GB);
63 if (
typeid(err) !=
typeid(std::bad_alloc)) {
64 LOGP(error,
"Exception: {}", err.what());
66 if (mTrkParams[iteration].DropTFUponFailure) {
69 mTimeFrame->getCapacityEstimator().reset();
70 ++mNumberOfDroppedTFs;
71 error(std::format(
"...Dropping TimeSlice {} (out of {} dropped {})...", mTimeSlice, mTimeFrameCounter, mNumberOfDroppedTFs));
78 for (iteration = 0; iteration < (
int)mTrkParams.size(); ++iteration) {
79 mMemoryPool->setMaxMemory(mTrkParams[iteration].MaxMemory);
81 mTimeFrame->useUPCMask();
83 float timeFrame{0.}, timeTracklets{0.}, timeCells{0.}, timeNeighbours{0.}, timeRoads{0.};
84 size_t nTracklets{0}, nCells{0}, nNeighbours{0};
85 int nTracks{-
static_cast<int>(mTimeFrame->getNumberOfTracks())};
86 iVertex = std::min(maxNvertices, 0);
87 logger(std::format(
"==== ITS {} Tracking iteration {} summary ====", mTraits->getName(), iteration));
88 total += timeFrame = evaluateTask(&Tracker::initialiseTimeFrame, StateNames[mCurStep = TFInit], iteration, evalLog, iteration);
89 logger(std::format(
" - TimeFrame initialisation completed in {:.2f} ms", timeFrame));
91 timeTracklets += evaluateTask(&Tracker::computeTracklets, StateNames[mCurStep = Trackleting], iteration, evalLog, iteration, iVertex);
92 nTracklets += mTraits->getTFNumberOfTracklets();
93 timeCells += evaluateTask(&Tracker::computeCells, StateNames[mCurStep = Celling], iteration, evalLog, iteration);
94 nCells += mTraits->getTFNumberOfCells();
95 timeNeighbours += evaluateTask(&Tracker::findCellsNeighbours, StateNames[mCurStep = Neighbouring], iteration, evalLog, iteration);
96 nNeighbours += mTimeFrame->getNumberOfNeighbours();
97 timeRoads += evaluateTask(&Tracker::findRoads, StateNames[mCurStep = Roading], iteration, evalLog, iteration);
98 }
while (++iVertex < maxNvertices);
99 logger(std::format(
" - Tracklet finding: {} tracklets found in {:.2f} ms", nTracklets, timeTracklets));
100 logger(std::format(
" - Cell finding: {} cells found in {:.2f} ms", nCells, timeCells));
101 logger(std::format(
" - Neighbours finding: {} neighbours found in {:.2f} ms", nNeighbours, timeNeighbours));
102 logger(std::format(
" - Track finding: {} tracks found in {:.2f} ms", nTracks + mTimeFrame->getNumberOfTracks(), timeRoads));
104 logger(std::format(
" - Integrated track extension: {} tracks accepted using {} clusters", mTimeFrame->getNExtendedTracks(), mTimeFrame->getNExtendedClusters()));
106 total += timeTracklets + timeCells + timeNeighbours + timeRoads;
109 handleException(err);
111 }
catch (
const std::bad_alloc& err) {
112 handleException(err);
114 }
catch (
const std::exception& err) {
115 error(std::format(
"Uncaught exception, all bets are off... {}", err.
what()));
117 mTimeFrame->getTracks().clear();
121 if (mTimeFrame->hasMCinformation()) {
122 computeTracksMClabels();
124 rectifyClusterIndices();
136 for (
auto&
track : mTimeFrame->getTracks()) {
137 std::vector<std::pair<MCCompLabel, size_t>> occurrences;
141 const int index =
track.getClusterIndex(iCluster);
145 auto labels = mTimeFrame->getClusterLabels(iCluster,
index);
147 for (
size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
148 std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
150 if (
label == occurrence.first) {
159 occurrences.emplace_back(
label, 1);
163 std::sort(std::begin(occurrences), std::end(occurrences), [](
auto e1,
auto e2) {
164 return e1.second > e2.second;
167 auto maxOccurrencesValue = occurrences[0].first;
171 auto clid =
track.getClusterIndex(ic);
173 auto labelsSpan = mTimeFrame->getClusterLabels(ic, clid);
174 for (
const auto& currentLabel : labelsSpan) {
175 if (currentLabel == maxOccurrencesValue) {
183 if (occurrences[0].second <
track.getNumberOfClusters()) {
184 maxOccurrencesValue.setFakeFlag();
186 mTimeFrame->getTracksLabel().emplace_back(maxOccurrencesValue);
259 auto avgTF = mTotalTime * 1.e-3 / ((mTimeFrameCounter > 0) ? (
double)mTimeFrameCounter : -1.0);
260 auto avgTFwithDropped = mTotalTime * 1.e-3 / (((mTimeFrameCounter + mNumberOfDroppedTFs) > 0) ? (double)(mTimeFrameCounter + mNumberOfDroppedTFs) : -1.0);
261 LOGP(info,
"Tracker summary: Processed {} TFs (dropped {}) in TOT={:.2f} s, AVG/TF={:.2f} ({:.2f}) s", mTimeFrameCounter, mNumberOfDroppedTFs, mTotalTime * 1.e-3, avgTF, avgTFwithDropped);
262 for (
size_t iteration = 0; iteration < mTimingStats.size(); ++iteration) {
264 const auto& stats = mTimingStats[iteration][
state];
268 LOGP(info,
" - iter {} {}: calls={} total={:.2f} ms avg={:.2f} ms", iteration, StateNames[
state], stats.calls, stats.totalTimeMs, stats.averageTimeMs());