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 TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_
17#define TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_
18
19#include <array>
20
21#include "ITStracking/Cluster.h"
24#include "GPUCommonMath.h"
25#include "GPUCommonDef.h"
26
27namespace o2::its
28{
29
30template <int nLayers>
32{
33 public:
34 template <class T>
36 float getInverseZCoordinate(const int layerIndex) const;
37 GPUhdi() int getZBinIndex(const int, const float) const;
38 GPUhdi() int getPhiBinIndex(const float) const;
39 GPUhdi() int getBinIndex(const int, const int) const;
40 GPUhdi() int countRowSelectedBins(const int*, const int, const int, const int) const;
41 GPUhdi() void print() const;
42
43 GPUhdi() int getNzBins() const { return mNzBins; }
44 GPUhdi() int getNphiBins() const { return mNphiBins; }
45 GPUhdi() float getLayerZ(int i) const { return mLayerZ[i]; }
46 GPUhdi() void setNzBins(const int zBins) { mNzBins = zBins; }
47 GPUhdi() void setNphiBins(const int phiBins) { mNphiBins = phiBins; }
48
49 private:
50 int mNzBins = 0;
51 int mNphiBins = 0;
52 float mInversePhiBinSize = 0.f;
53 std::array<float, nLayers> mLayerZ{};
54 std::array<float, nLayers> mInverseZBinSize{};
55};
56
57template <int nLayers>
58template <class T>
60{
61 mInversePhiBinSize = params.PhiBins / o2::constants::math::TwoPI;
62 mNzBins = params.ZBins;
63 mNphiBins = params.PhiBins;
64 for (int iLayer{0}; iLayer < params.LayerZ.size(); ++iLayer) {
65 mLayerZ[iLayer] = params.LayerZ[iLayer];
66 }
67 for (unsigned int iLayer{0}; iLayer < params.LayerZ.size(); ++iLayer) {
68 mInverseZBinSize[iLayer] = 0.5f * params.ZBins / params.LayerZ[iLayer];
69 }
70}
71
72template <int nLayers>
74{
75 return 0.5f * mNzBins / mLayerZ[layerIndex];
76}
77
78template <int nLayers>
79GPUhdi() int IndexTableUtils<nLayers>::getZBinIndex(const int layerIndex, const float zCoordinate) const
80{
81 return (zCoordinate + mLayerZ[layerIndex]) * mInverseZBinSize[layerIndex];
82}
83
84template <int nLayers>
85GPUhdi() int IndexTableUtils<nLayers>::getPhiBinIndex(const float currentPhi) const
86{
87 return (currentPhi * mInversePhiBinSize);
88}
89
90template <int nLayers>
91GPUhdi() int IndexTableUtils<nLayers>::getBinIndex(const int zIndex, const int phiIndex) const
92{
93 return o2::gpu::GPUCommonMath::Min(phiIndex * mNzBins + zIndex, (mNzBins * mNphiBins) - 1);
94}
95
96template <int nLayers>
97GPUhdi() int IndexTableUtils<nLayers>::countRowSelectedBins(const int* indexTable, const int phiBinIndex,
98 const int minZBinIndex, const int maxZBinIndex) const
99{
100 const int firstBinIndex{getBinIndex(minZBinIndex, phiBinIndex)};
101 const int maxBinIndex{firstBinIndex + maxZBinIndex - minZBinIndex + 1};
102
103 return indexTable[maxBinIndex] - indexTable[firstBinIndex];
104}
105
106template <int nLayers>
107GPUhdi() void IndexTableUtils<nLayers>::print() const
108{
109 printf("NzBins: %d, NphiBins: %d, InversePhiBinSize: %f\n", mNzBins, mNphiBins, mInversePhiBinSize);
110 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
111 printf("Layer %d: Z: %f, InverseZBinSize: %f\n", iLayer, mLayerZ[iLayer], mInverseZBinSize[iLayer]);
112 }
113}
114
115template <int nLayers>
117 const float phi,
118 const float z,
119 const float maxdeltaz,
120 const float maxdeltaphi,
121 const IndexTableUtils<nLayers>& utils)
122{
123 const float zRangeMin = z - maxdeltaz;
124 const float phiRangeMin = (maxdeltaphi > o2::constants::math::PI) ? 0.f : phi - maxdeltaphi;
125 const float zRangeMax = z + maxdeltaz;
127
128 if (zRangeMax < -utils.getLayerZ(layerIndex) ||
129 zRangeMin > utils.getLayerZ(layerIndex) || zRangeMin > zRangeMax) {
130 return int4{-1, -1, -1, -1};
131 }
132
133 return int4{o2::gpu::GPUCommonMath::Max(0, utils.getZBinIndex(layerIndex, zRangeMin)),
134 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMin)),
135 o2::gpu::GPUCommonMath::Min(utils.getNzBins() - 1, utils.getZBinIndex(layerIndex, zRangeMax)),
136 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMax))};
137}
138
139template <int nLayers>
140GPUhdi() int4 getBinsRect(const Cluster& currentCluster, const int layerIndex,
141 const float z1, const float z2, const float maxdeltaz, const float maxdeltaphi,
143{
144 const float zMean = 0.5f * (z1 + z2);
145 const float zDelta = 0.5f * o2::gpu::GPUCommonMath::Abs(z1 - z2) + maxdeltaz;
146 return getBinsRect(layerIndex, currentCluster.phi, zMean, zDelta, maxdeltaphi, utils);
147}
148
149} // namespace o2::its
150#endif /* TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_ */
void print() const
int32_t i
useful math constants
GPUhdi() int getNphiBins() const
GPUhdi() int getZBinIndex(const int
void setTrackingParameters(const T &params)
GPUhdi() float getLayerZ(int i) const
GPUhdi() void setNphiBins(const int phiBins)
float getInverseZCoordinate(const int layerIndex) const
GPUhdi() void setNzBins(const int zBins)
GLenum const GLfloat * params
Definition glcorearb.h:272
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
constexpr float TwoPI
constexpr float PI
const float zDelta
const int layerIndex
const bool const int nLayers
GPUhdi() int IndexTableUtils< nLayers >
const int const float const float const float const float maxdeltaphi
return getBinsRect(layerIndex, currentCluster.phi, zMean, zDelta, maxdeltaphi, utils)
const int const float const float z2
const int const float const float const float maxdeltaz
const int const float z1
Common utility functions.