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#ifndef GPUCA_ALIGPUCODE
24#include "DetectorsBase/GeometryManager.h" // for MatbudGeomBackend
25#endif
26#include "FlatObject.h"
27#include "GPUCommonRtypes.h"
28#include "GPUCommonMath.h"
30
31class TGeoNavigator;
32
33namespace o2
34{
35namespace base
36{
37
38/**********************************************************************
39 * *
40 * Material data on the cells of cylindrical layer *
41 * Cell is limited by 2 radial planes at phiMin,phiMax, *
42 * radii radMin,radMax and XY planes at zMin, zMax. *
43 * This limits are defined in the cell container class *
44 * *
45 * *
46 * Cylindrical material layer *
47 * *
48 * Logical division is given by mNZBins and mNPhiBins *
49 * but the actual number phi slices might be less if neighbouring *
50 * phi bins with similar properties are merged together. The actual *
51 * phi slice should be accessed via mPhiBin2Slice map. *
52 * *
53 **********************************************************************/
55{
56
57 public:
58 enum RangeStatus : short { Below = -1,
59 Within = 0,
60 Above = 1 };
61
62#ifndef GPUCA_GPUCODE
64 MatLayerCyl(const MatLayerCyl& src) = delete;
65 ~MatLayerCyl() = default;
66#endif
67
68#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
69 MatLayerCyl(float rMin, float rMax, float zHalfSpan, float dzMin, float drphiMin);
70
71 void initSegmentation(float rMin, float rMax, float zHalfSpan, int nz, int nphi);
72 void initSegmentation(float rMin, float rMax, float zHalfSpan, float dzMin, float drphiMin);
73 void populateFromTGeo(int ntrPerCell = 10, MatbudGeomBackend backend = MatbudGeomBackend::ROOT);
74 void populateFromTGeo(int ip, int iz, int ntrPerCell, TGeoNavigator* nav = nullptr, MatbudGeomBackend backend = MatbudGeomBackend::ROOT);
75 void print(bool data = false) const;
76#endif // !GPUCA_ALIGPUCODE
77
78 GPUd() float getRMin() const
79 {
80 return o2::gpu::CAMath::Sqrt(getRMin2());
81 }
82 GPUd() float getRMax() const { return o2::gpu::CAMath::Sqrt(getRMax2()); }
83 GPUd() float getZMin() const { return -mZHalf; }
84 GPUd() float getZMax() const { return mZHalf; }
85
86 GPUd() int getNZBins() const { return mNZBins; }
87 GPUd() int getNPhiBins() const { return mNPhiBins; }
88 GPUd() int getNPhiSlices() const { return mNPhiSlices; }
89 GPUd() int getNPhiBinsInSlice(int iSlice, int& binMin, int& binMax) const;
90
91 GPUd() float getRMin2() const { return mRMin2; }
92 GPUd() float getRMax2() const { return mRMax2; }
93 GPUd() float getDZ() const { return mDZ; }
94 GPUd() float getDPhi() const { return mDPhi; }
95
96 // obtain material cell, cell ID must be valid
97 GPUd() const MatCell& getCellPhiBin(int iphi, int iz) const { return mCells[getCellIDPhiBin(iphi, iz)]; }
98 GPUd() const MatCell& getCell(int iphiSlice, int iz) const { return mCells[getCellID(iphiSlice, iz)]; }
99 GPUd() const MatCell* getCellRow(int iphiSlice) const { return mCells + iphiSlice * getNZBins(); }
100
101#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
102 MatCell& getCellPhiBin(int iphi, int iz)
103 {
104 return mCells[getCellIDPhiBin(iphi, iz)];
105 }
106
107 void scale(float factor, bool _x2x0 = true, bool _rho = true);
108#endif
109
110 // ---------------------- Z slice manipulation
111 // convert Z to Zslice
112 GPUd() RangeStatus isZOutside(float z) const { return z < getZMin() ? Below : (z > getZMax() ? Above : Within); }
113 GPUd() int getZBinID(float z) const
114 {
115 int idz = int((z - getZMin()) * getDZInv()); // cannot be negative since before isZOutside is applied
116 return idz < getNZBins() ? (idz > 0 ? idz : 0) : getNZBins() - 1;
117 }
118
119 // lower boundary of Z slice
120 GPUd() float getZBinMin(int id) const { return getZMin() + id * getDZ(); }
121
122 // upper boundary of Z slice
123 GPUd() float getZBinMax(int id) const { return getZMin() + (id + 1) * getDZ(); }
124
125 // ---------------------- Phi slice manipulation (0:2pi convention, no check is done)
126 GPUd() int phiBin2Slice(int i) const { return mPhiBin2Slice[i]; }
127 GPUd() int getPhiSliceID(float phi) const { return phiBin2Slice(getPhiBinID(phi)); }
128
129 // lower boundary of phi slice
130 GPUd() float getPhiBinMin(int id) const { return id * getDPhi(); }
131
132 // upper boundary of phi slice
133 GPUd() float getPhiBinMax(int id) const { return (id + 1) * getDPhi(); }
134
135 // sin and cosine of the slice lower angle
136 GPUd() float getSliceCos(int i) const { return mSliceCos[i]; }
137 GPUd() float getSliceSin(int i) const { return mSliceSin[i]; }
138
139#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
140 void getMeanRMS(MatCell& mean, MatCell& rms) const;
141 bool cellsDiffer(const MatCell& cellA, const MatCell& cellB, float maxRelDiff) const;
142 bool canMergePhiSlices(int i, int j, float maxRelDiff = 0.05, int maxDifferent = 1) const;
143 void optimizePhiSlices(float maxRelDiff = 0.05);
144 void flatten(char* newPtr);
145#endif // !GPUCA_ALIGPUCODE
146
147#ifndef GPUCA_GPUCODE
148 std::size_t estimateFlatBufferSize() const
149 {
150 return estimateFlatBufferSize(getNPhiBins(), getNPhiSlices(), getNZBins());
151 }
152 static std::size_t estimateFlatBufferSize(int nPhiBins, int nPhiSlices, int nZBins)
153 {
154 size_t sz = 0;
155 sz += alignSize(sz + nPhiBins * sizeof(short), getBufferAlignmentBytes()); // mPhiBin2Slice
156 sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceCos
157 sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceSin
158 sz += alignSize(sz + nPhiSlices * nZBins * sizeof(MatCell), getBufferAlignmentBytes()); // mSliceSin
159 return sz;
160 }
161 void fixPointers(char* oldPtr, char* newPtr);
162 void setFlatPointer(char* ptr)
163 {
164 // brute force assignment of new pointers
168 }
169 }
170
172 static constexpr size_t getClassAlignmentBytes() { return 8; }
174 static constexpr size_t getBufferAlignmentBytes() { return 8; }
175#endif
176 // linearized cell ID from phi bin and z bin
177 GPUd() int getCellIDPhiBin(int iphi, int iz) const { return getCellID(phiBin2Slice(iphi), iz); }
178
179 protected:
180 GPUd() int getNCells() const { return getNZBins() * getNPhiSlices(); }
181 GPUd() float getDZInv() const { return mDZInv; }
182 GPUd() float getDPhiInv() const { return mDPhiInv; }
183
184 // linearized cell ID from phi slice and z bin
185 GPUd() int getCellID(int iphi, int iz) const { return iphi * getNZBins() + iz; }
186
187 // convert Phi (in 0:2pi convention) to PhiBinID
188 GPUd() int getPhiBinID(float phi) const
189 {
190 auto idphi = int(phi * getDPhiInv());
191 return idphi < getNPhiBins() ? idphi : getNPhiBins() - 1;
192 }
193
194 GPUd() int getEdgePhiBinOfSlice(int phiBin, int dir) const
195 {
196 // Get edge bin (in direction dir) of the slice, to which phiBin belongs
197 // No check for phiBin validity is done
198 auto slice = phiBin2Slice(phiBin);
199 while (slice == phiBin2Slice((phiBin += dir))) {
200 ;
201 }
202 return phiBin - dir;
203 }
204
205 //------------------------------------------------------
206
207 short mNZBins;
208 short mNPhiBins;
210 //
211 float mZHalf;
212 float mRMin2;
213 float mRMax2;
214 float mDZ;
215 float mDZInv;
216 float mDPhi;
217 float mDPhiInv;
218
220
221 float* mSliceCos;
222 float* mSliceSin;
223
225
227};
228
229} // namespace base
230} // namespace o2
231
232#endif
int getCellRow(const Cell2D &cell)
Definition of the GeometryManager class.
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:87
GPUd() float getRMax() const
Definition MatLayerCyl.h:82
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
void populateFromTGeo(int ntrPerCell=10, MatbudGeomBackend backend=MatbudGeomBackend::ROOT)
GPUd() float getDPhi() const
Definition MatLayerCyl.h:94
GPUd() int getNPhiSlices() const
Definition MatLayerCyl.h:88
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:86
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() const MatCell *getCellRow(int iphiSlice) const
Definition MatLayerCyl.h:99
GPUd() float getZMin() const
Definition MatLayerCyl.h:83
GPUd() float getPhiBinMin(int id) const
int int &binMax const
Definition MatLayerCyl.h:89
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:92
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)
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:84
void setFlatPointer(char *ptr)
GPUd() int getZBinID(float z) const
GPUd() float getRMin() const
Definition MatLayerCyl.h:78
GPUd() float getDZ() const
Definition MatLayerCyl.h:93
GPUd() int getCellIDPhiBin(int iphi
GPUd() const MatCell &getCell(int iphiSlice
float mDPhiInv
phi slice thickness inverse
bool canMergePhiSlices(int i, int j, float maxRelDiff=0.05, int maxDifferent=1) const
char * mFlatBufferContainer
Definition FlatObject.h:322
static constexpr size_t alignSize(size_t sizeBytes, size_t alignmentBytes)
_______________ Generic utilities _______________________________________________
Definition FlatObject.h:275
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 ...