File indexing completed on 2025-01-18 09:11:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Definitions/Common.hpp"
0010 #include "Acts/Definitions/Direction.hpp"
0011 #include "Acts/EventData/MultiTrajectory.hpp"
0012 #include "Acts/EventData/TrackContainer.hpp"
0013 #include "Acts/EventData/TrackParameters.hpp"
0014 #include "Acts/EventData/TrackStatePropMask.hpp"
0015 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0016 #include "Acts/EventData/VectorTrackContainer.hpp"
0017 #include "Acts/Geometry/GeometryIdentifier.hpp"
0018 #include "Acts/Propagator/DirectNavigator.hpp"
0019 #include "Acts/Propagator/MultiEigenStepperLoop.hpp"
0020 #include "Acts/Propagator/Navigator.hpp"
0021 #include "Acts/Propagator/Propagator.hpp"
0022 #include "Acts/TrackFitting/GainMatrixUpdater.hpp"
0023 #include "Acts/TrackFitting/GaussianSumFitter.hpp"
0024 #include "Acts/TrackFitting/GsfMixtureReduction.hpp"
0025 #include "Acts/TrackFitting/GsfOptions.hpp"
0026 #include "Acts/Utilities/Delegate.hpp"
0027 #include "Acts/Utilities/HashedString.hpp"
0028 #include "Acts/Utilities/Intersection.hpp"
0029 #include "Acts/Utilities/Logger.hpp"
0030 #include "Acts/Utilities/Zip.hpp"
0031 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0032 #include "ActsExamples/EventData/MeasurementCalibration.hpp"
0033 #include "ActsExamples/EventData/Track.hpp"
0034 #include "ActsExamples/TrackFitting/RefittingCalibrator.hpp"
0035 #include "ActsExamples/TrackFitting/TrackFitterFunction.hpp"
0036
0037 #include <algorithm>
0038 #include <array>
0039 #include <cstddef>
0040 #include <map>
0041 #include <memory>
0042 #include <optional>
0043 #include <string>
0044 #include <string_view>
0045 #include <tuple>
0046 #include <utility>
0047 #include <vector>
0048
0049 namespace Acts {
0050 class MagneticFieldProvider;
0051 class SourceLink;
0052 class Surface;
0053 class TrackingGeometry;
0054 }
0055
0056 using namespace ActsExamples;
0057
0058 namespace {
0059
0060 using MultiStepper =
0061 Acts::MultiEigenStepperLoop<Acts::EigenStepperDefaultExtension,
0062 Acts::MaxWeightReducerLoop>;
0063 using Propagator = Acts::Propagator<MultiStepper, Acts::Navigator>;
0064 using DirectPropagator = Acts::Propagator<MultiStepper, Acts::DirectNavigator>;
0065
0066 using Fitter = Acts::GaussianSumFitter<Propagator, BetheHeitlerApprox,
0067 Acts::VectorMultiTrajectory>;
0068 using DirectFitter =
0069 Acts::GaussianSumFitter<DirectPropagator, BetheHeitlerApprox,
0070 Acts::VectorMultiTrajectory>;
0071 using TrackContainer =
0072 Acts::TrackContainer<Acts::VectorTrackContainer,
0073 Acts::VectorMultiTrajectory, std::shared_ptr>;
0074
0075 struct GsfFitterFunctionImpl final : public ActsExamples::TrackFitterFunction {
0076 Fitter fitter;
0077 DirectFitter directFitter;
0078
0079 Acts::GainMatrixUpdater updater;
0080
0081 std::size_t maxComponents = 0;
0082 double weightCutoff = 0;
0083 const double momentumCutoff = 0;
0084 bool abortOnError = false;
0085 bool disableAllMaterialHandling = false;
0086 MixtureReductionAlgorithm reductionAlg =
0087 MixtureReductionAlgorithm::KLDistance;
0088 Acts::ComponentMergeMethod mergeMethod =
0089 Acts::ComponentMergeMethod::eMaxWeight;
0090
0091 IndexSourceLink::SurfaceAccessor m_slSurfaceAccessor;
0092
0093 GsfFitterFunctionImpl(Fitter&& f, DirectFitter&& df,
0094 const Acts::TrackingGeometry& trkGeo)
0095 : fitter(std::move(f)),
0096 directFitter(std::move(df)),
0097 m_slSurfaceAccessor{trkGeo} {}
0098
0099 template <typename calibrator_t>
0100 auto makeGsfOptions(const GeneralFitterOptions& options,
0101 const calibrator_t& calibrator) const {
0102 Acts::GsfExtensions<Acts::VectorMultiTrajectory> extensions;
0103 extensions.updater.connect<
0104 &Acts::GainMatrixUpdater::operator()<Acts::VectorMultiTrajectory>>(
0105 &updater);
0106
0107 Acts::GsfOptions<Acts::VectorMultiTrajectory> gsfOptions{
0108 options.geoContext, options.magFieldContext,
0109 options.calibrationContext};
0110 gsfOptions.extensions = extensions;
0111 gsfOptions.propagatorPlainOptions = options.propOptions;
0112 gsfOptions.referenceSurface = options.referenceSurface;
0113 gsfOptions.maxComponents = maxComponents;
0114 gsfOptions.weightCutoff = weightCutoff;
0115 gsfOptions.abortOnError = abortOnError;
0116 gsfOptions.disableAllMaterialHandling = disableAllMaterialHandling;
0117 gsfOptions.componentMergeMethod = mergeMethod;
0118
0119 gsfOptions.extensions.calibrator.connect<&calibrator_t::calibrate>(
0120 &calibrator);
0121
0122 if (options.doRefit) {
0123 gsfOptions.extensions.surfaceAccessor
0124 .connect<&RefittingCalibrator::accessSurface>();
0125 } else {
0126 gsfOptions.extensions.surfaceAccessor
0127 .connect<&IndexSourceLink::SurfaceAccessor::operator()>(
0128 &m_slSurfaceAccessor);
0129 }
0130 switch (reductionAlg) {
0131 case MixtureReductionAlgorithm::weightCut: {
0132 gsfOptions.extensions.mixtureReducer
0133 .connect<&Acts::reduceMixtureLargestWeights>();
0134 } break;
0135 case MixtureReductionAlgorithm::KLDistance: {
0136 gsfOptions.extensions.mixtureReducer
0137 .connect<&Acts::reduceMixtureWithKLDistance>();
0138 } break;
0139 }
0140
0141 return gsfOptions;
0142 }
0143
0144 TrackFitterResult operator()(const std::vector<Acts::SourceLink>& sourceLinks,
0145 const TrackParameters& initialParameters,
0146 const GeneralFitterOptions& options,
0147 const MeasurementCalibratorAdapter& calibrator,
0148 TrackContainer& tracks) const override {
0149 const auto gsfOptions = makeGsfOptions(options, calibrator);
0150
0151 using namespace Acts::GsfConstants;
0152 if (!tracks.hasColumn(Acts::hashString(kFinalMultiComponentStateColumn))) {
0153 std::string key(kFinalMultiComponentStateColumn);
0154 tracks.template addColumn<FinalMultiComponentState>(key);
0155 }
0156
0157 if (!tracks.hasColumn(Acts::hashString(kFwdMaxMaterialXOverX0))) {
0158 tracks.template addColumn<double>(std::string(kFwdMaxMaterialXOverX0));
0159 }
0160
0161 if (!tracks.hasColumn(Acts::hashString(kFwdSumMaterialXOverX0))) {
0162 tracks.template addColumn<double>(std::string(kFwdSumMaterialXOverX0));
0163 }
0164
0165 return fitter.fit(sourceLinks.begin(), sourceLinks.end(), initialParameters,
0166 gsfOptions, tracks);
0167 }
0168
0169 TrackFitterResult operator()(
0170 const std::vector<Acts::SourceLink>& sourceLinks,
0171 const TrackParameters& initialParameters,
0172 const GeneralFitterOptions& options,
0173 const RefittingCalibrator& calibrator,
0174 const std::vector<const Acts::Surface*>& surfaceSequence,
0175 TrackContainer& tracks) const override {
0176 const auto gsfOptions = makeGsfOptions(options, calibrator);
0177
0178 using namespace Acts::GsfConstants;
0179 if (!tracks.hasColumn(Acts::hashString(kFinalMultiComponentStateColumn))) {
0180 std::string key(kFinalMultiComponentStateColumn);
0181 tracks.template addColumn<FinalMultiComponentState>(key);
0182 }
0183
0184 return directFitter.fit(sourceLinks.begin(), sourceLinks.end(),
0185 initialParameters, gsfOptions, surfaceSequence,
0186 tracks);
0187 }
0188 };
0189
0190 }
0191
0192 std::shared_ptr<TrackFitterFunction> ActsExamples::makeGsfFitterFunction(
0193 std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
0194 std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
0195 BetheHeitlerApprox betheHeitlerApprox, std::size_t maxComponents,
0196 double weightCutoff, Acts::ComponentMergeMethod componentMergeMethod,
0197 MixtureReductionAlgorithm mixtureReductionAlgorithm,
0198 const Acts::Logger& logger) {
0199
0200 MultiStepper stepper(magneticField, logger.cloneWithSuffix("Step"));
0201 const auto& geo = *trackingGeometry;
0202 Acts::Navigator::Config cfg{std::move(trackingGeometry)};
0203 cfg.resolvePassive = false;
0204 cfg.resolveMaterial = true;
0205 cfg.resolveSensitive = true;
0206 Acts::Navigator navigator(cfg, logger.cloneWithSuffix("Navigator"));
0207 Propagator propagator(std::move(stepper), std::move(navigator),
0208 logger.cloneWithSuffix("Propagator"));
0209 Fitter trackFitter(std::move(propagator),
0210 BetheHeitlerApprox(betheHeitlerApprox),
0211 logger.cloneWithSuffix("GSF"));
0212
0213
0214 MultiStepper directStepper(std::move(magneticField),
0215 logger.cloneWithSuffix("Step"));
0216 Acts::DirectNavigator directNavigator{
0217 logger.cloneWithSuffix("DirectNavigator")};
0218 DirectPropagator directPropagator(std::move(directStepper),
0219 std::move(directNavigator),
0220 logger.cloneWithSuffix("DirectPropagator"));
0221 DirectFitter directTrackFitter(std::move(directPropagator),
0222 BetheHeitlerApprox(betheHeitlerApprox),
0223 logger.cloneWithSuffix("DirectGSF"));
0224
0225
0226 auto fitterFunction = std::make_shared<GsfFitterFunctionImpl>(
0227 std::move(trackFitter), std::move(directTrackFitter), geo);
0228 fitterFunction->maxComponents = maxComponents;
0229 fitterFunction->weightCutoff = weightCutoff;
0230 fitterFunction->mergeMethod = componentMergeMethod;
0231 fitterFunction->reductionAlg = mixtureReductionAlgorithm;
0232
0233 return fitterFunction;
0234 }