-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathMatLayerCyl.h
More file actions
226 lines (189 loc) · 8.6 KB
/
MatLayerCyl.h
File metadata and controls
226 lines (189 loc) · 8.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file MatLayerCyl.h
/// \brief Declarations for single cylindrical material layer class
#ifndef ALICEO2_MATLAYERCYL_H
#define ALICEO2_MATLAYERCYL_H
#ifndef GPUCA_GPUCODE_DEVICE
#include <cmath>
#include <cstring>
#endif
#include "GPUCommonDef.h"
#include "FlatObject.h"
#include "GPUCommonRtypes.h"
#include "GPUCommonMath.h"
#include "DetectorsBase/MatCell.h"
namespace o2
{
namespace base
{
/**********************************************************************
* *
* Material data on the cells of cylindrical layer *
* Cell is limited by 2 radial planes at phiMin,phiMax, *
* radii radMin,radMax and XY planes at zMin, zMax. *
* This limits are defined in the cell container class *
* *
* *
* Cylindrical material layer *
* *
* Logical division is given by mNZBins and mNPhiBins *
* but the actual number phi slices might be less if neighbouring *
* phi bins with similar properties are merged together. The actual *
* phi slice should be accessed via mPhiBin2Slice map. *
* *
**********************************************************************/
class MatLayerCyl : public o2::gpu::FlatObject
{
public:
enum RangeStatus : short { Below = -1,
Within = 0,
Above = 1 };
#ifndef GPUCA_GPUCODE
MatLayerCyl();
MatLayerCyl(const MatLayerCyl& src) = delete;
~MatLayerCyl() = default;
#endif
#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
MatLayerCyl(float rMin, float rMax, float zHalfSpan, float dzMin, float drphiMin);
void initSegmentation(float rMin, float rMax, float zHalfSpan, int nz, int nphi);
void initSegmentation(float rMin, float rMax, float zHalfSpan, float dzMin, float drphiMin);
void populateFromTGeo(int ntrPerCell = 10);
void populateFromTGeo(int ip, int iz, int ntrPerCell);
void print(bool data = false) const;
#endif // !GPUCA_ALIGPUCODE
GPUd() float getRMin() const
{
return o2::gpu::CAMath::Sqrt(getRMin2());
}
GPUd() float getRMax() const { return o2::gpu::CAMath::Sqrt(getRMax2()); }
GPUd() float getZMin() const { return -mZHalf; }
GPUd() float getZMax() const { return mZHalf; }
GPUd() int getNZBins() const { return mNZBins; }
GPUd() int getNPhiBins() const { return mNPhiBins; }
GPUd() int getNPhiSlices() const { return mNPhiSlices; }
GPUd() int getNPhiBinsInSlice(int iSlice, int& binMin, int& binMax) const;
GPUd() float getRMin2() const { return mRMin2; }
GPUd() float getRMax2() const { return mRMax2; }
GPUd() float getDZ() const { return mDZ; }
GPUd() float getDPhi() const { return mDPhi; }
// obtain material cell, cell ID must be valid
GPUd() const MatCell& getCellPhiBin(int iphi, int iz) const { return mCells[getCellIDPhiBin(iphi, iz)]; }
GPUd() const MatCell& getCell(int iphiSlice, int iz) const { return mCells[getCellID(iphiSlice, iz)]; }
#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
MatCell& getCellPhiBin(int iphi, int iz)
{
return mCells[getCellIDPhiBin(iphi, iz)];
}
void scale(float factor, bool _x2x0 = true, bool _rho = true);
#endif
// ---------------------- Z slice manipulation
// convert Z to Zslice
GPUd() RangeStatus isZOutside(float z) const { return z < getZMin() ? Below : (z > getZMax() ? Above : Within); }
GPUd() int getZBinID(float z) const
{
int idz = int((z - getZMin()) * getDZInv()); // cannot be negative since before isZOutside is applied
return idz < getNZBins() ? idz : getNZBins() - 1;
}
// lower boundary of Z slice
GPUd() float getZBinMin(int id) const { return getZMin() + id * getDZ(); }
// upper boundary of Z slice
GPUd() float getZBinMax(int id) const { return getZMin() + (id + 1) * getDZ(); }
// ---------------------- Phi slice manipulation (0:2pi convention, no check is done)
GPUd() int phiBin2Slice(int i) const { return mPhiBin2Slice[i]; }
GPUd() int getPhiSliceID(float phi) const { return phiBin2Slice(getPhiBinID(phi)); }
// lower boundary of phi slice
GPUd() float getPhiBinMin(int id) const { return id * getDPhi(); }
// upper boundary of phi slice
GPUd() float getPhiBinMax(int id) const { return (id + 1) * getDPhi(); }
// sin and cosine of the slice lower angle
GPUd() float getSliceCos(int i) const { return mSliceCos[i]; }
GPUd() float getSliceSin(int i) const { return mSliceSin[i]; }
#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
void getMeanRMS(MatCell& mean, MatCell& rms) const;
bool cellsDiffer(const MatCell& cellA, const MatCell& cellB, float maxRelDiff) const;
bool canMergePhiSlices(int i, int j, float maxRelDiff = 0.05, int maxDifferent = 1) const;
void optimizePhiSlices(float maxRelDiff = 0.05);
void flatten(char* newPtr);
#endif // !GPUCA_ALIGPUCODE
#ifndef GPUCA_GPUCODE
std::size_t estimateFlatBufferSize() const
{
return estimateFlatBufferSize(getNPhiBins(), getNPhiSlices(), getNZBins());
}
static std::size_t estimateFlatBufferSize(int nPhiBins, int nPhiSlices, int nZBins)
{
size_t sz = 0;
sz += alignSize(sz + nPhiBins * sizeof(short), getBufferAlignmentBytes()); // mPhiBin2Slice
sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceCos
sz += alignSize(sz + nPhiSlices * sizeof(float), getBufferAlignmentBytes()); // mSliceSin
sz += alignSize(sz + nPhiSlices * nZBins * sizeof(MatCell), getBufferAlignmentBytes()); // mSliceSin
return sz;
}
void fixPointers(char* oldPtr, char* newPtr);
void setFlatPointer(char* ptr)
{
// brute force assignment of new pointers
mFlatBufferPtr = ptr;
if (mFlatBufferContainer) {
mFlatBufferContainer = ptr;
}
}
/// Gives minimal alignment in bytes required for the class object
static constexpr size_t getClassAlignmentBytes() { return 8; }
/// Gives minimal alignment in bytes required for the flat buffer
static constexpr size_t getBufferAlignmentBytes() { return 8; }
#endif
// linearized cell ID from phi bin and z bin
GPUd() int getCellIDPhiBin(int iphi, int iz) const { return getCellID(phiBin2Slice(iphi), iz); }
protected:
GPUd() int getNCells() const { return getNZBins() * getNPhiSlices(); }
GPUd() float getDZInv() const { return mDZInv; }
GPUd() float getDPhiInv() const { return mDPhiInv; }
// linearized cell ID from phi slice and z bin
GPUd() int getCellID(int iphi, int iz) const { return iphi * getNZBins() + iz; }
// convert Phi (in 0:2pi convention) to PhiBinID
GPUd() int getPhiBinID(float phi) const
{
auto idphi = int(phi * getDPhiInv());
return idphi < getNPhiBins() ? idphi : getNPhiBins() - 1;
}
GPUd() int getEdgePhiBinOfSlice(int phiBin, int dir) const
{
// Get edge bin (in direction dir) of the slice, to which phiBin belongs
// No check for phiBin validity is done
auto slice = phiBin2Slice(phiBin);
while (slice == phiBin2Slice((phiBin += dir))) {
;
}
return phiBin - dir;
}
//------------------------------------------------------
short mNZBins; ///< number of Z bins
short mNPhiBins; ///< number of phi bins (logical)
short mNPhiSlices; ///< actual number of phi slices
//
float mZHalf; ///< Z half span
float mRMin2; ///< squared min r
float mRMax2; ///< squared max r
float mDZ; ///< Z slice thickness
float mDZInv; ///< Z slice thickness inverse
float mDPhi; ///< phi slice thickness
float mDPhiInv; ///< phi slice thickness inverse
short* mPhiBin2Slice; //! mapping from analytical phi bin ID to real slice ID
float* mSliceCos; //! cached cos each phi slice
float* mSliceSin; //! cached sin each phi slice
MatCell* mCells; //! mat.budget per cell
ClassDefNV(MatLayerCyl, 1);
};
} // namespace base
} // namespace o2
#endif