File indexing completed on 2025-01-18 09:11:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Propagator/detail/SympyCovarianceEngine.hpp"
0010
0011 #include "Acts/Propagator/detail/JacobianEngine.hpp"
0012 #include "Acts/Propagator/detail/SympyJacobianEngine.hpp"
0013
0014 #include "codegen/sympy_cov_math.hpp"
0015
0016 namespace Acts::detail {
0017
0018
0019 using Jacobian = BoundMatrix;
0020 using BoundState = std::tuple<BoundTrackParameters, Jacobian, double>;
0021 using CurvilinearState =
0022 std::tuple<CurvilinearTrackParameters, Jacobian, double>;
0023
0024 Result<BoundState> sympy::boundState(
0025 const GeometryContext& geoContext, const Surface& surface,
0026 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0027 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0028 BoundToFreeMatrix& boundToFreeJacobian, FreeVector& freeParameters,
0029 const ParticleHypothesis& particleHypothesis, bool covTransport,
0030 double accumulatedPath,
0031 const FreeToBoundCorrection& freeToBoundCorrection) {
0032
0033 Result<BoundVector> bv =
0034 transformFreeToBoundParameters(freeParameters, surface, geoContext);
0035 if (!bv.ok()) {
0036 return bv.error();
0037 }
0038
0039
0040 std::optional<BoundSquareMatrix> cov = std::nullopt;
0041 if (covTransport) {
0042
0043
0044
0045 transportCovarianceToBound(geoContext, surface, boundCovariance,
0046 fullTransportJacobian, freeTransportJacobian,
0047 freeToPathDerivatives, boundToFreeJacobian,
0048 freeParameters, freeToBoundCorrection);
0049 cov = boundCovariance;
0050 }
0051
0052
0053 return std::make_tuple(
0054 BoundTrackParameters(surface.getSharedPtr(), *bv, std::move(cov),
0055 particleHypothesis),
0056 fullTransportJacobian, accumulatedPath);
0057 }
0058
0059 CurvilinearState sympy::curvilinearState(
0060 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0061 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0062 BoundToFreeMatrix& boundToFreeJacobian, const FreeVector& freeParameters,
0063 const ParticleHypothesis& particleHypothesis, bool covTransport,
0064 double accumulatedPath) {
0065 const Vector3& direction = freeParameters.segment<3>(eFreeDir0);
0066
0067
0068 std::optional<BoundSquareMatrix> cov = std::nullopt;
0069 if (covTransport) {
0070
0071
0072
0073 transportCovarianceToCurvilinear(
0074 boundCovariance, fullTransportJacobian, freeTransportJacobian,
0075 freeToPathDerivatives, boundToFreeJacobian, direction);
0076 cov = boundCovariance;
0077 }
0078
0079
0080 Vector4 pos4 = Vector4::Zero();
0081 pos4[ePos0] = freeParameters[eFreePos0];
0082 pos4[ePos1] = freeParameters[eFreePos1];
0083 pos4[ePos2] = freeParameters[eFreePos2];
0084 pos4[eTime] = freeParameters[eFreeTime];
0085 CurvilinearTrackParameters curvilinearParams(
0086 pos4, direction, freeParameters[eFreeQOverP], std::move(cov),
0087 particleHypothesis);
0088
0089 return {std::move(curvilinearParams), fullTransportJacobian, accumulatedPath};
0090 }
0091
0092 void sympy::transportCovarianceToBound(
0093 const GeometryContext& geoContext, const Surface& surface,
0094 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0095 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0096 BoundToFreeMatrix& boundToFreeJacobian, FreeVector& freeParameters,
0097 const FreeToBoundCorrection& freeToBoundCorrection) {
0098
0099
0100 sympy::boundToBoundTransportJacobian(
0101 geoContext, surface, freeParameters, boundToFreeJacobian,
0102 freeTransportJacobian, freeToPathDerivatives, fullTransportJacobian);
0103
0104 bool correction = false;
0105 if (freeToBoundCorrection) {
0106 BoundToFreeMatrix startBoundToFinalFreeJacobian =
0107 freeTransportJacobian * boundToFreeJacobian;
0108 FreeSquareMatrix freeCovariance = startBoundToFinalFreeJacobian *
0109 boundCovariance *
0110 startBoundToFinalFreeJacobian.transpose();
0111
0112 auto transformer =
0113 detail::CorrectedFreeToBoundTransformer(freeToBoundCorrection);
0114 auto correctedRes =
0115 transformer(freeParameters, freeCovariance, surface, geoContext);
0116
0117 if (correctedRes.has_value()) {
0118 auto correctedValue = correctedRes.value();
0119 BoundVector boundParams = std::get<BoundVector>(correctedValue);
0120
0121 freeParameters =
0122 transformBoundToFreeParameters(surface, geoContext, boundParams);
0123
0124
0125 boundCovariance = std::get<BoundSquareMatrix>(correctedValue);
0126
0127 correction = true;
0128 }
0129 }
0130
0131 if (!correction) {
0132
0133
0134 BoundMatrix newBoundCovariance;
0135 transportCovarianceToBoundImpl(boundCovariance.data(),
0136 fullTransportJacobian.data(),
0137 newBoundCovariance.data());
0138 boundCovariance = newBoundCovariance;
0139 }
0140
0141
0142
0143
0144
0145 reinitializeJacobians(geoContext, surface, freeTransportJacobian,
0146 freeToPathDerivatives, boundToFreeJacobian,
0147 freeParameters);
0148 }
0149
0150 void sympy::transportCovarianceToCurvilinear(
0151 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0152 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0153 BoundToFreeMatrix& boundToFreeJacobian, const Vector3& direction) {
0154
0155
0156 sympy::boundToCurvilinearTransportJacobian(
0157 direction, boundToFreeJacobian, freeTransportJacobian,
0158 freeToPathDerivatives, fullTransportJacobian);
0159
0160
0161
0162 BoundMatrix newBoundCovariance;
0163 transportCovarianceToBoundImpl(boundCovariance.data(),
0164 fullTransportJacobian.data(),
0165 newBoundCovariance.data());
0166 boundCovariance = newBoundCovariance;
0167
0168
0169
0170
0171
0172
0173 reinitializeJacobians(freeTransportJacobian, freeToPathDerivatives,
0174 boundToFreeJacobian, direction);
0175 }
0176
0177 }