Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:03

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