Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Python/Plugins/src/Detray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,77 @@
#include <string>

#include <detray/builders/detector_builder.hpp>
#include <detray/definitions/algebra.hpp>
#include <detray/detectors/toy_metadata.hpp>
#include <detray/geometry/barcode.hpp>
#include <detray/geometry/surface_descriptor.hpp>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <vecmem/memory/host_memory_resource.hpp>
#include <vecmem/memory/memory_resource.hpp>

namespace py = pybind11;
using namespace pybind11::literals;

template <typename metadata_t>
void addGeometry(py::module& m) {
using metadata = metadata_t;
using mask_link = metadata::mask_link;

auto pyMetadata = py::class_<metadata>(m, "metadata");
// auto pyMaskLink = py::class_<mask_link>(pyMetadata, "mask_link");

py::enum_<typename metadata::mask_ids>(pyMetadata, "mask_ids")
// py::enum_<typename mask_link::id_type>(pyMaskLink, "id_type")
.value("e_rectangle2", metadata::mask_ids::e_rectangle2)
.value("e_trapezoid2", metadata::mask_ids::e_trapezoid2)
.value("e_portal_cylinder2", metadata::mask_ids::e_portal_cylinder2)
.value("e_portal_ring2", metadata::mask_ids::e_portal_ring2)
.value("e_cylinder2", metadata::mask_ids::e_cylinder2);

auto pyMaskLink = py::class_<mask_link>(m, "mask_link")
.def(py::init<>())
.def(py::init<const typename mask_link::id_type,
const typename mask_link::index_type>())
.def_property("id", &mask_link::id, &mask_link::set_id);

py::class_<typename mask_link::index_type>(pyMaskLink, "index_type")
.def(py::init<>());
}

PYBIND11_MODULE(ActsPluginsPythonBindingsDetray, detray) {
using namespace ActsPlugins;

{
py::class_<DetrayHostDetector, std::shared_ptr<DetrayHostDetector>>(
detray, "detray_detector");
}

using surface_id = detray::surface_id;
py::enum_<surface_id>(detray, "surface_id")
.value("e_portal", surface_id::e_portal)
.value("e_sensitive", surface_id::e_sensitive)
.value("e_passive", surface_id::e_passive)
.value("e_unknown", surface_id::e_unknown)
.value("e_all", surface_id::e_all);

using barcode = detray::geometry::barcode;
auto geometry = detray.def_submodule("geometry");
py::class_<barcode>(geometry, "barcode")
.def(py::init<>())
.def(py::init<detray::geometry::barcode::value_t>())
.def_property_readonly("value", &barcode::value)
.def_property("volume", &barcode::volume, &barcode::set_volume)
.def_property("id", &barcode::id, &barcode::set_id)
.def_property("index", &barcode::index, &barcode::set_index)
.def_property("transform", &barcode::transform, &barcode::set_transform)
.def_property("extra", &barcode::extra, &barcode::set_extra)
.def_property_readonly("is_invalid", &barcode::is_invalid)
.def(py::self == py::self);

// py::class_<detray::dindex>(detray, "dindex");

auto toy = detray.def_submodule("toy");
addGeometry<detray::toy_metadata<detray::array<float>>>(toy);
}
27 changes: 27 additions & 0 deletions Python/Plugins/tests/detray/test_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from acts import detray


def test_barcode():
barcode = detray.geometry.barcode()
assert barcode.is_invalid
barcode.volume = 1
barcode.id = detray.surface_id.e_sensitive
barcode.index = 3
barcode.transform = 4
barcode.extra = 5
assert not barcode.is_invalid
assert barcode.volume == 1
assert barcode.id == detray.surface_id.e_sensitive
assert barcode.index == 3
assert barcode.transform == 4
assert barcode.extra == 5


def test_toy_metadata():
print(detray.toy.metadata)

print(detray.toy.metadata.mask_ids.e_rectangle2)
detray.toy.mask_link(
detray.toy.metadata.mask_ids.e_rectangle2,
detray.toy.mask_link.index_type(),
)
1 change: 1 addition & 0 deletions cmake/ActsCreateSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure_file(
${PROJECT_BINARY_DIR}/this_acts.sh
@ONLY
)
message(STATUS "making setup script with dependencies: ${ROOT_DIR}")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message(STATUS "making setup script with dependencies: ${ROOT_DIR}")

configure_file(
${CMAKE_CURRENT_LIST_DIR}/setup_withdeps.sh.in
${PROJECT_BINARY_DIR}/this_acts_withdeps.sh
Expand Down
2 changes: 2 additions & 0 deletions thirdparty/traccc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ FetchContent_Declare(traccc SYSTEM ${ACTS_TRACCC_SOURCE})

set(ACTS_TRACCC_SCALARTYPE "double")

set(TRACCC_USE_ROOT OFF CACHE BOOL "Do not use ROOT as part of Traccc")

set(TRACCC_CUSTOM_SCALARTYPE
"${ACTS_TRACCC_SCALARTYPE}"
CACHE STRING
Expand Down
Loading