Skip to content

Commit

Permalink
Split the surface implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Oct 16, 2024
1 parent e3724d6 commit 4b59995
Show file tree
Hide file tree
Showing 46 changed files with 506 additions and 407 deletions.
2 changes: 1 addition & 1 deletion core/include/detray/builders/detail/bin_association.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "detray/geometry/coordinates/concentric_cylindrical2D.hpp"
#include "detray/geometry/coordinates/cylindrical2D.hpp"
#include "detray/geometry/coordinates/polar2D.hpp"
#include "detray/geometry/detail/vertexing.hpp"
#include "detray/geometry/detail/vertexer.hpp"
#include "detray/navigation/accelerators/concepts.hpp"
#include "detray/utils/grid/populators.hpp"
#include "detray/utils/ranges.hpp"
Expand Down
4 changes: 2 additions & 2 deletions core/include/detray/builders/detail/portal_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "detray/definitions/detail/qualifiers.hpp"
#include "detray/geometry/shapes/cylinder2D.hpp"
#include "detray/geometry/shapes/ring2D.hpp"
#include "detray/geometry/tracking_surface.hpp"
#include "detray/geometry/surface.hpp"
#include "detray/geometry/tracking_volume.hpp"

// System include(s).
Expand All @@ -37,7 +37,7 @@ auto get_cylinder_portals(const tracking_volume<detector_t> &vol) {

// Loop over all portals
for (const auto &pt_desc : vol.portals()) {
auto pt = tracking_surface{vol.detector(), pt_desc};
auto pt = geometry::surface{vol.detector(), pt_desc};
const std::string name = pt.shape_name();

if (name == "cylinder2D" || name == "concentric_cylinder2D") {
Expand Down
1 change: 0 additions & 1 deletion core/include/detray/builders/grid_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "detray/builders/surface_factory_interface.hpp"
#include "detray/builders/volume_builder.hpp"
#include "detray/builders/volume_builder_interface.hpp"
#include "detray/geometry/tracking_surface.hpp"
#include "detray/geometry/tracking_volume.hpp"
#include "detray/utils/grid/detail/concepts.hpp"

Expand Down
4 changes: 2 additions & 2 deletions core/include/detray/builders/material_map_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "detray/builders/material_map_generator.hpp"
#include "detray/builders/surface_factory_interface.hpp"
#include "detray/builders/volume_builder_interface.hpp"
#include "detray/geometry/tracking_surface.hpp"
#include "detray/geometry/surface.hpp"
#include "detray/materials/material_map.hpp"

// System include(s)
Expand Down Expand Up @@ -125,7 +125,7 @@ class material_map_builder final : public volume_decorator<detector_t> {
}

// Construct and append the material map for a given surface shape
auto sf = tracking_surface{det, sf_desc};
auto sf = geometry::surface{det, sf_desc};
[[maybe_unused]] auto [mat_id, mat_idx] = sf.template visit_mask<
detail::add_sf_material_map<materials_t>>(
m_factory, m_bin_data.at(sf_idx), m_n_bins.at(sf_idx),
Expand Down
4 changes: 2 additions & 2 deletions core/include/detray/builders/volume_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "detray/builders/surface_factory_interface.hpp"
#include "detray/builders/volume_builder_interface.hpp"
#include "detray/definitions/geometry.hpp"
#include "detray/geometry/tracking_surface.hpp"
#include "detray/geometry/surface.hpp"
#include "detray/utils/grid/detail/concepts.hpp"

// System include(s)
Expand Down Expand Up @@ -210,7 +210,7 @@ class volume_builder : public volume_builder_interface<detector_t> {
std::size_t n_portals{0u};
for (auto& sf_desc : m_surfaces) {

const auto sf = tracking_surface{det, sf_desc};
const auto sf = geometry::surface{det, sf_desc};

sf.template visit_mask<detail::mask_index_update>(sf_desc);
sf_desc.set_volume(m_volume.index());
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/geometry/detail/shape_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace detray::detail {
/// @return the opening angle of a chord the size of tol (= 2*arcsin(c/(2r)))
/// using a small angle approximation
template <typename scalar_t>
inline constexpr scalar_t phi_tolerance(scalar_t tol, scalar_t radius) {
constexpr scalar_t phi_tolerance(scalar_t tol, scalar_t radius) {
return tol / radius;
}

Expand Down
139 changes: 1 addition & 138 deletions core/include/detray/geometry/detail/surface_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
#pragma once

// Project include(s)
#include "detray/definitions/detail/algebra.hpp"
#include "detray/definitions/detail/indexing.hpp"
#include "detray/definitions/detail/qualifiers.hpp"
#include "detray/materials/detail/concepts.hpp"
#include "detray/materials/detail/material_accessor.hpp"
#include "detray/materials/material.hpp"
#include "detray/propagator/detail/jacobian_engine.hpp"
#include "detray/tracks/detail/transform_track_parameters.hpp"
#include "detray/tracks/tracks.hpp"

// System include(s)
#include <limits>
Expand All @@ -33,9 +31,6 @@ struct surface_kernels {
using point3_type = dpoint3D<algebra_t>;
using vector3_type = dvector3D<algebra_t>;
using transform3_type = dtransform3D<algebra_t>;
using bound_param_vector_type = bound_parameters_vector<algebra_t>;
using free_param_vector_type = free_parameters_vector<algebra_t>;
using free_matrix_type = free_matrix<algebra_t>;

/// A functor to retrieve the masks shape name
struct get_shape_name {
Expand Down Expand Up @@ -158,21 +153,6 @@ struct surface_kernels {
}
};

/// A functor to perform global to local bound transformation
struct global_to_bound {
template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline point2_type operator()(
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
const transform3_type& trf3, const point3_type& global,
const vector3_type& dir) const {
using mask_t = typename mask_group_t::value_type;

const point3_type local = mask_t::to_local_frame(trf3, global, dir);

return {local[0], local[1]};
}
};

/// A functor to perform global to local transformation
struct global_to_local {
template <typename mask_group_t, typename index_t>
Expand Down Expand Up @@ -210,123 +190,6 @@ struct surface_kernels {
return mask_t::to_global_frame(trf3, local);
}
};

/// A functor to get from a free to a bound vector
struct free_to_bound_vector {

// Visitor to the detector mask store that is called on the mask
// collection that contains the mask (shape) type of the surface
template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline bound_param_vector_type operator()(
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
const transform3_type& trf3,
const free_param_vector_type& free_vec) const {

using frame_t = typename mask_group_t::value_type::local_frame;

return detail::free_to_bound_vector<frame_t>(trf3, free_vec);
}
};

/// A functor to get from a bound to a free vector
struct bound_to_free_vector {

template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline free_param_vector_type operator()(
const mask_group_t& mask_group, const index_t& index,
const transform3_type& trf3,
const bound_param_vector_type& bound_vec) const {

return detail::bound_to_free_vector(trf3, mask_group[index],
bound_vec);
}
};

/// A functor to get the free-to-bound Jacobian
struct free_to_bound_jacobian {

template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline auto operator()(
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
const transform3_type& trf3,
const free_param_vector_type& free_vec) const {

using frame_t = typename mask_group_t::value_type::local_frame;

return detail::jacobian_engine<frame_t>::free_to_bound_jacobian(
trf3, free_vec);
}
};

/// A functor to get the bound-to-free Jacobian
struct bound_to_free_jacobian {

template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline auto operator()(
const mask_group_t& mask_group, const index_t& index,
const transform3_type& trf3,
const bound_param_vector_type& bound_vec) const {

using frame_t = typename mask_group_t::value_type::local_frame;

return detail::jacobian_engine<frame_t>::bound_to_free_jacobian(
trf3, mask_group[index], bound_vec);
}
};

/// A functor to get the path correction
struct path_correction {

template <typename mask_group_t, typename index_t, typename scalar_t>
DETRAY_HOST_DEVICE inline free_matrix_type operator()(
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
const transform3_type& trf3, const vector3_type& pos,
const vector3_type& dir, const vector3_type& dtds,
const scalar_t dqopds) const {

using frame_t = typename mask_group_t::value_type::local_frame;

return detail::jacobian_engine<frame_t>::path_correction(
pos, dir, dtds, dqopds, trf3);
}
};

/// A functor to get the local min bounds.
struct local_min_bounds {

template <typename mask_group_t, typename index_t, typename scalar_t>
DETRAY_HOST_DEVICE inline auto operator()(
const mask_group_t& mask_group, const index_t& index,
const scalar_t env =
std::numeric_limits<scalar_t>::epsilon()) const {

return mask_group[index].local_min_bounds(env);
}
};

/// A functor to get the minimum distance to any surface boundary.
struct min_dist_to_boundary {

template <typename mask_group_t, typename index_t, typename point_t>
DETRAY_HOST_DEVICE inline auto operator()(
const mask_group_t& mask_group, const index_t& index,
const point_t& loc_p) const {

return mask_group[index].min_dist_to_boundary(loc_p);
}
};

/// A functor to get the vertices in local coordinates.
struct local_vertices {

template <typename mask_group_t, typename index_t, typename scalar_t>
DETRAY_HOST_DEVICE inline auto operator()(
const mask_group_t& mask_group, const index_t& index,
const dindex n_seg) const {

return mask_group[index].vertices(n_seg);
}
};
};

} // namespace detray::detail
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2021-2023 CERN for the benefit of the ACTS project
* (c) 2021-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand All @@ -10,10 +10,40 @@
// Project include(s)
#include "detray/definitions/detail/containers.hpp"
#include "detray/definitions/detail/math.hpp"
#include "detray/geometry/surface.hpp"
#include "detray/utils/ranges.hpp"

namespace detray::detail {

template <typename point2_t, typename point3_t>
struct vertexer;

/// Compute vertices in global frame along the boundary of a surface
///
/// @param ctx geometry context
/// @param sf the surface
/// @param n_seg the number of segments used along arcs
///
/// @returns a vector of vetices (3D points)
template <typename detector_t>
DETRAY_HOST constexpr auto get_global_vertices(
const typename detector_t::geometry_context &ctx,
geometry::surface<detector_t> sf, const dindex n_seg) {
using algebra_t = typename detector_t::algebra_type;
using point2_t = dpoint2D<algebra_t>;
using point3_t = dpoint3D<algebra_t>;

auto vertices = sf.template visit_mask<vertexer<point2_t, point3_t>>(n_seg);
const auto &trf = sf.transform(ctx);

const std::size_t n_vertices{vertices.size()};
for (std::size_t i = 0u; i < n_vertices; ++i) {
vertices[i] = trf.point_to_global(vertices[i]);
}

return vertices;
}

/// Generate phi values along an arc
///
/// @param start_phi is the start for the arc generation
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/geometry/shapes/annulus2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "detray/definitions/units.hpp"
#include "detray/geometry/coordinates/polar2D.hpp"
#include "detray/geometry/detail/shape_utils.hpp"
#include "detray/geometry/detail/vertexing.hpp"
#include "detray/geometry/detail/vertexer.hpp"

// System include(s)
#include <limits>
Expand Down
Loading

0 comments on commit 4b59995

Please sign in to comment.