41 mTraits->updateTrackingParameters(mTrkParams);
43 int nSeedingPasses{0};
44 while (nSeedingPasses < (
int)mTrkParams.size() &&
48 if (nSeedingPasses == 0) {
51 logger(std::format(
"==== ITS {} Seeding-vertex pass ====", mTraits->getName()));
53 for (
int it = 0; it < nSeedingPasses; ++it) {
54 mMemoryPool->setMaxMemory(mTrkParams[it].MaxMemory);
55 const bool refineBeam = it == 0 && !mTimeFrame->isBeamOverridden();
59 const auto& vtxLookup = mTimeFrame->getROFVertexLookupTableView();
60 const int threshold = mTrkParams[it].VertPerRofThreshold;
61 int nEnabled = 0, nTotal = 0;
63 const int nRofs = mTimeFrame->getROFOverlapTableView().getLayer(
layer).mNROFsTF;
64 for (
int rof = 0; rof < nRofs; ++rof) {
66 const bool empty = (int)vtxLookup.getVertices(
layer, rof).getEntries() <= threshold;
67 upcMask.setROFEnabled(
layer, rof,
empty ? 1u : 0u);
74 mTimeFrame->setSeedingUPCMask(std::move(upcMask));
75 mTimeFrame->useSeedingUPCMask();
76 logger(std::format(
" - Seeding pass {}: UPC pass on {}/{} ROFs without vertices",
77 it, nEnabled, nTotal));
79 for (
int pass = 0; pass < maxBootstrap; ++pass) {
80 const float prevBeamX = mTimeFrame->getBeamX();
81 const float prevBeamY = mTimeFrame->getBeamY();
82 total += evaluateTask(&Tracker::initialiseTimeFrame, StateNames[mCurStep = TFInit], it, logger, it);
83 total += evaluateTask(&Tracker::computeTracklets, StateNames[mCurStep = Trackleting], it, logger, it, -1);
84 const int nTracklets = mTraits->getTFNumberOfTracklets();
85 total += evaluateTask(&Tracker::computeCells, StateNames[mCurStep = Celling], it, logger, it);
86 total += evaluateTask(&Tracker::computeVertexCandidates, StateNames[mCurStep = CellLinearising], it, logger, it);
87 logger(std::format(
" - Seeding pass {}.{}: {} tracklets, {} cells, {} lines", it, pass,
88 nTracklets, mTraits->getTFNumberOfCells(),
89 mTimeFrame->getNLinesTotal()));
90 total += evaluateTask(&Tracker::computeVertices, StateNames[mCurStep = SeedingVertices], it, logger, it);
94 total += evaluateTask(&Tracker::computeBeamFromVertices, StateNames[mCurStep = BeamPositioning], it, logger, it);
95 const float dx = mTimeFrame->getBeamX() - prevBeamX;
96 const float dy = mTimeFrame->getBeamY() - prevBeamY;
98 logger(std::format(
" - Beam bootstrap converged after pass {} (beam shift < 50 um)", pass));
103 if (nSeedingPasses > 1) {
104 mTimeFrame->useMultiplictyMask();
112 LogFunc evalLog = [](
const std::string&) {};
115 mTraits->updateTrackingParameters(mTrkParams);
117 int maxNvertices{-1};
118 int firstTrackingIteration{0};
119 while (firstTrackingIteration < (
int)mTrkParams.size() &&
121 ++firstTrackingIteration;
123 if (firstTrackingIteration < (
int)mTrkParams.size() && mTrkParams[firstTrackingIteration].PerPrimaryVertexProcessing) {
124 maxNvertices = mTimeFrame->getROFVertexLookupTableView().getMaxVerticesPerROF();
127 int iteration{firstTrackingIteration}, iVertex{0};
128 auto handleException = [&](
const auto& err) {
129 if (mTrkParams[iteration].MaxMemory == std::numeric_limits<size_t>::max()) {
130 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.",
131 StateNames[mCurStep], iteration, iVertex,
132 (
double)mTimeFrame->getArtefactsMemory() /
GB);
134 LOGP(error,
"Too much memory in {} in iteration {} iVtx={}: {:.2f} GB. Current limit is {:.2f} GB, check the detector status and/or the selections.",
135 StateNames[mCurStep], iteration, iVertex,
136 (
double)mTimeFrame->getArtefactsMemory() /
GB,
137 (
double)mTrkParams[iteration].MaxMemory /
GB);
139 if (
typeid(err) !=
typeid(std::bad_alloc)) {
140 LOGP(error,
"Exception: {}", err.what());
142 if (mTrkParams[iteration].DropTFUponFailure) {
143 mMemoryPool->print();
145 mTimeFrame->getCapacityEstimator().reset();
146 ++mNumberOfDroppedTFs;
147 error(std::format(
"...Dropping TimeSlice {} (out of {} dropped {})...", mTimeSlice, mTimeFrameCounter, mNumberOfDroppedTFs));
154 for (iteration = firstTrackingIteration; iteration < (int)mTrkParams.size(); ++iteration) {
155 mMemoryPool->setMaxMemory(mTrkParams[iteration].MaxMemory);
157 mTimeFrame->useUPCMask();
159 float timeFrame{0.}, timeTracklets{0.}, timeCells{0.}, timeNeighbours{0.}, timeRoads{0.};
160 size_t nTracklets{0}, nCells{0}, nNeighbours{0};
161 int nTracks{-
static_cast<int>(mTimeFrame->getNumberOfTracks())};
162 iVertex = std::min(maxNvertices, 0);
163 logger(std::format(
"==== ITS {} Tracking iteration {} summary ====", mTraits->getName(), iteration));
164 total += timeFrame = evaluateTask(&Tracker::initialiseTimeFrame, StateNames[mCurStep = TFInit], iteration, evalLog, iteration);
165 logger(std::format(
" - TimeFrame initialisation completed in {:.2f} ms", timeFrame));
167 timeTracklets += evaluateTask(&Tracker::computeTracklets, StateNames[mCurStep = Trackleting], iteration, evalLog, iteration, iVertex);
168 nTracklets += mTraits->getTFNumberOfTracklets();
169 timeCells += evaluateTask(&Tracker::computeCells, StateNames[mCurStep = Celling], iteration, evalLog, iteration);
170 nCells += mTraits->getTFNumberOfCells();
171 timeNeighbours += evaluateTask(&Tracker::findCellsNeighbours, StateNames[mCurStep = Neighbouring], iteration, evalLog, iteration);
172 nNeighbours += mTimeFrame->getNumberOfNeighbours();
173 timeRoads += evaluateTask(&Tracker::findRoads, StateNames[mCurStep = Roading], iteration, evalLog, iteration);
174 }
while (++iVertex < maxNvertices);
175 logger(std::format(
" - Tracklet finding: {} tracklets found in {:.2f} ms", nTracklets, timeTracklets));
176 logger(std::format(
" - Cell finding: {} cells found in {:.2f} ms", nCells, timeCells));
177 logger(std::format(
" - Neighbours finding: {} neighbours found in {:.2f} ms", nNeighbours, timeNeighbours));
178 logger(std::format(
" - Track finding: {} tracks found in {:.2f} ms", nTracks + mTimeFrame->getNumberOfTracks(), timeRoads));
180 logger(std::format(
" - Integrated track extension: {} tracks accepted using {} clusters", mTimeFrame->getNExtendedTracks(), mTimeFrame->getNExtendedClusters()));
182 total += timeTracklets + timeCells + timeNeighbours + timeRoads;
185 handleException(err);
187 }
catch (
const std::bad_alloc& err) {
188 handleException(err);
190 }
catch (
const std::exception& err) {
191 error(std::format(
"Uncaught exception, all bets are off... {}", err.
what()));
193 mTimeFrame->getTracks().clear();
197 if (mTimeFrame->hasMCinformation()) {
198 computeTracksMClabels();
200 rectifyClusterIndices();
212 for (
auto&
track : mTimeFrame->getTracks()) {
213 std::vector<std::pair<MCCompLabel, size_t>> occurrences;
217 const int index =
track.getClusterIndex(iCluster);
221 auto labels = mTimeFrame->getClusterLabels(iCluster,
index);
223 for (
size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
224 std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
226 if (
label == occurrence.first) {
235 occurrences.emplace_back(
label, 1);
239 std::sort(std::begin(occurrences), std::end(occurrences), [](
auto e1,
auto e2) {
240 return e1.second > e2.second;
243 auto maxOccurrencesValue = occurrences[0].first;
247 auto clid =
track.getClusterIndex(ic);
249 auto labelsSpan = mTimeFrame->getClusterLabels(ic, clid);
250 for (
const auto& currentLabel : labelsSpan) {
251 if (currentLabel == maxOccurrencesValue) {
259 if (occurrences[0].second <
track.getNumberOfClusters()) {
260 maxOccurrencesValue.setFakeFlag();
262 mTimeFrame->getTracksLabel().emplace_back(maxOccurrencesValue);
335 auto avgTF = mTotalTime * 1.e-3 / ((mTimeFrameCounter > 0) ? (
double)mTimeFrameCounter : -1.0);
336 auto avgTFwithDropped = mTotalTime * 1.e-3 / (((mTimeFrameCounter + mNumberOfDroppedTFs) > 0) ? (double)(mTimeFrameCounter + mNumberOfDroppedTFs) : -1.0);
337 LOGP(info,
"Tracker summary: Processed {} TFs (dropped {}) in TOT={:.2f} s, AVG/TF={:.2f} ({:.2f}) s", mTimeFrameCounter, mNumberOfDroppedTFs, mTotalTime * 1.e-3, avgTF, avgTFwithDropped);
338 for (
size_t iteration = 0; iteration < mTimingStats.size(); ++iteration) {
340 const auto& stats = mTimingStats[iteration][
state];
344 LOGP(info,
" - iter {} {}: calls={} total={:.2f} ms avg={:.2f} ms", iteration, StateNames[
state], stats.calls, stats.totalTimeMs, stats.averageTimeMs());