Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 07:52:49

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Geometry/CylinderVolumeStack.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Definitions/Tolerance.hpp"
0014 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0015 #include "Acts/Utilities/BinningType.hpp"
0016 #include "Acts/Utilities/Logger.hpp"
0017 
0018 #include <algorithm>
0019 #include <memory>
0020 #include <numbers>
0021 #include <sstream>
0022 
0023 namespace Acts {
0024 
0025 struct CylinderVolumeStack::VolumeTuple {
0026   Volume* volume{};
0027   const CylinderVolumeBounds* bounds{};
0028   std::shared_ptr<CylinderVolumeBounds> updatedBounds{};
0029   Transform3 localTransform = Transform3::Identity();
0030   Transform3 globalTransform = Transform3::Identity();
0031 
0032   bool transformDirty = false;
0033 
0034   VolumeTuple(Volume& volume_, const Transform3& groupTransform)
0035       : volume{&volume_},
0036         localTransform{groupTransform.inverse() * volume_.transform()},
0037         globalTransform{volume_.transform()} {
0038     bounds = dynamic_cast<const CylinderVolumeBounds*>(&volume_.volumeBounds());
0039     assert(bounds != nullptr);
0040     updatedBounds = std::make_shared<CylinderVolumeBounds>(*bounds);
0041   }
0042 
0043   double midZ() const { return localTransform.translation()[eZ]; }
0044   double halfLengthZ() const {
0045     return updatedBounds->get(CylinderVolumeBounds::eHalfLengthZ);
0046   }
0047   double minZ() const { return midZ() - halfLengthZ(); }
0048   double maxZ() const { return midZ() + halfLengthZ(); }
0049 
0050   double minR() const {
0051     return updatedBounds->get(CylinderVolumeBounds::eMinR);
0052   }
0053   double maxR() const {
0054     return updatedBounds->get(CylinderVolumeBounds::eMaxR);
0055   }
0056   double midR() const { return (minR() + maxR()) / 2.0; }
0057 
0058   void set(std::initializer_list<
0059            std::pair<CylinderVolumeBounds::BoundValues, double>>
0060                keyValues) {
0061     updatedBounds->set(keyValues);
0062   }
0063 
0064   void setLocalTransform(const Transform3& transform,
0065                          const Transform3& groupTransform) {
0066     localTransform = transform;
0067     globalTransform = groupTransform * localTransform;
0068     transformDirty = true;
0069   }
0070 
0071   void commit(const Logger& logger) {
0072     // make a copy so we can't accidentally modify in-place
0073     auto copy = std::make_shared<CylinderVolumeBounds>(*updatedBounds);
0074 
0075     std::optional<Transform3> transform = std::nullopt;
0076     if (transformDirty) {
0077       transform = globalTransform;
0078     }
0079 
0080     volume->update(std::move(updatedBounds), transform, logger);
0081     bounds = copy.get();
0082     updatedBounds = std::move(copy);
0083     transformDirty = false;
0084   }
0085 };
0086 
0087 CylinderVolumeStack::CylinderVolumeStack(std::vector<Volume*>& volumes,
0088                                          AxisDirection direction,
0089                                          VolumeAttachmentStrategy strategy,
0090                                          VolumeResizeStrategy resizeStrategy,
0091                                          const Logger& logger)
0092     : CylinderVolumeStack{volumes,
0093                           direction,
0094                           strategy,
0095                           {resizeStrategy, resizeStrategy},
0096                           logger} {}
0097 
0098 CylinderVolumeStack::CylinderVolumeStack(
0099     std::vector<Volume*>& volumes, AxisDirection direction,
0100     VolumeAttachmentStrategy strategy,
0101     std::pair<VolumeResizeStrategy, VolumeResizeStrategy> resizeStrategies,
0102     const Logger& logger)
0103     : VolumeStack(volumes, direction,
0104                   {resizeStrategies.first, resizeStrategies.second}) {
0105   initializeOuterVolume(direction, strategy, logger);
0106 }
0107 
0108 void CylinderVolumeStack::initializeOuterVolume(
0109     AxisDirection direction, VolumeAttachmentStrategy strategy,
0110     const Logger& logger) {
0111   ACTS_DEBUG("Creating CylinderVolumeStack from "
0112              << m_volumes.size() << " volumes in direction "
0113              << axisDirectionName(direction));
0114   if (m_volumes.empty()) {
0115     throw std::invalid_argument(
0116         "CylinderVolumeStack requires at least one volume");
0117   }
0118 
0119   if (direction != Acts::AxisDirection::AxisZ &&
0120       direction != Acts::AxisDirection::AxisR) {
0121     throw std::invalid_argument(axisDirectionName(direction) +
0122                                 " is not supported ");
0123   }
0124 
0125   // For alignment check, we have to pick one of the volumes as the base
0126   m_groupTransform = m_volumes.front()->transform();
0127   ACTS_VERBOSE("Initial group transform is:\n" << m_groupTransform.matrix());
0128 
0129   std::vector<VolumeTuple> volumeTuples;
0130   volumeTuples.reserve(m_volumes.size());
0131 
0132   for (const auto& volume : m_volumes) {
0133     const auto* cylinderBounds =
0134         dynamic_cast<const CylinderVolumeBounds*>(&volume->volumeBounds());
0135     if (cylinderBounds == nullptr) {
0136       throw std::invalid_argument{
0137           "CylinderVolumeStack requires all volumes to "
0138           "have CylinderVolumeBounds"};
0139     }
0140 
0141     checkNoPhiOrBevel(*cylinderBounds, logger);
0142 
0143     volumeTuples.emplace_back(*volume, m_groupTransform);
0144   }
0145 
0146   ACTS_DEBUG("*** Initial volume configuration:");
0147   printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0148 
0149   if (m_volumes.size() == 1) {
0150     ACTS_VERBOSE("Only one volume, returning");
0151     setTransform(m_volumes.front()->transform());
0152     const auto* cylBounds = dynamic_cast<const CylinderVolumeBounds*>(
0153         &m_volumes.front()->volumeBounds());
0154     assert(cylBounds != nullptr && "Volume bounds are not cylinder bounds");
0155     Volume::update(std::make_shared<CylinderVolumeBounds>(*cylBounds),
0156                    std::nullopt, logger);
0157     ACTS_VERBOSE("Transform is now: " << m_transform.matrix());
0158     return;
0159   }
0160 
0161   ACTS_VERBOSE("Checking volume alignment");
0162   checkVolumeAlignment(volumeTuples, logger);
0163 
0164   if (direction == Acts::AxisDirection::AxisZ) {
0165     ACTS_VERBOSE("Sorting by volume z position");
0166     std::ranges::sort(volumeTuples, {}, [](const auto& v) {
0167       return v.localTransform.translation()[eZ];
0168     });
0169 
0170     ACTS_VERBOSE("Checking for overlaps and attaching volumes in z");
0171     std::vector<VolumeTuple> gapVolumes =
0172         checkOverlapAndAttachInZ(volumeTuples, strategy, logger);
0173 
0174     ACTS_VERBOSE("Appending "
0175                  << gapVolumes.size()
0176                  << " gap volumes to the end of the volume vector");
0177     std::copy(gapVolumes.begin(), gapVolumes.end(),
0178               std::back_inserter(volumeTuples));
0179 
0180     ACTS_VERBOSE("*** Volume configuration after z attachment:");
0181     printVolumeSequence(volumeTuples, logger, Acts::Logging::VERBOSE);
0182 
0183     ACTS_VERBOSE("Synchronizing bounds in r");
0184     const auto [minR, maxR] = synchronizeRBounds(volumeTuples, logger);
0185 
0186     for (auto& vt : volumeTuples) {
0187       ACTS_VERBOSE("Updated bounds for volume at z: "
0188                    << vt.localTransform.translation()[eZ]);
0189       ACTS_VERBOSE(*vt.updatedBounds);
0190 
0191       vt.commit(logger);
0192     }
0193 
0194     ACTS_VERBOSE("*** Volume configuration after r synchronization:");
0195     printVolumeSequence(volumeTuples, logger, Acts::Logging::VERBOSE);
0196 
0197     std::ranges::sort(volumeTuples, {}, [](const auto& v) { return v.midZ(); });
0198 
0199     m_volumes.clear();
0200     for (const auto& vt : volumeTuples) {
0201       m_volumes.push_back(vt.volume);
0202     }
0203 
0204     ACTS_DEBUG("*** Volume configuration after final z sorting:");
0205     printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0206 
0207     double minZ = volumeTuples.front().minZ();
0208     double maxZ = volumeTuples.back().maxZ();
0209 
0210     double midZ = (minZ + maxZ) / 2.0;
0211     double hlZ = (maxZ - minZ) / 2.0;
0212 
0213     m_transform = m_groupTransform * Translation3{0, 0, midZ};
0214 
0215     Volume::update(std::make_shared<CylinderVolumeBounds>(minR, maxR, hlZ),
0216                    std::nullopt, logger);
0217     ACTS_DEBUG("Outer bounds are:\n" << volumeBounds());
0218     ACTS_DEBUG("Outer transform / new group transform is:\n"
0219                << m_transform.matrix());
0220 
0221     // Update group transform to the new center
0222     // @TODO: We probably can reuse m_transform
0223     m_groupTransform = m_transform;
0224 
0225   } else if (direction == Acts::AxisDirection::AxisR) {
0226     ACTS_VERBOSE("Sorting by volume r middle point");
0227     std::ranges::sort(volumeTuples, {}, [](const auto& v) { return v.midR(); });
0228 
0229     ACTS_VERBOSE("Checking for overlaps and attaching volumes in r");
0230     std::vector<VolumeTuple> gapVolumes =
0231         checkOverlapAndAttachInR(volumeTuples, strategy, logger);
0232 
0233     ACTS_VERBOSE("Appending "
0234                  << gapVolumes.size()
0235                  << " gap volumes to the end of the volume vector");
0236     std::copy(gapVolumes.begin(), gapVolumes.end(),
0237               std::back_inserter(volumeTuples));
0238 
0239     ACTS_VERBOSE("*** Volume configuration after r attachment:");
0240     printVolumeSequence(volumeTuples, logger, Acts::Logging::VERBOSE);
0241 
0242     ACTS_VERBOSE("Synchronizing bounds in z");
0243     const auto [minZ, maxZ] = synchronizeZBounds(volumeTuples, logger);
0244 
0245     for (auto& vt : volumeTuples) {
0246       ACTS_VERBOSE("Updated bounds for volume at r: " << vt.midR());
0247       ACTS_VERBOSE(*vt.updatedBounds);
0248       vt.commit(logger);
0249     }
0250 
0251     ACTS_VERBOSE("*** Volume configuration after z synchronization:");
0252     printVolumeSequence(volumeTuples, logger, Acts::Logging::VERBOSE);
0253 
0254     std::ranges::sort(volumeTuples, {}, [](const auto& v) { return v.midR(); });
0255 
0256     m_volumes.clear();
0257     for (const auto& vt : volumeTuples) {
0258       m_volumes.push_back(vt.volume);
0259     }
0260 
0261     ACTS_DEBUG("*** Volume configuration after final r sorting:");
0262     printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0263 
0264     double minR = volumeTuples.front().minR();
0265     double maxR = volumeTuples.back().maxR();
0266 
0267     double midZ = (minZ + maxZ) / 2.0;
0268     double hlZ = (maxZ - minZ) / 2.0;
0269 
0270     m_transform = m_groupTransform * Translation3{0, 0, midZ};
0271 
0272     Volume::update(std::make_shared<CylinderVolumeBounds>(minR, maxR, hlZ),
0273                    std::nullopt, logger);
0274 
0275     ACTS_DEBUG("Outer bounds are:\n" << volumeBounds());
0276     ACTS_DEBUG("Outer transform is:\n" << m_transform.matrix());
0277 
0278     // Update group transform to the new center
0279     // @TODO: We probably can reuse m_transform
0280     m_groupTransform = m_transform;
0281 
0282   } else {
0283     ACTS_ERROR("Binning in " << axisDirectionName(direction)
0284                              << " is not supported");
0285     throw std::invalid_argument(axisDirectionName(direction) +
0286                                 " is not supported ");
0287   }
0288 }
0289 
0290 void CylinderVolumeStack::overlapPrint(
0291     AxisDirection direction, const CylinderVolumeStack::VolumeTuple& a,
0292     const CylinderVolumeStack::VolumeTuple& b, const Logger& logger) {
0293   if (logger().doPrint(Acts::Logging::DEBUG)) {
0294     std::stringstream ss;
0295     ss << std::fixed;
0296     ss << std::setprecision(3);
0297     ss << std::setfill(' ');
0298 
0299     int w = 9;
0300 
0301     ACTS_VERBOSE("Checking overlap between");
0302     if (direction == AxisDirection::AxisZ) {
0303       ss << " - " << " z: [ " << std::setw(w) << a.minZ() << " <- "
0304          << std::setw(w) << a.midZ() << " -> " << std::setw(w) << a.maxZ()
0305          << " ]";
0306       ACTS_VERBOSE(ss.str());
0307 
0308       ss.str("");
0309       ss << " - " << " z: [ " << std::setw(w) << b.minZ() << " <- "
0310          << std::setw(w) << b.midZ() << " -> " << std::setw(w) << b.maxZ()
0311          << " ]";
0312       ACTS_VERBOSE(ss.str());
0313     } else {
0314       ss << " - " << " r: [ " << std::setw(w) << a.minR() << " <-> "
0315          << std::setw(w) << a.maxR() << " ]";
0316       ACTS_VERBOSE(ss.str());
0317 
0318       ss.str("");
0319       ss << " - " << " r: [ " << std::setw(w) << b.minR() << " <-> "
0320          << std::setw(w) << b.maxR() << " ]";
0321       ACTS_VERBOSE(ss.str());
0322     }
0323   }
0324 }
0325 
0326 std::vector<CylinderVolumeStack::VolumeTuple>
0327 CylinderVolumeStack::checkOverlapAndAttachInZ(std::vector<VolumeTuple>& volumes,
0328                                               VolumeAttachmentStrategy strategy,
0329                                               const Logger& logger) {
0330   // Preconditions: volumes are sorted by z
0331   std::vector<VolumeTuple> gapVolumes;
0332   for (std::size_t i = 0; i < volumes.size() - 1; i++) {
0333     std::size_t j = i + 1;
0334     auto& a = volumes.at(i);
0335     auto& b = volumes.at(j);
0336 
0337     overlapPrint(AxisDirection::AxisZ, a, b, logger);
0338 
0339     if (a.maxZ() > b.minZ()) {
0340       ACTS_ERROR(" -> Overlap in z");
0341       throw std::invalid_argument("Volumes overlap in z");
0342     } else {
0343       ACTS_VERBOSE(" -> No overlap");
0344     }
0345 
0346     constexpr auto tolerance = s_onSurfaceTolerance;
0347     if (std::abs(a.maxZ() - b.minZ()) < tolerance) {
0348       ACTS_VERBOSE("No gap between volumes, no attachment needed");
0349     } else {
0350       double gapWidth = b.minZ() - a.maxZ();
0351       ACTS_VERBOSE("Gap width: " << gapWidth);
0352 
0353       ACTS_VERBOSE("Synchronizing bounds in z with strategy: " << strategy);
0354       switch (strategy) {
0355         case VolumeAttachmentStrategy::Midpoint: {
0356           ACTS_VERBOSE(" -> Strategy: Expand both volumes to midpoint");
0357 
0358           double aZMidNew = (a.minZ() + a.maxZ()) / 2.0 + gapWidth / 4.0;
0359           double aHlZNew = a.halfLengthZ() + gapWidth / 4.0;
0360           ACTS_VERBOSE("  - New halflength for first volume: " << aHlZNew);
0361           ACTS_VERBOSE("  - New bounds for first volume: ["
0362                        << (aZMidNew - aHlZNew) << " <- " << aZMidNew << " -> "
0363                        << (aZMidNew + aHlZNew) << "]");
0364 
0365           assert(std::abs(a.minZ() - (aZMidNew - aHlZNew)) < 1e-9 &&
0366                  "Volume shrunk");
0367           assert(aHlZNew >= a.halfLengthZ() && "Volume shrunk");
0368 
0369           double bZMidNew = (b.minZ() + b.maxZ()) / 2.0 - gapWidth / 4.0;
0370           double bHlZNew = b.halfLengthZ() + gapWidth / 4.0;
0371           ACTS_VERBOSE("  - New halflength for second volume: " << bHlZNew);
0372           ACTS_VERBOSE("  - New bounds for second volume: ["
0373                        << (bZMidNew - bHlZNew) << " <- " << bZMidNew << " -> "
0374                        << (bZMidNew + bHlZNew) << "]");
0375 
0376           assert(bHlZNew >= b.halfLengthZ() && "Volume shrunk");
0377           assert(std::abs(b.maxZ() - (bZMidNew + bHlZNew)) < 1e-9 &&
0378                  "Volume shrunk");
0379 
0380           a.setLocalTransform(Transform3{Translation3{0, 0, aZMidNew}},
0381                               m_groupTransform);
0382           a.updatedBounds->set(CylinderVolumeBounds::eHalfLengthZ, aHlZNew);
0383 
0384           b.setLocalTransform(Transform3{Translation3{0, 0, bZMidNew}},
0385                               m_groupTransform);
0386           b.updatedBounds->set(CylinderVolumeBounds::eHalfLengthZ, bHlZNew);
0387 
0388           break;
0389         }
0390         case VolumeAttachmentStrategy::First: {
0391           ACTS_VERBOSE(" -> Strategy: Expand first volume");
0392           double aZMidNew = (a.minZ() + b.minZ()) / 2.0;
0393           double aHlZNew = (b.minZ() - a.minZ()) / 2.0;
0394           ACTS_VERBOSE("  - Gap width: " << gapWidth);
0395           ACTS_VERBOSE("  - New bounds for first volume: ["
0396                        << (aZMidNew - aHlZNew) << " <- " << aZMidNew << " -> "
0397                        << (aZMidNew + aHlZNew) << "]");
0398 
0399           assert(std::abs(a.minZ() - (aZMidNew - aHlZNew)) < 1e-9 &&
0400                  "Volume shrunk");
0401           assert(aHlZNew >= a.halfLengthZ() && "Volume shrunk");
0402 
0403           a.setLocalTransform(Transform3{Translation3{0, 0, aZMidNew}},
0404                               m_groupTransform);
0405           a.updatedBounds->set(CylinderVolumeBounds::eHalfLengthZ, aHlZNew);
0406 
0407           break;
0408         }
0409         case VolumeAttachmentStrategy::Second: {
0410           ACTS_VERBOSE(" -> Strategy: Expand second volume");
0411           double bZMidNew = (a.maxZ() + b.maxZ()) / 2.0;
0412           double bHlZNew = (b.maxZ() - a.maxZ()) / 2.0;
0413           ACTS_VERBOSE("  - New halflength for second volume: " << bHlZNew);
0414           ACTS_VERBOSE("  - New bounds for second volume: ["
0415                        << (bZMidNew - bHlZNew) << " <- " << bZMidNew << " -> "
0416                        << (bZMidNew + bHlZNew) << "]");
0417 
0418           assert(bHlZNew >= b.halfLengthZ() && "Volume shrunk");
0419           assert(std::abs(b.maxZ() - (bZMidNew + bHlZNew)) < 1e-9 &&
0420                  "Volume shrunk");
0421 
0422           b.setLocalTransform(Transform3{Translation3{0, 0, bZMidNew}},
0423                               m_groupTransform);
0424           b.updatedBounds->set(CylinderVolumeBounds::eHalfLengthZ, bHlZNew);
0425           break;
0426         }
0427         case VolumeAttachmentStrategy::Gap: {
0428           ACTS_VERBOSE(" -> Strategy: Create a gap volume");
0429           double gapHlZ = (b.minZ() - a.maxZ()) / 2.0;
0430           double gapMidZ = (b.minZ() + a.maxZ()) / 2.0;
0431 
0432           ACTS_VERBOSE("  - Gap half length: " << gapHlZ
0433                                                << " at z: " << gapMidZ);
0434 
0435           double minR = std::min(a.minR(), b.minR());
0436           double maxR = std::max(a.maxR(), b.maxR());
0437 
0438           Transform3 gapLocalTransform{Translation3{0, 0, gapMidZ}};
0439           Transform3 gapGlobalTransform = m_groupTransform * gapLocalTransform;
0440           auto gapBounds =
0441               std::make_shared<CylinderVolumeBounds>(minR, maxR, gapHlZ);
0442 
0443           auto gap = addGapVolume(gapGlobalTransform, gapBounds);
0444           gapVolumes.emplace_back(*gap, m_groupTransform);
0445 
0446           break;
0447         }
0448         default:
0449           ACTS_ERROR("Attachment strategy " << strategy << " not implemented");
0450           std::stringstream ss;
0451           ss << strategy;
0452           throw std::invalid_argument("Attachment strategy " + ss.str() +
0453                                       " not implemented");
0454       }
0455     }
0456   }
0457 
0458   return gapVolumes;
0459 }
0460 
0461 std::vector<CylinderVolumeStack::VolumeTuple>
0462 CylinderVolumeStack::checkOverlapAndAttachInR(std::vector<VolumeTuple>& volumes,
0463                                               VolumeAttachmentStrategy strategy,
0464                                               const Logger& logger) {
0465   std::vector<VolumeTuple> gapVolumes;
0466   for (std::size_t i = 0; i < volumes.size() - 1; i++) {
0467     std::size_t j = i + 1;
0468     auto& a = volumes.at(i);
0469     auto& b = volumes.at(j);
0470 
0471     overlapPrint(AxisDirection::AxisR, a, b, logger);
0472 
0473     if (a.maxR() > b.minR()) {
0474       ACTS_ERROR(" -> Overlap in r");
0475       throw std::invalid_argument("Volumes overlap in r");
0476     } else {
0477       ACTS_VERBOSE(" -> No overlap");
0478     }
0479 
0480     constexpr auto tolerance = s_onSurfaceTolerance;
0481     if (std::abs(a.maxR() - b.minR()) < tolerance) {
0482       ACTS_VERBOSE("No gap between volumes, no attachment needed");
0483     } else {
0484       double gapWidth = b.minR() - a.maxR();
0485       ACTS_VERBOSE("Gap width: " << gapWidth);
0486 
0487       ACTS_VERBOSE("Synchronizing bounds in r with strategy: " << strategy);
0488       switch (strategy) {
0489         case VolumeAttachmentStrategy::Midpoint: {
0490           ACTS_VERBOSE(" -> Strategy: Expand both volumes to midpoint");
0491 
0492           a.set({{CylinderVolumeBounds::eMaxR, a.maxR() + gapWidth / 2.0}});
0493           b.set({{CylinderVolumeBounds::eMinR, b.minR() - gapWidth / 2.0}});
0494 
0495           break;
0496         }
0497         case VolumeAttachmentStrategy::First: {
0498           ACTS_VERBOSE(" -> Strategy: Expand first volume");
0499 
0500           a.set({{CylinderVolumeBounds::eMaxR, b.minR()}});
0501 
0502           break;
0503         }
0504         case VolumeAttachmentStrategy::Second: {
0505           ACTS_VERBOSE(" -> Strategy: Expand second volume");
0506 
0507           b.set({{CylinderVolumeBounds::eMinR, a.maxR()}});
0508 
0509           break;
0510         }
0511         case VolumeAttachmentStrategy::Gap: {
0512           ACTS_VERBOSE(" -> Strategy: Create a gap volume");
0513 
0514           auto gapBounds = std::make_shared<CylinderVolumeBounds>(
0515               a.maxR(), b.minR(), a.halfLengthZ());
0516           auto gap = addGapVolume(m_groupTransform, gapBounds);
0517 
0518           gapVolumes.emplace_back(*gap, m_groupTransform);
0519           break;
0520         }
0521         default:
0522           ACTS_ERROR("Attachment strategy " << strategy << " not implemented");
0523           std::stringstream ss;
0524           ss << strategy;
0525           throw std::invalid_argument("Attachment strategy " + ss.str() +
0526                                       " not implemented");
0527       }
0528     }
0529   }
0530 
0531   return gapVolumes;
0532 }
0533 
0534 void CylinderVolumeStack::printVolumeSequence(
0535     const std::vector<VolumeTuple>& volumes, const Logger& logger,
0536     Acts::Logging::Level lvl) {
0537   if (!logger().doPrint(lvl)) {
0538     return;
0539   }
0540   for (const auto& vt : volumes) {
0541     std::stringstream ss;
0542     ss << std::fixed;
0543     ss << std::setprecision(3);
0544     ss << std::setfill(' ');
0545 
0546     int w = 9;
0547     ss << "z: [ " << std::setw(w) << vt.minZ() << " <- " << std::setw(w)
0548        << vt.midZ() << " -> " << std::setw(w) << vt.maxZ() << " ], r: [ "
0549        << std::setw(w) << vt.minR() << " <-> " << std::setw(w) << vt.maxR()
0550        << " ]";
0551 
0552     logger().log(lvl, ss.str());
0553   }
0554 }
0555 
0556 void CylinderVolumeStack::checkVolumeAlignment(
0557     const std::vector<VolumeTuple>& volumes, const Logger& logger) {
0558   std::size_t n = 0;
0559   for (auto& vt : volumes) {
0560     ACTS_VERBOSE("Checking volume #"
0561                  << n << " at z: " << vt.localTransform.translation()[eZ]);
0562     ACTS_VERBOSE("- Local transform is:\n" << vt.localTransform.matrix());
0563 
0564     // @TODO: What's a good tolerance here?
0565     constexpr auto tolerance = s_onSurfaceTolerance;
0566 
0567     // In the group coordinate system:
0568 
0569     // a) the volumes cannot rotate around x or y
0570     if (std::abs(vt.localTransform.rotation().col(eX)[eZ]) >= tolerance ||
0571         std::abs(vt.localTransform.rotation().col(eY)[eZ]) >= tolerance) {
0572       ACTS_ERROR("Volumes are not aligned: rotation is different");
0573       throw std::invalid_argument(
0574           "Volumes are not aligned: rotation is different");
0575     }
0576 
0577     ACTS_VERBOSE(" -> Rotation is ok!");
0578 
0579     // b) the volumes cannot have translation in x or y
0580     Vector2 translation = vt.localTransform.translation().head<2>();
0581     if (std::abs(translation[0]) > tolerance ||  //
0582         std::abs(translation[1]) > tolerance) {
0583       ACTS_ERROR("Volumes are not aligned: translation in x or y");
0584       throw std::invalid_argument(
0585           "Volumes are not aligned: translation in x or y");
0586     }
0587     ACTS_VERBOSE(" -> Translation in x/y is ok!");
0588 
0589     n++;
0590   }
0591 }
0592 
0593 std::pair<double, double> CylinderVolumeStack::synchronizeRBounds(
0594     std::vector<VolumeTuple>& volumes, const Logger& logger) {
0595   const double minR =
0596       std::min_element(volumes.begin(), volumes.end(),
0597                        [](const auto& a, const auto& b) {
0598                          return a.bounds->get(CylinderVolumeBounds::eMinR) <
0599                                 b.bounds->get(CylinderVolumeBounds::eMinR);
0600                        })
0601           ->bounds->get(CylinderVolumeBounds::eMinR);
0602 
0603   const double maxR =
0604       std::max_element(volumes.begin(), volumes.end(),
0605                        [](const auto& a, const auto& b) {
0606                          return a.bounds->get(CylinderVolumeBounds::eMaxR) <
0607                                 b.bounds->get(CylinderVolumeBounds::eMaxR);
0608                        })
0609           ->bounds->get(CylinderVolumeBounds::eMaxR);
0610   ACTS_VERBOSE("Found: minR: " << minR << " maxR: " << maxR);
0611 
0612   for (auto& vt : volumes) {
0613     vt.set({
0614         {CylinderVolumeBounds::eMinR, minR},
0615         {CylinderVolumeBounds::eMaxR, maxR},
0616     });
0617   }
0618 
0619   return {minR, maxR};
0620 }
0621 
0622 std::pair<double, double> CylinderVolumeStack::synchronizeZBounds(
0623     std::vector<VolumeTuple>& volumes, const Logger& logger) {
0624   const double minZ = std::min_element(volumes.begin(), volumes.end(),
0625                                        [](const auto& a, const auto& b) {
0626                                          return a.minZ() < b.minZ();
0627                                        })
0628                           ->minZ();
0629 
0630   const double maxZ = std::max_element(volumes.begin(), volumes.end(),
0631                                        [](const auto& a, const auto& b) {
0632                                          return a.maxZ() < b.maxZ();
0633                                        })
0634                           ->maxZ();
0635   const double midZ = (minZ + maxZ) / 2.0;
0636   const double hlZ = (maxZ - minZ) / 2.0;
0637   ACTS_DEBUG("Found overall z bounds: [ " << minZ << " <- " << midZ << " -> "
0638                                           << maxZ << " ]");
0639   const Transform3 transform{Translation3{0, 0, midZ}};
0640 
0641   for (auto& vt : volumes) {
0642     vt.set({{CylinderVolumeBounds::eHalfLengthZ, hlZ}});
0643     vt.setLocalTransform(transform, m_groupTransform);
0644   }
0645 
0646   return {minZ, maxZ};
0647 }
0648 
0649 void CylinderVolumeStack::update(std::shared_ptr<VolumeBounds> volbounds,
0650                                  std::optional<Transform3> transform,
0651                                  const Logger& logger) {
0652   ACTS_DEBUG(
0653       "Resizing CylinderVolumeStack with strategy: " << m_resizeStrategies);
0654   ACTS_DEBUG("Currently have " << m_volumes.size() << " children");
0655   ACTS_DEBUG(m_gaps.size() << " gaps");
0656   for (const auto& v : m_volumes) {
0657     ACTS_DEBUG(" - volume bounds: \n" << v->volumeBounds());
0658     ACTS_DEBUG("          transform: \n" << v->transform().matrix());
0659   }
0660 
0661   ACTS_DEBUG("New bounds are: \n" << *volbounds);
0662 
0663   auto cylBounds = std::dynamic_pointer_cast<CylinderVolumeBounds>(volbounds);
0664   if (cylBounds == nullptr) {
0665     throw std::invalid_argument(
0666         "CylinderVolumeStack requires CylinderVolumeBounds");
0667   }
0668 
0669   if (cylBounds == nullptr) {
0670     throw std::invalid_argument("New bounds are nullptr");
0671   }
0672 
0673   if (*cylBounds == volumeBounds()) {
0674     ACTS_VERBOSE("Bounds are the same, no resize needed");
0675     return;
0676   }
0677 
0678   ACTS_VERBOSE("Group transform is:\n" << m_groupTransform.matrix());
0679   ACTS_VERBOSE("Current transform is:\n" << m_transform.matrix());
0680   if (transform.has_value()) {
0681     ACTS_VERBOSE("Input transform:\n" << transform.value().matrix());
0682   }
0683 
0684   VolumeTuple oldVolume{*this, m_transform};
0685   VolumeTuple newVolume{*this, m_transform};
0686   newVolume.updatedBounds = std::make_shared<CylinderVolumeBounds>(*cylBounds);
0687   newVolume.globalTransform = transform.value_or(m_transform);
0688   newVolume.localTransform = m_transform.inverse() * newVolume.globalTransform;
0689 
0690   if (!transform.has_value()) {
0691     ACTS_VERBOSE("Local transform does not change");
0692   } else {
0693     ACTS_VERBOSE("Local transform changes from\n"
0694                  << m_groupTransform.matrix() << "\nto\n"
0695                  << newVolume.localTransform.matrix());
0696     ACTS_VERBOSE("Checking transform consistency");
0697 
0698     std::vector<VolumeTuple> volTemp{newVolume};
0699     checkVolumeAlignment(volTemp, logger);
0700   }
0701 
0702   checkNoPhiOrBevel(*cylBounds, logger);
0703 
0704   const double newMinR = newVolume.minR();
0705   const double newMaxR = newVolume.maxR();
0706   const double newMinZ = newVolume.minZ();
0707   const double newMaxZ = newVolume.maxZ();
0708   const double newMidZ = newVolume.midZ();
0709   const double newHlZ = newVolume.halfLengthZ();
0710 
0711   const double oldMinR = oldVolume.minR();
0712   const double oldMaxR = oldVolume.maxR();
0713   const double oldMinZ = oldVolume.minZ();
0714   const double oldMaxZ = oldVolume.maxZ();
0715   const double oldMidZ = oldVolume.midZ();
0716   const double oldHlZ = oldVolume.halfLengthZ();
0717 
0718   ACTS_VERBOSE("Previous bounds are: z: [ "
0719                << oldMinZ << " <- " << oldMidZ << " -> " << oldMaxZ << " ] ("
0720                << oldHlZ << "), r: [ " << oldMinR << " <-> " << oldMaxR
0721                << " ]");
0722   ACTS_VERBOSE("New bounds are: z:      [ "
0723                << newMinZ << " <- " << newMidZ << " -> " << newMaxZ << " ] ("
0724                << newHlZ << "), r: [ " << newMinR << " <-> " << newMaxR
0725                << " ]");
0726 
0727   constexpr auto tolerance = s_onSurfaceTolerance;
0728   auto same = [](double a, double b) { return std::abs(a - b) < tolerance; };
0729 
0730   if (!same(newMinZ, oldMinZ) && newMinZ > oldMinZ) {
0731     ACTS_ERROR("Shrinking the stack size in z is not supported: "
0732                << newMinZ << " -> " << oldMinZ);
0733     throw std::invalid_argument("Shrinking the stack in z is not supported");
0734   }
0735 
0736   if (!same(newMaxZ, oldMaxZ) && newMaxZ < oldMaxZ) {
0737     ACTS_ERROR("Shrinking the stack size in z is not supported: "
0738                << newMaxZ << " -> " << oldMaxZ);
0739     throw std::invalid_argument("Shrinking the stack in z is not supported");
0740   }
0741 
0742   if (!same(newMinR, oldMinR) && newMinR > oldMinR) {
0743     ACTS_ERROR("Shrinking the stack size in r is not supported: "
0744                << newMinR << " -> " << oldMinR);
0745     throw std::invalid_argument("Shrinking the stack in r is not supported");
0746   }
0747 
0748   if (!same(newMaxR, oldMaxR) && newMaxR < oldMaxR) {
0749     ACTS_ERROR("Shrinking the stack size in r is not supported: "
0750                << newMaxR << " -> " << oldMaxR);
0751     throw std::invalid_argument("Shrinking the stack is r in not supported");
0752   }
0753 
0754   auto isGap = [this](const Volume* vol) {
0755     return std::ranges::any_of(
0756         m_gaps, [&](const auto& gap) { return vol == gap.get(); });
0757   };
0758 
0759   const auto& [firstStrategy, secondStrategy] = m_resizeStrategies;
0760 
0761   if (m_direction == AxisDirection::AxisZ) {
0762     ACTS_VERBOSE("Stack direction is z");
0763 
0764     std::vector<VolumeTuple> volumeTuples;
0765     volumeTuples.reserve(m_volumes.size());
0766     std::transform(m_volumes.begin(), m_volumes.end(),
0767                    std::back_inserter(volumeTuples),
0768                    [this](const auto& volume) {
0769                      return VolumeTuple{*volume, m_groupTransform};
0770                    });
0771 
0772     ACTS_VERBOSE("*** Initial volume configuration:");
0773     printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0774 
0775     if (!same(newMinR, oldMinR) || !same(newMaxR, oldMaxR)) {
0776       ACTS_VERBOSE("Resize all volumes to new r bounds");
0777       for (auto& volume : volumeTuples) {
0778         volume.set({
0779             {CylinderVolumeBounds::eMinR, newMinR},
0780             {CylinderVolumeBounds::eMaxR, newMaxR},
0781         });
0782       }
0783       ACTS_VERBOSE("*** Volume configuration after r resizing:");
0784       printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0785     } else {
0786       ACTS_VERBOSE("R bounds are the same, no r resize needed");
0787     }
0788 
0789     auto printGapDimensions = [&](const VolumeTuple& gap,
0790                                   const std::string& prefix = "") {
0791       ACTS_VERBOSE(" -> gap" << prefix << ": [ " << gap.minZ() << " <- "
0792                              << gap.midZ() << " -> " << gap.maxZ()
0793                              << " ], r: [ " << gap.minR() << " <-> "
0794                              << gap.maxR() << " ]");
0795     };
0796 
0797     if (same(newHlZ, oldHlZ)) {
0798       ACTS_VERBOSE("Halflength z is the same, no z resize needed");
0799     } else {
0800       if (newMinZ < oldMinZ) {
0801         if (firstStrategy == VolumeResizeStrategy::Expand) {
0802           ACTS_VERBOSE("Expanding first volume to new z bounds");
0803 
0804           auto& first = volumeTuples.front();
0805           double newMinZFirst = newVolume.minZ();
0806           double newMidZFirst = (newMinZFirst + first.maxZ()) / 2.0;
0807           double newHlZFirst = (first.maxZ() - newMinZFirst) / 2.0;
0808 
0809           ACTS_VERBOSE(" -> first z: [ "
0810                        << newMinZFirst << " <- " << newMidZFirst << " -> "
0811                        << first.maxZ() << " ] (hl: " << newHlZFirst << ")");
0812 
0813           first.set({{CylinderVolumeBounds::eHalfLengthZ, newHlZFirst}});
0814           first.setLocalTransform(Transform3{Translation3{0, 0, newMidZFirst}},
0815                                   m_groupTransform);
0816         } else if (firstStrategy == VolumeResizeStrategy::Gap) {
0817           ACTS_VERBOSE("Creating gap volumes to fill the new z bounds at minZ");
0818 
0819           double gap1MinZ = newVolume.minZ();
0820           double gap1MaxZ = oldVolume.minZ();
0821           double gap1HlZ = (gap1MaxZ - gap1MinZ) / 2.0;
0822           double gap1PZ = (gap1MaxZ + gap1MinZ) / 2.0;
0823 
0824           // // check if we need a new gap volume or reuse an existing one
0825           auto& candidate = volumeTuples.front();
0826           if (isGap(candidate.volume)) {
0827             ACTS_VERBOSE("~> Reusing existing gap volume at negative z");
0828 
0829             gap1HlZ =
0830                 candidate.bounds->get(CylinderVolumeBounds::eHalfLengthZ) +
0831                 gap1HlZ;
0832             gap1MaxZ = gap1MinZ + gap1HlZ * 2;
0833             gap1PZ = (gap1MaxZ + gap1MinZ) / 2.0;
0834 
0835             printGapDimensions(candidate, " before");
0836             auto gap1Bounds = std::make_shared<CylinderVolumeBounds>(
0837                 newMinR, newMaxR, gap1HlZ);
0838             auto gap1Transform = m_groupTransform * Translation3{0, 0, gap1PZ};
0839             candidate.volume->update(std::move(gap1Bounds), gap1Transform);
0840             candidate = VolumeTuple{*candidate.volume, m_groupTransform};
0841             ACTS_VERBOSE("After:");
0842             printGapDimensions(candidate, " after ");
0843 
0844           } else {
0845             ACTS_VERBOSE("~> Creating new gap volume at negative z");
0846             auto gap1Bounds = std::make_shared<CylinderVolumeBounds>(
0847                 newMinR, newMaxR, gap1HlZ);
0848             auto gap1Transform = m_groupTransform * Translation3{0, 0, gap1PZ};
0849             auto gap1 = addGapVolume(gap1Transform, std::move(gap1Bounds));
0850             volumeTuples.insert(volumeTuples.begin(),
0851                                 VolumeTuple{*gap1, m_groupTransform});
0852             printGapDimensions(volumeTuples.front());
0853           }
0854         }
0855       }
0856 
0857       if (newMaxZ > oldMaxZ) {
0858         if (secondStrategy == VolumeResizeStrategy::Expand) {
0859           ACTS_VERBOSE("Expanding last volume to new z bounds");
0860 
0861           auto& last = volumeTuples.back();
0862           double newMaxZLast = newVolume.maxZ();
0863           double newMidZLast = (last.minZ() + newMaxZLast) / 2.0;
0864           double newHlZLast = (newMaxZLast - last.minZ()) / 2.0;
0865 
0866           ACTS_VERBOSE(" -> last z: [ " << last.minZ() << " <- " << newMidZLast
0867                                         << " -> " << newMaxZLast
0868                                         << " ] (hl: " << newHlZLast << ")");
0869 
0870           last.set({{CylinderVolumeBounds::eHalfLengthZ, newHlZLast}});
0871           last.setLocalTransform(Transform3{Translation3{0, 0, newMidZLast}},
0872                                  m_groupTransform);
0873         } else if (secondStrategy == VolumeResizeStrategy::Gap) {
0874           ACTS_VERBOSE("Creating gap volumes to fill the new z bounds at maxZ");
0875 
0876           double gap2MinZ = oldVolume.maxZ();
0877           double gap2MaxZ = newVolume.maxZ();
0878           double gap2HlZ = (gap2MaxZ - gap2MinZ) / 2.0;
0879           double gap2PZ = (gap2MaxZ + gap2MinZ) / 2.0;
0880 
0881           // check if we need a new gap volume or reuse an existing one
0882           auto& candidate = volumeTuples.back();
0883           if (isGap(candidate.volume)) {
0884             ACTS_VERBOSE("~> Reusing existing gap volume at positive z");
0885 
0886             gap2HlZ =
0887                 candidate.bounds->get(CylinderVolumeBounds::eHalfLengthZ) +
0888                 gap2HlZ;
0889             gap2MinZ = newVolume.maxZ() - gap2HlZ * 2;
0890             gap2PZ = (gap2MaxZ + gap2MinZ) / 2.0;
0891 
0892             printGapDimensions(candidate, " before");
0893             auto gap2Bounds = std::make_shared<CylinderVolumeBounds>(
0894                 newMinR, newMaxR, gap2HlZ);
0895             auto gap2Transform = m_groupTransform * Translation3{0, 0, gap2PZ};
0896 
0897             candidate.volume->update(std::move(gap2Bounds), gap2Transform);
0898             candidate = VolumeTuple{*candidate.volume, m_groupTransform};
0899             printGapDimensions(candidate, " after ");
0900           } else {
0901             ACTS_VERBOSE("~> Creating new gap volume at positive z");
0902             auto gap2Bounds = std::make_shared<CylinderVolumeBounds>(
0903                 newMinR, newMaxR, gap2HlZ);
0904             auto gap2Transform = m_groupTransform * Translation3{0, 0, gap2PZ};
0905             auto gap2 = addGapVolume(gap2Transform, std::move(gap2Bounds));
0906             volumeTuples.emplace_back(*gap2, m_groupTransform);
0907             printGapDimensions(volumeTuples.back());
0908           }
0909         }
0910       }
0911 
0912       ACTS_VERBOSE("*** Volume configuration after z resizing:");
0913       printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0914     }
0915 
0916     ACTS_VERBOSE("Commit and update outer vector of volumes");
0917     m_volumes.clear();
0918     for (auto& vt : volumeTuples) {
0919       vt.commit(logger);
0920       m_volumes.push_back(vt.volume);
0921     }
0922 
0923   } else if (m_direction == AxisDirection::AxisR) {
0924     ACTS_VERBOSE("Stack direction is r");
0925 
0926     std::vector<VolumeTuple> volumeTuples;
0927     volumeTuples.reserve(m_volumes.size());
0928     std::transform(m_volumes.begin(), m_volumes.end(),
0929                    std::back_inserter(volumeTuples),
0930                    [this](const auto& volume) {
0931                      return VolumeTuple{*volume, m_groupTransform};
0932                    });
0933 
0934     ACTS_VERBOSE("*** Initial volume configuration:");
0935     printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0936 
0937     ACTS_VERBOSE("Resize all volumes to new z bounds and update transforms");
0938     for (auto& volume : volumeTuples) {
0939       volume.set({
0940           {CylinderVolumeBounds::eHalfLengthZ, newHlZ},
0941       });
0942       volume.setLocalTransform(newVolume.localTransform, m_groupTransform);
0943     }
0944 
0945     ACTS_VERBOSE("*** Volume configuration after z resizing:");
0946     printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
0947 
0948     if (oldMinR == newMinR && oldMaxR == newMaxR) {
0949       ACTS_VERBOSE("Radii are the same, no r resize needed");
0950     } else {
0951       auto printGapDimensions = [&](const VolumeTuple& gap,
0952                                     const std::string& prefix = "") {
0953         ACTS_VERBOSE(" -> gap" << prefix << ": [ " << gap.minZ() << " <- "
0954                                << gap.midZ() << " -> " << gap.maxZ()
0955                                << " ], r: [ " << gap.minR() << " <-> "
0956                                << gap.maxR() << " ]");
0957       };
0958 
0959       if (oldMinR > newMinR) {
0960         if (firstStrategy == VolumeResizeStrategy::Expand) {
0961           // expand innermost volume
0962           auto& first = volumeTuples.front();
0963           first.set({
0964               {CylinderVolumeBounds::eMinR, newMinR},
0965           });
0966           ACTS_VERBOSE(" -> z: [ " << first.minZ() << " <- " << first.midZ()
0967                                    << " -> " << first.maxZ() << " ], r: [ "
0968                                    << first.minR() << " <-> " << first.maxR()
0969                                    << " ]");
0970         } else if (firstStrategy == VolumeResizeStrategy::Gap) {
0971           auto& candidate = volumeTuples.front();
0972           if (isGap(candidate.volume)) {
0973             ACTS_VERBOSE("~> Reusing existing gap volume at inner r");
0974             auto& candidateCylBounds = dynamic_cast<CylinderVolumeBounds&>(
0975                 candidate.volume->volumeBounds());
0976             printGapDimensions(candidate, " before");
0977             candidateCylBounds.set(CylinderVolumeBounds::eMinR, newMinR);
0978             candidate = VolumeTuple{*candidate.volume, m_groupTransform};
0979             printGapDimensions(candidate, " after ");
0980           } else {
0981             ACTS_VERBOSE("~> Creating new gap volume at inner r");
0982             auto gapBounds = std::make_shared<CylinderVolumeBounds>(
0983                 newMinR, oldMinR, newHlZ);
0984             auto gapTransform = m_groupTransform;
0985             auto gapVolume = addGapVolume(gapTransform, gapBounds);
0986             volumeTuples.insert(volumeTuples.begin(),
0987                                 VolumeTuple{*gapVolume, m_groupTransform});
0988             auto gap = volumeTuples.front();
0989             printGapDimensions(gap);
0990           }
0991         }
0992       }
0993 
0994       if (oldMaxR < newMaxR) {
0995         if (secondStrategy == VolumeResizeStrategy::Expand) {
0996           // expand outermost volume
0997           auto& last = volumeTuples.back();
0998           last.set({
0999               {CylinderVolumeBounds::eMaxR, newMaxR},
1000           });
1001           ACTS_VERBOSE(" -> z: [ " << last.minZ() << " <- " << last.midZ()
1002                                    << " -> " << last.maxZ() << " ], r: [ "
1003                                    << last.minR() << " <-> " << last.maxR()
1004                                    << " ]");
1005         } else if (secondStrategy == VolumeResizeStrategy::Gap) {
1006           auto& candidate = volumeTuples.back();
1007           if (isGap(candidate.volume)) {
1008             ACTS_VERBOSE("~> Reusing existing gap volume at outer r");
1009             auto& candidateCylBounds = dynamic_cast<CylinderVolumeBounds&>(
1010                 candidate.volume->volumeBounds());
1011             printGapDimensions(candidate, " before");
1012             candidateCylBounds.set(CylinderVolumeBounds::eMaxR, newMaxR);
1013             candidate = VolumeTuple{*candidate.volume, m_groupTransform};
1014             printGapDimensions(candidate, " after ");
1015           } else {
1016             ACTS_VERBOSE("~> Creating new gap volume at outer r");
1017             auto gapBounds = std::make_shared<CylinderVolumeBounds>(
1018                 oldMaxR, newMaxR, newHlZ);
1019             auto gapTransform = m_groupTransform;
1020             auto gapVolume = addGapVolume(gapTransform, gapBounds);
1021             volumeTuples.emplace_back(*gapVolume, m_groupTransform);
1022             auto gap = volumeTuples.back();
1023             printGapDimensions(gap);
1024           }
1025         }
1026       }
1027 
1028       ACTS_VERBOSE("*** Volume configuration after r resizing:");
1029       printVolumeSequence(volumeTuples, logger, Acts::Logging::DEBUG);
1030     }
1031 
1032     ACTS_VERBOSE("Commit and update outer vector of volumes");
1033     m_volumes.clear();
1034     for (auto& vt : volumeTuples) {
1035       vt.commit(logger);
1036       m_volumes.push_back(vt.volume);
1037     }
1038   }
1039 
1040   m_transform = newVolume.globalTransform;
1041   // @TODO: We probably can reuse m_transform
1042   m_groupTransform = m_transform;
1043   Volume::update(std::move(cylBounds), std::nullopt, logger);
1044 }
1045 
1046 void CylinderVolumeStack::checkNoPhiOrBevel(const CylinderVolumeBounds& bounds,
1047                                             const Logger& logger) {
1048   if (bounds.get(CylinderVolumeBounds::eHalfPhiSector) != std::numbers::pi) {
1049     ACTS_ERROR(
1050         "CylinderVolumeStack requires all volumes to have a full "
1051         "phi sector");
1052     throw std::invalid_argument(
1053         "CylinderVolumeStack requires all volumes to have a full phi sector");
1054   }
1055 
1056   if (bounds.get(CylinderVolumeBounds::eAveragePhi) != 0.0) {
1057     ACTS_ERROR(
1058         "CylinderVolumeStack requires all volumes to have an average "
1059         "phi of 0");
1060     throw std::invalid_argument(
1061         "CylinderVolumeStack requires all volumes to have an average phi of "
1062         "0");
1063   }
1064 
1065   if (bounds.get(CylinderVolumeBounds::eBevelMinZ) != 0.0) {
1066     ACTS_ERROR(
1067         "CylinderVolumeStack requires all volumes to have a bevel angle of "
1068         "0");
1069     throw std::invalid_argument(
1070         "CylinderVolumeStack requires all volumes to have a bevel angle of "
1071         "0");
1072   }
1073 
1074   if (bounds.get(CylinderVolumeBounds::eBevelMaxZ) != 0.0) {
1075     ACTS_ERROR(
1076         "CylinderVolumeStack requires all volumes to have a bevel angle of "
1077         "0");
1078     throw std::invalid_argument(
1079         "CylinderVolumeStack requires all volumes to have a bevel angle of "
1080         "0");
1081   }
1082 }
1083 
1084 }  // namespace Acts