Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Propagation.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Propagation.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 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 
21 
22 #include <algorithm>
23 #include <array>
24 #include <map>
25 #include <memory>
26 #include <optional>
27 #include <string>
28 #include <tuple>
29 #include <utility>
30 #include <vector>
31 
32 #include <pybind11/pybind11.h>
33 #include <pybind11/stl.h>
34 
35 namespace Acts {
36 class MagneticFieldProvider;
37 } // namespace Acts
38 
39 namespace py = pybind11;
40 
41 namespace {
42 
43 template <typename stepper_t, typename navigator_t>
44 void addPropagator(py::module_& m, const std::string& prefix) {
46  py::class_<propagator_t>(m, (prefix + "Propagator").c_str())
47  .def(py::init<>(
48  [=](stepper_t stepper, navigator_t navigator,
50  return propagator_t{
51  std::move(stepper), std::move(navigator),
52  Acts::getDefaultLogger(prefix + "Propagator", level)};
53  }),
54  py::arg("stepper"), py::arg("navigator"),
55  py::arg("level") = Acts::Logging::INFO);
56 
58  py::class_<prop_if_t, ActsExamples::PropagatorInterface,
59  std::shared_ptr<prop_if_t>>(
60  m, (prefix + "ConcretePropagator").c_str())
61  .def(py::init<propagator_t>());
62 }
63 
64 } // namespace
65 
66 namespace Acts::Python {
67 void addPropagation(Context& ctx) {
68  auto [m, prop, mex] = ctx.get("main", "propagation", "examples");
69 
70  {
72  auto nav =
73  py::class_<Acts::Navigator, std::shared_ptr<Acts::Navigator>>(
74  m, "Navigator")
75  .def(py::init<>([](Config cfg,
77  return Navigator{cfg, getDefaultLogger("Navigator", level)};
78  }),
79  py::arg("cfg"), py::arg("level") = Logging::INFO);
80 
81  auto c = py::class_<Config>(nav, "Config").def(py::init<>());
82 
84  ACTS_PYTHON_MEMBER(resolveMaterial);
85  ACTS_PYTHON_MEMBER(resolvePassive);
86  ACTS_PYTHON_MEMBER(resolveSensitive);
89  }
90 
91  {
93  auto nav =
95  std::shared_ptr<Acts::Experimental::DetectorNavigator>>(
96  m, "DetectorNavigator")
97  .def(py::init<>(
99  return Acts::Experimental::DetectorNavigator{
100  cfg, getDefaultLogger("DetectorNavigator", level)};
101  }),
102  py::arg("cfg"), py::arg("level") = Logging::INFO);
103 
104  auto c = py::class_<Config>(nav, "Config").def(py::init<>());
105 
107  ACTS_PYTHON_MEMBER(resolveMaterial);
108  ACTS_PYTHON_MEMBER(resolvePassive);
109  ACTS_PYTHON_MEMBER(resolveSensitive);
112  }
113 
115  ActsExamples::PropagationAlgorithm, mex, "PropagationAlgorithm",
116  propagatorImpl, randomNumberSvc, mode, sterileLogger, debugOutput,
117  energyLoss, multipleScattering, recordMaterialInteractions, ntests,
118  d0Sigma, z0Sigma, phiSigma, thetaSigma, qpSigma, tSigma, phiRange,
119  etaRange, ptRange, particleHypothesis, ptLoopers, maxStepSize,
120  propagationStepCollection, propagationMaterialCollection,
121  covarianceTransport, covariances, correlations);
122 
123  py::class_<ActsExamples::PropagatorInterface,
124  std::shared_ptr<ActsExamples::PropagatorInterface>>(
125  mex, "PropagatorInterface");
126 
127  {
128  auto stepper = py::class_<Acts::EigenStepper<>>(m, "EigenStepper");
129  stepper.def(
130  // Add custom constructor lambda so that not specifying the overstep
131  // limit takes the default from C++ EigenStepper
132  py::init(
133  [](std::shared_ptr<const Acts::MagneticFieldProvider> bField,
134  std::optional<double> overstepLimit) -> Acts::EigenStepper<> {
135  if (overstepLimit) {
136  return {std::move(bField), overstepLimit.value()};
137  } else {
138  return {std::move(bField)};
139  }
140  }),
141  py::arg("bField"), py::arg("overstepLimit") = std::nullopt);
142 
143  addPropagator<Acts::EigenStepper<>, Acts::Navigator>(prop, "Eigen");
144  }
145 
146  {
147  addPropagator<Acts::EigenStepper<>, Acts::Experimental::DetectorNavigator>(
148  prop, "EigenNext");
149  }
150 
151  {
152  auto stepper = py::class_<Acts::AtlasStepper>(m, "AtlasStepper");
153  stepper.def(py::init<std::shared_ptr<const Acts::MagneticFieldProvider>>());
154 
155  addPropagator<Acts::AtlasStepper, Acts::Navigator>(prop, "Atlas");
156  }
157 
158  {
159  auto stepper =
160  py::class_<Acts::StraightLineStepper>(m, "StraightLineStepper");
161  stepper.def(py::init<>());
162 
163  addPropagator<Acts::StraightLineStepper, Acts::Navigator>(prop,
164  "StraightLine");
165  }
166 }
167 
168 } // namespace Acts::Python