File indexing completed on 2025-07-11 08:04:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/EventData/MultiComponentTrackParameters.hpp"
0013 #include "Acts/EventData/MultiTrajectory.hpp"
0014 #include "Acts/EventData/MultiTrajectoryHelpers.hpp"
0015 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0016 #include "Acts/Material/ISurfaceMaterial.hpp"
0017 #include "Acts/Surfaces/CylinderSurface.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/TrackFitting/BetheHeitlerApprox.hpp"
0020 #include "Acts/TrackFitting/GsfError.hpp"
0021 #include "Acts/TrackFitting/GsfOptions.hpp"
0022 #include "Acts/TrackFitting/KalmanFitter.hpp"
0023 #include "Acts/TrackFitting/detail/GsfComponentMerging.hpp"
0024 #include "Acts/TrackFitting/detail/GsfUtils.hpp"
0025 #include "Acts/TrackFitting/detail/KalmanUpdateHelpers.hpp"
0026 #include "Acts/Utilities/Zip.hpp"
0027
0028 #include <ios>
0029 #include <map>
0030 #include <numeric>
0031
0032 namespace Acts::detail {
0033
0034 template <typename traj_t>
0035 struct GsfResult {
0036
0037 traj_t* fittedStates{nullptr};
0038
0039
0040 MultiTrajectoryTraits::IndexType currentTip = MultiTrajectoryTraits::kInvalid;
0041
0042
0043 MultiTrajectoryTraits::IndexType lastMeasurementTip =
0044 MultiTrajectoryTraits::kInvalid;
0045
0046
0047
0048 std::optional<MultiComponentBoundTrackParameters> lastMeasurementState;
0049
0050
0051 std::size_t measurementStates = 0;
0052 std::size_t measurementHoles = 0;
0053 std::size_t processedStates = 0;
0054
0055 std::vector<const Acts::Surface*> visitedSurfaces;
0056 std::vector<const Acts::Surface*> surfacesVisitedBwdAgain;
0057
0058
0059 Updatable<std::size_t> nInvalidBetheHeitler;
0060 Updatable<double> maxPathXOverX0;
0061 Updatable<double> sumPathXOverX0;
0062
0063
0064 Result<void> result{Result<void>::success()};
0065
0066
0067 std::vector<GsfComponent> componentCache;
0068 };
0069
0070
0071 template <typename bethe_heitler_approx_t, typename traj_t>
0072 struct GsfActor {
0073
0074 GsfActor() = default;
0075
0076 using ComponentCache = Acts::GsfComponent;
0077
0078
0079 using result_type = GsfResult<traj_t>;
0080
0081
0082 struct Config {
0083
0084 std::size_t maxComponents = 16;
0085
0086
0087 const std::map<GeometryIdentifier, SourceLink>* inputMeasurements = nullptr;
0088
0089
0090
0091 const bethe_heitler_approx_t* bethe_heitler_approx = nullptr;
0092
0093
0094 bool multipleScattering = true;
0095
0096
0097 double weightCutoff = 1.0e-4;
0098
0099
0100
0101
0102 bool disableAllMaterialHandling = false;
0103
0104
0105 bool abortOnError = false;
0106
0107
0108
0109 std::optional<std::size_t> numberMeasurements;
0110
0111
0112 GsfExtensions<traj_t> extensions;
0113
0114
0115
0116
0117 bool inReversePass = false;
0118
0119
0120 ComponentMergeMethod mergeMethod = ComponentMergeMethod::eMaxWeight;
0121
0122 const Logger* logger{nullptr};
0123
0124
0125 const CalibrationContext* calibrationContext{nullptr};
0126
0127 } m_cfg;
0128
0129 const Logger& logger() const { return *m_cfg.logger; }
0130
0131 struct TemporaryStates {
0132 traj_t traj;
0133 std::vector<MultiTrajectoryTraits::IndexType> tips;
0134 std::map<MultiTrajectoryTraits::IndexType, double> weights;
0135 };
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 template <typename propagator_state_t, typename stepper_t,
0147 typename navigator_t>
0148 void operator()(propagator_state_t& state, const stepper_t& stepper,
0149 const navigator_t& navigator, result_type& result,
0150 const Logger& ) const {
0151 assert(result.fittedStates && "No MultiTrajectory set");
0152
0153
0154 if (!result.result.ok()) {
0155 ACTS_WARNING("result.result not ok, return!");
0156 return;
0157 }
0158
0159
0160 auto setErrorOrAbort = [&](auto error) {
0161 if (m_cfg.abortOnError) {
0162 std::abort();
0163 } else {
0164 result.result = error;
0165 }
0166 };
0167
0168
0169
0170 const detail::ScopedGsfInfoPrinterAndChecker printer(state, stepper,
0171 navigator, logger());
0172
0173
0174 if (!navigator.currentSurface(state.navigation)) {
0175 return;
0176 }
0177
0178 const auto& surface = *navigator.currentSurface(state.navigation);
0179 ACTS_VERBOSE("Step is at surface " << surface.geometryId());
0180
0181
0182
0183 [[maybe_unused]] auto stepperComponents =
0184 stepper.constComponentIterable(state.stepping);
0185 assert(detail::weightsAreNormalized(
0186 stepperComponents, [](const auto& cmp) { return cmp.weight(); }));
0187
0188
0189
0190
0191 using Status [[maybe_unused]] = Acts::Intersection3D::Status;
0192 assert(std::all_of(
0193 stepperComponents.begin(), stepperComponents.end(),
0194 [](const auto& cmp) { return cmp.status() == Status::onSurface; }));
0195
0196
0197
0198 const bool visited =
0199 std::find(result.visitedSurfaces.begin(), result.visitedSurfaces.end(),
0200 &surface) != result.visitedSurfaces.end();
0201
0202 if (visited) {
0203 ACTS_VERBOSE("Already visited surface, return");
0204 return;
0205 }
0206
0207 result.visitedSurfaces.push_back(&surface);
0208
0209
0210 const auto found_source_link =
0211 m_cfg.inputMeasurements->find(surface.geometryId());
0212 const bool haveMaterial =
0213 navigator.currentSurface(state.navigation)->surfaceMaterial() &&
0214 !m_cfg.disableAllMaterialHandling;
0215 const bool haveMeasurement =
0216 found_source_link != m_cfg.inputMeasurements->end();
0217
0218 ACTS_VERBOSE(std::boolalpha << "haveMaterial " << haveMaterial
0219 << ", haveMeasurement: " << haveMeasurement);
0220
0221
0222
0223
0224
0225
0226 if (!haveMaterial && !haveMeasurement) {
0227
0228 if (result.processedStates > 0 && surface.associatedDetectorElement()) {
0229 TemporaryStates tmpStates;
0230 noMeasurementUpdate(state, stepper, navigator, result, tmpStates, true);
0231 }
0232 return;
0233 }
0234
0235
0236
0237
0238 if (haveMeasurement) {
0239 result.maxPathXOverX0.update();
0240 result.sumPathXOverX0.update();
0241 result.nInvalidBetheHeitler.update();
0242 }
0243
0244 for (auto cmp : stepper.componentIterable(state.stepping)) {
0245 auto singleState = cmp.singleState(state);
0246 cmp.singleStepper(stepper).transportCovarianceToBound(
0247 singleState.stepping, surface);
0248 }
0249
0250 if (haveMaterial) {
0251 if (haveMeasurement) {
0252 applyMultipleScattering(state, stepper, navigator,
0253 MaterialUpdateStage::PreUpdate);
0254 } else {
0255 applyMultipleScattering(state, stepper, navigator,
0256 MaterialUpdateStage::FullUpdate);
0257 }
0258 }
0259
0260
0261
0262
0263 if (!haveMaterial) {
0264 TemporaryStates tmpStates;
0265
0266 auto res = kalmanUpdate(state, stepper, navigator, result, tmpStates,
0267 found_source_link->second);
0268
0269 if (!res.ok()) {
0270 setErrorOrAbort(res.error());
0271 return;
0272 }
0273
0274 updateStepper(state, stepper, tmpStates);
0275 }
0276
0277
0278
0279 else {
0280 TemporaryStates tmpStates;
0281 Result<void> res;
0282
0283 if (haveMeasurement) {
0284 res = kalmanUpdate(state, stepper, navigator, result, tmpStates,
0285 found_source_link->second);
0286 } else {
0287 res = noMeasurementUpdate(state, stepper, navigator, result, tmpStates,
0288 false);
0289 }
0290
0291 if (!res.ok()) {
0292 setErrorOrAbort(res.error());
0293 return;
0294 }
0295
0296
0297 std::vector<ComponentCache>& componentCache = result.componentCache;
0298 componentCache.clear();
0299
0300 convoluteComponents(state, stepper, navigator, tmpStates, componentCache,
0301 result);
0302
0303 if (componentCache.empty()) {
0304 ACTS_WARNING(
0305 "No components left after applying energy loss. "
0306 "Is the weight cutoff "
0307 << m_cfg.weightCutoff << " too high?");
0308 ACTS_WARNING("Return to propagator without applying energy loss");
0309 return;
0310 }
0311
0312
0313 const auto finalCmpNumber = std::min(
0314 static_cast<std::size_t>(stepper.maxComponents), m_cfg.maxComponents);
0315 m_cfg.extensions.mixtureReducer(componentCache, finalCmpNumber, surface);
0316
0317 removeLowWeightComponents(componentCache);
0318
0319 updateStepper(state, stepper, navigator, componentCache);
0320 }
0321
0322
0323 if (haveMaterial && haveMeasurement) {
0324 applyMultipleScattering(state, stepper, navigator,
0325 MaterialUpdateStage::PostUpdate);
0326 }
0327
0328
0329 if (m_cfg.numberMeasurements &&
0330 result.measurementStates == m_cfg.numberMeasurements) {
0331 ACTS_VERBOSE("Stop navigation because all measurements are found");
0332 navigator.navigationBreak(state.navigation, true);
0333 }
0334 }
0335
0336 template <typename propagator_state_t, typename stepper_t,
0337 typename navigator_t>
0338 void convoluteComponents(propagator_state_t& state, const stepper_t& stepper,
0339 const navigator_t& navigator,
0340 const TemporaryStates& tmpStates,
0341 std::vector<ComponentCache>& componentCache,
0342 result_type& result) const {
0343 auto cmps = stepper.componentIterable(state.stepping);
0344 double pathXOverX0 = 0.0;
0345 for (auto [idx, cmp] : zip(tmpStates.tips, cmps)) {
0346 auto proxy = tmpStates.traj.getTrackState(idx);
0347
0348 BoundTrackParameters bound(proxy.referenceSurface().getSharedPtr(),
0349 proxy.filtered(), proxy.filteredCovariance(),
0350 stepper.particleHypothesis(state.stepping));
0351
0352 pathXOverX0 +=
0353 applyBetheHeitler(state, navigator, bound, tmpStates.weights.at(idx),
0354 componentCache, result);
0355 }
0356
0357
0358
0359 result.sumPathXOverX0.tmp() += pathXOverX0 / tmpStates.tips.size();
0360 }
0361
0362 template <typename propagator_state_t, typename navigator_t>
0363 double applyBetheHeitler(const propagator_state_t& state,
0364 const navigator_t& navigator,
0365 const BoundTrackParameters& old_bound,
0366 const double old_weight,
0367 std::vector<ComponentCache>& componentCaches,
0368 result_type& result) const {
0369 const auto& surface = *navigator.currentSurface(state.navigation);
0370 const auto p_prev = old_bound.absoluteMomentum();
0371 const auto& particleHypothesis = old_bound.particleHypothesis();
0372
0373
0374 auto slab = surface.surfaceMaterial()->materialSlab(
0375 old_bound.position(state.stepping.geoContext), state.options.direction,
0376 MaterialUpdateStage::FullUpdate);
0377
0378 const auto pathCorrection = surface.pathCorrection(
0379 state.stepping.geoContext,
0380 old_bound.position(state.stepping.geoContext), old_bound.direction());
0381 slab.scaleThickness(pathCorrection);
0382
0383 const double pathXOverX0 = slab.thicknessInX0();
0384 result.maxPathXOverX0.tmp() =
0385 std::max(result.maxPathXOverX0.tmp(), pathXOverX0);
0386
0387
0388 if (!m_cfg.bethe_heitler_approx->validXOverX0(pathXOverX0)) {
0389 ++result.nInvalidBetheHeitler.tmp();
0390 ACTS_DEBUG(
0391 "Bethe-Heitler approximation encountered invalid value for x/x0="
0392 << pathXOverX0 << " at surface " << surface.geometryId());
0393 }
0394
0395
0396 const auto mixture = m_cfg.bethe_heitler_approx->mixture(pathXOverX0);
0397
0398
0399 for (const auto& gaussian : mixture) {
0400
0401
0402 const auto new_weight = gaussian.weight * old_weight;
0403
0404 if (new_weight < m_cfg.weightCutoff) {
0405 ACTS_VERBOSE("Skip component with weight " << new_weight);
0406 continue;
0407 }
0408
0409 if (gaussian.mean < 1.e-8) {
0410 ACTS_WARNING("Skip component with gaussian " << gaussian.mean << " +- "
0411 << gaussian.var);
0412 continue;
0413 }
0414
0415
0416 auto new_pars = old_bound.parameters();
0417
0418 const auto delta_p = [&]() {
0419 if (state.options.direction == Direction::Forward) {
0420 return p_prev * (gaussian.mean - 1.);
0421 } else {
0422 return p_prev * (1. / gaussian.mean - 1.);
0423 }
0424 }();
0425
0426 assert(p_prev + delta_p > 0. && "new momentum must be > 0");
0427 new_pars[eBoundQOverP] =
0428 particleHypothesis.qOverP(p_prev + delta_p, old_bound.charge());
0429
0430
0431 auto new_cov = old_bound.covariance().value();
0432
0433 const auto varInvP = [&]() {
0434 if (state.options.direction == Direction::Forward) {
0435 const auto f = 1. / (p_prev * gaussian.mean);
0436 return f * f * gaussian.var;
0437 } else {
0438 return gaussian.var / (p_prev * p_prev);
0439 }
0440 }();
0441
0442 new_cov(eBoundQOverP, eBoundQOverP) += varInvP;
0443 assert(std::isfinite(new_cov(eBoundQOverP, eBoundQOverP)) &&
0444 "new cov not finite");
0445
0446
0447 componentCaches.push_back({new_weight, new_pars, new_cov});
0448 }
0449
0450 return pathXOverX0;
0451 }
0452
0453
0454
0455
0456
0457 void removeLowWeightComponents(std::vector<ComponentCache>& cmps) const {
0458 auto proj = [](auto& cmp) -> double& { return cmp.weight; };
0459
0460 detail::normalizeWeights(cmps, proj);
0461
0462 auto new_end = std::remove_if(cmps.begin(), cmps.end(), [&](auto& cmp) {
0463 return proj(cmp) < m_cfg.weightCutoff;
0464 });
0465
0466
0467 if (std::distance(cmps.begin(), new_end) == 0) {
0468 cmps = {*std::max_element(
0469 cmps.begin(), cmps.end(),
0470 [&](auto& a, auto& b) { return proj(a) < proj(b); })};
0471 cmps.front().weight = 1.0;
0472 } else {
0473 cmps.erase(new_end, cmps.end());
0474 detail::normalizeWeights(cmps, proj);
0475 }
0476 }
0477
0478
0479 template <typename propagator_state_t, typename stepper_t>
0480 void updateStepper(propagator_state_t& state, const stepper_t& stepper,
0481 const TemporaryStates& tmpStates) const {
0482 auto cmps = stepper.componentIterable(state.stepping);
0483
0484 for (auto [idx, cmp] : zip(tmpStates.tips, cmps)) {
0485
0486
0487 if (tmpStates.weights.at(idx) < m_cfg.weightCutoff) {
0488 cmp.status() = Intersection3D::Status::missed;
0489 continue;
0490 }
0491
0492 auto proxy = tmpStates.traj.getTrackState(idx);
0493
0494 cmp.pars() =
0495 MultiTrajectoryHelpers::freeFiltered(state.options.geoContext, proxy);
0496 cmp.cov() = proxy.filteredCovariance();
0497 cmp.weight() = tmpStates.weights.at(idx);
0498 }
0499
0500 stepper.removeMissedComponents(state.stepping);
0501
0502
0503
0504 detail::normalizeWeights(cmps,
0505 [&](auto cmp) -> double& { return cmp.weight(); });
0506 }
0507
0508
0509 template <typename propagator_state_t, typename stepper_t,
0510 typename navigator_t>
0511 void updateStepper(propagator_state_t& state, const stepper_t& stepper,
0512 const navigator_t& navigator,
0513 const std::vector<ComponentCache>& componentCache) const {
0514 const auto& surface = *navigator.currentSurface(state.navigation);
0515
0516
0517 stepper.clearComponents(state.stepping);
0518
0519
0520 for (const auto& [weight, pars, cov] : componentCache) {
0521
0522 BoundTrackParameters bound(surface.getSharedPtr(), pars, cov,
0523 stepper.particleHypothesis(state.stepping));
0524
0525 auto res = stepper.addComponent(state.stepping, std::move(bound), weight);
0526
0527 if (!res.ok()) {
0528 ACTS_ERROR("Error adding component to MultiStepper");
0529 continue;
0530 }
0531
0532 auto& cmp = *res;
0533 auto freeParams = cmp.pars();
0534 cmp.jacToGlobal() = surface.boundToFreeJacobian(
0535 state.geoContext, freeParams.template segment<3>(eFreePos0),
0536 freeParams.template segment<3>(eFreeDir0));
0537 cmp.pathAccumulated() = state.stepping.pathAccumulated;
0538 cmp.jacobian() = Acts::BoundMatrix::Identity();
0539 cmp.derivative() = Acts::FreeVector::Zero();
0540 cmp.jacTransport() = Acts::FreeMatrix::Identity();
0541 }
0542 }
0543
0544
0545
0546 template <typename propagator_state_t, typename stepper_t,
0547 typename navigator_t>
0548 Result<void> kalmanUpdate(propagator_state_t& state, const stepper_t& stepper,
0549 const navigator_t& navigator, result_type& result,
0550 TemporaryStates& tmpStates,
0551 const SourceLink& source_link) const {
0552 const auto& surface = *navigator.currentSurface(state.navigation);
0553
0554
0555
0556
0557
0558 bool is_valid_measurement = false;
0559
0560 auto cmps = stepper.componentIterable(state.stepping);
0561 for (auto cmp : cmps) {
0562 auto singleState = cmp.singleState(state);
0563 const auto& singleStepper = cmp.singleStepper(stepper);
0564
0565 auto trackStateProxyRes = detail::kalmanHandleMeasurement(
0566 *m_cfg.calibrationContext, singleState, singleStepper,
0567 m_cfg.extensions, surface, source_link, tmpStates.traj,
0568 MultiTrajectoryTraits::kInvalid, false, logger());
0569
0570 if (!trackStateProxyRes.ok()) {
0571 return trackStateProxyRes.error();
0572 }
0573
0574 const auto& trackStateProxy = *trackStateProxyRes;
0575
0576
0577
0578 if (trackStateProxy.typeFlags().test(
0579 Acts::TrackStateFlag::MeasurementFlag)) {
0580 is_valid_measurement = true;
0581 }
0582
0583 tmpStates.tips.push_back(trackStateProxy.index());
0584 tmpStates.weights[tmpStates.tips.back()] = cmp.weight();
0585 }
0586
0587 computePosteriorWeights(tmpStates.traj, tmpStates.tips, tmpStates.weights);
0588
0589 detail::normalizeWeights(tmpStates.tips, [&](auto idx) -> double& {
0590 return tmpStates.weights.at(idx);
0591 });
0592
0593
0594 ++result.processedStates;
0595
0596
0597 if (is_valid_measurement) {
0598 ++result.measurementStates;
0599 }
0600
0601 addCombinedState(result, tmpStates, surface);
0602 result.lastMeasurementTip = result.currentTip;
0603
0604 using FiltProjector =
0605 MultiTrajectoryProjector<StatesType::eFiltered, traj_t>;
0606 FiltProjector proj{tmpStates.traj, tmpStates.weights};
0607
0608 std::vector<std::tuple<double, BoundVector, BoundMatrix>> v;
0609
0610
0611 for (const auto& idx : tmpStates.tips) {
0612 const auto [w, p, c] = proj(idx);
0613 if (w > 0.0) {
0614 v.push_back({w, p, c});
0615 }
0616 }
0617
0618 normalizeWeights(v, [](auto& c) -> double& { return std::get<double>(c); });
0619
0620 result.lastMeasurementState = MultiComponentBoundTrackParameters(
0621 surface.getSharedPtr(), std::move(v),
0622 stepper.particleHypothesis(state.stepping));
0623
0624
0625 return Acts::Result<void>::success();
0626 }
0627
0628 template <typename propagator_state_t, typename stepper_t,
0629 typename navigator_t>
0630 Result<void> noMeasurementUpdate(propagator_state_t& state,
0631 const stepper_t& stepper,
0632 const navigator_t& navigator,
0633 result_type& result,
0634 TemporaryStates& tmpStates,
0635 bool doCovTransport) const {
0636 const auto& surface = *navigator.currentSurface(state.navigation);
0637
0638
0639
0640 bool is_hole = true;
0641
0642 auto cmps = stepper.componentIterable(state.stepping);
0643 for (auto cmp : cmps) {
0644 auto singleState = cmp.singleState(state);
0645 const auto& singleStepper = cmp.singleStepper(stepper);
0646
0647
0648
0649 auto trackStateProxyRes = detail::kalmanHandleNoMeasurement(
0650 singleState, singleStepper, surface, tmpStates.traj,
0651 MultiTrajectoryTraits::kInvalid, doCovTransport, logger());
0652
0653 if (!trackStateProxyRes.ok()) {
0654 return trackStateProxyRes.error();
0655 }
0656
0657 const auto& trackStateProxy = *trackStateProxyRes;
0658
0659 if (!trackStateProxy.typeFlags().test(TrackStateFlag::HoleFlag)) {
0660 is_hole = false;
0661 }
0662
0663 tmpStates.tips.push_back(trackStateProxy.index());
0664 tmpStates.weights[tmpStates.tips.back()] = cmp.weight();
0665 }
0666
0667
0668 if (is_hole) {
0669 ++result.measurementHoles;
0670 }
0671
0672 ++result.processedStates;
0673
0674 addCombinedState(result, tmpStates, surface);
0675
0676 return Result<void>::success();
0677 }
0678
0679
0680 template <typename propagator_state_t, typename stepper_t,
0681 typename navigator_t>
0682 void applyMultipleScattering(propagator_state_t& state,
0683 const stepper_t& stepper,
0684 const navigator_t& navigator,
0685 const MaterialUpdateStage& updateStage =
0686 MaterialUpdateStage::FullUpdate) const {
0687 const auto& surface = *navigator.currentSurface(state.navigation);
0688
0689 for (auto cmp : stepper.componentIterable(state.stepping)) {
0690 auto singleState = cmp.singleState(state);
0691 const auto& singleStepper = cmp.singleStepper(stepper);
0692
0693 detail::PointwiseMaterialInteraction interaction(&surface, singleState,
0694 singleStepper);
0695 if (interaction.evaluateMaterialSlab(singleState, navigator,
0696 updateStage)) {
0697
0698 interaction.evaluatePointwiseMaterialInteraction(
0699 m_cfg.multipleScattering, false);
0700
0701
0702 ACTS_VERBOSE("Material effects on surface: "
0703 << surface.geometryId()
0704 << " at update stage: " << updateStage << " are :");
0705 ACTS_VERBOSE("eLoss = "
0706 << interaction.Eloss << ", "
0707 << "variancePhi = " << interaction.variancePhi << ", "
0708 << "varianceTheta = " << interaction.varianceTheta << ", "
0709 << "varianceQoverP = " << interaction.varianceQoverP);
0710
0711
0712 interaction.updateState(singleState, singleStepper, addNoise);
0713
0714 assert(singleState.stepping.cov.array().isFinite().all() &&
0715 "covariance not finite after multi scattering");
0716 }
0717 }
0718 }
0719
0720 void addCombinedState(result_type& result, const TemporaryStates& tmpStates,
0721 const Surface& surface) const {
0722 using PrtProjector =
0723 MultiTrajectoryProjector<StatesType::ePredicted, traj_t>;
0724 using FltProjector =
0725 MultiTrajectoryProjector<StatesType::eFiltered, traj_t>;
0726
0727 if (!m_cfg.inReversePass) {
0728 const auto firstCmpProxy =
0729 tmpStates.traj.getTrackState(tmpStates.tips.front());
0730 const auto isMeasurement =
0731 firstCmpProxy.typeFlags().test(MeasurementFlag);
0732
0733 const auto mask =
0734 isMeasurement
0735 ? TrackStatePropMask::Calibrated | TrackStatePropMask::Predicted |
0736 TrackStatePropMask::Filtered | TrackStatePropMask::Smoothed
0737 : TrackStatePropMask::Calibrated | TrackStatePropMask::Predicted;
0738
0739 auto proxy = result.fittedStates->makeTrackState(mask, result.currentTip);
0740 result.currentTip = proxy.index();
0741
0742 proxy.setReferenceSurface(surface.getSharedPtr());
0743 proxy.copyFrom(firstCmpProxy, mask);
0744
0745 auto [prtMean, prtCov] =
0746 mergeGaussianMixture(tmpStates.tips, surface, m_cfg.mergeMethod,
0747 PrtProjector{tmpStates.traj, tmpStates.weights});
0748 proxy.predicted() = prtMean;
0749 proxy.predictedCovariance() = prtCov;
0750
0751 if (isMeasurement) {
0752 auto [fltMean, fltCov] = mergeGaussianMixture(
0753 tmpStates.tips, surface, m_cfg.mergeMethod,
0754 FltProjector{tmpStates.traj, tmpStates.weights});
0755 proxy.filtered() = fltMean;
0756 proxy.filteredCovariance() = fltCov;
0757 proxy.smoothed() = BoundVector::Constant(-2);
0758 proxy.smoothedCovariance() = BoundSquareMatrix::Constant(-2);
0759 } else {
0760 proxy.shareFrom(TrackStatePropMask::Predicted,
0761 TrackStatePropMask::Filtered);
0762 }
0763
0764 } else {
0765 assert((result.currentTip != MultiTrajectoryTraits::kInvalid &&
0766 "tip not valid"));
0767
0768 result.fittedStates->applyBackwards(
0769 result.currentTip, [&](auto trackState) {
0770 auto fSurface = &trackState.referenceSurface();
0771 if (fSurface == &surface) {
0772 result.surfacesVisitedBwdAgain.push_back(&surface);
0773
0774 if (trackState.hasSmoothed()) {
0775 const auto [smtMean, smtCov] = mergeGaussianMixture(
0776 tmpStates.tips, surface, m_cfg.mergeMethod,
0777 FltProjector{tmpStates.traj, tmpStates.weights});
0778
0779 trackState.smoothed() = smtMean;
0780 trackState.smoothedCovariance() = smtCov;
0781 }
0782 return false;
0783 }
0784 return true;
0785 });
0786 }
0787 }
0788
0789
0790
0791 void setOptions(const Acts::GsfOptions<traj_t>& options) {
0792 m_cfg.maxComponents = options.maxComponents;
0793 m_cfg.extensions = options.extensions;
0794 m_cfg.abortOnError = options.abortOnError;
0795 m_cfg.disableAllMaterialHandling = options.disableAllMaterialHandling;
0796 m_cfg.weightCutoff = options.weightCutoff;
0797 m_cfg.mergeMethod = options.componentMergeMethod;
0798 m_cfg.calibrationContext = &options.calibrationContext.get();
0799 }
0800 };
0801
0802 }