Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-09 09:26:47

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/Propagation/PropagatorInterface.hpp"
0010 #include "ActsExamples/Traccc/DetrayPropagator.hpp"
0011 #include "ActsExamples/Traccc/DetrayStore.hpp"
0012 #include "ActsPlugins/Covfie/FieldConversion.hpp"
0013 #include "ActsPlugins/Detray/DetrayConversionUtils.hpp"
0014 #include "ActsPython/Utilities/Helpers.hpp"
0015 
0016 #include <detray/core/detector.hpp>
0017 #include <detray/io/frontend/detector_reader.hpp>
0018 #include <detray/navigation/volume_graph.hpp>
0019 #include <detray/propagator/line_stepper.hpp>
0020 #include <detray/propagator/propagator.hpp>
0021 #include <detray/propagator/rk_stepper.hpp>
0022 #include <pybind11/pybind11.h>
0023 #include <vecmem/memory/host_memory_resource.hpp>
0024 #include <vecmem/memory/memory_resource.hpp>
0025 
0026 namespace py = pybind11;
0027 using namespace pybind11::literals;
0028 
0029 using namespace Acts;
0030 using namespace ActsExamples;
0031 using namespace ActsPlugins;
0032 using namespace ActsPython;
0033 
0034 PYBIND11_MODULE(ActsExamplesPythonBindingsTraccc, traccc) {
0035   /// Define host detray store
0036   {
0037     py::class_<DetrayHostStore, std::shared_ptr<DetrayHostStore>>(
0038         traccc, "DetrayHostStore");
0039 
0040     /// Read the detray detector from files
0041     /// @param geometry the geometry file name
0042     /// @param materials the material file name
0043     /// @param grids the surface grids file name
0044     traccc.def("readDetectorHost", [](const std::string& geometry,
0045                                       const std::string& materials,
0046                                       const std::string& grids) {
0047       auto mr = std::make_shared<vecmem::host_memory_resource>();
0048 
0049       auto reader_cfg = detray::io::detector_reader_config{};
0050       reader_cfg.add_file(geometry);
0051       if (materials.empty() == false) {
0052         reader_cfg.add_file(materials);
0053       }
0054       if (grids.empty() == false) {
0055         reader_cfg.add_file(grids);
0056       }
0057 
0058       // Read the json files
0059       auto [det, names] =
0060           detray::io::read_detector<DetrayHostDetector>(*mr, reader_cfg);
0061       return DetrayHostStore{std::move(mr), std::move(det)};
0062     });
0063   }
0064 
0065   /// Define the DetrayPropagator straight line propagator
0066   {
0067     traccc.def(
0068         "createSlPropagatorHost",
0069         [](std::shared_ptr<const DetrayHostStore> detrayStore,
0070            bool sterile = false) {
0071           std::shared_ptr<PropagatorInterface> detrayPropagator = nullptr;
0072 
0073           using DetrayLineStepper =
0074               detray::line_stepper<typename DetrayHostDetector::algebra_type>;
0075 
0076           using DetrayPropagator =
0077               DetrayPropagator<DetrayLineStepper, DetrayHostStore>;
0078 
0079           DetrayPropagator::Config cfg{detrayStore, sterile};
0080           detrayPropagator = std::make_shared<DetrayPropagator>(cfg);
0081           return detrayPropagator;
0082         });
0083   }
0084 
0085   /// Define the DetrayPropagator with a covfie constant b field
0086   {
0087     traccc.def(
0088         "createConstBFieldPropagatorHost",
0089         [](std::shared_ptr<const DetrayHostStore> detrayStore,
0090            Covfie::ConstantField cfield, bool sterile = false) {
0091           std::shared_ptr<PropagatorInterface> detrayPropagator = nullptr;
0092 
0093           // Runge-Kutta-Nystrom stepper (field integration)
0094           using DetrayRknStepper =
0095               detray::rk_stepper<Covfie::ConstantField::view_t,
0096                                  typename DetrayHostDetector::algebra_type>;
0097 
0098           using DetrayPropagator =
0099               DetrayPropagator<DetrayRknStepper, DetrayHostStore,
0100                                Covfie::ConstantField>;
0101 
0102           DetrayPropagator::Config cfg{detrayStore, sterile, cfield};
0103           detrayPropagator = std::make_shared<DetrayPropagator>(cfg);
0104           return detrayPropagator;
0105         });
0106   }
0107 
0108   /// Define the DetrayPropagator with a covfie interpolated b field
0109   {
0110     traccc.def(
0111         "createInterpolatedBFieldPropagatorHost",
0112         [](std::shared_ptr<const DetrayHostStore> detrayStore,
0113            Covfie::InterpolatedField ifield, bool sterile = false) {
0114           std::shared_ptr<PropagatorInterface> detrayPropagator = nullptr;
0115 
0116           // Runge-Kutta-Nystrom stepper (field integration)
0117           using DetrayRknStepper =
0118               detray::rk_stepper<Covfie::InterpolatedField::view_t,
0119                                  typename DetrayHostDetector::algebra_type>;
0120 
0121           using DetrayPropagator =
0122               DetrayPropagator<DetrayRknStepper, DetrayHostStore,
0123                                Covfie::InterpolatedField>;
0124 
0125           DetrayPropagator::Config cfg{detrayStore, sterile, ifield};
0126           detrayPropagator = std::make_shared<DetrayPropagator>(cfg);
0127 
0128           return detrayPropagator;
0129         });
0130   }
0131   /// Define the DetrayPropagator with interpolated b field
0132 }