Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:11:52

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/Surfaces/BoundaryTolerance.hpp"
0013 
0014 #include <cmath>
0015 #include <ostream>
0016 
0017 namespace Acts {
0018 
0019 /// @class SurfaceBounds
0020 ///
0021 /// Interface for surface bounds.
0022 ///
0023 /// Surface bounds provide:
0024 /// - inside() checks
0025 /// - distance to boundary calculations
0026 /// - the BoundsType and a set of parameters to simplify persistency
0027 ///
0028 class SurfaceBounds {
0029  public:
0030   /// @enum BoundsType
0031   /// This is nested to the SurfaceBounds, as also VolumeBounds will have
0032   /// Bounds Type.
0033   enum BoundsType : int {
0034     eCone = 0,
0035     eCylinder = 1,
0036     eDiamond = 2,
0037     eDisc = 3,
0038     eEllipse = 4,
0039     eLine = 5,
0040     eRectangle = 6,
0041     eTrapezoid = 7,
0042     eTriangle = 8,
0043     eDiscTrapezoid = 9,
0044     eConvexPolygon = 10,
0045     eAnnulus = 11,
0046     eBoundless = 12,
0047     eOther = 13
0048   };
0049 
0050   virtual ~SurfaceBounds() = default;
0051 
0052   /// Return the bounds type - for persistency optimization
0053   /// @return the bounds type
0054   virtual BoundsType type() const = 0;
0055 
0056   /// Check if the bound coordinates are cartesian
0057   /// @return true if the bound coordinates are cartesian
0058   virtual bool isCartesian() const = 0;
0059 
0060   /// Computes the bound to cartesian jacobian at a given local position
0061   /// @param lposition is the local position at which the jacobian is computed
0062   /// @return the bound to cartesian jacobian
0063   virtual SquareMatrix2 boundToCartesianJacobian(
0064       const Vector2& lposition) const = 0;
0065 
0066   /// Computes the bound to cartesian metric at a given local position
0067   /// @param lposition is the local position at which the metric is computed
0068   /// @return the bound to cartesian metric
0069   virtual SquareMatrix2 boundToCartesianMetric(
0070       const Vector2& lposition) const = 0;
0071 
0072   /// Access method for bound values, this is a dynamically sized
0073   /// vector containing the parameters needed to describe these bounds
0074   /// @return of the stored values for this SurfaceBounds object
0075   virtual std::vector<double> values() const = 0;
0076 
0077   /// Inside check for the bounds object
0078   /// @param lposition is the local position
0079   /// @return true if the local position is inside the bounds
0080   virtual bool inside(const Vector2& lposition) const = 0;
0081 
0082   /// Calculates the closest point on the bounds to a given local position
0083   /// @param lposition is the local position
0084   /// @param metric to be used for the distance calculation
0085   /// @return the closest point on the bounds
0086   virtual Vector2 closestPoint(const Vector2& lposition,
0087                                const SquareMatrix2& metric) const = 0;
0088 
0089   /// Calculates the distance to the bounds from a given local position
0090   /// @param lposition is the local position
0091   /// @return the distance to the bounds
0092   virtual double distance(const Vector2& lposition) const {
0093     SquareMatrix2 metric = boundToCartesianMetric(lposition);
0094 
0095     Vector2 closest = closestPoint(lposition, metric);
0096     Vector2 diff = closest - lposition;
0097     return std::sqrt((diff.transpose() * metric * diff)(0, 0));
0098   }
0099 
0100   /// Inside check for the bounds object given a boundary tolerance.
0101   /// @param lposition is the local position
0102   /// @param boundaryTolerance is the boundary tolerance object
0103   /// @return true if the local position is inside the bounds and tolerance
0104   virtual bool inside(const Vector2& lposition,
0105                       const BoundaryTolerance& boundaryTolerance) const;
0106 
0107   /// Calculate the center of the surface bounds in local coordinates
0108   ///
0109   /// This method returns a representative center point of the bounds region.
0110   /// The exact definition varies by bounds type and coordinate system:
0111   ///
0112   /// **Cartesian bounds** (Rectangle, Diamond, Trapezoid):
0113   /// - Returns the geometric center or center of symmetry
0114   /// - For symmetric shapes: center of bounding box or origin (0,0)
0115   ///
0116   /// **Polar/Cylindrical bounds** (Radial, Cylinder, Cone):
0117   /// - Returns (r, phi) where r is average radius, phi is average angle
0118   /// - Coordinates are in the bounds' natural coordinate system
0119   ///
0120   /// **Complex bounds** (Annulus, ConvexPolygon):
0121   /// - Annulus: Pre-calculated from corner vertices (accounts for coordinate
0122   /// transforms)
0123   /// - Polygon: Average of all vertices (vertex centroid, not area centroid)
0124   ///
0125   /// **Infinite bounds**: Returns conceptual center at (0,0)
0126   ///
0127   /// @note The returned point is guaranteed to be a reasonable representative
0128   /// center, but may not be the true geometric centroid for all shapes.
0129   ///
0130   /// @return Vector2 representing the center position in local coordinates
0131   virtual Vector2 center() const = 0;
0132 
0133   /// Output Method for std::ostream, to be overloaded by child classes
0134   /// @param os is the outstream in which the string dump is done
0135   virtual std::ostream& toStream(std::ostream& os) const = 0;
0136 
0137   friend bool operator==(const SurfaceBounds& lhs, const SurfaceBounds& rhs) {
0138     if (&lhs == &rhs) {
0139       return true;
0140     }
0141     return (lhs.type() == rhs.type()) && (lhs.values() == rhs.values());
0142   }
0143 
0144   friend std::ostream& operator<<(std::ostream& os, const SurfaceBounds& sb) {
0145     return sb.toStream(os);
0146   }
0147 };
0148 
0149 }  // namespace Acts