Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-05 07:57: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 #pragma once
0010 
0011 #include "Acts/Geometry/BlueprintNode.hpp"
0012 #include "Acts/Geometry/BlueprintOptions.hpp"
0013 #include "Acts/Geometry/PortalShell.hpp"
0014 #include "Acts/Geometry/TrackingVolume.hpp"
0015 #include "Acts/Geometry/VolumeAttachmentStrategy.hpp"
0016 #include "Acts/Geometry/VolumeResizeStrategy.hpp"
0017 #include "Acts/Geometry/VolumeStack.hpp"
0018 #include "Acts/Utilities/AxisDefinitions.hpp"
0019 #include "Acts/Utilities/GraphViz.hpp"
0020 #include "Acts/Utilities/Logger.hpp"
0021 #include "Acts/Utilities/ThrowAssert.hpp"
0022 
0023 #include <map>
0024 
0025 namespace Acts::Experimental {
0026 
0027 /// @class ContainerBlueprintNode
0028 ///
0029 /// A blueprint node that can contain multiple child volumes. It is responsible
0030 /// for managing the child volumes and their shells. The child volumes can be
0031 /// either gap volumes or volumes from child nodes.
0032 ///
0033 /// The container node is responsible for:
0034 /// 1. Managing the child volumes and their shells
0035 /// 2. Creating gap volumes between child volumes
0036 /// 3. Collecting shells from child nodes and gap volumes
0037 /// 4. Building the volume stack
0038 ///
0039 /// The container node is an abstract base class. Derived classes must
0040 /// implement:
0041 /// 1. makeStack - to create the appropriate volume stack
0042 /// 2. typeName - to provide the type name for debug output
0043 ///
0044 class ContainerBlueprintNode : public BlueprintNode {
0045  public:
0046   /// Main constructor for the container node.
0047   /// @param name The name of the node (for debug only)
0048   /// @param axis The stacking axis direction in local reference frame
0049   /// @param attachmentStrategy The attachment strategy for the stack
0050   /// @param resizeStrategy The resize strategy for the stack
0051   ContainerBlueprintNode(
0052       const std::string& name, AxisDirection axis,
0053       VolumeAttachmentStrategy attachmentStrategy =
0054           VolumeAttachmentStrategy::Midpoint,
0055       VolumeResizeStrategy resizeStrategy = VolumeResizeStrategy::Expand);
0056 
0057   /// Main constructor for the container node.
0058   /// @param name The name of the node (for debug only)
0059   /// @param axis The stacking axis direction in local reference frame
0060   /// @param attachmentStrategy The attachment strategy for the stack
0061   /// @param resizeStrategies The resize strategies for the stack
0062   ContainerBlueprintNode(
0063       const std::string& name, AxisDirection axis,
0064       VolumeAttachmentStrategy attachmentStrategy,
0065       std::pair<VolumeResizeStrategy, VolumeResizeStrategy> resizeStrategies);
0066 
0067   /// @copydoc BlueprintNode::name
0068   const std::string& name() const override;
0069 
0070   /// This participates in the construction of the geometry via the blueprint
0071   /// tree. The steps are approximately as follows:
0072   /// -# Collect all child volumes
0073   /// -# Package them into a VolumeStack (cuboid or cylinder), which performs
0074   ///    sizing and/or gap creation
0075   /// -# Return the VolumeStack as a volume up the tree
0076   ///
0077   /// @param options The global blueprint options
0078   /// @param gctx The geometry context (nominal usually)
0079   /// @param logger The logger to use
0080   /// @return The combined VolumeStack
0081   Volume& build(const Experimental::BlueprintOptions& options,
0082                 const GeometryContext& gctx,
0083                 const Logger& logger = Acts::getDummyLogger()) override;
0084 
0085   /// This participates in the construction of the geometry via the blueprint
0086   /// tree. The steps are approximately as follows:
0087   /// -# Register portals created for gap volumes, as they're not handled by
0088   ///    dedicated nodes
0089   /// -# Register gap volumes in the @p parent volume
0090   /// -# Create a configured @ref Acts::INavigationPolicy for the gap
0091   /// -# Call `finalize` on all children while passing through @p parent.
0092   ///
0093   /// @param options The global blueprint options
0094   /// @param gctx The geometry context (nominal usually)
0095   /// @param parent The parent volume
0096   /// @param logger The logger to use
0097   void finalize(const Experimental::BlueprintOptions& options,
0098                 const GeometryContext& gctx, TrackingVolume& parent,
0099                 const Logger& logger) override;
0100 
0101   /// Setter for the stacking direction
0102   /// @param direction The stacking direction
0103   /// @return This node for chaining
0104   ContainerBlueprintNode& setDirection(AxisDirection direction);
0105 
0106   /// Setter for the attachment strategy
0107   /// @param attachmentStrategy The attachment strategy
0108   /// @return This node for chaining
0109   ContainerBlueprintNode& setAttachmentStrategy(
0110       VolumeAttachmentStrategy attachmentStrategy);
0111 
0112   /// Setter for the resize strategy
0113   /// @param resizeStrategy The resize strategy
0114   /// @note @p resizeStrategy is used for both sides of the container
0115   /// @return This node for chaining
0116   ContainerBlueprintNode& setResizeStrategy(
0117       VolumeResizeStrategy resizeStrategy);
0118 
0119   /// Setter for the resize strategies
0120   /// @param inner The inner resize strategy
0121   /// @param outer The outer resize strategy
0122   /// @return This node for chaining
0123   ContainerBlueprintNode& setResizeStrategies(VolumeResizeStrategy inner,
0124                                               VolumeResizeStrategy outer);
0125 
0126   /// Accessor to the stacking direction
0127   /// @return The stacking direction
0128   AxisDirection direction() const;
0129 
0130   /// Accessor to the attachment strategy
0131   /// @return The attachment strategy
0132   VolumeAttachmentStrategy attachmentStrategy() const;
0133 
0134   /// Accessor to the resize strategies
0135   /// @return The resize strategies
0136   std::pair<VolumeResizeStrategy, VolumeResizeStrategy> resizeStrategies()
0137       const;
0138 
0139   /// @copydoc BlueprintNode::addToGraphviz
0140   void addToGraphviz(std::ostream& os) const override;
0141 
0142  protected:
0143   /// Make the volume stack for the container. This is called by the build
0144   /// method and is implemented by the derived classes.
0145   /// @param gctx The current geometry context object, e.g. alignment
0146   /// @param volumes The volumes to stack
0147   /// @param logger The logger to use
0148   /// @return The volume stack
0149   virtual std::unique_ptr<VolumeStack> makeStack(const GeometryContext& gctx,
0150                                                  std::vector<Volume*>& volumes,
0151                                                  const Logger& logger) = 0;
0152 
0153   /// Get the type name of the container. This is used for the debug output
0154   /// of the container and encoding the volume shape in the dot graph.
0155   /// @return The type name
0156   virtual const std::string& typeName() const = 0;
0157 
0158   /// Collect shells from child nodes and gap volumes
0159   ///
0160   /// This function is responsible for collecting shells from child nodes and
0161   /// creating shells for gap volumes. It is used by the connect method to
0162   /// prepare the shells for the volume stack.
0163   ///
0164   /// The function processes each volume in m_childVolumes in two ways:
0165   /// 1. For gap volumes:
0166   ///    - Creates a TrackingVolume from the gap volume
0167   ///    - Assigns a unique name (ContainerName::GapN)
0168   ///    - Creates a single shell for the gap volume
0169   ///    - Stores both the shell and gap volume in m_gaps for later use
0170   ///
0171   /// 2. For child volumes:
0172   ///    - Looks up the corresponding child node in m_volumeToNode
0173   ///    - Calls connect() on the child node to get its shell
0174   ///    - Validates that the shell type matches the expected type
0175   ///    - Ensures the shell is valid
0176   ///
0177   /// The function maintains the order of volumes as they appear in
0178   /// m_childVolumes, which is important for the final stack shell construction.
0179   ///
0180   /// @tparam BaseShell The base shell type (e.g. CylinderPortalShell)
0181   /// @tparam SingleShell The single shell type (e.g. SingleCylinderPortalShell)
0182   /// @param options The blueprint options
0183   /// @param gctx The geometry context
0184   /// @param stack The volume stack
0185   /// @param prefix The prefix for debug output
0186   /// @param logger The logger to use
0187   /// @return A vector of shells in the same order as m_childVolumes
0188   template <typename BaseShell, typename SingleShell>
0189   std::vector<BaseShell*> collectChildShells(
0190       const Experimental::BlueprintOptions& options,
0191       const GeometryContext& gctx, VolumeStack& stack,
0192       const std::string& prefix, const Logger& logger);
0193 
0194   /// Implementation of the connect method for container nodes
0195   ///
0196   /// This method is responsible for:
0197   /// 1. Collecting shells from child nodes and gap volumes
0198   /// 2. Validating that the number of shells matches the number of child
0199   /// volumes
0200   /// 3. Ensuring all shells are valid
0201   /// 4. Creating a merged stack shell from all collected shells
0202   ///
0203   /// @tparam BaseShell The base shell type (e.g. CylinderPortalShell)
0204   /// @tparam SingleShell The single shell type (e.g. SingleCylinderPortalShell)
0205   /// @tparam ShellStack The stack shell type (e.g. StackCylinderPortalShell)
0206   /// @param options The blueprint options
0207   /// @param gctx The geometry context
0208   /// @param stack The volume stack
0209   /// @param prefix The prefix for debug output
0210   /// @param logger The logger to use
0211   /// @return The merged stack shell
0212   template <typename BaseShell, typename SingleShell, typename ShellStack>
0213   PortalShellBase& connectImpl(const Experimental::BlueprintOptions& options,
0214                                const GeometryContext& gctx, VolumeStack* stack,
0215                                const std::string& prefix, const Logger& logger);
0216 
0217   /// Name of the container node for debugging purposes
0218   std::string m_name;
0219   /// Stacking axis direction in local reference frame
0220   AxisDirection m_direction = AxisDirection::AxisZ;
0221   /// Volume attachment strategy for connecting volumes in the stack
0222   VolumeAttachmentStrategy m_attachmentStrategy{
0223       VolumeAttachmentStrategy::Midpoint};
0224 
0225   /// Resize strategies for inner and outer sides of the container
0226   std::pair<VolumeResizeStrategy, VolumeResizeStrategy> m_resizeStrategies{
0227       VolumeResizeStrategy::Expand, VolumeResizeStrategy::Expand};
0228 
0229   /// Container of child volumes managed by this blueprint node
0230   std::vector<Volume*> m_childVolumes;
0231   /// Volume stack instance created by derived classes during build phase
0232   /// @note This is populated during the build process by makeStack implementations
0233   std::unique_ptr<VolumeStack> m_stack{nullptr};
0234   /// Mapping from child volumes to their corresponding blueprint nodes
0235   std::map<const Volume*, BlueprintNode*> m_volumeToNode;
0236 
0237   /// Portal shell representation of this container for geometry connection
0238   std::unique_ptr<PortalShellBase> m_shell{nullptr};
0239   /// Container of gap volumes and their portal shells created between child
0240   /// volumes
0241   std::vector<std::pair<std::unique_ptr<PortalShellBase>,
0242                         std::unique_ptr<TrackingVolume>>>
0243       m_gaps;
0244 };
0245 
0246 /// Container blueprint node stacking cylindrical volumes.
0247 class CylinderContainerBlueprintNode final : public ContainerBlueprintNode {
0248  public:
0249   using ContainerBlueprintNode::ContainerBlueprintNode;
0250 
0251   /// This participates in the construction of the geometry via the blueprint
0252   /// tree. The steps are approximately as follows:
0253   /// -# Walk through all volumes that were created by the build phase
0254   /// -# Check if they are: *real* child volumes or gap volumes
0255   ///   - If gap volume: produce a @ref Acts::TrackingVolume, and wrap it in a single use shell
0256   ///   - If child volume: locate the right child node it came from, call
0257   ///   ` connect` and collect the returned shell
0258   /// -# Produce a combined StackPortalShell (cuboid or cylinder) from all the
0259   /// shells
0260   /// -# Return that shell representation
0261   ///
0262   /// @param options The global blueprint options
0263   /// @param gctx The geometry context (nominal usually)
0264   /// @param logger The logger to use
0265   /// @return The combined StackPortalShell (cuboid or cylinder)
0266   PortalShellBase& connect(
0267       const Experimental::BlueprintOptions& options,
0268       const GeometryContext& gctx,
0269       const Logger& logger = Acts::getDummyLogger()) override;
0270 
0271   std::unique_ptr<VolumeStack> makeStack(const GeometryContext& gctx,
0272                                          std::vector<Volume*>& volumes,
0273                                          const Logger& logger) override;
0274 
0275  protected:
0276   /// @brief Type name for cylinder container
0277   inline static const std::string s_typeName = "Cylinder";
0278   const std::string& typeName() const override;
0279 };
0280 
0281 /// Container blueprint node stacking cuboid volumes.
0282 class CuboidContainerBlueprintNode final : public ContainerBlueprintNode {
0283  public:
0284   using ContainerBlueprintNode::ContainerBlueprintNode;
0285 
0286   /// This participates in the construction of the geometry via the blueprint
0287   /// tree. The steps are approximately as follows:
0288   /// -# Walk through all volumes that were created by the build phase
0289   /// -# Check if they are: *real* child volumes or gap volumes
0290   ///   - If gap volume: produce a @ref Acts::TrackingVolume, and wrap it in a single use shell
0291   ///   - If child volume: locate the right child node it came from, call
0292   ///   ` connect` and collect the returned shell
0293   /// -# Produce a combined StackPortalShell (cuboid or cylinder) from all the
0294   /// shells
0295   /// -# Return that shell representation
0296   ///
0297   /// @param options The global blueprint options
0298   /// @param gctx The geometry context (nominal usually)
0299   /// @param logger The logger to use
0300   /// @return The combined StackPortalShell (cuboid or cylinder)
0301   PortalShellBase& connect(
0302       const Experimental::BlueprintOptions& options,
0303       const GeometryContext& gctx,
0304       const Logger& logger = Acts::getDummyLogger()) override;
0305 
0306   std::unique_ptr<VolumeStack> makeStack(const GeometryContext& gctx,
0307                                          std::vector<Volume*>& volumes,
0308                                          const Logger& logger) override;
0309 
0310  protected:
0311   /// @brief Type name for cuboid container
0312   inline static const std::string s_typeName = "Cuboid";
0313   const std::string& typeName() const override;
0314 };
0315 
0316 }  // namespace Acts::Experimental