Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Core/include/Acts/Surfaces/SurfaceArray.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 <iostream>
0019 #include <vector>
0020 
0021 // Forward declared friend class for private access in tests.
0022 namespace ActsTests {
0023 struct SurfaceArrayCreatorFixture;
0024 }
0025 
0026 namespace Acts {
0027 
0028 /// @brief Provides Surface binning in 2 dimensions
0029 ///
0030 /// Uses @c Grid under the hood to implement the storage and lookup
0031 /// Contains a lookup struct which talks to the @c Grid
0032 /// and performs utility actions. This struct needs to be initialised
0033 /// externally and passed to @c SurfaceArray on construction.
0034 class SurfaceArray {
0035  public:
0036   /// Constructor with a single surface
0037   /// @param srf The one and only surface
0038   explicit SurfaceArray(std::shared_ptr<const Surface> srf);
0039 
0040   /// Constructor to create a surface grid lookup for a given representative
0041   /// surface, tolerance, and axes.
0042   /// @param gctx The current geometry context object, e.g. alignment
0043   /// @param surfaces The input vector of surfaces that will be accessible
0044   ///                 through this @ref SurfaceArray.
0045   /// @param representative The surface which is used as representative
0046   /// @param tolerance The tolerance used for intersection checks
0047   /// @param axes The axes used for the grid
0048   /// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups
0049   SurfaceArray(const GeometryContext& gctx,
0050                std::vector<std::shared_ptr<const Surface>> surfaces,
0051                std::shared_ptr<RegularSurface> representative, double tolerance,
0052                std::tuple<const IAxis&, const IAxis&> axes,
0053                std::uint8_t maxNeighborDistance = 1);
0054 
0055   // non-copyable but movable due to unique_ptr member. deferred implementation
0056   // to source since the pimpl is not fully defined in the header.
0057 
0058   /// @param other the other SurfaceArray to copy from
0059   SurfaceArray(const SurfaceArray& other) = delete;
0060 
0061   /// @param other the other SurfaceArray to move from
0062   SurfaceArray(SurfaceArray&& other) noexcept;
0063 
0064   /// @param other the other SurfaceArray to copy-assign from
0065   /// @return reference to this SurfaceArray
0066   SurfaceArray& operator=(const SurfaceArray& other) = delete;
0067 
0068   /// @param other the other SurfaceArray to move-assign from
0069   /// @return reference to this SurfaceArray
0070   SurfaceArray& operator=(SurfaceArray&& other) noexcept;
0071 
0072   ~SurfaceArray();
0073 
0074   /// Get all surfaces in bin given by the global bin index
0075   /// @param bin the global bin index
0076   /// @return span of surface pointers of the bin at that position
0077   std::span<const Surface* const> at(std::size_t bin) const;
0078 
0079   /// Get all surfaces in bin given by position @p pos.
0080   /// @param gctx The current geometry context object, e.g. alignment
0081   /// @param position the lookup position
0082   /// @param direction the lookup direction
0083   /// @return span of surface pointers of the bin at that position
0084   std::span<const Surface* const> at(const GeometryContext& gctx,
0085                                      const Vector3& position,
0086                                      const Vector3& direction) const;
0087 
0088   /// Get all surfaces in bin given by local grid indices and neighbor
0089   /// distance.
0090   /// @param gridIndices the local grid indices
0091   /// @param neighborDistance the neighbor distance to include in the lookup
0092   /// @return span of surface pointers of the bin at that position and its neighbors
0093   std::span<const Surface* const> neighbors(
0094       std::array<std::size_t, 2> gridIndices,
0095       std::uint8_t neighborDistance) const;
0096 
0097   /// Get all surfaces in bin at @p pos and its neighbors
0098   /// @param gctx The current geometry context object, e.g. alignment
0099   /// @param position The position to lookup
0100   /// @param direction The direction to lookup
0101   /// @return span of surface pointers of neighbors and nominal
0102   std::span<const Surface* const> neighbors(const GeometryContext& gctx,
0103                                             const Vector3& position,
0104                                             const Vector3& direction) const;
0105 
0106   /// Get the size of the underlying grid structure including under/overflow
0107   /// bins
0108   /// @return the size
0109   std::size_t size() const;
0110 
0111   /// Get the center of the bin identified by global bin index @p bin
0112   /// @param bin the global bin index
0113   /// @return Center position of the bin in global coordinates
0114   Vector3 getBinCenter(std::size_t bin) const;
0115 
0116   /// Get all surfaces attached to this @c SurfaceArray
0117   /// @return Reference to vector of all surfaces
0118   /// @note This does not reflect the actual state of the grid. It only
0119   ///       returns what was given in the constructor, without any checks
0120   ///       if that is actually what's in the grid.
0121   const std::vector<const Surface*>& surfaces() const {
0122     return m_surfacesRawPointers;
0123   }
0124 
0125   /// Get vector of axes spanning the grid as @c AnyAxis
0126   /// @return vector of @c AnyAxis
0127   /// @note The axes in the vector are copies. Only use for introspection and
0128   ///       querying.
0129   std::vector<const IAxis*> getAxes() const;
0130 
0131   /// Checks if global bin is valid
0132   /// @param bin the global bin index
0133   /// @return bool if the bin is valid
0134   /// @note Valid means that the index points to a bin which is not a under
0135   ///       or overflow bin or out of range in any axis.
0136   bool isValidBin(std::size_t bin) const;
0137 
0138   /// The binning values described by this surface grid lookup. They are in
0139   /// order of the axes
0140   /// @return Vector of axis directions for binning
0141   std::vector<AxisDirection> binningValues() const;
0142 
0143   /// Get string representation of this @c SurfaceArray
0144   /// @param gctx The current geometry context object, e.g. alignment
0145   /// @param sl Output stream to write to
0146   /// @return the output stream given as @p sl
0147   std::ostream& toStream(const GeometryContext& gctx, std::ostream& sl) const;
0148 
0149   /// Get the representative surface used for this surface array
0150   /// @return Surface pointer
0151   const Surface* surfaceRepresentation() const;
0152 
0153   /// Get the number of local bins in each dimension. This is used to
0154   /// determine the size of the grid for neighbor lookups.
0155   /// @return Array of number of local bins in each dimension
0156   std::array<std::size_t, 2> numLocalBins() const;
0157 
0158   /// Get the maximum neighbor distance that is supported by this lookup. This
0159   /// is used to determine how many neighbors to include in neighbor lookups.
0160   /// @return Maximum neighbor distance
0161   std::uint8_t maxNeighborDistance() const;
0162 
0163   /// Forward declaration of the internal lookup struct. The actual definition
0164   /// is in the source file.
0165   struct ISurfaceGridLookup;
0166 
0167  private:
0168   /// The actual grid lookup implementation
0169   std::unique_ptr<ISurfaceGridLookup> m_gridLookup;
0170   /// this vector makes sure we have shared ownership over the surfaces
0171   std::vector<std::shared_ptr<const Surface>> m_surfaces;
0172   /// this vector is returned, so that (expensive) copying of the shared_ptr
0173   /// vector does not happen by default
0174   std::vector<const Surface*> m_surfacesRawPointers;
0175 };
0176 
0177 }  // namespace Acts