File indexing completed on 2025-08-06 08:10:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Propagator/detail/CovarianceEngine.hpp"
0010
0011 #include "Acts/Definitions/Common.hpp"
0012 #include "Acts/Definitions/Tolerance.hpp"
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/EventData/GenericBoundTrackParameters.hpp"
0015 #include "Acts/EventData/GenericCurvilinearTrackParameters.hpp"
0016 #include "Acts/EventData/TransformationHelpers.hpp"
0017 #include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
0018 #include "Acts/Propagator/detail/JacobianEngine.hpp"
0019 #include "Acts/Utilities/AlgebraHelpers.hpp"
0020 #include "Acts/Utilities/JacobianHelpers.hpp"
0021 #include "Acts/Utilities/Result.hpp"
0022
0023 #include <optional>
0024 #include <system_error>
0025 #include <utility>
0026
0027 namespace Acts {
0028
0029
0030 using Jacobian = BoundMatrix;
0031 using BoundState = std::tuple<BoundTrackParameters, Jacobian, double>;
0032 using CurvilinearState =
0033 std::tuple<CurvilinearTrackParameters, Jacobian, double>;
0034
0035 Result<BoundState> detail::boundState(
0036 const GeometryContext& geoContext, const Surface& surface,
0037 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0038 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0039 BoundToFreeMatrix& boundToFreeJacobian, FreeVector& freeParameters,
0040 const ParticleHypothesis& particleHypothesis, bool covTransport,
0041 double accumulatedPath,
0042 const FreeToBoundCorrection& freeToBoundCorrection) {
0043
0044 Result<BoundVector> bv =
0045 transformFreeToBoundParameters(freeParameters, surface, geoContext);
0046 if (!bv.ok()) {
0047 return bv.error();
0048 }
0049
0050
0051 std::optional<BoundSquareMatrix> cov = std::nullopt;
0052 if (covTransport) {
0053
0054
0055
0056 transportCovarianceToBound(geoContext, surface, boundCovariance,
0057 fullTransportJacobian, freeTransportJacobian,
0058 freeToPathDerivatives, boundToFreeJacobian,
0059 freeParameters, freeToBoundCorrection);
0060 cov = boundCovariance;
0061 }
0062
0063
0064 return std::make_tuple(
0065 BoundTrackParameters(surface.getSharedPtr(), *bv, std::move(cov),
0066 particleHypothesis),
0067 fullTransportJacobian, accumulatedPath);
0068 }
0069
0070 CurvilinearState detail::curvilinearState(
0071 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0072 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0073 BoundToFreeMatrix& boundToFreeJacobian, const FreeVector& freeParameters,
0074 const ParticleHypothesis& particleHypothesis, bool covTransport,
0075 double accumulatedPath) {
0076 const Vector3& direction = freeParameters.segment<3>(eFreeDir0);
0077
0078
0079 std::optional<BoundSquareMatrix> cov = std::nullopt;
0080 if (covTransport) {
0081
0082
0083
0084 transportCovarianceToCurvilinear(
0085 boundCovariance, fullTransportJacobian, freeTransportJacobian,
0086 freeToPathDerivatives, boundToFreeJacobian, direction);
0087 cov = boundCovariance;
0088 }
0089
0090
0091 Vector4 pos4 = Vector4::Zero();
0092 pos4[ePos0] = freeParameters[eFreePos0];
0093 pos4[ePos1] = freeParameters[eFreePos1];
0094 pos4[ePos2] = freeParameters[eFreePos2];
0095 pos4[eTime] = freeParameters[eFreeTime];
0096 CurvilinearTrackParameters curvilinearParams(
0097 pos4, direction, freeParameters[eFreeQOverP], std::move(cov),
0098 particleHypothesis);
0099
0100 return std::make_tuple(std::move(curvilinearParams), fullTransportJacobian,
0101 accumulatedPath);
0102 }
0103
0104 void detail::transportCovarianceToBound(
0105 const GeometryContext& geoContext, const Surface& surface,
0106 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0107 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0108 BoundToFreeMatrix& boundToFreeJacobian, FreeVector& freeParameters,
0109 const FreeToBoundCorrection& freeToBoundCorrection) {
0110
0111
0112 boundToBoundTransportJacobian(geoContext, surface, freeParameters,
0113 boundToFreeJacobian, freeTransportJacobian,
0114 freeToPathDerivatives, fullTransportJacobian);
0115
0116 bool correction = false;
0117 if (freeToBoundCorrection) {
0118 BoundToFreeMatrix startBoundToFinalFreeJacobian =
0119 freeTransportJacobian * boundToFreeJacobian;
0120 FreeSquareMatrix freeCovariance = startBoundToFinalFreeJacobian *
0121 boundCovariance *
0122 startBoundToFinalFreeJacobian.transpose();
0123
0124 auto transformer =
0125 detail::CorrectedFreeToBoundTransformer(freeToBoundCorrection);
0126 auto correctedRes =
0127 transformer(freeParameters, freeCovariance, surface, geoContext);
0128
0129 if (correctedRes.has_value()) {
0130 auto correctedValue = correctedRes.value();
0131 BoundVector boundParams = std::get<BoundVector>(correctedValue);
0132
0133 freeParameters =
0134 transformBoundToFreeParameters(surface, geoContext, boundParams);
0135
0136
0137 boundCovariance = std::get<BoundSquareMatrix>(correctedValue);
0138
0139 correction = true;
0140 }
0141 }
0142
0143 if (!correction) {
0144
0145
0146 boundCovariance = fullTransportJacobian * boundCovariance *
0147 fullTransportJacobian.transpose();
0148 }
0149
0150
0151
0152
0153
0154 reinitializeJacobians(geoContext, surface, freeTransportJacobian,
0155 freeToPathDerivatives, boundToFreeJacobian,
0156 freeParameters);
0157 }
0158
0159 void detail::transportCovarianceToCurvilinear(
0160 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0161 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0162 BoundToFreeMatrix& boundToFreeJacobian, const Vector3& direction) {
0163
0164
0165 boundToCurvilinearTransportJacobian(
0166 direction, boundToFreeJacobian, freeTransportJacobian,
0167 freeToPathDerivatives, fullTransportJacobian);
0168
0169
0170
0171 boundCovariance = fullTransportJacobian * boundCovariance *
0172 fullTransportJacobian.transpose();
0173
0174
0175
0176
0177
0178
0179 reinitializeJacobians(freeTransportJacobian, freeToPathDerivatives,
0180 boundToFreeJacobian, direction);
0181 }
0182
0183 Acts::Result<Acts::BoundTrackParameters> detail::boundToBoundConversion(
0184 const GeometryContext& gctx, const BoundTrackParameters& boundParameters,
0185 const Surface& targetSurface, const Vector3& bField) {
0186 const auto& sourceSurface = boundParameters.referenceSurface();
0187
0188 Acts::FreeVector freePars = Acts::transformBoundToFreeParameters(
0189 sourceSurface, gctx, boundParameters.parameters());
0190
0191 auto res =
0192 Acts::transformFreeToBoundParameters(freePars, targetSurface, gctx);
0193
0194 if (!res.ok()) {
0195 return res.error();
0196 }
0197 Acts::BoundVector parOut = *res;
0198
0199 std::optional<Acts::BoundMatrix> covOut = std::nullopt;
0200
0201 if (boundParameters.covariance().has_value()) {
0202 Acts::BoundToFreeMatrix boundToFreeJacobian =
0203 sourceSurface.boundToFreeJacobian(gctx, freePars.segment<3>(eFreePos0),
0204 freePars.segment<3>(eFreeDir0));
0205
0206 Acts::FreeMatrix freeTransportJacobian = FreeMatrix::Identity();
0207
0208 FreeVector freeToPathDerivatives = FreeVector::Zero();
0209 freeToPathDerivatives.head<3>() = freePars.segment<3>(eFreeDir0);
0210
0211 freeToPathDerivatives.segment<3>(eFreeDir0) =
0212 bField.cross(freePars.segment<3>(eFreeDir0));
0213
0214 BoundMatrix boundToBoundJac;
0215 detail::boundToBoundTransportJacobian(
0216 gctx, targetSurface, freePars, boundToFreeJacobian,
0217 freeTransportJacobian, freeToPathDerivatives, boundToBoundJac);
0218
0219 covOut = boundToBoundJac * (*boundParameters.covariance()) *
0220 boundToBoundJac.transpose();
0221 }
0222
0223 return Acts::BoundTrackParameters{targetSurface.getSharedPtr(), parOut,
0224 covOut,
0225 boundParameters.particleHypothesis()};
0226 }
0227
0228 }