Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-31 08:16:06

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/Tolerance.hpp"
0012 #include "Acts/Geometry/PortalLinkBase.hpp"
0013 #include "Acts/Utilities/TransformRange.hpp"
0014 
0015 #include <iosfwd>
0016 
0017 #include <boost/container/small_vector.hpp>
0018 
0019 namespace Acts {
0020 
0021 class GridPortalLink;
0022 class Surface;
0023 
0024 /// Composite portal links can graft together other portal link instances, for
0025 /// example grids that could not be merged due to invalid binnings.
0026 ///
0027 /// ```
0028 /// +-------+      +-------+
0029 /// |       |      |       |
0030 /// |       |      |       |
0031 /// |       |      |       |
0032 /// +-------+      |       |
0033 /// |       |      |       |
0034 /// |       |  +   +-------+
0035 /// |       |      |       |
0036 /// +-------+      |       |
0037 /// |       |      |       |
0038 /// |       |      +-------+
0039 /// |       |      |       |
0040 /// +-------+      +-------+
0041 /// ```
0042 ///
0043 /// During resolution, it will consult each of it's children and return
0044 /// the result on the first surface where the lookup position is within
0045 /// bounds.
0046 class CompositePortalLink final : public PortalLinkBase {
0047  public:
0048   /// Construct a composite portal from two arbitrary other portal links. The
0049   /// only requirement is that the portal link surfaces are mergeable.
0050   /// @param a The first portal link
0051   /// @param b The second portal link
0052   /// @param direction The binning direction
0053   /// @param flatten If true, the composite will flatten any nested composite
0054   CompositePortalLink(std::unique_ptr<PortalLinkBase> a,
0055                       std::unique_ptr<PortalLinkBase> b,
0056                       AxisDirection direction, bool flatten = true);
0057 
0058   /// Construct a composite portal from any number of arbitrary other portal
0059   /// links. The only requirement is that the portal link surfaces are
0060   /// mergeable.
0061   /// @param links The portal links
0062   /// @param direction The binning direction
0063   /// @param flatten If true, the composite will flatten any nested composite
0064   CompositePortalLink(std::vector<std::unique_ptr<PortalLinkBase>> links,
0065                       AxisDirection direction, bool flatten = true);
0066 
0067   /// Print the composite portal link
0068   /// @param os The output stream
0069   void toStream(std::ostream& os) const override;
0070 
0071   /// Resolve the volume for a 2D position
0072   /// @note This will transform the position to global coordinates before
0073   ///       consulting its children.
0074   /// @note @p position is assumed to be on surface
0075   /// @param gctx The geometry context
0076   /// @param position The 2D position
0077   /// @param tolerance The on-surface tolerance
0078   /// @return Result containing the resolved tracking volume or error
0079   Result<const TrackingVolume*> resolveVolume(
0080       const GeometryContext& gctx, const Vector2& position,
0081       double tolerance = s_onSurfaceTolerance) const override;
0082 
0083   /// Resolve the volume for a 3D position
0084   /// @note @p position is assumed to be on surface
0085   /// @param gctx The geometry context
0086   /// @param position The 3D position
0087   /// @param tolerance The tolerance
0088   /// @return Result containing the resolved tracking volume or error
0089   Result<const TrackingVolume*> resolveVolume(
0090       const GeometryContext& gctx, const Vector3& position,
0091       double tolerance = s_onSurfaceTolerance) const override;
0092 
0093   /// Get the depth of the composite tree
0094   /// @return The depth
0095   std::size_t depth() const;
0096 
0097   /// Get the number of children
0098   /// @return The number of children
0099   std::size_t size() const;
0100 
0101   /// (Potentially) create a grid portal link that represents this composite
0102   /// portal link.
0103   /// @note This only works, if the composite is **flat** and only contains
0104   ///       **trivial portal links**. If these preconditions are not met, this
0105   ///       function returns a nullptr.
0106   /// @param gctx The geometry context
0107   /// @param logger The logger
0108   /// @return The grid portal link
0109   std::unique_ptr<GridPortalLink> makeGrid(const GeometryContext& gctx,
0110                                            const Logger& logger) const;
0111 
0112   /// Type alias for range of portal links with const dereferencing transform
0113   using PortalLinkRange = detail::TransformRange<
0114       detail::ConstDereference,
0115       const boost::container::small_vector<std::unique_ptr<PortalLinkBase>, 4>>;
0116 
0117   /// Get the range of children
0118   /// @return The range of children
0119   PortalLinkRange links() const;
0120 
0121  private:
0122   boost::container::small_vector<std::unique_ptr<PortalLinkBase>, 4>
0123       m_children{};
0124 
0125   AxisDirection m_direction;
0126 };
0127 
0128 }  // namespace Acts