diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 46b05ef86..c64f03ba7 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -57,7 +57,7 @@ jobs: SCALAR_TYPE: ["float", "double"] PLATFORM: - NAME: "HOST" - CONTAINER: "ghcr.io/acts-project/ubuntu2004:v30" + CONTAINER: "ghcr.io/acts-project/ubuntu2004:v43" OPTIONS: -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=ON -DDETRAY_VC_PLUGIN=ON # The system to run on. diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 45e3c4e51..8a96cc649 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -33,7 +33,7 @@ file( GLOB _detray_core_private_headers detray_add_library( detray_core core ${_detray_core_public_headers} ${_detray_core_private_headers} ) target_link_libraries( detray_core - INTERFACE covfie::core vecmem::core detray::Thrust ) + INTERFACE vecmem::core detray::Thrust ) # Generate a version header for the project. configure_file( "cmake/version.hpp.in" diff --git a/core/include/detray/core/detector.hpp b/core/include/detray/core/detector.hpp index 2c217bf41..9dbcd4391 100644 --- a/core/include/detray/core/detector.hpp +++ b/core/include/detray/core/detector.hpp @@ -11,7 +11,6 @@ #include "detray/core/detail/container_buffers.hpp" #include "detray/core/detail/container_views.hpp" #include "detray/core/detector_metadata.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/containers.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/geometry/detail/volume_descriptor.hpp" @@ -32,7 +31,7 @@ namespace detray { /// @brief Forward declaration of a detector view type -template +template struct detector_view; /// @brief The detector definition. @@ -46,13 +45,11 @@ struct detector_view; /// @tparam container_t type collection of the underlying containers /// @tparam source_link the surface source link template , typename container_t = host_container_types> class detector { // Allow the building of the detector containers - friend class volume_builder_interface< - detector>; + friend class volume_builder_interface>; public: /// Algebra types @@ -65,8 +62,6 @@ class detector { using metadata = metadata_t; - using bfield_type = bfield_t; - /// Raw container types template using array_type = typename container_t::template array_type; @@ -128,22 +123,15 @@ class detector { using volume_finder = typename metadata::template volume_finder; - // TODO: Remove - template - using detector_view_type = - detector_view; - - // TODO: rename back to 'view_type' etc, once covfie is wrapped in the - // container view/buffer formalism /// Detector view types - using view_t = dmulti_view< + using view_type = dmulti_view< dvector_view, typename transform_container::view_type, typename mask_container::view_type, typename material_container::view_type, typename surface_container::view_type, dvector_view, typename volume_finder::view_type>; - using const_view_t = + using const_view_type = dmulti_view, typename transform_container::const_view_type, typename mask_container::const_view_type, @@ -153,7 +141,7 @@ class detector { typename volume_finder::const_view_type>; /// Detector buffer types - using buffer_t = dmulti_buffer< + using buffer_type = dmulti_buffer< dvector_buffer, typename transform_container::buffer_type, typename mask_container::buffer_type, typename material_container::buffer_type, @@ -179,39 +167,20 @@ class detector { _surfaces(resource), _surface_lookup(&resource), _volume_finder(resource), - _resource(&resource), - _bfield() {} - - /// @param resource memory resource for the allocation of members and - /// externally provided magnetic field @param field - DETRAY_HOST - detector(vecmem::memory_resource &resource, bfield_type &&field) - : _volumes(&resource), - _transforms(resource), - _masks(resource), - _materials(resource), - _surfaces(resource), - _surface_lookup(&resource), - _volume_finder(resource), - _resource(&resource), - _bfield(std::move(field)) {} + _resource(&resource) {} /// Constructor with detector_data - template , - bool> = true> - DETRAY_HOST_DEVICE explicit detector(detector_data_type &det_data) - : _volumes(detray::detail::get<0>(det_data._detector_data.m_view)), - _transforms(detray::detail::get<1>(det_data._detector_data.m_view)), - _masks(detray::detail::get<2>(det_data._detector_data.m_view)), - _materials(detray::detail::get<3>(det_data._detector_data.m_view)), - _surfaces(detray::detail::get<4>(det_data._detector_data.m_view)), - _surface_lookup( - detray::detail::get<5>(det_data._detector_data.m_view)), - _volume_finder( - detray::detail::get<6>(det_data._detector_data.m_view)), - _bfield(det_data._bfield_view) {} + template , bool> = true> + DETRAY_HOST_DEVICE explicit detector(detector_view_t &det_data) + : _volumes(detray::detail::get<0>(det_data.m_view)), + _transforms(detray::detail::get<1>(det_data.m_view)), + _masks(detray::detail::get<2>(det_data.m_view)), + _materials(detray::detail::get<3>(det_data.m_view)), + _surfaces(detray::detail::get<4>(det_data.m_view)), + _surface_lookup(detray::detail::get<5>(det_data.m_view)), + _volume_finder(detray::detail::get<6>(det_data.m_view)) {} /// @} /// Add a new volume and retrieve a reference to it. @@ -542,14 +511,23 @@ class detector { return *std::max_element(n_candidates.begin(), n_candidates.end()); } - /// @brief Add a bfield to the detector - DETRAY_HOST - void set_bfield(bfield_type &&field) { - _bfield = std::forward(field); + /// @returns view of a detector + DETRAY_HOST auto get_data() -> view_type { + return view_type{ + detray::get_data(_volumes), detray::get_data(_transforms), + detray::get_data(_masks), detray::get_data(_materials), + detray::get_data(_surfaces), detray::get_data(_surface_lookup), + detray::get_data(_volume_finder)}; } - DETRAY_HOST_DEVICE - inline const bfield_type &get_bfield() const { return _bfield; } + /// @returns const view of a detector + DETRAY_HOST auto get_data() const -> const_view_type { + return const_view_type{ + detray::get_data(_volumes), detray::get_data(_transforms), + detray::get_data(_masks), detray::get_data(_materials), + detray::get_data(_surfaces), detray::get_data(_surface_lookup), + detray::get_data(_volume_finder)}; + } /// @param names maps a volume to its string representation. /// @returns a string representation of the detector. @@ -618,128 +596,6 @@ class detector { /// The memory resource represents how and where (host, device, managed) /// the memory for the detector containers is allocated vecmem::memory_resource *_resource = nullptr; - - /// Storage for magnetic field data - bfield_type _bfield; -}; - -/// @brief The detector data buffer -/// -/// Contains the buffers for all detector components plus the covfie device -/// field type, which is being copied to device when this type gets constructed -template -struct detector_buffer { - - using detector_type = detector; - - /// Automatic buffer creation with the given parameters - detector_buffer(detector_type &det, vecmem::memory_resource &mr, - vecmem::copy &cpy, - detray::copy cpy_type = detray::copy::sync, - vecmem::data::buffer_type buff_type = - vecmem::data::buffer_type::fixed_size) - : _detector_buffer(detray::get_buffer(detray::get_data(det.volumes()), - mr, cpy, cpy_type, buff_type), - detray::get_buffer(det.transform_store(), mr, cpy, - cpy_type, buff_type), - detray::get_buffer(det.mask_store(), mr, cpy, - cpy_type, buff_type), - detray::get_buffer(det.material_store(), mr, cpy, - cpy_type, buff_type), - detray::get_buffer(det.surface_store(), mr, cpy, - cpy_type, buff_type), - detray::get_buffer(det.surface_lookup(), mr, cpy, - cpy_type, buff_type), - detray::get_buffer(det.volume_search_grid(), mr, cpy, - cpy_type, buff_type)), - _bfield(det.get_bfield()) {} - - /// Buffers were created manually - detector_buffer( - const detector_type &det, - detail::get_buffer_t - &&vol_buffer, - typename detector_type::transform_container::buffer_type &&trf_buffer, - typename detector_type::mask_container::buffer_type &&msk_buffer, - typename detector_type::material_container::buffer_type &&mat_buffer, - typename detector_type::surface_container::buffer_type &&sf_buffer, - detail::get_buffer_t - &&sf_lkp_buffer, - typename detector_type::volume_finder::buffer_type &&vgrd_buffer) - : _detector_buffer(std::move(vol_buffer), std::move(trf_buffer), - std::move(msk_buffer), std::move(mat_buffer), - std::move(sf_buffer), std::move(sf_lkp_buffer), - std::move(vgrd_buffer)), - _bfield(det.get_bfield()) {} - - /// Buffers for the vecemem types - typename detector_type::buffer_t _detector_buffer; - /// Covfie device field - covfie::field _bfield; -}; - -/// @brief The detector view -/// -/// Contains the views for all detector components, including the device view -/// of the bfield -template -struct detector_view { - - using detector_type = detector; - - detector_view(detector_type &det) - : _detector_data(detray::get_data(det.volumes()), - detray::get_data(det.transform_store()), - detray::get_data(det.mask_store()), - detray::get_data(det.material_store()), - detray::get_data(det.surface_store()), - detray::get_data(det.surface_lookup()), - detray::get_data(det.volume_search_grid())), - _bfield_view(det.get_bfield()) {} - - detector_view( - detector_buffer &det_buff) - : _detector_data(detray::get_data(det_buff._detector_buffer)), - _bfield_view(det_buff._bfield) {} - - /// Views for the vecmem types - typename detector_type::view_t _detector_data; - /// Covfie field view - covfie::field_view _bfield_view; }; -/// Stand-alone function that @returns the detector view for transfer to -/// device. -/// -/// @param detector the detector to be tranferred -template -inline detector_view get_data( - detector &det) { - return {det}; -} - -/// Stand-alone function that @returns the detector buffer for transfer to -/// device. -/// -/// @param detector the detector to be transferred -template -inline detector_buffer get_buffer( - detector &det, - vecmem::memory_resource &mr, vecmem::copy &cpy, - detray::copy cpy_type = detray::copy::sync, - vecmem::data::buffer_type buff_type = - vecmem::data::buffer_type::fixed_size) { - return {det, mr, cpy, cpy_type, buff_type}; -} - -/// Stand-alone function that @returns the detector view for transfer to -/// device. -/// -/// @param detector the detector to be transferred -template -inline detector_view get_data( - detector_buffer &det_buff) { - return {det_buff}; -} - } // namespace detray diff --git a/core/include/detray/propagator/rk_stepper.ipp b/core/include/detray/propagator/rk_stepper.ipp index 36f2678b6..3188d64e9 100644 --- a/core/include/detray/propagator/rk_stepper.ipp +++ b/core/include/detray/propagator/rk_stepper.ipp @@ -175,8 +175,7 @@ bool detray::rk_stepper class volume_builder_t = volume_builder, template class volume_data_t = std::vector> class detector_builder { public: - using detector_type = - detector, host_container_types>; + using detector_type = detector; /// Empty detector builder detector_builder() = default; @@ -88,7 +85,6 @@ class detector_builder { vol_builder->build(det); } - det.set_bfield(std::move(m_bfield)); det.set_volume_finder(std::move(m_vol_finder)); // TODO: Add sorting, data deduplication etc. here later... @@ -96,12 +92,6 @@ class detector_builder { return det; } - /// Assembles the detector, without a magnetic field - DETRAY_HOST - void set_bfield(typename detector_type::bfield_type&& field) { - m_bfield = std::forward(field); - } - /// Put the volumes into a search data structure template DETRAY_HOST void set_volume_finder(Args&&... /*args*/) { @@ -133,8 +123,6 @@ class detector_builder { m_volumes{}; /// Data structure to find volumes typename detector_type::volume_finder m_vol_finder{}; - /// The detector bfield - typename detector_type::bfield_type m_bfield; }; } // namespace detray diff --git a/io/CMakeLists.txt b/io/CMakeLists.txt index dc894618e..b22a80892 100644 --- a/io/CMakeLists.txt +++ b/io/CMakeLists.txt @@ -16,7 +16,7 @@ file( GLOB _detray_io_public_headers detray_add_library( detray_io io ${_detray_io_public_headers} ) target_link_libraries( detray_io INTERFACE - dfelibs::dfelibs nlohmann_json::nlohmann_json vecmem::core detray::core ) + dfelibs::dfelibs nlohmann_json::nlohmann_json vecmem::core covfie::core detray::core ) # Set up libraries using particular algebra plugins. detray_add_library( detray_io_array io_array ) diff --git a/io/include/detray/io/common/bfield_reader.hpp b/io/include/detray/io/common/bfield_reader.hpp deleted file mode 100644 index 64831c365..000000000 --- a/io/include/detray/io/common/bfield_reader.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2023 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s) -#include "detray/io/common/detail/file_handle.hpp" -#include "detray/io/common/io_interface.hpp" - -// Covfie include(s) -#include - -// System include(s) -#include -#include - -namespace detray { - -/// @brief Function that reads the first 4 bytes of a potential bfield file and -/// checks that it contains data for a covfie field -inline bool check_covfie_file(const std::string& file_name) { - - // Open binary file - io::detail::file_handle file{file_name, - std::ios_base::in | std::ios_base::binary}; - - // See "covfie/lib/core/utility/binary_io.hpp" - std::uint32_t hdr = covfie::utility::read_binary(*file); - - // Compare to magic bytes - return (hdr == covfie::utility::MAGIC_HEADER); -} - -/// @brief Reader that constructs a covfie field from file input -template -class covfie_file_reader : public reader_interface { - - using base_type = reader_interface; - - protected: - /// Tag the reader as magnetic field reader - inline static const std::string tag = "bfield"; - - public: - /// Same constructors for this class as for base_type - using base_type::base_type; - - /// Covfie constructs the field directly from the input stream in - /// @param file - auto deserialize(io::detail::file_handle& file) const { - return typename detector_t::bfield_type(*file); - } -}; - -/// @brief Generic magnetic field reader -template class reader_t> -class bfield_reader final : public reader_t { - - using base_reader = reader_t; - - public: - /// Default file ending for covfie input - bfield_reader() : base_reader{".cvf"} {} - - /// Read from file with given extension @param ext - bfield_reader(const std::string& ext) : base_reader{ext} {} - - /// Reads the geometry from file with the given name - virtual void read( - detector_builder& det_builder, - typename detector_t::name_map&, const std::string& file_name) override { - - io::detail::file_handle file{file_name, - std::ios_base::binary | std::ios_base::in}; - - det_builder.set_bfield(base_reader::deserialize(file)); - } -}; - -/// Read a covfie field from file and add it to a detray detector -template -using covfie_reader = bfield_reader; - -} // namespace detray diff --git a/io/include/detray/io/common/detail/detector_components_io.hpp b/io/include/detray/io/common/detail/detector_components_io.hpp index 4d7caa079..f33773ddc 100644 --- a/io/include/detray/io/common/detail/detector_components_io.hpp +++ b/io/include/detray/io/common/detail/detector_components_io.hpp @@ -107,11 +107,9 @@ class detector_component_readers final { /// Reads the full detector into @param det by calling the readers, while /// using the name map @param names for to write the volume names. - virtual void read( - detector_builder& det_builder, - typename detector_t::name_map& names) { + virtual void read(detector_builder& det_builder, + typename detector_t::name_map& names) { // We have to at least read a geometry assert(m_readers.size() != 0u && diff --git a/io/include/detray/io/common/detector_reader.hpp b/io/include/detray/io/common/detector_reader.hpp index b5c8a5c07..56c4171fe 100644 --- a/io/include/detray/io/common/detector_reader.hpp +++ b/io/include/detray/io/common/detector_reader.hpp @@ -8,18 +8,12 @@ #pragma once // Project include(s) -#include "detray/io/common/bfield_reader.hpp" #include "detray/io/common/detail/detector_components_io.hpp" #include "detray/io/common/detail/type_traits.hpp" #include "detray/io/json/json_reader.hpp" #include "detray/tools/detector_builder.hpp" #include "detray/utils/consistency_checker.hpp" -// Covfie include(s) -#include -#include -#include - // System include(s) #include #include @@ -46,12 +40,6 @@ struct detector_reader_config { /// @{ const std::vector& files() const { return m_files; } bool do_check() const { return m_do_check; } - template - auto bfield() const { - return covfie::field(covfie::make_parameter_pack( - typename const_bfield_bknd_t::configuration_t{ - m_bfield_vec[0], m_bfield_vec[1], m_bfield_vec[2]})); - } /// @} /// Setters @@ -64,11 +52,6 @@ struct detector_reader_config { m_do_check = check; return *this; } - detector_reader_config& bfield_vec(const scalar x, const scalar y, - const scalar z) { - m_bfield_vec = {x, y, z}; - return *this; - } /// @} }; @@ -125,15 +108,6 @@ auto assemble_reader(const io::detector_reader_config& cfg) noexcept(false) { header.tag + "' in input file: " + file_name); } - - // This is the file type covfie uses - } else if (extension == ".cvf" and check_covfie_file(file_name)) { - - if constexpr (not std::is_same_v< - typename detector_t::bfield_type::backend_t, - bfield::const_bknd_t>) { - readers.template add(file_name); - } } else { throw std::runtime_error("Unsupported file format '" + extension + "' for input file: " + file_name); @@ -163,24 +137,16 @@ template + detector_builder det_builder; // Find all required readers auto [reader, det_name] = detray::detail::assemble_reader(cfg); - // Add a constant b-field (no bfield reader is added in this case) - if constexpr (std::is_same_v) { - det_builder.set_bfield(cfg.template bfield()); - } - // Read the data names.emplace(0u, std::move(det_name)); reader.read(det_builder, names); diff --git a/io/include/detray/io/common/geometry_reader.hpp b/io/include/detray/io/common/geometry_reader.hpp index eed6f8924..c56a7cf67 100644 --- a/io/include/detray/io/common/geometry_reader.hpp +++ b/io/include/detray/io/common/geometry_reader.hpp @@ -64,12 +64,10 @@ class geometry_reader : public reader_interface { protected: /// Deserialize a detector @param det from its io payload @param det_data /// and add the volume names to @param name_map - static void deserialize( - detector_builder& det_builder, - typename detector_t::name_map& name_map, - const detector_payload& det_data) { + static void deserialize(detector_builder& det_builder, + typename detector_t::name_map& name_map, + const detector_payload& det_data) { // Deserialize the volumes one-by-one for (const auto& vol_data : det_data.volumes) { diff --git a/io/include/detray/io/common/grid_reader.hpp b/io/include/detray/io/common/grid_reader.hpp index 5b819f9be..35cc104f0 100644 --- a/io/include/detray/io/common/grid_reader.hpp +++ b/io/include/detray/io/common/grid_reader.hpp @@ -62,9 +62,8 @@ class grid_reader : public reader_interface { /// Deserialize the detector grids @param grids_data from their IO /// payload static void deserialize( - detector_builder &det_builder, + detector_builder + &det_builder, typename detector_t::name_map &, const detector_grids_payload &grids_data) { @@ -205,11 +204,9 @@ class grid_reader : public reader_interface { std::enable_if_t == Dim and types::size == Dim, bool> = true> - static void deserialize( - const grid_payload &grid_data, - detector_builder &det_builder) { + static void deserialize(const grid_payload &grid_data, + detector_builder &det_builder) { // Throw expection if the accelerator link type id is invalid auto print_error = [](io::detail::acc_type acc_link) -> void { @@ -280,12 +277,11 @@ class grid_reader : public reader_interface { std::enable_if_t = true> - static void deserialize( - const grid_payload &grid_data, - detector_builder &det_builder, - types::type_list, types::type_list) { + static void deserialize(const grid_payload &grid_data, + detector_builder &det_builder, + types::type_list, + types::type_list) { // Assemble the grid type using populator_t = regular_attacher; using axes_t = diff --git a/io/include/detray/io/common/homogeneous_material_reader.hpp b/io/include/detray/io/common/homogeneous_material_reader.hpp index 24987896a..0133c8e2f 100644 --- a/io/include/detray/io/common/homogeneous_material_reader.hpp +++ b/io/include/detray/io/common/homogeneous_material_reader.hpp @@ -46,9 +46,8 @@ class homogeneous_material_reader : public reader_interface { /// Deserialize the detector material @param det_mat_data from its IO /// payload static void deserialize( - detector_builder& det_builder, + detector_builder& + det_builder, typename detector_t::name_map& /*name_map*/, const detector_homogeneous_material_payload& det_mat_data) { using mat_types = typename detector_t::material_container::value_types; diff --git a/io/include/detray/io/common/io_interface.hpp b/io/include/detray/io/common/io_interface.hpp index 318f6b028..218fb4da8 100644 --- a/io/include/detray/io/common/io_interface.hpp +++ b/io/include/detray/io/common/io_interface.hpp @@ -37,9 +37,7 @@ class reader_interface { /// does not keep the volume names, the name map is also passed and /// filled. virtual void read( - detector_builder&, + detector_builder&, typename detector_t::name_map&, const std::string&) = 0; protected: diff --git a/io/include/detray/io/common/read_bfield.hpp b/io/include/detray/io/common/read_bfield.hpp new file mode 100644 index 000000000..d8888b4c1 --- /dev/null +++ b/io/include/detray/io/common/read_bfield.hpp @@ -0,0 +1,54 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2023 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s) +#include "detray/io/common/detail/file_handle.hpp" + +// Covfie include(s) +#include + +// System include(s) +#include +#include +#include +#include + +namespace detray::io { + +/// @brief Function that reads the first 4 bytes of a potential bfield file and +/// checks that it contains data for a covfie field +inline bool check_covfie_file(const std::string& file_name) { + + // Open binary file + io::detail::file_handle file{file_name, + std::ios_base::in | std::ios_base::binary}; + + // See "covfie/lib/core/utility/binary_io.hpp" + std::uint32_t hdr = covfie::utility::read_binary(*file); + + // Compare to magic bytes + return (hdr == covfie::utility::MAGIC_HEADER); +} + +/// @brief function that reads a covfie field from file +template +inline bfield_t read_bfield(const std::string& file_name) { + + if (not check_covfie_file(file_name)) { + throw std::runtime_error("Not a valid covfie file: " + file_name); + } + + // Open binary file + io::detail::file_handle file{file_name, + std::ios_base::in | std::ios_base::binary}; + + return bfield_t(*file); +} + +} // namespace detray::io diff --git a/io/include/detray/io/json/json_reader.hpp b/io/include/detray/io/json/json_reader.hpp index c66912333..6c62a2b07 100644 --- a/io/include/detray/io/json/json_reader.hpp +++ b/io/include/detray/io/json/json_reader.hpp @@ -68,12 +68,10 @@ class json_reader final : public common_reader_t { json_reader() : base_reader(".json") {} /// Writes the geometry to file with a given name - virtual void read( - detector_builder& det_builder, - typename detector_t::name_map& name_map, - const std::string& file_name) override { + virtual void read(detector_builder& det_builder, + typename detector_t::name_map& name_map, + const std::string& file_name) override { // Read json from file io::detail::file_handle file{file_name, diff --git a/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp b/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp index d962310cd..7b38b8f0b 100644 --- a/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp +++ b/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp @@ -7,6 +7,7 @@ // Project include(s) #include "benchmark_propagator_cuda_kernel.hpp" +#include "detray/detectors/create_toy_geometry.hpp" #include "detray/simulation/event_generator/track_generators.hpp" // Vecmem include(s) @@ -44,9 +45,10 @@ void fill_tracks(vecmem::vector> &tracks, template static void BM_PROPAGATOR_CPU(benchmark::State &state) { - // Create the toy geometry - auto [det, names] = - create_toy_geometry(host_mr, toy_cfg); + // Create the toy geometry and bfield + auto [det, names] = create_toy_geometry(host_mr, toy_cfg); + vector3 B{0.f, 0.f, 2.f * unit::T}; + auto bfield = bfield::create_const_field(B); // Create RK stepper rk_stepper_type s; @@ -84,7 +86,7 @@ static void BM_PROPAGATOR_CPU(benchmark::State &state) { tie(transporter_state, interactor_state, resetter_state); // Create the propagator state - propagator_host_type::state p_state(track, det.get_bfield(), det); + propagator_host_type::state p_state(track, bfield, det); // Run propagation if constexpr (opt == propagate_option::e_unsync) { @@ -103,11 +105,12 @@ template static void BM_PROPAGATOR_CUDA(benchmark::State &state) { // Create the toy geometry - auto [det, names] = - create_toy_geometry(bp_mng_mr, toy_cfg); + auto [det, names] = create_toy_geometry(bp_mng_mr, toy_cfg); + vector3 B{0.f, 0.f, 2.f * unit::T}; + auto bfield = bfield::create_const_field(B); // Get detector data - auto det_data = detray::get_data(det); + auto det_data = detray::get_data(det); // vecmem copy helper object vecmem::cuda::copy copy; @@ -136,7 +139,8 @@ static void BM_PROPAGATOR_CUDA(benchmark::State &state) { copy.setup(candidates_buffer); // Run the propagator test for GPU device - propagator_benchmark(det_data, tracks_data, candidates_buffer, opt); + propagator_benchmark(det_data, bfield, tracks_data, candidates_buffer, + opt); } state.counters["TracksPropagated"] = benchmark::Counter( diff --git a/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu b/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu index c852ba9a5..f512b625d 100644 --- a/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu +++ b/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu @@ -11,8 +11,8 @@ namespace detray { __global__ void __launch_bounds__(256, 4) propagator_benchmark_kernel( - typename detector_host_type::detector_view_type - det_data, + typename detector_host_type::view_type det_data, + covfie::field_view field_data, vecmem::data::vector_view> tracks_data, vecmem::data::jagged_vector_view candidates_data, const propagate_option opt) { @@ -45,7 +45,7 @@ __global__ void __launch_bounds__(256, 4) propagator_benchmark_kernel( auto actor_states = tie(transporter_state, interactor_state, resetter_state); // Create the propagator state - propagator_device_type::state p_state(tracks.at(gid), det.get_bfield(), det, + propagator_device_type::state p_state(tracks.at(gid), field_data, det, candidates.at(gid)); // Run propagation @@ -57,8 +57,8 @@ __global__ void __launch_bounds__(256, 4) propagator_benchmark_kernel( } void propagator_benchmark( - typename detector_host_type::detector_view_type - det_data, + typename detector_host_type::view_type det_data, + covfie::field_view field_data, vecmem::data::vector_view>& tracks_data, vecmem::data::jagged_vector_view& candidates_data, const propagate_option opt) { @@ -69,7 +69,7 @@ void propagator_benchmark( // run the test kernel propagator_benchmark_kernel<<>>( - det_data, tracks_data, candidates_data, opt); + det_data, field_data, tracks_data, candidates_data, opt); // cuda error check DETRAY_CUDA_ERROR_CHECK(cudaGetLastError()); diff --git a/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.hpp b/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.hpp index 7d631ef4d..223ccc097 100644 --- a/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.hpp +++ b/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.hpp @@ -9,9 +9,9 @@ // Project include(s) #include "detray/definitions/algebra.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" -#include "detray/detectors/create_toy_geometry.hpp" +#include "detray/detectors/bfield.hpp" +#include "detray/detectors/toy_metadata.hpp" #include "detray/propagator/actor_chain.hpp" #include "detray/propagator/actors/aborters.hpp" #include "detray/propagator/actors/parameter_resetter.hpp" @@ -27,19 +27,15 @@ using namespace detray; using transform3 = __plugin::transform3; -using detector_host_type = - detector, - host_container_types>; -using detector_device_type = - detector, - device_container_types>; +using detector_host_type = detector; +using detector_device_type = detector; using intersection_t = intersection2D; using navigator_host_type = navigator; using navigator_device_type = navigator; -using field_type = detector_host_type::bfield_type; +using field_type = bfield::const_field_t; using rk_stepper_type = rk_stepper; using actor_chain_t = actor_chain, pointwise_material_interactor, @@ -58,8 +54,8 @@ namespace detray { /// test function for propagator with single state void propagator_benchmark( - typename detector_host_type::detector_view_type - det_data, + typename detector_host_type::view_type det_data, + typename field_type::view_t field_data, vecmem::data::vector_view>& tracks_data, vecmem::data::jagged_vector_view& candidates_data, const propagate_option opt); diff --git a/tests/common/include/tests/common/test_base/propagator_test.hpp b/tests/common/include/tests/common/test_base/propagator_test.hpp index ec7096a53..b1286696a 100644 --- a/tests/common/include/tests/common/test_base/propagator_test.hpp +++ b/tests/common/include/tests/common/test_base/propagator_test.hpp @@ -9,9 +9,9 @@ // Project include(s). #include "detray/definitions/algebra.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" -#include "detray/detectors/create_toy_geometry.hpp" +#include "detray/detectors/bfield.hpp" +#include "detray/detectors/toy_metadata.hpp" #include "detray/propagator/actor_chain.hpp" #include "detray/propagator/actors/aborters.hpp" #include "detray/propagator/actors/parameter_resetter.hpp" @@ -36,19 +36,15 @@ namespace detray { // Host detector type -template -using detector_host_t = - detector, host_container_types>; +using detector_host_t = detector; // Device detector type using views -template -using detector_device_t = - detector, - device_container_types>; +using detector_device_t = detector; // These types are identical in host and device code for all bfield types -using transform3 = typename detector_host_t::transform3; +using transform3 = typename detector_host_t::transform3; using vector3_t = typename transform3::vector3; +using point3_t = typename transform3::point3; using matrix_operator = standard_matrix_operator; using track_t = free_track_parameters; using free_matrix = typename track_t::covariance_type; @@ -64,9 +60,6 @@ using constraints_t = constrained_step<>; template using rk_stepper_t = rk_stepper; -// Detector configuration -toy_det_config toy_cfg{}; - // Geomery navigation configurations constexpr unsigned int theta_steps{10u}; constexpr unsigned int phi_steps{10u}; @@ -156,16 +149,16 @@ inline vecmem::vector generate_tracks( /// Test function for propagator on the host template inline auto run_propagation_host(vecmem::memory_resource *mr, - const detector_host_t &det, + const detector_host_t &det, + covfie::field &field, const vecmem::vector &tracks) -> std::tuple, vecmem::jagged_vector, vecmem::jagged_vector> { // Construct propagator from stepper and navigator - auto stepr = rk_stepper_t< - typename detector_host_t::bfield_type::view_t>{}; - auto nav = navigator_t>{}; + auto stepr = rk_stepper_t::view_t>{}; + auto nav = navigator_t{}; using propagator_host_t = propagator; @@ -188,7 +181,7 @@ inline auto run_propagation_host(vecmem::memory_resource *mr, detray::tie(insp_state, pathlimit_state, transporter_state, interactor_state, resetter_state); - typename propagator_host_t::state state(trk, det.get_bfield(), det); + typename propagator_host_t::state state(trk, field, det); state._stepping.template set_constraint( constrainted_step_size); @@ -234,7 +227,7 @@ inline void compare_propagation_results( const vector3_t &device_pos = device_positions[i][j]; auto relative_error = - static_cast(1. / host_pl * (host_pos - device_pos)); + static_cast(1. / host_pl * (host_pos - device_pos)); ASSERT_NEAR(getter::norm(relative_error), 0.f, is_close); } diff --git a/tests/unit_tests/cpu/grid_grid_builder.cpp b/tests/unit_tests/cpu/grid_grid_builder.cpp index abda75aed..db985e79d 100644 --- a/tests/unit_tests/cpu/grid_grid_builder.cpp +++ b/tests/unit_tests/cpu/grid_grid_builder.cpp @@ -9,7 +9,6 @@ // Detray include(s) #include "detray/core/detector.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/indexing.hpp" #include "detray/detectors/toy_metadata.hpp" #include "detray/intersection/cylinder_portal_intersector.hpp" diff --git a/tests/unit_tests/cpu/line_stepper.cpp b/tests/unit_tests/cpu/line_stepper.cpp index 7bdeff45e..48ccf7c2f 100644 --- a/tests/unit_tests/cpu/line_stepper.cpp +++ b/tests/unit_tests/cpu/line_stepper.cpp @@ -8,7 +8,6 @@ // Project include(s). #include "detray/propagator/line_stepper.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" #include "detray/detectors/create_telescope_detector.hpp" #include "detray/masks/masks.hpp" diff --git a/tests/unit_tests/cpu/tools_guided_navigator.cpp b/tests/unit_tests/cpu/tools_guided_navigator.cpp index 88ab9e685..e4eaba151 100644 --- a/tests/unit_tests/cpu/tools_guided_navigator.cpp +++ b/tests/unit_tests/cpu/tools_guided_navigator.cpp @@ -5,11 +5,8 @@ * Mozilla Public License Version 2.0 */ -#include - -#include - #include "detray/definitions/units.hpp" +#include "detray/detectors/bfield.hpp" #include "detray/detectors/create_telescope_detector.hpp" #include "detray/masks/masks.hpp" #include "detray/masks/unbounded.hpp" @@ -23,6 +20,12 @@ #include "detray/tracks/tracks.hpp" #include "detray/utils/inspectors.hpp" +// vecmem include(s) +#include + +// GTest include(s) +#include + // This tests the construction and general methods of the navigator GTEST_TEST(detray_propagator, guided_navigator) { using namespace detray; @@ -53,7 +56,7 @@ GTEST_TEST(detray_propagator, guided_navigator) { object_tracer; using inspector_t = aggregate_inspector; - using b_field_t = detector_t::bfield_type; + using b_field_t = bfield::const_field_t; using runge_kutta_stepper = rk_stepper; @@ -67,8 +70,7 @@ GTEST_TEST(detray_propagator, guided_navigator) { const vector3 mom{0.f, 0.f, 1.f}; free_track_parameters track(pos, 0.f, mom, -1.f); const vector3 B{0.f, 0.f, 1.f * unit::T}; - const b_field_t b_field(covfie::make_parameter_pack( - b_field_t::backend_t::configuration_t{B[0], B[1], B[2]})); + const b_field_t b_field = bfield::create_const_field(B); // Actors pathlimit_aborter::state pathlimit{200.f * unit::cm}; diff --git a/tests/unit_tests/cpu/tools_particle_gun.cpp b/tests/unit_tests/cpu/tools_particle_gun.cpp index b8c30be22..c6a6e3ceb 100644 --- a/tests/unit_tests/cpu/tools_particle_gun.cpp +++ b/tests/unit_tests/cpu/tools_particle_gun.cpp @@ -37,7 +37,6 @@ GTEST_TEST(detray_tools, particle_gun) { // Build the geometry vecmem::host_memory_resource host_mr; toy_det_config toy_cfg{}; - toy_cfg.bfield_vec(B); auto [toy_det, names] = create_toy_geometry(host_mr, toy_cfg); diff --git a/tests/unit_tests/cpu/tools_propagator.cpp b/tests/unit_tests/cpu/tools_propagator.cpp index 3b0589007..5b6d35a8d 100644 --- a/tests/unit_tests/cpu/tools_propagator.cpp +++ b/tests/unit_tests/cpu/tools_propagator.cpp @@ -6,8 +6,8 @@ */ // Project include(s) -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" +#include "detray/detectors/bfield.hpp" #include "detray/detectors/create_toy_geometry.hpp" #include "detray/geometry/surface.hpp" #include "detray/intersection/detail/trajectories.hpp" @@ -170,10 +170,10 @@ class PropagatorWithRkStepper TEST_P(PropagatorWithRkStepper, rk4_propagator_const_bfield) { // Constant magnetic field type - using bfield_t = covfie::field; + using bfield_t = bfield::const_field_t; // Toy detector - using detector_t = detector; + using detector_t = detector; // Runge-Kutta propagation using navigator_t = navigator; @@ -191,9 +191,10 @@ TEST_P(PropagatorWithRkStepper, rk4_propagator_const_bfield) { using propagator_t = propagator; // Build detector and magnetic field - toy_cfg.bfield_vec(std::get<2>(GetParam())); const auto [det, names] = create_toy_geometry(host_mr, toy_cfg); + const bfield_t bfield = bfield::create_const_field(std::get<2>(GetParam())); + // Propagator is built from the stepper and navigator propagator_t p(stepper_t{}, navigator_t{}); @@ -228,8 +229,8 @@ TEST_P(PropagatorWithRkStepper, rk4_propagator_const_bfield) { transporter_state, interactor_state, resetter_state); // Init propagator states - propagator_t::state state(track, det.get_bfield(), det); - propagator_t::state lim_state(lim_track, det.get_bfield(), det); + propagator_t::state state(track, bfield, det); + propagator_t::state lim_state(lim_track, bfield, det); // Set step constraints state._stepping.template set_constraint( @@ -270,10 +271,10 @@ TEST_P(PropagatorWithRkStepper, rk4_propagator_const_bfield) { TEST_P(PropagatorWithRkStepper, rk4_propagator_inhom_bfield) { // Magnetic field map using nearest neightbor interpolation - using bfield_t = covfie::field; + using bfield_t = bfield::inhom_field_t; // Toy detector - using detector_t = detector; + using detector_t = detector; // Runge-Kutta propagation using navigator_t = navigator; @@ -291,8 +292,9 @@ TEST_P(PropagatorWithRkStepper, rk4_propagator_inhom_bfield) { using propagator_t = propagator; // Build detector and magnetic field - const auto [det, names] = - create_toy_geometry(host_mr, toy_cfg); + const auto [det, names] = create_toy_geometry(host_mr, toy_cfg); + const bfield_t bfield = bfield::create_inhom_field(); + // Propagator is built from the stepper and navigator propagator_t p(stepper_t{}, navigator_t{}); @@ -323,8 +325,8 @@ TEST_P(PropagatorWithRkStepper, rk4_propagator_inhom_bfield) { transporter_state, interactor_state, resetter_state); // Init propagator states - propagator_t::state state(track, det.get_bfield(), det); - propagator_t::state lim_state(lim_track, det.get_bfield(), det); + propagator_t::state state(track, bfield, det); + propagator_t::state lim_state(lim_track, bfield, det); // Set step constraints state._stepping.template set_constraint( diff --git a/tests/unit_tests/cpu/tools_stepper.cpp b/tests/unit_tests/cpu/tools_stepper.cpp index b05221c60..8cd6814cf 100644 --- a/tests/unit_tests/cpu/tools_stepper.cpp +++ b/tests/unit_tests/cpu/tools_stepper.cpp @@ -6,8 +6,8 @@ */ // detray include(s) -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" +#include "detray/detectors/bfield.hpp" #include "detray/geometry/surface.hpp" #include "detray/intersection/detail/trajectories.hpp" #include "detray/io/common/detail/file_handle.hpp" @@ -38,18 +38,6 @@ namespace { constexpr scalar tol{1e-3f}; -template -inline bfield_t load_field() { - detray::io::detail::file_handle file( - !std::getenv("DETRAY_BFIELD_FILE") ? "" - : std::getenv("DETRAY_BFIELD_FILE"), - std::ios_base::binary | std::ios_base::in); - - bfield_t field(*file); - - return field; -} - // dummy navigation struct struct nav_state { scalar operator()() const { return _step_size; } @@ -150,12 +138,11 @@ GTEST_TEST(detray_propagator, rk_stepper) { using namespace step; // Constant magnetic field - using bfield_t = covfie::field; + using bfield_t = bfield::const_field_t; vector3 B{1.f * unit::T, 1.f * unit::T, 1.f * unit::T}; - bfield_t hom_bfield(covfie::make_parameter_pack( - typename bfield_t::backend_t::configuration_t{B[0], B[1], B[2]})); + const bfield_t hom_bfield = bfield::create_const_field(B); // RK stepper rk_stepper_t rk_stepper; @@ -256,10 +243,9 @@ GTEST_TEST(detray_propagator, rk_stepper) { TEST(detray_propagator, rk_stepper_inhomogeneous_bfield) { using namespace step; - using bfield_t = covfie::field; - // Read the magnetic field map - bfield_t inhom_bfield(load_field()); + using bfield_t = bfield::inhom_field_t; + bfield_t inhom_bfield = bfield::create_inhom_field(); // RK stepper rk_stepper_t rk_stepper; diff --git a/tests/unit_tests/device/cuda/detector_cuda.cpp b/tests/unit_tests/device/cuda/detector_cuda.cpp index 98ee47cb4..39d9abe9f 100644 --- a/tests/unit_tests/device/cuda/detector_cuda.cpp +++ b/tests/unit_tests/device/cuda/detector_cuda.cpp @@ -53,7 +53,7 @@ TEST(detector_cuda, detector) { vecmem::vector cylinders_device(cylinders_host.size(), &mng_mr); // get data object for toy detector - auto toy_det_data = detray::get_data(toy_det); + auto toy_det_data = detray::get_data(toy_det); // get data object for device outputs auto volumes_data = vecmem::get_data(volumes_device); diff --git a/tests/unit_tests/device/cuda/detector_cuda_kernel.cu b/tests/unit_tests/device/cuda/detector_cuda_kernel.cu index 14e993071..cc939b938 100644 --- a/tests/unit_tests/device/cuda/detector_cuda_kernel.cu +++ b/tests/unit_tests/device/cuda/detector_cuda_kernel.cu @@ -12,7 +12,7 @@ namespace detray { // cuda kernel to copy sub-detector objects __global__ void detector_test_kernel( - typename detector_host_t::detector_view_type det_data, + typename detector_host_t::view_type det_data, vecmem::data::vector_view volumes_data, vecmem::data::vector_view surfaces_data, vecmem::data::vector_view transforms_data, @@ -84,14 +84,13 @@ __global__ void detector_test_kernel( } /// implementation of the test function for detector -void detector_test( - typename detector_host_t::detector_view_type det_data, - vecmem::data::vector_view volumes_data, - vecmem::data::vector_view surfaces_data, - vecmem::data::vector_view transforms_data, - vecmem::data::vector_view rectangles_data, - vecmem::data::vector_view discs_data, - vecmem::data::vector_view cylinders_data) { +void detector_test(typename detector_host_t::view_type det_data, + vecmem::data::vector_view volumes_data, + vecmem::data::vector_view surfaces_data, + vecmem::data::vector_view transforms_data, + vecmem::data::vector_view rectangles_data, + vecmem::data::vector_view discs_data, + vecmem::data::vector_view cylinders_data) { constexpr int block_dim = 1u; constexpr int thread_dim = 1u; diff --git a/tests/unit_tests/device/cuda/detector_cuda_kernel.hpp b/tests/unit_tests/device/cuda/detector_cuda_kernel.hpp index 503d4b1f9..9067e1b3f 100644 --- a/tests/unit_tests/device/cuda/detector_cuda_kernel.hpp +++ b/tests/unit_tests/device/cuda/detector_cuda_kernel.hpp @@ -10,7 +10,6 @@ // Projetc include(s) #include "detray/core/detector.hpp" #include "detray/definitions/algebra.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/detectors/toy_metadata.hpp" #include "detray/utils/ranges.hpp" @@ -20,12 +19,8 @@ using namespace __plugin; namespace detray { // some useful type declarations -using detector_host_t = - detector, - host_container_types>; -using detector_device_t = - detector, - device_container_types>; +using detector_host_t = detector; +using detector_device_t = detector; using volume_t = typename detector_host_t::volume_type; using surface_t = typename detector_host_t::surface_type; @@ -41,13 +36,12 @@ using disc_t = typename mask_defs::template get_type::type; using cylinder_t = typename mask_defs::template get_type::type; /// declaration of a test function for detector -void detector_test( - typename detector_host_t::detector_view_type det_data, - vecmem::data::vector_view volumes_data, - vecmem::data::vector_view surfaces_data, - vecmem::data::vector_view transforms_data, - vecmem::data::vector_view rectangles_data, - vecmem::data::vector_view discs_data, - vecmem::data::vector_view cylinders_data); +void detector_test(typename detector_host_t::view_type det_data, + vecmem::data::vector_view volumes_data, + vecmem::data::vector_view surfaces_data, + vecmem::data::vector_view transforms_data, + vecmem::data::vector_view rectangles_data, + vecmem::data::vector_view discs_data, + vecmem::data::vector_view cylinders_data); } // namespace detray diff --git a/tests/unit_tests/device/cuda/navigator_cuda.cpp b/tests/unit_tests/device/cuda/navigator_cuda.cpp index a622042b3..78cecd6c9 100644 --- a/tests/unit_tests/device/cuda/navigator_cuda.cpp +++ b/tests/unit_tests/device/cuda/navigator_cuda.cpp @@ -5,13 +5,17 @@ * Mozilla Public License Version 2.0 */ -#include +// Project include(s) +#include "detray/detectors/create_toy_geometry.hpp" +#include "navigator_cuda_kernel.hpp" +// vecmem include(s) #include #include +#include -#include "navigator_cuda_kernel.hpp" -#include "vecmem/utils/cuda/copy.hpp" +// GTest include(s) +#include TEST(navigator_cuda, navigator) { @@ -103,7 +107,7 @@ TEST(navigator_cuda, navigator) { copy.setup(position_records_buffer); // Get detector data - auto det_data = detray::get_data(det); + auto det_data = detray::get_data(det); // Get tracks data auto tracks_data = vecmem::get_data(tracks_device); diff --git a/tests/unit_tests/device/cuda/navigator_cuda_kernel.cu b/tests/unit_tests/device/cuda/navigator_cuda_kernel.cu index d21255785..2cf6ccd90 100644 --- a/tests/unit_tests/device/cuda/navigator_cuda_kernel.cu +++ b/tests/unit_tests/device/cuda/navigator_cuda_kernel.cu @@ -11,7 +11,7 @@ namespace detray { __global__ void navigator_test_kernel( - typename detector_host_t::detector_view_type det_data, + typename detector_host_t::view_type det_data, vecmem::data::vector_view> tracks_data, vecmem::data::jagged_vector_view candidates_data, vecmem::data::jagged_vector_view volume_records_data, @@ -63,7 +63,7 @@ __global__ void navigator_test_kernel( } void navigator_test( - typename detector_host_t::detector_view_type det_data, + typename detector_host_t::view_type det_data, vecmem::data::vector_view>& tracks_data, vecmem::data::jagged_vector_view& candidates_data, vecmem::data::jagged_vector_view& volume_records_data, diff --git a/tests/unit_tests/device/cuda/navigator_cuda_kernel.hpp b/tests/unit_tests/device/cuda/navigator_cuda_kernel.hpp index 2adeb8e9e..8da848f6f 100644 --- a/tests/unit_tests/device/cuda/navigator_cuda_kernel.hpp +++ b/tests/unit_tests/device/cuda/navigator_cuda_kernel.hpp @@ -9,9 +9,8 @@ // Project include(s) #include "detray/definitions/algebra.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" -#include "detray/detectors/create_toy_geometry.hpp" +#include "detray/detectors/toy_metadata.hpp" #include "detray/propagator/line_stepper.hpp" #include "detray/propagator/navigator.hpp" #include "detray/simulation/event_generator/track_generators.hpp" @@ -19,14 +18,11 @@ using namespace detray; using transform3 = __plugin::transform3; +using point3 = __plugin::point3; // some useful type declarations -using detector_host_t = - detector, - host_container_types>; -using detector_device_t = - detector, - device_container_types>; +using detector_host_t = detector; +using detector_device_t = detector; using intersection_t = intersection2D; @@ -60,7 +56,7 @@ namespace detray { /// test function for navigator with single state void navigator_test( - typename detector_host_t::detector_view_type det_data, + typename detector_host_t::view_type det_data, vecmem::data::vector_view>& tracks_data, vecmem::data::jagged_vector_view& candidates_data, vecmem::data::jagged_vector_view& volume_records_data, diff --git a/tests/unit_tests/device/cuda/propagator_cuda.cpp b/tests/unit_tests/device/cuda/propagator_cuda.cpp index e3337df8f..9acf3ddaa 100644 --- a/tests/unit_tests/device/cuda/propagator_cuda.cpp +++ b/tests/unit_tests/device/cuda/propagator_cuda.cpp @@ -6,6 +6,8 @@ */ // Project include(s) +#include "detray/detectors/bfield.hpp" +#include "detray/detectors/create_toy_geometry.hpp" #include "propagator_cuda_kernel.hpp" // Vecmem include(s) @@ -26,15 +28,15 @@ TEST_P(CudaPropConstBFieldMng, propagator) { // VecMem memory resource(s) vecmem::cuda::managed_memory_resource mng_mr; - // Set the magnetic field + // Get the magnetic field const vector3_t B = GetParam(); + auto field = bfield::create_const_field(B); // Create the toy geometry - toy_cfg.bfield_vec(B); - auto [det, names] = create_toy_geometry(mng_mr, toy_cfg); + auto [det, names] = create_toy_geometry(mng_mr); run_propagation_test( - &mng_mr, det, detray::get_data(det)); + &mng_mr, det, detray::get_data(det), std::move(field)); } class CudaPropConstBFieldCpy : public ::testing::TestWithParam {}; @@ -48,18 +50,17 @@ TEST_P(CudaPropConstBFieldCpy, propagator) { vecmem::cuda::copy cuda_cpy; - // Set the magnetic field + // Get the magnetic field const vector3_t B = GetParam(); + auto field = bfield::create_const_field(B); // Create the toy geometry - toy_cfg.bfield_vec(B); - auto [det, names] = create_toy_geometry(host_mr, toy_cfg); + auto [det, names] = create_toy_geometry(host_mr); - auto det_buff = - detray::get_buffer(det, dev_mr, cuda_cpy); + auto det_buff = detray::get_buffer(det, dev_mr, cuda_cpy); - run_propagation_test(&mng_mr, det, - detray::get_data(det_buff)); + run_propagation_test( + &mng_mr, det, detray::get_data(det_buff), std::move(field)); } INSTANTIATE_TEST_SUITE_P(CudaPropagatorValidation1, CudaPropConstBFieldMng, @@ -112,13 +113,14 @@ TEST(CudaPropagatorValidation10, inhomogeneous_bfield_cpy) { vecmem::cuda::copy cuda_cpy; + // Get the magnetic field + auto field = bfield::create_inhom_field(); + // Create the toy geometry with inhomogeneous bfield from file - auto [det, names] = - create_toy_geometry(host_mr, toy_cfg); + auto [det, names] = create_toy_geometry(host_mr); - auto det_buff = - detray::get_buffer(det, dev_mr, cuda_cpy); + auto det_buff = detray::get_buffer(det, dev_mr, cuda_cpy); run_propagation_test( - &mng_mr, det, detray::get_data(det_buff)); + &mng_mr, det, detray::get_data(det_buff), std::move(field)); } diff --git a/tests/unit_tests/device/cuda/propagator_cuda_kernel.cu b/tests/unit_tests/device/cuda/propagator_cuda_kernel.cu index a8bd87997..e44f29d0d 100644 --- a/tests/unit_tests/device/cuda/propagator_cuda_kernel.cu +++ b/tests/unit_tests/device/cuda/propagator_cuda_kernel.cu @@ -12,7 +12,8 @@ namespace detray { template __global__ void propagator_test_kernel( - typename detector_t::template detector_view_type det_data, + typename detector_t::view_type det_data, + covfie::field_view field_data, vecmem::data::vector_view tracks_data, vecmem::data::jagged_vector_view> candidates_data, @@ -22,7 +23,7 @@ __global__ void propagator_test_kernel( int gid = threadIdx.x + blockIdx.x * blockDim.x; - detector_device_t det(det_data); + detector_device_t det(det_data); vecmem::device_vector tracks(tracks_data); vecmem::jagged_device_vector> candidates( candidates_data); @@ -35,9 +36,8 @@ __global__ void propagator_test_kernel( return; } - auto stepr = - rk_stepper_t::bfield_type>{}; - auto nav = navigator_t>{}; + auto stepr = rk_stepper_t>{}; + auto nav = navigator_t{}; // Create propagator using propagator_device_t = @@ -57,8 +57,8 @@ __global__ void propagator_test_kernel( ::detray::tie(insp_state, aborter_state, transporter_state, interactor_state, resetter_state); // Create the propagator state - typename propagator_device_t::state state(tracks[gid], det.get_bfield(), - det, candidates.at(gid)); + typename propagator_device_t::state state(tracks[gid], field_data, det, + candidates.at(gid)); state._stepping.set_tolerance(rk_tolerance); @@ -72,7 +72,8 @@ __global__ void propagator_test_kernel( /// Launch the device kernel template void propagator_test( - typename detector_t::template detector_view_type det_view, + typename detector_t::view_type det_view, + covfie::field_view field_data, vecmem::data::vector_view& tracks_data, vecmem::data::jagged_vector_view>& candidates_data, @@ -85,9 +86,9 @@ void propagator_test( // run the test kernel propagator_test_kernel - <<>>(det_view, tracks_data, candidates_data, - path_lengths_data, positions_data, - jac_transports_data); + <<>>(det_view, field_data, tracks_data, + candidates_data, path_lengths_data, + positions_data, jac_transports_data); // cuda error check DETRAY_CUDA_ERROR_CHECK(cudaGetLastError()); @@ -95,25 +96,19 @@ void propagator_test( } /// Explicit instantiation for a constant magnetic field -template void -propagator_test>( - detector_host_t::template detector_view_type< - bfield::const_bknd_t>, +template void propagator_test( + detector_host_t::view_type, covfie::field_view, vecmem::data::vector_view&, - vecmem::data::jagged_vector_view< - intersection_t>>&, + vecmem::data::jagged_vector_view>&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&); /// Explicit instantiation for an inhomogeneous magnetic field -template void propagator_test>( - detector_host_t::template detector_view_type< - bfield::cuda::inhom_bknd_t>, +template void propagator_test( + detector_host_t::view_type, covfie::field_view, vecmem::data::vector_view&, - vecmem::data::jagged_vector_view< - intersection_t>>&, + vecmem::data::jagged_vector_view>&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&); diff --git a/tests/unit_tests/device/cuda/propagator_cuda_kernel.hpp b/tests/unit_tests/device/cuda/propagator_cuda_kernel.hpp index 718684df3..8200fe648 100644 --- a/tests/unit_tests/device/cuda/propagator_cuda_kernel.hpp +++ b/tests/unit_tests/device/cuda/propagator_cuda_kernel.hpp @@ -7,6 +7,7 @@ #pragma once +// Project include(s) #include "tests/common/test_base/propagator_test.hpp" // Vecmem include(s) @@ -31,7 +32,7 @@ using inhom_bknd_t = covfie::backend::affine< /// Launch the propagation test kernel template void propagator_test( - typename detector_t::template detector_view_type, + typename detector_t::view_type, covfie::field_view, vecmem::data::vector_view &, vecmem::data::jagged_vector_view> &, vecmem::data::jagged_vector_view &, @@ -42,8 +43,8 @@ void propagator_test( template inline auto run_propagation_device( vecmem::memory_resource *mr, detector_t &det, - typename detector_t::template detector_view_type det_view, - dvector &tracks, + typename detector_t::view_type det_view, + covfie::field_view field_data, dvector &tracks, const vecmem::jagged_vector &host_positions) -> std::tuple, vecmem::jagged_vector, @@ -80,8 +81,8 @@ inline auto run_propagation_device( // Run the propagator test for GPU device propagator_test( - det_view, tracks_data, candidates_buffer, path_lengths_buffer, - positions_buffer, jac_transports_buffer); + det_view, field_data, tracks_data, candidates_buffer, + path_lengths_buffer, positions_buffer, jac_transports_buffer); vecmem::jagged_vector device_path_lengths(mr); vecmem::jagged_vector device_positions(mr); @@ -97,10 +98,11 @@ inline auto run_propagation_device( } /// Test chain for the propagator -template -inline auto run_propagation_test( - vecmem::memory_resource *mr, detector_t &det, - typename detector_t::template detector_view_type det_view) { +template +inline auto run_propagation_test(vecmem::memory_resource *mr, detector_t &det, + typename detector_t::view_type det_view, + covfie::field &&field) { // Create the vector of initial track parameterizations auto tracks_host = generate_tracks(mr); @@ -108,12 +110,13 @@ inline auto run_propagation_test( // Host propagation auto &&[host_path_lengths, host_positions, host_jac_transports] = - run_propagation_host(mr, det, tracks_host); + run_propagation_host(mr, det, field, tracks_host); // Device propagation (device backend specific implementation) + covfie::field device_field(field); auto &&[device_path_lengths, device_positions, device_jac_transports] = - run_propagation_device(mr, det, det_view, tracks_device, - host_positions); + run_propagation_device( + mr, det, det_view, device_field, tracks_device, host_positions); // Check the results compare_propagation_results(host_positions, device_positions, diff --git a/tests/unit_tests/device/sycl/propagator.sycl b/tests/unit_tests/device/sycl/propagator.sycl index 05c0bd5bd..d56a3cb42 100644 --- a/tests/unit_tests/device/sycl/propagator.sycl +++ b/tests/unit_tests/device/sycl/propagator.sycl @@ -6,6 +6,7 @@ */ // Project include(s) +#include "detray/detectors/create_toy_geometry.hpp" #include "propagator_sycl_kernel.hpp" // Vecmem include(s) @@ -43,14 +44,16 @@ TEST_P(SyclPropConstBFieldMng, propagator) { vecmem::sycl::shared_memory_resource shared_mr; // Set the magnetic field - const vector3 B = GetParam(); + const vector3_t B = GetParam(); + auto field = bfield::create_const_field(B); // Create the toy geometry - toy_cfg.bfield_vec(B); - auto [det, names] = create_toy_geometry(shared_mr, toy_cfg); + auto [det, names] = create_toy_geometry(shared_mr); - run_propagation_test( - &shared_mr, &q, det, detray::get_data(det)); + auto det_view = detray::get_data(det); + + run_propagation_test(&shared_mr, &q, det, det_view, + field); } class SyclPropConstBFieldCpy : public ::testing::TestWithParam {}; @@ -71,17 +74,16 @@ TEST_P(SyclPropConstBFieldCpy, propagator) { vecmem::sycl::copy sycl_cpy(q_wrapper); // Set the magnetic field - const vector3 B = GetParam(); + const vector3_t B = GetParam(); + auto field = bfield::create_const_field(B); // Create the toy geometry - toy_cfg.bfield_vec(B); - auto [det, names] = create_toy_geometry(host_mr, toy_cfg); + auto [det, names] = create_toy_geometry(host_mr); - auto det_buff = - detray::get_buffer(det, dev_mr, sycl_cpy); + auto det_buff = detray::get_buffer(det, dev_mr, sycl_cpy); - run_propagation_test(&shared_mr, &q, det, - detray::get_data(det_buff)); + run_propagation_test( + &shared_mr, &q, det, detray::get_data(det_buff), field); } INSTANTIATE_TEST_SUITE_P(SyclPropagatorValidation1, SyclPropConstBFieldMng, diff --git a/tests/unit_tests/device/sycl/propagator_kernel.sycl b/tests/unit_tests/device/sycl/propagator_kernel.sycl index 22dec4175..1e0f5d043 100644 --- a/tests/unit_tests/device/sycl/propagator_kernel.sycl +++ b/tests/unit_tests/device/sycl/propagator_kernel.sycl @@ -13,7 +13,8 @@ namespace detray { /// Test function for propagator template void propagator_test( - typename detector_t::template detector_view_type det_data, + typename detector_t::view_type det_data, + covfie::field_view field_data, vecmem::data::vector_view& tracks_data, vecmem::data::jagged_vector_view>& candidates_data, @@ -31,18 +32,19 @@ void propagator_test( reinterpret_cast<::sycl::queue*>(queue.queue()) ->submit([&](::sycl::handler& h) { - h.parallel_for(ndrange, [det_data, tracks_data, candidates_data, - path_lengths_data, positions_data, - jac_transports_data]( + h.parallel_for(ndrange, [det_data, field_data, tracks_data, + candidates_data, path_lengths_data, + positions_data, jac_transports_data]( ::sycl::nd_item<1> item) { - detector_device_t dev_det(det_data); + detector_device_t dev_det(det_data); vecmem::device_vector tracks(tracks_data); vecmem::jagged_device_vector> candidates(candidates_data); vecmem::jagged_device_vector path_lengths( path_lengths_data); - vecmem::jagged_device_vector positions(positions_data); + vecmem::jagged_device_vector positions( + positions_data); vecmem::jagged_device_vector jac_transports( jac_transports_data); @@ -52,9 +54,8 @@ void propagator_test( return; } - auto stepr = rk_stepper_t< - typename detector_device_t::bfield_type>{}; - auto nav = navigator_t>{}; + auto stepr = rk_stepper_t>{}; + auto nav = navigator_t{}; // Create propagator using propagator_device_t = @@ -78,8 +79,7 @@ void propagator_test( interactor_state, resetter_state); // Create the propagator state typename propagator_device_t::state state( - tracks[gid], dev_det.get_bfield(), dev_det, - candidates.at(gid)); + tracks[gid], field_data, dev_det, candidates.at(gid)); state._stepping.set_tolerance(rk_tolerance); @@ -94,26 +94,21 @@ void propagator_test( } /// Explicit instantiation for a constant magnetic field -template void -propagator_test>( - detector_host_t::template detector_view_type< - bfield::const_bknd_t>, +template void propagator_test( + detector_host_t::view_type, covfie::field_view, vecmem::data::vector_view&, - vecmem::data::jagged_vector_view< - intersection_t>>&, + vecmem::data::jagged_vector_view>&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&, detray::sycl::queue_wrapper); /// Explicit instantiation for an inhomogeneous magnetic field -/*template void propagator_test>( - detector_host_t::detector_view_type< - bfield::sycl::inhom_bknd_t>, +/*template void propagator_test( + detector_host_t::view_type, + covfie::field_view, vecmem::data::vector_view&, - vecmem::data::jagged_vector_view< - intersection_t>>&, + vecmem::data::jagged_vector_view>&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&, vecmem::data::jagged_vector_view&, diff --git a/tests/unit_tests/device/sycl/propagator_sycl_kernel.hpp b/tests/unit_tests/device/sycl/propagator_sycl_kernel.hpp index cedc4db9a..3fd35cd1a 100644 --- a/tests/unit_tests/device/sycl/propagator_sycl_kernel.hpp +++ b/tests/unit_tests/device/sycl/propagator_sycl_kernel.hpp @@ -19,7 +19,7 @@ namespace detray { /// Launch the propagation test kernel template void propagator_test( - typename detector_t::template detector_view_type, + typename detector_t::view_type, covfie::field_view, vecmem::data::vector_view &, vecmem::data::jagged_vector_view> &, vecmem::data::jagged_vector_view &, @@ -30,8 +30,9 @@ void propagator_test( template inline auto run_propagation_device( vecmem::memory_resource *mr, detector_t &det, - typename detector_t::template detector_view_type det_view, - sycl::queue_wrapper queue, dvector &tracks, + typename detector_t::view_type det_view, + covfie::field_view field_data, sycl::queue_wrapper queue, + dvector &tracks, const vecmem::jagged_vector &host_positions) -> std::tuple, vecmem::jagged_vector, @@ -68,8 +69,8 @@ inline auto run_propagation_device( // Run the propagator test for GPU device propagator_test( - det_view, tracks_data, candidates_buffer, path_lengths_buffer, - positions_buffer, jac_transports_buffer, queue); + det_view, field_data, tracks_data, candidates_buffer, + path_lengths_buffer, positions_buffer, jac_transports_buffer, queue); vecmem::jagged_vector device_path_lengths(mr); vecmem::jagged_vector device_positions(mr); @@ -85,10 +86,12 @@ inline auto run_propagation_device( } /// Test chain for the propagator -template -inline auto run_propagation_test( - vecmem::memory_resource *mr, ::sycl::queue *q, detector_t &det, - typename detector_t::template detector_view_type det_view) { +template +inline auto run_propagation_test(vecmem::memory_resource *mr, ::sycl::queue *q, + detector_t &det, + typename detector_t::view_type det_view, + covfie::field &field) { // Create the vector of initial track parameterizations auto tracks_host = generate_tracks(mr); @@ -96,14 +99,16 @@ inline auto run_propagation_test( // Host propagation auto &&[host_path_lengths, host_positions, host_jac_transports] = - run_propagation_host(mr, det, tracks_host); + run_propagation_host(mr, det, field, tracks_host); // Device propagation detray::sycl::queue_wrapper queue(q); + covfie::field device_field(field); auto &&[device_path_lengths, device_positions, device_jac_transports] = - run_propagation_device(mr, det, det_view, queue, - tracks_device, host_positions); + run_propagation_device( + mr, det, det_view, device_field, queue, tracks_device, + host_positions); // Check the results compare_propagation_results(host_positions, device_positions, diff --git a/tests/unit_tests/io/CMakeLists.txt b/tests/unit_tests/io/CMakeLists.txt index 60e0e1a6f..d12af50fb 100644 --- a/tests/unit_tests/io/CMakeLists.txt +++ b/tests/unit_tests/io/CMakeLists.txt @@ -15,6 +15,3 @@ detray_add_test( io_reader "io_json_detector_reader.cpp" LINK_LIBRARIES GTest::gtest_main vecmem::core detray::core_array detray::io_array detray::test detray_tests_common detray::utils_array) -detray_add_test( io_bfield_reader - "io_bfield_reader.cpp" - LINK_LIBRARIES GTest::gtest_main detray::core_array detray::io_array detray::utils_array covfie::core vecmem::core ) diff --git a/tests/unit_tests/io/io_bfield_reader.cpp b/tests/unit_tests/io/io_bfield_reader.cpp deleted file mode 100644 index d1a7b3c09..000000000 --- a/tests/unit_tests/io/io_bfield_reader.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2023 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -// Project include(s) -#include "detray/definitions/algebra.hpp" -#include "detray/definitions/bfield_backends.hpp" -#include "detray/detectors/create_toy_geometry.hpp" -#include "detray/io/common/bfield_reader.hpp" -#include "detray/io/common/detector_reader.hpp" - -// Vecmem include(s) -#include - -// GTest include(s) -#include - -#include - -using namespace detray; - -/// Test the reading of a magnetic field from file -TEST(io, bfield_reader) { - - // Magnetic field map using nearest neightbor interpolation - using bfield_t = covfie::field; - - // Toy detector - using detector_t = detector; - - // Empty volume name map - typename detector_t::name_map volume_name_map = {{0u, "toy_detector"}}; - - // Toy detector with inhomogeneous bfield - vecmem::host_memory_resource host_mr; - detector_builder toy_builder; - - // Read the bfield from file into the detector - covfie_reader bf_reader; - bf_reader.read(toy_builder, volume_name_map, - !std::getenv("DETRAY_BFIELD_FILE") - ? "" - : std::getenv("DETRAY_BFIELD_FILE")); - auto det = toy_builder.build(host_mr); - - // Test the field - const bfield_t& bf = det.get_bfield(); - bfield_t::view_t bv(bf); - - auto field_strength = [&bv](float x, float y, float z) { - return std::sqrt(std::pow(bv.at(x, y, z)[0], 2) + - std::pow(bv.at(x, y, z)[1], 2) + - std::pow(bv.at(x, y, z)[2], 2)); - }; - - // Sample some field strengths - constexpr scalar tol{1e-7f}; - float x = -5000.0f, y = 3200.0f, z = -7700.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.668426511f * unit::T, tol); - x = -2400.0f, y = 7500.0f, z = 6500.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.597449579f * unit::T, tol); - x = -1000.0f, y = -4300.0f, z = 2700.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.41904773f * unit::T, tol); - x = 6100.0f, y = 4800.0f, z = -4300.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.439638488f * unit::T, tol); - x = -7800.0f, y = -8400.0f, z = 9000.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.061408468f * unit::T, tol); - x = 6900.0f, y = -8800.0f, z = -4900.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.087212384f * unit::T, tol); - x = -9600.0f, y = 8600.0f, z = 3000.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.026944387f * unit::T, tol); - x = 6400.0f, y = -3200.0f, z = -6400.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.629775357f * unit::T, tol); - x = 200.0f, y = -4000.0f, z = 1700.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.004898979f * unit::T, tol); - x = 400.0f, y = -7100.0f, z = -11700.0f; - ASSERT_NEAR(field_strength(x, y, z), 0.293974489f * unit::T, tol); -} diff --git a/tests/unit_tests/io/io_json_detector_reader.cpp b/tests/unit_tests/io/io_json_detector_reader.cpp index c2f5b1ca9..eb953c717 100644 --- a/tests/unit_tests/io/io_json_detector_reader.cpp +++ b/tests/unit_tests/io/io_json_detector_reader.cpp @@ -185,8 +185,7 @@ TEST(io, json_toy_geometry) { /// Test the reading and writing of a toy detector geometry TEST(io, json_toy_detector_reader) { - using detector_t = - detector>; + using detector_t = detector; // Toy detector vecmem::host_memory_resource host_mr; @@ -203,8 +202,7 @@ TEST(io, json_toy_detector_reader) { reader_cfg.do_check(true) .add_file("toy_detector_geometry.json") .add_file("toy_detector_homogeneous_material.json") - .add_file("toy_detector_surface_grids.json") - .add_file(toy_cfg.bfield_file()); + .add_file("toy_detector_surface_grids.json"); const auto [det, names] = io::read_detector(host_mr, reader_cfg); diff --git a/tests/validation/include/detray/validation/detector_helix_scan.hpp b/tests/validation/include/detray/validation/detector_helix_scan.hpp index dab052a89..4988ae1d9 100644 --- a/tests/validation/include/detray/validation/detector_helix_scan.hpp +++ b/tests/validation/include/detray/validation/detector_helix_scan.hpp @@ -77,7 +77,6 @@ class helix_scan : public test::fixture_base<> { /// Run the helix scan void TestBody() override { - using b_field_t = typename detector_t::bfield_type; using scalar_t = typename detector_t::scalar_type; using nav_link_t = typename detector_t::surface_type::navigation_link; @@ -87,11 +86,9 @@ class helix_scan : public test::fixture_base<> { dindex start_index{0u}; // B-field vector for helix - const auto &origin = m_cfg.track_generator().origin(); - typename b_field_t::view_t bfield_view{m_det.get_bfield()}; - const typename b_field_t::output_t bvec = - bfield_view.at(origin[0], origin[1], origin[2]); - const typename fixture_type::point3 B{bvec[0], bvec[1], bvec[2]}; + const typename fixture_type::point3 B{0.f * unit::T, + 0.f * unit::T, + 2.f * unit::T}; // Iterate through uniformly distributed momentum directions std::size_t n_tracks{0u}; diff --git a/tests/validation/include/detray/validation/helix_navigation.hpp b/tests/validation/include/detray/validation/helix_navigation.hpp index c1503d5cc..a1c98d9c4 100644 --- a/tests/validation/include/detray/validation/helix_navigation.hpp +++ b/tests/validation/include/detray/validation/helix_navigation.hpp @@ -8,6 +8,7 @@ #pragma once // Project include(s) +#include "detray/detectors/bfield.hpp" #include "detray/intersection/detail/trajectories.hpp" #include "detray/propagator/actor_chain.hpp" #include "detray/propagator/actors/aborters.hpp" @@ -99,8 +100,8 @@ class helix_navigation : public test::fixture_base<> { // Navigation with inspection using navigator_t = navigator; // Runge-Kutta stepper - using b_field_t = typename detector_t::bfield_type; - using stepper_t = rk_stepper; + using bfield_t = bfield::const_field_t; + using stepper_t = rk_stepper; // Propagator with pathlimit aborter using actor_chain_t = actor_chain; using propagator_t = propagator; @@ -109,11 +110,10 @@ class helix_navigation : public test::fixture_base<> { propagator_t prop(stepper_t{}, navigator_t{}); // B-field vector for helix - const auto &origin = m_cfg.track_generator().origin(); - typename b_field_t::view_t bfield_view{m_det.get_bfield()}; - const typename b_field_t::output_t bvec = - bfield_view.at(origin[0], origin[1], origin[2]); - const typename fixture_type::point3 B{bvec[0], bvec[1], bvec[2]}; + const typename fixture_type::point3 B{0.f * unit::T, + 0.f * unit::T, + 2.f * unit::T}; + bfield_t hom_bfield = bfield::create_const_field(B); // Iterate through uniformly distributed momentum directions std::size_t n_tracks{0u}; @@ -144,8 +144,7 @@ class helix_navigation : public test::fixture_base<> { unit::m}; auto actor_states = std::tie(pathlimit_aborter_state); - typename propagator_t::state propagation(track, m_det.get_bfield(), - m_det); + typename propagator_t::state propagation(track, hom_bfield, m_det); // Access to navigation information auto &inspector = propagation._navigation.inspector(); diff --git a/tests/validation/src/detector_validation.cpp b/tests/validation/src/detector_validation.cpp index 17ac7442c..e1eff3caa 100644 --- a/tests/validation/src/detector_validation.cpp +++ b/tests/validation/src/detector_validation.cpp @@ -50,8 +50,6 @@ int main(int argc, char **argv) { "write_ray_scan", "writes the ray scan intersections to file")( "geometry_file", po::value(), "geometry input file")( "material_file", po::value(), "material input file")( - "bfield_file", po::value(), - "magnetic field map input file")( "phi_steps", po::value()->default_value(50u), "# phi steps for particle gun")( "theta_steps", po::value()->default_value(50u), @@ -102,12 +100,6 @@ int main(int argc, char **argv) { if (vm.count("material_file")) { reader_cfg.add_file(vm["material_file"].as()); } - if (vm.count("bfield_file")) { - // reader_cfg.add_file(vm["bfield_file"].as()); - throw std::invalid_argument("Reading of bfield file not implemented"); - } else { - reader_cfg.bfield_vec(0.f, 0.f, 2.f * unit::T); - } // Particle gun if (vm.count("phi_steps")) { diff --git a/tests/validation/src/material_validation.cpp b/tests/validation/src/material_validation.cpp index 7e45d3b7e..9606204e0 100644 --- a/tests/validation/src/material_validation.cpp +++ b/tests/validation/src/material_validation.cpp @@ -33,7 +33,6 @@ int main(int argc, char **argv) { // Use the most general type to be able to read in all detector files using detector_t = detray::detector<>; - using scalar_t = detector_t::scalar_type; // Filter out the google test flags ::testing::InitGoogleTest(&argc, argv); @@ -44,8 +43,6 @@ int main(int argc, char **argv) { desc.add_options()("help", "produce help message")( "geometry_file", po::value(), "geometry input file")( "material_file", po::value(), "material input file")( - "bfield_file", po::value(), - "magnetic field map input file")( "phi_steps", po::value()->default_value(50u), "# phi steps for particle gun")( "eta_steps", po::value()->default_value(50u), @@ -83,11 +80,6 @@ int main(int argc, char **argv) { throw std::invalid_argument(err_stream.str()); } - if (vm.count("bfield_file")) { - reader_cfg.add_file(vm["bfield_file"].as()); - } else { - reader_cfg.bfield_vec(0.f, 0.f, 2.f * unit::T); - } // Particle gun if (vm.count("phi_steps")) { diff --git a/tests/validation/src/telescope_detector_validation.cpp b/tests/validation/src/telescope_detector_validation.cpp index 8399c43d0..a260bc2fa 100644 --- a/tests/validation/src/telescope_detector_validation.cpp +++ b/tests/validation/src/telescope_detector_validation.cpp @@ -36,10 +36,7 @@ int main(int argc, char **argv) { tel_det_config> tel_cfg{20.f * unit::mm, 20.f * unit::mm}; - tel_cfg.n_surfaces(10u) - .length(500.f * unit::mm) - .bfield_vec(0.f * unit::T, 0.f * unit::T, - 2.f * unit::T); + tel_cfg.n_surfaces(10u).length(500.f * unit::mm); vecmem::host_memory_resource host_mr; diff --git a/tests/validation/src/toy_detector_validation.cpp b/tests/validation/src/toy_detector_validation.cpp index 31c81a822..6ddacddb5 100644 --- a/tests/validation/src/toy_detector_validation.cpp +++ b/tests/validation/src/toy_detector_validation.cpp @@ -33,8 +33,6 @@ int main(int argc, char **argv) { // toy_det_config toy_cfg{}; toy_cfg.n_brl_layers(4u).n_edc_layers(7u); - toy_cfg.bfield_vec( - {0.f * unit::T, 0.f * unit::T, 2.f * unit::T}); using toy_detector_t = detector; using scalar_t = typename toy_detector_t::scalar_type; diff --git a/tests/validation/src/wire_chamber_validation.cpp b/tests/validation/src/wire_chamber_validation.cpp index b7e8a20d6..b47e3b915 100644 --- a/tests/validation/src/wire_chamber_validation.cpp +++ b/tests/validation/src/wire_chamber_validation.cpp @@ -38,7 +38,6 @@ int main(int argc, char **argv) { wire_chamber_config wire_chamber_cfg{}; wire_chamber_cfg.half_z(500.f * unit::mm); - wire_chamber_cfg.bfield_vec(0.f, 0.f, 2.f * unit::T); auto [det, names] = create_wire_chamber(host_mr, wire_chamber_cfg); diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 9a7e2df0d..83731b4d4 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -11,12 +11,9 @@ include( detray-compiler-options-cpp ) file( GLOB _detray_tutorial_headers RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "include/detray/tutorials/*.hpp" ) -add_library( detray_tutorial INTERFACE "${_detray_tutorial_headers}" ) -add_library( detray::tutorial ALIAS detray_tutorial ) -target_include_directories( detray_tutorial - INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) -target_link_libraries( detray_tutorial INTERFACE - vecmem::core detray::core ) + +detray_add_library( detray_tutorial tutorial ${_detray_tutorial_headers}) +target_link_libraries( detray_tutorial INTERFACE vecmem::core detray::core ) unset( _detray_tutorial_headers ) # Include all of the code-holding sub-directories. diff --git a/tutorials/include/detray/tutorial/detector_metadata.hpp b/tutorials/include/detray/tutorial/detector_metadata.hpp index 13aee548c..17f928f83 100644 --- a/tutorials/include/detray/tutorial/detector_metadata.hpp +++ b/tutorials/include/detray/tutorial/detector_metadata.hpp @@ -32,8 +32,7 @@ /// navigation. /// In this example detector design, volumes do not contain other volumes, so /// the volume lookup is done using a uniform grid. -/// Furthermore, the detector will contain homogeneous material on its surfaces -/// and a constant B-field. +/// Furthermore, the detector will contain homogeneous material on its surfaces. namespace detray { namespace tutorial { diff --git a/tutorials/include/detray/tutorial/square_surface_generator.hpp b/tutorials/include/detray/tutorial/square_surface_generator.hpp index 3a391acae..8b8c5e4b6 100644 --- a/tutorials/include/detray/tutorial/square_surface_generator.hpp +++ b/tutorials/include/detray/tutorial/square_surface_generator.hpp @@ -25,12 +25,10 @@ namespace detray::tutorial { /// @brief Generates a sequence of square surfaces for the example detector class square_surface_generator final - : public surface_factory_interface>> { + : public surface_factory_interface> { public: - using detector_t = - detector>; + using detector_t = detector; using scalar_t = typename detector_t::scalar_type; /// Generate @param n square surfaces with half length @param hl . diff --git a/tutorials/src/cpu/detector/build_predefined_detectors.cpp b/tutorials/src/cpu/detector/build_predefined_detectors.cpp index 008e0366e..f0b909133 100644 --- a/tutorials/src/cpu/detector/build_predefined_detectors.cpp +++ b/tutorials/src/cpu/detector/build_predefined_detectors.cpp @@ -6,7 +6,6 @@ */ // Project include(s) -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" #include "detray/detectors/create_telescope_detector.hpp" #include "detray/detectors/create_toy_geometry.hpp" @@ -106,7 +105,7 @@ int main(int argc, char** argv) { // // Case 1: Defaults: Straight telescope in z-direction, // 10 rectangle surfaces, 500mm in length, modules evenly spaced, - // no B-field, silicon material (80mm) + // silicon material (80mm) const auto [tel_det1, tel_names1] = detray::create_telescope_detector>(host_mr); @@ -116,8 +115,7 @@ int main(int argc, char** argv) { // // Case 2: Straight telescope in z-direction, 15 trapezoid surfaces, 2000mm - // in length, modules evenly spaced, no B-field, - // silicon material (80mm) + // in length, modules evenly spaced, silicon material (80mm) detray::tel_det_config trp_cfg{trapezoid}; trp_cfg.n_surfaces(15).length(2000.f * detray::unit::mm); @@ -130,7 +128,7 @@ int main(int argc, char** argv) { // // Case 3: Straight telescope in x-direction, 11 rectangle surfaces, 2000mm - // in length, modules places according to 'positions', no B-field, + // in length, modules places according to 'positions', // silicon material (80mm) // Pilot trajectory in x-direction @@ -150,7 +148,7 @@ int main(int argc, char** argv) { // // Case 4: Bent telescope along helical track, 11 trapezoid surfaces, // modules spaced according to given positions, - // constant B-field, silicon material (80mm) + // silicon material (80mm) // Pilot track in x-direction detray::free_track_parameters y_track{ @@ -163,7 +161,7 @@ int main(int argc, char** argv) { helix_t helix(y_track, &B_z); detray::tel_det_config htrp_cfg{trapezoid, helix}; - htrp_cfg.positions(positions).bfield_vec(B_z); + htrp_cfg.positions(positions); const auto [tel_det4, tel_names4] = detray::create_telescope_detector(host_mr, htrp_cfg); diff --git a/tutorials/src/cpu/detector/detector_to_dot.cpp b/tutorials/src/cpu/detector/detector_to_dot.cpp index fecb0e68c..f9894c687 100644 --- a/tutorials/src/cpu/detector/detector_to_dot.cpp +++ b/tutorials/src/cpu/detector/detector_to_dot.cpp @@ -34,7 +34,7 @@ int main(int argc, char** argv) { throw std::runtime_error("Please specify an input file name!"); } - // Read a toy detector with constant bfield (default) + // Read a toy detector using detector_t = detray::detector; // Create an empty detector to be filled diff --git a/tutorials/src/cpu/detector/do_it_yourself_detector.cpp b/tutorials/src/cpu/detector/do_it_yourself_detector.cpp index d40502204..e41d1144d 100644 --- a/tutorials/src/cpu/detector/do_it_yourself_detector.cpp +++ b/tutorials/src/cpu/detector/do_it_yourself_detector.cpp @@ -7,7 +7,6 @@ // Project include(s) #include "detray/core/detector.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/geometry.hpp" #include "detray/definitions/units.hpp" #include "detray/detectors/create_toy_geometry.hpp" @@ -32,9 +31,7 @@ int main() { // The new detector type - using detector_t = - detray::detector>; + using detector_t = detray::detector; // First, create an empty detector in in host memory to be filled vecmem::host_memory_resource host_mr; diff --git a/tutorials/src/cpu/propagation/navigation_inspection.cpp b/tutorials/src/cpu/propagation/navigation_inspection.cpp index 344dfde38..741f4db33 100644 --- a/tutorials/src/cpu/propagation/navigation_inspection.cpp +++ b/tutorials/src/cpu/propagation/navigation_inspection.cpp @@ -6,7 +6,6 @@ */ // Project include(s) -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" #include "detray/detectors/create_toy_geometry.hpp" #include "detray/intersection/detail/trajectories.hpp" // ray @@ -32,9 +31,7 @@ /// of the encountered surfaces (using the navigation inspectors) int main() { // Toy detector - using toy_detector_t = - detray::detector>; + using toy_detector_t = detray::detector; /// Type that holds the intersection information using intersection_t = diff --git a/tutorials/src/device/cuda/CMakeLists.txt b/tutorials/src/device/cuda/CMakeLists.txt index 408c1b692..91849c0b1 100644 --- a/tutorials/src/device/cuda/CMakeLists.txt +++ b/tutorials/src/device/cuda/CMakeLists.txt @@ -14,18 +14,18 @@ enable_language(CUDA) include(detray-compiler-options-cuda) # Examples using the array algebra plugin. -detray_add_tutorial( detector_construction_cuda - "detector_construction.cpp" - "detector_construction.hpp" - "detector_construction.cu" - LINK_LIBRARIES vecmem::cuda detray::core_array covfie::core - detray::tutorial detray::utils) -target_compile_definitions(detray_tutorial_detector_construction_cuda PRIVATE array=array) +#detray_add_tutorial( detector_construction_cuda +# "detector_construction.cpp" +# "detector_construction.hpp" +# "detector_construction.cu" +# LINK_LIBRARIES vecmem::cuda detray::core_array +# detray::tutorial detray::utils) +#target_compile_definitions(detray_tutorial_detector_construction_cuda PRIVATE array=array) -detray_add_tutorial( propagation_cuda - "propagation.cpp" - "propagation.hpp" - "propagation_kernel.cu" - LINK_LIBRARIES vecmem::cuda detray::core_array covfie::core - detray::tutorial detray::utils) -target_compile_definitions(detray_tutorial_propagation_cuda PRIVATE array=array) +#detray_add_tutorial( propagation_cuda +# "propagation.cpp" +# "propagation.hpp" +# "propagation_kernel.cu" +# LINK_LIBRARIES vecmem::cuda detray::core_array covfie::core covfie::cuda +# detray::tutorial detray::utils) +#target_compile_definitions(detray_tutorial_propagation_cuda PRIVATE array=array) diff --git a/tutorials/src/device/cuda/detector_construction.cpp b/tutorials/src/device/cuda/detector_construction.cpp index 6bb1a9f26..23324e1bc 100644 --- a/tutorials/src/device/cuda/detector_construction.cpp +++ b/tutorials/src/device/cuda/detector_construction.cpp @@ -8,6 +8,9 @@ // Project include(s) #include "detector_construction.hpp" +#include "detray/detectors/bfield.hpp" +#include "detray/detectors/create_toy_geometry.hpp" + // Vecmem include(s) #include #include @@ -36,7 +39,7 @@ int main() { auto [det_mng, names_mng] = detray::create_toy_geometry(mng_mr); // Get the view onto the detector data directly - auto det_mng_data = detray::get_data(det_mng); + auto det_mng_data = detray::get_data(det_mng); // Pass the view and call the kernel std::cout << "Using CUDA unified memory:" << std::endl; @@ -50,17 +53,16 @@ int main() { auto [det_host, names_host] = detray::create_toy_geometry(host_mr); // Copy the detector data to device (synchronous copy, fixed size buffers) - auto det_fixed_buff = detray::get_buffer( - det_host, dev_mr, cuda_cpy); + auto det_fixed_buff = detray::get_buffer(det_host, dev_mr, cuda_cpy); // Get the detector view from the buffer and call the kernel std::cout << "\nSynchronous copy, fixed size buffers:" << std::endl; detray::tutorial::print(detray::get_data(det_fixed_buff)); // Copy the data to device in resizable buffers (synchronous copy) - auto det_resz_buff = detray::get_buffer( - det_host, dev_mr, cuda_cpy, detray::copy::sync, - vecmem::data::buffer_type::resizable); + auto det_resz_buff = + detray::get_buffer(det_host, dev_mr, cuda_cpy, detray::copy::sync, + vecmem::data::buffer_type::resizable); std::cout << "\nSynchronous copy, resizable buffers:" << std::endl; detray::tutorial::print(detray::get_data(det_resz_buff)); @@ -94,13 +96,10 @@ int main() { vecmem::data::buffer_type::fixed_size); // Assemble the detector buffer - auto det_custom_buff = - detray::detector_buffer>( - det_host, std::move(vol_buff), std::move(trf_buff), - std::move(msk_buff), std::move(mat_buff), std::move(sf_buff), - std::move(sf_lkp_buff), std::move(vgrid_buff)); + auto det_custom_buff = typename decltype(det_host)::buffer_type( + std::move(vol_buff), std::move(trf_buff), std::move(msk_buff), + std::move(mat_buff), std::move(sf_buff), std::move(sf_lkp_buff), + std::move(vgrid_buff)); std::cout << "\nCustom buffer setup:" << std::endl; detray::tutorial::print(detray::get_data(det_custom_buff)); diff --git a/tutorials/src/device/cuda/detector_construction.cu b/tutorials/src/device/cuda/detector_construction.cu index 9fc07fe03..c9b52d09f 100644 --- a/tutorials/src/device/cuda/detector_construction.cu +++ b/tutorials/src/device/cuda/detector_construction.cu @@ -12,9 +12,7 @@ namespace detray::tutorial { /// Kernel that runs the entire propagation loop __global__ void print_kernel( - typename detray::tutorial::detector_host_t::detector_view_type< - bfield::const_bknd_t> - det_data) { + typename detray::tutorial::detector_host_t::view_type det_data) { int gid = threadIdx.x + blockIdx.x * blockDim.x; @@ -43,9 +41,7 @@ __global__ void print_kernel( det.surface_store().get().size()); } -void print(typename detray::tutorial::detector_host_t::detector_view_type< - bfield::const_bknd_t> - det_data) { +void print(typename detray::tutorial::detector_host_t::view_type det_data) { // run the tutorial kernel print_kernel<<<1, 1>>>(det_data); diff --git a/tutorials/src/device/cuda/detector_construction.hpp b/tutorials/src/device/cuda/detector_construction.hpp index f3c8147d4..23a199217 100644 --- a/tutorials/src/device/cuda/detector_construction.hpp +++ b/tutorials/src/device/cuda/detector_construction.hpp @@ -8,26 +8,22 @@ #pragma once // Project include(s). -#include "detray/definitions/bfield_backends.hpp" +#include "detray/core/detector.hpp" #include "detray/definitions/units.hpp" -#include "detray/detectors/create_toy_geometry.hpp" +#include "detray/detectors/toy_metadata.hpp" #include "detray/tutorial/types.hpp" namespace detray::tutorial { // Detector -using detector_host_t = - detector, - host_container_types>; +using detector_host_t = detector; using detector_device_t = - detector, - device_container_types>; + detector; using mask_id = typename detector_host_t::masks::id; using acc_id = typename detector_host_t::sf_finders::id; /// Detector construction tutorial function (prints some detector statistics) -void print(typename detector_host_t::detector_view_type - det_data); +void print(typename detector_host_t::view_type det_data); } // namespace detray::tutorial diff --git a/tutorials/src/device/cuda/propagation.cpp b/tutorials/src/device/cuda/propagation.cpp index 0135e21e3..5fa882c06 100644 --- a/tutorials/src/device/cuda/propagation.cpp +++ b/tutorials/src/device/cuda/propagation.cpp @@ -8,6 +8,7 @@ // Project include(s) #include "propagation.hpp" +#include "detray/detectors/create_toy_geometry.hpp" #include "detray/simulation/event_generator/track_generators.hpp" // Vecmem include(s) @@ -23,17 +24,16 @@ int main() { // VecMem memory resource(s) vecmem::cuda::managed_memory_resource mng_mr; - // Set the magnetic field vector + // Create the bfield const auto B = detray::tutorial::vector3{0. * detray::unit::T, 0. * detray::unit::T, 2. * detray::unit::T}; - // Create the toy geometry - detray::toy_det_config toy_cfg{}; - toy_cfg.bfield_vec(B); + detray::tutorial::field_t bfield = detray::bfield::create_const_field(B); - auto [det, names] = detray::create_toy_geometry(mng_mr, toy_cfg); + // Create the toy geometry + auto [det, names] = detray::create_toy_geometry(mng_mr); // Create the vector of initial track parameters vecmem::vector> @@ -59,7 +59,7 @@ int main() { } // Get data for device - auto det_data = detray::get_data(det); + auto det_data = detray::get_data(det); auto tracks_data = detray::get_data(tracks); // Create navigator candidates buffer @@ -69,5 +69,6 @@ int main() { copy.setup(candidates_buffer); // Run the propagator test for GPU device - detray::tutorial::propagation(det_data, tracks_data, candidates_buffer); + detray::tutorial::propagation(det_data, bfield, tracks_data, + candidates_buffer); } diff --git a/tutorials/src/device/cuda/propagation.hpp b/tutorials/src/device/cuda/propagation.hpp index 0ca1a07f3..6c8e1c07f 100644 --- a/tutorials/src/device/cuda/propagation.hpp +++ b/tutorials/src/device/cuda/propagation.hpp @@ -8,9 +8,10 @@ #pragma once // Project include(s). -#include "detray/definitions/bfield_backends.hpp" +#include "detray/core/detector.hpp" #include "detray/definitions/units.hpp" -#include "detray/detectors/create_toy_geometry.hpp" +#include "detray/detectors/bfield.hpp" +#include "detray/detectors/toy_metadata.hpp" #include "detray/propagator/actor_chain.hpp" #include "detray/propagator/actors/aborters.hpp" #include "detray/propagator/actors/parameter_resetter.hpp" @@ -25,19 +26,16 @@ namespace detray::tutorial { // Detector -using detector_host_t = - detector, - host_container_types>; +using detector_host_t = detector; using detector_device_t = - detector, - device_container_types>; + detector; // Navigator using navigator_t = navigator; using intersection_t = navigator_t::intersection_type; // Stepper -using field_t = detector_host_t::bfield_type; +using field_t = detray::bfield::const_field_t; using stepper_t = rk_stepper; // Actors @@ -52,7 +50,8 @@ using propagator_t = propagator; /// Propagation tutorial function void propagation( - typename detector_host_t::detector_view_type det_data, + typename detector_host_t::view_type det_data, + typename field_t::view_t field_data, const vecmem::data::vector_view< free_track_parameters> tracks_data, diff --git a/tutorials/src/device/cuda/propagation_kernel.cu b/tutorials/src/device/cuda/propagation_kernel.cu index 4f768a280..d832925c1 100644 --- a/tutorials/src/device/cuda/propagation_kernel.cu +++ b/tutorials/src/device/cuda/propagation_kernel.cu @@ -16,9 +16,8 @@ inline constexpr detray::scalar path_limit{2.f * /// Kernel that runs the entire propagation loop __global__ void propagation_kernel( - typename detray::tutorial::detector_host_t::detector_view_type< - bfield::const_bknd_t> - det_data, + typename detray::tutorial::detector_host_t::view_type det_data, + typename detray::tutorial::field_t::view_t field_data, const vecmem::data::vector_view< detray::free_track_parameters> tracks_data, @@ -41,8 +40,6 @@ __global__ void propagation_kernel( // Setup of the avigator cache vecmem::jagged_device_vector candidates( candidates_data); - // Setup of the device b-field - detray::tutorial::detector_device_t::bfield_type B_field = det.get_bfield(); // Create propagator from a stepper and a navigator detray::tutorial::propagator_t p(detray::tutorial::stepper_t{}, @@ -61,7 +58,7 @@ __global__ void propagation_kernel( interactor_state, resetter_state); // Create the propagator state for the track - detray::tutorial::propagator_t::state state(tracks[gid], B_field, det, + detray::tutorial::propagator_t::state state(tracks[gid], field_data, det, candidates.at(gid)); // Run propagation @@ -69,9 +66,8 @@ __global__ void propagation_kernel( } void propagation( - typename detray::tutorial::detector_host_t::detector_view_type< - bfield::const_bknd_t> - det_data, + typename detray::tutorial::detector_host_t::view_type det_data, + typename detray::tutorial::field_t::view_t field_data, const vecmem::data::vector_view< detray::free_track_parameters> tracks_data, @@ -82,8 +78,8 @@ void propagation( int block_dim = tracks_data.size() / thread_dim + 1; // run the tutorial kernel - propagation_kernel<<>>(det_data, tracks_data, - candidates_data); + propagation_kernel<<>>(det_data, field_data, + tracks_data, candidates_data); // cuda error check DETRAY_CUDA_ERROR_CHECK(cudaGetLastError()); diff --git a/core/include/detray/definitions/bfield_backends.hpp b/utils/include/detray/detectors/bfield.hpp similarity index 54% rename from core/include/detray/definitions/bfield_backends.hpp rename to utils/include/detray/detectors/bfield.hpp index 10abb8b16..0216913eb 100644 --- a/core/include/detray/definitions/bfield_backends.hpp +++ b/utils/include/detray/detectors/bfield.hpp @@ -9,6 +9,7 @@ // Project include(s) #include "detray/definitions/algebra.hpp" +#include "detray/io/common/read_bfield.hpp" // Covfie include(s) #include @@ -16,19 +17,36 @@ #include #include #include -#include namespace detray::bfield { -// Constant bfield (host and device) +/// Constant bfield (host and device) using const_bknd_t = covfie::backend::constant, covfie::vector::vector_d>; -// Inhomogeneous field (host) +using const_field_t = covfie::field; + +/// Inhomogeneous field (host) using inhom_bknd_t = covfie::backend::affine< covfie::backend::nearest_neighbour>>>>; +using inhom_field_t = covfie::field; + +/// @returns a constant covfie field constructed from the field vector @param B +inline const_field_t create_const_field( + const __plugin::vector3 &B) { + return const_field_t{covfie::make_parameter_pack( + const_bknd_t::configuration_t{B[0], B[1], B[2]})}; +} + +/// @returns a constant covfie field constructed from the field vector @param B +inline inhom_field_t create_inhom_field() { + return io::read_bfield( + !std::getenv("DETRAY_BFIELD_FILE") ? "" + : std::getenv("DETRAY_BFIELD_FILE")); +} + } // namespace detray::bfield diff --git a/utils/include/detray/detectors/create_telescope_detector.hpp b/utils/include/detray/detectors/create_telescope_detector.hpp index 439bcf77c..76f824011 100644 --- a/utils/include/detray/detectors/create_telescope_detector.hpp +++ b/utils/include/detray/detectors/create_telescope_detector.hpp @@ -9,7 +9,6 @@ // Project include(s) #include "detray/core/detector.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" #include "detray/detectors/telescope_metadata.hpp" #include "detray/masks/masks.hpp" @@ -64,8 +63,6 @@ struct tel_det_config { trajectory_t m_trajectory{}; /// Safety envelope between the test surfaces and the portals scalar m_envelope{0.1f * unit::mm}; - /// Field vector for an homogenoues b-field - vector3 m_bfield_vec{0.f, 0.f, 2.f * unit::T}; /// Setters /// @{ @@ -108,14 +105,6 @@ struct tel_det_config { m_envelope = e; return *this; } - tel_det_config &bfield_vec(const vector3 &field_vec) { - m_bfield_vec = field_vec; - return *this; - } - tel_det_config &bfield_vec(const scalar x, const scalar y, const scalar z) { - m_bfield_vec = {x, y, z}; - return *this; - } /// @} /// Getters @@ -130,7 +119,6 @@ struct tel_det_config { constexpr scalar mat_thickness() const { return m_thickness; } const trajectory_t &pilot_track() const { return m_trajectory; } constexpr scalar envelope() const { return m_envelope; } - constexpr const vector3 &bfield_vec() const { return m_bfield_vec; } /// @} }; @@ -426,7 +414,6 @@ inline void create_telescope(context_t &ctx, volume_t &volume, /// @tparam trajectory_t the type of the pilot trajectory /// /// @param resource the memory resource for the detector containers -/// @param bfield /// /// @returns a complete detector object template , @@ -438,8 +425,7 @@ inline auto create_telescope_detector( // detector type using detector_t = - detector, - covfie::field, host_container_types>; + detector, host_container_types>; // Detector and volume names typename detector_t::name_map name_map = {{0u, "telescope_detector"}, @@ -467,13 +453,8 @@ inline auto create_telescope_detector( assert((positions.size() < 20u) && "Due to WIP, please choose less than 20 surfaces for now"); - const auto &B = cfg.bfield_vec(); - auto bfield = - covfie::field{covfie::make_parameter_pack( - bfield::const_bknd_t::configuration_t{B[0], B[1], B[2]})}; - // create empty detector - detector_t det(resource, std::move(bfield)); + detector_t det(resource); typename detector_t::geometry_context ctx{}; diff --git a/utils/include/detray/detectors/create_toy_geometry.hpp b/utils/include/detray/detectors/create_toy_geometry.hpp index e60887adc..70334397b 100644 --- a/utils/include/detray/detectors/create_toy_geometry.hpp +++ b/utils/include/detray/detectors/create_toy_geometry.hpp @@ -9,7 +9,6 @@ // Project include(s) #include "detray/core/detector.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/math.hpp" #include "detray/definitions/units.hpp" #include "detray/detectors/detector_helper.hpp" @@ -47,12 +46,6 @@ struct toy_det_config { unsigned int m_n_brl_layers{4u}; /// No. of endcap layers (on either side) the detector should be built with unsigned int m_n_edc_layers{3u}; - /// Field vector for an homogenoues b-field - vector3 m_bfield_vec{0.f, 0.f, 2.f * unit::T}; - /// Input file name for the covfie b-field - std::string m_bfield_file{!std::getenv("DETRAY_BFIELD_FILE") - ? "" - : std::getenv("DETRAY_BFIELD_FILE")}; /// Setters /// @{ @@ -64,26 +57,12 @@ struct toy_det_config { m_n_edc_layers = n; return *this; } - toy_det_config &bfield_vec(const vector3 &field_vec) { - m_bfield_vec = field_vec; - return *this; - } - toy_det_config &bfield_vec(const scalar x, const scalar y, const scalar z) { - m_bfield_vec = {x, y, z}; - return *this; - } - toy_det_config &bfield_file(const std::string &file_name) { - m_bfield_file = file_name; - return *this; - } /// @} /// Getters /// @{ constexpr unsigned int n_brl_layers() const { return m_n_brl_layers; } constexpr unsigned int n_edc_layers() const { return m_n_edc_layers; } - constexpr const vector3 &bfield_vec() const { return m_bfield_vec; } - const std::string &bfield_file() const { return m_bfield_file; } /// @} }; @@ -925,19 +904,15 @@ inline void add_barrel_detector( /// present when an endcap detector is built to have the barrel region radius /// match the endcap diameter. /// -/// @tparam bfield_bknd_t the type of magnetic field to construct -/// /// @param resource vecmem memory resource to use for container allocations /// @param cfg toy detector configuration /// /// @returns a complete detector object -template inline auto create_toy_geometry(vecmem::memory_resource &resource, const toy_det_config &cfg = {}) { // detector type - using detector_t = detector, - host_container_types>; + using detector_t = detector; // Detector and volume names typename detector_t::name_map name_map = {{0u, "toy_detector"}}; @@ -1034,21 +1009,6 @@ inline auto create_toy_geometry(vecmem::memory_resource &resource, // create empty detector detector_t det(resource); - // Constant b-field: 2T in z-direction as default - if constexpr (std::is_same_v) { - const vector3 &B = cfg.bfield_vec(); - auto bfield = covfie::field(covfie::make_parameter_pack( - bfield::const_bknd_t::configuration_t{B[0], B[1], B[2]})); - det.set_bfield(std::move(bfield)); - } - // Read b-field map from file - else { - detray::io::detail::file_handle file(cfg.bfield_file(), - std::ios::binary | std::ios::in); - - det.set_bfield(covfie::field(*file)); - } - // geometry context object typename detector_t::geometry_context ctx0{}; diff --git a/utils/include/detray/detectors/create_wire_chamber.hpp b/utils/include/detray/detectors/create_wire_chamber.hpp index 4be903867..bb05f17bc 100644 --- a/utils/include/detray/detectors/create_wire_chamber.hpp +++ b/utils/include/detray/detectors/create_wire_chamber.hpp @@ -10,13 +10,10 @@ // Project include(s) #include "detray/core/detector.hpp" #include "detray/core/detector_metadata.hpp" -#include "detray/definitions/bfield_backends.hpp" #include "detray/definitions/units.hpp" #include "detray/detectors/detector_helper.hpp" -#include "detray/io/common/detail/file_handle.hpp" #include "detray/masks/masks.hpp" #include "detray/materials/predefined_materials.hpp" -#include "detray/tools/bounding_volume.hpp" #include "detray/tools/grid_builder.hpp" #include "detray/utils/axis_rotation.hpp" #include "detray/utils/unit_vectors.hpp" @@ -43,14 +40,6 @@ struct wire_chamber_config { /// Half z of cylinder chamber scalar m_half_z{1000.f * unit::mm}; - /// Field vector for an homogenoues b-field - vector3 m_bfield_vec{0.f, 0.f, 2.f * unit::T}; - - /// Input file name for the covfie b-field - std::string m_bfield_file{!std::getenv("DETRAY_BFIELD_FILE") - ? "" - : std::getenv("DETRAY_BFIELD_FILE")}; - constexpr wire_chamber_config &n_layers(const unsigned int n) { m_n_layers = n; return *this; @@ -61,36 +50,16 @@ struct wire_chamber_config { return *this; } - wire_chamber_config &bfield_vec(const vector3 &field_vec) { - m_bfield_vec = field_vec; - return *this; - } - - wire_chamber_config &bfield_vec(const scalar x, const scalar y, - const scalar z) { - m_bfield_vec = {x, y, z}; - return *this; - } - - wire_chamber_config &bfield_file(const std::string &file_name) { - m_bfield_file = file_name; - return *this; - } - constexpr unsigned int n_layers() const { return m_n_layers; } constexpr scalar half_z() const { return m_half_z; } - constexpr const vector3 &bfield_vec() const { return m_bfield_vec; } - const std::string &bfield_file() const { return m_bfield_file; } }; // wire chamber config -template -auto create_wire_chamber(vecmem::memory_resource &resource, - const wire_chamber_config &cfg) { +inline auto create_wire_chamber(vecmem::memory_resource &resource, + const wire_chamber_config &cfg) { // Detector type - using detector_t = detector, - host_container_types>; + using detector_t = detector; using nav_link_t = typename detector_t::surface_type::navigation_link; using mask_id = typename detector_t::surface_type::mask_id; @@ -112,22 +81,6 @@ auto create_wire_chamber(vecmem::memory_resource &resource, // Create detector detector_t det(resource); - // B field - // Constant b-field: 2T in z-direction as default - if constexpr (std::is_same_v) { - const vector3 &B = cfg.bfield_vec(); - auto bfield = covfie::field(covfie::make_parameter_pack( - bfield::const_bknd_t::configuration_t{B[0], B[1], B[2]})); - det.set_bfield(std::move(bfield)); - } - // Read b-field map from file - else { - detray::io::detail::file_handle file(cfg.bfield_file(), - std::ios::binary | std::ios::in); - - det.set_bfield(covfie::field(*file)); - } - // Detector and volume names typename detector_t::name_map name_map = {{0u, "wire_chamber"}};