Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-20 09:26:07

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 #include "Acts/Vertexing/NumericalTrackLinearizer.hpp"
0010 
0011 #include "Acts/MagneticField/MagneticFieldQuery.hpp"
0012 #include "Acts/Propagator/PropagatorOptions.hpp"
0013 #include "Acts/Propagator/detail/DirectionToSurface.hpp"
0014 #include "Acts/Utilities/UnitVectors.hpp"
0015 #include "Acts/Vertexing/LinearizerTrackParameters.hpp"
0016 
0017 #include <numbers>
0018 
0019 Acts::Result<Acts::LinearizedTrack>
0020 Acts::NumericalTrackLinearizer::linearizeTrack(
0021     const BoundTrackParameters& params, double linPointTime,
0022     const Surface& perigeeSurface, const GeometryContext& gctx,
0023     MagneticFieldQuery& fieldQuery) const {
0024   // Create propagator options
0025   PropagatorPlainOptions pOptions(gctx, fieldQuery.context());
0026 
0027   // Length scale at which we consider to be sufficiently close to the Perigee
0028   // surface to skip the propagation.
0029   pOptions.surfaceTolerance = m_cfg.targetTolerance;
0030 
0031   pOptions.direction = detail::directionToSurface(
0032       gctx, perigeeSurface, params.position(gctx), params.direction());
0033 
0034   // Propagate to the PCA of the reference point
0035   auto result =
0036       m_cfg.propagator->propagateToSurface(params, perigeeSurface, pOptions);
0037   if (!result.ok()) {
0038     return result.error();
0039   }
0040 
0041   // Extracting the Perigee representation of the track wrt the reference point
0042   auto endParams = *result;
0043   BoundVector perigeeParams = endParams.parameters();
0044 
0045   // Covariance and weight matrix at the PCA to the reference point
0046   BoundMatrix parCovarianceAtPCA = endParams.covariance().value();
0047   BoundMatrix weightAtPCA = parCovarianceAtPCA.inverse();
0048 
0049   // Vector containing the track parameters at the PCA
0050   // Note that we parametrize the track using the following parameters:
0051   // (x, y, z, t, phi, theta, q/p),
0052   // where
0053   // -) (x, y, z, t) is the global 4D position of the PCA
0054   // -) phi and theta are the global angles of the momentum at the PCA
0055   // -) q/p is the charge divided by the total momentum at the PCA
0056   Acts::Vector<eLinSize> paramVec;
0057 
0058   // 4D PCA and the momentum of the track at the PCA
0059   // These quantities will be used in the computation of the constant term in
0060   // the Taylor expansion
0061   Vector4 pca;
0062   Vector3 momentumAtPCA;
0063 
0064   // Fill "paramVec", "pca", and "momentumAtPCA"
0065   {
0066     Vector3 globalCoords = endParams.position(gctx);
0067     double globalTime = endParams.time();
0068     double phi = perigeeParams(BoundIndices::eBoundPhi);
0069     double theta = perigeeParams(BoundIndices::eBoundTheta);
0070     double qOvP = perigeeParams(BoundIndices::eBoundQOverP);
0071 
0072     paramVec.head<3>() = globalCoords;
0073     paramVec[eLinTime] = globalTime;
0074     paramVec[eLinPhi] = phi;
0075     paramVec[eLinTheta] = theta;
0076     paramVec[eLinQOverP] = qOvP;
0077     pca.head<3>() = globalCoords;
0078     pca[eTime] = globalTime;
0079     momentumAtPCA << phi, theta, qOvP;
0080   }
0081 
0082   // Complete Jacobian (consists of positionJacobian and momentumJacobian)
0083   Matrix<eBoundSize, eLinSize> completeJacobian =
0084       Matrix<eBoundSize, eLinSize>::Zero(eBoundSize, eLinSize);
0085 
0086   // Perigee parameters wrt the reference point after wiggling
0087   BoundVector newPerigeeParams;
0088 
0089   // Check if wiggled angle theta are within definition range [0, pi]
0090   if (paramVec(eLinTheta) + m_cfg.delta > std::numbers::pi) {
0091     ACTS_ERROR(
0092         "Wiggled theta outside range, choose a smaller wiggle (i.e., delta)! "
0093         "You might need to decrease targetTolerance as well.");
0094   }
0095 
0096   // Wiggling each of the parameters at the PCA and computing the Perigee
0097   // parametrization of the resulting new track. This allows us to approximate
0098   // the numerical derivatives.
0099   for (unsigned int i = 0; i < eLinSize; i++) {
0100     Acts::Vector<eLinSize> paramVecCopy = paramVec;
0101     // Wiggle
0102     paramVecCopy(i) += m_cfg.delta;
0103 
0104     // Create curvilinear track object from our parameters. This is needed for
0105     // the propagation. Note that we work without covariance since we don't need
0106     // it to compute the derivative.
0107     Vector3 wiggledDir = makeDirectionFromPhiTheta(paramVecCopy(eLinPhi),
0108                                                    paramVecCopy(eLinTheta));
0109     // Since we work in 4D we have eLinPosSize = 4
0110     BoundTrackParameters wiggledCurvilinearParams =
0111         BoundTrackParameters::createCurvilinear(
0112             paramVecCopy.template head<eLinPosSize>(), wiggledDir,
0113             paramVecCopy(eLinQOverP), std::nullopt, ParticleHypothesis::pion());
0114 
0115     // Obtain propagation direction
0116     pOptions.direction = detail::directionToSurface(
0117         gctx, perigeeSurface, paramVecCopy.template head<3>(), wiggledDir);
0118 
0119     // Propagate to the new PCA and extract Perigee parameters
0120     auto newResult = m_cfg.propagator->propagateToSurface(
0121         wiggledCurvilinearParams, perigeeSurface, pOptions);
0122     if (!newResult.ok()) {
0123       return newResult.error();
0124     }
0125     newPerigeeParams = newResult->parameters();
0126 
0127     // Computing the numerical derivatives and filling the Jacobian
0128     completeJacobian.array().col(i) =
0129         (newPerigeeParams - perigeeParams) / m_cfg.delta;
0130     // We need to account for the periodicity of phi. We overwrite the
0131     // previously computed value for better readability.
0132     completeJacobian(eLinPhi, i) =
0133         Acts::detail::difference_periodic(newPerigeeParams(eLinPhi),
0134                                           perigeeParams(eLinPhi),
0135                                           2 * std::numbers::pi) /
0136         m_cfg.delta;
0137   }
0138 
0139   // Extracting positionJacobian and momentumJacobian from the complete Jacobian
0140   Matrix<eBoundSize, eLinPosSize> positionJacobian =
0141       completeJacobian.block<eBoundSize, eLinPosSize>(0, 0);
0142   Matrix<eBoundSize, eLinMomSize> momentumJacobian =
0143       completeJacobian.block<eBoundSize, eLinMomSize>(0, eLinPosSize);
0144 
0145   // Constant term of Taylor expansion (Eq. 5.38 in Ref. (1))
0146   BoundVector constTerm =
0147       perigeeParams - positionJacobian * pca - momentumJacobian * momentumAtPCA;
0148 
0149   Vector4 linPoint;
0150   linPoint.head<3>() = perigeeSurface.center(gctx);
0151   linPoint[3] = linPointTime;
0152 
0153   return LinearizedTrack(perigeeParams, parCovarianceAtPCA, weightAtPCA,
0154                          linPoint, positionJacobian, momentumJacobian, pca,
0155                          momentumAtPCA, constTerm);
0156 }