Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackFittingAlgorithmFunctionsKalman.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackFittingAlgorithmFunctionsKalman.cc
1 #pragma GCC diagnostic push
2 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
4 #pragma GCC diagnostic pop
7 
8 #pragma GCC diagnostic push
9 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
10 #pragma GCC diagnostic ignored "-Wunused-value"
12 #pragma GCC diagnostic pop
13 
20 
22 
23 namespace
24 {
25  using Updater = Acts::GainMatrixUpdater;
26  using Smoother = Acts::GainMatrixSmoother;
32 
33  struct SimpleReverseFilteringLogic
34  {
35  SimpleReverseFilteringLogic() = default;
36  double momentumThreshold = 0.0;
37 
38  bool doBackwardFiltering(
40  {
41  auto momentum = fabs(1 / trackState.filtered()[Acts::eBoundQOverP]);
42  return (momentum <= momentumThreshold);
43  }
44  };
45 
46  template <typename TrackFitterFunction>
47  auto makeKfOptions(const TrackFitterFunction& f,
49  {
51  // cppcheck-suppress constStatement
52  extensions.updater.connect<&Acts::GainMatrixUpdater::operator()<Acts::VectorMultiTrajectory>>(&f.kfUpdater);
53  // cppcheck-suppress constStatement
54  extensions.smoother.connect<&Acts::GainMatrixSmoother::operator()<Acts::VectorMultiTrajectory>>(&f.kfSmoother);
55  extensions.reverseFilteringLogic
56  .connect<&SimpleReverseFilteringLogic::doBackwardFiltering>(
57  &f.reverseFilteringLogic);
58 
60  options.geoContext, options.magFieldContext, options.calibrationContext,
61  extensions, options.propOptions,
62  &(*options.referenceSurface));
63 
64  kfOptions.multipleScattering = f.multipleScattering;
65  kfOptions.energyLoss = f.energyLoss;
66  kfOptions.freeToBoundCorrection = f.freeToBoundCorrection;
67 
68  return kfOptions;
69  }
70 
71  struct TrackFitterFunctionImpl
73  {
74  Fitter trackFitter;
75  ActsSourceLink::SurfaceAccessor m_slSurfaceAccessor;
76 
77  Acts::GainMatrixUpdater kfUpdater;
78  Acts::GainMatrixSmoother kfSmoother;
79  SimpleReverseFilteringLogic reverseFilteringLogic;
80 
81  bool multipleScattering;
82  bool energyLoss;
83  Acts::FreeToBoundCorrection freeToBoundCorrection;
84 
85  TrackFitterFunctionImpl(Fitter&& f,
86  const Acts::TrackingGeometry& trkGeo)
87  : trackFitter(std::move(f))
88  , m_slSurfaceAccessor{trkGeo}
89  , multipleScattering(true)
90  , energyLoss(true)
91  , freeToBoundCorrection(Acts::FreeToBoundCorrection())
92  {
93  }
94 
96  const std::vector<Acts::SourceLink>& sourceLinks,
97  const ActsTrackFittingAlgorithm::TrackParameters& initialParameters,
99  const CalibratorAdapter& calibrator,
101  {
102  auto kfOptions = makeKfOptions(*this, options);
103  kfOptions.extensions.surfaceAccessor
104  .connect<&ActsSourceLink::SurfaceAccessor::operator()>(
105  &m_slSurfaceAccessor);
106  kfOptions.extensions.calibrator
107  .connect<&CalibratorAdapter::calibrate>(
108  &calibrator);
109  return trackFitter.fit(sourceLinks.begin(), sourceLinks.end(),
110  initialParameters, kfOptions, tracks);
111  }
112  };
113 
114  struct DirectedFitterFunctionImpl
116  {
117  DirectFitter fitter;
118  ActsSourceLink::SurfaceAccessor m_slSurfaceAccessor;
119 
120  Acts::GainMatrixUpdater kfUpdater;
121  Acts::GainMatrixSmoother kfSmoother;
122  SimpleReverseFilteringLogic reverseFilteringLogic;
123 
124  bool multipleScattering;
125  bool energyLoss;
126  Acts::FreeToBoundCorrection freeToBoundCorrection;
127 
128  DirectedFitterFunctionImpl(DirectFitter&& f,
129  const Acts::TrackingGeometry& trkGeo)
130  : fitter(std::move(f))
131  , m_slSurfaceAccessor{trkGeo}
132  , multipleScattering(true)
133  , energyLoss(true)
134  , freeToBoundCorrection(Acts::FreeToBoundCorrection())
135  {
136  }
137 
139  const std::vector<Acts::SourceLink>& sourceLinks,
140  const ActsTrackFittingAlgorithm::TrackParameters& initialParameters,
142  const std::vector<const Acts::Surface*>& sSequence,
143  const CalibratorAdapter& calibrator,
144  ActsTrackFittingAlgorithm::TrackContainer& tracks) const override
145  {
146  auto kfOptions = makeKfOptions(*this, options);
147  kfOptions.extensions.calibrator
148  .connect<&CalibratorAdapter::calibrate>(
149  &calibrator);
150  kfOptions.extensions.surfaceAccessor
151  .connect<&ActsSourceLink::SurfaceAccessor::operator()>(
152  &m_slSurfaceAccessor);
153  return fitter.fit(sourceLinks.begin(), sourceLinks.end(), initialParameters,
154  kfOptions, sSequence, tracks);
155  };
156  };
157 
158 } // namespace
159 
160 struct sPHENIXTrackFitterFunctionImpl : public TrackFitterFunctionImpl
161 {
163 
164  bool use_OF = false;
165 
166  void outlierFinder(const ResidualOutlierFinder& finder) override
167  {
168  m_oFinder = finder;
169  use_OF = true;
170  }
171 
173  const Acts::TrackingGeometry& trkGeo)
174  : TrackFitterFunctionImpl(std::move(f), trkGeo)
175  {
176  }
177 
179  const std::vector<Acts::SourceLink>& sourceLinks,
180  const ActsTrackFittingAlgorithm::TrackParameters& initialParameters,
182  const CalibratorAdapter& calibrator,
184  const override
185  {
186  auto kfOptions = makeKfOptions(*this, options);
187  kfOptions.extensions.calibrator.connect<&CalibratorAdapter::calibrate>(
188  &calibrator);
189  kfOptions.extensions.surfaceAccessor
190  .connect<&ActsSourceLink::SurfaceAccessor::operator()>(
191  &m_slSurfaceAccessor);
192  if (use_OF)
193  {
194  kfOptions.extensions.outlierFinder.connect<&ResidualOutlierFinder::operator()>(&m_oFinder);
195  }
196 
197  return trackFitter.fit(sourceLinks.begin(), sourceLinks.end(),
198  initialParameters, kfOptions, tracks);
199  };
200 };
201 
202 std::shared_ptr<ActsTrackFittingAlgorithm::TrackFitterFunction>
204  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
205  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
206  bool multipleScattering, bool energyLoss,
207  double reverseFilteringMomThreshold,
208  Acts::FreeToBoundCorrection freeToBoundCorrection,
209  const Acts::Logger& logger)
210 {
211  Stepper stepper(std::move(magneticField));
212  const auto& geo = *trackingGeometry;
213 
214  Acts::Navigator::Config cfg{trackingGeometry};
215  cfg.resolvePassive = false;
216  cfg.resolveMaterial = true;
217  cfg.resolveSensitive = true;
218  Acts::Navigator navigator(cfg, logger.cloneWithSuffix("Navigator"));
219  Propagator propagator(std::move(stepper), std::move(navigator),
220  logger.cloneWithSuffix("Propagator"));
221  Fitter trackFitter(std::move(propagator), logger.cloneWithSuffix("Fitter"));
222 
223  // build the fitter functions. owns the fitter object.
224  auto fitterFunction =
225  std::make_shared<sPHENIXTrackFitterFunctionImpl>(std::move(trackFitter), geo);
226  fitterFunction->multipleScattering = multipleScattering;
227  fitterFunction->energyLoss = energyLoss;
228  fitterFunction->reverseFilteringLogic.momentumThreshold =
229  reverseFilteringMomThreshold;
230  fitterFunction->freeToBoundCorrection = freeToBoundCorrection;
231 
232  return fitterFunction;
233 }
234 
235 std::shared_ptr<
238  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
239  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
240  bool multipleScattering, bool energyLoss,
241  double reverseFilteringMomThreshold,
242  Acts::FreeToBoundCorrection freeToBoundCorrection,
243  const Acts::Logger& logger)
244 {
245  // construct all components for the fitter
246  const Stepper stepper(std::move(magneticField));
247  const auto& geo = *trackingGeometry;
248 
250  logger.cloneWithSuffix("DirectNavigator")};
251  DirectPropagator propagator(stepper, std::move(navigator),
252  logger.cloneWithSuffix("DirectPropagator"));
253  DirectFitter fitter(std::move(propagator),
254  logger.cloneWithSuffix("DirectFitter"));
255 
256  // build the fitter functions. owns the fitter object.
257  auto fitterFunction =
258  std::make_shared<DirectedFitterFunctionImpl>(std::move(fitter), geo);
259  fitterFunction->multipleScattering = multipleScattering;
260  fitterFunction->energyLoss = energyLoss;
261  fitterFunction->reverseFilteringLogic.momentumThreshold =
262  reverseFilteringMomThreshold;
263  fitterFunction->freeToBoundCorrection = freeToBoundCorrection;
264 
265  return fitterFunction;
266 }