Back to home page

EIC code displayed by LXR

 
 

    


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

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