Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-23 08:23:32

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/Detector/Detector.hpp"
0010 #include "ActsPlugins/Detray/DetrayConversionUtils.hpp"
0011 #include "ActsPlugins/Detray/DetrayConverter.hpp"
0012 #include "ActsPython/Utilities/Helpers.hpp"
0013 #include "ActsPython/Utilities/Macros.hpp"
0014 
0015 #include <memory>
0016 #include <string>
0017 
0018 #include <detray/builders/detector_builder.hpp>
0019 #include <pybind11/pybind11.h>
0020 #include <vecmem/memory/host_memory_resource.hpp>
0021 #include <vecmem/memory/memory_resource.hpp>
0022 
0023 namespace py = pybind11;
0024 using namespace pybind11::literals;
0025 
0026 using namespace Acts;
0027 using namespace Acts::Experimental;
0028 using namespace detray;
0029 using namespace detray::io::detail;
0030 using namespace ActsPlugins;
0031 
0032 namespace ActsPython {
0033 
0034 void addDetray(Context& ctx) {
0035   auto [m, mex] = ctx.get("main", "examples");
0036 
0037   auto detray = m.def_submodule("detray");
0038   {
0039     py::class_<DetrayHostDetector, std::shared_ptr<DetrayHostDetector>>(
0040         detray, "detray_detector");
0041   }
0042 
0043   {
0044     // This test function will convert an ACTS detector into a detray detector
0045     // and write it to the corresponding json files.
0046     //
0047     // The memory resource and the detector are destroyed after the function
0048     detray.def("writeToJson",
0049                [](const GeometryContext& gctx, const Detector& detector) {
0050                  auto memoryResource = vecmem::host_memory_resource();
0051 
0052                  DetrayConverter::Options options;
0053                  options.writeToJson = true;
0054                  options.convertMaterial = false;
0055                  options.convertSurfaceGrids = true;
0056                  auto DetrayHostDetector = DetrayConverter().convert<>(
0057                      gctx, detector, memoryResource, options);
0058                });
0059   }
0060 
0061   {
0062     auto converter = py::class_<DetrayConverter>(detray, "DetrayConverter");
0063 
0064     auto options = py::class_<DetrayConverter::Options>(converter, "Options")
0065                        .def(py::init<>());
0066 
0067     ACTS_PYTHON_STRUCT(options, convertMaterial, convertSurfaceGrids,
0068                        writeToJson);
0069   }
0070 }
0071 }  // namespace ActsPython