Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:07:29

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/CylinderVolumeBounds.hpp"
0013 #include "Acts/Geometry/Volume.hpp"
0014 #include "Acts/Geometry/VolumeAttachmentStrategy.hpp"
0015 #include "Acts/Geometry/VolumeResizeStrategy.hpp"
0016 #include "Acts/Geometry/VolumeStack.hpp"
0017 #include "Acts/Utilities/AxisDefinitions.hpp"
0018 #include "Acts/Utilities/Logger.hpp"
0019 
0020 #include <vector>
0021 
0022 namespace Acts {
0023 
0024 /// @class CylinderVolumeStack
0025 /// This class implements a z-aligned or r-aligned stack
0026 /// of cylinder volumes with synchronized bounds.
0027 /// Externally, it presents as a single volume.
0028 /// On construction, the input volumes are modified so that
0029 /// they are connected in z and r and have synchronized bounds.
0030 /// The way this is done can be configured using an *attachment*
0031 /// and a *resize* strategy. Depending on the configuration,
0032 /// the input volumes are either extended or gap volumes are created.
0033 ///
0034 /// @note The volumes are never shrunk, because this would potentially
0035 ///       result in overlaps of the resulting volumes bounds.
0036 class CylinderVolumeStack : public VolumeStack {
0037  public:
0038   /// Constructor from a vector of volumes and direction
0039   /// @param gctx The current geometry context object, e.g. alignment
0040   /// @param volumes is the vector of volumes
0041   /// @param direction is the binning direction
0042   /// @param strategy is the attachment strategy
0043   /// @param resizeStrategy is the resize strategy
0044   /// @note @p resizeStrategy only affects resizing along
0045   ///       @p direction. Resizing in the other direction
0046   ///       is always delegated to the child volumes,
0047   ///       which might in turn be @c CylinderVolumeStack
0048   /// @note @p resizeStrategy is used for both ends of the stack
0049   /// @param logger is the logger
0050   /// @pre The volumes need to have a common coordinate
0051   ///      system relative to @p direction. I.e. they need
0052   ///      to be aligned in @c z and cannot have a rotation
0053   ///      in @c x or @c y.
0054   /// @pre The volumes all need to have @c CylinerVolumeBounds
0055   ///      and cannot have a @f$\phi@f$ sector or bevels.
0056   /// @note Preconditions are checked on construction
0057   CylinderVolumeStack(
0058       const GeometryContext& gctx, std::vector<Volume*>& volumes,
0059       AxisDirection direction,
0060       VolumeAttachmentStrategy strategy = VolumeAttachmentStrategy::Midpoint,
0061       VolumeResizeStrategy resizeStrategy = VolumeResizeStrategy::Expand,
0062       const Logger& logger = Acts::getDummyLogger());
0063 
0064   /// Constructor from a vector of volumes and direction
0065   /// @param gctx The current geometry context object, e.g. alignment
0066   /// @param volumes is the vector of volumes
0067   /// @param direction is the binning direction
0068   /// @param strategy is the attachment strategy
0069   /// @param resizeStrategies is the resize strategies
0070   /// @note @p resizeStrategy only affects resizing along
0071   ///       @p direction. Resizing in the other direction
0072   ///       is always delegated to the child volumes,
0073   ///       which might in turn be @c CylinderVolumeStack
0074   /// @note The first element of @p resizeStrategies is used for the *low* end
0075   ///       and the second element is used for the *high* end of the stack
0076   /// @param logger is the logger
0077   /// @pre The volumes need to have a common coordinate
0078   ///      system relative to @p direction. I.e. they need
0079   ///      to be aligned in @c z and cannot have a rotation
0080   ///      in @c x or @c y.
0081   /// @pre The volumes all need to have @c CylinerVolumeBounds
0082   ///      and cannot have a @f$\phi@f$ sector or bevels.
0083   /// @note Preconditions are checked on construction
0084   CylinderVolumeStack(
0085       const GeometryContext& gctx, std::vector<Volume*>& volumes,
0086       AxisDirection direction, VolumeAttachmentStrategy strategy,
0087       std::pair<VolumeResizeStrategy, VolumeResizeStrategy> resizeStrategies,
0088       const Logger& logger = Acts::getDummyLogger());
0089 
0090   /// Update the volume bounds and transform. This
0091   /// will update the bounds of all volumes in the stack
0092   /// to accommodate the new bounds and optionally create
0093   /// gap volumes according to the resize strategy set during
0094   /// construction.
0095   /// @param gctx The current geometry context object, e.g. alignment
0096   /// @param volbounds is the new bounds
0097   /// @param transform is the new transform
0098   /// @param logger is the logger
0099   /// @pre The volume bounds need to be of type
0100   ///      @c CylinderVolumeBounds.
0101   void update(const GeometryContext& gctx,
0102               std::shared_ptr<VolumeBounds> volbounds,
0103               std::optional<Transform3> transform = std::nullopt,
0104               const Logger& logger = getDummyLogger()) override;
0105 
0106  private:
0107   /// Helper function called during construction that performs the
0108   /// internal attachment and produces the overall outer volume bounds.
0109   /// @param gctx The current geometry context object, e.g. alignment
0110   /// @param direction is the binning direction
0111   /// @param strategy is the attachment strategy
0112   /// @param logger is the logger
0113   void initializeOuterVolume(const GeometryContext& gctx,
0114                              AxisDirection direction,
0115                              VolumeAttachmentStrategy strategy,
0116                              const Logger& logger);
0117 
0118   struct VolumeTuple;
0119 
0120   /// Helper function to pretty print the internal volume representation
0121   /// @param volumes is the vector of volumes
0122   /// @param logger is the logger
0123   /// @param lvl is the logging level
0124   static void printVolumeSequence(const std::vector<VolumeTuple>& volumes,
0125                                   const Logger& logger,
0126                                   Acts::Logging::Level lvl);
0127 
0128   /// Helper function that prints output helping in debugging overlaps
0129   /// @param direction is the overlap check direction
0130   /// @param a is the first volume
0131   /// @param b is the second volume
0132   /// @param logger is the logger
0133   static void overlapPrint(AxisDirection direction, const VolumeTuple& a,
0134                            const VolumeTuple& b, const Logger& logger);
0135 
0136   /// Helper function that checks if volumes are properly aligned
0137   /// for attachment.
0138   /// @param volumes is the vector of volumes
0139   /// @param logger is the logger
0140   static void checkVolumeAlignment(const std::vector<VolumeTuple>& volumes,
0141                                    const Logger& logger);
0142 
0143   /// Helper function that checks overlaps and attaches in z direction
0144   /// @param gctx The current geometry context object, e.g. alignment
0145   /// @param volumes is the vector of volumes
0146   /// @param strategy is the attachment strategy
0147   /// @param logger is the logger
0148   /// @return vector of gap volumes. Can be empty if none were created.
0149   std::vector<VolumeTuple> checkOverlapAndAttachInZ(
0150       const GeometryContext& gctx, std::vector<VolumeTuple>& volumes,
0151       VolumeAttachmentStrategy strategy, const Logger& logger);
0152 
0153   /// Helper function to synchronize the r bounds of the volumes
0154   /// @param volumes is the vector of volumes
0155   /// @param logger is the logger
0156   /// @return tuple of the minimum and maximum radii
0157   std::pair<double, double> synchronizeRBounds(
0158       std::vector<VolumeTuple>& volumes, const Logger& logger);
0159 
0160   /// Helper function that checks overlaps and attaches in r direction
0161   /// @param gctx The current geometry context object, e.g. alignment
0162   /// @param volumes is the vector of volumes
0163   /// @param strategy is the attachment strategy
0164   /// @param logger is the logger
0165   /// @return vector of gap volumes. Can be empty if none were created.
0166   std::vector<VolumeTuple> checkOverlapAndAttachInR(
0167       const GeometryContext& gctx, std::vector<VolumeTuple>& volumes,
0168       VolumeAttachmentStrategy strategy, const Logger& logger);
0169 
0170   /// Helper function to synchronize the z bounds of the volumes
0171   /// @param volumes is the vector of volumes
0172   /// @param logger is the logger
0173   /// @return tuple of the minimum and maximum z extent
0174   std::pair<double, double> synchronizeZBounds(
0175       std::vector<VolumeTuple>& volumes, const Logger& logger);
0176 
0177   /// Helper functions that checks if the cylinder volume bounds
0178   /// given do not contain any phi sectors or bevels.
0179   /// @param bounds is the cylinder volume bounds
0180   /// @param logger is the logger
0181   static void checkNoPhiOrBevel(const CylinderVolumeBounds& bounds,
0182                                 const Logger& logger);
0183 
0184   Transform3 m_groupTransform{};
0185 };
0186 
0187 }  // namespace Acts