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
51template <int nLayers>
53{
54 using IndexTableUtilsN = IndexTableUtils<nLayers>;
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 IndexTableUtilsN&);
67 GPUhd() static const int2 getPhiBins(float phi, float deltaPhi, const IndexTableUtilsN&);
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(TimeFrameN* tf) noexcept { mTimeFrame = tf; }
76 virtual void updateVertexingParameters(const std::vector<VertexingParameters>& vrtPar, const TimeFrameGPUParameters& gpuTfPar);
77
78 // truth tracking
80
81 // utils
83 auto getVertexingParameters() const { return mVrtParams; }
84 void setVertexingParameters(std::vector<VertexingParameters>& vertParams) { mVrtParams = vertParams; }
85 void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena);
86 int getNThreads() { return mTaskArena->max_concurrency(); }
87 virtual bool isGPU() const noexcept { return false; }
88 virtual const char* getName() const noexcept { return "CPU"; }
89 virtual bool usesMemoryPool() const noexcept { return true; }
90 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool) { mMemoryPool = pool; }
91
92 static std::pair<o2::MCCompLabel, float> computeMain(const bounded_vector<o2::MCCompLabel>& elements)
93 {
94 // we only care about the source&event of the tracks, not the trackId
95 auto composeVtxLabel = [](const o2::MCCompLabel& lbl) -> o2::MCCompLabel {
96 return {o2::MCCompLabel::maxTrackID(), lbl.getEventID(), lbl.getSourceID(), lbl.isFake()};
97 };
98 std::unordered_map<o2::MCCompLabel, size_t> frequency;
99 for (const auto& element : elements) {
100 ++frequency[composeVtxLabel(element)];
101 }
102 o2::MCCompLabel elem{};
103 size_t maxCount = 0;
104 for (const auto& [key, count] : frequency) {
105 if (count > maxCount) {
106 maxCount = count;
107 elem = key;
108 }
109 }
110 return std::make_pair(elem, static_cast<float>(maxCount) / static_cast<float>(elements.size()));
111 }
112
113 protected:
114 std::vector<VertexingParameters> mVrtParams;
115 IndexTableUtilsN mIndexTableUtils;
116
117 // Frame related quantities
118 TimeFrameN* mTimeFrame = nullptr; // observer ptr
119 private:
120 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
121 std::shared_ptr<tbb::task_arena> mTaskArena;
122
123 // debug output
124 void debugComputeTracklets(int iteration);
125 void debugComputeTrackletMatching(int iteration);
126 void debugComputeVertices(int iteration);
127};
128
129template <int nLayers>
130inline void VertexerTraits<nLayers>::initialise(const TrackingParameters& trackingParams, const int iteration)
131{
132 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.
133}
134
135template <int nLayers>
136GPUhdi() const int2 VertexerTraits<nLayers>::getPhiBins(float phi, float dPhi, const IndexTableUtilsN& utils)
137{
138 return int2{utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi - dPhi)),
139 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi + dPhi))};
140}
141
142template <int nLayers>
143GPUhdi() const int4 VertexerTraits<nLayers>::getBinsRect(const Cluster& currentCluster, const int layerIndex,
144 const float directionZIntersection, float maxdeltaz, float maxdeltaphi,
145 const IndexTableUtilsN& utils)
146{
147 const float zRangeMin = directionZIntersection - 2 * maxdeltaz;
148 const float phiRangeMin = currentCluster.phi - maxdeltaphi;
149 const float zRangeMax = directionZIntersection + 2 * maxdeltaz;
150 const float phiRangeMax = currentCluster.phi + maxdeltaphi;
151
152 if (zRangeMax < -utils.getLayerZ(layerIndex + 1) ||
153 zRangeMin > utils.getLayerZ(layerIndex + 1) || zRangeMin > zRangeMax) {
154 return getEmptyBinsRect();
155 }
156
157 return int4{o2::gpu::GPUCommonMath::Max(0, utils.getZBinIndex(layerIndex + 1, zRangeMin)),
158 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMin)),
159 o2::gpu::GPUCommonMath::Min(utils.getNzBins() - 1, utils.getZBinIndex(layerIndex + 1, zRangeMax)),
160 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMax))};
161}
162
163template <int nLayers>
164GPUhdi() const int4 VertexerTraits<nLayers>::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
StringRef key
static constexpr int maxTrackID()
HMPID cluster implementation.
Definition Cluster.h:27
virtual void computeTracklets(const int iteration=0)
static std::pair< o2::MCCompLabel, float > computeMain(const bounded_vector< o2::MCCompLabel > &elements)
virtual ~VertexerTraits()=default
const const float float const IndexTableUtilsN float deltaPhi
virtual bool usesMemoryPool() const noexcept
virtual const char * getName() const noexcept
virtual void initialise(const TrackingParameters &trackingParams, const int iteration=0)
auto getVertexingParameters() const
const const float maxdeltaz
virtual void computeVertices(const int iteration=0)
GPUhdi() static const eval int4 getEmptyBinsRect()
const const float float maxdeltaphi
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > &pool)
const const float float const IndexTableUtilsN & GPUhd() static const int2 getPhiBins(float phi
IndexTableUtilsN mIndexTableUtils
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
void setVertexingParameters(std::vector< VertexingParameters > &vertParams)
virtual bool isGPU() const noexcept
std::vector< VertexingParameters > mVrtParams
virtual void computeTrackletMatching(const int iteration=0)
virtual void adoptTimeFrame(TimeFrameN *tf) noexcept
virtual void updateVertexingParameters(const std::vector< VertexingParameters > &vrtPar, const TimeFrameGPUParameters &gpuTfPar)
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