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 // truth tracking
79
80 // utils
82 auto getVertexingParameters() const { return mVrtParams; }
83 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;
116
117 // Frame related quantities
118 TimeFrame7* mTimeFrame = nullptr; // observer ptr
119 private:
120 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
121 std::shared_ptr<tbb::task_arena> mTaskArena;
122};
123
124inline void VertexerTraits::initialise(const TrackingParameters& trackingParams, const int iteration)
125{
126 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.
127}
128
129GPUhdi() const int2 VertexerTraits::getPhiBins(float phi, float dPhi, const IndexTableUtils& utils)
130{
131 return int2{utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi - dPhi)),
132 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phi + dPhi))};
133}
134
135GPUhdi() const int4 VertexerTraits::getBinsRect(const Cluster& currentCluster, const int layerIndex,
136 const float directionZIntersection, float maxdeltaz, float maxdeltaphi,
137 const IndexTableUtils& utils)
138{
139 const float zRangeMin = directionZIntersection - 2 * maxdeltaz;
140 const float phiRangeMin = currentCluster.phi - maxdeltaphi;
141 const float zRangeMax = directionZIntersection + 2 * maxdeltaz;
142 const float phiRangeMax = currentCluster.phi + maxdeltaphi;
143
144 if (zRangeMax < -utils.getLayerZ(layerIndex + 1) ||
145 zRangeMin > utils.getLayerZ(layerIndex + 1) || zRangeMin > zRangeMax) {
146 return getEmptyBinsRect();
147 }
148
149 return int4{o2::gpu::GPUCommonMath::Max(0, utils.getZBinIndex(layerIndex + 1, zRangeMin)),
150 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMin)),
151 o2::gpu::GPUCommonMath::Min(utils.getNzBins() - 1, utils.getZBinIndex(layerIndex + 1, zRangeMax)),
152 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMax))};
153}
154
155GPUhdi() const int4 VertexerTraits::getBinsRect(const Cluster& currentCluster, const int layerIndex,
156 const float directionZIntersection, float maxdeltaz, float maxdeltaphi)
157{
158 return VertexerTraits::getBinsRect(currentCluster, layerIndex, directionZIntersection, maxdeltaz, maxdeltaphi, mIndexTableUtils);
159}
160
161} // namespace its
162} // namespace o2
163#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
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
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)