Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:06

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2021 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Definitions/Direction.hpp"
0010 #include "Acts/EventData/TrackParameters.hpp"
0011 #include "Acts/Navigation/DetectorNavigator.hpp"
0012 #include "Acts/Plugins/Python/Utilities.hpp"
0013 #include "Acts/Propagator/AtlasStepper.hpp"
0014 #include "Acts/Propagator/EigenStepper.hpp"
0015 #include "Acts/Propagator/Navigator.hpp"
0016 #include "Acts/Propagator/Propagator.hpp"
0017 #include "Acts/Propagator/StraightLineStepper.hpp"
0018 #include "Acts/Utilities/Logger.hpp"
0019 #include "ActsExamples/Propagation/PropagationAlgorithm.hpp"
0020 #include "ActsExamples/Propagation/PropagatorInterface.hpp"
0021 
0022 #include <algorithm>
0023 #include <array>
0024 #include <map>
0025 #include <memory>
0026 #include <optional>
0027 #include <string>
0028 #include <tuple>
0029 #include <utility>
0030 #include <vector>
0031 
0032 #include <pybind11/pybind11.h>
0033 #include <pybind11/stl.h>
0034 
0035 namespace Acts {
0036 class MagneticFieldProvider;
0037 }  // namespace Acts
0038 
0039 namespace py = pybind11;
0040 
0041 namespace {
0042 
0043 template <typename stepper_t, typename navigator_t>
0044 void addPropagator(py::module_& m, const std::string& prefix) {
0045   using propagator_t = Acts::Propagator<stepper_t, navigator_t>;
0046   py::class_<propagator_t>(m, (prefix + "Propagator").c_str())
0047       .def(py::init<>(
0048                [=](stepper_t stepper, navigator_t navigator,
0049                    Acts::Logging::Level level = Acts::Logging::Level::INFO) {
0050                  return propagator_t{
0051                      std::move(stepper), std::move(navigator),
0052                      Acts::getDefaultLogger(prefix + "Propagator", level)};
0053                }),
0054            py::arg("stepper"), py::arg("navigator"),
0055            py::arg("level") = Acts::Logging::INFO);
0056 
0057   using prop_if_t = ActsExamples::ConcretePropagator<propagator_t>;
0058   py::class_<prop_if_t, ActsExamples::PropagatorInterface,
0059              std::shared_ptr<prop_if_t>>(
0060       m, (prefix + "ConcretePropagator").c_str())
0061       .def(py::init<propagator_t>());
0062 }
0063 
0064 }  // namespace
0065 
0066 namespace Acts::Python {
0067 void addPropagation(Context& ctx) {
0068   auto [m, prop, mex] = ctx.get("main", "propagation", "examples");
0069 
0070   {
0071     using Config = Acts::Navigator::Config;
0072     auto nav =
0073         py::class_<Acts::Navigator, std::shared_ptr<Acts::Navigator>>(
0074             m, "Navigator")
0075             .def(py::init<>([](Config cfg,
0076                                Logging::Level level = Logging::INFO) {
0077                    return Navigator{cfg, getDefaultLogger("Navigator", level)};
0078                  }),
0079                  py::arg("cfg"), py::arg("level") = Logging::INFO);
0080 
0081     auto c = py::class_<Config>(nav, "Config").def(py::init<>());
0082 
0083     ACTS_PYTHON_STRUCT_BEGIN(c, Config);
0084     ACTS_PYTHON_MEMBER(resolveMaterial);
0085     ACTS_PYTHON_MEMBER(resolvePassive);
0086     ACTS_PYTHON_MEMBER(resolveSensitive);
0087     ACTS_PYTHON_MEMBER(trackingGeometry);
0088     ACTS_PYTHON_STRUCT_END();
0089   }
0090 
0091   {
0092     using Config = Acts::Experimental::DetectorNavigator::Config;
0093     auto nav =
0094         py::class_<Acts::Experimental::DetectorNavigator,
0095                    std::shared_ptr<Acts::Experimental::DetectorNavigator>>(
0096             m, "DetectorNavigator")
0097             .def(py::init<>(
0098                      [](Config cfg, Logging::Level level = Logging::INFO) {
0099                        return Acts::Experimental::DetectorNavigator{
0100                            cfg, getDefaultLogger("DetectorNavigator", level)};
0101                      }),
0102                  py::arg("cfg"), py::arg("level") = Logging::INFO);
0103 
0104     auto c = py::class_<Config>(nav, "Config").def(py::init<>());
0105 
0106     ACTS_PYTHON_STRUCT_BEGIN(c, Config);
0107     ACTS_PYTHON_MEMBER(resolveMaterial);
0108     ACTS_PYTHON_MEMBER(resolvePassive);
0109     ACTS_PYTHON_MEMBER(resolveSensitive);
0110     ACTS_PYTHON_MEMBER(detector);
0111     ACTS_PYTHON_STRUCT_END();
0112   }
0113 
0114   ACTS_PYTHON_DECLARE_ALGORITHM(
0115       ActsExamples::PropagationAlgorithm, mex, "PropagationAlgorithm",
0116       propagatorImpl, randomNumberSvc, mode, sterileLogger, debugOutput,
0117       energyLoss, multipleScattering, recordMaterialInteractions, ntests,
0118       d0Sigma, z0Sigma, phiSigma, thetaSigma, qpSigma, tSigma, phiRange,
0119       etaRange, ptRange, particleHypothesis, ptLoopers, maxStepSize,
0120       propagationStepCollection, propagationMaterialCollection,
0121       covarianceTransport, covariances, correlations);
0122 
0123   py::class_<ActsExamples::PropagatorInterface,
0124              std::shared_ptr<ActsExamples::PropagatorInterface>>(
0125       mex, "PropagatorInterface");
0126 
0127   {
0128     auto stepper = py::class_<Acts::EigenStepper<>>(m, "EigenStepper");
0129     stepper.def(
0130         // Add custom constructor lambda so that not specifying the overstep
0131         // limit takes the default from C++ EigenStepper
0132         py::init(
0133             [](std::shared_ptr<const Acts::MagneticFieldProvider> bField,
0134                std::optional<double> overstepLimit) -> Acts::EigenStepper<> {
0135               if (overstepLimit) {
0136                 return {std::move(bField), overstepLimit.value()};
0137               } else {
0138                 return {std::move(bField)};
0139               }
0140             }),
0141         py::arg("bField"), py::arg("overstepLimit") = std::nullopt);
0142 
0143     addPropagator<Acts::EigenStepper<>, Acts::Navigator>(prop, "Eigen");
0144   }
0145 
0146   {
0147     addPropagator<Acts::EigenStepper<>, Acts::Experimental::DetectorNavigator>(
0148         prop, "EigenNext");
0149   }
0150 
0151   {
0152     auto stepper = py::class_<Acts::AtlasStepper>(m, "AtlasStepper");
0153     stepper.def(py::init<std::shared_ptr<const Acts::MagneticFieldProvider>>());
0154 
0155     addPropagator<Acts::AtlasStepper, Acts::Navigator>(prop, "Atlas");
0156   }
0157 
0158   {
0159     auto stepper =
0160         py::class_<Acts::StraightLineStepper>(m, "StraightLineStepper");
0161     stepper.def(py::init<>());
0162 
0163     addPropagator<Acts::StraightLineStepper, Acts::Navigator>(prop,
0164                                                               "StraightLine");
0165   }
0166 }
0167 
0168 }  // namespace Acts::Python