Project
Loading...
Searching...
No Matches
Vertexer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
15
18#include "ITStracking/Cluster.h"
19
25
26namespace o2::its
27{
28
29Vertexer::Vertexer(VertexerTraits* traits) : mTraits(traits)
30{
31 if (!mTraits) {
32 LOG(fatal) << "nullptr passed to ITS vertexer construction.";
33 }
34 mVertParams.resize(1);
35}
36
37float Vertexer::clustersToVertices(LogFunc logger)
38{
39 LogFunc evalLog = [](const std::string&) {};
40
41 if (mTimeFrame->hasMCinformation() && mVertParams[0].useTruthSeeding) {
42 return evaluateTask(&Vertexer::addTruthSeeds, StateNames[mCurState = TruthSeeding], 0, evalLog);
43 }
44
45 TrackingParameters trkPars;
47 mTraits->updateVertexingParameters(mVertParams, tfGPUpar);
48
49 auto handleException = [&](const auto& err) {
50 LOGP(error, "Encountered critical error in step {}, stopping further processing of this TF: {}", StateNames[mCurState], err.what());
51 if (!mVertParams[0].DropTFUponFailure) {
52 throw err;
53 } else {
54 LOGP(error, "Dropping this TF!");
55 mTimeFrame->resetTracklets();
56 }
57 };
58
59 float timeTracklet{0.f}, timeSelection{0.f}, timeVertexing{0.f}, timeInit{0.f};
60 try {
61 for (int iteration = 0; iteration < std::min(mVertParams[0].nIterations, (int)mVertParams.size()); ++iteration) {
62 mMemoryPool->setMaxMemory(mVertParams[iteration].MaxMemory);
63 unsigned int nTracklets01{0}, nTracklets12{0};
64 logger(fmt::format("=== ITS {} Seeding vertexer iteration {} summary:", mTraits->getName(), iteration));
65 trkPars.PhiBins = mTraits->getVertexingParameters()[0].PhiBins;
66 trkPars.ZBins = mTraits->getVertexingParameters()[0].ZBins;
67 auto timeInitIteration = evaluateTask(&Vertexer::initialiseVertexer, StateNames[mCurState = Init], iteration, evalLog, trkPars, iteration);
68 auto timeTrackletIteration = evaluateTask(&Vertexer::findTracklets, StateNames[mCurState = Trackleting], iteration, evalLog, iteration);
69 nTracklets01 = mTimeFrame->getTotalTrackletsTF(0);
70 nTracklets12 = mTimeFrame->getTotalTrackletsTF(1);
71 auto timeSelectionIteration = evaluateTask(&Vertexer::validateTracklets, StateNames[mCurState = Validating], iteration, evalLog, iteration);
72 auto timeVertexingIteration = evaluateTask(&Vertexer::findVertices, StateNames[mCurState = Finding], iteration, evalLog, iteration);
73 printEpilog(logger, nTracklets01, nTracklets12, mTimeFrame->getNLinesTotal(), mTimeFrame->getTotVertIteration()[iteration], timeInitIteration, timeTrackletIteration, timeSelectionIteration, timeVertexingIteration);
74 timeInit += timeInitIteration;
75 timeTracklet += timeTrackletIteration;
76 timeSelection += timeSelectionIteration;
77 timeVertexing += timeVertexingIteration;
78 }
80 handleException(err);
81 } catch (const std::bad_alloc& err) {
82 handleException(err);
83 } catch (...) {
84 LOGP(fatal, "Uncaught exception!");
85 }
86
87 return timeInit + timeTracklet + timeSelection + timeVertexing;
88}
89
91{
92 mTimeFrame = &tf;
93 mTraits->adoptTimeFrame(&tf);
94}
95
96void Vertexer::printEpilog(LogFunc& logger,
97 const unsigned int trackletN01, const unsigned int trackletN12,
98 const unsigned selectedN, const unsigned int vertexN, const float initT,
99 const float trackletT, const float selecT, const float vertexT)
100{
101 logger(fmt::format(" - {} Vertexer: found {} | {} tracklets in: {} ms", mTraits->getName(), trackletN01, trackletN12, trackletT));
102 logger(fmt::format(" - {} Vertexer: selected {} tracklets in: {} ms", mTraits->getName(), selectedN, selecT));
103 logger(fmt::format(" - {} Vertexer: found {} vertices in: {} ms", mTraits->getName(), vertexN, vertexT));
104 if (mVertParams[0].PrintMemory) {
105 mTimeFrame->printArtefactsMemory();
106 mMemoryPool->print();
107 }
108}
109
110} // namespace o2::its
Class to compute the primary vertex in ITS from tracklets.
virtual void adoptTimeFrame(TimeFrame7 *tf) noexcept
virtual const char * getName() const noexcept
virtual void updateVertexingParameters(const std::vector< VertexingParameters > &vrtPar, const TimeFrameGPUParameters &gpuTfPar)
void findTracklets(T &&... args)
Definition Vertexer.h:119
void initialiseVertexer(T &&... args)
Definition Vertexer.h:113
void validateTracklets(T &&... args)
Definition Vertexer.h:125
void findVertices(T &&... args)
Definition Vertexer.h:131
void adoptTimeFrame(TimeFrame7 &tf)
Definition Vertexer.cxx:90
float evaluateTask(void(Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc &logger, T &&... args)
Definition Vertexer.h:137
float clustersToVertices(LogFunc=[](const std::string &s) { std::cout<< s<< '\n';})
Definition Vertexer.cxx:37
void addTruthSeeds()
Definition Vertexer.h:72
Vertexer(VertexerTraits *traits)
Definition Vertexer.cxx:29
void printEpilog(LogFunc &logger, const unsigned int trackletN01, const unsigned int trackletN12, const unsigned selectedN, const unsigned int vertexN, const float initT, const float trackletT, const float selecT, const float vertexT)
Definition Vertexer.cxx:96
std::unique_ptr< GPUReconstructionTimeframe > tf
bool hasMCinformation() const
Definition TimeFrame.h:150
int getNLinesTotal() const
Definition TimeFrame.h:206
auto & getTotVertIteration()
Definition TimeFrame.h:100
void printArtefactsMemory() const
uint32_t getTotalTrackletsTF(const int iLayer)
Definition TimeFrame.h:216
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"