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