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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/include/detray/builders/bin_fillers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

// Project include(s).
#include "detray/builders/detail/bin_association.hpp"
#include "detray/navigation/accelerators/concepts.hpp"
#include "detray/utils/grid/detail/axis.hpp"
#include "detray/utils/grid/detail/concepts.hpp"
#include "detray/utils/grid/populators.hpp"
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/builders/detail/volume_connector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace detray {
template <typename detector_t,
template <typename...> class vector_type = dvector>
void connect_cylindrical_volumes(
detector_t &d, const typename detector_t::volume_finder &volume_grid) {
detector_t &d, const typename detector_t::volume_accelerator &volume_grid) {

using scalar_t = dscalar<typename detector_t::algebra_type>;
typename detector_t::context default_context = {};
Expand Down
52 changes: 2 additions & 50 deletions core/include/detray/builders/detector_builder.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
* (c) 2023-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s).
#include "detray/builders/grid_factory.hpp"
#include "detray/builders/volume_builder.hpp"
#include "detray/builders/volume_builder_interface.hpp"
#include "detray/core/concepts.hpp"
#include "detray/core/detector.hpp"
#include "detray/definitions/geometry.hpp"
#include "detray/utils/detector_statistics.hpp"
#include "detray/utils/grid/detail/concepts.hpp"
#include "detray/utils/log.hpp"
#include "detray/utils/type_traits.hpp"

// Vecmem include(s)
#include <vecmem/memory/memory_resource.hpp>
Expand All @@ -33,7 +29,6 @@ namespace detray {
/// @brief Provides functionality to build a detray detector volume by volume
///
/// @tparam metadata the type definitions for the detector
/// @tparam bfield_bknd_t the type of magnetic field to be used
/// @tparam volume_builder_t the basic volume builder to be used for the
/// geometry data
/// @tparam volume_data_t the data structure that holds the volume builders
Expand Down Expand Up @@ -133,7 +128,7 @@ class detector_builder {
vol_builder->build(det);
}

det.set_volume_finder(std::move(m_vol_finder));
// TODO: Make fully generic for more volume accelerator types

// TODO: Add sorting, data deduplication etc. here later...

Expand Down Expand Up @@ -185,55 +180,12 @@ class detector_builder {
return build(resource);
}

/// Put the volumes into a search data structure
template <typename... Args>
DETRAY_HOST void set_volume_finder([[maybe_unused]] Args&&... args) {
DETRAY_VERBOSE_HOST("Setting volume finder for detector: '" << name()
<< "'");

using vol_finder_t = typename detector_type::volume_finder;

// Add dummy volume grid for now
if constexpr (concepts::grid<vol_finder_t>) {

// TODO: Construct it correctly with the grid builder
mask<cylinder3D, algebra_type> vgrid_dims{
0u, 0.f, -constant<scalar_type>::pi,
-2000.f, 180.f, constant<scalar_type>::pi,
2000.f};
darray<std::size_t, 3> n_vgrid_bins{1u, 1u, 1u};

darray<std::vector<scalar_type>, 3UL> bin_edges{
std::vector<scalar_type>{0.f, 180.f},
std::vector<scalar_type>{-constant<scalar_type>::pi,
constant<scalar_type>::pi},
std::vector<scalar_type>{-2000.f, 2000.f}};

grid_factory_type<vol_finder_t> vgrid_factory{};
m_vol_finder = vgrid_factory.template new_grid<
axis::open<axis::label::e_r>,
axis::circular<axis::label::e_phi>,
axis::open<axis::label::e_z>, axis::irregular<scalar_type>,
axis::regular<scalar_type>, axis::irregular<scalar_type>>(
vgrid_dims, n_vgrid_bins, {}, bin_edges);
} else {
m_vol_finder = vol_finder_t{args...};
}
}

/// @returns access to the volume finder
DETRAY_HOST typename detector_type::volume_finder& volume_finder() {
return m_vol_finder;
}

private:
/// Name of the new detector
std::string m_detector_name{"detray_detector"};
/// Data structure that holds a volume builder for every detector volume
volume_data_t<std::unique_ptr<volume_builder_interface<detector_type>>>
m_volumes{};
/// Data structure to find volumes
typename detector_type::volume_finder m_vol_finder{};
};

} // namespace detray
37 changes: 29 additions & 8 deletions core/include/detray/builders/grid_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "detray/builders/volume_builder.hpp"
#include "detray/builders/volume_builder_interface.hpp"
#include "detray/geometry/tracking_volume.hpp"
#include "detray/navigation/accelerators/concepts.hpp"
#include "detray/navigation/accelerators/spatial_grid.hpp"
#include "detray/utils/grid/detail/concepts.hpp"
#include "detray/utils/log.hpp"

Expand Down Expand Up @@ -41,7 +43,7 @@ class grid_builder : public volume_decorator<detector_t> {
using value_type = typename detector_type::surface_type;
using scalar_type = dscalar<algebra_type>;

/// Decorate a volume with a grid
/// Decorate a volume with a surface accelerator grid
DETRAY_HOST
explicit grid_builder(
std::unique_ptr<volume_builder_interface<detector_t>> vol_builder)
Expand All @@ -66,13 +68,13 @@ class grid_builder : public volume_decorator<detector_t> {
}

/// Set the surface category this grid should contain (type id in the
/// accelrator link in the volume)
/// accelerator link in the volume descriptor)
void set_type(std::size_t sf_id) {
set_type(static_cast<link_id_t>(sf_id));
}

/// Set the surface category this grid should contain (type id in the
/// accelrator link in the volume)
/// accelerator link in the volume descriptor)
void set_type(link_id_t sf_id) {
// Exclude zero, it is reserved for the brute force method
assert(static_cast<int>(sf_id) > 0);
Expand Down Expand Up @@ -160,12 +162,18 @@ class grid_builder : public volume_decorator<detector_t> {

DETRAY_VERBOSE_HOST("Build surface grid...");

DETRAY_VERBOSE_HOST(
" -> Defer to other builders to get complete surface descriptors "
"first:");

using surface_desc_t = typename detector_t::surface_type;

// Add the surfaces (portals and/or passives) that are owned by the vol
typename detector_t::volume_type *vol_ptr =
volume_decorator<detector_t>::build(det, ctx);

DETRAY_VERBOSE_HOST("Resume building with updated surface descriptors");

// Find the surfaces that should be filled into the grid
const auto vol = tracking_volume{det, vol_ptr->index()};

Expand Down Expand Up @@ -207,18 +215,30 @@ class grid_builder : public volume_decorator<detector_t> {
}
}

// Add the grid to the detector and link it to its volume
constexpr auto gid{types::id<typename detector_t::accel, grid_t>};
DETRAY_DEBUG_HOST("Grid indices: m_id=" << m_id << ", gid=" << gid);
// Is the given grid type already an acceleration structure?
using spatial_grid_t =
std::conditional_t<concepts::surface_accelerator<grid_t>, grid_t,
spatial_grid_impl<grid_t>>;
constexpr auto gid{
types::id<typename detector_t::accel, spatial_grid_t>};
const dindex grid_idx{det.accelerator_store().template size<gid>()};

DETRAY_DEBUG_HOST("Adding grid to volume in detector. Surface type: "
<< m_id << ", grid: " << gid
<< ", grid idx: " << grid_idx);

// Set: contained surface type, grid type, grid instance index
vol_ptr->set_accel_link(m_id, gid, grid_idx);

// Add to detector
det._accelerators.template push_back<gid>(m_grid);
vol_ptr->set_link(m_id, gid,
det.accelerator_store().template size<gid>() - 1);

DETRAY_DEBUG_HOST("Accelerator link: " << vol_ptr->accel_link());
DETRAY_VERBOSE_HOST("Successfully built "
<< gid << " for volume: " << this->name());

DETRAY_DEBUG_HOST("Finished grid: " << m_grid);

return vol_ptr;
}

Expand All @@ -229,6 +249,7 @@ class grid_builder : public volume_decorator<detector_t> {
private:
link_id_t m_id{link_id_t::e_sensitive};
grid_factory_t m_factory{};
// Data owning grid type, so that surface data can be filled into memory
typename grid_t::template type<true> m_grid{};
bin_filler_t m_bin_filler{};
bool m_add_passives{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "detray/materials/predefined_materials.hpp"
#include "detray/utils/log.hpp"
#include "detray/utils/ranges.hpp"
#include "detray/utils/type_registry.hpp"

// System include(s)
#include <sstream>
Expand Down
4 changes: 1 addition & 3 deletions core/include/detray/core/detail/alignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ typename host_detector_type::view_type misaligned_detector_view(
detray::get_data(
detray::detail::get<4>(det_buffer.m_buffer)), // materials
detray::get_data(
detray::detail::get<5>(det_buffer.m_buffer)), // accelerators
detray::get_data(detray::detail::get<6>(
det_buffer.m_buffer))}; // volume search grid
detray::detail::get<5>(det_buffer.m_buffer))}; // accelerators
return detview;
}

Expand Down
9 changes: 1 addition & 8 deletions core/include/detray/core/detail/indexing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ template <typename I>
DETRAY_HOST inline std::ostream& operator<<(std::ostream& os,
const darray<I, 2>& r) {

bool writeSeparator = false;
for (auto i = 0u; i < r.size(); ++i) {
if (writeSeparator) {
os << ", ";
}
os << "[" << i << "]: " << r[i];
writeSeparator = true;
}
os << "[0: " << r[0] << ", 1: " << r[1] << "]";
return os;
}

Expand Down
17 changes: 6 additions & 11 deletions core/include/detray/core/detail/multi_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "detray/core/detail/tuple_container.hpp"
#include "detray/definitions/detail/qualifiers.hpp"
#include "detray/definitions/indexing.hpp"
#include "detray/utils/type_list.hpp"
#include "detray/utils/type_registry.hpp"
#include "detray/utils/type_traits.hpp"

Expand All @@ -29,13 +28,11 @@ namespace detray {
/// @brief Wraps a vecmem enabled tuple and adds functionality to handle data
/// collections @tparam Ts.
///
/// @tparam An enum of type IDs that needs to match the value types of the
/// @tparam Ts pack.
/// @tparam An enum of type IDs that needs to match the value types of the Ts
/// pack.
/// @tparam context_t How to retrieve data according to e.g. conditions data
/// @tparam tuple_t The type of the underlying tuple container.
/// @tparam container_t The type of container to use for the respective
/// data collections.
/// @tparam Ts the data types (value types of the collections)
/// @tparam Ts the data collection types
template <typename ID = std::size_t, typename context_t = empty_context,
template <typename...> class tuple_t = dtuple, typename... Ts>
class multi_store {
Expand All @@ -53,10 +50,8 @@ class multi_store {
/// How to find and index a data collection in the store
/// @{
using ids = ID;
template <typename index_t>
using link_type = dtyped_index<ID, index_t>;
using single_link = link_type<dindex>;
using range_link = link_type<index_range_t>;
using single_link = dtyped_index<ID, dindex>;
using range_link = dtyped_index<ID, index_range_t>;
/// @}

/// Allow matching between IDs and collection value types
Expand Down Expand Up @@ -397,7 +392,7 @@ class multi_store {
tuple_type m_tuple_container;
};

/// Helper type for a data store that uses a sinlge collection container
/// Helper type for a data store that uses a single collection container
template <typename ID, typename context_t, template <typename...> class tuple_t,
template <typename...> class container_t, typename... Ts>
using regular_multi_store =
Expand Down
1 change: 0 additions & 1 deletion core/include/detray/core/detail/single_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class single_store {

/// How to find data in the store
/// @{
using link_type = dindex;
using single_link = dindex;
using range_link = dindex_range;
/// @}
Expand Down
Loading
Loading