Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:38

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 "Acts/Definitions/Units.hpp"
0010 #include "Acts/Material/IMaterialDecorator.hpp"
0011 #include "Acts/Utilities/Logger.hpp"
0012 #include "ActsPlugins/Root/RootMagneticFieldIo.hpp"
0013 #include "ActsPlugins/Root/RootMaterialDecorator.hpp"
0014 #include "ActsPlugins/Root/RootMaterialMapIo.hpp"
0015 #include "ActsPython/Utilities/Helpers.hpp"
0016 #include "ActsPython/Utilities/Macros.hpp"
0017 
0018 #include <memory>
0019 #include <vector>
0020 
0021 #include <TGeoManager.h>
0022 #include <TGeoVolume.h>
0023 #include <pybind11/pybind11.h>
0024 #include <pybind11/stl.h>
0025 #include <pybind11/stl/filesystem.h>
0026 
0027 namespace py = pybind11;
0028 using namespace pybind11::literals;
0029 using namespace Acts;
0030 using namespace ActsPlugins;
0031 
0032 PYBIND11_MODULE(ActsPluginsPythonBindingsRoot, root) {
0033   {
0034     auto ac = py::class_<RootMaterialMapIo::Config>(root, "AccessorConfig")
0035                   .def(py::init<>());
0036 
0037     ACTS_PYTHON_STRUCT(ac, volumePrefix, portalPrefix, layerPrefix,
0038                        passivePrefix, sensitivePrefix, nBinsHistName,
0039                        axisDirHistName, axisBoundaryTypeHistName, indexHistName,
0040                        minRangeHistName, maxRangeHistName, thicknessHistName,
0041                        x0HistName, l0HistName, aHistName, zHistName,
0042                        rhoHistName);
0043 
0044     auto ao = py::class_<RootMaterialMapIo::Options>(root, "AccessorOptions")
0045                   .def(py::init<>());
0046 
0047     ACTS_PYTHON_STRUCT(ao, homogeneousMaterialTreeName, indexedMaterialTreeName,
0048                        folderSurfaceNameBase, folderVolumeNameBase,
0049                        indexedMaterial);
0050 
0051     auto rmd =
0052         py::class_<RootMaterialDecorator, IMaterialDecorator,
0053                    std::shared_ptr<RootMaterialDecorator>>(
0054             root, "RootMaterialDecorator")
0055             .def(py::init<RootMaterialDecorator::Config, Logging::Level>(),
0056                  py::arg("config"), py::arg("level"));
0057 
0058     using Config = RootMaterialDecorator::Config;
0059     auto c = py::class_<Config>(rmd, "Config").def(py::init<>());
0060 
0061     ACTS_PYTHON_STRUCT(c, accessorConfig, accessorOptions, fileName);
0062   }
0063 
0064   {
0065     root.def(
0066         "MagneticFieldMapXyz",
0067         [](const std::string& filename, const std::string& tree,
0068            double lengthUnit, double BFieldUnit, bool firstOctant) {
0069           const std::filesystem::path file = filename;
0070 
0071           auto mapBins = [](std::array<std::size_t, 3> bins,
0072                             std::array<std::size_t, 3> sizes) {
0073             return (bins[0] * (sizes[1] * sizes[2]) + bins[1] * sizes[2] +
0074                     bins[2]);
0075           };
0076 
0077           if (file.extension() == ".root") {
0078             auto map = makeMagneticFieldMapXyzFromRoot(
0079                 std::move(mapBins), file.native(), tree, lengthUnit, BFieldUnit,
0080                 firstOctant);
0081             return std::make_shared<decltype(map)>(std::move(map));
0082           } else {
0083             throw std::runtime_error(
0084                 "Unsupported magnetic field map file type");
0085           }
0086         },
0087         py::arg("file"), py::arg("tree") = "bField",
0088         py::arg("lengthUnit") = UnitConstants::mm,
0089         py::arg("BFieldUnit") = UnitConstants::T,
0090         py::arg("firstOctant") = false);
0091 
0092     root.def(
0093         "MagneticFieldMapRz",
0094         [](const std::string& filename, const std::string& tree,
0095            double lengthUnit, double BFieldUnit, bool firstQuadrant) {
0096           const std::filesystem::path file = filename;
0097 
0098           auto mapBins = [](std::array<std::size_t, 2> bins,
0099                             std::array<std::size_t, 2> sizes) {
0100             return (bins[1] * sizes[0] + bins[0]);
0101           };
0102 
0103           if (file.extension() == ".root") {
0104             auto map = makeMagneticFieldMapRzFromRoot(
0105                 std::move(mapBins), file.native(), tree, lengthUnit, BFieldUnit,
0106                 firstQuadrant);
0107             return std::make_shared<decltype(map)>(std::move(map));
0108           } else {
0109             throw std::runtime_error(
0110                 "Unsupported magnetic field map file type");
0111           }
0112         },
0113         py::arg("file"), py::arg("tree") = "bField",
0114         py::arg("lengthUnit") = UnitConstants::mm,
0115         py::arg("BFieldUnit") = UnitConstants::T,
0116         py::arg("firstQuadrant") = false);
0117   }
0118 }