Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:07:50

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/TrapezoidPortalShell.hpp"
0010 
0011 #include "Acts/Geometry/Portal.hpp"
0012 #include "Acts/Geometry/PortalLinkBase.hpp"
0013 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0014 
0015 namespace Acts {
0016 
0017 void TrapezoidPortalShell::fill(TrackingVolume& volume) {
0018   for (Face face : {NegativeZFaceXY, PositiveZFaceXY, TrapezoidFaceAlpha,
0019                     TrapezoidFaceBeta, NegativeYFaceZX, PositiveYFaceZX}) {
0020     const auto& portalAtFace = portal(face);
0021     if (portalAtFace != nullptr) {
0022       portalAtFace->fill(volume);
0023       volume.addPortal(portalAtFace);
0024     }
0025   }
0026 }
0027 
0028 SingleTrapezoidPortalShell::SingleTrapezoidPortalShell(TrackingVolume& volume)
0029     : m_volume{&volume} {
0030   if (m_volume->volumeBounds().type() != VolumeBounds::BoundsType::eTrapezoid) {
0031     throw std::invalid_argument("Invalid volume bounds - not trapezoid");
0032   }
0033 
0034   const auto& bounds =
0035       dynamic_cast<const TrapezoidVolumeBounds&>(m_volume->volumeBounds());
0036 
0037   ACTS_PUSH_IGNORE_DEPRECATED()
0038   std::vector<OrientedSurface> orientedSurfaces =
0039       bounds.orientedSurfaces(m_volume->transform());
0040   ACTS_POP_IGNORE_DEPRECATED()
0041 
0042   for (Face face : {NegativeZFaceXY, PositiveZFaceXY, TrapezoidFaceAlpha,
0043                     TrapezoidFaceBeta, NegativeYFaceZX, PositiveYFaceZX}) {
0044     const auto& portalSurface = orientedSurfaces.at(toUnderlying(face));
0045 
0046     m_portals.at(toUnderlying(face)) = std::make_shared<Portal>(
0047         portalSurface.direction, portalSurface.surface, *m_volume);
0048   }
0049 }
0050 
0051 std::shared_ptr<Portal> SingleTrapezoidPortalShell::portal(Face face) {
0052   return m_portals.at(toUnderlying(face));
0053 }
0054 
0055 void SingleTrapezoidPortalShell::setPortal(std::shared_ptr<Portal> portal,
0056                                            Face face) {
0057   assert(portal != nullptr);
0058   assert(portal->isValid());
0059   m_portals.at(toUnderlying(face)) = std::move(portal);
0060 }
0061 
0062 std::size_t SingleTrapezoidPortalShell::size() const {
0063   std::size_t count = 0;
0064   std::ranges::for_each(
0065       m_portals, [&count](const auto& portal) { count += portal ? 1 : 0; });
0066   return count;
0067 }
0068 
0069 void SingleTrapezoidPortalShell::applyToVolume() {
0070   for (std::size_t i = 0; i < m_portals.size(); i++) {
0071     const auto& portal = m_portals.at(i);
0072     if (portal != nullptr) {
0073       if (!portal->isValid()) {
0074         std::stringstream ss;
0075         ss << static_cast<Face>(i);
0076         throw std::runtime_error{"Invalid portal found in shell at " +
0077                                  ss.str()};
0078       }
0079       m_volume->addPortal(portal);
0080     }
0081   }
0082 }
0083 
0084 bool SingleTrapezoidPortalShell::isValid() const {
0085   return std::ranges::all_of(m_portals, [](const auto& portal) {
0086     return portal == nullptr || portal->isValid();
0087   });
0088 }
0089 
0090 std::string SingleTrapezoidPortalShell::label() const {
0091   std::stringstream ss;
0092   ss << "TrapezoidShell(vol=" << m_volume->volumeName() << ")";
0093   return ss.str();
0094 }
0095 
0096 std::ostream& operator<<(std::ostream& os, TrapezoidPortalShell::Face face) {
0097   switch (face) {
0098     case TrapezoidPortalShell::NegativeZFaceXY:
0099       return os << "NegativeZFaceXY";
0100     case TrapezoidPortalShell::PositiveZFaceXY:
0101       return os << "PositiveZFaceXY";
0102     case TrapezoidPortalShell::TrapezoidFaceAlpha:
0103       return os << "TrapezoidFaceAlpha";
0104     case TrapezoidPortalShell::TrapezoidFaceBeta:
0105       return os << "TrapezoidFaceBeta";
0106     case TrapezoidPortalShell::NegativeYFaceZX:
0107       return os << "NegativeYFaceZX";
0108     case TrapezoidPortalShell::PositiveYFaceZX:
0109       return os << "PositiveYFaceZX";
0110     default:
0111       return os << "Invalid face";
0112   }
0113 }
0114 
0115 }  // namespace Acts