Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:51

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