Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 08:01:20

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/Alignment.hpp"
0013 #include "Acts/Definitions/Tolerance.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/Polyhedron.hpp"
0016 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0017 #include "Acts/Surfaces/CylinderBounds.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/Logger.hpp"
0023 #include "Acts/Utilities/Result.hpp"
0024 #include "Acts/Utilities/detail/RealQuadraticEquation.hpp"
0025 
0026 #include <memory>
0027 #include <numbers>
0028 #include <string>
0029 
0030 namespace Acts {
0031 
0032 /// @class CylinderSurface
0033 ///
0034 /// Class for a CylinderSurface in the TrackingGeometry.
0035 /// It inherits from Surface.
0036 ///
0037 /// The cylinder surface has a special role in the TrackingGeometry,
0038 /// since it builds the surfaces of all TrackingVolumes at container level
0039 /// for a cylindrical tracking geometry.
0040 ///
0041 /// @image html CylinderSurface.png
0042 
0043 class CylinderSurface : public RegularSurface {
0044   friend class Surface;
0045 
0046  protected:
0047   /// Constructor from Transform3 and CylinderBounds
0048   ///
0049   /// @param transform The transform to position the surface
0050   /// @param radius The radius of the cylinder
0051   /// @param halfz The half length in z
0052   /// @param halfphi The half opening angle
0053   /// @param avphi The phi value from which the opening angle spans (both sides)
0054   CylinderSurface(const Transform3& transform, double radius, double halfz,
0055                   double halfphi = std::numbers::pi, double avphi = 0.);
0056 
0057   /// Constructor from Transform3 and CylinderBounds arguments
0058   ///
0059   /// @param transform The transform to position the surface
0060   /// @param cbounds is a shared pointer to a cylindeer bounds object,
0061   /// it must exist (assert test)
0062   CylinderSurface(const Transform3& transform,
0063                   std::shared_ptr<const CylinderBounds> cbounds);
0064 
0065   /// Constructor from SurfacePlacementBase: Element proxy
0066   ///
0067   /// @param cbounds are the provided cylinder bounds (shared)
0068   /// @param placement Reference to the surface placement
0069   /// @note The Surface does not take any ownership over the
0070   ///       `SurfacePlacementBase` it is expected that the user
0071   ///        ensures the life-time of the `SurfacePlacementBase`
0072   ///        and that the `Surface` is actually owned by
0073   ///        the `SurfacePlacementBase` instance
0074   CylinderSurface(std::shared_ptr<const CylinderBounds> cbounds,
0075                   const SurfacePlacementBase& placement);
0076 
0077   /// Copy constructor
0078   ///
0079   /// @param other is the source cylinder for the copy
0080   CylinderSurface(const CylinderSurface& other);
0081 
0082   /// Copy constructor - with shift
0083   ///
0084   /// @param gctx The current geometry context object, e.g. alignment
0085   /// @param other is the source cone surface
0086   /// @param shift is the additional transform applied after copying
0087   CylinderSurface(const GeometryContext& gctx, const CylinderSurface& other,
0088                   const Transform3& shift);
0089 
0090  public:
0091   ~CylinderSurface() override = default;
0092 
0093   /// Assignment operator
0094   ///
0095   /// @param other is the source cylinder for the copy
0096   /// @return Reference to this CylinderSurface after assignment
0097   CylinderSurface& operator=(const CylinderSurface& other);
0098 
0099   /// The binning position method - is overloaded for r-type binning
0100   ///
0101   /// @param gctx The current geometry context object, e.g. alignment
0102   /// @param aDir is the axis Direction of global binning to be done
0103   ///
0104   /// @return is the global position to be used for binning
0105   Vector3 referencePosition(const GeometryContext& gctx,
0106                             AxisDirection aDir) const final;
0107 
0108   /// Return the measurement frame - this is needed for alignment, in particular
0109   /// The measurement frame of a cylinder is the tangential plane at a given
0110   /// position
0111   ///
0112   /// @param gctx The current geometry context object, e.g. alignment
0113   /// @param position is the position where the measurement frame is defined
0114   /// @param direction is the momentum direction vector (ignored)
0115   /// @return rotation matrix that defines the measurement frame
0116   RotationMatrix3 referenceFrame(const GeometryContext& gctx,
0117                                  const Vector3& position,
0118                                  const Vector3& direction) const final;
0119 
0120   /// Return the surface type
0121   /// @return Surface type identifier
0122   SurfaceType type() const override;
0123 
0124   /// Return method for surface normal information
0125   /// @note for a Cylinder a local position is always required for the normal
0126   /// vector
0127   ///
0128   /// @param gctx The current geometry context object, e.g. alignment
0129   /// @param lposition is the local position for which the normal vector is
0130   /// requested
0131   ///
0132   /// @return normal vector at the local position by value
0133   Vector3 normal(const GeometryContext& gctx,
0134                  const Vector2& lposition) const final;
0135 
0136   /// Return method for surface normal information
0137   /// @note for a Cylinder a local position is always required for the normal
0138   /// vector
0139   ///
0140   /// @param gctx The current geometry context object, e.g. alignment
0141   /// @param position is the global position for which the normal vector is
0142   /// requested
0143   ///
0144   /// @return normal vector at the global position by value
0145   Vector3 normal(const GeometryContext& gctx,
0146                  const Vector3& position) const final;
0147 
0148   // Use overloads from `RegularSurface`
0149   using RegularSurface::globalToLocal;
0150   using RegularSurface::localToGlobal;
0151   using RegularSurface::normal;
0152 
0153   /// Return method for the rotational symmetry axis
0154   ///
0155   /// @param gctx The current geometry context object, e.g. alignment
0156   ///
0157   /// @return  the z-Axis of transform
0158   virtual Vector3 rotSymmetryAxis(const GeometryContext& gctx) const;
0159 
0160   /// This method returns the CylinderBounds by reference
0161   /// @return Reference to the cylinder bounds
0162   const CylinderBounds& bounds() const final;
0163 
0164   /// This method returns the shared_ptr to the CylinderBounds
0165   /// @return Shared pointer to the cylinder bounds
0166   const std::shared_ptr<const CylinderBounds>& boundsPtr() const;
0167 
0168   /// Overwrite the existing surface bounds with new ones
0169   /// @param newBounds: Pointer to the new bounds
0170   void assignSurfaceBounds(std::shared_ptr<const CylinderBounds> newBounds);
0171 
0172   /// Local to global transformation
0173   ///
0174   /// @param gctx The current geometry context object, e.g. alignment
0175   /// @param lposition is the local position to be transformed
0176   ///
0177   /// @return The global position by value
0178   Vector3 localToGlobal(const GeometryContext& gctx,
0179                         const Vector2& lposition) const final;
0180 
0181   /// Global to local transformation
0182   ///
0183   /// @param gctx The current geometry context object, e.g. alignment
0184   /// @param position is the global position to be transformed
0185   /// @param tolerance optional tolerance within which a point is considered
0186   /// valid on surface
0187   ///
0188   /// @return a Result<Vector2> which can be !ok() if the operation fails
0189   Result<Vector2> globalToLocal(
0190       const GeometryContext& gctx, const Vector3& position,
0191       double tolerance = s_onSurfaceTolerance) const final;
0192 
0193   /// Straight line intersection schema from position/direction
0194   ///
0195   /// @param gctx The current geometry context object, e.g. alignment
0196   /// @param position The position to start from
0197   /// @param direction The direction at start
0198   /// @param boundaryTolerance the Boundary Check Tolerance
0199   /// @param tolerance the tolerance used for the intersection
0200   ///
0201   /// If possible returns both solutions for the cylinder
0202   ///
0203   /// @return SurfaceIntersection object (contains intersection & surface)
0204   MultiIntersection3D intersect(
0205       const GeometryContext& gctx, const Vector3& position,
0206       const Vector3& direction,
0207       const BoundaryTolerance& boundaryTolerance =
0208           BoundaryTolerance::Infinite(),
0209       double tolerance = s_onSurfaceTolerance) const final;
0210 
0211   /// Path correction due to incident of the track
0212   ///
0213   /// @param gctx The current geometry context object, e.g. alignment
0214   /// @param position is the global position as a starting point
0215   /// @param direction is the global momentum direction at the starting point
0216   ///
0217   /// @return is the correction factor due to incident
0218   double pathCorrection(const GeometryContext& gctx, const Vector3& position,
0219                         const Vector3& direction) const final;
0220 
0221   /// Return method for properly formatted output string
0222   /// @return String representation of the class name
0223   std::string name() const override;
0224 
0225   /// Return a Polyhedron for a cylinder
0226   ///
0227   /// This method represents the cylinder as a polyhedron with a given number
0228   /// of segments to represent a quarter of a full circle. The polyedron will
0229   /// consist of the vertices of the cylinder on both sides, and faces between
0230   /// them, both as rectangular faces and as triangular faces.
0231   ///
0232   /// @param gctx The current geometry context object, e.g. alignment
0233   /// @param quarterSegments The number of segments to approximate a quarter of the
0234   /// full circle; it's chosen to be 1, only the extrema points (-pi, -0.5pi,
0235   /// 0., 0.5pi) are inserted to capture the correct extent in the x-y plane
0236   ///
0237   /// @return A list of vertices and a face/facett description of it
0238   Polyhedron polyhedronRepresentation(
0239       const GeometryContext& gctx,
0240       unsigned int quarterSegments = 2u) const override;
0241 
0242   /// Calculate the derivative of path length at the geometry constraint or
0243   /// point-of-closest-approach w.r.t. alignment parameters of the surface (i.e.
0244   /// local frame origin in global 3D Cartesian coordinates and its rotation
0245   /// represented with extrinsic Euler angles)
0246   ///
0247   /// @param gctx The current geometry context object, e.g. alignment
0248   /// @param position global 3D position
0249   /// @param direction global 3D momentum direction
0250   ///
0251   /// @return Derivative of path length w.r.t. the alignment parameters
0252   AlignmentToPathMatrix alignmentToPathDerivative(
0253       const GeometryContext& gctx, const Vector3& position,
0254       const Vector3& direction) const final;
0255 
0256   /// Calculate the derivative of bound track parameters local position w.r.t.
0257   /// position in local 3D Cartesian coordinates
0258   ///
0259   /// @param gctx The current geometry context object, e.g. alignment
0260   /// @param position The position of the parameters in global
0261   ///
0262   /// @return Derivative of bound local position w.r.t. position in local 3D
0263   /// cartesian coordinates
0264   Matrix<2, 3> localCartesianToBoundLocalDerivative(
0265       const GeometryContext& gctx, const Vector3& position) const final;
0266 
0267   /// Merge two cylinder surfaces into a single one.
0268   /// @image html Cylinder_Merging.svg
0269   /// @note The surfaces need to be *compatible*, i.e. have cylinder bounds
0270   ///       that align, and have the same radius
0271   /// @param other The other cylinder surface to merge with
0272   /// @param direction The axis direction: either @c AxisZ or @c AxisRPhi
0273   /// @param externalRotation If true, any phi rotation is done in the transform
0274   /// @param logger The logger to use
0275   /// @return The merged cylinder surface and a boolean indicating if surfaces are reversed
0276   /// @note The returned boolean is `false` if `this` is *left* or
0277   ///       *counter-clockwise* of @p other, and `true` if not.
0278   std::pair<std::shared_ptr<CylinderSurface>, bool> mergedWith(
0279       const CylinderSurface& other, AxisDirection direction,
0280       bool externalRotation, const Logger& logger = getDummyLogger()) const;
0281 
0282   /// @copydoc Surface::assignSurfaceMaterial
0283   void assignSurfaceMaterial(
0284       std::shared_ptr<const ISurfaceMaterial> material) override;
0285 
0286  protected:
0287   std::shared_ptr<const CylinderBounds> m_bounds;  //!< bounds (shared)
0288 
0289   /// @copydoc Surface::localAxes
0290   std::array<AxisDirection, 2> localAxes() const override {
0291     return {AxisDirection::AxisRPhi, AxisDirection::AxisZ};
0292   }
0293 
0294   /// @copydoc Surface::transformSurfaceLocalToMaterialLocal
0295   Vector2 transformSurfaceLocalToMaterialLocal(
0296       const Vector2& surfaceLocal) const override;
0297 
0298  private:
0299   bool m_scaleMaterialAxis = false;
0300 
0301   /// Implementation of the intersection solver
0302   ///
0303   ///  <b>mathematical motivation:</b>
0304   ///
0305   /// The cylinder is given by :
0306   ///   - cylinder center: ccenter (C)
0307   ///   - the direction of the cylinder axis: cdirection (DZ)
0308   ///   - the radius r
0309   /// The line is given by :
0310   ///   - a reference position : lposition (L0)
0311   ///   - the line direction: ldirection (DL)
0312   ///   the parametric form for the line is then : L(t) = L0 + t * DL
0313   ///
0314   /// Any point P on infinite cylinder if :
0315   ///      ((P - C) x DZ)^2 = r^2 * DZ^2
0316   /// We know that DZ is a unit vector:
0317   ///   DZ^2 == 1
0318   /// When expanded with the line equation, this is  :
0319   ///      ((L0 - C) x DZ + t * (DL x DZ))^2 = r^2 * DZ^2
0320   /// which is a quadratic equation in the form (X + t * Y)^2 = d, where :
0321   ///  X = (L0 - C) x DZ
0322   ///  Y = DL x DZ
0323   ///  d = r^2 * (DZ)^2
0324   /// Now, expand the equation :
0325   /// t^2 * (Y . Y) + t * (2 * (X . Y)) + (X . X) - d = 0
0326   /// => second order equation in the form : a*t^2 + b*t + c = 0 where
0327   /// a = (Y . Y)
0328   /// b = 2 * (X . Y)
0329   /// c = (X . X) - d
0330   /// finally solve the second order equation : a*t^2 + b*t + c = 0
0331   /// reinsertion into the line equation.
0332   ///
0333   /// @return the quadratic equation
0334   detail::RealQuadraticEquation intersectionSolver(
0335       const Transform3& transform, const Vector3& position,
0336       const Vector3& direction) const;
0337 };
0338 
0339 static_assert(RegularSurfaceConcept<CylinderSurface>,
0340               "CylinderSurface does not fulfill RegularSurfaceConcept");
0341 
0342 }  // namespace Acts