File indexing completed on 2025-01-18 09:11:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Definitions/Direction.hpp"
0010 #include "Acts/Definitions/TrackParametrization.hpp"
0011 #include "Acts/EventData/MultiTrajectory.hpp"
0012 #include "Acts/EventData/TrackContainer.hpp"
0013 #include "Acts/EventData/TrackStatePropMask.hpp"
0014 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0015 #include "Acts/EventData/VectorTrackContainer.hpp"
0016 #include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
0017 #include "Acts/Geometry/GeometryIdentifier.hpp"
0018 #include "Acts/Propagator/DirectNavigator.hpp"
0019 #include "Acts/Propagator/Navigator.hpp"
0020 #include "Acts/Propagator/Propagator.hpp"
0021 #include "Acts/Propagator/SympyStepper.hpp"
0022 #include "Acts/TrackFitting/GainMatrixSmoother.hpp"
0023 #include "Acts/TrackFitting/GainMatrixUpdater.hpp"
0024 #include "Acts/TrackFitting/KalmanFitter.hpp"
0025 #include "Acts/Utilities/Delegate.hpp"
0026 #include "Acts/Utilities/Logger.hpp"
0027 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0028 #include "ActsExamples/EventData/MeasurementCalibration.hpp"
0029 #include "ActsExamples/EventData/Track.hpp"
0030 #include "ActsExamples/TrackFitting/RefittingCalibrator.hpp"
0031 #include "ActsExamples/TrackFitting/TrackFitterFunction.hpp"
0032
0033 #include <algorithm>
0034 #include <cmath>
0035 #include <functional>
0036 #include <memory>
0037 #include <utility>
0038 #include <vector>
0039
0040 namespace Acts {
0041 class MagneticFieldProvider;
0042 class SourceLink;
0043 class Surface;
0044 class TrackingGeometry;
0045 }
0046
0047 namespace {
0048
0049 using Stepper = Acts::SympyStepper;
0050 using Propagator = Acts::Propagator<Stepper, Acts::Navigator>;
0051 using Fitter = Acts::KalmanFitter<Propagator, Acts::VectorMultiTrajectory>;
0052 using DirectPropagator = Acts::Propagator<Stepper, Acts::DirectNavigator>;
0053 using DirectFitter =
0054 Acts::KalmanFitter<DirectPropagator, Acts::VectorMultiTrajectory>;
0055
0056 using TrackContainer =
0057 Acts::TrackContainer<Acts::VectorTrackContainer,
0058 Acts::VectorMultiTrajectory, std::shared_ptr>;
0059
0060 struct SimpleReverseFilteringLogic {
0061 double momentumThreshold = 0;
0062
0063 bool doBackwardFiltering(
0064 Acts::VectorMultiTrajectory::ConstTrackStateProxy trackState) const {
0065 auto momentum = std::abs(1 / trackState.filtered()[Acts::eBoundQOverP]);
0066 return (momentum <= momentumThreshold);
0067 }
0068 };
0069
0070 using namespace ActsExamples;
0071
0072 struct KalmanFitterFunctionImpl final : public TrackFitterFunction {
0073 Fitter fitter;
0074 DirectFitter directFitter;
0075
0076 Acts::GainMatrixUpdater kfUpdater;
0077 Acts::GainMatrixSmoother kfSmoother;
0078 SimpleReverseFilteringLogic reverseFilteringLogic;
0079
0080 bool multipleScattering = false;
0081 bool energyLoss = false;
0082 Acts::FreeToBoundCorrection freeToBoundCorrection;
0083
0084 IndexSourceLink::SurfaceAccessor slSurfaceAccessor;
0085
0086 KalmanFitterFunctionImpl(Fitter&& f, DirectFitter&& df,
0087 const Acts::TrackingGeometry& trkGeo)
0088 : fitter(std::move(f)),
0089 directFitter(std::move(df)),
0090 slSurfaceAccessor{trkGeo} {}
0091
0092 template <typename calibrator_t>
0093 auto makeKfOptions(const GeneralFitterOptions& options,
0094 const calibrator_t& calibrator) const {
0095 Acts::KalmanFitterExtensions<Acts::VectorMultiTrajectory> extensions;
0096 extensions.updater.connect<
0097 &Acts::GainMatrixUpdater::operator()<Acts::VectorMultiTrajectory>>(
0098 &kfUpdater);
0099 extensions.smoother.connect<
0100 &Acts::GainMatrixSmoother::operator()<Acts::VectorMultiTrajectory>>(
0101 &kfSmoother);
0102 extensions.reverseFilteringLogic
0103 .connect<&SimpleReverseFilteringLogic::doBackwardFiltering>(
0104 &reverseFilteringLogic);
0105
0106 Acts::KalmanFitterOptions<Acts::VectorMultiTrajectory> kfOptions(
0107 options.geoContext, options.magFieldContext, options.calibrationContext,
0108 extensions, options.propOptions, &(*options.referenceSurface));
0109
0110 kfOptions.referenceSurfaceStrategy =
0111 Acts::KalmanFitterTargetSurfaceStrategy::first;
0112 kfOptions.multipleScattering = multipleScattering;
0113 kfOptions.energyLoss = energyLoss;
0114 kfOptions.freeToBoundCorrection = freeToBoundCorrection;
0115 kfOptions.extensions.calibrator.connect<&calibrator_t::calibrate>(
0116 &calibrator);
0117
0118 if (options.doRefit) {
0119 kfOptions.extensions.surfaceAccessor
0120 .connect<&RefittingCalibrator::accessSurface>();
0121 } else {
0122 kfOptions.extensions.surfaceAccessor
0123 .connect<&IndexSourceLink::SurfaceAccessor::operator()>(
0124 &slSurfaceAccessor);
0125 }
0126
0127 return kfOptions;
0128 }
0129
0130 TrackFitterResult operator()(const std::vector<Acts::SourceLink>& sourceLinks,
0131 const TrackParameters& initialParameters,
0132 const GeneralFitterOptions& options,
0133 const MeasurementCalibratorAdapter& calibrator,
0134 TrackContainer& tracks) const override {
0135 const auto kfOptions = makeKfOptions(options, calibrator);
0136 return fitter.fit(sourceLinks.begin(), sourceLinks.end(), initialParameters,
0137 kfOptions, tracks);
0138 }
0139
0140 TrackFitterResult operator()(
0141 const std::vector<Acts::SourceLink>& sourceLinks,
0142 const TrackParameters& initialParameters,
0143 const GeneralFitterOptions& options,
0144 const RefittingCalibrator& calibrator,
0145 const std::vector<const Acts::Surface*>& surfaceSequence,
0146 TrackContainer& tracks) const override {
0147 const auto kfOptions = makeKfOptions(options, calibrator);
0148 return directFitter.fit(sourceLinks.begin(), sourceLinks.end(),
0149 initialParameters, kfOptions, surfaceSequence,
0150 tracks);
0151 }
0152 };
0153
0154 }
0155
0156 std::shared_ptr<ActsExamples::TrackFitterFunction>
0157 ActsExamples::makeKalmanFitterFunction(
0158 std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
0159 std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
0160 bool multipleScattering, bool energyLoss,
0161 double reverseFilteringMomThreshold,
0162 Acts::FreeToBoundCorrection freeToBoundCorrection,
0163 const Acts::Logger& logger) {
0164
0165 const Stepper stepper(std::move(magneticField));
0166
0167
0168 const auto& geo = *trackingGeometry;
0169 Acts::Navigator::Config cfg{std::move(trackingGeometry)};
0170 cfg.resolvePassive = false;
0171 cfg.resolveMaterial = true;
0172 cfg.resolveSensitive = true;
0173 Acts::Navigator navigator(cfg, logger.cloneWithSuffix("Navigator"));
0174 Propagator propagator(stepper, std::move(navigator),
0175 logger.cloneWithSuffix("Propagator"));
0176 Fitter trackFitter(std::move(propagator), logger.cloneWithSuffix("Fitter"));
0177
0178
0179 Acts::DirectNavigator directNavigator{
0180 logger.cloneWithSuffix("DirectNavigator")};
0181 DirectPropagator directPropagator(stepper, std::move(directNavigator),
0182 logger.cloneWithSuffix("DirectPropagator"));
0183 DirectFitter directTrackFitter(std::move(directPropagator),
0184 logger.cloneWithSuffix("DirectFitter"));
0185
0186
0187 auto fitterFunction = std::make_shared<KalmanFitterFunctionImpl>(
0188 std::move(trackFitter), std::move(directTrackFitter), geo);
0189 fitterFunction->multipleScattering = multipleScattering;
0190 fitterFunction->energyLoss = energyLoss;
0191 fitterFunction->reverseFilteringLogic.momentumThreshold =
0192 reverseFilteringMomThreshold;
0193 fitterFunction->freeToBoundCorrection = freeToBoundCorrection;
0194
0195 return fitterFunction;
0196 }