Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-03 07:52:02

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