Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:11

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Direction.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Geometry/GeometryIdentifier.hpp"
0015 #include "Acts/Navigation/NavigationDelegates.hpp"
0016 #include "Acts/Navigation/NavigationState.hpp"
0017 #include "Acts/Surfaces/BoundaryCheck.hpp"
0018 #include "Acts/Surfaces/RegularSurface.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
0021 #include "Acts/Utilities/Concepts.hpp"
0022 
0023 #include <array>
0024 #include <map>
0025 #include <memory>
0026 #include <optional>
0027 #include <vector>
0028 
0029 namespace Acts {
0030 
0031 class ISurfaceMaterial;
0032 class Surface;
0033 
0034 namespace Experimental {
0035 class DetectorVolume;
0036 struct NavigationState;
0037 
0038 /// A portal description between the detector volumes
0039 ///
0040 /// It has a Surface representation for navigation and propagation
0041 /// and guides from one volume to the next.
0042 ///
0043 /// The surface can carry material to allow mapping onto
0044 /// portal positions if required.
0045 ///
0046 class Portal {
0047  public:
0048   /// Constructor from surface w/o portal links
0049   ///
0050   /// @param surface is the representing surface
0051   Portal(std::shared_ptr<RegularSurface> surface);
0052 
0053   /// The volume links forward/backward with respect to the surface normal
0054   using DetectorVolumeUpdaters = std::array<DetectorVolumeUpdater, 2u>;
0055 
0056   /// The vector of attached volumes forward/backward, this is useful in the
0057   /// geometry building
0058   using AttachedDetectorVolumes =
0059       std::array<std::vector<std::shared_ptr<DetectorVolume>>, 2u>;
0060 
0061   /// Declare the DetectorVolume friend for portal setting
0062   friend class DetectorVolume;
0063 
0064   Portal() = delete;
0065 
0066   /// Const access to the surface representation
0067   const RegularSurface& surface() const;
0068 
0069   /// Non-const access to the surface reference
0070   RegularSurface& surface();
0071 
0072   /// @brief Visit all reachable surfaces of the detector
0073   ///
0074   /// @tparam visitor_t Type of the callable visitor
0075   ///
0076   /// @param visitor will be called with the represented surface
0077   template <ACTS_CONCEPT(SurfaceVisitor) visitor_t>
0078   void visitSurface(visitor_t&& visitor) const {
0079     visitor(m_surface.get());
0080   }
0081 
0082   /// @brief Visit all reachable surfaces of the detector - non-const
0083   ///
0084   /// @tparam visitor_t Type of the callable visitor
0085   ///
0086   /// @param visitor will be called with the represented surface
0087   template <ACTS_CONCEPT(MutableSurfaceVisitor) visitor_t>
0088   void visitMutableSurface(visitor_t&& visitor) {
0089     visitor(m_surface.get());
0090   }
0091 
0092   /// Update the current volume
0093   ///
0094   /// @param gctx is the Geometry context of this call
0095   /// @param nState [in,out] the navigation state for the volume to be updated
0096   ///
0097   void updateDetectorVolume(const GeometryContext& gctx,
0098                             NavigationState& nState) const noexcept(false);
0099 
0100   /// Set the geometry identifier (to the underlying surface)
0101   ///
0102   /// @param geometryId the geometry identifier to be assigned
0103   void assignGeometryId(const GeometryIdentifier& geometryId);
0104 
0105   /// Fuse with another portal, this one is kept
0106   ///
0107   /// @param aPortal is the first portal to fuse
0108   /// @param bPortal is the second portal to fuse
0109   ///
0110   /// @note this will combine the portal links from the both
0111   /// portals into a new one, it will throw an exception if the
0112   /// portals are not fusable
0113   ///
0114   /// @note if one portal carries material, it will be kept,
0115   /// however, if both portals carry material, an exception
0116   /// will be thrown and the portals are not fusable
0117   ///
0118   /// @note Both input portals become invalid, in that their update
0119   /// delegates and attached volumes are reset
0120   static std::shared_ptr<Portal> fuse(
0121       std::shared_ptr<Portal>& aPortal,
0122       std::shared_ptr<Portal>& bPortal) noexcept(false);
0123 
0124   /// Update the volume link
0125   ///
0126   /// @param dir the direction of the link
0127   /// @param dVolumeUpdater is the mangaged volume updator delegate
0128   /// @param attachedVolumes is the list of attached volumes for book keeping
0129   ///
0130   /// @note this overwrites the existing link
0131   void assignDetectorVolumeUpdater(
0132       Direction dir, DetectorVolumeUpdater dVolumeUpdater,
0133       std::vector<std::shared_ptr<DetectorVolume>> attachedVolumes);
0134 
0135   /// Update the volume link, w/o directive, i.e. it relies that there's only
0136   /// one remaining link to be set, throws an exception if that's not the case
0137   ///
0138   /// @param dVolumeUpdater is the mangaged volume updator delegate
0139   /// @param attachedVolumes is the list of attached volumes for book keeping
0140   ///
0141   /// @note this overwrites the existing link
0142   void assignDetectorVolumeUpdater(DetectorVolumeUpdater dVolumeUpdater,
0143                                    std::vector<std::shared_ptr<DetectorVolume>>
0144                                        attachedVolumes) noexcept(false);
0145 
0146   // Access to the portal targets: opposite/along normal vector
0147   const DetectorVolumeUpdaters& detectorVolumeUpdaters() const;
0148 
0149   // Access to the attached volumes - non-const access
0150   AttachedDetectorVolumes& attachedDetectorVolumes();
0151 
0152  private:
0153   /// The surface representation of this portal
0154   std::shared_ptr<RegularSurface> m_surface;
0155 
0156   /// The portal targets along/opposite the normal vector
0157   DetectorVolumeUpdaters m_volumeUpdaters = {DetectorVolumeUpdater{},
0158                                              DetectorVolumeUpdater{}};
0159 
0160   /// The portal attaches to the following volumes
0161   AttachedDetectorVolumes m_attachedVolumes;
0162 };
0163 
0164 }  // namespace Experimental
0165 }  // namespace Acts