diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dc1dccfa..4e05e2fe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "Directory for the built static libraries" ) +set(DETRAY_PYTHON_INSTALL_DIR "python/detray") + # Include the Detray CMake code. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(detray-functions) @@ -67,6 +69,11 @@ set_property( PROPERTY STRINGS "NONE" "WARNING" "INFO" "VERBOSE" "DEBUG" ) option(DETRAY_BUILD_CLI_TOOLS "Build the command line tools of Detray" OFF) +option( + DETRAY_BUILD_PYTHON_BINDINGS + "Build python bindings for all enabled components" + OFF +) # Device compilation @@ -83,7 +90,6 @@ option(DETRAY_BUILD_SYCL "Build the SYCL sources included in detray" OFF) # Check if HIP is available option(DETRAY_BUILD_HIP "Build the HIP sources included in detray" OFF) - cmake_dependent_option( DETRAY_BUILD_HOST "Build the host sources included in detray" @@ -132,7 +138,23 @@ elseif(DETRAY_SET_LOGGING STREQUAL "DEBUG") set(DETRAY_LOG_LVL 3 CACHE INTERNAL "Print expert information" FORCE) endif() -# Need test utils for the example detector generation +# +# Resolve build options and option dependencies +# + +# Set the internal log level from user input +set(DETRAY_LOG_LVL -1 CACHE INTERNAL "Disable logging") +if(DETRAY_SET_LOGGING STREQUAL "WARN") + set(DETRAY_LOG_LVL 0 CACHE INTERNAL "Print warnings and errors" FORCE) +elseif(DETRAY_SET_LOGGING STREQUAL "INFO") + set(DETRAY_LOG_LVL 1 CACHE INTERNAL "Print general information" FORCE) +elseif(DETRAY_SET_LOGGING STREQUAL "VERBOSE") + set(DETRAY_LOG_LVL 2 CACHE INTERNAL "Print detailed information" FORCE) +elseif(DETRAY_SET_LOGGING STREQUAL "DEBUG") + set(DETRAY_LOG_LVL 3 CACHE INTERNAL "Print expert information" FORCE) +endif() + +# Need test utils in CLI tools for the example detector generation if(DETRAY_BUILD_CLI_TOOLS) set(DETRAY_BUILD_TEST_UTILS ON) endif() @@ -145,12 +167,9 @@ if(${DETRAY_BUILD_CUDA} AND ${CMAKE_CUDA_STANDARD} LESS 20) ) endif() -if(${DETRAY_BUILD_SYCL} AND ${CMAKE_SYCL_STANDARD} LESS 20) - message( - SEND_ERROR - "CMAKE_SYCL_STANDARD=${CMAKE_SYCL_STANDARD}, but detray requires C++>=20" - ) -endif() +# +# Configure dependencies +# if(${DETRAY_BUILD_HIP} AND ${CMAKE_HIP_STANDARD} LESS 20) message( @@ -461,11 +480,15 @@ if(DETRAY_SETUP_COVFIE) endif() endif() +# # Set up all of the libraries of the project. +# + add_subdirectory(core) add_subdirectory(detectors) add_subdirectory(io) add_subdirectory(plugins) +add_subdirectory(python) # Test utils and validation tools can also be required standalone # (e.g. in ACTS detray plugin) @@ -479,7 +502,6 @@ if( add_subdirectory(tests) endif() -# Set up the tutorial(s). if(DETRAY_BUILD_TUTORIALS) add_subdirectory(tutorials) endif() diff --git a/README.md b/README.md index c53dd5b6e..2e2729fb7 100644 --- a/README.md +++ b/README.md @@ -62,13 +62,13 @@ The following cmake options are available and can also be specified explicitly f | DETRAY_SET_LOGGING | Set log level (NONE, WARN, INFO, VERBOSE, DEBUG) | INFO | | DETRAY_BUILD_CUDA | Build the CUDA sources included in detray | ON (if available) | | DETRAY_BUILD_SYCL | Build the SYCL sources included in detray | OFF | -| DETRAY_BUILD_TEST_UTILS | Build the detray test utilities library (contains e.g. test detectors) | OFF | -| DETRAY_BUILD_UNITTESTS | Build the detray unit tests | OFF | -| DETRAY_BUILD_INTEGRATIONTESTS | Build the detray integration tests | OFF | -| DETRAY_BUILD_ALL_TESTS | Build the detray unit and integration tests | OFF | -| DETRAY_BUILD_BENCHMARKS | Build the detray benchmarks | OFF | | DETRAY_BUILD_CLI_TOOLS | Build the detray command line tools | OFF | +| DETRAY_BUILD_BENCHMARKS | Build the detray benchmarks | OFF | | DETRAY_BUILD_TUTORIALS | Build the examples of detray | OFF | +| DETRAY_BUILD_ALL_TESTS | Build the detray unit and integration tests | OFF | +| DETRAY_BUILD_UNITTESTS | Build the detray unit tests | OFF | +| DETRAY_BUILD_INTEGRATIONTESTS | Build the detray integration tests | OFF | +| DETRAY_BUILD_TEST_UTILS | Build the detray test utilities library (test detectors etc.) | OFF | | DETRAY_CUSTOM_SCALARTYPE | Floating point precision | float | | DETRAY_EIGEN_PLUGIN | Build Eigen math plugin | OFF | | DETRAY_FASTOR_PLUGIN | Build Fastor math plugin | OFF | @@ -87,6 +87,10 @@ extra navigation tracing information - Moving a detector to device - Host and device track propagation +In order to define a custom detector geometry type (called a detector 'metadata'), please follow the instructions in `detray/detectors/README.md`. + +Otherwise, the default detector metadata (`#include detray/detectors/default_metadata.hpp`) can be used in most cases to define the detector type, however, incurring increased build times and likely also increased runtime of client algorithms. + ## Detector Validation Given a detray detector (and optionally also a grid and a material) json file, a number of validation test can be run from the command-line. For this, the library has to be built with the `-DDETRAY_BUILD_CLI_TOOLS=ON` option enabled. An example detector file can then be obtained using e.g. diff --git a/core/include/detray/builders/cuboid_portal_generator.hpp b/core/include/detray/builders/cuboid_portal_generator.hpp index 21339a057..4c19a6c7d 100644 --- a/core/include/detray/builders/cuboid_portal_generator.hpp +++ b/core/include/detray/builders/cuboid_portal_generator.hpp @@ -116,7 +116,7 @@ class cuboid_portal_generator final auto surfaces_offset{static_cast(n_surfaces)}; // Fetch the position in the mask tuple for the rectangle portals - constexpr auto rectangle_id{detector_t::masks::id::e_portal_rectangle2}; + constexpr auto rectangle_id{detector_t::masks::id::e_rectangle2D}; // The material will be added in a later step constexpr auto no_material = surface_t::material_id::e_none; diff --git a/core/include/detray/builders/cylinder_portal_generator.hpp b/core/include/detray/builders/cylinder_portal_generator.hpp index 6f094e4b6..5e194d7a5 100644 --- a/core/include/detray/builders/cylinder_portal_generator.hpp +++ b/core/include/detray/builders/cylinder_portal_generator.hpp @@ -305,14 +305,14 @@ class cylinder_portal_generator final // Add transform and mask data transforms.emplace_back(ctx, tsl); - masks.template emplace_back( + masks.template emplace_back( empty_context{}, vol_link, r, min_z, max_z); // Add surface links mask_link_t mask_link{}; const auto mask_idx{static_cast( - masks.template size() - 1u)}; - set_mask_link(mask_link, mask_id::e_portal_cylinder2, mask_idx); + masks.template size() - 1u)}; + set_mask_link(mask_link, mask_id::e_concentric_cylinder2D, mask_idx); material_link_t material_link{material_id::e_none, dindex_invalid}; @@ -341,14 +341,14 @@ class cylinder_portal_generator final // Add transform and mask data transforms.emplace_back(ctx, tsl); - masks.template emplace_back( - empty_context{}, vol_link, min_r, max_r); + masks.template emplace_back(empty_context{}, + vol_link, min_r, max_r); // Add surface links mask_link_t mask_link{}; - const auto mask_idx{static_cast( - masks.template size() - 1u)}; - set_mask_link(mask_link, mask_id::e_portal_ring2, mask_idx); + const auto mask_idx{ + static_cast(masks.template size() - 1u)}; + set_mask_link(mask_link, mask_id::e_ring2D, mask_idx); material_link_t material_link{material_id::e_none, dindex_invalid}; diff --git a/core/include/detray/builders/detail/volume_connector.hpp b/core/include/detray/builders/detail/volume_connector.hpp index 61803f7bc..213efefaf 100644 --- a/core/include/detray/builders/detail/volume_connector.hpp +++ b/core/include/detray/builders/detail/volume_connector.hpp @@ -248,8 +248,9 @@ void connect_cylindrical_volumes( 0., 0., volume_bounds[bound_index]}; // Get the mask context group and fill it - constexpr auto disc_id = detector_t::masks::id::e_portal_ring2; - constexpr auto slab_id = detector_t::materials::id::e_slab; + constexpr auto disc_id = detector_t::masks::id::e_ring2D; + constexpr auto slab_id = + detector_t::materials::id::e_material_slab; typename portal_t::mask_link mask_index = { disc_id, portal_masks.template size()}; typename portal_t::material_link material_index = { @@ -298,7 +299,8 @@ void connect_cylindrical_volumes( detector_t::masks::id::e_portal_cylinder3; typename portal_t::mask_link mask_index = { cylinder_id, portal_masks.template size()}; - constexpr auto slab_id = detector_t::materials::id::e_slab; + constexpr auto slab_id = + detector_t::materials::id::e_material_slab; for (auto &info_ : portals_info) { // Add new mask to container diff --git a/core/include/detray/builders/homogeneous_material_builder.hpp b/core/include/detray/builders/homogeneous_material_builder.hpp index 1b8e5058f..be97c78cb 100644 --- a/core/include/detray/builders/homogeneous_material_builder.hpp +++ b/core/include/detray/builders/homogeneous_material_builder.hpp @@ -97,34 +97,38 @@ class homogeneous_material_builder final : public volume_decorator { for (auto &sf : this->surfaces()) { DETRAY_DEBUG_HOST("-> sf=" << sf); DETRAY_DEBUG_HOST(" -> material_id=" << sf.material().id()); - if (sf.material().id() == material_id::e_slab) { - dindex offset = material.template size(); + if (sf.material().id() == material_id::e_material_slab) { + dindex offset = + material.template size(); DETRAY_DEBUG_HOST("-> update material slab offset: " << offset); sf.update_material(offset); DETRAY_DEBUG_HOST("-> material now: " << sf.material()); } if constexpr (types::contains>) { - if (sf.material().id() == material_id::e_rod) { + if (sf.material().id() == material_id::e_material_rod) { DETRAY_DEBUG_HOST( "-> update material rod offset: " - << material.template size()); + << material + .template size()); sf.update_material( - material.template size()); + material.template size()); } } } // Add material to the detector - DETRAY_DEBUG_HOST("-> Appending " - << m_materials.template size() - << " slabs into detector materials"); + DETRAY_DEBUG_HOST( + "-> Appending " + << m_materials.template size() + << " slabs into detector materials"); if constexpr (types::contains>) { - DETRAY_DEBUG_HOST("-> Appending " - << m_materials.template size() - << " rods into detector materials"); + DETRAY_DEBUG_HOST( + "-> Appending " + << m_materials.template size() + << " rods into detector materials"); } det._materials.append(std::move(m_materials)); m_materials.clear_all(); diff --git a/core/include/detray/builders/homogeneous_material_factory.hpp b/core/include/detray/builders/homogeneous_material_factory.hpp index ce7a78cc8..cf62690cc 100644 --- a/core/include/detray/builders/homogeneous_material_factory.hpp +++ b/core/include/detray/builders/homogeneous_material_factory.hpp @@ -354,8 +354,9 @@ class homogeneous_material_factory final DETRAY_DEBUG_HOST(" mat=" << mat << " thickness=" << t); dindex mat_idx{0u}; - if (m_links.at(sf_idx).first == material_id::e_slab) { - auto &mat_coll = materials.template get(); + if (m_links.at(sf_idx).first == material_id::e_material_slab) { + auto &mat_coll = + materials.template get(); material_slab mat_slab{mat, t}; mat_idx = this->insert_in_container(mat_coll, mat_slab, @@ -363,9 +364,9 @@ class homogeneous_material_factory final } if constexpr (types::contains>) { - if (m_links.at(sf_idx).first == material_id::e_rod) { + if (m_links.at(sf_idx).first == material_id::e_material_rod) { auto &mat_coll = - materials.template get(); + materials.template get(); material_rod mat_rod{mat, t}; mat_idx = this->insert_in_container( diff --git a/core/include/detray/builders/homogeneous_material_generator.hpp b/core/include/detray/builders/homogeneous_material_generator.hpp index 5874ae3f0..401db58ee 100644 --- a/core/include/detray/builders/homogeneous_material_generator.hpp +++ b/core/include/detray/builders/homogeneous_material_generator.hpp @@ -198,20 +198,21 @@ class homogeneous_material_generator final is_line = true; auto &mat_coll = - materials.template get(); + materials.template get(); mat_coll.emplace_back(*mat_ptr, m_cfg.thickness()); - mat_link = {material_id::e_rod, + mat_link = {material_id::e_material_rod, static_cast(mat_coll.size() - 1u)}; } } // For all surfaces that are not lines, generate a material slab if (!is_line) { - auto &mat_coll = materials.template get(); + auto &mat_coll = + materials.template get(); mat_coll.emplace_back(*mat_ptr, m_cfg.thickness()); - mat_link = {material_id::e_slab, + mat_link = {material_id::e_material_slab, static_cast(mat_coll.size() - 1u)}; } diff --git a/core/include/detray/builders/volume_builder.hpp b/core/include/detray/builders/volume_builder.hpp index ac9959871..b5a228f2c 100644 --- a/core/include/detray/builders/volume_builder.hpp +++ b/core/include/detray/builders/volume_builder.hpp @@ -53,7 +53,7 @@ class volume_builder : public volume_builder_interface { // force method that will at least contain the portals m_volume.template set_accel_link< static_cast(0)>( - detector_t::accel::id::e_default, 0); + detector_t::accel::id::e_surface_default, 0); DETRAY_VERBOSE_HOST("Created builder for volume: " << idx); }; @@ -254,7 +254,7 @@ class volume_builder : public volume_builder_interface { } // Place the appropriate surfaces in the brute force search method. - constexpr auto default_acc_id{detector_t::accel::id::e_default}; + constexpr auto default_acc_id{detector_t::accel::id::e_surface_default}; // Strip the source link from the lookup data structure typename detector_t::surface_container descriptors; diff --git a/core/include/detray/core/detector.hpp b/core/include/detray/core/detector.hpp index 42281cff6..8418644f7 100644 --- a/core/include/detray/core/detector.hpp +++ b/core/include/detray/core/detector.hpp @@ -232,7 +232,7 @@ class detector { // TODO: Add volume accelerator builder volume_type v_desc{}; v_desc.template set_accel_link( - accel::id::e_default_volume_searcher, 0u); + accel::id::e_volume_default, 0u); tracking_volume world{*this, v_desc}; dindex volume_index{0u}; @@ -248,7 +248,8 @@ class detector { DETRAY_HOST_DEVICE inline const auto &portals() const { // All portals are registered with the brute force search - return _accelerators.template get().all(); + return _accelerators.template get() + .all(); } /// @returns the sub-volumes of the detector - const access diff --git a/core/include/detray/utils/detector_statistics.hpp b/core/include/detray/utils/detector_statistics.hpp index 5ec0ad08b..26e1a2bae 100644 --- a/core/include/detray/utils/detector_statistics.hpp +++ b/core/include/detray/utils/detector_statistics.hpp @@ -89,7 +89,7 @@ DETRAY_HOST_DEVICE inline std::size_t n_material_maps(const detector_t& det) { template DETRAY_HOST_DEVICE inline std::size_t n_material_slabs(const detector_t& det) { if constexpr (detray::concepts::has_material_slabs) { - constexpr auto slab_id{detector_t::materials::id::e_slab}; + constexpr auto slab_id{detector_t::materials::id::e_material_slab}; return det.material_store().template size(); } else { return 0u; @@ -100,7 +100,7 @@ DETRAY_HOST_DEVICE inline std::size_t n_material_slabs(const detector_t& det) { template DETRAY_HOST_DEVICE inline std::size_t n_material_rods(const detector_t& det) { if constexpr (detray::concepts::has_material_rods) { - constexpr auto rod_id{detector_t::materials::id::e_rod}; + constexpr auto rod_id{detector_t::materials::id::e_material_rod}; return det.material_store().template size(); } else { return 0u; diff --git a/detectors/README.md b/detectors/README.md new file mode 100644 index 000000000..f4659ac15 --- /dev/null +++ b/detectors/README.md @@ -0,0 +1,34 @@ +## Generating custom Detector Metadata + +The detector metadata is a C++ `struct` used by the detray core library as a template parameter to gather the compile-time information on the capabilities of the detector modelling, for example: + +`using odd_detector_t = detray::detector>`, + +with the `algebra_t` defined according to the linear algebra backend to be used, for instance the `detray::array` plugin. + +A generic metadata type (the default metadata) exists, which comprises most of the geometry modelling capabilities detray has to offer, however, at the expense of increased build times and likely higher runtime of subsequent track reconstruction pipelines. A custom metadata can be defined by providing a python script that configures the detray metadata code generator, +which can be invoked during the configuration stage of the cmake build: +```shell +cmake -S detray -B detray-build -DDETRAY_METADATA_GENERATOR=path/to/custom_metadata.py +``` +The resulting metadata header, ready to be used in downstream projects, will be available in the `detray/detectors` folder. Example metadata generation scripts, for instance for the ACTS Open Data Detector (ODD detector mentioned above), can be found in the `detray/detectors/python/` folder. They can be invoked manually by: +```shell +source detray-build/python/setup.sh +python3 detray/detectors/python/odd_metadata.py +``` + +### Metadata Configuration Manual + +Generate a metadata representation and dump the header file: + +```python +from detray.detectors import metadata, metadata_generator + +md = metadata("detector_name") + +[...] + +metadata_generator(md) +``` + +Adding surface shapes for passive or sensitive detector elements or portals between detector sub-volumes: diff --git a/detectors/include/detray/detectors/default_metadata.hpp b/detectors/include/detray/detectors/default_metadata.hpp index aa04b025e..6bc849010 100644 --- a/detectors/include/detray/detectors/default_metadata.hpp +++ b/detectors/include/detray/detectors/default_metadata.hpp @@ -1,6 +1,6 @@ /** Detray library, part of the ACTS project (R&D line) * - * (c) 2022-2024 CERN for the benefit of the ACTS project + * (c) 2026 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -14,10 +14,17 @@ #include "detray/definitions/containers.hpp" #include "detray/definitions/indexing.hpp" #include "detray/geometry/mask.hpp" -#include "detray/geometry/shapes.hpp" -#include "detray/geometry/shapes/unbounded.hpp" -#include "detray/geometry/shapes/unmasked.hpp" +#include "detray/geometry/shapes/annulus2D.hpp" +#include "detray/geometry/shapes/concentric_cylinder2D.hpp" +#include "detray/geometry/shapes/cuboid3D.hpp" +#include "detray/geometry/shapes/cylinder2D.hpp" +#include "detray/geometry/shapes/cylinder3D.hpp" +#include "detray/geometry/shapes/line.hpp" +#include "detray/geometry/shapes/rectangle2D.hpp" +#include "detray/geometry/shapes/ring2D.hpp" +#include "detray/geometry/shapes/trapezoid2D.hpp" #include "detray/geometry/surface_descriptor.hpp" +#include "detray/material/material.hpp" #include "detray/material/material_map.hpp" #include "detray/material/material_rod.hpp" #include "detray/material/material_slab.hpp" @@ -26,427 +33,250 @@ namespace detray { -/// Assembles the detector type. This metatdata contains all available types template struct default_metadata { - /// Define the algebra type for the geometry and navigation using algebra_type = algebra_t; using scalar_t = dscalar; - /// Mask-to-(next)-volume link (potentially switchable for SoA) using nav_link = std::uint_least16_t; - /// How to store coordinate transform matrices template