Skip to content

Commit

Permalink
Reduce size of navigation state
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Oct 29, 2024
1 parent d6bc161 commit 6cfd212
Show file tree
Hide file tree
Showing 47 changed files with 413 additions and 277 deletions.
8 changes: 4 additions & 4 deletions core/include/detray/core/detector_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ struct default_metadata {

/// Give your mask types a name (needs to be consecutive and has to match
/// the types position in the mask store!)
enum class mask_ids : std::uint8_t {
enum class mask_ids : std::uint_least8_t {
e_rectangle2 = 0,
e_portal_rectangle2 = 0,
e_trapezoid2 = 1,
Expand Down Expand Up @@ -188,7 +188,7 @@ unbounded_cell, unmasked_plane*/>;

/// Give your material types a name (needs to be consecutive and has to
/// match the types position in the mask store!)
enum class material_ids : std::uint8_t {
enum class material_ids : std::uint_least8_t {
// Material texture (grid) shapes
e_disc2_map = 0u,
e_concentric_cylinder2_map = 1u,
Expand Down Expand Up @@ -234,7 +234,7 @@ unbounded_cell, unmasked_plane*/>;
/// How to index the constituent objects (surfaces) in a volume
/// If they share the same index value here, they will be added into the
/// same acceleration data structure (brute force is always at 0)
enum geo_objects : std::uint8_t {
enum geo_objects : std::uint_least8_t {
e_portal = 0, // Brute force search
e_sensitive = 1, // Grid accelerated search (can be different types)
e_passive = 0, // Brute force search
Expand All @@ -243,7 +243,7 @@ unbounded_cell, unmasked_plane*/>;
};

/// Acceleration data structures
enum class accel_ids : std::uint8_t {
enum class accel_ids : std::uint_least8_t {
e_brute_force = 0, // test all surfaces in a volume (brute force)
e_disc_grid = 1, // e.g. endcap layers
e_cylinder2_grid = 2, // e.g. barrel layers
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/geometry/detail/surface_descriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace detray {
template <typename mask_link_t = dtyped_index<dindex, dindex>,
typename material_link_t = dtyped_index<dindex, dindex>,
typename transform_link_t = dindex,
typename navigation_link_t = dindex>
typename navigation_link_t = std::uint_least16_t>
class surface_descriptor {

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ struct helix_intersector_impl;
/// @note Don't use for low p_t tracks!
template <concepts::aos_algebra algebra_t>
struct helix_intersector_impl<cylindrical2D<algebra_t>, algebra_t>
: public ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t> {
: public ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, true> {

using scalar_type = dscalar<algebra_t>;
using point3_type = dpoint3D<algebra_t>;
using vector3_type = dvector3D<algebra_t>;
using transform3_type = dtransform3D<algebra_t>;

template <typename surface_descr_t>
using intersection_type = intersection2D<surface_descr_t, algebra_t>;
using intersection_type = intersection2D<surface_descr_t, algebra_t, true>;
using helix_type = detail::helix<algebra_t>;

/// Operator function to find intersections between helix and cylinder mask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace detray {
template <typename frame_t, typename algebra_t>
struct helix_intersector_impl {};

template <typename shape_t, typename algebra_t>
template <typename shape_t, typename algebra_t, bool = true>
using helix_intersector = helix_intersector_impl<
typename shape_t::template local_frame_type<algebra_t>, algebra_t>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct helix_intersector_impl<line2D<algebra_t>, algebra_t> {
using transform3_type = dtransform3D<algebra_t>;

template <typename surface_descr_t>
using intersection_type = intersection2D<surface_descr_t, algebra_t>;
using intersection_type = intersection2D<surface_descr_t, algebra_t, true>;
using helix_type = detail::helix<algebra_t>;

/// Operator function to find intersections between helix and line mask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct helix_intersector_impl<cartesian2D<algebra_t>, algebra_t> {
using transform3_type = dtransform3D<algebra_t>;

template <typename surface_descr_t>
using intersection_type = intersection2D<surface_descr_t, algebra_t>;
using intersection_type = intersection2D<surface_descr_t, algebra_t, true>;
using helix_type = detail::helix<algebra_t>;

/// Operator function to find intersections between helix and planar mask
Expand Down
49 changes: 41 additions & 8 deletions core/include/detray/navigation/intersection/intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@

namespace detray {

template <typename surface_descr_t, typename algebra_t, bool debug = false>
struct intersection2D {};

/// @brief This class holds the intersection information.
///
/// @tparam surface_descr_t is the type of surface descriptor
template <typename surface_descr_t, typename algebra_t>
struct intersection2D {
struct intersection2D<surface_descr_t, algebra_t, false> {

using T = typename algebra_t::value_type;
using algebra_type = algebra_t;
Expand All @@ -41,10 +44,6 @@ struct intersection2D {
/// Descriptor of the surface this intersection belongs to
surface_descr_t sf_desc{};

/// Local position of the intersection on the surface
point3_type local{detail::invalid_value<T>(), detail::invalid_value<T>(),
detail::invalid_value<T>()};

/// Distance between track and candidate
scalar_type path = detail::invalid_value<T>();

Expand All @@ -58,6 +57,9 @@ struct intersection2D {
/// false = opposite)
bool_t direction{true};

/// @returns true if debug information needs to be filled
static consteval bool is_debug() { return false; }

/// @note: Three way comparison cannot be used easily with SoA boolean masks
/// @{
/// @param rhs is the right hand side intersection for comparison
Expand Down Expand Up @@ -107,9 +109,7 @@ struct intersection2D {
out_stream << "dist:" << is.path
<< "\tsurface: " << is.sf_desc.barcode()
<< ", type: " << static_cast<int>(is.sf_desc.mask().id())
<< ", links to vol:" << is.volume_link << ")"
<< ", loc [" << is.local[0] << ", " << is.local[1] << ", "
<< is.local[2] << "], ";
<< ", links to vol:" << is.volume_link << ")";

if constexpr (std::is_scalar_v<bool_t>) {
out_stream << (is.status ? ", status: inside"
Expand All @@ -126,4 +126,37 @@ struct intersection2D {
}
};

/// @brief This class holds the intersection information with additional debug
/// information.
///
/// @tparam surface_descr_t is the type of surface descriptor
template <typename surface_descr_t, typename algebra_t>
struct intersection2D<surface_descr_t, algebra_t, true>
: public intersection2D<surface_descr_t, algebra_t, false> {

using T = typename algebra_t::value_type;
using algebra_type = algebra_t;
using point3_type = dpoint3D<algebra_t>;

/// @returns true if debug information needs to be filled
static consteval bool is_debug() { return true; }

/// Local position of the intersection on the surface
point3_type local{detail::invalid_value<T>(), detail::invalid_value<T>(),
detail::invalid_value<T>()};

/// Transform to a string for output debugging
DETRAY_HOST
friend std::ostream &operator<<(std::ostream &out_stream,
const intersection2D &is) {
using base_t = intersection2D<surface_descr_t, algebra_t, false>;

out_stream << static_cast<base_t>(is);
out_stream << ", loc [" << is.local[0] << ", " << is.local[1] << ", "
<< is.local[2] << "], ";

return out_stream;
}
};

} // namespace detray
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace detray {

/// A functor to find intersections between trajectory and concentric cylinder
/// mask
template <concepts::aos_algebra algebra_t>
template <concepts::aos_algebra algebra_t, bool do_debug = false>
struct ray_concentric_cylinder_intersector {

/// linear algebra types
Expand All @@ -36,7 +36,8 @@ struct ray_concentric_cylinder_intersector {
/// @}

template <typename surface_descr_t>
using intersection_type = intersection2D<surface_descr_t, algebra_t>;
using intersection_type =
intersection2D<surface_descr_t, algebra_t, do_debug>;
using ray_type = detail::ray<algebra_t>;

/// Operator function to find intersections between ray and concentric
Expand Down Expand Up @@ -109,17 +110,20 @@ struct ray_concentric_cylinder_intersector {

const point3_type p3 = candidates[cindex];
const scalar_type phi{getter::phi(p3)};
is.local = {r * phi, p3[2], r};
const point3_type loc{r * phi, p3[2], r};
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
is.local = loc;
}

is.path = t01[cindex];
// In this case, the point has to be in cylinder3 coordinates
// for the r-check
// Tolerance: per mille of the distance
is.status = mask.is_inside(
is.local, math::max(mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor *
math::fabs(is.path))));
loc, math::max(
mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor * math::fabs(is.path))));
is.sf_desc = sf;
is.direction = !detail::signbit(is.path);
is.volume_link = mask.volume_link();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

namespace detray {

template <typename frame_t, typename algebra_t>
template <typename frame_t, typename algebra_t, bool do_debug>
struct ray_intersector_impl;

/// A functor to find intersections between a ray and a 2D cylinder mask
template <concepts::aos_algebra algebra_t>
struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t> {
template <concepts::aos_algebra algebra_t, bool do_debug>
struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, do_debug> {

/// Linear algebra types
/// @{
Expand All @@ -38,7 +38,8 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t> {
/// @}

template <typename surface_descr_t>
using intersection_type = intersection2D<surface_descr_t, algebra_t>;
using intersection_type =
intersection2D<surface_descr_t, algebra_t, do_debug>;
using ray_type = detail::ray<algebra_t>;

/// Operator function to find intersections between a ray and a 2D cylinder
Expand Down Expand Up @@ -189,10 +190,13 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t> {
is.path = path;
const point3_type p3 = ro + is.path * rd;

is.local = mask_t::to_local_frame(trf, p3);
const auto loc{mask_t::to_local_frame(trf, p3)};
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
is.local = loc;
}
// Tolerance: per mille of the distance
is.status = mask.is_inside(
is.local,
loc,
math::max(mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor * math::fabs(is.path))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@

namespace detray {

template <typename frame_t, typename algebra_t>
template <typename frame_t, typename algebra_t, bool do_debug>
struct ray_intersector_impl;

/// @brief A functor to find intersections between a straight line and a
/// cylindrical portal surface.
///
/// With the way the navigation works, only the closest one of the two possible
/// intersection points is needed in the case of a cylinderical portal surface.
template <concepts::aos_algebra algebra_t>
struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t>
: public ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t> {
template <concepts::aos_algebra algebra_t, bool do_debug>
struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
do_debug>
: public ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t,
do_debug> {

/// linear algebra types
/// @{
Expand All @@ -44,7 +46,8 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t>
/// @}

template <typename surface_descr_t>
using intersection_type = intersection2D<surface_descr_t, algebra_t>;
using intersection_type =
intersection2D<surface_descr_t, algebra_t, do_debug>;
using ray_type = detail::ray<algebra_t>;

/// Operator function to find intersections between ray and cylinder mask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ namespace detray {
///
/// @note specialized into the concrete intersectors for the different local
/// geometries in the respective header files
template <typename frame_t, typename algebra_t>
template <typename frame_t, typename algebra_t, bool do_debug>
struct ray_intersector_impl {};

template <typename shape_t, typename algebra_t>
template <typename shape_t, typename algebra_t, bool do_debug = false>
using ray_intersector =
ray_intersector_impl<typename shape_t::template local_frame_type<algebra_t>,
algebra_t>;
algebra_t, do_debug>;

} // namespace detray
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@

namespace detray {

template <typename frame_t, typename algebra_t>
template <typename frame_t, typename algebra_t, bool do_debug>
struct ray_intersector_impl;

/// A functor to find intersections between trajectory and line mask
template <concepts::aos_algebra algebra_t>
struct ray_intersector_impl<line2D<algebra_t>, algebra_t> {
template <concepts::aos_algebra algebra_t, bool do_debug>
struct ray_intersector_impl<line2D<algebra_t>, algebra_t, do_debug> {

using scalar_type = dscalar<algebra_t>;
using point3_type = dpoint3D<algebra_t>;
using vector3_type = dvector3D<algebra_t>;
using transform3_type = dtransform3D<algebra_t>;

template <typename surface_descr_t>
using intersection_type = intersection2D<surface_descr_t, algebra_t>;
using intersection_type =
intersection2D<surface_descr_t, algebra_t, do_debug>;
using ray_type = detail::ray<algebra_t>;

/// Operator function to find intersections between ray and line mask
Expand Down Expand Up @@ -102,10 +103,13 @@ struct ray_intersector_impl<line2D<algebra_t>, algebra_t> {
// point of closest approach on the track
const point3_type m = _p + _d * A;

is.local = mask_t::to_local_frame(trf, m, _d);
const auto loc{mask_t::to_local_frame(trf, m, _d)};
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
is.local = loc;
}
// Tolerance: per mille of the distance
is.status = mask.is_inside(
is.local,
loc,
math::max(mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor * math::fabs(is.path))));
Expand Down
Loading

0 comments on commit 6cfd212

Please sign in to comment.