File indexing completed on 2026-12-05 09:51:56
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/EventData/BoundTrackParameters.hpp"
0016 #include "Acts/EventData/TransformationHelpers.hpp"
0017 #include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
0018 #include "Acts/Geometry/GeometryContext.hpp"
0019 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0020 #include "Acts/Propagator/ConstrainedStep.hpp"
0021 #include "Acts/Propagator/EigenStepperError.hpp"
0022 #include "Acts/Propagator/NavigationTarget.hpp"
0023 #include "Acts/Propagator/StepperOptions.hpp"
0024 #include "Acts/Propagator/StepperStatistics.hpp"
0025 #include "Acts/Propagator/detail/SteppingHelper.hpp"
0026 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0027 #include "Acts/Surfaces/CurvilinearSurface.hpp"
0028 #include "Acts/Surfaces/Surface.hpp"
0029 #include "Acts/Surfaces/SurfaceError.hpp"
0030 #include "Acts/Utilities/Intersection.hpp"
0031 #include "Acts/Utilities/MathHelpers.hpp"
0032 #include "Acts/Utilities/Result.hpp"
0033
0034 #include <algorithm>
0035 #include <array>
0036 #include <cmath>
0037 #include <cstdint>
0038 #include <memory>
0039 #include <optional>
0040 #include <stdexcept>
0041 #include <string>
0042 #include <utility>
0043
0044 namespace Acts {
0045
0046 class IVolumeMaterial;
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 class AtlasStepper {
0062 public:
0063
0064 using BoundParameters = BoundTrackParameters;
0065
0066 using Jacobian = BoundMatrix;
0067
0068 using Covariance = BoundMatrix;
0069
0070
0071 struct Config {
0072
0073 std::shared_ptr<const MagneticFieldProvider> bField;
0074 };
0075
0076
0077 struct Options : public StepperPlainOptions {
0078
0079
0080
0081 Options(const GeometryContext& gctx, const MagneticFieldContext& mctx)
0082 : StepperPlainOptions(gctx, mctx) {}
0083
0084
0085
0086 void setPlainOptions(const StepperPlainOptions& options) {
0087 static_cast<StepperPlainOptions&>(*this) = options;
0088 }
0089 };
0090
0091
0092 struct State {
0093
0094
0095
0096
0097 State(const Options& optionsIn, MagneticFieldProvider::Cache fieldCacheIn)
0098 : options(optionsIn), fieldCache(std::move(fieldCacheIn)) {}
0099
0100
0101 Options options;
0102
0103
0104 ParticleHypothesis particleHypothesis = ParticleHypothesis::pion();
0105
0106
0107 bool newField = true;
0108
0109 Vector3 field = Vector3::Zero();
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126 std::array<double, 60> pVector{};
0127
0128
0129 bool derivativeReady = false;
0130
0131
0132
0133 std::optional<Covariance> cov;
0134
0135
0136 double pathAccumulated = 0.;
0137
0138
0139 std::size_t nSteps = 0;
0140
0141
0142 ConstrainedStep stepSize;
0143
0144
0145 double previousStepSize = 0.;
0146
0147
0148
0149 MagneticFieldProvider::Cache fieldCache;
0150
0151
0152 StepperStatistics statistics;
0153 };
0154
0155
0156
0157 explicit AtlasStepper(std::shared_ptr<const MagneticFieldProvider> bField)
0158 : m_bField(std::move(bField)) {}
0159
0160
0161
0162 explicit AtlasStepper(const Config& config) : m_bField(config.bField) {}
0163
0164
0165
0166
0167 State makeState(const Options& options) const {
0168 State state{options, m_bField->makeCache(options.magFieldContext)};
0169 return state;
0170 }
0171
0172
0173
0174
0175 void initialize(State& state, const BoundParameters& par) const {
0176 initialize(state, par.parameters(), par.covariance(),
0177 par.particleHypothesis(), par.referenceSurface());
0178 }
0179
0180
0181
0182
0183
0184
0185
0186 void initialize(State& state, const BoundVector& boundParams,
0187 const std::optional<BoundMatrix>& cov,
0188 ParticleHypothesis particleHypothesis,
0189 const Surface& surface) const {
0190 state.particleHypothesis = particleHypothesis;
0191
0192 state.pathAccumulated = 0;
0193 state.nSteps = 0;
0194 state.stepSize = ConstrainedStep();
0195 state.stepSize.setAccuracy(state.options.initialStepSize);
0196 state.stepSize.setUser(state.options.maxStepSize);
0197 state.previousStepSize = 0;
0198 state.statistics = StepperStatistics();
0199
0200 const FreeVector freeParams = transformBoundToFreeParameters(
0201 surface, state.options.geoContext, boundParams);
0202 update(state, freeParams.segment<3>(eFreePos0),
0203 freeParams.segment<3>(eFreeDir0), freeParams[eFreeQOverP],
0204 freeParams[eFreeTime]);
0205 state.cov = cov;
0206 resetJacobian(state, surface);
0207 }
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217 Result<Vector3> getField(State& state, const Vector3& pos) const {
0218 return m_bField->getField(pos, state.fieldCache);
0219 }
0220
0221
0222
0223
0224
0225 Result<Vector3> curvature(State& state) const {
0226 return detail::magneticCurvature(*this, state);
0227 }
0228
0229
0230
0231
0232 Vector3 position(const State& state) const {
0233 return Vector3(state.pVector[0], state.pVector[1], state.pVector[2]);
0234 }
0235
0236
0237
0238
0239 Vector3 direction(const State& state) const {
0240 return Vector3(state.pVector[4], state.pVector[5], state.pVector[6]);
0241 }
0242
0243
0244
0245
0246 double qOverP(const State& state) const { return state.pVector[7]; }
0247
0248
0249
0250
0251
0252 double absoluteMomentum(const State& state) const {
0253 return particleHypothesis(state).extractMomentum(qOverP(state));
0254 }
0255
0256
0257
0258
0259 Vector3 momentum(const State& state) const {
0260 return absoluteMomentum(state) * direction(state);
0261 }
0262
0263
0264
0265
0266
0267 double charge(const State& state) const {
0268 return particleHypothesis(state).extractCharge(qOverP(state));
0269 }
0270
0271
0272
0273
0274
0275 const ParticleHypothesis& particleHypothesis(const State& state) const {
0276 return state.particleHypothesis;
0277 }
0278
0279
0280
0281 double overstepLimit(const State& ) const {
0282 return -m_overstepLimit;
0283 }
0284
0285
0286
0287
0288 double time(const State& state) const { return state.pVector[3]; }
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307 IntersectionStatus updateSurfaceStatus(
0308 State& state, const Surface& surface, std::uint8_t index,
0309 Direction navDir, const BoundaryTolerance& boundaryTolerance,
0310 double surfaceTolerance, ConstrainedStep::Type stype,
0311 const Logger& logger = getDummyLogger(),
0312 const Vector3& curvature = Vector3::Zero()) const {
0313 return detail::updateSingleSurfaceStatus<AtlasStepper>(
0314 *this, state, surface, index, navDir, boundaryTolerance,
0315 surfaceTolerance, stype, logger, curvature);
0316 }
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327 void updateStepSize(State& state, const NavigationTarget& target,
0328 Direction direction, ConstrainedStep::Type stype) const {
0329 static_cast<void>(direction);
0330 double stepSize = target.pathLength();
0331 updateStepSize(state, stepSize, stype);
0332 }
0333
0334
0335
0336
0337
0338
0339 void updateStepSize(State& state, double stepSize,
0340 ConstrainedStep::Type stype) const {
0341 state.previousStepSize = state.stepSize.value();
0342 state.stepSize.update(stepSize, stype);
0343 }
0344
0345
0346
0347
0348
0349 void releaseStepSize(State& state, ConstrainedStep::Type stype) const {
0350 state.stepSize.release(stype);
0351 }
0352
0353
0354
0355
0356
0357
0358 double getStepSize(const State& state, ConstrainedStep::Type stype) const {
0359 return state.stepSize.value(stype);
0360 }
0361
0362
0363
0364
0365
0366 std::string outputStepSize(const State& state) const {
0367 return state.stepSize.toString();
0368 }
0369
0370
0371
0372
0373
0374 const ConstrainedStep& stepSize(const State& state) const {
0375 return state.stepSize;
0376 }
0377
0378
0379
0380
0381
0382 const StepperStatistics& statistics(const State& state) const {
0383 return state.statistics;
0384 }
0385
0386
0387
0388
0389
0390 double pathLength(const State& state) const { return state.pathAccumulated; }
0391
0392
0393
0394
0395
0396 bool hasCovariance(const State& state) const { return state.cov.has_value(); }
0397
0398
0399
0400
0401
0402
0403
0404
0405 const std::optional<Covariance>& covariance(const State& state) const {
0406 return state.cov;
0407 }
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417 void setCovariance(State& state, const Covariance& covariance) const {
0418 if (!state.cov.has_value()) {
0419 throw std::logic_error(
0420 "Cannot set the covariance of a state without a covariance");
0421 }
0422 state.cov = covariance;
0423 }
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433 Result<BoundParameters> boundParameters(const State& state,
0434 const Surface& surface) const {
0435 Vector4 pos4(state.pVector[0], state.pVector[1], state.pVector[2],
0436 state.pVector[3]);
0437 return BoundTrackParameters::create(
0438 state.options.geoContext, surface.getSharedPtr(), pos4,
0439 direction(state), qOverP(state), state.cov, state.particleHypothesis);
0440 }
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450 bool prepareCurvilinearState(State& state) const {
0451 return prepareDerivatives(state).ok();
0452 }
0453
0454
0455
0456
0457
0458
0459
0460 BoundParameters curvilinearParameters(const State& state) const {
0461 Vector4 pos4(state.pVector[0], state.pVector[1], state.pVector[2],
0462 state.pVector[3]);
0463 return BoundTrackParameters::createCurvilinear(pos4, direction(state),
0464 qOverP(state), state.cov,
0465 state.particleHypothesis);
0466 }
0467
0468
0469
0470
0471
0472
0473
0474
0475 void update(State& state, const FreeVector& parameters,
0476 const BoundVector& boundParams, const Covariance& covariance,
0477 const Surface& surface) const {
0478 static_cast<void>(boundParams);
0479 update(state, parameters.segment<3>(eFreePos0),
0480 parameters.segment<3>(eFreeDir0).normalized(),
0481 parameters[eFreeQOverP], parameters[eFreeTime]);
0482 state.cov = covariance;
0483 resetJacobian(state, surface);
0484 }
0485
0486
0487
0488
0489
0490
0491
0492
0493 void update(State& state, const Vector3& uposition, const Vector3& udirection,
0494 double qop, double time) const {
0495
0496 state.pVector[0] = uposition[0];
0497 state.pVector[1] = uposition[1];
0498 state.pVector[2] = uposition[2];
0499 state.pVector[3] = time;
0500 state.pVector[4] = udirection[0];
0501 state.pVector[5] = udirection[1];
0502 state.pVector[6] = udirection[2];
0503
0504 constexpr double minQOverP = 1e-15;
0505 state.pVector[7] =
0506 state.particleHypothesis.absoluteCharge() == 0.
0507 ? qop
0508 : std::copysign(std::max(std::abs(qop), minQOverP), qop);
0509 state.newField = true;
0510 state.derivativeReady = false;
0511 }
0512
0513
0514
0515
0516
0517
0518
0519
0520 Jacobian transportToCurvilinear(State& state) const {
0521 if (!state.cov.has_value()) {
0522 return Jacobian::Identity();
0523 }
0524
0525 const auto surface =
0526 CurvilinearSurface(position(state), direction(state)).surface();
0527 return transportToBound(state, *surface).value();
0528 }
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540 Result<Jacobian> transportToBound(
0541 State& state, const Surface& surface,
0542 const FreeToBoundCorrection& =
0543 FreeToBoundCorrection(false)) const {
0544 if (!surface.isOnSurface(state.options.geoContext, position(state),
0545 direction(state), BoundaryTolerance::Infinite())) {
0546 return Result<Jacobian>::failure(
0547 SurfaceError::GlobalPositionNotOnSurface);
0548 }
0549
0550 if (!state.cov.has_value()) {
0551 return Result<Jacobian>::success(Jacobian::Identity());
0552 }
0553
0554 auto prepared = prepareDerivatives(state);
0555 if (!prepared.ok()) {
0556 return Result<Jacobian>::failure(prepared.error());
0557 }
0558
0559 const Vector3 pos = position(state);
0560 const Vector3 dir = direction(state);
0561 BoundToFreeMatrix transportJacobian =
0562 Eigen::Map<const BoundToFreeMatrix>(state.pVector.data() + eFreeSize);
0563
0564 const double inverseQOverP = qOverP(state) == 0. ? 0. : 1. / qOverP(state);
0565 transportJacobian.block<3, 1>(eFreePos0, eBoundQOverP) *= inverseQOverP;
0566 transportJacobian.block<3, 1>(eFreeDir0, eBoundQOverP) *= inverseQOverP;
0567
0568 FreeVector pathDerivative = FreeVector::Zero();
0569 pathDerivative.segment<3>(eFreePos0) = dir;
0570 pathDerivative[eFreeTime] = state.pVector[59];
0571 pathDerivative.segment<3>(eFreeDir0) =
0572 Eigen::Map<const Vector3>(state.pVector.data() + 56);
0573 const FreeToPathMatrix freeToPath =
0574 surface.freeToPathDerivative(state.options.geoContext, pos, dir);
0575 const FreeToBoundMatrix freeToBound =
0576 surface.freeToBoundJacobian(state.options.geoContext, pos, dir);
0577 const Jacobian jac =
0578 freeToBound *
0579 (transportJacobian + pathDerivative * (freeToPath * transportJacobian));
0580 *state.cov = jac * *state.cov * jac.transpose();
0581
0582 resetJacobian(state, surface);
0583
0584 return Result<Jacobian>::success(jac);
0585 }
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599 Result<double> step(State& state, Direction propDir,
0600 const IVolumeMaterial* material) const {
0601 static_cast<void>(material);
0602
0603
0604 auto h = state.stepSize.value() * propDir;
0605 const bool withJacobian = state.cov.has_value();
0606 if (!std::isfinite(h)) {
0607 return EigenStepperError::StepInvalid;
0608 }
0609
0610
0611 if (h == 0.) {
0612 return 0.;
0613 }
0614
0615 double* R = &(state.pVector[0]);
0616 double* A = &(state.pVector[4]);
0617 double* sA = &(state.pVector[56]);
0618
0619 const double halfQOverP = charge(state) == 0. ? 0. : 0.5 * qOverP(state);
0620 Vector3 f0, f;
0621
0622
0623 if (state.newField) {
0624 const Vector3 pos(R[0], R[1], R[2]);
0625
0626 auto fRes = getField(state, pos);
0627 if (!fRes.ok()) {
0628 return fRes.error();
0629 }
0630 f0 = *fRes;
0631 } else {
0632 f0 = state.field;
0633 }
0634
0635 const auto calcStepSizeScaling = [&](const double errorEstimate) -> double {
0636
0637 constexpr double lower = 0.25;
0638 constexpr double upper = 4.0;
0639 if (errorEstimate == 0.) {
0640 return upper;
0641 }
0642
0643 double x =
0644 std::sqrt(std::sqrt(state.options.stepTolerance / errorEstimate));
0645
0646 return std::clamp(x, lower, upper);
0647 };
0648
0649 const auto isErrorTolerable = [&](const double errorEstimate) {
0650
0651 constexpr double marginFactor = 4.0;
0652
0653 return errorEstimate <= marginFactor * state.options.stepTolerance;
0654 };
0655
0656 double errorEstimate = 0;
0657 double initialStepSize = h;
0658
0659 std::uint32_t nStepTrials = 0;
0660 while (true) {
0661 ++state.statistics.nAttemptedSteps;
0662
0663
0664 double S3 = (1. / 3.) * h, S4 = .25 * h, PS2 = halfQOverP * h;
0665
0666
0667
0668
0669 double H0[3] = {f0[0] * PS2, f0[1] * PS2, f0[2] * PS2};
0670
0671 double A0 = A[1] * H0[2] - A[2] * H0[1];
0672 double B0 = A[2] * H0[0] - A[0] * H0[2];
0673 double C0 = A[0] * H0[1] - A[1] * H0[0];
0674
0675 double A2 = A0 + A[0];
0676 double B2 = B0 + A[1];
0677 double C2 = C0 + A[2];
0678
0679 double A1 = A2 + A[0];
0680 double B1 = B2 + A[1];
0681 double C1 = C2 + A[2];
0682
0683
0684 const Vector3 middlePosition(R[0] + A1 * S4, R[1] + B1 * S4,
0685 R[2] + C1 * S4);
0686
0687 auto middleFieldResult = getField(state, middlePosition);
0688 if (!middleFieldResult.ok()) {
0689 return middleFieldResult.error();
0690 }
0691 f = *middleFieldResult;
0692
0693
0694 double H1[3] = {f[0] * PS2, f[1] * PS2, f[2] * PS2};
0695
0696 double A3 = (A[0] + B2 * H1[2]) - C2 * H1[1];
0697 double B3 = (A[1] + C2 * H1[0]) - A2 * H1[2];
0698 double C3 = (A[2] + A2 * H1[1]) - B2 * H1[0];
0699
0700 double A4 = (A[0] + B3 * H1[2]) - C3 * H1[1];
0701 double B4 = (A[1] + C3 * H1[0]) - A3 * H1[2];
0702 double C4 = (A[2] + A3 * H1[1]) - B3 * H1[0];
0703
0704 double A5 = 2. * A4 - A[0];
0705 double B5 = 2. * B4 - A[1];
0706 double C5 = 2. * C4 - A[2];
0707
0708
0709 const Vector3 endPosition(R[0] + h * A4, R[1] + h * B4, R[2] + h * C4);
0710
0711 auto endFieldResult = getField(state, endPosition);
0712 if (!endFieldResult.ok()) {
0713 return endFieldResult.error();
0714 }
0715 f = *endFieldResult;
0716
0717
0718 double H2[3] = {f[0] * PS2, f[1] * PS2, f[2] * PS2};
0719
0720 double A6 = B5 * H2[2] - C5 * H2[1];
0721 double B6 = C5 * H2[0] - A5 * H2[2];
0722 double C6 = A5 * H2[1] - B5 * H2[0];
0723
0724
0725
0726
0727
0728 errorEstimate =
0729 2. * std::abs(h) *
0730 (std::abs((A1 + A6) - (A3 + A4)) + std::abs((B1 + B6) - (B3 + B4)) +
0731 std::abs((C1 + C6) - (C3 + C4)));
0732 if (!std::isfinite(errorEstimate)) {
0733 return EigenStepperError::StepInvalid;
0734 }
0735 if (!isErrorTolerable(errorEstimate)) {
0736 ++state.statistics.nRejectedSteps;
0737 const double stepSizeScaling = calcStepSizeScaling(errorEstimate);
0738 h *= stepSizeScaling;
0739
0740 state.stepSize.setAccuracy(h * propDir);
0741 if (h == 0. || std::abs(h) < std::abs(state.options.stepSizeCutOff)) {
0742 return EigenStepperError::StepSizeStalled;
0743 }
0744 if (++nStepTrials > state.options.maxRungeKuttaStepTrials) {
0745 return EigenStepperError::StepSizeAdjustmentFailed;
0746 }
0747 continue;
0748 }
0749
0750
0751
0752 double A00 = A[0], A11 = A[1], A22 = A[2];
0753
0754 A[0] = 2. * A3 + (A0 + A5 + A6);
0755 A[1] = 2. * B3 + (B0 + B5 + B6);
0756 A[2] = 2. * C3 + (C0 + C5 + C6);
0757
0758 double D = (A[0] * A[0] + A[1] * A[1]) + (A[2] * A[2] - 9.);
0759 double Sl = 2. / h;
0760 D = (1. / 3.) - ((1. / 648.) * D) * (12. - D);
0761
0762 R[0] += (A2 + A3 + A4) * S3;
0763 R[1] += (B2 + B3 + B4) * S3;
0764 R[2] += (C2 + C3 + C4) * S3;
0765 A[0] *= D;
0766 A[1] *= D;
0767 A[2] *= D;
0768 sA[0] = A6 * Sl;
0769 sA[1] = B6 * Sl;
0770 sA[2] = C6 * Sl;
0771
0772 double mass = particleHypothesis(state).mass();
0773 double momentum = absoluteMomentum(state);
0774
0775
0776 const double mOverP = mass / momentum;
0777 double dtds = fastHypot(1., mOverP);
0778 state.pVector[3] += h * dtds;
0779 state.pVector[59] = dtds;
0780 state.field = f;
0781 state.newField = false;
0782 state.derivativeReady = true;
0783
0784 if (withJacobian) {
0785
0786
0787 double dtdl = particleHypothesis(state).hasMomentumHypothesis()
0788 ? 0.
0789 : h * mOverP * mOverP / (qOverP(state) * dtds);
0790 state.pVector[43] += dtdl;
0791
0792
0793
0794 double* d2A = &state.pVector[28];
0795 double* d3A = &state.pVector[36];
0796 double* d4A = &state.pVector[44];
0797 double d2A0 = H0[2] * d2A[1] - H0[1] * d2A[2];
0798 double d2B0 = H0[0] * d2A[2] - H0[2] * d2A[0];
0799 double d2C0 = H0[1] * d2A[0] - H0[0] * d2A[1];
0800 double d3A0 = H0[2] * d3A[1] - H0[1] * d3A[2];
0801 double d3B0 = H0[0] * d3A[2] - H0[2] * d3A[0];
0802 double d3C0 = H0[1] * d3A[0] - H0[0] * d3A[1];
0803 double d4A0 = (A0 + H0[2] * d4A[1]) - H0[1] * d4A[2];
0804 double d4B0 = (B0 + H0[0] * d4A[2]) - H0[2] * d4A[0];
0805 double d4C0 = (C0 + H0[1] * d4A[0]) - H0[0] * d4A[1];
0806 double d2A2 = d2A0 + d2A[0];
0807 double d2B2 = d2B0 + d2A[1];
0808 double d2C2 = d2C0 + d2A[2];
0809 double d3A2 = d3A0 + d3A[0];
0810 double d3B2 = d3B0 + d3A[1];
0811 double d3C2 = d3C0 + d3A[2];
0812 double d4A2 = d4A0 + d4A[0];
0813 double d4B2 = d4B0 + d4A[1];
0814 double d4C2 = d4C0 + d4A[2];
0815 double d0 = d4A[0] - A00;
0816 double d1 = d4A[1] - A11;
0817 double d2 = d4A[2] - A22;
0818 double d2A3 = (d2A[0] + d2B2 * H1[2]) - d2C2 * H1[1];
0819 double d2B3 = (d2A[1] + d2C2 * H1[0]) - d2A2 * H1[2];
0820 double d2C3 = (d2A[2] + d2A2 * H1[1]) - d2B2 * H1[0];
0821 double d3A3 = (d3A[0] + d3B2 * H1[2]) - d3C2 * H1[1];
0822 double d3B3 = (d3A[1] + d3C2 * H1[0]) - d3A2 * H1[2];
0823 double d3C3 = (d3A[2] + d3A2 * H1[1]) - d3B2 * H1[0];
0824 double d4A3 = ((A3 + d0) + d4B2 * H1[2]) - d4C2 * H1[1];
0825 double d4B3 = ((B3 + d1) + d4C2 * H1[0]) - d4A2 * H1[2];
0826 double d4C3 = ((C3 + d2) + d4A2 * H1[1]) - d4B2 * H1[0];
0827 double d2A4 = (d2A[0] + d2B3 * H1[2]) - d2C3 * H1[1];
0828 double d2B4 = (d2A[1] + d2C3 * H1[0]) - d2A3 * H1[2];
0829 double d2C4 = (d2A[2] + d2A3 * H1[1]) - d2B3 * H1[0];
0830 double d3A4 = (d3A[0] + d3B3 * H1[2]) - d3C3 * H1[1];
0831 double d3B4 = (d3A[1] + d3C3 * H1[0]) - d3A3 * H1[2];
0832 double d3C4 = (d3A[2] + d3A3 * H1[1]) - d3B3 * H1[0];
0833 double d4A4 = ((A4 + d0) + d4B3 * H1[2]) - d4C3 * H1[1];
0834 double d4B4 = ((B4 + d1) + d4C3 * H1[0]) - d4A3 * H1[2];
0835 double d4C4 = ((C4 + d2) + d4A3 * H1[1]) - d4B3 * H1[0];
0836 double d2A5 = 2. * d2A4 - d2A[0];
0837 double d2B5 = 2. * d2B4 - d2A[1];
0838 double d2C5 = 2. * d2C4 - d2A[2];
0839 double d3A5 = 2. * d3A4 - d3A[0];
0840 double d3B5 = 2. * d3B4 - d3A[1];
0841 double d3C5 = 2. * d3C4 - d3A[2];
0842 double d4A5 = 2. * d4A4 - d4A[0];
0843 double d4B5 = 2. * d4B4 - d4A[1];
0844 double d4C5 = 2. * d4C4 - d4A[2];
0845 double d2A6 = d2B5 * H2[2] - d2C5 * H2[1];
0846 double d2B6 = d2C5 * H2[0] - d2A5 * H2[2];
0847 double d2C6 = d2A5 * H2[1] - d2B5 * H2[0];
0848 double d3A6 = d3B5 * H2[2] - d3C5 * H2[1];
0849 double d3B6 = d3C5 * H2[0] - d3A5 * H2[2];
0850 double d3C6 = d3A5 * H2[1] - d3B5 * H2[0];
0851 double d4A6 = d4B5 * H2[2] - d4C5 * H2[1];
0852 double d4B6 = d4C5 * H2[0] - d4A5 * H2[2];
0853 double d4C6 = d4A5 * H2[1] - d4B5 * H2[0];
0854
0855 double* dR = &state.pVector[24];
0856 dR[0] += (d2A2 + d2A3 + d2A4) * S3;
0857 dR[1] += (d2B2 + d2B3 + d2B4) * S3;
0858 dR[2] += (d2C2 + d2C3 + d2C4) * S3;
0859 d2A[0] = ((d2A0 + 2. * d2A3) + (d2A5 + d2A6)) * (1. / 3.);
0860 d2A[1] = ((d2B0 + 2. * d2B3) + (d2B5 + d2B6)) * (1. / 3.);
0861 d2A[2] = ((d2C0 + 2. * d2C3) + (d2C5 + d2C6)) * (1. / 3.);
0862
0863 dR = &state.pVector[32];
0864 dR[0] += (d3A2 + d3A3 + d3A4) * S3;
0865 dR[1] += (d3B2 + d3B3 + d3B4) * S3;
0866 dR[2] += (d3C2 + d3C3 + d3C4) * S3;
0867 d3A[0] = ((d3A0 + 2. * d3A3) + (d3A5 + d3A6)) * (1. / 3.);
0868 d3A[1] = ((d3B0 + 2. * d3B3) + (d3B5 + d3B6)) * (1. / 3.);
0869 d3A[2] = ((d3C0 + 2. * d3C3) + (d3C5 + d3C6)) * (1. / 3.);
0870
0871 dR = &state.pVector[40];
0872 dR[0] += (d4A2 + d4A3 + d4A4) * S3;
0873 dR[1] += (d4B2 + d4B3 + d4B4) * S3;
0874 dR[2] += (d4C2 + d4C3 + d4C4) * S3;
0875 d4A[0] = ((d4A0 + 2. * d4A3) + (d4A5 + d4A6 + A6)) * (1. / 3.);
0876 d4A[1] = ((d4B0 + 2. * d4B3) + (d4B5 + d4B6 + B6)) * (1. / 3.);
0877 d4A[2] = ((d4C0 + 2. * d4C3) + (d4C5 + d4C6 + C6)) * (1. / 3.);
0878 }
0879
0880 break;
0881 }
0882
0883 state.pathAccumulated += h;
0884 ++state.nSteps;
0885
0886 ++state.statistics.nSuccessfulSteps;
0887 if (propDir != Direction::fromScalarZeroAsPositive(initialStepSize)) {
0888 ++state.statistics.nReverseSteps;
0889 }
0890 state.statistics.pathLength += h;
0891 state.statistics.absolutePathLength += std::abs(h);
0892
0893 const double stepSizeScaling = calcStepSizeScaling(errorEstimate);
0894 const double nextAccuracy = std::abs(h * stepSizeScaling);
0895 const double previousAccuracy = std::abs(state.stepSize.accuracy());
0896 const double initialStepLength = std::abs(initialStepSize);
0897 if (nextAccuracy < initialStepLength || nextAccuracy > previousAccuracy) {
0898 state.stepSize.setAccuracy(nextAccuracy);
0899 }
0900
0901 return h;
0902 }
0903
0904 private:
0905
0906 void resetJacobian(State& state, const Surface& surface) const {
0907 std::ranges::fill(state.pVector.begin() + eFreeSize, state.pVector.end(),
0908 0.);
0909 if (state.cov.has_value()) {
0910 Eigen::Map<BoundToFreeMatrix>(state.pVector.data() + eFreeSize) =
0911 surface.boundToFreeJacobian(state.options.geoContext, position(state),
0912 direction(state));
0913 }
0914 state.derivativeReady = false;
0915 }
0916
0917
0918 Result<void> prepareDerivatives(State& state) const {
0919 if (state.derivativeReady) {
0920 return Result<void>::success();
0921 }
0922 auto field = getField(state, position(state));
0923 if (!field.ok()) {
0924 return field.error();
0925 }
0926 const double curvature = charge(state) == 0. ? 0. : qOverP(state);
0927 Eigen::Map<Vector3>(state.pVector.data() + 56) =
0928 curvature * direction(state).cross(*field);
0929 const double mOverP =
0930 particleHypothesis(state).mass() / absoluteMomentum(state);
0931 state.pVector[59] = fastHypot(1., mOverP);
0932 state.derivativeReady = true;
0933 return Result<void>::success();
0934 }
0935
0936 std::shared_ptr<const MagneticFieldProvider> m_bField;
0937
0938
0939 double m_overstepLimit = 100 * UnitConstants::um;
0940 };
0941
0942 }