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>
73inline float IndexTableUtils<nLayers>::getInverseZCoordinate(const int layerIndex) const
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>
116GPUhdi() int4 getBinsRect(const Cluster& currentCluster, const int layerIndex,
117 const float z1, const float z2, const float maxdeltaz, const float maxdeltaphi,
118 const IndexTableUtils<nLayers>& utils)
119{
120 const float zRangeMin = o2::gpu::GPUCommonMath::Min(z1, z2) - maxdeltaz;
121 const float phiRangeMin = (maxdeltaphi > o2::constants::math::PI) ? 0.f : currentCluster.phi - maxdeltaphi;
122 const float zRangeMax = o2::gpu::GPUCommonMath::Max(z1, z2) + maxdeltaz;
123 const float phiRangeMax = (maxdeltaphi > o2::constants::math::PI) ? o2::constants::math::TwoPI : currentCluster.phi + maxdeltaphi;
124
125 if (zRangeMax < -utils.getLayerZ(layerIndex) ||
126 zRangeMin > utils.getLayerZ(layerIndex) || zRangeMin > zRangeMax) {
127 return int4{0, 0, 0, 0};
128 }
129
130 return int4{o2::gpu::GPUCommonMath::Max(0, utils.getZBinIndex(layerIndex, zRangeMin)),
131 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMin)),
132 o2::gpu::GPUCommonMath::Min(utils.getNzBins() - 1, utils.getZBinIndex(layerIndex, zRangeMax)),
133 utils.getPhiBinIndex(math_utils::getNormalizedPhi(phiRangeMax))};
134}
135
136} // namespace o2::its
137#endif /* TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_ */
void print() const
int32_t i
useful math constants
HMPID cluster implementation.
Definition Cluster.h:27
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)
constexpr float TwoPI
constexpr float PI
GPUhdi() int IndexTableUtils< nLayers >
Common utility functions.