File indexing completed on 2025-07-13 07:50:39
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Propagator/detail/SympyCovarianceEngine.hpp"
0010
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/Propagator/detail/JacobianEngine.hpp"
0013 #include "Acts/Propagator/detail/SympyJacobianEngine.hpp"
0014
0015 #include "codegen/sympy_cov_math.hpp"
0016
0017 namespace Acts::detail {
0018
0019
0020 using Jacobian = BoundMatrix;
0021 using BoundState = std::tuple<BoundTrackParameters, Jacobian, double>;
0022
0023 Result<BoundState> sympy::boundState(
0024 const GeometryContext& geoContext, const Surface& surface,
0025 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0026 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0027 BoundToFreeMatrix& boundToFreeJacobian,
0028 const std::optional<FreeMatrix>& additionalFreeCovariance,
0029 FreeVector& freeParameters, const ParticleHypothesis& particleHypothesis,
0030 bool covTransport, 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(
0046 geoContext, surface, boundCovariance, fullTransportJacobian,
0047 freeTransportJacobian, freeToPathDerivatives, boundToFreeJacobian,
0048 additionalFreeCovariance, 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 BoundState sympy::curvilinearState(
0060 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0061 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0062 BoundToFreeMatrix& boundToFreeJacobian,
0063 const std::optional<FreeMatrix>& additionalFreeCovariance,
0064 const FreeVector& freeParameters,
0065 const ParticleHypothesis& particleHypothesis, bool covTransport,
0066 double accumulatedPath) {
0067 const Vector3& direction = freeParameters.segment<3>(eFreeDir0);
0068
0069
0070 std::optional<BoundSquareMatrix> cov = std::nullopt;
0071 if (covTransport) {
0072
0073
0074
0075 transportCovarianceToCurvilinear(boundCovariance, fullTransportJacobian,
0076 freeTransportJacobian,
0077 freeToPathDerivatives, boundToFreeJacobian,
0078 additionalFreeCovariance, direction);
0079 cov = boundCovariance;
0080 }
0081
0082
0083 Vector4 pos4 = Vector4::Zero();
0084 pos4[ePos0] = freeParameters[eFreePos0];
0085 pos4[ePos1] = freeParameters[eFreePos1];
0086 pos4[ePos2] = freeParameters[eFreePos2];
0087 pos4[eTime] = freeParameters[eFreeTime];
0088 BoundTrackParameters curvilinearParams =
0089 BoundTrackParameters::createCurvilinear(
0090 pos4, direction, freeParameters[eFreeQOverP], std::move(cov),
0091 particleHypothesis);
0092
0093 return {std::move(curvilinearParams), fullTransportJacobian, accumulatedPath};
0094 }
0095
0096 void sympy::transportCovarianceToBound(
0097 const GeometryContext& geoContext, const Surface& surface,
0098 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0099 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0100 BoundToFreeMatrix& boundToFreeJacobian,
0101 const std::optional<FreeMatrix>& additionalFreeCovariance,
0102 FreeVector& freeParameters,
0103 const FreeToBoundCorrection& freeToBoundCorrection) {
0104 FreeToBoundMatrix freeToBoundJacobian;
0105
0106
0107
0108 sympy::boundToBoundTransportJacobian(
0109 geoContext, surface, freeParameters, boundToFreeJacobian,
0110 freeTransportJacobian, freeToBoundJacobian, freeToPathDerivatives,
0111 fullTransportJacobian);
0112
0113 bool correction = false;
0114 if (freeToBoundCorrection) {
0115 BoundToFreeMatrix startBoundToFinalFreeJacobian =
0116 freeTransportJacobian * boundToFreeJacobian;
0117 FreeSquareMatrix freeCovariance = startBoundToFinalFreeJacobian *
0118 boundCovariance *
0119 startBoundToFinalFreeJacobian.transpose();
0120
0121 auto transformer =
0122 detail::CorrectedFreeToBoundTransformer(freeToBoundCorrection);
0123 auto correctedRes =
0124 transformer(freeParameters, freeCovariance, surface, geoContext);
0125
0126 if (correctedRes.has_value()) {
0127 auto correctedValue = correctedRes.value();
0128 BoundVector boundParams = std::get<BoundVector>(correctedValue);
0129
0130 freeParameters =
0131 transformBoundToFreeParameters(surface, geoContext, boundParams);
0132
0133
0134 boundCovariance = std::get<BoundSquareMatrix>(correctedValue);
0135
0136 correction = true;
0137 }
0138 }
0139
0140 if (!correction) {
0141
0142
0143 BoundMatrix newBoundCovariance;
0144 transportCovarianceToBoundImpl(boundCovariance.data(),
0145 fullTransportJacobian.data(),
0146 newBoundCovariance.data());
0147 boundCovariance = newBoundCovariance;
0148 }
0149
0150 if (additionalFreeCovariance) {
0151 boundCovariance += freeToBoundJacobian * (*additionalFreeCovariance) *
0152 freeToBoundJacobian.transpose();
0153 }
0154
0155
0156
0157
0158
0159 reinitializeJacobians(geoContext, surface, freeTransportJacobian,
0160 freeToPathDerivatives, boundToFreeJacobian,
0161 freeParameters);
0162 }
0163
0164 void sympy::transportCovarianceToCurvilinear(
0165 BoundSquareMatrix& boundCovariance, BoundMatrix& fullTransportJacobian,
0166 FreeMatrix& freeTransportJacobian, FreeVector& freeToPathDerivatives,
0167 BoundToFreeMatrix& boundToFreeJacobian,
0168 const std::optional<FreeMatrix>& additionalFreeCovariance,
0169 const Vector3& direction) {
0170 FreeToBoundMatrix freeToBoundJacobian;
0171
0172
0173
0174 sympy::boundToCurvilinearTransportJacobian(
0175 direction, boundToFreeJacobian, freeTransportJacobian,
0176 freeToBoundJacobian, freeToPathDerivatives, fullTransportJacobian);
0177
0178
0179
0180 BoundMatrix newBoundCovariance;
0181 transportCovarianceToBoundImpl(boundCovariance.data(),
0182 fullTransportJacobian.data(),
0183 newBoundCovariance.data());
0184 boundCovariance = newBoundCovariance;
0185
0186 if (additionalFreeCovariance) {
0187 boundCovariance += freeToBoundJacobian * (*additionalFreeCovariance) *
0188 freeToBoundJacobian.transpose();
0189 }
0190
0191
0192
0193
0194
0195
0196 reinitializeJacobians(freeTransportJacobian, freeToPathDerivatives,
0197 boundToFreeJacobian, direction);
0198 }
0199
0200 }