Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 07:50:43

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