Skip to content

Commit

Permalink
Move the calculation of the surface center position into the shapes a…
Browse files Browse the repository at this point in the history
…nd add an approximation for the annulus shape
  • Loading branch information
niermann999 committed Nov 14, 2023
1 parent 9650590 commit 9c1051c
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 75 deletions.
11 changes: 11 additions & 0 deletions core/include/detray/geometry/detail/surface_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ struct surface_kernels {
}
};

/// A functor get the surface center in global cartesian coordinates
struct center {
template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline point3 operator()(
const mask_group_t& mask_group, const index_t& index,
const transform3& trf3) const {

return mask_group[index].center(trf3);
}
};

/// A functor to perform global to local bound transformation
struct global_to_bound {
template <typename mask_group_t, typename index_t>
Expand Down
10 changes: 5 additions & 5 deletions core/include/detray/geometry/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class surface {
/// @returns the center position on the surface in global coordinates
DETRAY_HOST_DEVICE
constexpr auto center(const context &ctx) const -> const point3 {
return transform(ctx).translation();
return visit_mask<typename kernels::center>(transform(ctx));
}

/// @returns the surface normal in global coordinates at a given bound/local
Expand Down Expand Up @@ -277,7 +277,7 @@ class surface {
/// @tparam functor_t the prescription to be applied to the mask
/// @tparam Args types of additional arguments to the functor
template <typename functor_t, typename... Args>
DETRAY_HOST_DEVICE constexpr auto visit_mask(Args &&... args) const {
DETRAY_HOST_DEVICE constexpr auto visit_mask(Args &&...args) const {
const auto &masks = m_detector.mask_store();

return masks.template visit<functor_t>(m_desc.mask(),
Expand All @@ -289,7 +289,7 @@ class surface {
/// @tparam functor_t the prescription to be applied to the mask
/// @tparam Args types of additional arguments to the functor
template <typename functor_t, typename... Args>
DETRAY_HOST_DEVICE constexpr auto visit_material(Args &&... args) const {
DETRAY_HOST_DEVICE constexpr auto visit_material(Args &&...args) const {
const auto &materials = m_detector.material_store();

return materials.template visit<functor_t>(m_desc.material(),
Expand Down Expand Up @@ -378,10 +378,10 @@ class surface {

template <typename detector_t, typename descr_t>
DETRAY_HOST_DEVICE surface(const detector_t &, const descr_t &)
->surface<detector_t>;
-> surface<detector_t>;

template <typename detector_t>
DETRAY_HOST_DEVICE surface(const detector_t &, const geometry::barcode)
->surface<detector_t>;
-> surface<detector_t>;

} // namespace detray
19 changes: 19 additions & 0 deletions core/include/detray/masks/annulus2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,25 @@ class annulus2D {
return corner_pos;
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(
const transform3_t &trf, const bounds_t<scalar_t, kDIM> &bounds) const {
using local_frame_t = local_frame_type<transform3_t>;
using point3_t = typename local_frame_t::point3;

// Strip polar system
const auto crns = corners(bounds);
auto centroid =
0.25f * point3_t{crns[0] + crns[2] + crns[4] + crns[6],
crns[1] + crns[3] + crns[5] + crns[7], 0.f};

return local_frame_t{}.local_to_global(trf, centroid);
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the stereo annulus
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/cuboid3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ class cuboid3D {
return o_bounds;
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the cuboid
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/cylinder2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ class cylinder2D {
xy_bound, xy_bound, bounds[e_p_half_z] + env};
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the cylinder
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/cylinder3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ class cylinder3D {
r_bound, r_bound, bounds[e_max_z] + env};
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the cylinder
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ class line {
return {-xy_bound, -xy_bound, -z_bound, xy_bound, xy_bound, z_bound};
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the line
Expand Down
6 changes: 6 additions & 0 deletions core/include/detray/masks/masks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ class mask {
DETRAY_HOST_DEVICE
auto volume_link() -> links_type& { return _volume_link; }

/// @returns the masks center in global cartesian coordinates
template <typename transform3_t>
DETRAY_HOST_DEVICE auto center(const transform3_t& trf) const {
return _shape.center(trf, _values);
}

/// @brief Lower and upper point for minimum axis aligned bounding box.
///
/// Computes the min and max vertices in a local 3 dim cartesian frame.
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/rectangle2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ class rectangle2D {
return {-x_bound, -y_bound, -env, x_bound, y_bound, env};
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the stereo annulus
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/ring2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ class ring2D {
return {-r_bound, -r_bound, -env, r_bound, r_bound, env};
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the stereo annulus
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/single3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ class single3D {
return o_bounds;
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the single value
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/trapezoid2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ class trapezoid2D {
return {-x_bound, -y_bound, -env, x_bound, y_bound, env};
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t &trf,
const bounds_t<scalar_t, kDIM> &) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the trapezoid
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/unbounded.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ class unbounded {
return shape{}.template local_min_bounds<algebra_t>(bounds, env);
}

/// @returns the shapes center in global cartesian coordinates
template <
typename transform3_t, template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == boundaries::e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(
const transform3_t& trf, const bounds_t<scalar_t, kDIM>& bounds) const {
return shape{}.center(trf, bounds);
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values for the underlying shape
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/masks/unmasked.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ class unmasked {
return {-inf, -inf, -inf, inf, inf, inf};
}

/// @returns the shapes center in global cartesian coordinates
template <typename transform3_t,
template <typename, std::size_t> class bounds_t,
typename scalar_t, std::size_t kDIM,
typename std::enable_if_t<kDIM == e_size, bool> = true>
DETRAY_HOST_DEVICE auto center(const transform3_t& trf,
const bounds_t<scalar_t, kDIM>&) const {
return trf.translation();
}

/// Generate vertices in local cartesian frame
///
/// @param bounds the boundary values
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/cpu/masks_annulus2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* Mozilla Public License Version 2.0
*/

#include <gtest/gtest.h>

// Project include(s)
#include "detray/definitions/units.hpp"
#include "detray/masks/masks.hpp"
#include "detray/test/types.hpp"
#include "detray/tracks/bound_track_parameters.hpp"

// GTest include
#include <gtest/gtest.h>

using namespace detray;
using point3_t = test::point3;
using transform3_t = test::transform3;

constexpr scalar tol{1e-5f};

Expand Down
13 changes: 5 additions & 8 deletions tests/unit_tests/cpu/masks_cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* Mozilla Public License Version 2.0
*/

#include <gtest/gtest.h>

// Project include(s)
#include "detray/definitions/units.hpp"
#include "detray/masks/masks.hpp"
#include "detray/test/types.hpp"
#include "detray/tracks/bound_track_parameters.hpp"

// GTest include
#include <gtest/gtest.h>

using namespace detray;
using point3_t = test::point3;
using transform3_t = test::transform3;

constexpr scalar tol{1e-7f};

Expand All @@ -41,9 +41,6 @@ GTEST_TEST(detray_masks, cylinder2D) {
// Move outside point inside using a tolerance
ASSERT_TRUE(c.is_inside(p2_out, 0.6f) == intersection::status::e_inside);

// Dummy bound track parameter
bound_track_parameters<transform3_t> bound_params;

// Check bounding box
constexpr scalar envelope{0.01f};
const auto loc_bounds = c.local_min_bounds(envelope);
Expand Down Expand Up @@ -91,4 +88,4 @@ GTEST_TEST(detray_masks, cylinder3D) {
ASSERT_NEAR(loc_bounds[cuboid3D<>::e_max_x], (r + envelope), tol);
ASSERT_NEAR(loc_bounds[cuboid3D<>::e_max_y], (r + envelope), tol);
ASSERT_NEAR(loc_bounds[cuboid3D<>::e_max_z], (hz + envelope), tol);
}
}
20 changes: 5 additions & 15 deletions tests/unit_tests/cpu/masks_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* Mozilla Public License Version 2.0
*/

#include <gtest/gtest.h>

// Project include(s)
#include "detray/definitions/units.hpp"
#include "detray/masks/masks.hpp"
#include "detray/test/types.hpp"
#include "detray/tracks/bound_track_parameters.hpp"

// GTest include
#include <gtest/gtest.h>

using namespace detray;
using point3_t = test::point3;
using transform3_t = test::transform3;

namespace {

Expand Down Expand Up @@ -45,11 +45,6 @@ GTEST_TEST(detray_masks, line_radial_cross_sect) {
ASSERT_TRUE(ln.is_inside(ln_out1) == intersection::status::e_outside);
ASSERT_TRUE(ln.is_inside(ln_out2) == intersection::status::e_outside);

// Dummy bound track parameter
bound_track_parameters<transform3_t> bound_params;
auto& bound_vec = bound_params.vector();
getter::element(bound_vec, e_bound_loc0, 0u) = 1.f;

// Check bounding box
constexpr scalar envelope{0.01f};
const auto loc_bounds = ln.local_min_bounds(envelope);
Expand Down Expand Up @@ -83,11 +78,6 @@ GTEST_TEST(detray_masks, line_square_cross_sect) {
ASSERT_TRUE(ln.is_inside(ln_out1) == intersection::status::e_outside);
ASSERT_TRUE(ln.is_inside(ln_out2) == intersection::status::e_outside);

// Dummy bound track parameter
bound_track_parameters<transform3_t> bound_params;
auto& bound_vec = bound_params.vector();
getter::element(bound_vec, e_bound_loc0, 0u) = -1.f;

// Check bounding box
constexpr scalar envelope{0.01f};
const auto loc_bounds = ln.local_min_bounds(envelope);
Expand All @@ -97,4 +87,4 @@ GTEST_TEST(detray_masks, line_square_cross_sect) {
ASSERT_NEAR(loc_bounds[cuboid3D<>::e_max_x], (cell_size + envelope), tol);
ASSERT_NEAR(loc_bounds[cuboid3D<>::e_max_y], (cell_size + envelope), tol);
ASSERT_NEAR(loc_bounds[cuboid3D<>::e_max_z], (hz + envelope), tol);
}
}
Loading

0 comments on commit 9c1051c

Please sign in to comment.