Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GsfFitterFunction.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GsfFitterFunction.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
31 #include "Acts/Utilities/Zip.hpp"
37 
38 #include <algorithm>
39 #include <array>
40 #include <cstddef>
41 #include <map>
42 #include <memory>
43 #include <optional>
44 #include <string>
45 #include <string_view>
46 #include <tuple>
47 #include <utility>
48 #include <vector>
49 
50 namespace Acts {
51 class MagneticFieldProvider;
52 class SourceLink;
53 class Surface;
54 class TrackingGeometry;
55 } // namespace Acts
56 
57 using namespace ActsExamples;
58 
59 namespace {
60 
61 using MultiStepper = Acts::MultiEigenStepperLoop<>;
64 
67 using DirectFitter =
70 using TrackContainer =
72  Acts::VectorMultiTrajectory, std::shared_ptr>;
73 
74 struct GsfFitterFunctionImpl final : public ActsExamples::TrackFitterFunction {
75  Fitter fitter;
76  DirectFitter directFitter;
77 
79 
80  std::size_t maxComponents = 0;
81  double weightCutoff = 0;
82  bool abortOnError = false;
83  bool disableAllMaterialHandling = false;
84  Acts::MixtureReductionMethod reductionMethod =
85  Acts::MixtureReductionMethod::eMaxWeight;
86 
87  IndexSourceLink::SurfaceAccessor m_slSurfaceAccessor;
88 
89  GsfFitterFunctionImpl(Fitter&& f, DirectFitter&& df,
90  const Acts::TrackingGeometry& trkGeo)
91  : fitter(std::move(f)),
92  directFitter(std::move(df)),
93  m_slSurfaceAccessor{trkGeo} {}
94 
95  template <typename calibrator_t>
96  auto makeGsfOptions(const GeneralFitterOptions& options,
97  const calibrator_t& calibrator) const {
99  extensions.updater.connect<
100  &Acts::GainMatrixUpdater::operator()<Acts::VectorMultiTrajectory>>(
101  &updater);
102 
104  options.geoContext,
105  options.magFieldContext,
106  options.calibrationContext,
107  extensions,
108  options.propOptions,
109  &(*options.referenceSurface),
110  maxComponents,
111  weightCutoff,
112  abortOnError,
113  disableAllMaterialHandling};
114  gsfOptions.stateReductionMethod = reductionMethod;
115 
116  gsfOptions.extensions.calibrator.connect<&calibrator_t::calibrate>(
117  &calibrator);
118  gsfOptions.extensions.surfaceAccessor
119  .connect<&IndexSourceLink::SurfaceAccessor::operator()>(
120  &m_slSurfaceAccessor);
121  gsfOptions.extensions.mixtureReducer
123 
124  return gsfOptions;
125  }
126 
127  TrackFitterResult operator()(const std::vector<Acts::SourceLink>& sourceLinks,
128  const TrackParameters& initialParameters,
129  const GeneralFitterOptions& options,
130  const MeasurementCalibratorAdapter& calibrator,
131  TrackContainer& tracks) const override {
132  const auto gsfOptions = makeGsfOptions(options, calibrator);
133 
134  using namespace Acts::GsfConstants;
135  if (not tracks.hasColumn(
138  tracks.template addColumn<FinalMultiComponentState>(key);
139  }
140 
141  return fitter.fit(sourceLinks.begin(), sourceLinks.end(), initialParameters,
142  gsfOptions, tracks);
143  }
144 
145  TrackFitterResult operator()(
146  const std::vector<Acts::SourceLink>& sourceLinks,
147  const TrackParameters& initialParameters,
148  const GeneralFitterOptions& options,
149  const RefittingCalibrator& calibrator,
150  const std::vector<const Acts::Surface*>& surfaceSequence,
151  TrackContainer& tracks) const override {
152  const auto gsfOptions = makeGsfOptions(options, calibrator);
153 
154  using namespace Acts::GsfConstants;
155  if (not tracks.hasColumn(
158  tracks.template addColumn<FinalMultiComponentState>(key);
159  }
160 
161  return directFitter.fit(sourceLinks.begin(), sourceLinks.end(),
162  initialParameters, gsfOptions, surfaceSequence,
163  tracks);
164  }
165 };
166 
167 } // namespace
168 
169 std::shared_ptr<TrackFitterFunction> ActsExamples::makeGsfFitterFunction(
170  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
171  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
172  BetheHeitlerApprox betheHeitlerApprox, std::size_t maxComponents,
173  double weightCutoff, Acts::MixtureReductionMethod finalReductionMethod,
174  bool abortOnError, bool disableAllMaterialHandling,
175  const Acts::Logger& logger) {
176  // Standard fitter
177  MultiStepper stepper(magneticField, logger.cloneWithSuffix("Step"));
178  const auto& geo = *trackingGeometry;
179  Acts::Navigator::Config cfg{std::move(trackingGeometry)};
180  cfg.resolvePassive = false;
181  cfg.resolveMaterial = true;
182  cfg.resolveSensitive = true;
183  Acts::Navigator navigator(cfg, logger.cloneWithSuffix("Navigator"));
185  logger.cloneWithSuffix("Propagator"));
186  Fitter trackFitter(std::move(propagator),
187  BetheHeitlerApprox(betheHeitlerApprox),
188  logger.cloneWithSuffix("GSF"));
189 
190  // Direct fitter
191  MultiStepper directStepper(std::move(magneticField),
192  logger.cloneWithSuffix("Step"));
193  Acts::DirectNavigator directNavigator{
194  logger.cloneWithSuffix("DirectNavigator")};
195  DirectPropagator directPropagator(std::move(directStepper),
196  std::move(directNavigator),
197  logger.cloneWithSuffix("DirectPropagator"));
198  DirectFitter directTrackFitter(std::move(directPropagator),
199  BetheHeitlerApprox(betheHeitlerApprox),
200  logger.cloneWithSuffix("DirectGSF"));
201 
202  // build the fitter functions. owns the fitter object.
203  auto fitterFunction = std::make_shared<GsfFitterFunctionImpl>(
204  std::move(trackFitter), std::move(directTrackFitter), geo);
205  fitterFunction->maxComponents = maxComponents;
206  fitterFunction->weightCutoff = weightCutoff;
207  fitterFunction->abortOnError = abortOnError;
208  fitterFunction->disableAllMaterialHandling = disableAllMaterialHandling;
209  fitterFunction->reductionMethod = finalReductionMethod;
210 
211  return fitterFunction;
212 }