Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:27:25

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