Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-22 08:23:49

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/CylinderVolumeStack.hpp"
0013 #include "Acts/Geometry/PortalShell.hpp"
0014 #include "Acts/Geometry/VolumeAttachmentStrategy.hpp"
0015 #include "Acts/Geometry/VolumeResizeStrategy.hpp"
0016 #include "Acts/Utilities/AxisDefinitions.hpp"
0017 #include "Acts/Utilities/Logger.hpp"
0018 
0019 #include <map>
0020 
0021 namespace Acts {
0022 
0023 /// This class handles the case of wrapping a set of cylinder-shaped children
0024 /// and stacking them in a configured direction.
0025 /// The stacking is done using @ref CylinderVolumeStack.
0026 /// The container does not result in an extra volume in the hierarchy, as all
0027 /// input volumes and any gap volumes produced are directly registered in the
0028 /// volume of the parent of this node.
0029 /// @note This node assumes all children produce only cylinder volumes! It throws
0030 ///       if this is not the case.
0031 class CylinderContainerBlueprintNode final : public BlueprintNode {
0032  public:
0033   /// Main constructor for the cylinder container node.
0034   /// @param name The name of the node (for debug only)
0035   /// @param direction The stacking direction
0036   /// @param attachmentStrategy The attachment strategy for the stack
0037   /// @param resizeStrategy The resize strategy
0038   /// @note The parameters are passed through to @ref CylinderVolumeStack,
0039   ///       see documentation of that class for more information
0040   CylinderContainerBlueprintNode(
0041       const std::string& name, AxisDirection direction,
0042       VolumeAttachmentStrategy attachmentStrategy =
0043           VolumeAttachmentStrategy::Midpoint,
0044       VolumeResizeStrategy resizeStrategy = VolumeResizeStrategy::Expand);
0045 
0046   /// @copydoc BlueprintNode::name
0047   const std::string& name() const override;
0048 
0049   /// This participates in the construction of the geometry via the blueprint
0050   /// tree. The steps are approximately as follows:
0051   /// -# Collect all child volumes
0052   /// -# Package them into a @ref Acts::CylinderVolumeStack, which performs
0053   ///    sizing and/or gap creation
0054   /// -# Return the @ref Acts::CylinderVolumeStack as a volume up the tree
0055   ///
0056   /// @param options The global blueprint options
0057   /// @param gctx The geometry context (nominal usually)
0058   /// @param logger The logger to use
0059   /// @return The combined @ref Acts::CylinderVolumeStack
0060   Volume& build(const BlueprintOptions& options, const GeometryContext& gctx,
0061                 const Logger& logger = Acts::getDummyLogger()) override;
0062 
0063   /// This participates in the construction of the geometry via the blueprint
0064   /// tree. The steps are approximately as follows:
0065   /// -# Walk through all volumes that were created by the build phase
0066   /// -# Check if they are: *real* child volumes or gap volumes
0067   ///   - If gap volume: produce a @ref Acts::TrackingVolume, and wrap it in a single use shell
0068   ///   - If child volume: locate the right child node it came from, call
0069   ///   ` connect` and collect the returned shell
0070   /// -# Produce a combined @ref Acts::CylinderStackPortalShell from all the shells
0071   /// -# Return that shell representation
0072   ///
0073   /// @param options The global blueprint options
0074   /// @param gctx The geometry context (nominal usually)
0075   /// @param logger The logger to use
0076   /// @return The combined @ref Acts::CylinderStackPortalShell
0077   CylinderStackPortalShell& connect(
0078       const BlueprintOptions& options, const GeometryContext& gctx,
0079       const Logger& logger = Acts::getDummyLogger()) override;
0080 
0081   /// This participates in the construction of the geometry via the blueprint
0082   /// tree. The steps are approximately as follows:
0083   /// -# Register portals created for gap volumes, as they're not handled by
0084   ///    dedicated nodes
0085   /// -# Register gap volumes in the @p parent volume
0086   /// -# Create a configured @ref Acts::INavigationPolicy for the gap
0087   /// -# Call `finalize` on all children while passing through @p parent.
0088   ///
0089   /// @param options The global blueprint options
0090   /// @param gctx The geometry context (nominal usually)
0091   /// @param parent The parent volume
0092   /// @param logger The logger to use
0093   void finalize(const BlueprintOptions& options, const GeometryContext& gctx,
0094                 TrackingVolume& parent, const Logger& logger) override;
0095 
0096   /// Setter for the stacking direction
0097   /// @param direction The stacking direction
0098   /// @return This node for chaining
0099   CylinderContainerBlueprintNode& setDirection(AxisDirection direction);
0100 
0101   /// Setter for the attachment strategy
0102   /// @param attachmentStrategy The attachment strategy
0103   /// @return This node for chaining
0104   CylinderContainerBlueprintNode& setAttachmentStrategy(
0105       VolumeAttachmentStrategy attachmentStrategy);
0106 
0107   /// Setter for the resize strategy
0108   /// @param resizeStrategy The resize strategy
0109   /// @return This node for chaining
0110   CylinderContainerBlueprintNode& setResizeStrategy(
0111       VolumeResizeStrategy resizeStrategy);
0112 
0113   /// Accessor to the stacking direction
0114   /// @return The stacking direction
0115   AxisDirection direction() const;
0116 
0117   /// Accessor to the attachment strategy
0118   /// @return The attachment strategy
0119   VolumeAttachmentStrategy attachmentStrategy() const;
0120 
0121   /// Accessor to the resize strategy
0122   /// @return The resize strategy
0123   VolumeResizeStrategy resizeStrategy() const;
0124 
0125  private:
0126   /// @copydoc BlueprintNode::addToGraphviz
0127   void addToGraphviz(std::ostream& os) const override;
0128 
0129   /// Helper function to check if a volume was created as a gap volume.
0130   /// @param volume The volume to check
0131   /// @return True if the volume is a gap volume, false otherwise
0132   bool isGapVolume(const Volume& volume) const;
0133 
0134   std::vector<CylinderPortalShell*> collectChildShells(
0135       const BlueprintOptions& options, const GeometryContext& gctx,
0136       const Logger& logger);
0137 
0138   std::string m_name;
0139 
0140   AxisDirection m_direction = AxisDirection::AxisZ;
0141 
0142   VolumeAttachmentStrategy m_attachmentStrategy{
0143       VolumeAttachmentStrategy::Midpoint};
0144 
0145   VolumeResizeStrategy m_resizeStrategy{VolumeResizeStrategy::Expand};
0146 
0147   // Is only initialized during `build`
0148   std::vector<Volume*> m_childVolumes;
0149   std::unique_ptr<CylinderVolumeStack> m_stack{nullptr};
0150   std::map<const Volume*, BlueprintNode*> m_volumeToNode;
0151   std::vector<std::pair<std::unique_ptr<SingleCylinderPortalShell>,
0152                         std::unique_ptr<TrackingVolume>>>
0153       m_gaps;
0154   std::unique_ptr<CylinderStackPortalShell> m_shell{nullptr};
0155 };
0156 
0157 }  // namespace Acts