Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-28 08:19:07

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 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/GeometryIdentifier.hpp"
0014 #include "Acts/Geometry/TrackingGeometryVisitor.hpp"
0015 #include "Acts/Geometry/TrackingVolume.hpp"
0016 #include "Acts/Geometry/TrackingVolumeVisitorConcept.hpp"
0017 #include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
0018 #include "Acts/Utilities/Logger.hpp"
0019 
0020 #include <functional>
0021 #include <memory>
0022 #include <string>
0023 #include <string_view>
0024 #include <unordered_map>
0025 #include <utility>
0026 
0027 namespace Acts {
0028 
0029 class Layer;
0030 class Surface;
0031 class Portal;
0032 class PerigeeSurface;
0033 class IMaterialDecorator;
0034 class TrackingVolume;
0035 class TrackingGeometryVisitor;
0036 class TrackingGeometryMutableVisitor;
0037 
0038 namespace detail {
0039 /// Transparent hash for string-keyed associative containers, allowing
0040 /// heterogeneous lookup with @c std::string_view without constructing a
0041 /// temporary @c std::string.
0042 struct TransparentStringHash {
0043   using is_transparent = void;
0044 
0045   std::size_t operator()(std::string_view sv) const {
0046     return std::hash<std::string_view>{}(sv);
0047   }
0048 };
0049 
0050 /// Map from portal tag to portal, with transparent string lookup.
0051 using PortalTagMap = std::unordered_map<std::string, const Portal*,
0052                                         TransparentStringHash, std::equal_to<>>;
0053 }  // namespace detail
0054 
0055 // Forward declaration only, the implementation is hidden in the .cpp file.
0056 class Gen1GeometryClosureVisitor;
0057 
0058 ///  @class TrackingGeometry
0059 ///
0060 ///  The TrackingGeometry class is the owner of the constructed TrackingVolumes.
0061 ///
0062 ///  It enables both, a global search for an asociatedVolume
0063 ///  (respectively, if existing, a global search of an associated Layer or the
0064 ///  next associated Layer), such as a continuous navigation by BoundarySurfaces
0065 ///  between the confined TrackingVolumes.
0066 class TrackingGeometry {
0067   /// Give the GeometryBuilder friend rights
0068   friend class TrackingGeometryBuilder;
0069 
0070  public:
0071   /// Constructor
0072   ///
0073   /// @param highestVolume is the world volume
0074   /// @param materialDecorator is a dediated decorator that can assign
0075   ///        surface or volume based material to the TrackingVolume
0076   /// @param hook Identifier hook to be applied to surfaces
0077   /// @param logger instance of a logger (defaulting to the "silent" one)
0078   /// @param close If true, run the Gen1 geometry closure
0079   explicit TrackingGeometry(
0080       const std::shared_ptr<TrackingVolume>& highestVolume,
0081       const IMaterialDecorator* materialDecorator = nullptr,
0082       const GeometryIdentifierHook& hook = {},
0083       const Logger& logger = getDummyLogger(), bool close = true);
0084 
0085   /// Destructor
0086   ~TrackingGeometry();
0087 
0088   /// Access to the world volume
0089   /// @return plain pointer to the world volume
0090   const TrackingVolume* highestTrackingVolume() const;
0091 
0092   /// Access to the world volume
0093   /// @return plain pointer to the world volume
0094   TrackingVolume* highestTrackingVolume();
0095 
0096   /// Access to the world volume
0097   /// @return shared pointer to the world volume
0098   std::shared_ptr<const TrackingVolume> highestTrackingVolumePtr() const;
0099 
0100   /// return the lowest tracking Volume
0101   ///
0102   /// @param gctx The current geometry context object, e.g. alignment
0103   /// @param gp is the global position of the call
0104   ///
0105   /// @return plain pointer to the lowest TrackingVolume
0106   const TrackingVolume* lowestTrackingVolume(const GeometryContext& gctx,
0107                                              const Vector3& gp) const;
0108 
0109   /// Forward the associated Layer information
0110   ///
0111   /// @param gctx is the context for this request (e.g. alignment)
0112   /// @param gp is the global position of the call
0113   ///
0114   /// @return plain pointer to assocaiated layer
0115   const Layer* associatedLayer(const GeometryContext& gctx,
0116                                const Vector3& gp) const;
0117 
0118   /// @brief Visit all reachable surfaces
0119   ///
0120   /// @tparam visitor_t Type of the callable visitor
0121   ///
0122   /// @param visitor The callable. Will be called for each reachable surface
0123   /// that is found, a selection of the surfaces can be done in the visitor
0124   /// @param restrictToSensitives If true, only sensitive surfaces are visited
0125   ///
0126   /// @note If a context is needed for the visit, the visitor has to provide
0127   /// this, e.g. as a private member
0128   template <SurfaceVisitor visitor_t>
0129   void visitSurfaces(visitor_t&& visitor, bool restrictToSensitives) const {
0130     highestTrackingVolume()->template visitSurfaces<visitor_t>(
0131         std::forward<visitor_t>(visitor), restrictToSensitives);
0132   }
0133 
0134   /// @brief Visit all sensitive surfaces
0135   ///
0136   /// @tparam visitor_t Type of the callable visitor
0137   ///
0138   /// @param visitor The callable. Will be called for each sensitive surface
0139   /// that is found, a selection of the surfaces can be done in the visitor
0140   ///
0141   /// @note If a context is needed for the visit, the visitor has to provide
0142   /// this, e.g. as a private member
0143   template <SurfaceVisitor visitor_t>
0144   void visitSurfaces(visitor_t&& visitor) const {
0145     visitSurfaces(std::forward<visitor_t>(visitor), true);
0146   }
0147 
0148   /// @brief Visit all reachable tracking volumes
0149   ///
0150   /// @tparam visitor_t Type of the callable visitor
0151   ///
0152   /// @param visitor The callable. Will be called for each reachable volume
0153   /// that is found, a selection of the volumes can be done in the visitor
0154   ///
0155   /// @note If a context is needed for the visit, the visitor has to provide
0156   /// this, e.g. as a private member
0157   template <TrackingVolumeVisitor visitor_t>
0158   void visitVolumes(visitor_t&& visitor) const {
0159     highestTrackingVolume()->template visitVolumes<visitor_t>(
0160         std::forward<visitor_t>(visitor));
0161   }
0162 
0163   /// @copydoc TrackingVolume::apply
0164   void apply(TrackingGeometryVisitor& visitor) const;
0165 
0166   /// @copydoc TrackingVolume::apply
0167   void apply(TrackingGeometryMutableVisitor& visitor);
0168 
0169   /// @brief Apply an arbitrary callable as a visitor to the tracking volume
0170   ///
0171   /// @param callable The callable to apply
0172   ///
0173   /// @note The visitor can be overloaded on any of the arguments that
0174   ///       the methods in @c TrackingGeometryVisitor receive.
0175   template <typename Callable>
0176   void apply(Callable&& callable)
0177     requires(detail::callableWithAnyMutable<Callable>() &&
0178              !detail::callableWithAnyConst<Callable>())
0179   {
0180     detail::TrackingGeometryLambdaMutableVisitor visitor{
0181         std::forward<Callable>(callable)};
0182     apply(visitor);
0183   }
0184 
0185   /// @brief Apply an arbitrary callable as a visitor to the tracking volume
0186   ///
0187   /// @param callable The callable to apply
0188   ///
0189   /// @note The visitor can be overloaded on any of the arguments that
0190   ///       the methods in @c TrackingGeometryMutableVisitor receive.
0191   template <typename Callable>
0192   void apply(Callable&& callable) const
0193     requires(detail::callableWithAnyConst<Callable>())
0194   {
0195     detail::TrackingGeometryLambdaVisitor visitor{
0196         std::forward<Callable>(callable)};
0197     apply(visitor);
0198   }
0199 
0200   /// Search for a volume with the given identifier.
0201   ///
0202   /// @param id is the geometry identifier of the volume
0203   /// @retval nullptr if no such volume exists
0204   /// @retval pointer to the found volume otherwise.
0205   const TrackingVolume* findVolume(GeometryIdentifier id) const;
0206 
0207   /// Search for the first volume with the given name.
0208   ///
0209   /// @param name is the volume name to search for
0210   /// @retval nullptr if no volume carries the name
0211   /// @retval pointer to the first matching volume otherwise.
0212   const TrackingVolume* findVolumeByName(std::string_view name) const;
0213 
0214   /// Search for a surface with the given identifier.
0215   ///
0216   /// @param id is the geometry identifier of the surface
0217   /// @retval nullptr if no such surface exists
0218   /// @retval pointer to the found surface otherwise.
0219   const Surface* findSurface(GeometryIdentifier id) const;
0220 
0221   /// Search for a portal that was tagged with the given label during the
0222   /// blueprint construction (see @ref Acts::PortalDesignatorBlueprintNode).
0223   ///
0224   /// @param tag the tag assigned to the portal
0225   /// @retval nullptr if no portal carries the tag
0226   /// @retval pointer to the tagged portal otherwise.
0227   const Portal* findPortal(std::string_view tag) const;
0228 
0229   /// Access to the GeometryIdentifier - Surface association map
0230   /// @return Const reference to the geometry ID to surface map
0231   const std::unordered_map<GeometryIdentifier, const Surface*>&
0232   geoIdSurfaceMap() const;
0233 
0234   /// Visualize a tracking geometry including substructure
0235   /// @param helper The visualization helper that implement the output
0236   /// @param gctx The geometry context
0237   /// @param viewConfig Global view config
0238   /// @param portalViewConfig View config for portals
0239   /// @param sensitiveViewConfig View configuration for sensitive surfaces
0240   void visualize(IVisualization3D& helper, const GeometryContext& gctx,
0241                  const ViewConfig& viewConfig = s_viewVolume,
0242                  const ViewConfig& portalViewConfig = s_viewPortal,
0243                  const ViewConfig& sensitiveViewConfig = s_viewSensitive) const;
0244 
0245   /// Which *type* of geometry this represents: Gen1 or Gen3
0246   enum class GeometryVersion { Gen1, Gen3 };
0247 
0248   /// Return the *generation* of this `TrackingGeometry`
0249   /// @return the generation of this `TrackingGeometry`
0250   GeometryVersion geometryVersion() const;
0251 
0252  private:
0253   // the known world
0254   std::shared_ptr<TrackingVolume> m_world;
0255   // lookup containers
0256   std::unordered_map<GeometryIdentifier, const TrackingVolume*> m_volumesById;
0257   std::unordered_map<GeometryIdentifier, const Surface*> m_surfacesById;
0258   detail::PortalTagMap m_portalsByTag;
0259 };
0260 
0261 }  // namespace Acts