Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:50:13

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 = portalPtr(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   std::vector<OrientedSurface> orientedSurfaces =
0038       bounds.orientedSurfaces(m_volume->transform());
0039 
0040   for (Face face : {NegativeZFaceXY, PositiveZFaceXY, TrapezoidFaceAlpha,
0041                     TrapezoidFaceBeta, NegativeYFaceZX, PositiveYFaceZX}) {
0042     const auto& portalSurface = orientedSurfaces.at(toUnderlying(face));
0043 
0044     m_portals.at(toUnderlying(face)) = std::make_shared<Portal>(
0045         portalSurface.direction, portalSurface.surface, *m_volume);
0046   }
0047 }
0048 
0049 Portal* SingleTrapezoidPortalShell::portal(Face face) {
0050   return portalPtr(face).get();
0051 }
0052 
0053 std::shared_ptr<Portal> SingleTrapezoidPortalShell::portalPtr(Face face) {
0054   return m_portals.at(toUnderlying(face));
0055 }
0056 
0057 void SingleTrapezoidPortalShell::setPortal(std::shared_ptr<Portal> portal,
0058                                            Face face) {
0059   assert(portal != nullptr);
0060   assert(portal->isValid());
0061   m_portals.at(toUnderlying(face)) = std::move(portal);
0062 }
0063 
0064 std::size_t SingleTrapezoidPortalShell::size() const {
0065   std::size_t count = 0;
0066   std::ranges::for_each(
0067       m_portals, [&count](const auto& portal) { count += portal ? 1 : 0; });
0068   return count;
0069 }
0070 
0071 void SingleTrapezoidPortalShell::applyToVolume() {
0072   for (std::size_t i = 0; i < m_portals.size(); i++) {
0073     const auto& portal = m_portals.at(i);
0074     if (portal != nullptr) {
0075       if (!portal->isValid()) {
0076         std::stringstream ss;
0077         ss << static_cast<Face>(i);
0078         throw std::runtime_error{"Invalid portal found in shell at " +
0079                                  ss.str()};
0080       }
0081       m_volume->addPortal(portal);
0082     }
0083   }
0084 }
0085 
0086 bool SingleTrapezoidPortalShell::isValid() const {
0087   return std::ranges::all_of(m_portals, [](const auto& portal) {
0088     return portal == nullptr || portal->isValid();
0089   });
0090 }
0091 
0092 std::string SingleTrapezoidPortalShell::label() const {
0093   std::stringstream ss;
0094   ss << "TrapezoidShell(vol=" << m_volume->volumeName() << ")";
0095   return ss.str();
0096 }
0097 
0098 std::ostream& operator<<(std::ostream& os, TrapezoidPortalShell::Face face) {
0099   switch (face) {
0100     case TrapezoidPortalShell::NegativeZFaceXY:
0101       return os << "NegativeZFaceXY";
0102     case TrapezoidPortalShell::PositiveZFaceXY:
0103       return os << "PositiveZFaceXY";
0104     case TrapezoidPortalShell::TrapezoidFaceAlpha:
0105       return os << "TrapezoidFaceAlpha";
0106     case TrapezoidPortalShell::TrapezoidFaceBeta:
0107       return os << "TrapezoidFaceBeta";
0108     case TrapezoidPortalShell::NegativeYFaceZX:
0109       return os << "NegativeYFaceZX";
0110     case TrapezoidPortalShell::PositiveYFaceZX:
0111       return os << "PositiveYFaceZX";
0112     default:
0113       return os << "Invalid face";
0114   }
0115 }
0116 
0117 }  // namespace Acts