Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:23

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