18#ifndef GPUCA_ALIGPUCODE
28MatLayerCyl::MatLayerCyl() : mNZBins(0), mNPhiBins(0), mNPhiSlices(0), mZHalf(0.f), mRMin2(0.f), mRMax2(0.f), mDZ(0.f), mDZInv(0.f), mDPhi(0.f), mDPhiInv(0.f), mPhiBin2Slice(nullptr), mSliceCos(nullptr), mSliceSin(nullptr), mCells(nullptr)
33#ifndef GPUCA_ALIGPUCODE
48 if (drphiMin < 0.001f) {
52 int nz = 2 * zHalfSpan / dzMin, nphi = peri / drphiMin;
53 initSegmentation(rMin, rMax, zHalfSpan, nz < 1 ? 1 : nz, nphi < 1 ? 1 : nphi);
78 mDZ = 2. * zHalfSpan / nz;
89 for (
int i = nphi;
i--;) {
101 for (
int i = nphi;
i--;) {
102 mSliceCos[
i] = o2::math_utils::cos(getPhiBinMin(
i));
103 mSliceSin[
i] = o2::math_utils::sin(getPhiBinMin(
i));
117 ntrPerCell = ntrPerCell > 1 ? ntrPerCell : 1;
118 for (
int iz = getNZBins();
iz--;) {
119 for (
int ip = getNPhiBins(); ip--;) {
130 float zmn = getZBinMin(
iz), phmn = getPhiBinMin(ip), sn, cs, rMin = getRMin(), rMax = getRMax();
131 double meanRho = 0., meanX2X0 = 0., lgt = 0.;
133 float dz = getDZ() / ntrPerCell;
134 for (
int isz = ntrPerCell; isz--;) {
135 float zs = zmn + (isz + 0.5) * dz;
136 float dzt = zs > 0.f ? 0.25 * dz : -0.25 * dz;
137 for (
int isp = ntrPerCell; isp--;) {
138 o2::math_utils::sincos(phmn + (isp + 0.5) * getDPhi() / ntrPerCell, sn, cs);
140 if (bud.length > 0.) {
141 meanRho += bud.length * bud.meanRho;
142 meanX2X0 += bud.meanX2X0;
148 auto& cell =
mCells[getCellIDPhiBin(ip,
iz)];
150 cell.meanX2X0 = meanX2X0 / lgt;
157 if (std::abs(
i -
j) > 1 ||
i ==
j || std::max(
i,
j) >= getNPhiSlices()) {
158 LOG(error) <<
"Only existing " << getNPhiSlices() <<
" slices with diff. of 1 can be merged, input is " <<
i <<
" and " <<
j;
162 for (
int iz = getNZBins();
iz--;) {
163 const auto& cellI = getCellPhiBin(
i,
iz);
164 const auto& cellJ = getCellPhiBin(
j,
iz);
166 if (++ndiff > maxDifferent) {
180 if (rav > 0 && std::abs(rdf / rav) > maxRelDiff) {
183 if (xav > 0 && std::abs(xdf / xav) > maxRelDiff) {
193 if (getNPhiSlices() < getNPhiBins()) {
194 LOG(error) << getNPhiBins() <<
" phi bins were already merged to " << getNPhiSlices() <<
" slices";
198 std::vector<int> phi2SlNew(getNPhiBins());
199 for (
int i = 0;
i < getNPhiBins();
i++) {
202 for (
int is = 1; is < getNPhiSlices(); is++) {
208 phi2SlNew[is] = newSl;
210 if (newSl + 1 == getNPhiSlices()) {
214 int slMin = 0, slMax = 0, is = 0;
215 while (is++ < getNPhiSlices()) {
216 while (is < getNPhiSlices() && phi2SlNew[is] == newSl) {
220 if (slMax > slMin || newSl != slMin) {
223 float norm = 1.f / (1.f + slMax - slMin);
224 for (
int iz = getNZBins();
iz--;) {
225 int iDest = newSl * getNZBins() +
iz, iSrc = slMin * getNZBins() +
iz;
227 for (
int ism = slMin + 1; ism <= slMax; ism++) {
228 iSrc = ism * getNZBins() +
iz;
232 mCells[iDest].scale(norm);
234 LOG(info) <<
"mapping " << slMin <<
":" << slMax <<
" to new slice " << newSl;
239 for (
int i = 0;
i < getNPhiBins();
i++) {
253 LOG(info) <<
"Updated Nslices = " << getNPhiSlices();
260 mean.meanRho = rms.
meanRho = 0.f;
262 for (
int ip = getNPhiBins(); ip--;) {
263 for (
int iz = getNZBins();
iz--;) {
264 const auto& cell = getCellPhiBin(ip,
iz);
265 mean.meanRho += cell.meanRho;
266 mean.meanX2X0 += cell.meanX2X0;
267 rms.
meanRho += cell.meanRho * cell.meanRho;
268 rms.
meanX2X0 += cell.meanX2X0 * cell.meanX2X0;
271 int nc = getNPhiBins() * getNZBins();
276 rms.
meanRho -= mean.meanRho * mean.meanRho;
277 rms.
meanX2X0 -= mean.meanX2X0 * mean.meanX2X0;
287 printf(
"Cyl.Layer %.3f<r<%.3f %+.3f<Z<%+.3f | Nphi: %5d (%d slices) Nz: %5d Size: %.3f KB\n",
288 getRMin(), getRMax(), getZMin(), getZMax(), getNPhiBins(), getNPhiSlices(), getNZBins(), szkb);
292 for (
int ip = 0; ip < getNPhiSlices(); ip++) {
294 int nb = getNPhiBinsInSlice(ip, ib0, ib1);
295 printf(
"phi slice: %d (%d bins %d-%d %.4f:%.4f) sn:%+.4f/cs:%+.4f ... [iz/<rho>/<x/x0>] \n",
296 ip, nb, ib0, ib1, getDPhi() * ib0, getDPhi() * (ib1 + 1), getSliceSin(ip), getSliceCos(ip));
297 for (
int iz = 0;
iz < getNZBins();
iz++) {
298 auto cell = getCellPhiBin(ib0,
iz);
299 printf(
"%3d/%.2e/%.2e ",
iz, cell.meanRho, cell.meanX2X0);
300 if (((
iz + 1) % 5) == 0) {
304 if (getNZBins() % 5) {
341 binMin = binMax = -1;
342 for (
int ib = getNPhiBins(); ib--;) {
343 if (phiBin2Slice(ib) == iSlice) {
344 binMax < 0 ? binMin = binMax = ib : binMin = ib;
General auxilliary methods.
Definition of the GeometryManager class.
Declarations for single cylindrical material layer class.
static o2::base::MatBudget meanMaterialBudget(float x0, float y0, float z0, float x1, float y1, float z1)
short mNPhiSlices
actual number of phi slices
MatCell * mCells
cached sin each phi slice
short mNPhiBins
number of phi bins (logical)
void optimizePhiSlices(float maxRelDiff=0.05)
float mRMin2
squared min r
std::size_t estimateFlatBufferSize() const
float mDZ
Z slice thickness.
float mDPhi
phi slice thickness
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
void print(bool data=false) const
float * mSliceSin
cached cos each phi slice
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
float * mSliceCos
mapping from analytical phi bin ID to real slice ID
void flatten(char *newPtr)
short mNZBins
number of Z bins
float mRMax2
squared max r
void fixPointers(char *oldPtr, char *newPtr)
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
uint32_t mConstructionMask
mask for constructed object members, first two bytes are used by this class
int32_t mFlatBufferSize
size of the flat buffer
char * mFlatBufferContainer
static size_t alignSize(size_t sizeBytes, size_t alignmentBytes)
_______________ Generic utilities _______________________________________________
static T * relocatePointer(const char *oldBase, char *newBase, const T *ptr)
Relocates a pointer inside a buffer to the new buffer address.
size_t getFlatBufferSize() const
Gives size of the flat buffer.
@ InProgress
construction started: temporary memory is reserved
@ NotConstructed
the object is not constructed
@ Constructed
the object is constructed, temporary memory is released
T * resizeArray(T *&ptr, int32_t oldSize, int32_t newSize, T *newPtr=nullptr)
float meanRho
mean density, g/cm^3
float meanX2X0
fraction of radiaton lenght
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"