Project
Loading...
Searching...
No Matches
GPUTPCGrid.cxx
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.
11
14
15#include "GPUTPCGrid.h"
16#include "GPUCommonMath.h"
17using namespace o2::gpu;
18
19#if !defined(assert) && !defined(GPUCA_GPUCODE)
20#include <cassert>
21#endif
22
23GPUd() void GPUTPCGrid::CreateEmpty()
24{
25 // Create an empty grid
26 mYMin = 0.f;
27 mYMax = 1.f;
28 mZMin = 0.f;
29 mZMax = 1.f;
30
31 mNy = 1;
32 mNz = 1;
33 mN = 1;
34
35 mStepYInv = 1.f;
36 mStepZInv = 1.f;
37}
38
39GPUd() void GPUTPCGrid::Create(float yMin, float yMax, float zMin, float zMax, int32_t ny, int32_t nz)
40{
41 //* Create the grid
42 mYMin = yMin;
43 mZMin = zMin;
44
45 float sy = CAMath::Max((yMax + 0.1f - yMin) / ny, GPUCA_MIN_BIN_SIZE);
46 float sz = CAMath::Max((zMax + 0.1f - zMin) / nz, GPUCA_MIN_BIN_SIZE);
47
48 mStepYInv = 1.f / sy;
49 mStepZInv = 1.f / sz;
50
51 mNy = ny;
52 mNz = nz;
53
54 mN = mNy * mNz;
55
56 mYMax = mYMin + mNy * sy;
57 mZMax = mZMin + mNz * sz;
58}
59
60GPUd() int32_t GPUTPCGrid::GetBin(float Y, float Z) const
61{
62 //* get the bin pointer
63 const int32_t yBin = static_cast<int32_t>((Y - mYMin) * mStepYInv);
64 const int32_t zBin = static_cast<int32_t>((Z - mZMin) * mStepZInv);
65 const int32_t bin = zBin * mNy + yBin;
66#ifndef GPUCA_GPUCODE
67 assert(bin >= 0);
68 assert(bin < static_cast<int32_t>(mN));
69#endif
70 return bin;
71}
72
73GPUd() int32_t GPUTPCGrid::GetBinBounded(float Y, float Z) const
74{
75 //* get the bin pointer
76 const int32_t yBin = static_cast<int32_t>((Y - mYMin) * mStepYInv);
77 const int32_t zBin = static_cast<int32_t>((Z - mZMin) * mStepZInv);
78 int32_t bin = zBin * mNy + yBin;
79 if (bin >= static_cast<int32_t>(mN)) {
80 bin = mN - 1;
81 }
82 if (bin < 0) {
83 bin = 0;
84 }
85 return bin;
86}
87
88GPUd() void GPUTPCGrid::GetBin(float Y, float Z, int32_t* const bY, int32_t* const bZ) const
89{
90 //* get the bin pointer
91
92 int32_t bbY = (int32_t)((Y - mYMin) * mStepYInv);
93 int32_t bbZ = (int32_t)((Z - mZMin) * mStepZInv);
94
95 if (bbY >= (int32_t)mNy) {
96 bbY = mNy - 1;
97 }
98 if (bbY < 0) {
99 bbY = 0;
100 }
101 if (bbZ >= (int32_t)mNz) {
102 bbZ = mNz - 1;
103 }
104 if (bbZ < 0) {
105 bbZ = 0;
106 }
107
108 *bY = (uint32_t)bbY;
109 *bZ = (uint32_t)bbZ;
110}
111
112GPUd() void GPUTPCGrid::GetBinArea(float Y, float Z, float dy, float dz, int32_t& bin, int32_t& ny, int32_t& nz) const
113{
114 Y -= mYMin;
115 int32_t by = (int32_t)((Y - dy) * mStepYInv);
116 ny = (int32_t)((Y + dy) * mStepYInv) - by;
117 Z -= mZMin;
118 int32_t bz = (int32_t)((Z - dz) * mStepZInv);
119 nz = (int32_t)((Z + dz) * mStepZInv) - bz;
120 if (by >= (int32_t)mNy) {
121 by = mNy - 1;
122 }
123 if (by < 0) {
124 by = 0;
125 }
126 if (bz >= (int32_t)mNz) {
127 bz = mNz - 1;
128 }
129 if (bz < 0) {
130 bz = 0;
131 }
132 if (by + ny >= (int32_t)mNy) {
133 ny = mNy - 1 - by;
134 }
135 if (bz + nz >= (int32_t)mNz) {
136 nz = mNz - 1 - bz;
137 }
138 bin = bz * mNy + by;
139}
#define GPUCA_MIN_BIN_SIZE
GPUd() void GPUTPCGrid
float float float & zMax
float float & zMin
float & yMax
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)