Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlobalChiSquareFitterFunction.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GlobalChiSquareFitterFunction.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
9 // TODO We still use some Kalman Fitter functionalities. Check for replacement
10 
33 
34 #include <algorithm>
35 #include <cmath>
36 #include <functional>
37 #include <memory>
38 #include <utility>
39 #include <vector>
40 
41 namespace Acts {
42 class MagneticFieldProvider;
43 class SourceLink;
44 class Surface;
45 class TrackingGeometry;
46 } // namespace Acts
47 
48 namespace {
49 
52 using Fitter =
55 using DirectFitter =
57 
58 using TrackContainer =
60  Acts::VectorMultiTrajectory, std::shared_ptr>;
61 
62 using namespace ActsExamples;
63 
64 struct GlobalChiSquareFitterFunctionImpl final : public TrackFitterFunction {
65  Fitter fitter;
66  DirectFitter directFitter;
67 
68  bool multipleScattering = false;
69  bool energyLoss = false;
70  Acts::FreeToBoundCorrection freeToBoundCorrection;
71 
72  IndexSourceLink::SurfaceAccessor m_slSurfaceAccessor;
73 
74  GlobalChiSquareFitterFunctionImpl(Fitter&& f, DirectFitter&& df,
75  const Acts::TrackingGeometry& trkGeo)
76  : fitter(std::move(f)),
77  directFitter(std::move(df)),
78  m_slSurfaceAccessor{trkGeo} {}
79 
80  template <typename calibrator_t>
81  auto makeGx2fOptions(const GeneralFitterOptions& options,
82  const calibrator_t& calibrator) const {
84  extensions;
85  extensions.calibrator.connect<&calibrator_t::calibrate>(&calibrator);
86 
87  extensions.surfaceAccessor
88  .connect<&IndexSourceLink::SurfaceAccessor::operator()>(
89  &m_slSurfaceAccessor);
90 
91  const Acts::Experimental::Gx2FitterOptions gx2fOptions(
92  options.geoContext, options.magFieldContext, options.calibrationContext,
93  extensions, options.propOptions, &(*options.referenceSurface),
94  multipleScattering, energyLoss, freeToBoundCorrection, 5);
95 
96  return gx2fOptions;
97  }
98 
99  TrackFitterResult operator()(const std::vector<Acts::SourceLink>& sourceLinks,
100  const TrackParameters& initialParameters,
101  const GeneralFitterOptions& options,
102  const MeasurementCalibratorAdapter& calibrator,
103  TrackContainer& tracks) const override {
104  const auto gx2fOptions = makeGx2fOptions(options, calibrator);
105  return fitter.fit(sourceLinks.begin(), sourceLinks.end(), initialParameters,
106  gx2fOptions, tracks);
107  }
108 
109  // We need a placeholder for the directNavigator overload. Otherwise, we would
110  // have an unimplemented pure virtual method in a final class.
111  TrackFitterResult operator()(
112  const std::vector<Acts::SourceLink>& /*sourceLinks*/,
113  const TrackParameters& /*initialParameters*/,
114  const GeneralFitterOptions& /*options*/,
115  const RefittingCalibrator& /*calibrator*/,
116  const std::vector<const Acts::Surface*>& /*surfaceSequence*/,
117  TrackContainer& /*tracks*/) const override {
118  throw std::runtime_error(
119  "direct navigation with GX2 fitter is not implemented");
120  }
121 };
122 
123 } // namespace
124 
125 std::shared_ptr<ActsExamples::TrackFitterFunction>
127  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
128  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
129  bool multipleScattering, bool energyLoss,
130  Acts::FreeToBoundCorrection freeToBoundCorrection,
131  const Acts::Logger& logger) {
132  // Stepper should be copied into the fitters
133  const Stepper stepper(std::move(magneticField));
134 
135  // Standard fitter
136  const auto& geo = *trackingGeometry;
137  Acts::Navigator::Config cfg{std::move(trackingGeometry)};
138  cfg.resolvePassive = false;
139  cfg.resolveMaterial = true;
140  cfg.resolveSensitive = true;
141  Acts::Navigator navigator(cfg, logger.cloneWithSuffix("Navigator"));
142  Propagator propagator(stepper, std::move(navigator),
143  logger.cloneWithSuffix("Propagator"));
144  Fitter trackFitter(std::move(propagator), logger.cloneWithSuffix("Fitter"));
145 
146  // Direct fitter
147  Acts::DirectNavigator directNavigator{
148  logger.cloneWithSuffix("DirectNavigator")};
149  DirectPropagator directPropagator(stepper, std::move(directNavigator),
150  logger.cloneWithSuffix("DirectPropagator"));
151  DirectFitter directTrackFitter(std::move(directPropagator),
152  logger.cloneWithSuffix("DirectFitter"));
153 
154  // build the fitter function. owns the fitter object.
155  auto fitterFunction = std::make_shared<GlobalChiSquareFitterFunctionImpl>(
156  std::move(trackFitter), std::move(directTrackFitter), geo);
157  fitterFunction->multipleScattering = multipleScattering;
158  fitterFunction->energyLoss = energyLoss;
159  fitterFunction->freeToBoundCorrection = freeToBoundCorrection;
160 
161  return fitterFunction;
162 }