Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:42:21

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   /// @return Reference to this DiscSurface after assignment
0114   DiscSurface& operator=(const DiscSurface& other);
0115 
0116   /// Return the surface type
0117   /// @return Surface type identifier
0118   SurfaceType type() const override;
0119 
0120   // User overloads from `RegularSurface`
0121   using RegularSurface::globalToLocal;
0122   using RegularSurface::localToGlobal;
0123   using RegularSurface::normal;
0124 
0125   /// Normal vector return
0126   ///
0127   /// @param gctx The current geometry context object, e.g. alignment
0128   /// @param lposition The local position is ignored
0129   ///
0130   /// @return a Vector3 by value
0131   Vector3 normal(const GeometryContext& gctx,
0132                  const Vector2& lposition) const final;
0133 
0134   /// Get the normal vector of this surface at a given global position
0135   /// @note The @p position is required to be on-surface.
0136   /// @param gctx The current geometry context object, e.g. alignment
0137   /// @param position is the global positiono (for @ref DiscSurface this is ignored)
0138   /// @return The normal vector
0139   Vector3 normal(const GeometryContext& gctx,
0140                  const Vector3& position) const final;
0141 
0142   /// Get the normal vector, independent of the location
0143   /// @param gctx The current geometry context object, e.g. alignment
0144   /// @return The normal vector
0145   Vector3 normal(const GeometryContext& gctx) const;
0146 
0147   /// A reference position for a given axis direction
0148   ///
0149   /// @param gctx The current geometry context object, e.g. alignment
0150   /// @param aDir The axis direction for the reference position request
0151   /// @return position that can beused for this binning
0152   Vector3 referencePosition(const GeometryContext& gctx,
0153                             AxisDirection aDir) const final;
0154 
0155   /// A reference position value for a given axis direction
0156   ///
0157   /// @param gctx The current geometry context object, e.g. alignment
0158   /// @param aDir the value generated for the reference position
0159   ///
0160   /// @note This calls the parent method except for AxisR
0161   ///
0162   /// @return float to be used for the binning schema
0163   double referencePositionValue(const GeometryContext& gctx,
0164                                 AxisDirection aDir) const final;
0165 
0166   /// This method returns the bounds by reference
0167   /// @return Reference to the surface bounds
0168   const SurfaceBounds& bounds() const final;
0169   /// This method returns the shared_ptr to the DiscBounds
0170   const std::shared_ptr<const DiscBounds>& boundsPtr() const;
0171   /// Overwrite the existing surface bounds with new ones
0172   /// @param newBounds: Pointer to the new bounds
0173   void assignSurfaceBounds(std::shared_ptr<const DiscBounds> newBounds);
0174 
0175   /// Local to global transformation
0176   /// For planar surfaces the momentum direction is ignored in the local to
0177   /// global transformation
0178   ///
0179   /// @param gctx The current geometry context object, e.g. alignment
0180   /// @param lposition local 2D position in specialized surface frame
0181   ///
0182   /// @return global position by value
0183   Vector3 localToGlobal(const GeometryContext& gctx,
0184                         const Vector2& lposition) const final;
0185 
0186   /// Global to local transformation
0187   /// @note the direction is ignored for Disc surfaces in this calculateion
0188   ///
0189   /// @param gctx The current geometry context object, e.g. alignment
0190   /// @param position global 3D position - considered to be on surface but not
0191   /// inside bounds (check is done)
0192   /// @param tolerance optional tolerance within which a point is considered
0193   /// valid on surface
0194   ///
0195   /// @return a Result<Vector2> which can be !ok() if the operation fails
0196   Result<Vector2> globalToLocal(
0197       const GeometryContext& gctx, const Vector3& position,
0198       double tolerance = s_onSurfaceTolerance) const final;
0199 
0200   /// Special method for DiscSurface : local<->local transformations polar <->
0201   /// cartesian
0202   ///
0203   /// @param lpolar is a local position in polar coordinates
0204   ///
0205   /// @return values is local 2D position in cartesian coordinates  @todo check
0206   Vector2 localPolarToCartesian(const Vector2& lpolar) const;
0207 
0208   /// Special method for Disc surface : local<->local transformations polar <->
0209   /// cartesian
0210   ///
0211   /// @param lcart is local 2D position in cartesian coordinates
0212   ///
0213   /// @return value is a local position in polar coordinates
0214   Vector2 localCartesianToPolar(const Vector2& lcart) const;
0215 
0216   /// Special method for DiscSurface : local<->local transformations polar <->
0217   /// cartesian
0218   ///
0219   /// @param locpol is a local position in polar coordinates
0220   ///
0221   /// @return values is local 2D position in cartesian coordinates
0222   Vector2 localPolarToLocalCartesian(const Vector2& locpol) const;
0223 
0224   /// Special method for DiscSurface :  local<->global transformation when
0225   /// provided cartesian coordinates
0226   ///
0227   /// @param gctx The current geometry context object, e.g. alignment
0228   /// @param lposition is local 2D position in cartesian coordinates
0229   ///
0230   /// @return value is a global cartesian 3D position
0231   Vector3 localCartesianToGlobal(const GeometryContext& gctx,
0232                                  const Vector2& lposition) const;
0233 
0234   /// Special method for DiscSurface : global<->local from cartesian coordinates
0235   ///
0236   /// @param gctx The current geometry context object, e.g. alignment
0237   /// @param position is a global cartesian 3D position
0238   /// @param tol The absolute tolerance parameter
0239   ///
0240   /// @return value is a local polar
0241   Vector2 globalToLocalCartesian(const GeometryContext& gctx,
0242                                  const Vector3& position,
0243                                  double tol = 0.) const;
0244 
0245   /// Calculate the jacobian from local to global which the surface knows best,
0246   /// hence the calculation is done here.
0247   ///
0248   /// @param gctx The current geometry context object, e.g. alignment
0249   /// @param position global 3D position
0250   /// @param direction global 3D momentum direction
0251   ///
0252   /// @return Jacobian from local to global
0253   BoundToFreeMatrix boundToFreeJacobian(const GeometryContext& gctx,
0254                                         const Vector3& position,
0255                                         const Vector3& direction) const final;
0256 
0257   /// Calculate the jacobian from global to local which the surface knows best,
0258   /// hence the calculation is done here.
0259   ///
0260   /// @param gctx The current geometry context object, e.g. alignment
0261   /// @param position global 3D position
0262   /// @param direction global 3D momentum direction
0263   ///
0264   /// @return Jacobian from global to local
0265   FreeToBoundMatrix freeToBoundJacobian(const GeometryContext& gctx,
0266                                         const Vector3& position,
0267                                         const Vector3& direction) const final;
0268 
0269   /// Path correction due to incident of the track
0270   ///
0271   /// @param gctx The current geometry context object, e.g. alignment
0272   /// @param position The global position as a starting point
0273   /// @param direction The global momentum direction at the starting point
0274   /// @return The correction factor due to incident
0275   double pathCorrection(const GeometryContext& gctx, const Vector3& position,
0276                         const Vector3& direction) const final;
0277 
0278   /// @brief Straight line intersection schema
0279   ///
0280   /// @param gctx The current geometry context object, e.g. alignment
0281   /// @param position The global position as a starting point
0282   /// @param direction The global direction at the starting point
0283   ///        @note expected to be normalized (no checking)
0284   /// @param boundaryTolerance The boundary check prescription
0285   /// @param tolerance the tolerance used for the intersection
0286   ///
0287   /// <b>Mathematical motivation:</b>
0288   ///
0289   /// the equation of the plane is given by: <br>
0290   /// @f$ \vec n \cdot \vec x = \vec n \cdot \vec p,@f$ <br>
0291   /// where @f$ \vec n = (n_{x}, n_{y}, n_{z})@f$ denotes the normal vector of
0292   /// the plane, @f$ \vec p = (p_{x}, p_{y}, p_{z})@f$ one specific point on
0293   /// the plane and @f$ \vec x = (x,y,z) @f$ all possible points
0294   /// on the plane.<br>
0295   /// Given a line with:<br>
0296   /// @f$ \vec l(u) = \vec l_{1} + u \cdot \vec v @f$, <br>
0297   /// the solution for @f$ u @f$ can be written:
0298   /// @f$ u = \frac{\vec n (\vec p - \vec l_{1})}{\vec n \vec v}@f$ <br>
0299   /// If the denominator is 0 then the line lies:
0300   /// - either in the plane
0301   /// - perpendicular to the normal of the plane
0302   ///
0303   /// @return The @c MultiIntersection3D object
0304   MultiIntersection3D intersect(
0305       const GeometryContext& gctx, const Vector3& position,
0306       const Vector3& direction,
0307       const BoundaryTolerance& boundaryTolerance =
0308           BoundaryTolerance::Infinite(),
0309       double tolerance = s_onSurfaceTolerance) const final;
0310 
0311   /// Return properly formatted class name for screen output
0312   /// @return String representation of the class name
0313   std::string name() const override;
0314 
0315   /// Return a Polyhedron for the surfaces
0316   ///
0317   /// @param gctx The current geometry context object, e.g. alignment
0318   /// @param quarterSegments Number of segments used to describe the
0319   /// quarter of a full circle
0320   ///
0321   /// @return A list of vertices and a face/facett description of it
0322   Polyhedron polyhedronRepresentation(
0323       const GeometryContext& gctx, unsigned int quarterSegments) const override;
0324 
0325   /// Calculate the derivative of bound track parameters local position w.r.t.
0326   /// position in local 3D Cartesian coordinates
0327   ///
0328   /// @param gctx The current geometry context object, e.g. alignment
0329   /// @param position The position of the parameters in global
0330   ///
0331   /// @return Derivative of bound local position w.r.t. position in local 3D
0332   /// cartesian coordinates
0333   ActsMatrix<2, 3> localCartesianToBoundLocalDerivative(
0334       const GeometryContext& gctx, const Vector3& position) const final;
0335 
0336   /// Merge two disc surfaces into a single one.
0337   /// @image html Disc_Merging.svg
0338   /// @note The surfaces need to be *compatible*, i.e. have disc bounds
0339   ///       that align
0340   /// @param other The other disc surface to merge with
0341   /// @param direction The binning direction: either @c AxisR or @c AxisPhi
0342   /// @param externalRotation If true, any phi rotation is done in the transform
0343   /// @param logger The logger to use
0344   /// @return The merged disc surface and a boolean indicating if surfaces are reversed
0345   /// @note The returned boolean is `false` if `this` is *left* or
0346   ///       *counter-clockwise* of @p other, and `true` if not.
0347   std::pair<std::shared_ptr<DiscSurface>, bool> mergedWith(
0348       const DiscSurface& other, AxisDirection direction, bool externalRotation,
0349       const Logger& logger = getDummyLogger()) const;
0350 
0351  protected:
0352   std::shared_ptr<const DiscBounds> m_bounds;  ///< bounds (shared)
0353 };
0354 
0355 static_assert(RegularSurfaceConcept<DiscSurface>,
0356               "DiscSurface does not fulfill RegularSurfaceConcept");
0357 
0358 }  // namespace Acts