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 <string>
21#include <vector>
22
24#include "ITStracking/Cluster.h"
32
33#include "GPUCommonDef.h"
34#include "GPUCommonMath.h"
35
36#include <oneapi/tbb/task_arena.h>
37
38namespace o2
39{
40class MCCompLabel;
41
42namespace its
43{
44class ROframe;
46
47enum class TrackletMode {
48 Layer0Layer1 = 0,
49 Layer1Layer2 = 2
50};
51
53{
54 static constexpr int NLayers{7};
56
57 public:
58 VertexerTraits() = default;
59 virtual ~VertexerTraits() = default;
60
61 GPUhdi() static consteval int4 getEmptyBinsRect()
62 {
63 return int4{0, 0, 0, 0};
64 }
65 GPUhd() const int4 getBinsRect(const Cluster&, const int, const float, float maxdeltaz, float maxdeltaphi);
66 GPUhd() static const int4 getBinsRect(const Cluster&, const int, const float, float maxdeltaz, float maxdeltaphi, const IndexTableUtils&);
67 GPUhd() static const int2 getPhiBins(float phi, float deltaPhi, const IndexTableUtils&);
68 GPUhd() const int2 getPhiBins(float phi, float deltaPhi) { return getPhiBins(phi, deltaPhi, mIndexTableUtils); }
69
70 // virtual vertexer interface
71 virtual void initialise(const TrackingParameters& trackingParams, const int iteration = 0);
72 virtual void computeTracklets(const int iteration = 0);
73 virtual void computeTrackletMatching(const int iteration = 0);
74 virtual void computeVertices(const int iteration = 0);
75 virtual void adoptTimeFrame(TimeFrame7* tf) noexcept { mTimeFrame = tf; }
76 virtual void updateVertexingParameters(const std::vector<VertexingParameters>& vrtPar, const TimeFrameGPUParameters& gpuTfPar);
77
78 void computeVerticesInRof(int,
79 gsl::span<const o2::its::Line>&,
82 std::array<float, 2>&,
85 TimeFrame7*,
87 const int iteration = 0);
88
89 const bounded_vector<std::pair<int, int>> selectClusters(const int* indexTable,
90 const std::array<int, 4>& selectedBinsRect,
91 const IndexTableUtils& utils);
92
93 // utils
95 auto getVertexingParameters() const { return mVrtParams; }
96 void setVertexingParameters(std::vector<VertexingParameters>& vertParams) { mVrtParams = vertParams; }
98 void setNThreads(int n);
99 int getNThreads() const { return mNThreads; }
100 virtual bool isGPU() const noexcept { return false; }
101 virtual const char* getName() const noexcept { return "CPU"; }
102 virtual bool usesMemoryPool() const noexcept { return true; }
103 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool) { mMemoryPool = pool; }
104
105 template <typename T = o2::MCCompLabel>
106 static std::pair<T, float> computeMain(const bounded_vector<T>& elements)
107 {
108 T elem;
109 size_t maxCount = 0;
110 for (auto& element : elements) {
111 size_t count = std::count(elements.begin(), elements.end(), element);
112 if (count > maxCount) {
113 maxCount = count;
114 elem = element;
115 }
116 }
117 return std::make_pair(elem, static_cast<float>(maxCount) / elements.size());
118 }
119
120 protected:
121 int mNThreads = 1;
122
123 std::vector<VertexingParameters> mVrtParams;
125
126 // Frame related quantities
127 TimeFrame7* mTimeFrame = nullptr; // observer ptr
128 private:
129 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
130 tbb::task_arena mTaskArena;
131};
132
133inline void VertexerTraits::initialise(const TrackingParameters& trackingParams, const int iteration)
134{
135 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.
136}
137
138GPUhdi() const int2 VertexerTraits::getPhiBins(float phi, float dPhi, const IndexTableUtils& utils)
139{
140 return int2{utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi - dPhi)),
141 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi + dPhi))};
142}
143
144GPUhdi() const int4 VertexerTraits::getBinsRect(const Cluster& currentCluster, const int layerIndex,
145 const float directionZIntersection, float maxdeltaz, float maxdeltaphi,
146 const IndexTableUtils& utils)
147{
148 const float zRangeMin = directionZIntersection - 2 * maxdeltaz;
149 const float phiRangeMin = currentCluster.phi - maxdeltaphi;
150 const float zRangeMax = directionZIntersection + 2 * maxdeltaz;
151 const float phiRangeMax = currentCluster.phi + maxdeltaphi;
152
153 if (zRangeMax < -utils.getLayerZ(layerIndex + 1) ||
154 zRangeMin > utils.getLayerZ(layerIndex + 1) || zRangeMin > zRangeMax) {
155 return getEmptyBinsRect();
156 }
157
158 return int4{o2::gpu::GPUCommonMath::Max(0, utils.getZBinIndex(layerIndex + 1, zRangeMin)),
159 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMin)),
160 o2::gpu::GPUCommonMath::Min(utils.getNzBins() - 1, utils.getZBinIndex(layerIndex + 1, zRangeMax)),
161 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMax))};
162}
163
164GPUhdi() const int4 VertexerTraits::getBinsRect(const Cluster& currentCluster, const int layerIndex,
165 const float directionZIntersection, float maxdeltaz, float maxdeltaphi)
166{
167 return VertexerTraits::getBinsRect(currentCluster, layerIndex, directionZIntersection, maxdeltaz, maxdeltaphi, mIndexTableUtils);
168}
169
170} // namespace its
171} // namespace o2
172#endif
HMPID cluster implementation.
Definition Cluster.h:27
auto getVertexingParameters() const
const const float float const IndexTableUtils float deltaPhi
virtual void computeTrackletMatching(const int iteration=0)
virtual void computeTracklets(const int iteration=0)
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
static std::pair< T, float > computeMain(const bounded_vector< T > &elements)
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)
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > &pool)
const const float maxdeltaz
const bounded_vector< std::pair< int, int > > selectClusters(const int *indexTable, const std::array< int, 4 > &selectedBinsRect, const IndexTableUtils &utils)
GLdouble n
Definition glcorearb.h:1982
GLint GLsizei count
Definition glcorearb.h:399
constexpr int LayersNumberVertexer
Definition Constants.h:52
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)