Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackFitting.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackFitting.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021-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 
22 
23 #include <cstddef>
24 #include <memory>
25 #include <vector>
26 
27 #include <pybind11/pybind11.h>
28 #include <pybind11/stl.h>
29 
30 namespace Acts {
32 class TrackingGeometry;
33 } // namespace Acts
34 namespace ActsExamples {
35 class IAlgorithm;
36 } // namespace ActsExamples
37 
38 namespace py = pybind11;
39 
40 using namespace ActsExamples;
41 using namespace Acts;
42 
43 namespace Acts::Python {
44 
46  auto mex = ctx.get("examples");
47 
49  "SurfaceSortingAlgorithm", inputProtoTracks,
50  inputSimHits, inputMeasurementSimHitsMap,
51  outputProtoTracks);
52 
54  "TrackFittingAlgorithm", inputMeasurements,
55  inputSourceLinks, inputProtoTracks,
56  inputInitialTrackParameters, inputClusters,
57  outputTracks, fit, pickTrack, calibrator);
58 
60  "RefittingAlgorithm", inputTracks, outputTracks,
61  fit, pickTrack);
62 
63  {
64  py::class_<TrackFitterFunction, std::shared_ptr<TrackFitterFunction>>(
65  mex, "TrackFitterFunction");
66 
67  mex.def(
68  "makeKalmanFitterFunction",
69  [](std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
70  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
71  bool multipleScattering, bool energyLoss,
72  double reverseFilteringMomThreshold,
73  Acts::FreeToBoundCorrection freeToBoundCorrection,
76  trackingGeometry, magneticField, multipleScattering, energyLoss,
77  reverseFilteringMomThreshold, freeToBoundCorrection,
78  *Acts::getDefaultLogger("Kalman", level));
79  },
80  py::arg("trackingGeometry"), py::arg("magneticField"),
81  py::arg("multipleScattering"), py::arg("energyLoss"),
82  py::arg("reverseFilteringMomThreshold"),
83  py::arg("freeToBoundCorrection"), py::arg("level"));
84 
85  py::class_<MeasurementCalibrator, std::shared_ptr<MeasurementCalibrator>>(
86  mex, "MeasurementCalibrator");
87 
88  mex.def("makePassThroughCalibrator",
89  []() -> std::shared_ptr<MeasurementCalibrator> {
90  return std::make_shared<PassThroughCalibrator>();
91  });
92 
93  mex.def(
94  "makeScalingCalibrator",
95  [](const char* path) -> std::shared_ptr<MeasurementCalibrator> {
96  return std::make_shared<ActsExamples::ScalingCalibrator>(path);
97  },
98  py::arg("path"));
99 
100  py::enum_<Acts::MixtureReductionMethod>(mex, "FinalReductionMethod")
101  .value("mean", Acts::MixtureReductionMethod::eMean)
102  .value("maxWeight", Acts::MixtureReductionMethod::eMaxWeight);
103 
104  py::class_<ActsExamples::BetheHeitlerApprox>(mex, "AtlasBetheHeitlerApprox")
105  .def_static("loadFromFiles",
107  py::arg("lowParametersPath"), py::arg("lowParametersPath"))
108  .def_static("makeDefault",
109  []() { return Acts::makeDefaultBetheHeitlerApprox(); });
110 
111  mex.def(
112  "makeGsfFitterFunction",
113  [](std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
114  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
115  BetheHeitlerApprox betheHeitlerApprox, std::size_t maxComponents,
116  double weightCutoff,
117  Acts::MixtureReductionMethod finalReductionMethod, bool abortOnError,
118  bool disableAllMaterialHandling, Logging::Level level) {
120  trackingGeometry, magneticField, betheHeitlerApprox,
121  maxComponents, weightCutoff, finalReductionMethod, abortOnError,
122  disableAllMaterialHandling,
123  *Acts::getDefaultLogger("GSFFunc", level));
124  },
125  py::arg("trackingGeometry"), py::arg("magneticField"),
126  py::arg("betheHeitlerApprox"), py::arg("maxComponents"),
127  py::arg("weightCutoff"), py::arg("finalReductionMethod"),
128  py::arg("abortOnError"), py::arg("disableAllMaterialHandling"),
129  py::arg("level"));
130 
131  mex.def(
132  "makeGlobalChiSquareFitterFunction",
133  [](std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
134  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
135  bool multipleScattering, bool energyLoss,
136  Acts::FreeToBoundCorrection freeToBoundCorrection,
137  Logging::Level level) {
139  trackingGeometry, magneticField, multipleScattering, energyLoss,
140  freeToBoundCorrection, *Acts::getDefaultLogger("Gx2f", level));
141  },
142  py::arg("trackingGeometry"), py::arg("magneticField"),
143  py::arg("multipleScattering"), py::arg("energyLoss"),
144  py::arg("freeToBoundCorrection"), py::arg("level"));
145 
146  // TODO add other important parameters like nUpdates
147  // TODO add also in trackfitterfunction
148  }
149 
150  {
151  py::class_<FreeToBoundCorrection>(mex, "FreeToBoundCorrection")
152  .def(py::init<>())
153  .def(py::init<bool>(), py::arg("apply") = false)
154  .def(py::init<bool, double, double>(), py::arg("apply") = false,
155  py::arg("alpha") = 0.1, py::arg("beta") = 2);
156  }
157 }
158 
159 } // namespace Acts::Python