|
|
|||
File indexing completed on 2026-11-25 09:02:29
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 0013 #include <cmath> 0014 #include <optional> 0015 0016 namespace Acts::detail { 0017 0018 /// Predicted position and signed path before shape projection and bounds 0019 /// checks. 0020 /// Unlike Intersection3D, this intermediate result has no surface status: 0021 /// the position may still be off-surface and outside the physical bounds. 0022 struct CurvatureCorrection { 0023 /// Position before any cylinder projection. 0024 Vector3 position; 0025 /// Signed corrected path from the original starting point. 0026 double pathLength; 0027 }; 0028 0029 /// Reject near-tangent seeds: below this cosine, the normal equation can 0030 /// amplify displacement errors by more than 10^6. This is a conditioning guard. 0031 static constexpr double s_minCurvatureIncidence = 1e-6; 0032 /// Limit the estimated tangent change to 0.2 (~11 degrees for a circle). 0033 /// This keeps the frozen-curvature expansion local; it is not an error bound. 0034 static constexpr double s_maxCurvatureBend = 0.2; 0035 /// Limit the path adjustment to 20% of the ray path, keeping the prediction 0036 /// near its seed branch. This is a heuristic, not a calibrated accuracy cut. 0037 static constexpr double s_maxRelativeCurvaturePathShift = 0.2; 0038 0039 /// Compile-time selection for all curvature-aware surface intersections (and 0040 /// hence navigation). Changing this requires rebuilding the library. 0041 static constexpr bool s_useQuadraticCurvatureCorrection = false; 0042 0043 /// Local trajectory model: x(u) = x0 + u*t + u^2*k/2, with unit t and 0044 /// geometric curvature k = d^2 x / ds^2. The vector t is the starting track 0045 /// direction, not a direction along the surface. The total shift 0046 /// (s^2/2)*k + ds*t lies in the surface tangent plane. At y = x0 + s*t, 0047 /// write the corrected path as s + ds. To first order in k, 0048 /// 0049 /// x(s + ds) = y + (s^2/2)*k + ds*t + O(k^2), 0050 /// n.(x(s + ds) - y) = 0, 0051 /// ds = -(s^2/2)*(n.k)/(n.t). 0052 /// 0053 /// This drops s*ds*k and ds^2*k/2. It is a tangent-plane perturbation, not 0054 /// an exact helix intersection. The incidence, bend and relative path-shift 0055 /// guards below limit the perturbation; they do NOT bound its physical error. 0056 /// A scaled normal is allowed: normalScale is its length. For cylinders the 0057 /// radial seed vector can be used directly, cancelling the common 1/R factor 0058 /// in the ratio. All vectors must use the same coordinate frame. 0059 /// @tparam Quadratic Retain all local-parabola terms in the tangent-plane solve 0060 /// @param rayPathLength Signed ray path from the starting position to the seed 0061 /// @param rayPosition Ray intersection position, in the same frame as all vectors 0062 /// @param direction Unit track direction at the starting position 0063 /// @param curvature Starting geometric curvature d^2 x / ds^2 (inverse length) 0064 /// @param incidence n.dot(direction), using the possibly scaled surface normal n 0065 /// @param normalCurvature n.dot(curvature), using the same normal 0066 /// @param curvatureNorm Magnitude of curvature, reusable across both ray roots 0067 /// @param normalScale Magnitude of n (one for a unit normal) 0068 /// @return Prediction, or nullopt when the caller should retain the ray seed 0069 template <bool Quadratic = s_useQuadraticCurvatureCorrection> 0070 inline std::optional<CurvatureCorrection> correctCurvatureIntersection( 0071 double rayPathLength, const Vector3& rayPosition, const Vector3& direction, 0072 const Vector3& curvature, double incidence, double normalCurvature, 0073 double curvatureNorm, double normalScale = 1.) { 0074 if (std::abs(incidence) < s_minCurvatureIncidence * normalScale || 0075 std::abs(rayPathLength) * curvatureNorm > s_maxCurvatureBend) { 0076 return std::nullopt; 0077 } 0078 const double halfPathSquared = 0.5 * rayPathLength * rayPathLength; 0079 double ds = 0.; 0080 double displacementScale = halfPathSquared; 0081 if constexpr (Quadratic) { 0082 // With s = rayPathLength, retain s*ds*k and ds^2*k/2 in the parabola: 0083 // a*ds^2 + b*ds + c = 0, 0084 // a = n.k/2, b = n.t + s*n.k, c = (s^2/2)*n.k. 0085 // The rationalized root is continuous with ds = 0 as k -> 0. 0086 // A reversed slope or negative discriminant invalidates this branch. 0087 // This solves the seed tangent plane, not the full cylinder or helix. 0088 const double a = 0.5 * normalCurvature; 0089 const double b = incidence + rayPathLength * normalCurvature; 0090 const double c = halfPathSquared * normalCurvature; 0091 const double discriminant = b * b - 4. * a * c; 0092 if (discriminant < 0. || b * incidence <= 0.) { 0093 return std::nullopt; 0094 } 0095 ds = -2. * c / (b + std::copysign(std::sqrt(discriminant), b)); 0096 displacementScale = 0.5 * (rayPathLength + ds) * (rayPathLength + ds); 0097 } else { 0098 ds = -halfPathSquared * normalCurvature / incidence; 0099 } 0100 if (!std::isfinite(ds) || std::abs(ds) > s_maxRelativeCurvaturePathShift * 0101 std::abs(rayPathLength)) { 0102 return std::nullopt; 0103 } 0104 const Vector3 point = 0105 rayPosition + displacementScale * curvature + ds * direction; 0106 if (!point.allFinite()) { 0107 return std::nullopt; 0108 } 0109 return CurvatureCorrection{point, rayPathLength + ds}; 0110 } 0111 0112 } // namespace Acts::detail
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|