Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:01

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