24 #include <system_error>
25 #include <type_traits>
33 using BoundState = std::tuple<BoundTrackParameters, Jacobian, double>;
34 using CurvilinearState =
35 std::tuple<CurvilinearTrackParameters, Jacobian, double>;
44 const double x = direction(0);
45 const double y = direction(1);
46 const double z = direction(2);
48 const double cosTheta =
z;
49 const double sinTheta = std::hypot(x, y);
50 const double invSinTheta = 1. / sinTheta;
51 const double cosPhi = x * invSinTheta;
52 const double sinPhi = y * invSinTheta;
57 jacToCurv(0, 0) = -sinPhi;
58 jacToCurv(0, 1) = cosPhi;
59 jacToCurv(1, 0) = -cosPhi * cosTheta;
60 jacToCurv(1, 1) = -sinPhi * cosTheta;
61 jacToCurv(1, 2) = sinTheta;
65 const double c = std::hypot(y, z);
66 const double invC = 1. /
c;
67 jacToCurv(0, 1) = -z * invC;
68 jacToCurv(0, 2) = y * invC;
70 jacToCurv(1, 1) = -x * y * invC;
71 jacToCurv(1, 2) = -x * z * invC;
76 jacToCurv(2, 4) = -sinPhi * invSinTheta;
77 jacToCurv(2, 5) = cosPhi * invSinTheta;
78 jacToCurv(3, 4) = cosPhi * cosTheta;
79 jacToCurv(3, 5) = sinPhi * cosTheta;
80 jacToCurv(3, 6) = -sinTheta;
117 surface.freeToPathDerivative(geoContext, freeParameters);
120 surface.freeToBoundJacobian(geoContext, freeParameters);
125 fullTransportJacobian =
126 freeToBoundJacobian *
127 (FreeMatrix::Identity() + freeToPathDerivatives * freeToPath) *
128 freeTransportJacobian * boundToFreeJacobian;
153 void boundToCurvilinearJacobian(
const Vector3& direction,
163 freeToBoundJacobian.topLeftCorner<6, 3>() +=
164 (freeToBoundJacobian * freeToPathDerivatives) *
165 (-1.0 * direction).transpose();
171 fullTransportJacobian =
173 blockedMult(freeTransportJacobian, boundToFreeJacobian));
198 freeTransportJacobian = FreeMatrix::Identity();
199 freeToPathDerivatives = FreeVector::Zero();
204 auto lpResult = surface.globalToLocal(geoContext, position, direction);
205 if (not lpResult.ok()) {
206 return lpResult.error();
210 freeParameters, surface, geoContext);
211 if (!boundParameters.ok()) {
212 return boundParameters.error();
215 boundToFreeJacobian =
216 surface.boundToFreeJacobian(geoContext, *boundParameters);
217 return Result<void>::success();
230 void reinitializeJacobians(
FreeMatrix& freeTransportJacobian,
235 freeTransportJacobian = FreeMatrix::Identity();
236 freeToPathDerivatives = FreeVector::Zero();
237 boundToFreeJacobian = BoundToFreeMatrix::Zero();
240 const double x = direction(0);
241 const double y = direction(1);
242 const double z = direction(2);
244 const double cosTheta =
z;
245 const double sinTheta = std::hypot(x, y);
246 const double invSinTheta = 1. / sinTheta;
247 const double cosPhi = x * invSinTheta;
248 const double sinPhi = y * invSinTheta;
272 bool covTransport,
double accumulatedPath,
const Surface& surface,
275 std::optional<BoundSquareMatrix>
cov = std::nullopt;
278 jacobian = BoundMatrix::Identity();
283 transportJacobian, derivatives, jacToGlobal,
284 parameters, surface, freeToBoundCorrection);
286 if (covarianceMatrix != BoundSquareMatrix::Zero()) {
287 cov = covarianceMatrix;
300 jacobian, accumulatedPath);
310 bool covTransport,
double accumulatedPath) {
314 std::optional<BoundSquareMatrix>
cov = std::nullopt;
317 jacobian = BoundMatrix::Identity();
322 transportJacobian, derivatives,
323 jacToGlobal, direction);
325 if (covarianceMatrix != BoundSquareMatrix::Zero()) {
326 cov = covarianceMatrix;
351 boundToBoundJacobian(geoContext, freeParameters, boundToFreeJacobian,
352 freeTransportJacobian, freeToPathDerivatives,
353 fullTransportJacobian, surface);
355 bool correction =
false;
356 if (freeToBoundCorrection) {
358 freeTransportJacobian * boundToFreeJacobian;
361 startBoundToFinalFreeJacobian.transpose();
366 transformer(freeParameters, freeCovariance, surface, geoContext);
368 if (correctedRes.has_value()) {
369 auto correctedValue = correctedRes.value();
370 BoundVector boundParams = std::get<BoundVector>(correctedValue);
373 surface, geoContext, boundParams);
376 boundCovariance = std::get<BoundSquareMatrix>(correctedValue);
382 if (not correction) {
385 boundCovariance = fullTransportJacobian * boundCovariance *
386 fullTransportJacobian.transpose();
393 reinitializeJacobians(geoContext, freeTransportJacobian,
394 freeToPathDerivatives, boundToFreeJacobian,
395 freeParameters, surface);
406 boundToCurvilinearJacobian(direction, boundToFreeJacobian,
407 freeTransportJacobian, freeToPathDerivatives,
408 fullTransportJacobian);
412 boundCovariance = fullTransportJacobian * boundCovariance *
413 fullTransportJacobian.transpose();
420 reinitializeJacobians(freeTransportJacobian, freeToPathDerivatives,
421 boundToFreeJacobian, direction);