Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023-2024 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 #include "Acts/Surfaces/CurvilinearSurface.hpp"
0010 
0011 #include "Acts/Definitions/Tolerance.hpp"
0012 #include "Acts/Surfaces/PlaneSurface.hpp"
0013 #include "Acts/Utilities/JacobianHelpers.hpp"
0014 #include "Acts/Utilities/VectorHelpers.hpp"
0015 
0016 #include <iomanip>
0017 #include <ios>
0018 #include <ostream>
0019 
0020 namespace Acts {
0021 
0022 bool CurvilinearSurface::isStandardRepresentation() const {
0023   Vector3 T = m_direction.normalized();
0024   return std::abs(T.dot(Vector3::UnitZ())) < s_curvilinearProjTolerance;
0025 }
0026 
0027 RotationMatrix3 CurvilinearSurface::referenceFrame() const {
0028   /// the right-handed coordinate system is defined as
0029   /// T = normal
0030   /// U = Z x T if T not parallel to Z otherwise U = X x T
0031   /// V = T x U
0032   Vector3 T = m_direction.normalized();
0033   Vector3 U = (isStandardRepresentation() ? Vector3::UnitZ() : Vector3::UnitX())
0034                   .cross(T)
0035                   .normalized();
0036   Vector3 V = T.cross(U);
0037 
0038   RotationMatrix3 rframe;
0039   rframe << U, V, T;
0040   return rframe;
0041 }
0042 
0043 Transform3 CurvilinearSurface::transform() const {
0044   Transform3 transform = Transform3(referenceFrame());
0045   transform.pretranslate(center());
0046   return transform;
0047 }
0048 
0049 BoundToFreeMatrix CurvilinearSurface::boundToFreeJacobian() const {
0050   // this is copied from the `Surface::boundToFreeJacobian`
0051   // implementation without bounds check and definite direction
0052 
0053   // Initialize the jacobian from local to global
0054   BoundToFreeMatrix jacobian = BoundToFreeMatrix::Zero();
0055 
0056   // retrieve the reference frame
0057   const auto rframe = referenceFrame();
0058 
0059   // the local error components - given by reference frame
0060   jacobian.topLeftCorner<3, 2>() = rframe.topLeftCorner<3, 2>();
0061   // the time component
0062   jacobian(eFreeTime, eBoundTime) = 1;
0063   // the momentum components
0064   jacobian.block<3, 2>(eFreeDir0, eBoundPhi) =
0065       sphericalToFreeDirectionJacobian(m_direction);
0066   jacobian(eFreeQOverP, eBoundQOverP) = 1;
0067 
0068   return jacobian;
0069 }
0070 
0071 FreeToBoundMatrix CurvilinearSurface::freeToBoundJacobian() const {
0072   // this is copied from the `Surface::freeToBoundJacobian`
0073   // implementation without bounds check and definite direction
0074 
0075   // Initialize the jacobian from global to local
0076   FreeToBoundMatrix jacobian = FreeToBoundMatrix::Zero();
0077 
0078   // The measurement frame of the surface
0079   RotationMatrix3 rframeT = referenceFrame().transpose();
0080 
0081   // Local position component given by the reference frame
0082   jacobian.block<2, 3>(eBoundLoc0, eFreePos0) = rframeT.block<2, 3>(0, 0);
0083   // Time component
0084   jacobian(eBoundTime, eFreeTime) = 1;
0085   // Directional and momentum elements for reference frame surface
0086   jacobian.block<2, 3>(eBoundPhi, eFreeDir0) =
0087       freeToSphericalDirectionJacobian(m_direction);
0088   jacobian(eBoundQOverP, eFreeQOverP) = 1;
0089 
0090   return jacobian;
0091 }
0092 
0093 FreeToPathMatrix CurvilinearSurface::freeToPathDerivative() const {
0094   FreeToPathMatrix freeToPath = FreeToPathMatrix::Zero();
0095   freeToPath.segment<3>(eFreePos0) = -1.0 * m_direction;
0096   return freeToPath;
0097 }
0098 
0099 std::ostream& CurvilinearSurface::toStream(std::ostream& sl) const {
0100   sl << "Curvilinear Surface" << std::endl;
0101   sl << "     Center position  (x, y, z) = (" << m_position.x() << ", "
0102      << m_position.y() << ", " << m_position.z() << ")" << std::endl;
0103   sl << "     Direction  (x, y, z) = (" << m_direction.x() << ", "
0104      << m_direction.y() << ", " << m_direction.z() << ")" << std::endl;
0105   return sl;
0106 }
0107 
0108 std::string CurvilinearSurface::toString() const {
0109   std::stringstream ss;
0110   ss << std::setiosflags(std::ios::fixed);
0111   ss << std::setprecision(4);
0112   ss << std::boolalpha;
0113   toStream(ss);
0114   return ss.str();
0115 }
0116 
0117 std::shared_ptr<PlaneSurface> CurvilinearSurface::planeSurface() const {
0118   return Surface::makeShared<PlaneSurface>(transform());
0119 }
0120 
0121 std::shared_ptr<Surface> CurvilinearSurface::surface() const {
0122   return planeSurface();
0123 }
0124 
0125 std::ostream& operator<<(std::ostream& os, const CurvilinearSurface& surface) {
0126   return surface.toStream(os);
0127 }
0128 
0129 }  // namespace Acts