Project
Loading...
Searching...
No Matches
VertexerTraits.h
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
16#ifndef O2_ITS_TRACKING_VERTEXER_TRAITS_H_
17#define O2_ITS_TRACKING_VERTEXER_TRAITS_H_
18
19#include <array>
20#include <memory>
21#include <string>
22#include <vector>
23
25#include "ITStracking/Cluster.h"
33
34#include "GPUCommonDef.h"
35#include "GPUCommonMath.h"
36
37#include <oneapi/tbb/task_arena.h>
38
39namespace o2
40{
41class MCCompLabel;
42
43namespace its
44{
45
46enum class TrackletMode {
47 Layer0Layer1 = 0,
48 Layer1Layer2 = 2
49};
50
52{
53 static constexpr int NLayers{7};
55
56 public:
57 VertexerTraits() = default;
58 virtual ~VertexerTraits() = default;
59
60 GPUhdi() static consteval int4 getEmptyBinsRect()
61 {
62 return int4{0, 0, 0, 0};
63 }
64 GPUhd() const int4 getBinsRect(const Cluster&, const int, const float, float maxdeltaz, float maxdeltaphi);
65 GPUhd() static const int4 getBinsRect(const Cluster&, const int, const float, float maxdeltaz, float maxdeltaphi, const IndexTableUtils&);
66 GPUhd() static const int2 getPhiBins(float phi, float deltaPhi, const IndexTableUtils&);
67 GPUhd() const int2 getPhiBins(float phi, float deltaPhi) { return getPhiBins(phi, deltaPhi, mIndexTableUtils); }
68
69 // virtual vertexer interface
70 virtual void initialise(const TrackingParameters& trackingParams, const int iteration = 0);
71 virtual void computeTracklets(const int iteration = 0);
72 virtual void computeTrackletMatching(const int iteration = 0);
73 virtual void computeVertices(const int iteration = 0);
74 virtual void adoptTimeFrame(TimeFrame7* tf) noexcept { mTimeFrame = tf; }
75 virtual void updateVertexingParameters(const std::vector<VertexingParameters>& vrtPar, const TimeFrameGPUParameters& gpuTfPar);
76
77 void computeVerticesInRof(int,
78 gsl::span<const o2::its::Line>&,
81 std::array<float, 2>&,
84 TimeFrame7*,
86 const int iteration = 0);
87
89 const std::array<int, 4>& selectedBinsRect,
90 const IndexTableUtils& utils);
91
92 // utils
94 auto getVertexingParameters() const { return mVrtParams; }
95 void setVertexingParameters(std::vector<VertexingParameters>& vertParams) { mVrtParams = vertParams; }
97 void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena);
98 int getNThreads() { return mTaskArena->max_concurrency(); }
99 virtual bool isGPU() const noexcept { return false; }
100 virtual const char* getName() const noexcept { return "CPU"; }
101 virtual bool usesMemoryPool() const noexcept { return true; }
102 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool) { mMemoryPool = pool; }
103
104 static std::pair<o2::MCCompLabel, float> computeMain(const bounded_vector<o2::MCCompLabel>& elements)
105 {
106 // we only care about the source&event of the tracks, not the trackId
107 auto composeVtxLabel = [](const o2::MCCompLabel& lbl) -> o2::MCCompLabel {
108 return {o2::MCCompLabel::maxTrackID(), lbl.getEventID(), lbl.getSourceID(), lbl.isFake()};
109 };
110 std::unordered_map<o2::MCCompLabel, size_t> frequency;
111 for (const auto& element : elements) {
112 ++frequency[composeVtxLabel(element)];
113 }
114 o2::MCCompLabel elem{};
115 size_t maxCount = 0;
116 for (const auto& [key, count] : frequency) {
117 if (count > maxCount) {
118 maxCount = count;
119 elem = key;
120 }
121 }
122 return std::make_pair(elem, static_cast<float>(maxCount) / static_cast<float>(elements.size()));
123 }
124
125 protected:
126 std::vector<VertexingParameters> mVrtParams;
128
129 // Frame related quantities
130 TimeFrame7* mTimeFrame = nullptr; // observer ptr
131 private:
132 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
133 std::shared_ptr<tbb::task_arena> mTaskArena;
134};
135
136inline void VertexerTraits::initialise(const TrackingParameters& trackingParams, const int iteration)
137{
138 mTimeFrame->initialise(0, trackingParams, 3, (bool)(!iteration)); // iteration for initialisation must be 0 for correctly resetting the frame, we need to pass the non-reset flag for vertices as well, tho.
139}
140
141GPUhdi() const int2 VertexerTraits::getPhiBins(float phi, float dPhi, const IndexTableUtils& utils)
142{
143 return int2{utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi - dPhi)),
144 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi + dPhi))};
145}
146
147GPUhdi() const int4 VertexerTraits::getBinsRect(const Cluster& currentCluster, const int layerIndex,
148 const float directionZIntersection, float maxdeltaz, float maxdeltaphi,
149 const IndexTableUtils& utils)
150{
151 const float zRangeMin = directionZIntersection - 2 * maxdeltaz;
152 const float phiRangeMin = currentCluster.phi - maxdeltaphi;
153 const float zRangeMax = directionZIntersection + 2 * maxdeltaz;
154 const float phiRangeMax = currentCluster.phi + maxdeltaphi;
155
156 if (zRangeMax < -utils.getLayerZ(layerIndex + 1) ||
157 zRangeMin > utils.getLayerZ(layerIndex + 1) || zRangeMin > zRangeMax) {
158 return getEmptyBinsRect();
159 }
160
161 return int4{o2::gpu::GPUCommonMath::Max(0, utils.getZBinIndex(layerIndex + 1, zRangeMin)),
162 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMin)),
163 o2::gpu::GPUCommonMath::Min(utils.getNzBins() - 1, utils.getZBinIndex(layerIndex + 1, zRangeMax)),
164 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMax))};
165}
166
167GPUhdi() const int4 VertexerTraits::getBinsRect(const Cluster& currentCluster, const int layerIndex,
168 const float directionZIntersection, float maxdeltaz, float maxdeltaphi)
169{
170 return VertexerTraits::getBinsRect(currentCluster, layerIndex, directionZIntersection, maxdeltaz, maxdeltaphi, mIndexTableUtils);
171}
172
173} // namespace its
174} // namespace o2
175#endif
StringRef key
static constexpr int maxTrackID()
HMPID cluster implementation.
Definition Cluster.h:27
auto getVertexingParameters() const
const const float float const IndexTableUtils float deltaPhi
bounded_vector< std::pair< int, int > > selectClusters(const int *indexTable, const std::array< int, 4 > &selectedBinsRect, const IndexTableUtils &utils)
virtual void computeTrackletMatching(const int iteration=0)
virtual void computeTracklets(const int iteration=0)
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
GPUhdi() static const eval int4 getEmptyBinsRect()
void setVertexingParameters(std::vector< VertexingParameters > &vertParams)
virtual bool isGPU() const noexcept
virtual void initialise(const TrackingParameters &trackingParams, const int iteration=0)
virtual void computeVertices(const int iteration=0)
const const float float const IndexTableUtils & GPUhd() static const int2 getPhiBins(float phi
virtual void adoptTimeFrame(TimeFrame7 *tf) noexcept
virtual ~VertexerTraits()=default
virtual const char * getName() const noexcept
const const float float maxdeltaphi
std::vector< VertexingParameters > mVrtParams
IndexTableUtils mIndexTableUtils
void computeVerticesInRof(int, gsl::span< const o2::its::Line > &, bounded_vector< bool > &, bounded_vector< o2::its::ClusterLines > &, std::array< float, 2 > &, bounded_vector< Vertex > &, bounded_vector< int > &, TimeFrame7 *, bounded_vector< o2::MCCompLabel > *, const int iteration=0)
virtual bool usesMemoryPool() const noexcept
virtual void updateVertexingParameters(const std::vector< VertexingParameters > &vrtPar, const TimeFrameGPUParameters &gpuTfPar)
static std::pair< o2::MCCompLabel, float > computeMain(const bounded_vector< o2::MCCompLabel > &elements)
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > &pool)
const const float maxdeltaz
GLdouble n
Definition glcorearb.h:1982
GLint GLsizei count
Definition glcorearb.h:399
std::pmr::vector< T > bounded_vector
GPUhdi() Line
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Common utility functions.
std::unique_ptr< GPUReconstructionTimeframe > tf
void initialise(const int iteration, const TrackingParameters &trkParam, const int maxLayers=7, bool resetVertices=true)