Project
Loading...
Searching...
No Matches
IndexTableUtils.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 ALICEO2_ITSMFT_TRACKING_INDEXTABLEUTILS_H_
17#define ALICEO2_ITSMFT_TRACKING_INDEXTABLEUTILS_H_
18
19#include <algorithm>
20#include <array>
21#include <cstddef>
22
23#include <gsl/span>
24
26#include "GPUCommonMath.h"
27#include "GPUCommonDef.h"
31
32namespace o2::itsmft
33{
34
35enum class IndexTableCoordType : uint8_t { PhiZ,
36 PhiR };
37
43{
44 public:
45 static constexpr int MaxLayers = static_cast<int>(o2::itsmft::tracking::MaxLayoutSurfaces);
46
52 void setIndexTableParams(IndexTableCoordType coordType, int nRowBins, int nColBins,
53 float rowMin, float rowMax,
54 gsl::span<const float> layerColMin,
55 gsl::span<const float> layerColMax)
56 {
57 mCoordType = coordType;
58 mRowOrigin = 0.f;
59 mRowCoordinateSpan = rowMax - rowMin;
60 mInverseRowBinSize = (mRowCoordinateSpan > 0.f) ? static_cast<float>(nRowBins) / mRowCoordinateSpan : 0.f;
61 mNcolBins = nColBins;
62 mNrowBins = nRowBins;
63 const int nLayers = std::min({static_cast<int>(layerColMin.size()), static_cast<int>(layerColMax.size()), MaxLayers});
64 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
65 mLayerColMin[iLayer] = layerColMin[iLayer];
66 mLayerColMax[iLayer] = layerColMax[iLayer];
67 mInverseColBinSize[iLayer] = static_cast<float>(nColBins) / (layerColMax[iLayer] - layerColMin[iLayer]);
68 }
69 }
70
71 void setIndexTableParams(IndexTableCoordType coordType, int nRowBins, int nColBins,
72 float rowMin, float rowMax,
73 gsl::span<const float> layerColHalfExtent)
74 {
75 std::array<float, MaxLayers> minima{};
76 std::array<float, MaxLayers> maxima{};
77 const int count = std::min(static_cast<int>(layerColHalfExtent.size()), MaxLayers);
78 for (int iLayer = 0; iLayer < count; ++iLayer) {
79 minima[iLayer] = -layerColHalfExtent[iLayer];
80 maxima[iLayer] = layerColHalfExtent[iLayer];
81 }
82 setIndexTableParams(coordType, nRowBins, nColBins, rowMin, rowMax,
83 gsl::span<const float>{minima.data(), static_cast<size_t>(count)},
84 gsl::span<const float>{maxima.data(), static_cast<size_t>(count)});
85 }
86
87 GPUhdi() float getInverseColCoordinate(const int layerIndex) const
88 {
89 return mInverseColBinSize[layerIndex];
90 }
91
92 GPUhdi() int getColBinIndex(const int layerIndex, const float colCoordinate) const
93 {
94 return (colCoordinate - mLayerColMin[layerIndex]) * mInverseColBinSize[layerIndex];
95 }
96
97 GPUhdi() int getRowBinIndex(const float rowCoordinate) const
98 {
99 return rowCoordinate * mInverseRowBinSize;
100 }
101
102 GPUhdi() int getBinIndex(const int colIndex, const int rowIndex) const
103 {
104 return o2::gpu::GPUCommonMath::Min(rowIndex * mNcolBins + colIndex, (mNcolBins * mNrowBins) - 1);
105 }
106
107 GPUhdi() int countRowSelectedBins(const int* indexTable, const int rowBinIndex,
108 const int minColBinIndex, const int maxColBinIndex) const
109 {
110 const int firstBinIndex{getBinIndex(minColBinIndex, rowBinIndex)};
111 const int maxBinIndex{firstBinIndex + maxColBinIndex - minColBinIndex + 1};
112
113 return indexTable[maxBinIndex] - indexTable[firstBinIndex];
114 }
115
116 void print() const;
117
118 GPUhdi() int getNcolBins() const { return mNcolBins; }
119 GPUhdi() int getNrowBins() const { return mNrowBins; }
120 GPUhdi() float getLayerColHalfExtent(int i) const { return 0.5f * (mLayerColMax[i] - mLayerColMin[i]); }
121 GPUhdi() float getLayerColMin(int i) const { return mLayerColMin[i]; }
122 GPUhdi() float getLayerColMax(int i) const { return mLayerColMax[i]; }
123 GPUhdi() void setNcolBins(const int colBins) { mNcolBins = colBins; }
124 GPUhdi() void setNrowBins(const int rowBins) { mNrowBins = rowBins; }
125 GPUhdi() IndexTableCoordType getCoordType() const { return mCoordType; }
129 GPUhdi() float getRowOrigin() const { return mRowOrigin; }
130 GPUhdi() float getRowCoordinateSpan() const { return mRowCoordinateSpan; }
131
132 private:
133 int mNcolBins = 0;
134 int mNrowBins = 0;
135 float mInverseRowBinSize = 0.f;
136 float mRowOrigin = 0.f;
137 float mRowCoordinateSpan = o2::constants::math::TwoPI;
139 std::array<float, MaxLayers> mLayerColMin{};
140 std::array<float, MaxLayers> mLayerColMax{};
141 std::array<float, MaxLayers> mInverseColBinSize{};
142};
143
144inline void IndexTableUtilsCore::print() const
145{
146 printf("NcolBins: %d, NrowBins: %d, InverseRowBinSize: %f\n", mNcolBins, mNrowBins, mInverseRowBinSize);
147 for (int iLayer{0}; iLayer < MaxLayers; ++iLayer) {
148 printf("Layer %d: ColRange: [%f, %f], InverseColBinSize: %f\n", iLayer, mLayerColMin[iLayer], mLayerColMax[iLayer], mInverseColBinSize[iLayer]);
149 }
150}
151
155GPUhdi() int4 getBinsPhiColumn(float phi, const int layerIndex,
156 float col, float maxDeltaCol, float maxDeltaRow,
158{
159 const float colRangeMin = col - maxDeltaCol;
160 const float rowRangeMin = (maxDeltaRow > o2::constants::math::PI) ? 0.f : phi - maxDeltaRow;
161 const float colRangeMax = col + maxDeltaCol;
162 const float rowRangeMax = (maxDeltaRow > o2::constants::math::PI) ? o2::constants::math::TwoPI : phi + maxDeltaRow;
163
164 if (colRangeMax < utils.getLayerColMin(layerIndex) ||
165 colRangeMin > utils.getLayerColMax(layerIndex) || colRangeMin > colRangeMax) {
166 return int4{-1, -1, -1, -1};
167 }
168
169 return int4{o2::gpu::GPUCommonMath::Max(0, utils.getColBinIndex(layerIndex, colRangeMin)),
170 utils.getRowBinIndex(o2::its::math_utils::getNormalizedPhi(rowRangeMin)),
171 o2::gpu::GPUCommonMath::Min(utils.getNcolBins() - 1, utils.getColBinIndex(layerIndex, colRangeMax)),
172 utils.getRowBinIndex(o2::its::math_utils::getNormalizedPhi(rowRangeMax))};
173}
174
175} // namespace o2::itsmft
176
177#endif /* ALICEO2_ITSMFT_TRACKING_INDEXTABLEUTILS_H_ */
Shared CA tracking configuration for ITS and MFT.
int32_t i
useful math constants
GPUhdi() float getLayerColMax(int i) const
GPUhdi() float getInverseColCoordinate(const int layerIndex) const
GPUhdi() float getLayerColMin(int i) const
void setIndexTableParams(IndexTableCoordType coordType, int nRowBins, int nColBins, float rowMin, float rowMax, gsl::span< const float > layerColHalfExtent)
GPUhdi() void setNrowBins(const int rowBins)
GPUhdi() float getRowOrigin() const
GPUhdi() int getNrowBins() const
GPUhdi() IndexTableCoordType getCoordType() const
void setIndexTableParams(IndexTableCoordType coordType, int nRowBins, int nColBins, float rowMin, float rowMax, gsl::span< const float > layerColMin, gsl::span< const float > layerColMax)
GPUhdi() float getRowCoordinateSpan() const
GPUhdi() float getLayerColHalfExtent(int i) const
GPUhdi() int countRowSelectedBins(const int *indexTable
GPUhdi() int getNcolBins() const
const float colCoordinate const
GPUhdi() void setNcolBins(const int colBins)
GPUhdi() int getRowBinIndex(const float rowCoordinate) const
return indexTable[maxBinIndex] indexTable[firstBinIndex]
GLint GLsizei count
Definition glcorearb.h:399
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLsizei const GLubyte GLsizei GLenum coordType
Definition glcorearb.h:5468
constexpr uint32_t MaxLayoutSurfaces
Definition IdTypes.h:70
const float colRangeMax
const int layerIndex
const int float float maxDeltaCol
const int float float float maxDeltaRow
const float rowRangeMax
const float rowRangeMin
const int float col
GPUhdi() int4 getBinsPhiColumn(float phi
Common utility functions.