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
20
21namespace o2::its
22{
23
24template <int NLayers>
26{
27 if (!mTraits) {
28 LOG(fatal) << "nullptr passed to ITS vertexer construction.";
29 }
30 mVertParams.resize(1);
31}
32
33template <int NLayers>
35{
36 LogFunc evalLog = [](const std::string&) {};
37
38 if (mTimeFrame->hasMCinformation() && mVertParams[0].useTruthSeeding) {
39 float t = evaluateTask(&Vertexer::addTruthSeeds, StateNames[mCurStep = TruthSeeding], 0, evalLog);
40 sortVertices();
41 ++mTimeFrameCounter;
42 return t;
43 }
44
45 TrackingParameters trkPars;
46 mTraits->updateVertexingParameters(mVertParams);
47
48 auto handleException = [&](const auto& err) {
49 LOGP(error, "Encountered critical error in step {}, stopping further processing of this TF: {}", StateNames[mCurStep], err.what());
50 if (!mVertParams[0].DropTFUponFailure) {
51 throw err;
52 } else {
53 LOGP(error, "Dropping this TF!");
54 }
55 };
56
57 float timeTracklet{0.f}, timeSelection{0.f}, timeVertexing{0.f}, timeInit{0.f};
58 bool completed = false;
59 try {
60 for (int iteration = 0; iteration < (int)mVertParams.size(); ++iteration) {
61 mMemoryPool->setMaxMemory(mVertParams[iteration].MaxMemory);
62 unsigned int nTracklets01{0}, nTracklets12{0};
63 logger(fmt::format("=== ITS {} Seeding vertexer iteration {} summary:", mTraits->getName(), iteration));
64 const auto& currentVtxPars = mTraits->getVertexingParameters()[iteration];
65 trkPars.PhiBins = currentVtxPars.PhiBins;
66 trkPars.ZBins = currentVtxPars.ZBins;
67 trkPars.LayerZ = currentVtxPars.LayerZ;
68 trkPars.LayerRadii = currentVtxPars.LayerRadii;
69 trkPars.PassFlags = mVertParams[iteration].PassFlags;
71 auto timeInitIteration = evaluateTask(&Vertexer::initialiseVertexer, StateNames[mCurStep = Init], iteration, evalLog, trkPars);
72 auto timeTrackletIteration = evaluateTask(&Vertexer::findTracklets, StateNames[mCurStep = Trackleting], iteration, evalLog, iteration);
73 nTracklets01 = mTimeFrame->getTotalTrackletsTF(0);
74 nTracklets12 = mTimeFrame->getTotalTrackletsTF(1);
75 auto timeSelectionIteration = evaluateTask(&Vertexer::validateTracklets, StateNames[mCurStep = Selection], iteration, evalLog, iteration);
76 const auto nVerticesBefore = mTimeFrame->getPrimaryVertices().size();
77 auto timeVertexingIteration = evaluateTask(&Vertexer::findVertices, StateNames[mCurStep = Finding], iteration, evalLog, iteration);
78 const auto nVerticesAfter = mTimeFrame->getPrimaryVertices().size();
79 printEpilog(logger, nTracklets01, nTracklets12, mTimeFrame->getNLinesTotal(), nVerticesAfter - nVerticesBefore, nVerticesAfter, timeInitIteration, timeTrackletIteration, timeSelectionIteration, timeVertexingIteration);
80 timeInit += timeInitIteration;
81 timeTracklet += timeTrackletIteration;
82 timeSelection += timeSelectionIteration;
83 timeVertexing += timeVertexingIteration;
84
85 // update LUT with all currently found vertices so in second iteration we can check vertPerROFThreshold
86 sortVertices();
87 }
88 completed = true;
90 handleException(err);
91 } catch (const std::bad_alloc& err) {
92 handleException(err);
93 } catch (...) {
94 LOGP(fatal, "Uncaught exception!");
95 }
96
97 if (completed) {
98 ++mTimeFrameCounter;
99 }
100
101 return timeInit + timeTracklet + timeSelection + timeVertexing;
102}
103
104template <int NLayers>
106{
107 auto& pvs = mTimeFrame->getPrimaryVertices();
108 bounded_vector<size_t> indices(pvs.size(), mMemoryPool.get());
109 std::iota(indices.begin(), indices.end(), 0);
110 // provide vertices sorted by lower-bound
111 std::sort(indices.begin(), indices.end(), [&pvs](size_t i, size_t j) {
112 const auto& a = pvs[i].getTimeStamp();
113 const auto& b = pvs[j].getTimeStamp();
114 const auto aLower = a.lower();
115 const auto bLower = b.lower();
116 if (aLower != bLower) {
117 return aLower < bLower;
118 }
119 return pvs[i].getNContributors() > pvs[j].getNContributors();
120 });
121 bounded_vector<Vertex> sortedVtx(mMemoryPool.get());
122 sortedVtx.reserve(pvs.size());
123 for (const size_t idx : indices) {
124 sortedVtx.push_back(pvs[idx]);
125 }
126 pvs.swap(sortedVtx);
127 if (mTimeFrame->hasMCinformation()) {
128 auto& mc = mTimeFrame->getPrimaryVerticesLabels();
129 bounded_vector<VertexLabel> sortedMC(mMemoryPool.get());
130 for (const size_t idx : indices) {
131 sortedMC.push_back(mc[idx]);
132 }
133 mc.swap(sortedMC);
134 }
135 // update LUT after sorting
136 mTimeFrame->updateROFVertexLookupTable();
137}
138
139template <int NLayers>
141{
142 mTimeFrame = &tf;
143 mTraits->adoptTimeFrame(&tf);
144}
145
146template <int NLayers>
147void Vertexer<NLayers>::addTimingStatCurStep(int iteration, double timeMs)
148{
149 if (iteration < 0) {
150 return;
151 }
152 if (mTimingStats.size() < (iteration + 1)) {
153 mTimingStats.resize(iteration + 1);
154 }
155 mTimingStats[iteration][mCurStep].add(timeMs);
156}
157
158template <int NLayers>
160{
161 LOGP(info, "Vertexer summary: Processed {} TFs", mTimeFrameCounter);
162 for (size_t iteration = 0; iteration < mTimingStats.size(); ++iteration) {
163 for (size_t state = 0; state < NSteps; ++state) {
164 const auto& stats = mTimingStats[iteration][state];
165 if (!stats.calls) {
166 continue;
167 }
168 LOGP(info, " - iter {} {}: calls={} total={:.2f} ms avg={:.2f} ms", iteration, StateNames[state], stats.calls, stats.totalTimeMs, stats.averageTimeMs());
169 }
170 }
171}
172
173template <int NLayers>
175 unsigned int trackletN01, unsigned int trackletN12,
176 unsigned selectedN, unsigned int vertexN, unsigned int totalVertexN,
177 float initT, float trackletT, float selecT, float vertexT)
178{
179 logger(fmt::format(" - {}: completed in {:.2f} ms", StateNames[Init], initT));
180 logger(fmt::format(" - {}: found {} | {} tracklets in {:.2f} ms", StateNames[Trackleting], trackletN01, trackletN12, trackletT));
181 logger(fmt::format(" - {}: selected {} tracklets in {:.2f} ms", StateNames[Selection], selectedN, selecT));
182 logger(fmt::format(" - {}: found {} vertices (total {}) in {:.2f} ms", StateNames[Finding], vertexN, totalVertexN, vertexT));
183}
184
185template class Vertexer<7>;
186
187} // namespace o2::its
benchmark::State & state
int32_t i
uint32_t j
Definition RawData.h:0
Class to compute the primary vertex in ITS from tracklets.
void initialiseVertexer(T &&... args)
Definition Vertexer.h:80
Vertexer(VertexerTraitsN *traits)
Definition Vertexer.cxx:25
void addTruthSeeds()
Definition Vertexer.h:77
void adoptTimeFrame(TimeFrameN &tf)
Definition Vertexer.cxx:140
void validateTracklets(T &&... args)
Definition Vertexer.h:67
float clustersToVertices(LogFunc=[](const std::string &s) { std::cout<< s<< '\n';})
Definition Vertexer.cxx:34
void findTracklets(T &&... args)
Definition Vertexer.h:62
void findVertices(T &&... args)
Definition Vertexer.h:72
void set(const std::string &s, int base=DefaultBase)
Definition EnumFlags.h:435
GLsizei GLenum const void * indices
Definition glcorearb.h:400
std::pmr::vector< T > bounded_vector
std::unique_ptr< GPUReconstructionTimeframe > tf
std::vector< float > LayerRadii
std::vector< float > LayerZ
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"