Project
Loading...
Searching...
No Matches
MatLayerCyl.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.
11
14
15#ifndef ALICEO2_MATLAYERCYL_H
16#define ALICEO2_MATLAYERCYL_H
17
18#ifndef GPUCA_GPUCODE_DEVICE
19#include <cmath>
20#include <cstring>
21#endif
22#include "GPUCommonDef.h"
23#include "FlatObject.h"
24#include "GPUCommonRtypes.h"
25#include "GPUCommonMath.h"
27
28namespace o2
29{
30namespace base
31{
32
33/**********************************************************************
34 * *
35 * Material data on the cells of cylindrical layer *
36 * Cell is limited by 2 radial planes at phiMin,phiMax, *
37 * radii radMin,radMax and XY planes at zMin, zMax. *
38 * This limits are defined in the cell container class *
39 * *
40 * *
41 * Cylindrical material layer *
42 * *
43 * Logical division is given by mNZBins and mNPhiBins *
44 * but the actual number phi slices might be less if neighbouring *
45 * phi bins with similar properties are merged together. The actual *
46 * phi slice should be accessed via mPhiBin2Slice map. *
47 * *
48 **********************************************************************/
50{
51
52 public:
53 enum RangeStatus : short { Below = -1,
54 Within = 0,
55 Above = 1 };
56
57#ifndef GPUCA_GPUCODE
59 MatLayerCyl(const MatLayerCyl& src) = delete;
60 ~MatLayerCyl() = default;
61#endif
62
63#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
64 MatLayerCyl(float rMin, float rMax, float zHalfSpan, float dzMin, float drphiMin);
65
66 void initSegmentation(float rMin, float rMax, float zHalfSpan, int nz, int nphi);
67 void initSegmentation(float rMin, float rMax, float zHalfSpan, float dzMin, float drphiMin);
68 void populateFromTGeo(int ntrPerCell = 10);
69 void populateFromTGeo(int ip, int iz, int ntrPerCell);
70 void print(bool data = false) const;
71#endif // !GPUCA_ALIGPUCODE
72
73 GPUd() float getRMin() const
74 {
75 return o2::gpu::CAMath::Sqrt(getRMin2());
76 }
77 GPUd() float getRMax() const { return o2::gpu::CAMath::Sqrt(getRMax2()); }
78 GPUd() float getZMin() const { return -mZHalf; }
79 GPUd() float getZMax() const { return mZHalf; }
80
81 GPUd() int getNZBins() const { return mNZBins; }
82 GPUd() int getNPhiBins() const { return mNPhiBins; }
83 GPUd() int getNPhiSlices() const { return mNPhiSlices; }
84 GPUd() int getNPhiBinsInSlice(int iSlice, int& binMin, int& binMax) const;
85
86 GPUd() float getRMin2() const { return mRMin2; }
87 GPUd() float getRMax2() const { return mRMax2; }
88 GPUd() float getDZ() const { return mDZ; }
89 GPUd() float getDPhi() const { return mDPhi; }
90
91 // obtain material cell, cell ID must be valid
92 GPUd() const MatCell& getCellPhiBin(int iphi, int iz) const { return mCells[getCellIDPhiBin(iphi, iz)]; }
93 GPUd() const MatCell& getCell(int iphiSlice, int iz) const { return mCells[getCellID(iphiSlice, iz)]; }
94
95#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
96 GPUd() MatCell& getCellPhiBin(int iphi, int iz)
97 {
98 return mCells[getCellIDPhiBin(iphi, iz)];
99 }
100#endif
101
102 // ---------------------- Z slice manipulation
103 // convert Z to Zslice
104 GPUd() RangeStatus isZOutside(float z) const { return z < getZMin() ? Below : (z > getZMax() ? Above : Within); }
105 GPUd() int getZBinID(float z) const
106 {
107 int idz = int((z - getZMin()) * getDZInv()); // cannot be negative since before isZOutside is applied
108 return idz < getNZBins() ? idz : getNZBins() - 1;
109 }
110
111 // lower boundary of Z slice
112 GPUd() float getZBinMin(int id) const { return getZMin() + id * getDZ(); }
113
114 // upper boundary of Z slice
115 GPUd() float getZBinMax(int id) const { return getZMin() + (id + 1) * getDZ(); }
116
117 // ---------------------- Phi slice manipulation (0:2pi convention, no check is done)
118 GPUd() int phiBin2Slice(int i) const { return mPhiBin2Slice[i]; }
119 GPUd() int getPhiSliceID(float phi) const { return phiBin2Slice(getPhiBinID(phi)); }
120
121 // lower boundary of phi slice
122 GPUd() float getPhiBinMin(int id) const { return id * getDPhi(); }
123
124 // upper boundary of phi slice
125 GPUd() float getPhiBinMax(int id) const { return (id + 1) * getDPhi(); }
126
127 // sin and cosine of the slice lower angle
128 GPUd() float getSliceCos(int i) const { return mSliceCos[i]; }
129 GPUd() float getSliceSin(int i) const { return mSliceSin[i]; }
130
131#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
132 void getMeanRMS(MatCell& mean, MatCell& rms) const;
133 bool cellsDiffer(const MatCell& cellA, const MatCell& cellB, float maxRelDiff) const;
134 bool canMergePhiSlices(int i, int j, float maxRelDiff = 0.05, int maxDifferent = 1) const;
135 void optimizePhiSlices(float maxRelDiff = 0.05);
136 void flatten(char* newPtr);
137#endif // !GPUCA_ALIGPUCODE
138
139#ifndef GPUCA_GPUCODE
140 std::size_t estimateFlatBufferSize() const
141 {
142 return estimateFlatBufferSize(getNPhiBins(), getNPhiSlices(), getNZBins());
143 }
144 static std::size_t estimateFlatBufferSize(int nPhiBins, int nPhiSlices, int nZBins)
145 {
146 size_t sz = 0;
147 sz += alignSize(sz + nPhiBins * sizeof(short), getBufferAlignmentBytes()); // mPhiBin2Slice
148 sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceCos
149 sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceSin
150 sz += alignSize(sz + nPhiSlices * nZBins * sizeof(MatCell), getBufferAlignmentBytes()); // mSliceSin
151 return sz;
152 }
153 void fixPointers(char* oldPtr, char* newPtr);
154 void setFlatPointer(char* ptr)
155 {
156 // brute force assignment of new pointers
160 }
161 }
162
164 static constexpr size_t getClassAlignmentBytes() { return 8; }
166 static constexpr size_t getBufferAlignmentBytes() { return 8; }
167#endif
168 // linearized cell ID from phi bin and z bin
169 GPUd() int getCellIDPhiBin(int iphi, int iz) const { return getCellID(phiBin2Slice(iphi), iz); }
170
171 protected:
172 GPUd() int getNCells() const { return getNZBins() * getNPhiSlices(); }
173 GPUd() float getDZInv() const { return mDZInv; }
174 GPUd() float getDPhiInv() const { return mDPhiInv; }
175
176 // linearized cell ID from phi slice and z bin
177 GPUd() int getCellID(int iphi, int iz) const { return iphi * getNZBins() + iz; }
178
179 // convert Phi (in 0:2pi convention) to PhiBinID
180 GPUd() int getPhiBinID(float phi) const
181 {
182 auto idphi = int(phi * getDPhiInv());
183 return idphi < getNPhiBins() ? idphi : getNPhiBins() - 1;
184 }
185
186 GPUd() int getEdgePhiBinOfSlice(int phiBin, int dir) const
187 {
188 // Get edge bin (in direction dir) of the slice, to which phiBin belongs
189 // No check for phiBin validity is done
190 auto slice = phiBin2Slice(phiBin);
191 while (slice == phiBin2Slice((phiBin += dir))) {
192 ;
193 }
194 return phiBin - dir;
195 }
196
197 //------------------------------------------------------
198
199 short mNZBins;
200 short mNPhiBins;
202 //
203 float mZHalf;
204 float mRMin2;
205 float mRMax2;
206 float mDZ;
207 float mDZInv;
208 float mDPhi;
209 float mDPhiInv;
210
212
213 float* mSliceCos;
214 float* mSliceSin;
215
217
219};
220
221} // namespace base
222} // namespace o2
223
224#endif
void print() const
Definition of FlatObject class.
int32_t i
Declarations for material properties of the cell (voxel)
uint32_t j
Definition RawData.h:0
TBranch * ptr
short mNPhiSlices
actual number of phi slices
MatCell * mCells
cached sin each phi slice
float mZHalf
Z half span.
short mNPhiBins
number of phi bins (logical)
GPUd() float getSliceCos(int i) const
void optimizePhiSlices(float maxRelDiff=0.05)
float mRMin2
squared min r
std::size_t estimateFlatBufferSize() const
GPUd() int getNPhiBins() const
Definition MatLayerCyl.h:82
GPUd() float getRMax() const
Definition MatLayerCyl.h:77
GPUd() float getPhiBinMax(int id) const
float mDZ
Z slice thickness.
static constexpr size_t getClassAlignmentBytes()
Gives minimal alignment in bytes required for the class object.
GPUd() float getSliceSin(int i) const
GPUd() float getDPhi() const
Definition MatLayerCyl.h:89
GPUd() int getNPhiSlices() const
Definition MatLayerCyl.h:83
GPUd() float getDZInv() const
ClassDefNV(MatLayerCyl, 1)
mat.budget per cell
float mDPhi
phi slice thickness
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
MatLayerCyl(const MatLayerCyl &src)=delete
GPUd() int getNZBins() const
Definition MatLayerCyl.h:81
float * mSliceSin
cached cos each phi slice
GPUd() float getZBinMin(int id) const
void initSegmentation(float rMin, float rMax, float zHalfSpan, int nz, int nphi)
bool cellsDiffer(const MatCell &cellA, const MatCell &cellB, float maxRelDiff) const
float mDZInv
Z slice thickness inverse.
void getMeanRMS(MatCell &mean, MatCell &rms) const
GPUd() int getPhiSliceID(float phi) const
GPUd() float getDPhiInv() const
GPUd() float getZMin() const
Definition MatLayerCyl.h:78
GPUd() float getPhiBinMin(int id) const
int int &binMax const
Definition MatLayerCyl.h:84
float * mSliceCos
mapping from analytical phi bin ID to real slice ID
GPUd() int getNCells() const
void flatten(char *newPtr)
GPUd() float getZBinMax(int id) const
GPUd() int getPhiBinID(float phi) const
GPUd() int getCellID(int iphi
GPUd() float getRMax2() const
Definition MatLayerCyl.h:87
GPUd() RangeStatus isZOutside(float z) const
GPUd() int phiBin2Slice(int i) const
short mNZBins
number of Z bins
float mRMax2
squared max r
void fixPointers(char *oldPtr, char *newPtr)
static std::size_t estimateFlatBufferSize(int nPhiBins, int nPhiSlices, int nZBins)
GPUd() float getZMax() const
Definition MatLayerCyl.h:79
GPUd() MatCell &getCellPhiBin(int iphi
void setFlatPointer(char *ptr)
GPUd() int getZBinID(float z) const
GPUd() float getRMin() const
Definition MatLayerCyl.h:73
GPUd() float getDZ() const
Definition MatLayerCyl.h:88
GPUd() int getCellIDPhiBin(int iphi
GPUd() const MatCell &getCell(int iphiSlice
float mDPhiInv
phi slice thickness inverse
void populateFromTGeo(int ntrPerCell=10)
bool canMergePhiSlices(int i, int j, float maxRelDiff=0.05, int maxDifferent=1) const
GPUCA_GPUCODE.
Definition FlatObject.h:176
char * mFlatBufferContainer
Definition FlatObject.h:324
static size_t alignSize(size_t sizeBytes, size_t alignmentBytes)
_______________ Generic utilities _______________________________________________
Definition FlatObject.h:277
GLenum src
Definition glcorearb.h:1767
GLboolean * data
Definition glcorearb.h:298
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...