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