Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-07 07:59:53

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Detray/DetrayPropagator.hpp"
0010 #include "ActsExamples/Detray/DetrayStore.hpp"
0011 #include "ActsExamples/Propagation/PropagatorInterface.hpp"
0012 #include "ActsPlugins/Covfie/FieldConversion.hpp"
0013 #include "ActsPlugins/Detray/DetrayConversionUtils.hpp"
0014 #include "ActsPython/Utilities/Helpers.hpp"
0015 
0016 // detray includes
0017 #include <detray/core/detector.hpp>
0018 #include <detray/io/frontend/detector_reader.hpp>
0019 #include <detray/navigation/volume_graph.hpp>
0020 #include <detray/propagator/line_stepper.hpp>
0021 #include <detray/propagator/propagator.hpp>
0022 #include <detray/propagator/rk_stepper.hpp>
0023 #include <pybind11/pybind11.h>
0024 #include <vecmem/memory/host_memory_resource.hpp>
0025 #include <vecmem/memory/memory_resource.hpp>
0026 
0027 namespace py = pybind11;
0028 using namespace pybind11::literals;
0029 
0030 using namespace Acts;
0031 using namespace ActsExamples;
0032 using namespace ActsPlugins;
0033 using namespace ActsPython;
0034 
0035 PYBIND11_MODULE(ActsExamplesPythonBindingsDetray, detray) {
0036   /// Define host detray store
0037   {
0038     py::class_<DetrayHostStore, std::shared_ptr<DetrayHostStore>>(
0039         detray, "DetrayHostStore");
0040 
0041     detray.def("readDetectorHost", [](const std::string& geometry,
0042                                       const std::string& materials,
0043                                       const std::string& grids) {
0044       auto mr = std::make_shared<vecmem::host_memory_resource>();
0045       auto reader_cfg = detray::io::detector_reader_config{};
0046       reader_cfg.add_file(geometry);
0047       if (!materials.empty())
0048         reader_cfg.add_file(materials);
0049       if (!grids.empty())
0050         reader_cfg.add_file(grids);
0051       auto [det, names] =
0052           detray::io::read_detector<DetrayHostDetector>(*mr, reader_cfg);
0053       return DetrayHostStore{std::move(mr), std::move(det)};
0054     });
0055   }
0056 
0057   /// Propagators
0058   {
0059     detray.def(
0060         "createSlPropagatorHost",
0061         [](const std::shared_ptr<const DetrayHostStore>& detrayStore,
0062            bool sterile) {
0063           using DetrayLineStepper =
0064               detray::line_stepper<typename DetrayHostDetector::algebra_type>;
0065           using DP = DetrayPropagator<DetrayLineStepper, DetrayHostStore>;
0066           DP::Config cfg{detrayStore, sterile};
0067           return std::shared_ptr<PropagatorInterface>(
0068               std::make_shared<DP>(cfg));
0069         },
0070         "store"_a, "sterile"_a = false);
0071 
0072     detray.def(
0073         "createConstBFieldPropagatorHost",
0074         [](const std::shared_ptr<const DetrayHostStore>& detrayStore,
0075            Covfie::ConstantField cfield, bool sterile) {
0076           using Stepper =
0077               detray::rk_stepper<Covfie::ConstantField::view_t,
0078                                  typename DetrayHostDetector::algebra_type>;
0079           using DP = DetrayPropagator<Stepper, DetrayHostStore,
0080                                       Covfie::ConstantField::view_t>;
0081           DP::Config cfg{detrayStore, sterile, cfield};
0082           return std::shared_ptr<PropagatorInterface>(
0083               std::make_shared<DP>(cfg));
0084         },
0085         "store"_a, "field"_a, "sterile"_a = false);
0086   }
0087 }