Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-16 08:17:49

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 // Detray IO include(s)
0010 #include "detray/io/frontend/detector_writer.hpp"
0011 
0012 // Detray test include(s)
0013 #include "detray/test/common/build_toy_detector.hpp"
0014 #include "detray/test/framework/types.hpp"
0015 
0016 // Vecmem include(s)
0017 #include <vecmem/memory/host_memory_resource.hpp>
0018 
0019 // Pybind11 include(s)
0020 #include <pybind11/pybind11.h>
0021 
0022 // System include(s)
0023 #include <stdexcept>
0024 #include <string>
0025 
0026 namespace py = pybind11;
0027 
0028 namespace {
0029 
0030 /// Build a toy detector and write it to JSON files in @param output_dir.
0031 void generate_toy_detector(unsigned int barrel_layers,
0032                            unsigned int endcap_layers, bool material_use_maps,
0033                            const std::string& output_dir) {
0034   if (barrel_layers > 4) {
0035     throw std::invalid_argument(
0036         "Number of barrel layers out of range (0-4): got '" +
0037         std::to_string(barrel_layers) + "'");
0038   }
0039   if (endcap_layers > 7) {
0040     throw std::invalid_argument(
0041         "Number of endcap layers out of range (0-7): got '" +
0042         std::to_string(endcap_layers) + "'");
0043   }
0044 
0045   detray::toy_det_config<detray::test::scalar> cfg{};
0046   cfg.n_brl_layers(barrel_layers);
0047   cfg.n_edc_layers(endcap_layers);
0048   cfg.use_material_maps(material_use_maps);
0049 
0050   vecmem::host_memory_resource host_mr;
0051   auto [det, names] =
0052       detray::build_toy_detector<detray::test::algebra>(host_mr, cfg);
0053 
0054   detray::io::detector_writer_config writer_cfg{};
0055   writer_cfg.format(detray::io::format::json).replace_files(false);
0056   writer_cfg.path(output_dir);
0057 
0058   detray::io::write_detector(det, names, writer_cfg);
0059 }
0060 
0061 }  // namespace
0062 
0063 PYBIND11_MODULE(DetrayExamplesPythonBindings, m) {
0064   m.doc() = "Detray example bindings";
0065 
0066   m.def("generateToyDetector", &generate_toy_detector,
0067         py::arg("barrelLayers") = 4u, py::arg("endcapLayers") = 3u,
0068         py::arg("materialUseMaps") = false,
0069         py::arg("outputDir") = "./toy_detector/",
0070         "Build a toy detector and write it to JSON files in output_dir");
0071 }