|
|
|||
File indexing completed on 2026-11-30 09:23:42
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/GeometryContext.hpp" 0013 #include "Acts/Surfaces/RegularSurface.hpp" 0014 #include "Acts/Surfaces/Surface.hpp" 0015 #include "Acts/Utilities/AxisDefinitions.hpp" 0016 #include "Acts/Utilities/IAxis.hpp" 0017 0018 #include <algorithm> 0019 #include <array> 0020 #include <cstdint> 0021 #include <iostream> 0022 #include <vector> 0023 0024 // Forward declared friend class for private access in tests. 0025 namespace ActsTests { 0026 struct SurfaceArrayCreatorFixture; 0027 } 0028 0029 namespace Acts { 0030 0031 /// @brief Provides Surface binning in 2 dimensions 0032 /// 0033 /// Uses @c Grid under the hood to implement the storage and lookup 0034 /// Contains a lookup struct which talks to the @c Grid 0035 /// and performs utility actions. This struct needs to be initialised 0036 /// externally and passed to @c SurfaceArray on construction. 0037 class SurfaceArray { 0038 public: 0039 /// Bounds on the neighbor window, in bins per grid axis. The floor serves 0040 /// lookups that cannot see the surfaces the fill saw, e.g. under alignment. 0041 struct NeighborWindow { 0042 /// Fewest bins served in each direction, regardless of the crossing angle 0043 std::array<std::uint8_t, 2> min = {0, 0}; 0044 /// Most bins served in each direction; also sizes the neighbor cache 0045 std::array<std::uint8_t, 2> max = {2, 2}; 0046 0047 /// Default window: no floor, at most two bins per axis 0048 constexpr NeighborWindow() = default; 0049 0050 /// Window with an explicit floor and bound per axis 0051 /// @param windowMin Fewest bins served in each direction 0052 /// @param windowMax Most bins served in each direction 0053 constexpr NeighborWindow(std::array<std::uint8_t, 2> windowMin, 0054 std::array<std::uint8_t, 2> windowMax) 0055 : min(windowMin), max(windowMax) {} 0056 0057 /// Isotropic window: at least one bin unless the bound forbids it, at 0058 /// most @p maxNeighborDistance. 0059 /// @deprecated The two axes of a layer grid are not equivalent, give the 0060 /// bounds per axis. 0061 /// @param maxNeighborDistance Most bins served in each direction 0062 [[deprecated( 0063 "Pass an Acts::SurfaceArray::NeighborWindow with per-axis bounds " 0064 "instead of a single neighbor distance")]] 0065 constexpr NeighborWindow( // NOLINT(google-explicit-constructor) 0066 std::uint8_t maxNeighborDistance) 0067 : min({std::min<std::uint8_t>(1, maxNeighborDistance), 0068 std::min<std::uint8_t>(1, maxNeighborDistance)}), 0069 max({maxNeighborDistance, maxNeighborDistance}) {} 0070 }; 0071 0072 /// Constructor with a single surface 0073 /// @param srf The one and only surface 0074 explicit SurfaceArray(std::shared_ptr<const Surface> srf); 0075 0076 /// Constructor to create a surface grid lookup for a given representative 0077 /// surface, tolerance, and axes. 0078 /// @param gctx The current geometry context object, e.g. alignment 0079 /// @param surfaces The input vector of surfaces that will be accessible 0080 /// through this @ref SurfaceArray. 0081 /// @param representative The surface which is used as representative 0082 /// @param tolerance The tolerance used for intersection checks 0083 /// @param axes The axes used for the grid 0084 /// @param neighborWindow Bounds on the neighbor window, in bins per grid axis 0085 /// @param overfill Extra cells per direction and axis to fill around each matched 0086 /// cell, wrapping closed axes and stopping at the grid edges. Zero 0087 /// preserves the footprint; one adds immediate neighbors, including 0088 /// diagonals. This also affects at(), independently of neighborWindow. 0089 SurfaceArray(const GeometryContext& gctx, 0090 std::vector<std::shared_ptr<const Surface>> surfaces, 0091 std::shared_ptr<RegularSurface> representative, double tolerance, 0092 std::tuple<const IAxis&, const IAxis&> axes, 0093 NeighborWindow neighborWindow = NeighborWindow{{0, 0}, {2, 2}}, 0094 std::uint8_t overfill = 0); 0095 0096 // non-copyable but movable due to unique_ptr member. deferred implementation 0097 // to source since the pimpl is not fully defined in the header. 0098 0099 /// @param other the other SurfaceArray to copy from 0100 SurfaceArray(const SurfaceArray& other) = delete; 0101 0102 /// @param other the other SurfaceArray to move from 0103 SurfaceArray(SurfaceArray&& other) noexcept; 0104 0105 /// @param other the other SurfaceArray to copy-assign from 0106 /// @return reference to this SurfaceArray 0107 SurfaceArray& operator=(const SurfaceArray& other) = delete; 0108 0109 /// @param other the other SurfaceArray to move-assign from 0110 /// @return reference to this SurfaceArray 0111 SurfaceArray& operator=(SurfaceArray&& other) noexcept; 0112 0113 ~SurfaceArray(); 0114 0115 /// Get all surfaces in bin given by the global bin index 0116 /// @param bin the global bin index 0117 /// @return span of surface pointers of the bin at that position 0118 std::span<const Surface* const> at(std::size_t bin) const; 0119 0120 /// Get all surfaces in bin given by position @p pos. 0121 /// @param gctx The current geometry context object, e.g. alignment 0122 /// @param position the lookup position 0123 /// @param direction the lookup direction 0124 /// @return span of surface pointers of the bin at that position 0125 std::span<const Surface* const> at(const GeometryContext& gctx, 0126 const Vector3& position, 0127 const Vector3& direction) const; 0128 0129 /// Get all surfaces in bin given by local grid indices and neighbor 0130 /// distance. 0131 /// @param gridIndices the local grid indices 0132 /// @param neighborDistance the neighbor distance to include in the lookup, 0133 /// the same along both axes 0134 /// @return span of surface pointers of the bin at that position and its neighbors 0135 std::span<const Surface* const> neighbors( 0136 std::array<std::size_t, 2> gridIndices, 0137 std::uint8_t neighborDistance) const; 0138 0139 /// Get all surfaces in bin given by local grid indices and a neighbor 0140 /// distance per axis. 0141 /// @param gridIndices the local grid indices 0142 /// @param neighborDistance the neighbor distance to include in the lookup, 0143 /// per axis 0144 /// @return span of surface pointers of the bin at that position and its neighbors 0145 std::span<const Surface* const> neighbors( 0146 std::array<std::size_t, 2> gridIndices, 0147 std::array<std::uint8_t, 2> neighborDistance) const; 0148 0149 /// Get all surfaces in bin at @p pos and its neighbors 0150 /// @param gctx The current geometry context object, e.g. alignment 0151 /// @param position The position to lookup 0152 /// @param direction The direction to lookup 0153 /// @note Curvature is reserved for a follow-up crossing correction; 0154 /// the lookup currently uses a ray. 0155 /// @param curvature Global geometric curvature for the lookup crossing 0156 /// @return span of surface pointers of neighbors and nominal 0157 std::span<const Surface* const> neighbors( 0158 const GeometryContext& gctx, const Vector3& position, 0159 const Vector3& direction, 0160 const Vector3& curvature = Vector3::Zero()) const; 0161 0162 /// Get the size of the underlying grid structure including under/overflow 0163 /// bins 0164 /// @return the size 0165 std::size_t size() const; 0166 0167 /// Get the center of the bin identified by global bin index @p bin 0168 /// @param bin the global bin index 0169 /// @return Center position of the bin in global coordinates 0170 Vector3 getBinCenter(std::size_t bin) const; 0171 0172 /// Get all surfaces attached to this @c SurfaceArray 0173 /// @return Reference to vector of all surfaces 0174 /// @note This does not reflect the actual state of the grid. It only 0175 /// returns what was given in the constructor, without any checks 0176 /// if that is actually what's in the grid. 0177 const std::vector<const Surface*>& surfaces() const { 0178 return m_surfacesRawPointers; 0179 } 0180 0181 /// Get vector of axes spanning the grid as @c AnyAxis 0182 /// @return vector of @c AnyAxis 0183 /// @note The axes in the vector are copies. Only use for introspection and 0184 /// querying. 0185 std::vector<const IAxis*> getAxes() const; 0186 0187 /// Checks if global bin is valid 0188 /// @param bin the global bin index 0189 /// @return bool if the bin is valid 0190 /// @note Valid means that the index points to a bin which is not a under 0191 /// or overflow bin or out of range in any axis. 0192 bool isValidBin(std::size_t bin) const; 0193 0194 /// The binning values described by this surface grid lookup. They are in 0195 /// order of the axes 0196 /// @return Vector of axis directions for binning 0197 std::vector<AxisDirection> binningValues() const; 0198 0199 /// Get string representation of this @c SurfaceArray 0200 /// @param gctx The current geometry context object, e.g. alignment 0201 /// @param sl Output stream to write to 0202 /// @return the output stream given as @p sl 0203 std::ostream& toStream(const GeometryContext& gctx, std::ostream& sl) const; 0204 0205 /// Get the representative surface used for this surface array 0206 /// @return Surface pointer 0207 const Surface* surfaceRepresentation() const; 0208 0209 /// Get the number of local bins in each dimension. This is used to 0210 /// determine the size of the grid for neighbor lookups. 0211 /// @return Array of number of local bins in each dimension 0212 std::array<std::size_t, 2> numLocalBins() const; 0213 0214 /// Get the bounds on the neighbor window this lookup serves. 0215 /// @return Neighbor window bounds per axis 0216 NeighborWindow neighborWindow() const; 0217 0218 /// Get the maximum neighbor distance that is supported by this lookup. 0219 /// @deprecated Use @ref neighborWindow; this reports the larger bound. 0220 /// @return Maximum neighbor distance over both axes 0221 [[deprecated( 0222 "Use Acts::SurfaceArray::neighborWindow(), the window is bounded per " 0223 "axis")]] 0224 std::uint8_t maxNeighborDistance() const; 0225 0226 /// Forward declaration of the internal lookup struct. The actual definition 0227 /// is in the source file. 0228 struct ISurfaceGridLookup; 0229 0230 private: 0231 /// The actual grid lookup implementation 0232 std::unique_ptr<ISurfaceGridLookup> m_gridLookup; 0233 /// this vector makes sure we have shared ownership over the surfaces 0234 std::vector<std::shared_ptr<const Surface>> m_surfaces; 0235 /// this vector is returned, so that (expensive) copying of the shared_ptr 0236 /// vector does not happen by default 0237 std::vector<const Surface*> m_surfacesRawPointers; 0238 }; 0239 0240 } // namespace Acts
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|