Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-25 07:56:17

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 "ActsPlugins/Covfie/FieldConversion.hpp"
0010 #include "ActsPython/Utilities/Helpers.hpp"
0011 
0012 #include <string>
0013 
0014 #include <pybind11/pybind11.h>
0015 #include <pybind11/stl.h>
0016 
0017 namespace py = pybind11;
0018 using namespace pybind11::literals;
0019 using namespace Acts;
0020 using namespace ActsPlugins;
0021 
0022 namespace ActsPython {
0023 
0024 namespace {
0025 template <typename field_t, typename scalar_type>
0026 void declareCovfieField(py::module& m, const std::string& fieldName) {
0027   using view_t = typename field_t::view_t;
0028   m.def("toView",
0029         [](const field_t& field) { return typename field_t::view_t(field); });
0030   py::class_<field_t, std::shared_ptr<field_t>>(m, fieldName.c_str());
0031   py::class_<view_t, std::shared_ptr<view_t>>(
0032       m, (fieldName + std::string("View")).c_str())
0033       .def("at", &view_t::template at<scalar_type, scalar_type, scalar_type>);
0034 }
0035 }  // namespace
0036 
0037 void addCovfie(Context& ctx) {
0038   auto main = ctx.get("main");
0039   auto m = main.def_submodule("covfie", "Submodule for covfie conversion");
0040 
0041   py::class_<covfie::array::array<float, 3ul>,
0042              std::shared_ptr<covfie::array::array<float, 3ul>>>(m,
0043                                                                 "ArrayFloat3")
0044       .def("at", [](const covfie::array::array<float, 3ul>& self,
0045                     std::size_t i) { return self[i]; });
0046 
0047   declareCovfieField<Covfie::ConstantField, float>(m, "CovfieConstantField");
0048   declareCovfieField<Covfie::InterpolatedField, float>(
0049       m, "CovfieAffineLinearStridedField");
0050 
0051   m.def("makeCovfieField", py::overload_cast<const InterpolatedMagneticField&>(
0052                                &Covfie::covfieField));
0053   m.def("makeCovfieField",
0054         py::overload_cast<const ConstantBField&>(&Covfie::covfieField));
0055   m.def("makeCovfieField",
0056         py::overload_cast<
0057             const MagneticFieldProvider&, MagneticFieldProvider::Cache&,
0058             const std::array<std::size_t, 3>&, const Vector3&, const Vector3&>(
0059             &Covfie::covfieField));
0060 }
0061 
0062 }  // namespace ActsPython