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 MatCell& getCellPhiBin(int iphi, int iz)
97 {
98 return mCells[getCellIDPhiBin(iphi, iz)];
99 }
100
101 void scale(float factor, bool _x2x0 = true, bool _rho = true);
102#endif
103
104 // ---------------------- Z slice manipulation
105 // convert Z to Zslice
106 GPUd() RangeStatus isZOutside(float z) const { return z < getZMin() ? Below : (z > getZMax() ? Above : Within); }
107 GPUd() int getZBinID(float z) const
108 {
109 int idz = int((z - getZMin()) * getDZInv()); // cannot be negative since before isZOutside is applied
110 return idz < getNZBins() ? idz : getNZBins() - 1;
111 }
112
113 // lower boundary of Z slice
114 GPUd() float getZBinMin(int id) const { return getZMin() + id * getDZ(); }
115
116 // upper boundary of Z slice
117 GPUd() float getZBinMax(int id) const { return getZMin() + (id + 1) * getDZ(); }
118
119 // ---------------------- Phi slice manipulation (0:2pi convention, no check is done)
120 GPUd() int phiBin2Slice(int i) const { return mPhiBin2Slice[i]; }
121 GPUd() int getPhiSliceID(float phi) const { return phiBin2Slice(getPhiBinID(phi)); }
122
123 // lower boundary of phi slice
124 GPUd() float getPhiBinMin(int id) const { return id * getDPhi(); }
125
126 // upper boundary of phi slice
127 GPUd() float getPhiBinMax(int id) const { return (id + 1) * getDPhi(); }
128
129 // sin and cosine of the slice lower angle
130 GPUd() float getSliceCos(int i) const { return mSliceCos[i]; }
131 GPUd() float getSliceSin(int i) const { return mSliceSin[i]; }
132
133#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
134 void getMeanRMS(MatCell& mean, MatCell& rms) const;
135 bool cellsDiffer(const MatCell& cellA, const MatCell& cellB, float maxRelDiff) const;
136 bool canMergePhiSlices(int i, int j, float maxRelDiff = 0.05, int maxDifferent = 1) const;
137 void optimizePhiSlices(float maxRelDiff = 0.05);
138 void flatten(char* newPtr);
139#endif // !GPUCA_ALIGPUCODE
140
141#ifndef GPUCA_GPUCODE
142 std::size_t estimateFlatBufferSize() const
143 {
144 return estimateFlatBufferSize(getNPhiBins(), getNPhiSlices(), getNZBins());
145 }
146 static std::size_t estimateFlatBufferSize(int nPhiBins, int nPhiSlices, int nZBins)
147 {
148 size_t sz = 0;
149 sz += alignSize(sz + nPhiBins * sizeof(short), getBufferAlignmentBytes()); // mPhiBin2Slice
150 sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceCos
151 sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceSin
152 sz += alignSize(sz + nPhiSlices * nZBins * sizeof(MatCell), getBufferAlignmentBytes()); // mSliceSin
153 return sz;
154 }
155 void fixPointers(char* oldPtr, char* newPtr);
156 void setFlatPointer(char* ptr)
157 {
158 // brute force assignment of new pointers
162 }
163 }
164
166 static constexpr size_t getClassAlignmentBytes() { return 8; }
168 static constexpr size_t getBufferAlignmentBytes() { return 8; }
169#endif
170 // linearized cell ID from phi bin and z bin
171 GPUd() int getCellIDPhiBin(int iphi, int iz) const { return getCellID(phiBin2Slice(iphi), iz); }
172
173 protected:
174 GPUd() int getNCells() const { return getNZBins() * getNPhiSlices(); }
175 GPUd() float getDZInv() const { return mDZInv; }
176 GPUd() float getDPhiInv() const { return mDPhiInv; }
177
178 // linearized cell ID from phi slice and z bin
179 GPUd() int getCellID(int iphi, int iz) const { return iphi * getNZBins() + iz; }
180
181 // convert Phi (in 0:2pi convention) to PhiBinID
182 GPUd() int getPhiBinID(float phi) const
183 {
184 auto idphi = int(phi * getDPhiInv());
185 return idphi < getNPhiBins() ? idphi : getNPhiBins() - 1;
186 }
187
188 GPUd() int getEdgePhiBinOfSlice(int phiBin, int dir) const
189 {
190 // Get edge bin (in direction dir) of the slice, to which phiBin belongs
191 // No check for phiBin validity is done
192 auto slice = phiBin2Slice(phiBin);
193 while (slice == phiBin2Slice((phiBin += dir))) {
194 ;
195 }
196 return phiBin - dir;
197 }
198
199 //------------------------------------------------------
200
201 short mNZBins;
202 short mNPhiBins;
204 //
205 float mZHalf;
206 float mRMin2;
207 float mRMax2;
208 float mDZ;
209 float mDZInv;
210 float mDPhi;
211 float mDPhiInv;
212
214
215 float* mSliceCos;
216 float* mSliceSin;
217
219
221};
222
223} // namespace base
224} // namespace o2
225
226#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
void scale(float factor, bool _x2x0=true, bool _rho=true)
short mNZBins
number of Z bins
MatCell & getCellPhiBin(int iphi, int iz)
Definition MatLayerCyl.h:96
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
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 ...