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
29template <int NLayers>
31{
32 if (!mTraits) {
33 LOG(fatal) << "nullptr passed to ITS vertexer construction.";
34 }
35 mVertParams.resize(1);
36}
37
38template <int NLayers>
40{
41 LogFunc evalLog = [](const std::string&) {};
42
43 if (mTimeFrame->hasMCinformation() && mVertParams[0].useTruthSeeding) {
44 float t = evaluateTask(&Vertexer::addTruthSeeds, StateNames[mCurState = TruthSeeding], 0, evalLog);
45 sortVertices();
46 return t;
47 }
48
49 TrackingParameters trkPars;
50 mTraits->updateVertexingParameters(mVertParams);
51
52 auto handleException = [&](const auto& err) {
53 LOGP(error, "Encountered critical error in step {}, stopping further processing of this TF: {}", StateNames[mCurState], err.what());
54 if (!mVertParams[0].DropTFUponFailure) {
55 throw err;
56 } else {
57 LOGP(error, "Dropping this TF!");
58 }
59 };
60
61 float timeTracklet{0.f}, timeSelection{0.f}, timeVertexing{0.f}, timeInit{0.f};
62 try {
63 for (int iteration = 0; iteration < (int)mVertParams.size(); ++iteration) {
64 mMemoryPool->setMaxMemory(mVertParams[iteration].MaxMemory);
65 unsigned int nTracklets01{0}, nTracklets12{0};
66 logger(fmt::format("=== ITS {} Seeding vertexer iteration {} summary:", mTraits->getName(), iteration));
67 trkPars.PhiBins = mTraits->getVertexingParameters()[0].PhiBins;
68 trkPars.ZBins = mTraits->getVertexingParameters()[0].ZBins;
69 auto timeInitIteration = evaluateTask(&Vertexer::initialiseVertexer, StateNames[mCurState = Init], iteration, evalLog, trkPars, iteration);
70 auto timeTrackletIteration = evaluateTask(&Vertexer::findTracklets, StateNames[mCurState = Trackleting], iteration, evalLog, iteration);
71 nTracklets01 = mTimeFrame->getTotalTrackletsTF(0);
72 nTracklets12 = mTimeFrame->getTotalTrackletsTF(1);
73 auto timeSelectionIteration = evaluateTask(&Vertexer::validateTracklets, StateNames[mCurState = Validating], iteration, evalLog, iteration);
74 const auto nVerticesBefore = mTimeFrame->getPrimaryVertices().size();
75 auto timeVertexingIteration = evaluateTask(&Vertexer::findVertices, StateNames[mCurState = Finding], iteration, evalLog, iteration);
76 const auto nVerticesAfter = mTimeFrame->getPrimaryVertices().size();
77 printEpilog(logger, nTracklets01, nTracklets12, mTimeFrame->getNLinesTotal(), nVerticesAfter - nVerticesBefore, nVerticesAfter, timeTrackletIteration, timeSelectionIteration, timeVertexingIteration);
78 timeInit += timeInitIteration;
79 timeTracklet += timeTrackletIteration;
80 timeSelection += timeSelectionIteration;
81 timeVertexing += timeVertexingIteration;
82
83 // update LUT with all currently found vertices so in second iteration we can check vertPerROFThreshold
84 sortVertices();
85 mTimeFrame->updateROFVertexLookupTable();
86 }
88 handleException(err);
89 } catch (const std::bad_alloc& err) {
90 handleException(err);
91 } catch (...) {
92 LOGP(fatal, "Uncaught exception!");
93 }
94
95 return timeInit + timeTracklet + timeSelection + timeVertexing;
96}
97
98template <int NLayers>
100{
101 auto& pvs = mTimeFrame->getPrimaryVertices();
102 bounded_vector<size_t> indices(pvs.size(), mMemoryPool.get());
103 std::iota(indices.begin(), indices.end(), 0);
104 // provide vertices sorted by lower-bound
105 std::sort(indices.begin(), indices.end(), [&pvs](size_t i, size_t j) {
106 const auto& a = pvs[i].getTimeStamp();
107 const auto& b = pvs[j].getTimeStamp();
108 const auto aLower = a.lower();
109 const auto bLower = b.lower();
110 if (aLower != bLower) {
111 return aLower < bLower;
112 }
113 return pvs[i].getNContributors() > pvs[j].getNContributors();
114 });
115 bounded_vector<Vertex> sortedVtx(mMemoryPool.get());
116 sortedVtx.reserve(pvs.size());
117 for (const size_t idx : indices) {
118 sortedVtx.push_back(pvs[idx]);
119 }
120 pvs.swap(sortedVtx);
121 if (mTimeFrame->hasMCinformation()) {
122 auto& mc = mTimeFrame->getPrimaryVerticesLabels();
123 bounded_vector<VertexLabel> sortedMC(mMemoryPool.get());
124 for (const size_t idx : indices) {
125 sortedMC.push_back(mc[idx]);
126 }
127 mc.swap(sortedMC);
128 }
129}
130
131template <int NLayers>
133{
134 mTimeFrame = &tf;
135 mTraits->adoptTimeFrame(&tf);
136}
137
138template <int NLayers>
140 const unsigned int trackletN01, const unsigned int trackletN12,
141 const unsigned selectedN, const unsigned int vertexN, const unsigned int totalVertexN,
142 const float trackletT, const float selecT, const float vertexT)
143{
144 logger(fmt::format(" - {} Vertexer: found {} | {} tracklets in: {:.2f} ms", mTraits->getName(), trackletN01, trackletN12, trackletT));
145 logger(fmt::format(" - {} Vertexer: selected {} tracklets in: {:.2f} ms", mTraits->getName(), selectedN, selecT));
146 logger(fmt::format(" - {} Vertexer: found {} vertices (total: {}) in: {:.2f} ms", mTraits->getName(), vertexN, totalVertexN, vertexT));
147}
148
149template class Vertexer<7>;
150
151} // namespace o2::its
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:79
Vertexer(VertexerTraitsN *traits)
Definition Vertexer.cxx:30
void addTruthSeeds()
Definition Vertexer.h:76
void adoptTimeFrame(TimeFrameN &tf)
Definition Vertexer.cxx:132
void validateTracklets(T &&... args)
Definition Vertexer.h:66
float clustersToVertices(LogFunc=[](const std::string &s) { std::cout<< s<< '\n';})
Definition Vertexer.cxx:39
void findTracklets(T &&... args)
Definition Vertexer.h:61
void findVertices(T &&... args)
Definition Vertexer.h:71
GLsizei GLenum const void * indices
Definition glcorearb.h:400
std::pmr::vector< T > bounded_vector
std::unique_ptr< GPUReconstructionTimeframe > tf
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"