File indexing completed on 2026-11-21 09:42:33
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/EventData/MeasurementHelpers.hpp"
0014 #include "Acts/EventData/MultiTrajectory.hpp"
0015 #include "Acts/EventData/SourceLink.hpp"
0016 #include "Acts/EventData/TrackProxyConcept.hpp"
0017 #include "Acts/EventData/Types.hpp"
0018 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0019 #include "Acts/EventData/VectorTrackContainer.hpp"
0020 #include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
0021 #include "Acts/Geometry/GeometryContext.hpp"
0022 #include "Acts/Geometry/TrackingVolume.hpp"
0023 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0024 #include "Acts/Material/Interactions.hpp"
0025 #include "Acts/Propagator/DirectNavigator.hpp"
0026 #include "Acts/Propagator/PropagatorOptions.hpp"
0027 #include "Acts/Propagator/StandardAborters.hpp"
0028 #include "Acts/Propagator/detail/PointwiseMaterialInteraction.hpp"
0029 #include "Acts/TrackFitting/GlobalChiSquareFitterError.hpp"
0030 #include "Acts/TrackFitting/detail/VoidFitterComponents.hpp"
0031 #include "Acts/Utilities/CalibrationContext.hpp"
0032 #include "Acts/Utilities/Delegate.hpp"
0033 #include "Acts/Utilities/Logger.hpp"
0034 #include "Acts/Utilities/Result.hpp"
0035 #include "Acts/Utilities/TrackHelpers.hpp"
0036
0037 #include <functional>
0038 #include <limits>
0039 #include <memory>
0040 #include <type_traits>
0041 #include <unordered_map>
0042
0043 namespace Acts::Experimental {
0044
0045
0046
0047
0048 namespace Gx2fConstants {
0049 constexpr std::string_view gx2fnUpdateColumn = "Gx2fnUpdateColumn";
0050
0051
0052 constexpr TrackStatePropMask trackStateMask = TrackStatePropMask::Smoothed |
0053 TrackStatePropMask::Jacobian |
0054 TrackStatePropMask::Calibrated;
0055
0056
0057
0058 const Eigen::Matrix<double, eBoundSize, 2> phiThetaProjector = [] {
0059 Eigen::Matrix<double, eBoundSize, 2> m =
0060 Eigen::Matrix<double, eBoundSize, 2>::Zero();
0061 m(eBoundPhi, 0) = 1.0;
0062 m(eBoundTheta, 1) = 1.0;
0063 return m;
0064 }();
0065 }
0066
0067
0068 template <typename traj_t>
0069 struct Gx2FitterExtensions {
0070
0071 using TrackStateProxy = typename MultiTrajectory<traj_t>::TrackStateProxy;
0072
0073 using ConstTrackStateProxy =
0074 typename MultiTrajectory<traj_t>::ConstTrackStateProxy;
0075
0076 using Parameters = typename TrackStateProxy::Parameters;
0077
0078
0079 using Calibrator =
0080 Delegate<void(const GeometryContext&, const CalibrationContext&,
0081 const SourceLink&, TrackStateProxy)>;
0082
0083
0084
0085 using Updater = Delegate<Result<void>(const GeometryContext&, TrackStateProxy,
0086 const Logger&)>;
0087
0088
0089 using OutlierFinder = Delegate<bool(ConstTrackStateProxy)>;
0090
0091
0092
0093
0094 Calibrator calibrator;
0095
0096
0097 Updater updater;
0098
0099
0100
0101 OutlierFinder outlierFinder;
0102
0103
0104 SourceLinkSurfaceAccessor surfaceAccessor;
0105
0106
0107 Gx2FitterExtensions() {
0108 calibrator.template connect<&Acts::detail::voidFitterCalibrator<traj_t>>();
0109 updater.template connect<&Acts::detail::voidFitterUpdater<traj_t>>();
0110 outlierFinder.template connect<&Acts::detail::voidOutlierFinder<traj_t>>();
0111 surfaceAccessor.connect<&Acts::detail::voidSurfaceAccessor>();
0112 }
0113 };
0114
0115
0116
0117
0118 template <typename traj_t>
0119 struct Gx2FitterOptions {
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 Gx2FitterOptions(const GeometryContext& gctx,
0134 const MagneticFieldContext& mctx,
0135 std::reference_wrapper<const CalibrationContext> cctx,
0136 Gx2FitterExtensions<traj_t> extensions_,
0137 const PropagatorPlainOptions& pOptions,
0138 const Surface* rSurface = nullptr, bool mScattering = false,
0139 bool eLoss = false,
0140 const FreeToBoundCorrection& freeToBoundCorrection_ =
0141 FreeToBoundCorrection(false),
0142 const std::size_t nUpdateMax_ = 5,
0143 double relChi2changeCutOff_ = 1e-5)
0144 : geoContext(gctx),
0145 magFieldContext(mctx),
0146 calibrationContext(cctx),
0147 extensions(extensions_),
0148 propagatorPlainOptions(pOptions),
0149 referenceSurface(rSurface),
0150 multipleScattering(mScattering),
0151 energyLoss(eLoss),
0152 freeToBoundCorrection(freeToBoundCorrection_),
0153 nUpdateMax(nUpdateMax_),
0154 relChi2changeCutOff(relChi2changeCutOff_) {}
0155
0156
0157 Gx2FitterOptions() = delete;
0158
0159
0160 std::reference_wrapper<const GeometryContext> geoContext;
0161
0162 std::reference_wrapper<const MagneticFieldContext> magFieldContext;
0163
0164 std::reference_wrapper<const CalibrationContext> calibrationContext;
0165
0166
0167 Gx2FitterExtensions<traj_t> extensions;
0168
0169
0170 PropagatorPlainOptions propagatorPlainOptions;
0171
0172
0173 const Surface* referenceSurface = nullptr;
0174
0175
0176 bool multipleScattering = false;
0177
0178
0179 bool energyLoss = false;
0180
0181
0182
0183 FreeToBoundCorrection freeToBoundCorrection;
0184
0185
0186 std::size_t nUpdateMax = 5;
0187
0188
0189 double relChi2changeCutOff = 1e-7;
0190 };
0191
0192
0193 template <typename traj_t>
0194 struct Gx2FitterResult {
0195
0196 traj_t* fittedStates{nullptr};
0197
0198
0199
0200
0201
0202 std::size_t lastMeasurementIndex = Acts::kTrackIndexInvalid;
0203
0204
0205
0206
0207
0208 std::size_t lastTrackIndex = Acts::kTrackIndexInvalid;
0209
0210
0211 std::optional<BoundTrackParameters> fittedParameters;
0212
0213
0214 std::size_t measurementStates = 0;
0215
0216
0217
0218
0219
0220 std::size_t measurementHoles = 0;
0221
0222
0223 std::size_t processedStates = 0;
0224
0225
0226 std::size_t processedMeasurements = 0;
0227
0228
0229 bool finished = false;
0230
0231
0232 std::vector<const Surface*> missedActiveSurfaces;
0233
0234
0235
0236 std::vector<const Surface*> passedAgainSurfaces;
0237
0238
0239 std::size_t surfaceCount = 0;
0240 };
0241
0242
0243
0244
0245
0246
0247 struct ScatteringProperties {
0248 public:
0249
0250
0251
0252
0253
0254 ScatteringProperties(const BoundVector& scatteringAngles_,
0255 const double invCovarianceMaterial_,
0256 const bool materialIsValid_)
0257 : m_scatteringAngles(scatteringAngles_),
0258 m_invCovarianceMaterial(invCovarianceMaterial_),
0259 m_materialIsValid(materialIsValid_) {}
0260
0261
0262
0263 const BoundVector& scatteringAngles() const { return m_scatteringAngles; }
0264
0265
0266
0267 BoundVector& scatteringAngles() { return m_scatteringAngles; }
0268
0269
0270
0271 double invCovarianceMaterial() const { return m_invCovarianceMaterial; }
0272
0273
0274
0275 bool materialIsValid() const { return m_materialIsValid; }
0276
0277 private:
0278
0279
0280 BoundVector m_scatteringAngles;
0281
0282
0283
0284 double m_invCovarianceMaterial;
0285
0286
0287
0288 bool m_materialIsValid;
0289 };
0290
0291
0292
0293
0294
0295 struct Gx2fSystem {
0296 public:
0297
0298
0299
0300 explicit Gx2fSystem(std::size_t nDims)
0301 : m_nDims{nDims},
0302 m_aMatrix{Eigen::MatrixXd::Zero(nDims, nDims)},
0303 m_bVector{Eigen::VectorXd::Zero(nDims)} {}
0304
0305
0306
0307 std::size_t nDims() const { return m_nDims; }
0308
0309
0310
0311 double chi2() const { return m_chi2; }
0312
0313
0314
0315 double& chi2() { return m_chi2; }
0316
0317
0318
0319 const Eigen::MatrixXd& aMatrix() const { return m_aMatrix; }
0320
0321
0322
0323 Eigen::MatrixXd& aMatrix() { return m_aMatrix; }
0324
0325
0326
0327 const Eigen::VectorXd& bVector() const { return m_bVector; }
0328
0329
0330
0331 Eigen::VectorXd& bVector() { return m_bVector; }
0332
0333
0334
0335 std::size_t ndf() const { return m_ndf; }
0336
0337
0338
0339 std::size_t& ndf() { return m_ndf; }
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350 std::size_t findRequiredNdf() {
0351 std::size_t ndfSystem = 0;
0352 if (m_aMatrix(4, 4) == 0) {
0353 ndfSystem = 4;
0354 } else if (m_aMatrix(5, 5) == 0) {
0355 ndfSystem = 5;
0356 } else {
0357 ndfSystem = 6;
0358 }
0359
0360 return ndfSystem;
0361 }
0362
0363
0364
0365 bool isWellDefined() { return m_ndf > findRequiredNdf(); }
0366
0367 private:
0368
0369 std::size_t m_nDims;
0370
0371
0372 double m_chi2 = 0.;
0373
0374
0375 Eigen::MatrixXd m_aMatrix;
0376
0377
0378 Eigen::VectorXd m_bVector;
0379
0380
0381 std::size_t m_ndf = 0u;
0382 };
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400 void addMeasurementToGx2fSumsBackend(
0401 Gx2fSystem& extendedSystem,
0402 const std::vector<BoundMatrix>& jacobianFromStart,
0403 const Eigen::MatrixXd& covarianceMeasurement, const BoundVector& predicted,
0404 const Eigen::VectorXd& measurement, const Eigen::MatrixXd& projector,
0405 const Logger& logger);
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420 template <std::size_t kMeasDim, typename track_state_t>
0421 void addMeasurementToGx2fSums(Gx2fSystem& extendedSystem,
0422 const std::vector<BoundMatrix>& jacobianFromStart,
0423 const track_state_t& trackState,
0424 const Logger& logger) {
0425 const SquareMatrix<kMeasDim> covarianceMeasurement =
0426 trackState.template calibratedCovariance<kMeasDim>();
0427
0428 const BoundVector predicted = trackState.smoothed();
0429
0430 const Vector<kMeasDim> measurement =
0431 trackState.template calibrated<kMeasDim>();
0432
0433 const Matrix<kMeasDim, eBoundSize> projector =
0434 trackState.template projectorSubspaceHelper<kMeasDim>().projector();
0435
0436 addMeasurementToGx2fSumsBackend(extendedSystem, jacobianFromStart,
0437 covarianceMeasurement, predicted, measurement,
0438 projector, logger);
0439 }
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454 template <typename track_state_t>
0455 void addMaterialToGx2fSums(
0456 Gx2fSystem& extendedSystem, const std::size_t nMaterialsHandled,
0457 const std::unordered_map<GeometryIdentifier, ScatteringProperties>&
0458 scatteringMap,
0459 const track_state_t& trackState, const Logger& logger) {
0460
0461 const GeometryIdentifier geoId = trackState.referenceSurface().geometryId();
0462 const auto scatteringMapId = scatteringMap.find(geoId);
0463 if (scatteringMapId == scatteringMap.end()) {
0464 ACTS_ERROR("No scattering angles found for material surface " << geoId);
0465 throw std::runtime_error(
0466 "No scattering angles found for material surface.");
0467 }
0468
0469
0470 const std::size_t deltaPosition = eBoundSize + 2 * nMaterialsHandled;
0471
0472 const BoundVector& scatteringAngles =
0473 scatteringMapId->second.scatteringAngles();
0474
0475 const double invCovTheta = scatteringMapId->second.invCovarianceMaterial();
0476 const double sinThetaLoc = std::sin(trackState.smoothed()[eBoundTheta]);
0477 const double invCovPhi = invCovTheta * sinThetaLoc * sinThetaLoc;
0478
0479
0480 extendedSystem.aMatrix()(deltaPosition, deltaPosition) += invCovPhi;
0481 extendedSystem.bVector()(deltaPosition, 0) -=
0482 invCovPhi * scatteringAngles[eBoundPhi];
0483 extendedSystem.chi2() +=
0484 invCovPhi * scatteringAngles[eBoundPhi] * scatteringAngles[eBoundPhi];
0485
0486
0487 extendedSystem.aMatrix()(deltaPosition + 1, deltaPosition + 1) += invCovTheta;
0488 extendedSystem.bVector()(deltaPosition + 1, 0) -=
0489 invCovTheta * scatteringAngles[eBoundTheta];
0490 extendedSystem.chi2() += invCovTheta * scatteringAngles[eBoundTheta] *
0491 scatteringAngles[eBoundTheta];
0492
0493 ACTS_VERBOSE(
0494 "Contributions in addMaterialToGx2fSums:\n"
0495 << " invCov: " << invCovPhi << "\n"
0496 << " sinThetaLoc: " << sinThetaLoc << "\n"
0497 << " deltaPosition: " << deltaPosition << "\n"
0498 << " Phi:\n"
0499 << " scattering angle: " << scatteringAngles[eBoundPhi] << "\n"
0500 << " aMatrix contribution: " << invCovPhi << "\n"
0501 << " bVector contribution: "
0502 << invCovPhi * scatteringAngles[eBoundPhi] << "\n"
0503 << " chi2sum contribution: "
0504 << invCovPhi * scatteringAngles[eBoundPhi] * scatteringAngles[eBoundPhi]
0505 << "\n"
0506 << " Theta:\n"
0507 << " scattering angle: " << scatteringAngles[eBoundTheta]
0508 << "\n"
0509 << " aMatrix contribution: " << invCovTheta << "\n"
0510 << " bVector contribution: "
0511 << invCovTheta * scatteringAngles[eBoundTheta] << "\n"
0512 << " chi2sum contribution: "
0513 << invCovTheta * scatteringAngles[eBoundTheta] *
0514 scatteringAngles[eBoundTheta]
0515 << "\n");
0516
0517 return;
0518 }
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535 template <TrackProxyConcept track_proxy_t>
0536 void fillGx2fSystem(
0537 const track_proxy_t track, Gx2fSystem& extendedSystem,
0538 const bool multipleScattering,
0539 const std::unordered_map<GeometryIdentifier, ScatteringProperties>&
0540 scatteringMap,
0541 std::vector<GeometryIdentifier>& geoIdVector, const Logger& logger) {
0542 std::vector<BoundMatrix> jacobianFromStart;
0543 jacobianFromStart.emplace_back(BoundMatrix::Identity());
0544
0545 for (const auto& trackState : track.trackStates()) {
0546
0547 const GeometryIdentifier geoId = trackState.referenceSurface().geometryId();
0548 ACTS_DEBUG("Start to investigate trackState on surface " << geoId);
0549 const auto typeFlags = trackState.typeFlags();
0550 const bool stateHasMeasurement = typeFlags.hasMeasurement();
0551 const bool stateHasMaterial = typeFlags.hasMaterial();
0552
0553
0554
0555
0556
0557 bool doMaterial = multipleScattering && stateHasMaterial;
0558 if (doMaterial) {
0559 const auto scatteringMapId = scatteringMap.find(geoId);
0560 assert(scatteringMapId != scatteringMap.end() &&
0561 "No scattering angles found for material surface.");
0562 doMaterial = doMaterial && scatteringMapId->second.materialIsValid();
0563 }
0564
0565
0566 if (!stateHasMeasurement && !doMaterial) {
0567 ACTS_DEBUG(" Skip state.");
0568 continue;
0569 }
0570
0571
0572 for (auto& jac : jacobianFromStart) {
0573 jac = trackState.jacobian() * jac;
0574 }
0575
0576
0577 if (stateHasMeasurement) {
0578 ACTS_DEBUG(" Handle measurement.");
0579
0580 const auto measDim = trackState.calibratedSize();
0581
0582 if (measDim < 1 || 6 < measDim) {
0583 ACTS_ERROR("Can not process state with measurement with "
0584 << measDim << " dimensions.");
0585 throw std::domain_error(
0586 "Found measurement with less than 1 or more than 6 dimension(s).");
0587 }
0588
0589 extendedSystem.ndf() += measDim;
0590
0591 visit_measurement(measDim, [&](auto N) {
0592 addMeasurementToGx2fSums<N>(extendedSystem, jacobianFromStart,
0593 trackState, logger);
0594 });
0595 }
0596
0597
0598 if (doMaterial) {
0599 ACTS_DEBUG(" Handle material");
0600
0601 jacobianFromStart.emplace_back(BoundMatrix::Identity());
0602
0603
0604 addMaterialToGx2fSums(extendedSystem, geoIdVector.size(), scatteringMap,
0605 trackState, logger);
0606
0607 geoIdVector.emplace_back(geoId);
0608 }
0609 }
0610 }
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626 template <TrackProxyConcept track_proxy_t>
0627 std::size_t countMaterialStates(
0628 const track_proxy_t track,
0629 const std::unordered_map<GeometryIdentifier, ScatteringProperties>&
0630 scatteringMap,
0631 const Logger& logger) {
0632 std::size_t nMaterialSurfaces = 0;
0633 ACTS_DEBUG("Count the valid material surfaces.");
0634 for (const auto& trackState : track.trackStates()) {
0635 const auto typeFlags = trackState.typeFlags();
0636 const bool stateHasMaterial = typeFlags.hasMaterial();
0637
0638 if (!stateHasMaterial) {
0639 continue;
0640 }
0641
0642
0643 const GeometryIdentifier geoId = trackState.referenceSurface().geometryId();
0644
0645 const auto scatteringMapId = scatteringMap.find(geoId);
0646 assert(scatteringMapId != scatteringMap.end() &&
0647 "No scattering angles found for material surface.");
0648 if (!scatteringMapId->second.materialIsValid()) {
0649 continue;
0650 }
0651
0652 nMaterialSurfaces++;
0653 }
0654
0655 return nMaterialSurfaces;
0656 }
0657
0658
0659
0660
0661
0662
0663
0664
0665
0666 Eigen::VectorXd computeGx2fDeltaParams(const Gx2fSystem& extendedSystem);
0667
0668
0669
0670
0671
0672
0673
0674
0675
0676 void updateGx2fParams(
0677 BoundTrackParameters& params, const Eigen::VectorXd& deltaParamsExtended,
0678 const std::size_t nMaterialSurfaces,
0679 std::unordered_map<GeometryIdentifier, ScatteringProperties>& scatteringMap,
0680 const std::vector<GeometryIdentifier>& geoIdVector);
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692 void updateGx2fCovarianceParams(BoundMatrix& fullCovariancePredicted,
0693 Gx2fSystem& extendedSystem);
0694
0695
0696
0697
0698
0699
0700 template <typename propagator_t, typename traj_t>
0701 class Gx2Fitter {
0702
0703 using Gx2fNavigator = typename propagator_t::Navigator;
0704
0705
0706 static constexpr bool isDirectNavigator =
0707 std::is_same_v<Gx2fNavigator, DirectNavigator>;
0708
0709 static constexpr auto kInvalid = kTrackIndexInvalid;
0710
0711 public:
0712
0713
0714
0715
0716
0717
0718
0719
0720 explicit Gx2Fitter(const propagator_t& pPropagator,
0721 std::unique_ptr<const Logger> _logger =
0722 getDefaultLogger("Gx2Fitter", Logging::INFO))
0723 : m_propagator(pPropagator),
0724 m_logger{std::move(_logger)},
0725 m_actorLogger{m_logger->cloneWithSuffix("Actor")},
0726 m_addToSumLogger{m_logger->cloneWithSuffix("AddToSum")} {}
0727
0728 private:
0729
0730 propagator_t m_propagator;
0731
0732
0733 std::unique_ptr<const Logger> m_logger;
0734 std::unique_ptr<const Logger> m_actorLogger;
0735 std::unique_ptr<const Logger> m_addToSumLogger;
0736
0737 const Logger& logger() const { return *m_logger; }
0738
0739
0740
0741
0742
0743
0744
0745
0746
0747 class Actor {
0748 public:
0749
0750 using result_type = Gx2FitterResult<traj_t>;
0751
0752
0753 const Surface* targetSurface = nullptr;
0754
0755
0756 const std::unordered_map<const Surface*, SourceLink>* inputMeasurements{};
0757
0758
0759 bool multipleScattering = false;
0760
0761
0762 bool energyLoss = false;
0763
0764
0765
0766 FreeToBoundCorrection freeToBoundCorrection;
0767
0768
0769 std::shared_ptr<MultiTrajectory<traj_t>> outputStates;
0770
0771
0772 const Logger* actorLogger{nullptr};
0773
0774
0775 const Logger& logger() const { return *actorLogger; }
0776
0777 Gx2FitterExtensions<traj_t> extensions;
0778
0779
0780 SurfaceReached targetReached;
0781
0782
0783 const CalibrationContext* calibrationContext{nullptr};
0784
0785
0786 const BoundTrackParameters* parametersWithHypothesis = nullptr;
0787
0788
0789
0790 std::unordered_map<GeometryIdentifier, ScatteringProperties>*
0791 scatteringMap = nullptr;
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803 template <typename propagator_state_t, typename stepper_t,
0804 typename navigator_t>
0805 Result<void> act(propagator_state_t& state, const stepper_t& stepper,
0806 const navigator_t& navigator, result_type& result,
0807 const Logger& ) const {
0808 assert(result.fittedStates && "No MultiTrajectory set");
0809
0810
0811 if (result.measurementStates == inputMeasurements->size()) {
0812 ACTS_DEBUG("Actor: finish: All measurements have been found.");
0813 result.finished = true;
0814 } else if (state.navigation.navigationBreak) {
0815 ACTS_DEBUG("Actor: finish: navigationBreak.");
0816 result.finished = true;
0817 }
0818
0819
0820 if (result.finished) {
0821
0822 if (result.measurementStates > 0) {
0823 result.missedActiveSurfaces.resize(result.measurementHoles);
0824 }
0825
0826 return Result<void>::success();
0827 }
0828
0829
0830
0831 auto surface = navigator.currentSurface(state.navigation);
0832 if (surface == nullptr) {
0833 return Result<void>::success();
0834 }
0835
0836 ++result.surfaceCount;
0837 const GeometryIdentifier geoId = surface->geometryId();
0838 ACTS_DEBUG("Surface " << geoId << " detected.");
0839
0840 const bool surfaceIsSensitive = surface->isSensitive();
0841 const bool surfaceHasMaterial = surface->hasMaterial();
0842
0843
0844
0845 bool doMaterial = multipleScattering && surfaceHasMaterial;
0846
0847
0848
0849 if (doMaterial) {
0850 ACTS_DEBUG(" The surface contains material, ...");
0851
0852 auto scatteringMapId = scatteringMap->find(geoId);
0853 if (scatteringMapId == scatteringMap->end()) {
0854 ACTS_DEBUG(" ... create entry in scattering map.");
0855
0856 const Result<MaterialSlab> slabResult =
0857 Acts::detail::evaluateMaterialSlab(
0858 state, stepper, *surface,
0859 Acts::detail::determineMaterialUpdateMode(
0860 state, navigator, MaterialUpdateMode::FullUpdate));
0861 if (!slabResult.ok()) {
0862 ACTS_DEBUG("GlobalChiSquareFitter | "
0863 << "Failed to evaluate material slab: "
0864 << slabResult.error());
0865 return Result<void>::failure(slabResult.error());
0866 }
0867 const MaterialSlab& slab = *slabResult;
0868 const bool slabIsValid = !slab.isVacuum();
0869
0870 double invSigma2 = 0.;
0871 if (slabIsValid) {
0872 const auto& particle =
0873 parametersWithHypothesis->particleHypothesis();
0874
0875 const double sigma =
0876 static_cast<double>(Acts::computeMultipleScatteringTheta0(
0877 slab, particle.absolutePdg(), particle.mass(),
0878 static_cast<float>(
0879 parametersWithHypothesis->parameters()[eBoundQOverP]),
0880 particle.absoluteCharge()));
0881 ACTS_VERBOSE(
0882 " The Highland formula gives sigma = " << sigma);
0883 invSigma2 = 1. / std::pow(sigma, 2);
0884 } else {
0885 ACTS_VERBOSE(" Material slab is not valid.");
0886 }
0887
0888 scatteringMap->emplace(
0889 geoId, ScatteringProperties{BoundVector::Zero(), invSigma2,
0890 slabIsValid});
0891 scatteringMapId = scatteringMap->find(geoId);
0892 } else {
0893 ACTS_DEBUG(" ... found entry in scattering map.");
0894 }
0895
0896 doMaterial = doMaterial && scatteringMapId->second.materialIsValid();
0897 }
0898
0899
0900 if (auto sourceLinkIt = inputMeasurements->find(surface);
0901 sourceLinkIt != inputMeasurements->end()) {
0902 ACTS_DEBUG(" The surface contains a measurement.");
0903
0904
0905 stepper.transportCovarianceToBound(state.stepping, *surface,
0906 freeToBoundCorrection);
0907
0908
0909 auto& fittedStates = *result.fittedStates;
0910
0911
0912
0913 typename traj_t::TrackStateProxy trackStateProxy =
0914 fittedStates.makeTrackState(Gx2fConstants::trackStateMask,
0915 result.lastTrackIndex);
0916 const std::size_t currentTrackIndex = trackStateProxy.index();
0917
0918
0919
0920 {
0921 trackStateProxy.setReferenceSurface(surface->getSharedPtr());
0922
0923 auto res = stepper.boundState(state.stepping, *surface, false,
0924 freeToBoundCorrection);
0925 if (!res.ok()) {
0926 return res.error();
0927 }
0928
0929 auto& [boundParams, jacobian, pathLength] = *res;
0930
0931
0932
0933 if (doMaterial) {
0934 ACTS_DEBUG(" Update parameters with scattering angles.");
0935 const auto scatteringMapId = scatteringMap->find(geoId);
0936 ACTS_VERBOSE(
0937 " scatteringAngles: "
0938 << scatteringMapId->second.scatteringAngles().transpose());
0939 ACTS_VERBOSE(" boundParams before the update: "
0940 << boundParams.parameters().transpose());
0941 boundParams.parameters() +=
0942 scatteringMapId->second.scatteringAngles();
0943 ACTS_VERBOSE(" boundParams after the update: "
0944 << boundParams.parameters().transpose());
0945 }
0946
0947
0948 trackStateProxy.smoothed() = boundParams.parameters();
0949 trackStateProxy.smoothedCovariance() = state.stepping.cov;
0950
0951 trackStateProxy.jacobian() = jacobian;
0952 trackStateProxy.pathLength() = pathLength;
0953
0954 if (doMaterial) {
0955 stepper.update(state.stepping,
0956 transformBoundToFreeParameters(
0957 trackStateProxy.referenceSurface(),
0958 state.geoContext, trackStateProxy.smoothed()),
0959 trackStateProxy.smoothed(),
0960 trackStateProxy.smoothedCovariance(), *surface);
0961 }
0962 }
0963
0964
0965
0966 extensions.calibrator(state.geoContext, *calibrationContext,
0967 sourceLinkIt->second, trackStateProxy);
0968
0969
0970 auto typeFlags = trackStateProxy.typeFlags();
0971 typeFlags.setHasParameters();
0972 if (surfaceHasMaterial) {
0973 typeFlags.setHasMaterial();
0974 }
0975
0976
0977 typeFlags.setIsMeasurement();
0978
0979 ++result.processedMeasurements;
0980
0981 result.lastMeasurementIndex = currentTrackIndex;
0982 result.lastTrackIndex = currentTrackIndex;
0983
0984
0985
0986 ++result.measurementStates;
0987
0988
0989 ++result.processedStates;
0990
0991
0992
0993 result.measurementHoles = result.missedActiveSurfaces.size();
0994
0995 return Result<void>::success();
0996 }
0997
0998 if (doMaterial) {
0999
1000
1001
1002 ACTS_DEBUG(
1003 " The surface contains no measurement, but material and maybe "
1004 "a hole.");
1005
1006
1007 stepper.transportCovarianceToBound(state.stepping, *surface,
1008 freeToBoundCorrection);
1009
1010
1011 auto& fittedStates = *result.fittedStates;
1012
1013
1014
1015 typename traj_t::TrackStateProxy trackStateProxy =
1016 fittedStates.makeTrackState(Gx2fConstants::trackStateMask,
1017 result.lastTrackIndex);
1018 const std::size_t currentTrackIndex = trackStateProxy.index();
1019
1020
1021
1022 {
1023 trackStateProxy.setReferenceSurface(surface->getSharedPtr());
1024
1025 auto res = stepper.boundState(state.stepping, *surface, false,
1026 freeToBoundCorrection);
1027 if (!res.ok()) {
1028 return res.error();
1029 }
1030
1031 auto& [boundParams, jacobian, pathLength] = *res;
1032
1033
1034
1035
1036
1037 ACTS_DEBUG(" Update parameters with scattering angles.");
1038 const auto scatteringMapId = scatteringMap->find(geoId);
1039 ACTS_VERBOSE(
1040 " scatteringAngles: "
1041 << scatteringMapId->second.scatteringAngles().transpose());
1042 ACTS_VERBOSE(" boundParams before the update: "
1043 << boundParams.parameters().transpose());
1044 boundParams.parameters() +=
1045 scatteringMapId->second.scatteringAngles();
1046 ACTS_VERBOSE(" boundParams after the update: "
1047 << boundParams.parameters().transpose());
1048
1049
1050 trackStateProxy.smoothed() = boundParams.parameters();
1051 trackStateProxy.smoothedCovariance() = state.stepping.cov;
1052
1053 trackStateProxy.jacobian() = jacobian;
1054 trackStateProxy.pathLength() = pathLength;
1055
1056 stepper.update(state.stepping,
1057 transformBoundToFreeParameters(
1058 trackStateProxy.referenceSurface(),
1059 state.geoContext, trackStateProxy.smoothed()),
1060 trackStateProxy.smoothed(),
1061 trackStateProxy.smoothedCovariance(), *surface);
1062 }
1063
1064
1065 auto typeFlags = trackStateProxy.typeFlags();
1066 typeFlags.setHasParameters();
1067 typeFlags.setHasMaterial();
1068
1069
1070
1071 const bool precedingMeasurementExists = (result.measurementStates > 0);
1072 if (surfaceIsSensitive && precedingMeasurementExists) {
1073 ACTS_DEBUG(" Surface is also sensitive. Marked as hole.");
1074 typeFlags.setIsHole();
1075
1076
1077 result.missedActiveSurfaces.push_back(surface);
1078 }
1079
1080 result.lastTrackIndex = currentTrackIndex;
1081
1082 ++result.processedStates;
1083
1084 return Result<void>::success();
1085 }
1086
1087 if (surfaceIsSensitive || surfaceHasMaterial) {
1088
1089
1090
1091 if (multipleScattering) {
1092 ACTS_DEBUG(
1093 " The surface contains no measurement, but maybe a hole.");
1094 } else {
1095 ACTS_DEBUG(
1096 " The surface contains no measurement, but maybe a hole "
1097 "and/or material.");
1098 }
1099
1100
1101
1102
1103 const bool precedingMeasurementExists = (result.measurementStates > 0);
1104 if (!precedingMeasurementExists && !surfaceHasMaterial) {
1105 ACTS_DEBUG(
1106 " Ignoring hole, because there are no preceding "
1107 "measurements.");
1108 return Result<void>::success();
1109 }
1110
1111 auto& fittedStates = *result.fittedStates;
1112
1113
1114
1115 typename traj_t::TrackStateProxy trackStateProxy =
1116 fittedStates.makeTrackState(Gx2fConstants::trackStateMask,
1117 result.lastTrackIndex);
1118 const std::size_t currentTrackIndex = trackStateProxy.index();
1119
1120
1121
1122 {
1123 trackStateProxy.setReferenceSurface(surface->getSharedPtr());
1124
1125 auto res = stepper.boundState(state.stepping, *surface, false,
1126 freeToBoundCorrection);
1127 if (!res.ok()) {
1128 return res.error();
1129 }
1130 const auto& [boundParams, jacobian, pathLength] = *res;
1131
1132
1133 trackStateProxy.smoothed() = boundParams.parameters();
1134 trackStateProxy.smoothedCovariance() = state.stepping.cov;
1135
1136 trackStateProxy.jacobian() = jacobian;
1137 trackStateProxy.pathLength() = pathLength;
1138 }
1139
1140
1141 auto typeFlags = trackStateProxy.typeFlags();
1142 typeFlags.setHasParameters();
1143 if (surfaceHasMaterial) {
1144 ACTS_DEBUG(" It is material.");
1145 typeFlags.setHasMaterial();
1146 }
1147
1148
1149 if (surfaceIsSensitive && precedingMeasurementExists) {
1150 ACTS_DEBUG(" It is a hole.");
1151 typeFlags.setIsHole();
1152
1153 result.missedActiveSurfaces.push_back(surface);
1154 }
1155
1156 result.lastTrackIndex = currentTrackIndex;
1157
1158 ++result.processedStates;
1159
1160 return Result<void>::success();
1161 }
1162
1163 ACTS_DEBUG(" The surface contains no measurement/material/hole.");
1164 return Result<void>::success();
1165 }
1166
1167 template <typename propagator_state_t, typename stepper_t,
1168 typename navigator_t, typename result_t>
1169 bool checkAbort(propagator_state_t& , const stepper_t& ,
1170 const navigator_t& , const result_t& result,
1171 const Logger& ) const {
1172 if (result.finished) {
1173 return true;
1174 }
1175 return false;
1176 }
1177 };
1178
1179 public:
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196 template <typename source_link_iterator_t,
1197 TrackContainerFrontend track_container_t>
1198 Result<typename track_container_t::TrackProxy> fit(
1199 source_link_iterator_t it, source_link_iterator_t end,
1200 const BoundTrackParameters& sParameters,
1201 const Gx2FitterOptions<traj_t>& gx2fOptions,
1202 track_container_t& trackContainer) const
1203 requires(!isDirectNavigator)
1204 {
1205
1206
1207
1208 ACTS_VERBOSE("Preparing " << std::distance(it, end)
1209 << " input measurements");
1210 std::unordered_map<const Surface*, SourceLink> inputMeasurements{};
1211
1212 for (; it != end; ++it) {
1213 inputMeasurements.try_emplace(gx2fOptions.extensions.surfaceAccessor(*it),
1214 *it);
1215 }
1216
1217
1218
1219 const bool multipleScattering = gx2fOptions.multipleScattering;
1220
1221
1222 using GX2FActor = Actor;
1223
1224 using GX2FResult = typename GX2FActor::result_type;
1225 using Actors = Acts::ActorList<GX2FActor>;
1226
1227 using PropagatorOptions = typename propagator_t::template Options<Actors>;
1228
1229 BoundTrackParameters params = sParameters;
1230 double chi2sum = 0;
1231 double oldChi2sum = std::numeric_limits<double>::max();
1232
1233
1234
1235
1236
1237 typename track_container_t::TrackContainerBackend trackContainerTempBackend;
1238 traj_t trajectoryTempBackend;
1239 TrackContainer trackContainerTemp{trackContainerTempBackend,
1240 trajectoryTempBackend};
1241
1242
1243
1244
1245 std::size_t tipIndex = kInvalid;
1246
1247
1248
1249 std::unordered_map<GeometryIdentifier, ScatteringProperties> scatteringMap;
1250
1251
1252
1253 BoundMatrix fullCovariancePredicted = BoundMatrix::Identity();
1254
1255 ACTS_VERBOSE("Initial parameters: " << params.parameters().transpose());
1256
1257
1258 ACTS_DEBUG("Start to iterate");
1259
1260
1261
1262
1263 std::size_t nUpdate = 0;
1264 for (nUpdate = 0; nUpdate < gx2fOptions.nUpdateMax; nUpdate++) {
1265 ACTS_DEBUG("nUpdate = " << nUpdate + 1 << "/" << gx2fOptions.nUpdateMax);
1266
1267
1268 PropagatorOptions propagatorOptions{gx2fOptions.propagatorPlainOptions};
1269
1270
1271
1272 for (const auto& [surface, _] : inputMeasurements) {
1273 propagatorOptions.navigation.appendExternalSurface(*surface);
1274 }
1275
1276 auto& gx2fActor = propagatorOptions.actorList.template get<GX2FActor>();
1277 gx2fActor.inputMeasurements = &inputMeasurements;
1278 gx2fActor.multipleScattering = false;
1279 gx2fActor.extensions = gx2fOptions.extensions;
1280 gx2fActor.calibrationContext = &gx2fOptions.calibrationContext.get();
1281 gx2fActor.actorLogger = m_actorLogger.get();
1282 gx2fActor.scatteringMap = &scatteringMap;
1283 gx2fActor.parametersWithHypothesis = ¶ms;
1284
1285 auto propagatorState = m_propagator.makeState(propagatorOptions);
1286
1287 auto propagatorInitResult =
1288 m_propagator.initialize(propagatorState, params);
1289 if (!propagatorInitResult.ok()) {
1290 ACTS_DEBUG("Propagation initialization failed: "
1291 << propagatorInitResult.error());
1292 return propagatorInitResult.error();
1293 }
1294
1295 auto& r = propagatorState.template get<Gx2FitterResult<traj_t>>();
1296 r.fittedStates = &trajectoryTempBackend;
1297
1298
1299
1300 trackContainerTemp.clear();
1301
1302
1303 auto propagationResult = m_propagator.propagate(propagatorState);
1304
1305 auto result =
1306 m_propagator.makeResult(std::move(propagatorState), propagationResult,
1307 propagatorOptions, false);
1308
1309 if (!result.ok()) {
1310 ACTS_DEBUG("Propagation failed: " << result.error());
1311 return result.error();
1312 }
1313
1314
1315
1316 auto& propRes = *result;
1317 GX2FResult gx2fResult = std::move(propRes.template get<GX2FResult>());
1318
1319 auto track = trackContainerTemp.makeTrack();
1320 tipIndex = gx2fResult.lastMeasurementIndex;
1321
1322
1323
1324
1325 if (tipIndex == kInvalid) {
1326 ACTS_INFO("Did not find any measurements in nUpdate "
1327 << nUpdate + 1 << "/" << gx2fOptions.nUpdateMax);
1328 return Experimental::GlobalChiSquareFitterError::NotEnoughMeasurements;
1329 }
1330
1331 track.tipIndex() = tipIndex;
1332 track.linkForward();
1333
1334
1335
1336 const std::size_t nMaterialSurfaces = 0u;
1337
1338
1339
1340 const std::size_t dimsExtendedParams = eBoundSize + 2 * nMaterialSurfaces;
1341
1342
1343
1344 Gx2fSystem extendedSystem{dimsExtendedParams};
1345
1346
1347
1348
1349
1350 std::vector<GeometryIdentifier> geoIdVector;
1351
1352 fillGx2fSystem(track, extendedSystem, false, scatteringMap, geoIdVector,
1353 *m_addToSumLogger);
1354
1355 chi2sum = extendedSystem.chi2();
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369 if ((nUpdate > 0) && !extendedSystem.isWellDefined()) {
1370 ACTS_INFO("Not enough measurements. Require "
1371 << extendedSystem.findRequiredNdf() + 1 << ", but only "
1372 << extendedSystem.ndf() << " could be used.");
1373 return Experimental::GlobalChiSquareFitterError::NotEnoughMeasurements;
1374 }
1375
1376 Eigen::VectorXd deltaParamsExtended =
1377 computeGx2fDeltaParams(extendedSystem);
1378
1379 ACTS_VERBOSE("aMatrix:\n"
1380 << extendedSystem.aMatrix() << "\n"
1381 << "bVector:\n"
1382 << extendedSystem.bVector() << "\n"
1383 << "deltaParamsExtended:\n"
1384 << deltaParamsExtended << "\n"
1385 << "oldChi2sum = " << oldChi2sum << "\n"
1386 << "chi2sum = " << extendedSystem.chi2());
1387
1388 if ((gx2fOptions.relChi2changeCutOff != 0) && (nUpdate > 0) &&
1389 (std::abs(extendedSystem.chi2() / oldChi2sum - 1) <
1390 gx2fOptions.relChi2changeCutOff)) {
1391 ACTS_DEBUG("Abort with relChi2changeCutOff after "
1392 << nUpdate + 1 << "/" << gx2fOptions.nUpdateMax
1393 << " iterations.");
1394 updateGx2fCovarianceParams(fullCovariancePredicted, extendedSystem);
1395 break;
1396 }
1397
1398 if (extendedSystem.chi2() > oldChi2sum + 1e-5) {
1399 ACTS_DEBUG("chi2 not converging monotonically in update " << nUpdate);
1400 }
1401
1402
1403
1404 if (nUpdate == gx2fOptions.nUpdateMax - 1) {
1405
1406
1407
1408
1409
1410 if (gx2fOptions.nUpdateMax > 5) {
1411 ACTS_INFO("Did not converge in " << gx2fOptions.nUpdateMax
1412 << " updates.");
1413 return Experimental::GlobalChiSquareFitterError::DidNotConverge;
1414 }
1415
1416 updateGx2fCovarianceParams(fullCovariancePredicted, extendedSystem);
1417 break;
1418 }
1419
1420 updateGx2fParams(params, deltaParamsExtended, nMaterialSurfaces,
1421 scatteringMap, geoIdVector);
1422 ACTS_VERBOSE("Updated parameters: " << params.parameters().transpose());
1423
1424 oldChi2sum = extendedSystem.chi2();
1425 }
1426 ACTS_DEBUG("Finished to iterate");
1427 ACTS_VERBOSE("Final parameters: " << params.parameters().transpose());
1428
1429
1430
1431 ACTS_DEBUG("Start to evaluate material");
1432 if (multipleScattering) {
1433
1434 PropagatorOptions propagatorOptions{gx2fOptions.propagatorPlainOptions};
1435
1436
1437
1438 for (const auto& [surface, _] : inputMeasurements) {
1439 propagatorOptions.navigation.appendExternalSurface(*surface);
1440 }
1441
1442 auto& gx2fActor = propagatorOptions.actorList.template get<GX2FActor>();
1443 gx2fActor.inputMeasurements = &inputMeasurements;
1444 gx2fActor.multipleScattering = true;
1445 gx2fActor.extensions = gx2fOptions.extensions;
1446 gx2fActor.calibrationContext = &gx2fOptions.calibrationContext.get();
1447 gx2fActor.actorLogger = m_actorLogger.get();
1448 gx2fActor.scatteringMap = &scatteringMap;
1449 gx2fActor.parametersWithHypothesis = ¶ms;
1450
1451 auto propagatorState = m_propagator.makeState(propagatorOptions);
1452
1453 auto propagatorInitResult =
1454 m_propagator.initialize(propagatorState, params);
1455 if (!propagatorInitResult.ok()) {
1456 ACTS_DEBUG("Propagation initialization failed: "
1457 << propagatorInitResult.error());
1458 return propagatorInitResult.error();
1459 }
1460
1461 auto& r = propagatorState.template get<Gx2FitterResult<traj_t>>();
1462 r.fittedStates = &trajectoryTempBackend;
1463
1464
1465
1466 trackContainerTemp.clear();
1467
1468
1469 auto propagationResult = m_propagator.propagate(propagatorState);
1470
1471 auto result =
1472 m_propagator.makeResult(std::move(propagatorState), propagationResult,
1473 propagatorOptions, false);
1474
1475 if (!result.ok()) {
1476 ACTS_DEBUG("Propagation failed: " << result.error());
1477 return result.error();
1478 }
1479
1480
1481
1482 auto& propRes = *result;
1483 GX2FResult gx2fResult = std::move(propRes.template get<GX2FResult>());
1484
1485 auto track = trackContainerTemp.makeTrack();
1486 tipIndex = gx2fResult.lastMeasurementIndex;
1487
1488
1489
1490
1491 if (tipIndex == kInvalid) {
1492 ACTS_INFO("Did not find any measurements in material fit.");
1493 return Experimental::GlobalChiSquareFitterError::NotEnoughMeasurements;
1494 }
1495
1496 track.tipIndex() = tipIndex;
1497 track.linkForward();
1498
1499
1500
1501 const std::size_t nMaterialSurfaces =
1502 countMaterialStates(track, scatteringMap, *m_addToSumLogger);
1503
1504
1505
1506 const std::size_t dimsExtendedParams = eBoundSize + 2 * nMaterialSurfaces;
1507
1508
1509
1510 Gx2fSystem extendedSystem{dimsExtendedParams};
1511
1512
1513
1514
1515
1516 std::vector<GeometryIdentifier> geoIdVector;
1517
1518 fillGx2fSystem(track, extendedSystem, true, scatteringMap, geoIdVector,
1519 *m_addToSumLogger);
1520
1521 chi2sum = extendedSystem.chi2();
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532 if ((nUpdate > 0) && !extendedSystem.isWellDefined()) {
1533 ACTS_INFO("Not enough measurements. Require "
1534 << extendedSystem.findRequiredNdf() + 1 << ", but only "
1535 << extendedSystem.ndf() << " could be used.");
1536 return Experimental::GlobalChiSquareFitterError::NotEnoughMeasurements;
1537 }
1538
1539 Eigen::VectorXd deltaParamsExtended =
1540 computeGx2fDeltaParams(extendedSystem);
1541
1542 ACTS_VERBOSE("aMatrix:\n"
1543 << extendedSystem.aMatrix() << "\n"
1544 << "bVector:\n"
1545 << extendedSystem.bVector() << "\n"
1546 << "deltaParamsExtended:\n"
1547 << deltaParamsExtended << "\n"
1548 << "oldChi2sum = " << oldChi2sum << "\n"
1549 << "chi2sum = " << extendedSystem.chi2());
1550
1551 chi2sum = extendedSystem.chi2();
1552
1553 updateGx2fParams(params, deltaParamsExtended, nMaterialSurfaces,
1554 scatteringMap, geoIdVector);
1555 ACTS_VERBOSE("Updated parameters: " << params.parameters().transpose());
1556
1557 updateGx2fCovarianceParams(fullCovariancePredicted, extendedSystem);
1558 }
1559 ACTS_DEBUG("Finished to evaluate material");
1560 ACTS_VERBOSE(
1561 "Final parameters after material: " << params.parameters().transpose());
1562
1563
1564 ACTS_VERBOSE("Final scattering angles:");
1565 for (const auto& [key, value] : scatteringMap) {
1566 if (!value.materialIsValid()) {
1567 continue;
1568 }
1569 const auto& angles = value.scatteringAngles();
1570 ACTS_VERBOSE(" ( " << angles[eBoundTheta] << " | " << angles[eBoundPhi]
1571 << " )");
1572 }
1573
1574 ACTS_VERBOSE("Final covariance:\n" << fullCovariancePredicted);
1575
1576
1577
1578
1579
1580
1581 if (gx2fOptions.nUpdateMax > 0) {
1582 ACTS_VERBOSE("Propagate with the final covariance.");
1583
1584 params.covariance() = fullCovariancePredicted;
1585
1586
1587 PropagatorOptions propagatorOptions{gx2fOptions.propagatorPlainOptions};
1588 auto& gx2fActor = propagatorOptions.actorList.template get<GX2FActor>();
1589 gx2fActor.inputMeasurements = &inputMeasurements;
1590 gx2fActor.multipleScattering = multipleScattering;
1591 gx2fActor.extensions = gx2fOptions.extensions;
1592 gx2fActor.calibrationContext = &gx2fOptions.calibrationContext.get();
1593 gx2fActor.actorLogger = m_actorLogger.get();
1594 gx2fActor.scatteringMap = &scatteringMap;
1595 gx2fActor.parametersWithHypothesis = ¶ms;
1596
1597 auto propagatorState = m_propagator.makeState(propagatorOptions);
1598
1599 auto propagatorInitResult =
1600 m_propagator.initialize(propagatorState, params);
1601 if (!propagatorInitResult.ok()) {
1602 ACTS_DEBUG("Propagation initialization failed: "
1603 << propagatorInitResult.error());
1604 return propagatorInitResult.error();
1605 }
1606
1607 auto& r = propagatorState.template get<Gx2FitterResult<traj_t>>();
1608 r.fittedStates = &trackContainer.trackStateContainer();
1609
1610
1611 auto propagationResult = m_propagator.propagate(propagatorState);
1612
1613 auto result =
1614 m_propagator.makeResult(std::move(propagatorState), propagationResult,
1615 propagatorOptions, false);
1616
1617 if (!result.ok()) {
1618 ACTS_DEBUG("Propagation failed: " << result.error());
1619 return result.error();
1620 }
1621
1622 auto& propRes = *result;
1623 GX2FResult gx2fResult = std::move(propRes.template get<GX2FResult>());
1624
1625 if (tipIndex != gx2fResult.lastMeasurementIndex) {
1626 ACTS_INFO("Final fit used unreachable measurements.");
1627 tipIndex = gx2fResult.lastMeasurementIndex;
1628
1629
1630
1631 if (tipIndex == kInvalid) {
1632 ACTS_INFO("Did not find any measurements in final propagation.");
1633 return Experimental::GlobalChiSquareFitterError::
1634 NotEnoughMeasurements;
1635 }
1636 }
1637 }
1638
1639 if (!trackContainer.hasColumn(
1640 Acts::hashString(Gx2fConstants::gx2fnUpdateColumn))) {
1641 trackContainer.template addColumn<std::uint32_t>("Gx2fnUpdateColumn");
1642 }
1643
1644
1645 auto track = trackContainer.makeTrack();
1646 track.tipIndex() = tipIndex;
1647 track.parameters() = params.parameters();
1648 track.covariance() = fullCovariancePredicted;
1649 track.setReferenceSurface(params.referenceSurface().getSharedPtr());
1650
1651 if (trackContainer.hasColumn(
1652 Acts::hashString(Gx2fConstants::gx2fnUpdateColumn))) {
1653 ACTS_DEBUG("Add nUpdate to track");
1654 track.template component<std::uint32_t>("Gx2fnUpdateColumn") =
1655 static_cast<std::uint32_t>(nUpdate);
1656 }
1657
1658
1659 calculateTrackQuantities(track);
1660
1661
1662
1663 track.chi2() = chi2sum;
1664
1665 track.linkForward();
1666
1667
1668 return track;
1669 }
1670 };
1671
1672
1673
1674 }