36 assert(rmin < rmax && zmax > 0 && dz > 0 && drphi > 0);
38 int nlr = getNLayers();
50 for (
int il = 0; il < nlr; il++) {
52 if (lr.getRMax() > rmin && rmax > lr.getRMin()) {
53 LOG(fatal) <<
"new layer overlaps with layer " << il;
58 for (
int i = nlr;
i--;) {
59 oldLayers[
i].clearInternalBufferPtr();
62 get()->mLayers[nlr].initSegmentation(rmin, rmax, zmax, dz, drphi);
64 get()->mRMin = get()->mRMin > rmin ? rmin : get()->mRMin;
65 get()->mRMax = get()->mRMax < rmax ? rmax : get()->mRMax;
66 get()->mZMax = get()->mZMax < zmax ? zmax : get()->mZMax;
67 get()->mRMin2 = get()->mRMin * get()->mRMin;
68 get()->mRMax2 = get()->mRMax * get()->mRMax;
99 int nlr = getNLayers();
100 int nR2Int = 2 * (nlr + 1);
103 get()->mR2Intervals[0] = get()->mRMin2;
104 get()->mR2Intervals[1] = get()->mRMax2;
105 get()->mInterval2LrID[0] = 0;
106 auto& nRIntervals = get()->mNRIntervals;
109 for (
int i = 1;
i < nlr;
i++) {
111 if (o2::math_utils::sqrt(lr.getRMin2()) > o2::math_utils::sqrt(get()->mR2Intervals[nRIntervals] +
Ray::Tiny)) {
113 get()->mInterval2LrID[nRIntervals] = -1;
114 get()->mR2Intervals[++nRIntervals] = lr.getRMin2();
116 get()->mInterval2LrID[nRIntervals] =
i;
117 get()->mR2Intervals[++nRIntervals] = lr.getRMax2();
130 for (
int i = 0;
i < getNLayers();
i++) {
132 float r = 0.5 * (lr.getRMin() + lr.getRMax());
134 int nphib = lr.getNPhiBins();
135 for (
int ip = 0; ip < nphib; ip++) {
136 float phi = 0.5 * (lr.getPhiBinMin(ip) + lr.getPhiBinMax(ip));
138 int ips = lr.phiBin2Slice(ip);
140 if (ip + 1 < nphib) {
141 int ips1 = lr.phiBin2Slice(ip + 1);
142 merge = ips == ips1 ? -1 : lr.canMergePhiSlices(ips, ips1);
146 o2::math_utils::sincos(phi, sn, cs);
147 float x =
r * cs,
y =
r * sn;
148 for (
int iz = 0; iz < lr.getNZBins(); iz++) {
149 float z = 0.5 * (lr.getZBinMin(iz) + lr.getZBinMax(iz));
150 auto cell = lr.getCellPhiBin(ip, iz);
152 <<
"ilr=" <<
i <<
"r=" <<
r <<
"phi=" << phi <<
"x=" <<
x <<
"y=" <<
y <<
"z=" <<
z <<
"ip=" << ip <<
"ips=" << ips <<
"iz=" << iz
153 <<
"mrgnxt=" <<
merge <<
"val=" << cell <<
"\n";
159 lr.getMeanRMS(mean, rms);
161 <<
"ilr=" <<
i <<
"r=" <<
r <<
"mean=" << mean <<
"rms=" << rms <<
"\n";
285 if (ray.isTooShort() || !getLayersRange(ray, lmin, lmax)) {
286 rval.
length = ray.getDist();
290 while (lrID >= lmin) {
291 const auto& lr = getLayer(lrID);
292 int nphiSlices = lr.getNPhiSlices();
293 int nc = ray.crossLayer(lr);
294 for (
int ic = nc; ic--;) {
295 float cross1, cross2;
296 ray.getCrossParams(ic, cross1, cross2);
298 auto phi0 = ray.getPhi(cross1), phi1 = ray.getPhi(cross2), dPhi = phi0 - phi1;
299 auto phiID = lr.getPhiSliceID(phi0), phiIDLast = lr.getPhiSliceID(phi1);
303 phiIDLast += nphiSlices;
311 int stepPhiID = phiID > phiIDLast ? -1 : 1;
312 bool checkMorePhi =
true;
313 auto tStartPhi = cross1, tEndPhi = 0.f;
316 if (phiID == phiIDLast) {
318 checkMorePhi =
false;
320 tEndPhi = ray.crossRadial(lr, (stepPhiID > 0 ? phiID + 1 : phiID) % nphiSlices);
325 auto zID = lr.getZBinID(ray.getZ(tStartPhi));
326 auto zIDLast = lr.getZBinID(ray.getZ(tEndPhi));
330 printf(
"-- Zdiff (%3d : %3d) mode: t: %+e %+e\n", zID, zIDLast, tStartPhi, tEndPhi);
333 if (zID != zIDLast) {
334 auto stepZID = zID < zIDLast ? 1 : -1;
335 bool checkMoreZ =
true;
336 auto tStartZ = tStartPhi, tEndZ = 0.f;
338 if (zID == zIDLast) {
342 tEndZ = ray.crossZ(lr.getZBinMin(stepZID > 0 ? zID + 1 : zID));
348 float step = tEndZ > tStartZ ? tEndZ - tStartZ : tStartZ - tEndZ;
349 const auto& cell = lr.getCell(phiID % nphiSlices, zID);
350 rval.
meanRho += cell.meanRho * step;
351 rval.
meanX2X0 += cell.meanX2X0 * step;
355 float pos0[3] = {ray.getPos(tStartZ, 0), ray.getPos(tStartZ, 1), ray.getPos(tStartZ, 2)};
356 float pos1[3] = {ray.getPos(tEndZ, 0), ray.getPos(tEndZ, 1), ray.getPos(tEndZ, 2)};
358 "Lr#%3d / cross#%d : account %f<t<%f at phiSlice %d | Zbin: %3d (%3d) |[%+e %+e +%e]:[%+e %+e %+e] "
359 "Step: %.3e StrpCor: %.3e\n",
360 lrID, ic, tEndZ, tStartZ, phiID % nphiSlices, zID, zIDLast,
361 pos0[0], pos0[1], pos0[2], pos1[0], pos1[1], pos1[2], step, ray.getDist(step));
366 }
while (checkMoreZ);
368 float step = tEndPhi > tStartPhi ? tEndPhi - tStartPhi : tStartPhi - tEndPhi;
369 const auto& cell = lr.getCell(phiID % nphiSlices, zID);
370 rval.
meanRho += cell.meanRho * step;
371 rval.
meanX2X0 += cell.meanX2X0 * step;
375 float pos0[3] = {ray.getPos(tStartPhi, 0), ray.getPos(tStartPhi, 1), ray.getPos(tStartPhi, 2)};
376 float pos1[3] = {ray.getPos(tEndPhi, 0), ray.getPos(tEndPhi, 1), ray.getPos(tEndPhi, 2)};
378 "Lr#%3d / cross#%d : account %f<t<%f at phiSlice %d | Zbin: %3d ----- |[%+e %+e +%e]:[%+e %+e %+e]"
379 "Step: %.3e StrpCor: %.3e\n",
380 lrID, ic, tEndPhi, tStartPhi, phiID % nphiSlices, zID,
381 pos0[0], pos0[1], pos0[2], pos1[0], pos1[1], pos1[2], step, ray.getDist(step));
388 }
while (checkMorePhi);
397 rval.
length = ray.getDist();
412 ray.getMinMaxR2(rmin2, rmax2);
414 if (rmin2 >= getRMax2() || rmax2 <= getRMin2()) {
418 if (!mInitializedLayerVoxelLU) {
419 lmxInt = rmax2 < getRMax2() ? searchSegment(rmax2, 0) :
get()->mNRIntervals - 2;
420 lmnInt = rmin2 >= getRMin2() ? searchSegment(rmin2, 0, lmxInt + 1) : 0;
422 lmxInt = rmax2 < getRMax2() ? searchLayerFast(rmax2, 0) :
get()->mNRIntervals - 2;
423 lmnInt = rmin2 >= getRMin2() ? searchLayerFast(rmin2, 0, lmxInt + 1) : 0;
426 const auto* interval2LrID =
get()->mInterval2LrID;
427 lmax = interval2LrID[lmxInt];
428 lmin = interval2LrID[lmnInt];
431 lmax = interval2LrID[lmxInt - 1];
434 lmin = interval2LrID[lmnInt + 1];
442 const auto index = 2 *
int(o2::gpu::CAMath::Sqrt(r2) * InvVoxelRDelta);
443 const auto layersfirst = mLayerVoxelLU[
index];
444 const auto layerslast = mLayerVoxelLU[
index + 1];
445 if (layersfirst != layerslast) {
447 return searchSegment(r2, layersfirst, layerslast + 1);
459 high =
get()->mNRIntervals;
461 int mid = (low + high) >> 1;
462 const auto* r2Intervals =
get()->mR2Intervals;
464 if (
val < r2Intervals[mid]) {
469 mid = (low + high) >> 1;
475#ifndef GPUCA_ALIGPUCODE
487 int nLr = getNLayers();
493 for (
int i = nLr;
i--;) {
494 oldLayers[
i].clearInternalBufferPtr();
507 for (
int il = 0; il < nLr; il++) {
586 Ray ray(std::max(getRMin(), rmin), 0., 0., std::min(getRMax(), rmax), 0., 0.);
588 if (!getLayersRange(ray,
lmin, lmax)) {
589 LOGP(warn,
"No layers found for {} < r < {}", rmin, rmax);
592 LOGP(info,
"Will extract layers {}:{} (out of {} layers) for {} < r < {}",
lmin, lmax, getNLayers(), rmin, rmax);
595 for (
int il =
lmin; il <= lmax; il++) {
597 float drphi = lr.getDPhi() * (lr.getRMin() + lr.getRMax()) / 2. * 0.999;
598 copy->
addLayer(lr.getRMin(), lr.getRMax(), lr.getZMax(), lr.getDZ(), drphi);
599 auto& lrNew = copy->
getLayer(lrCount);
600 for (
int iz = 0; iz < lrNew.getNZBins(); iz++) {
601 for (
int ip = 0; ip < lrNew.getNPhiBins(); ip++) {
602 lrNew.getCellPhiBin(ip, iz).set(lr.getCellPhiBin(ip, iz));