Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:07

0001 
0002 #ifndef TRACKBASE_ACTSTRACKFITTINGALGORITHM_H
0003 #define TRACKBASE_ACTSTRACKFITTINGALGORITHM_H
0004 
0005 #include "Calibrator.h"
0006 #include "ResidualOutlierFinder.h"
0007 
0008 #include <Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp>
0009 #include <Acts/EventData/VectorMultiTrajectory.hpp>
0010 #include <Acts/EventData/SourceLink.hpp>
0011 #include <Acts/EventData/TrackParameters.hpp>
0012 #include <Acts/EventData/VectorTrackContainer.hpp>
0013 #include <Acts/Geometry/TrackingGeometry.hpp>
0014 
0015 #pragma GCC diagnostic push // needed for local Act compilation
0016 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
0017 #include <Acts/Propagator/MultiEigenStepperLoop.hpp>
0018 #pragma GCC diagnostic pop
0019 
0020 #include <Acts/TrackFitting/KalmanFitter.hpp>
0021 
0022 #include <functional>
0023 #include <memory>
0024 #include <vector>
0025 
0026 namespace Acts
0027 {
0028   class TrackingGeometry;
0029 }
0030 
0031 class ActsTrackFittingAlgorithm final
0032 {
0033  public:
0034   using TrackParameters = ::Acts::BoundTrackParameters;
0035   using Measurement = ::Acts::BoundVariantMeasurement;
0036   using MeasurementContainer = std::vector<Measurement>;
0037 
0038   using TrackContainer =
0039       Acts::TrackContainer<Acts::VectorTrackContainer,
0040                            Acts::VectorMultiTrajectory, std::shared_ptr>;
0041 
0042   using TrackFitterResult = Acts::Result<TrackContainer::TrackProxy>;
0043 
0044   /// General options that do not depend on the fitter type, but need to be
0045   /// handed over by the algorithm
0046   struct GeneralFitterOptions
0047   {
0048     std::reference_wrapper<const Acts::GeometryContext> geoContext;
0049     std::reference_wrapper<const Acts::MagneticFieldContext> magFieldContext;
0050     std::reference_wrapper<const Acts::CalibrationContext> calibrationContext;
0051     const Acts::Surface* referenceSurface = nullptr;
0052     Acts::PropagatorPlainOptions propOptions;
0053   };
0054 
0055   /// Fit function that takes the above parameters and runs a fit
0056   /// @note This is separated into a virtual interface to keep compilation units
0057   /// small
0058   class TrackFitterFunction
0059   {
0060    public:
0061     virtual ~TrackFitterFunction() = default;
0062     virtual TrackFitterResult operator()(
0063         const std::vector<Acts::SourceLink>&,
0064         const TrackParameters&, const GeneralFitterOptions&,
0065         const CalibratorAdapter&,
0066         TrackContainer&) const = 0;
0067 
0068     virtual void outlierFinder(const ResidualOutlierFinder&) {}
0069   };
0070 
0071   /// Fit function that takes the above parameters plus a sorted surface
0072   /// sequence for the DirectNavigator to follow
0073   /// @note This is separated into a virtual interface to keep compilation units
0074   /// small
0075   class DirectedTrackFitterFunction
0076   {
0077    public:
0078     virtual ~DirectedTrackFitterFunction() = default;
0079 
0080     virtual TrackFitterResult operator()(
0081         const std::vector<Acts::SourceLink>&,
0082         const TrackParameters&, const GeneralFitterOptions&,
0083         const std::vector<const Acts::Surface*>&,
0084         const CalibratorAdapter&,
0085         TrackContainer&) const = 0;
0086   };
0087 
0088   struct Config
0089   {
0090     bool directNavigation;
0091     /// Type erased fitter function.
0092     std::shared_ptr<TrackFitterFunction> fit;
0093     /// Type erased direct navigation fitter function
0094     std::shared_ptr<DirectedTrackFitterFunction> dFit;
0095   };
0096 
0097   /// Constructor of the fitting algorithm
0098   ///
0099   /// @param config is the config struct to configure the algorihtm
0100   /// @param level is the logging level
0101   ActsTrackFittingAlgorithm(Config config, Acts::Logging::Level level);
0102 
0103   /// Get readonly access to the config parameters
0104   const Config& config() const { return m_cfg; }
0105 
0106   /// Create the track fitter function implementation.
0107   ///
0108   /// The magnetic field is intentionally given by-value since the variant
0109   /// contains shared_ptr anyways.
0110   /// @param trackingGeometry
0111   /// @param multipleScattering correct for MCS (mainly for debugging)
0112   /// @param energyLoss correct for e-loss
0113   /// @param reverseFilteringMomThreshold at which threshold
0114   /// @param freeToBoundCorrection Correction for non-linearity effect during transform from free to bound
0115   static std::shared_ptr<TrackFitterFunction> makeKalmanFitterFunction(
0116       const std::shared_ptr<const Acts::TrackingGeometry>& trackingGeometry,
0117       std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
0118       bool multipleScattering = true, bool energyLoss = true,
0119       double reverseFilteringMomThreshold = 0.0,
0120       Acts::FreeToBoundCorrection freeToBoundCorrection =
0121           Acts::FreeToBoundCorrection(),
0122       const Acts::Logger& logger = *Acts::getDefaultLogger("Kalman",
0123                                                            Acts::Logging::FATAL));
0124 
0125   static std::shared_ptr<DirectedTrackFitterFunction> makeDirectedKalmanFitterFunction(
0126       const std::shared_ptr<const Acts::TrackingGeometry>& trackingGeometry,
0127       std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
0128       bool multipleScattering = true, bool energyLoss = true,
0129       double reverseFilteringMomThreshold = 0.0,
0130       Acts::FreeToBoundCorrection freeToBoundCorrection =
0131           Acts::FreeToBoundCorrection(),
0132       const Acts::Logger& logger = *Acts::getDefaultLogger("Kalman",
0133                                                            Acts::Logging::FATAL));
0134 
0135  private:
0136   /// Helper function to call correct FitterFunction
0137   TrackFitterResult fitTrack(
0138       const std::vector<Acts::SourceLink>& sourceLinks,
0139       const TrackParameters& initialParameters,
0140       const GeneralFitterOptions& options,
0141       const std::vector<const Acts::Surface*>& surfSequence,
0142       const CalibratorAdapter& calibrator,
0143       TrackContainer& tracks) const;
0144 
0145   Config m_cfg;
0146 };
0147 
0148 inline ActsTrackFittingAlgorithm::TrackFitterResult
0149 ActsTrackFittingAlgorithm::fitTrack(
0150     const std::vector<Acts::SourceLink>& sourceLinks,
0151     const TrackParameters& initialParameters,
0152     const ActsTrackFittingAlgorithm::GeneralFitterOptions& options,
0153     const std::vector<const Acts::Surface*>& surfSequence,
0154     const CalibratorAdapter& calibrator,
0155     TrackContainer& tracks) const
0156 {
0157   if (m_cfg.directNavigation)
0158   {
0159     return (*m_cfg.dFit)(sourceLinks, initialParameters, options, surfSequence, calibrator, tracks);
0160   }
0161 
0162   return (*m_cfg.fit)(sourceLinks, initialParameters, options, calibrator, tracks);
0163 }
0164 
0165 #endif