Skip to content

Commit 5b0d25d

Browse files
authored
Possibility to combine 2 material LUTs (AliceO2Group#14861)
1 parent 297aa69 commit 5b0d25d

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Detectors/Base/include/DetectorsBase/MatLayerCylSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class MatLayerCylSet : public o2::gpu::FlatObject
8787
void flatten();
8888

8989
MatLayerCyl& getLayer(int i) { return get()->mLayers[i]; }
90-
MatLayerCylSet* extractCopy(float rmin, float rmax, float tol = 1e-3) const;
90+
MatLayerCylSet* extractCopy(float rmin, float rmax, float tol = 1e-3, const MatLayerCylSet* toAdd = nullptr) const;
9191
void finalizeStructures();
9292

9393
#endif // !GPUCA_ALIGPUCODE

Detectors/Base/src/MatLayerCylSet.cxx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,12 @@ void MatLayerCylSet::fixPointers(char* oldPtr, char* newPtr, bool newPtrValid)
608608

609609
#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
610610

611-
MatLayerCylSet* MatLayerCylSet::extractCopy(float rmin, float rmax, float tolerance) const
611+
MatLayerCylSet* MatLayerCylSet::extractCopy(float rmin, float rmax, float tolerance, const MatLayerCylSet* addTo) const
612612
{
613+
// extract layers in the covering rmin-rmax range. If addTo is provided, simply substitute its layers by those from this
614+
if (addTo && addTo->getNLayers() != getNLayers()) {
615+
LOGP(fatal, "addTo has {} layers, this has {}", addTo->getNLayers(), getNLayers());
616+
}
613617
Ray ray(std::max(getRMin(), rmin), 0., 0., std::min(getRMax(), rmax), 0., 0.);
614618
short lmin, lmax;
615619
if (!getLayersRange(ray, lmin, lmax)) {
@@ -618,23 +622,37 @@ MatLayerCylSet* MatLayerCylSet::extractCopy(float rmin, float rmax, float tolera
618622
}
619623
LOGP(info, "Will extract layers {}:{} (out of {} layers) for {} < r < {}", lmin, lmax, getNLayers(), rmin, rmax);
620624
MatLayerCylSet* copy = new MatLayerCylSet();
621-
int lrCount = 0;
622-
for (int il = lmin; il <= lmax; il++) {
623-
const auto& lr = getLayer(il);
625+
int lrCount = 0, lrCounOld = 0, lrCountTot = 0;
626+
auto addLr = [copy, &lrCountTot](const MatLayerCyl& lr) {
624627
float drphi = lr.getDPhi() * (lr.getRMin() + lr.getRMax()) / 2. * 0.999;
625628
copy->addLayer(lr.getRMin(), lr.getRMax(), lr.getZMax(), lr.getDZ(), drphi);
626-
auto& lrNew = copy->getLayer(lrCount);
629+
auto& lrNew = copy->getLayer(lrCountTot++);
627630
for (int iz = 0; iz < lrNew.getNZBins(); iz++) {
628631
for (int ip = 0; ip < lrNew.getNPhiBins(); ip++) {
629632
lrNew.getCellPhiBin(ip, iz).set(lr.getCellPhiBin(ip, iz));
630633
}
631634
}
635+
};
636+
if (addTo) {
637+
for (int il = 0; il < lmin; il++) {
638+
addLr(addTo->getLayer(il));
639+
lrCounOld++;
640+
}
641+
}
642+
for (int il = lmin; il <= lmax; il++) {
643+
addLr(getLayer(il));
632644
lrCount++;
633645
}
634-
646+
if (addTo) {
647+
for (int il = lmax + 1; il < getNLayers(); il++) {
648+
addLr(addTo->getLayer(il));
649+
lrCounOld++;
650+
}
651+
}
635652
copy->finalizeStructures();
636653
copy->optimizePhiSlices(tolerance);
637654
copy->flatten();
655+
LOGP(info, "Added layers {}:{} for {}<r<{} {}", lmin, lmax, rmin, rmax, fmt::format(", {} layers were transferred from additional set", lrCounOld));
638656
return copy;
639657
}
640658

0 commit comments

Comments
 (0)