46 LogFunc evalLog = [](
const std::string&) {};
51 if (mTrkParams[0].PerPrimaryVertexProcessing) {
52 for (
int iROF{0}; iROF < mTimeFrame->
getNrof(); ++iROF) {
53 maxNvertices = std::max(maxNvertices, (
int)mTimeFrame->
getPrimaryVertices(iROF).size());
57 int iteration{0}, iROFs{0}, iVertex{0};
58 auto handleException = [&](
const auto& err) {
59 LOGP(error,
"Too much memory used during {} in iteration {} in ROF span {}-{} iVtx={}: {:.2f} GB. Current limit is {:.2f} GB, check the detector status and/or the selections.",
60 StateNames[mCurState], iteration, iROFs, iROFs + mTrkParams[iteration].nROFsPerIterations, iVertex,
62 LOGP(error,
"Exception: {}", err.what());
63 if (mTrkParams[iteration].DropTFUponFailure) {
66 ++mNumberOfDroppedTFs;
67 error(
"...Dropping Timeframe...");
74 for (iteration = 0; iteration < (
int)mTrkParams.size(); ++iteration) {
75 mMemoryPool->setMaxMemory(mTrkParams[iteration].MaxMemory);
76 if (iteration == 3 && mTrkParams[0].DoUPCIteration) {
79 double timeTracklets{0.}, timeCells{0.}, timeNeighbours{0.}, timeRoads{0.};
80 int nTracklets{0}, nCells{0}, nNeighbours{0}, nTracks{-
static_cast<int>(mTimeFrame->
getNumberOfTracks())};
81 int nROFsIterations = mTrkParams[iteration].nROFsPerIterations > 0 ? mTimeFrame->
getNrof() / mTrkParams[iteration].nROFsPerIterations + bool(mTimeFrame->
getNrof() % mTrkParams[iteration].nROFsPerIterations) : 1;
82 int iVertex{std::min(maxNvertices, 0)};
83 logger(std::format(
"==== ITS {} Tracking iteration {} summary ====", mTraits->
getName(), iteration));
85 total += evaluateTask(&Tracker::initialiseTimeFrame, StateNames[mCurState = TFInit], iteration, logger, iteration);
87 for (iROFs = 0; iROFs < nROFsIterations; ++iROFs) {
88 timeTracklets += evaluateTask(&Tracker::computeTracklets, StateNames[mCurState = Trackleting], iteration, evalLog, iteration, iROFs, iVertex);
91 if (trackletsPerCluster > mTrkParams[iteration].TrackletsPerClusterLimit) {
92 error(std::format(
"Too many tracklets per cluster ({}) in iteration {} in ROF span {}-{}:, check the detector status and/or the selections. Current limit is {}",
93 trackletsPerCluster, iteration, iROFs, iROFs + mTrkParams[iteration].nROFsPerIterations, mTrkParams[iteration].TrackletsPerClusterLimit));
96 timeCells += evaluateTask(&Tracker::computeCells, StateNames[mCurState = Celling], iteration, evalLog, iteration);
99 if (cellsPerCluster > mTrkParams[iteration].CellsPerClusterLimit) {
100 error(std::format(
"Too many cells per cluster ({}) in iteration {} in ROF span {}-{}, check the detector status and/or the selections. Current limit is {}",
101 cellsPerCluster, iteration, iROFs, iROFs + mTrkParams[iteration].nROFsPerIterations, mTrkParams[iteration].CellsPerClusterLimit));
104 timeNeighbours += evaluateTask(&Tracker::findCellsNeighbours, StateNames[mCurState = Neighbouring], iteration, evalLog, iteration);
106 timeRoads += evaluateTask(&Tracker::findRoads, StateNames[mCurState = Roading], iteration, evalLog, iteration);
109 }
while (iVertex < maxNvertices);
110 logger(std::format(
" - Tracklet finding: {} tracklets found in {:.2f} ms", nTracklets, timeTracklets));
111 logger(std::format(
" - Cell finding: {} cells found in {:.2f} ms", nCells, timeCells));
112 logger(std::format(
" - Neighbours finding: {} neighbours found in {:.2f} ms", nNeighbours, timeNeighbours));
113 logger(std::format(
" - Track finding: {} tracks found in {:.2f} ms", nTracks + mTimeFrame->
getNumberOfTracks(), timeRoads));
114 total += timeTracklets + timeCells + timeNeighbours + timeRoads;
117 auto timeExtending = evaluateTask(&Tracker::extendTracks,
"Extending tracks", iteration, evalLog, iteration);
118 total += timeExtending;
119 logger(std::format(
" - Extending Tracks: {} extended tracks using {} clusters found in {:.2f} ms", nExtendedTracks + mTimeFrame->
mNExtendedTracks, nExtendedClusters + mTimeFrame->
mNExtendedUsedClusters, timeExtending));
121 if (mTrkParams[iteration].PrintMemory) {
122 mMemoryPool->print();
127 total += evaluateTask(&Tracker::findShortPrimaries,
"Short primaries finding", 0, logger);
129 logger(std::format(
" `-> found {} additional tracks", nTracksA - nTracksB));
131 if (mTrkParams[iteration].PrintMemory) {
132 mMemoryPool->print();
135 logger(std::format(
"=== TimeFrame {} processing completed in: {:.2f} ms using {} thread(s) ===", mTimeFrameCounter, total, mTraits->
getNThreads()));
138 handleException(err);
140 }
catch (
const std::bad_alloc& err) {
141 handleException(err);
144 error(
"Uncaught exception, all bets are off...");
147 if (mTrkParams[0].PrintMemory) {
149 mMemoryPool->print();
153 computeTracksMClabels();
155 rectifyClusterIndices();
160void Tracker::computeRoadsMClabels()
169 int roadsNum{
static_cast<int>(mTimeFrame->
getRoads().size())};
171 for (
int iRoad{0}; iRoad < roadsNum; ++iRoad) {
173 Road<5>& currentRoad{mTimeFrame->
getRoads()[iRoad]};
174 std::vector<std::pair<MCCompLabel, size_t>> occurrences;
175 bool isFakeRoad{
false};
176 bool isFirstRoadCell{
true};
178 for (
int iCell{0}; iCell < mTrkParams[0].CellsPerRoad(); ++iCell) {
179 const int currentCellIndex{currentRoad[iCell]};
182 if (isFirstRoadCell) {
189 const CellSeed& currentCell{mTimeFrame->
getCells()[iCell][currentCellIndex]};
191 if (isFirstRoadCell) {
193 const int cl0index{mTimeFrame->
getClusters()[iCell][currentCell.getFirstClusterIndex()].clusterId};
196 for (
size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
197 std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
198 for (
auto&
label : cl0labs) {
199 if (
label == occurrence.first) {
207 for (
auto&
label : cl0labs) {
208 occurrences.emplace_back(
label, 1);
212 const int cl1index{mTimeFrame->
getClusters()[iCell + 1][currentCell.getSecondClusterIndex()].clusterId};
216 for (
size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
217 std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
218 for (
auto&
label : cl1labs) {
219 if (
label == occurrence.first) {
227 for (
auto&
label : cl1labs) {
228 occurrences.emplace_back(
label, 1);
232 isFirstRoadCell =
false;
235 const int cl2index{mTimeFrame->
getClusters()[iCell + 2][currentCell.getThirdClusterIndex()].clusterId};
238 for (
size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
239 std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
240 for (
auto&
label : cl2labs) {
241 if (
label == occurrence.first) {
249 for (
auto&
label : cl2labs) {
250 occurrences.emplace_back(
label, 1);
255 std::sort(occurrences.begin(), occurrences.end(), [](
auto e1,
auto e2) {
256 return e1.second > e2.second;
259 auto maxOccurrencesValue = occurrences[0].first;
260 mTimeFrame->
setRoadLabel(iRoad, maxOccurrencesValue.getRawValue(), isFakeRoad);
264void Tracker::computeTracksMClabels()
266 for (
int iROF{0}; iROF < mTimeFrame->
getNrof(); ++iROF) {
267 for (
auto& track : mTimeFrame->getTracks(iROF)) {
268 std::vector<std::pair<MCCompLabel, size_t>> occurrences;
272 const int index = track.getClusterIndex(iCluster);
278 for (
size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
279 std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
280 for (
auto&
label : labels) {
281 if (
label == occurrence.first) {
289 for (
auto&
label : labels) {
290 occurrences.emplace_back(
label, 1);
294 std::sort(std::begin(occurrences), std::end(occurrences), [](
auto e1,
auto e2) {
295 return e1.second > e2.second;
298 auto maxOccurrencesValue = occurrences[0].first;
299 uint32_t
pattern = track.getPattern();
302 auto clid = track.getClusterIndex(ic);
305 for (
auto& currentLabel : labelsSpan) {
306 if (currentLabel == maxOccurrencesValue) {
314 if (occurrences[0].second < track.getNumberOfClusters()) {
315 maxOccurrencesValue.setFakeFlag();
317 mTimeFrame->
getTracksLabel(iROF).emplace_back(maxOccurrencesValue);
322void Tracker::rectifyClusterIndices()
324 for (
int iROF{0}; iROF < mTimeFrame->
getNrof(); ++iROF) {
325 for (
auto& track : mTimeFrame->getTracks(iROF)) {
327 const int index = track.getClusterIndex(iCluster);
339 if (tc.useMatCorrTGeo) {
341 }
else if (tc.useFastMaterial) {
347 int nROFsPerIterations = tc.nROFsPerIterations > 0 ? tc.nROFsPerIterations : -1;
348 if (tc.nOrbitsPerIterations > 0) {
351 for (
auto&
params : mTrkParams) {
352 if (
params.NLayers == 7) {
353 for (
int i{0};
i < 7; ++
i) {
354 params.SystErrorY2[
i] = tc.sysErrY2[
i] > 0 ? tc.sysErrY2[
i] :
params.SystErrorY2[
i];
355 params.SystErrorZ2[
i] = tc.sysErrZ2[
i] > 0 ? tc.sysErrZ2[
i] :
params.SystErrorZ2[
i];
358 params.DeltaROF = tc.deltaRof;
359 params.DoUPCIteration = tc.doUPCIteration;
360 params.MaxChi2ClusterAttachment = tc.maxChi2ClusterAttachment > 0 ? tc.maxChi2ClusterAttachment :
params.MaxChi2ClusterAttachment;
361 params.MaxChi2NDF = tc.maxChi2NDF > 0 ? tc.maxChi2NDF :
params.MaxChi2NDF;
362 params.PhiBins = tc.LUTbinsPhi > 0 ? tc.LUTbinsPhi :
params.PhiBins;
363 params.ZBins = tc.LUTbinsZ > 0 ? tc.LUTbinsZ :
params.ZBins;
365 params.NSigmaCut *= tc.nSigmaCut > 0 ? tc.nSigmaCut : 1.f;
366 params.CellDeltaTanLambdaSigma *= tc.deltaTanLres > 0 ? tc.deltaTanLres : 1.f;
367 params.TrackletMinPt *= tc.minPt > 0 ? tc.minPt : 1.f;
368 params.nROFsPerIterations = nROFsPerIterations;
369 params.PerPrimaryVertexProcessing = tc.perPrimaryVertexProcessing;
370 params.SaveTimeBenchmarks = tc.saveTimeBenchmarks;
371 params.FataliseUponFailure = tc.fataliseUponFailure;
372 params.DropTFUponFailure = tc.dropTFUponFailure;
373 for (
int iD{0}; iD < 3; ++iD) {
374 params.Diamond[iD] = tc.diamondPos[iD];
376 params.UseDiamond = tc.useDiamond;
378 params.MaxMemory = tc.maxMemory;
380 if (tc.useTrackFollower > 0) {
381 params.UseTrackFollower =
true;
385 params.UseTrackFollowerMix = ((tc.useTrackFollower & (1 << 0)) != 0);
386 params.UseTrackFollowerTop = ((tc.useTrackFollower & (1 << 1)) != 0);
387 params.UseTrackFollowerBot = ((tc.useTrackFollower & (1 << 2)) != 0);
388 params.TrackFollowerNSigmaCutZ = tc.trackFollowerNSigmaZ;
389 params.TrackFollowerNSigmaCutPhi = tc.trackFollowerNSigmaPhi;
391 if (tc.cellsPerClusterLimit >= 0) {
392 params.CellsPerClusterLimit = tc.cellsPerClusterLimit;
394 if (tc.trackletsPerClusterLimit >= 0) {
395 params.TrackletsPerClusterLimit = tc.trackletsPerClusterLimit;
397 if (tc.findShortTracks >= 0) {
398 params.FindShortTracks = tc.findShortTracks;
411 auto avgTF = mTotalTime * 1.e-3 / ((mTimeFrameCounter > 0) ? (
double)mTimeFrameCounter : -1.0);
412 auto avgTFwithDropped = mTotalTime * 1.e-3 / (((mTimeFrameCounter + mNumberOfDroppedTFs) > 0) ? (double)(mTimeFrameCounter + mNumberOfDroppedTFs) : -1.0);
413 LOGP(info,
"Tracker summary: Processed {} TFs (dropped {}) in TOT={:.2f} s, AVG/TF={:.2f} ({:.2f}) s", mTimeFrameCounter, mNumberOfDroppedTFs, mTotalTime * 1.e-3, avgTF, avgTFwithDropped);
Class to handle Kalman smoothing for ITS tracking. Its instance stores the state of the track to the ...
static const TrackerParamConfig & Instance()
static constexpr int MaxClusters
< heavy version of TrackITS, with clusters embedded
virtual int getTFNumberOfTracklets() const
virtual int getTFNumberOfClusters() const
void updateTrackingParameters(const std::vector< TrackingParameters > &trkPars)
virtual void adoptTimeFrame(TimeFrame< nLayers > *tf)
void setCorrType(const o2::base::PropagatorImpl< float >::MatCorrType type)
virtual bool supportsFindShortPrimaries() const noexcept
virtual bool supportsExtendTracks() const noexcept
virtual const char * getName() const noexcept
virtual int getTFNumberOfCells() const
void printSummary() const
void getGlobalConfiguration()
void adoptTimeFrame(TimeFrame< NLayers > &tf)
Tracker(TrackerTraits< NLayers > *traits)
void clustersToTracks(LogFunc=[](const std::string &s) { std::cout<< s<< '\n';}, LogFunc=[](const std::string &s) { std::cerr<< s<< '\n';})
GLenum const GLfloat * params
GLuint GLsizei const GLchar * label
constexpr int UnusedIndex
constexpr bool DoTimeBenchmarks
std::unique_ptr< GPUReconstructionTimeframe > tf
bool hasMCinformation() const
size_t getNumberOfTracks() const
int getClusterExternalIndex(int layerId, const int clId) const
int mNExtendedUsedClusters
gsl::span< const Vertex > getPrimaryVertices(int rofId) const
void initialiseRoadLabels()
gsl::span< const MCCompLabel > getClusterLabels(int layerId, const Cluster &cl) const
unsigned long getArtefactsMemory() const
int getNumberOfNeighbours() const
void printArtefactsMemory() const
auto & getTracksLabel(const int rofId)
void setRoadLabel(int i, const unsigned long long &lab, bool fake)
std::array< uint16_t, 5 > pattern