Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 07:50:53

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/Definitions/Tolerance.hpp"
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/Polyhedron.hpp"
0016 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0017 #include "Acts/Surfaces/DiscBounds.hpp"
0018 #include "Acts/Surfaces/RegularSurface.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Surfaces/SurfaceConcept.hpp"
0021 #include "Acts/Utilities/AxisDefinitions.hpp"
0022 #include "Acts/Utilities/Result.hpp"
0023 
0024 #include <memory>
0025 #include <numbers>
0026 #include <string>
0027 
0028 namespace Acts {
0029 
0030 class DetectorElementBase;
0031 class DiscBounds;
0032 class SurfaceBounds;
0033 
0034 /// @class DiscSurface
0035 ///
0036 /// Class for a disc surface (or a segment thereof)
0037 ///
0038 /// The DiscSurface is defined by the local polar coordinates @f$ (r,phi) @f$.
0039 ///
0040 /// The surface transform positions the disc such that the origin
0041 /// is at @f$ r=0 @f$, independent of the provided \c DiscBounds.
0042 /// The normal vector of the disc (i.e., the local @f$z@f$-axis) is given by
0043 /// @f$ \vec e_{z} = \vec e_{r} \times\vec e_{phi} @f$.
0044 ///
0045 /// The disc surface The only surface type for which the
0046 /// covariance matrix is NOT given in the reference frame.
0047 /// A conversion from polar to cartesian coordinates needs
0048 /// to happen to transfer the local coordinates onto the
0049 /// cartesian reference frame coordinates.
0050 ///
0051 /// @image html DiscSurface.png
0052 ///
0053 class DiscSurface : public RegularSurface {
0054   friend class Surface;
0055 
0056  protected:
0057   /// Constructor for Discs from Transform3, \f$ r_{min}, r_{max} \f$
0058   ///
0059   /// @param transform is transform that places the disc in the global 3D space
0060   /// @param rmin The inner radius of the disc surface
0061   /// @param rmax The outer radius of the disc surface
0062   /// @param hphisec The opening angle of the disc surface and is optional
0063   ///        the default is a full disc
0064   explicit DiscSurface(const Transform3& transform, double rmin, double rmax,
0065                        double hphisec = std::numbers::pi);
0066 
0067   /// Constructor for Discs from Transform3, \f$ r_{min}, r_{max}, hx_{min},
0068   /// hx_{max} \f$
0069   /// This is n this case you have DiscTrapezoidBounds
0070   ///
0071   /// @param transform is transform that places the disc in the global 3D space
0072   /// @param minhalfx The half length in x at minimal r
0073   /// @param maxhalfx The half length in x at maximal r
0074   /// @param minR The outer radius of the disc surface
0075   /// @param maxR The inner radius of the disc surface
0076   /// @param avephi The position in phi (default is 0.)
0077   /// @param stereo The optional stereo angle
0078   explicit DiscSurface(const Transform3& transform, double minhalfx,
0079                        double maxhalfx, double minR, double maxR,
0080                        double avephi = 0., double stereo = 0.);
0081 
0082   /// Constructor for Discs from Transform3 and shared DiscBounds
0083   ///
0084   /// @param transform The transform that positions the disc in global 3D
0085   /// @param dbounds The disc bounds describing the surface coverage
0086   explicit DiscSurface(const Transform3& transform,
0087                        std::shared_ptr<const DiscBounds> dbounds = nullptr);
0088 
0089   /// Constructor from DetectorElementBase : Element proxy
0090   ///
0091   /// @param dbounds The disc bounds describing the surface coverage
0092   /// @param detelement The detector element represented by this surface
0093   explicit DiscSurface(std::shared_ptr<const DiscBounds> dbounds,
0094                        const DetectorElementBase& detelement);
0095 
0096   /// Copy Constructor
0097   ///
0098   /// @param other The source surface for the copy
0099   DiscSurface(const DiscSurface& other);
0100 
0101   /// Copy constructor - with shift
0102   ///
0103   /// @param gctx The current geometry context object, e.g. alignment
0104   /// @param other is the source cone surface
0105   /// @param shift is the additional transform applied after copying
0106   DiscSurface(const GeometryContext& gctx, const DiscSurface& other,
0107               const Transform3& shift);
0108 
0109  public:
0110   /// Assignment operator
0111   ///
0112   /// @param other The source sourface for the assignment
0113   DiscSurface& operator=(const DiscSurface& other);
0114 
0115   /// Return the surface type
0116   SurfaceType type() const override;
0117 
0118   // User overloads from `RegularSurface`
0119   using RegularSurface::globalToLocal;
0120   using RegularSurface::localToGlobal;
0121   using RegularSurface::normal;
0122 
0123   /// Normal vector return
0124   ///
0125   /// @param gctx The current geometry context object, e.g. alignment
0126   /// @param lposition The local position is ignored
0127   ///
0128   /// @return a Vector3 by value
0129   Vector3 normal(const GeometryContext& gctx,
0130                  const Vector2& lposition) const final;
0131 
0132   /// Get the normal vector of this surface at a given global position
0133   /// @note The @p position is required to be on-surface.
0134   /// @param gctx The current geometry context object, e.g. alignment
0135   /// @param position is the global positiono (for @ref DiscSurface this is ignored)
0136   /// @return The normal vector
0137   Vector3 normal(const GeometryContext& gctx,
0138                  const Vector3& position) const final;
0139 
0140   /// Get the normal vector, independent of the location
0141   /// @param gctx The current geometry context object, e.g. alignment
0142   /// @return The normal vector
0143   Vector3 normal(const GeometryContext& gctx) const;
0144 
0145   /// A reference position for a given axis direction
0146   ///
0147   /// @param gctx The current geometry context object, e.g. alignment
0148   /// @param aDir The axis direction for the reference position request
0149   /// @return position that can beused for this binning
0150   Vector3 referencePosition(const GeometryContext& gctx,
0151                             AxisDirection aDir) const final;
0152 
0153   /// A reference position value for a given axis direction
0154   ///
0155   /// @param gctx The current geometry context object, e.g. alignment
0156   /// @param aDir the value generated for the reference position
0157   ///
0158   /// @note This calls the parent method except for AxisR
0159   ///
0160   /// @return float to be used for the binning schema
0161   double referencePositionValue(const GeometryContext& gctx,
0162                                 AxisDirection aDir) const final;
0163 
0164   /// This method returns the bounds by reference
0165   const SurfaceBounds& bounds() const final;
0166 
0167   /// Local to global transformation
0168   /// For planar surfaces the momentum direction is ignored in the local to
0169   /// global transformation
0170   ///
0171   /// @param gctx The current geometry context object, e.g. alignment
0172   /// @param lposition local 2D position in specialized surface frame
0173   ///
0174   /// @return global position by value
0175   Vector3 localToGlobal(const GeometryContext& gctx,
0176                         const Vector2& lposition) const final;
0177 
0178   /// Global to local transformation
0179   /// @note the direction is ignored for Disc surfaces in this calculateion
0180   ///
0181   /// @param gctx The current geometry context object, e.g. alignment
0182   /// @param position global 3D position - considered to be on surface but not
0183   /// inside bounds (check is done)
0184   /// @param tolerance optional tolerance within which a point is considered
0185   /// valid on surface
0186   ///
0187   /// @return a Result<Vector2> which can be !ok() if the operation fails
0188   Result<Vector2> globalToLocal(
0189       const GeometryContext& gctx, const Vector3& position,
0190       double tolerance = s_onSurfaceTolerance) const final;
0191 
0192   /// Special method for DiscSurface : local<->local transformations polar <->
0193   /// cartesian
0194   ///
0195   /// @param lpolar is a local position in polar coordinates
0196   ///
0197   /// @return values is local 2D position in cartesian coordinates  @todo check
0198   Vector2 localPolarToCartesian(const Vector2& lpolar) const;
0199 
0200   /// Special method for Disc surface : local<->local transformations polar <->
0201   /// cartesian
0202   ///
0203   /// @param lcart is local 2D position in cartesian coordinates
0204   ///
0205   /// @return value is a local position in polar coordinates
0206   Vector2 localCartesianToPolar(const Vector2& lcart) const;
0207 
0208   /// Special method for DiscSurface : local<->local transformations polar <->
0209   /// cartesian
0210   ///
0211   /// @param locpol is a local position in polar coordinates
0212   ///
0213   /// @return values is local 2D position in cartesian coordinates
0214   Vector2 localPolarToLocalCartesian(const Vector2& locpol) const;
0215 
0216   /// Special method for DiscSurface :  local<->global transformation when
0217   /// provided cartesian coordinates
0218   ///
0219   /// @param gctx The current geometry context object, e.g. alignment
0220   /// @param lposition is local 2D position in cartesian coordinates
0221   ///
0222   /// @return value is a global cartesian 3D position
0223   Vector3 localCartesianToGlobal(const GeometryContext& gctx,
0224                                  const Vector2& lposition) const;
0225 
0226   /// Special method for DiscSurface : global<->local from cartesian coordinates
0227   ///
0228   /// @param gctx The current geometry context object, e.g. alignment
0229   /// @param position is a global cartesian 3D position
0230   /// @param tol The absolute tolerance parameter
0231   ///
0232   /// @return value is a local polar
0233   Vector2 globalToLocalCartesian(const GeometryContext& gctx,
0234                                  const Vector3& position,
0235                                  double tol = 0.) const;
0236 
0237   /// Calculate the jacobian from local to global which the surface knows best,
0238   /// hence the calculation is done here.
0239   ///
0240   /// @param gctx The current geometry context object, e.g. alignment
0241   /// @param position global 3D position
0242   /// @param direction global 3D momentum direction
0243   ///
0244   /// @return Jacobian from local to global
0245   BoundToFreeMatrix boundToFreeJacobian(const GeometryContext& gctx,
0246                                         const Vector3& position,
0247                                         const Vector3& direction) const final;
0248 
0249   /// Calculate the jacobian from global to local which the surface knows best,
0250   /// hence the calculation is done here.
0251   ///
0252   /// @param gctx The current geometry context object, e.g. alignment
0253   /// @param position global 3D position
0254   /// @param direction global 3D momentum direction
0255   ///
0256   /// @return Jacobian from global to local
0257   FreeToBoundMatrix freeToBoundJacobian(const GeometryContext& gctx,
0258                                         const Vector3& position,
0259                                         const Vector3& direction) const final;
0260 
0261   /// Path correction due to incident of the track
0262   ///
0263   /// @param gctx The current geometry context object, e.g. alignment
0264   /// @param position The global position as a starting point
0265   /// @param direction The global momentum direction at the starting point
0266   /// @return The correction factor due to incident
0267   double pathCorrection(const GeometryContext& gctx, const Vector3& position,
0268                         const Vector3& direction) const final;
0269 
0270   /// @brief Straight line intersection schema
0271   ///
0272   /// @param gctx The current geometry context object, e.g. alignment
0273   /// @param position The global position as a starting point
0274   /// @param direction The global direction at the starting point
0275   ///        @note expected to be normalized (no checking)
0276   /// @param boundaryTolerance The boundary check prescription
0277   /// @param tolerance the tolerance used for the intersection
0278   ///
0279   /// <b>Mathematical motivation:</b>
0280   ///
0281   /// the equation of the plane is given by: <br>
0282   /// @f$ \vec n \cdot \vec x = \vec n \cdot \vec p,@f$ <br>
0283   /// where @f$ \vec n = (n_{x}, n_{y}, n_{z})@f$ denotes the normal vector of
0284   /// the plane, @f$ \vec p = (p_{x}, p_{y}, p_{z})@f$ one specific point on
0285   /// the plane and @f$ \vec x = (x,y,z) @f$ all possible points
0286   /// on the plane.<br>
0287   /// Given a line with:<br>
0288   /// @f$ \vec l(u) = \vec l_{1} + u \cdot \vec v @f$, <br>
0289   /// the solution for @f$ u @f$ can be written:
0290   /// @f$ u = \frac{\vec n (\vec p - \vec l_{1})}{\vec n \vec v}@f$ <br>
0291   /// If the denominator is 0 then the line lies:
0292   /// - either in the plane
0293   /// - perpendicular to the normal of the plane
0294   ///
0295   /// @return The @c SurfaceMultiIntersection object
0296   SurfaceMultiIntersection intersect(
0297       const GeometryContext& gctx, const Vector3& position,
0298       const Vector3& direction,
0299       const BoundaryTolerance& boundaryTolerance =
0300           BoundaryTolerance::Infinite(),
0301       double tolerance = s_onSurfaceTolerance) const final;
0302 
0303   /// Return properly formatted class name for screen output
0304   std::string name() const override;
0305 
0306   /// Return a Polyhedron for the surfaces
0307   ///
0308   /// @param gctx The current geometry context object, e.g. alignment
0309   /// @param quarterSegments Number of segments used to describe the
0310   /// quarter of a full circle
0311   ///
0312   /// @return A list of vertices and a face/facett description of it
0313   Polyhedron polyhedronRepresentation(
0314       const GeometryContext& gctx, unsigned int quarterSegments) const override;
0315 
0316   /// Calculate the derivative of bound track parameters local position w.r.t.
0317   /// position in local 3D Cartesian coordinates
0318   ///
0319   /// @param gctx The current geometry context object, e.g. alignment
0320   /// @param position The position of the parameters in global
0321   ///
0322   /// @return Derivative of bound local position w.r.t. position in local 3D
0323   /// cartesian coordinates
0324   ActsMatrix<2, 3> localCartesianToBoundLocalDerivative(
0325       const GeometryContext& gctx, const Vector3& position) const final;
0326 
0327   /// Merge two disc surfaces into a single one.
0328   /// @image html Disc_Merging.svg
0329   /// @note The surfaces need to be *compatible*, i.e. have disc bounds
0330   ///       that align
0331   /// @param other The other disc surface to merge with
0332   /// @param direction The binning direction: either @c AxisR or @c AxisPhi
0333   /// @param externalRotation If true, any phi rotation is done in the transform
0334   /// @param logger The logger to use
0335   /// @return The merged disc surface and a boolean indicating if surfaces are reversed
0336   /// @note The returned boolean is `false` if `this` is *left* or
0337   ///       *counter-clockwise* of @p other, and `true` if not.
0338   std::pair<std::shared_ptr<DiscSurface>, bool> mergedWith(
0339       const DiscSurface& other, AxisDirection direction, bool externalRotation,
0340       const Logger& logger = getDummyLogger()) const;
0341 
0342  protected:
0343   std::shared_ptr<const DiscBounds> m_bounds;  ///< bounds (shared)
0344 };
0345 
0346 static_assert(RegularSurfaceConcept<DiscSurface>,
0347               "DiscSurface does not fulfill RegularSurfaceConcept");
0348 
0349 }  // namespace Acts