File indexing completed on 2026-07-16 08:07:48
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Geometry/DiamondPortalShell.hpp"
0010
0011 #include "Acts/Geometry/DiamondVolumeBounds.hpp"
0012 #include "Acts/Geometry/Portal.hpp"
0013 #include "Acts/Geometry/PortalLinkBase.hpp"
0014
0015 #include <algorithm>
0016 #include <array>
0017 #include <cstddef>
0018 #include <numeric>
0019 #include <stdexcept>
0020 #include <unordered_map>
0021
0022 #include <boost/algorithm/string/join.hpp>
0023
0024 namespace Acts {
0025
0026 void DiamondPortalShell::fill(TrackingVolume& volume) {
0027 for (const auto face : {Face::NegativeZFaceXY, Face::PositiveZFaceXY,
0028 Face::NegativeXFaceYZ12, Face::PositiveXFaceYZ12,
0029 Face::NegativeXFaceYZ23, Face::PositiveXFaceYZ23,
0030 Face::NegativeYFaceZX, Face::PositiveYFaceZX}) {
0031 const auto& portalAtFace = portalPtr(face);
0032 if (portalAtFace != nullptr) {
0033 portalAtFace->fill(volume);
0034 volume.addPortal(portalAtFace);
0035 }
0036 }
0037 }
0038
0039 SingleDiamondPortalShell::SingleDiamondPortalShell(TrackingVolume& volume)
0040 : m_volume{&volume} {
0041 if (m_volume->volumeBounds().type() != VolumeBounds::BoundsType::eDiamond) {
0042 throw std::invalid_argument(
0043 "SingleDiamondPortalShell: Associated volume does not "
0044 "have DiamondVolumeBounds");
0045 }
0046
0047 const auto& bounds =
0048 dynamic_cast<const DiamondVolumeBounds&>(m_volume->volumeBounds());
0049
0050
0051 std::vector<OrientedSurface> orientedSurfaces{};
0052
0053 ACTS_PUSH_IGNORE_DEPRECATED()
0054 orientedSurfaces = bounds.orientedSurfaces(m_volume->transform());
0055 ACTS_POP_IGNORE_DEPRECATED()
0056 for (Face face : {Face::NegativeZFaceXY, Face::PositiveZFaceXY,
0057 Face::NegativeXFaceYZ12, Face::PositiveXFaceYZ12,
0058 Face::NegativeXFaceYZ23, Face::PositiveXFaceYZ23,
0059 Face::NegativeYFaceZX, Face::PositiveYFaceZX}) {
0060 const auto& orientedSurface = orientedSurfaces.at(toUnderlying(face));
0061 m_portals.at(toUnderlying(face)) = std::make_shared<Portal>(
0062 orientedSurface.direction, orientedSurface.surface, *m_volume);
0063 }
0064 }
0065
0066 std::shared_ptr<Portal> SingleDiamondPortalShell::portalPtr(Face face) {
0067 return m_portals.at(toUnderlying(face));
0068 }
0069
0070 void SingleDiamondPortalShell::setPortal(std::shared_ptr<Portal> portal,
0071 Face face) {
0072 assert(portal != nullptr);
0073 assert(portal->isValid());
0074 m_portals.at(toUnderlying(face)) = std::move(portal);
0075 }
0076
0077 std::size_t SingleDiamondPortalShell::size() const {
0078 return std::ranges::count_if(
0079 m_portals, [](const auto& portal) { return portal != nullptr; });
0080 }
0081
0082 void SingleDiamondPortalShell::applyToVolume() {
0083 for (std::size_t p = 0; p < m_portals.size(); ++p) {
0084 const auto& portal = m_portals.at(p);
0085 if (portal != nullptr) {
0086 if (!portal->isValid()) {
0087 std::stringstream ss;
0088 ss << static_cast<Face>(p);
0089 throw std::runtime_error{"Invalid portal found in shell at" + ss.str()};
0090 }
0091 m_volume->addPortal(portal);
0092 }
0093 }
0094 }
0095
0096 bool SingleDiamondPortalShell::isValid() const {
0097 return std::ranges::all_of(m_portals, [](const auto& portal) {
0098 return portal == nullptr || portal->isValid();
0099 });
0100 }
0101
0102 std::string SingleDiamondPortalShell::label() const {
0103 std::stringstream ss;
0104 ss << "Single Diamond Portal Shell for vol = " + m_volume->volumeName()
0105 << " ";
0106 return ss.str();
0107 }
0108
0109 }