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