Skip to content

Commit

Permalink
Similar to the volumes, this PR adds an interface around the detector…
Browse files Browse the repository at this point in the history
… surfaces that allows us

to pool the functionality of a surface. This also provides a layer of abstraction around
the surfaces descriptors, so that users and downstream projects don't have to handle e.g. transform
or mask links directly.

The old surface class has been renamed to surface_descriptor and two new surface classes
are added that implement the interface. One only contains geometric functionality
(e.g. local-to-global transformation) and the other extends this by propagation functionality
(e.g. bound-to-free Jacobian). The reason they are split is, that this allows to compile detray
with only geometry and navigation functionality (which is desired for ray tracing/Celeritas).
The corresponding functions on the detector have been removed to keep responsibilities cleanly divided.
The rest of the changes are the adoption of the new interface.
  • Loading branch information
niermann999 committed Jun 28, 2023
1 parent 6d62da7 commit e9029f9
Show file tree
Hide file tree
Showing 43 changed files with 890 additions and 530 deletions.
92 changes: 0 additions & 92 deletions core/include/detray/core/detail/detector_kernel.hpp

This file was deleted.

44 changes: 2 additions & 42 deletions core/include/detray/core/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// Project include(s)
#include "detray/core/detail/container_buffers.hpp"
#include "detray/core/detail/container_views.hpp"
#include "detray/core/detail/detector_kernel.hpp"
#include "detray/core/detector_metadata.hpp"
#include "detray/definitions/containers.hpp"
#include "detray/definitions/qualifiers.hpp"
Expand Down Expand Up @@ -341,7 +340,8 @@ class detector {

/// @returns a surface using its barcode - const
DETRAY_HOST_DEVICE
constexpr auto surface(geometry::barcode bcd) const -> surface_type {
constexpr auto surface(geometry::barcode bcd) const
-> const surface_type & {
return _surface_lookup[bcd.index()];
}

Expand Down Expand Up @@ -536,46 +536,6 @@ class detector {
DETRAY_HOST_DEVICE
inline const bfield_type &get_bfield() const { return _bfield; }

DETRAY_HOST_DEVICE
inline point3 global_to_local(const geometry::barcode bc, const point3 &pos,
const vector3 &dir) const {
const surface_type &sf = surface(bc);
const auto ret =
_masks.template visit<detail::global_to_local<transform3>>(
sf.mask(), _transforms[sf.transform()], pos, dir);
return ret;
}

DETRAY_HOST_DEVICE
inline point3 local_to_global(const geometry::barcode bc,
const point3 &local) const {
const surface_type &sf = surface(bc);
const auto ret =
_masks.template visit<detail::local_to_global<transform3>>(
sf.mask(), _transforms[sf.transform()], local);
return ret;
}

DETRAY_HOST_DEVICE
inline bound_vector_type free_to_bound_vector(
const geometry::barcode bc, const free_vector_type &free_vec) const {
const surface_type &sf = surface(bc);
const auto ret =
_masks.template visit<detail::free_to_bound_vector<transform3>>(
sf.mask(), _transforms[sf.transform()], free_vec);
return ret;
}

DETRAY_HOST_DEVICE
inline free_vector_type bound_to_free_vector(
const geometry::barcode bc, const bound_vector_type &bound_vec) const {
const surface_type &sf = surface(bc);
const auto ret =
_masks.template visit<detail::bound_to_free_vector<transform3>>(
sf.mask(), _transforms[sf.transform()], bound_vec);
return ret;
}

/// @param names maps a volume to its string representation.
/// @returns a string representation of the detector.
DETRAY_HOST
Expand Down
7 changes: 4 additions & 3 deletions core/include/detray/core/detector_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "detray/core/detail/single_store.hpp"
#include "detray/definitions/containers.hpp"
#include "detray/definitions/indexing.hpp"
#include "detray/geometry/surface.hpp"
#include "detray/geometry/detail/surface_descriptor.hpp"
#include "detray/intersection/cylinder_intersector.hpp"
#include "detray/intersection/cylinder_portal_intersector.hpp"
#include "detray/intersection/plane_intersector.hpp"
Expand Down Expand Up @@ -191,8 +191,9 @@ unbounded_cell, unmasked_plane*/>;
using material_link = typename material_store<>::single_link;
using source_link = dindex;
/// Surface type used for sensitives, passives and portals
using surface_type = surface<mask_link, material_link, transform_link,
nav_link, source_link>;
using surface_type =
surface_descriptor<mask_link, material_link, transform_link, nav_link,
source_link>;

/// How to index the constituent objects (surfaces) in a volume
/// If they share the same index value here, they will be added into the
Expand Down
132 changes: 132 additions & 0 deletions core/include/detray/geometry/detail/propagation_kernels.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/** 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/definitions/indexing.hpp"
#include "detray/definitions/qualifiers.hpp"
#include "detray/tracks/tracks.hpp"

namespace detray::detail {

/// A functor to get from a free to a bound vector
template <typename algebra_t>
struct free_to_bound_vector {

using transform3 = algebra_t;
using free_vector_type =
typename free_track_parameters<algebra_t>::vector_type;
using bound_vector_type =
typename bound_track_parameters<algebra_t>::vector_type;

// 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_vector_type operator()(
const mask_group_t& mask_group, const index_t& index,
const transform3& trf3, const free_vector_type& free_vec) const {
// Get the concrete mask instance for this surface
const auto& m = mask_group[index];
// Call shape-specific behaviour on the mask
return m.local_frame().free_to_bound_vector(trf3, free_vec);
}
};

/// A functor to get from a bound to a free vector
template <typename algebra_t>
struct bound_to_free_vector {

using transform3 = algebra_t;
using free_vector_type =
typename free_track_parameters<algebra_t>::vector_type;
using bound_vector_type =
typename bound_track_parameters<algebra_t>::vector_type;

template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline free_vector_type operator()(
const mask_group_t& mask_group, const index_t& index,
const transform3& trf3, const bound_vector_type& bound_vec) const {

const auto& m = mask_group[index];

return m.local_frame().bound_to_free_vector(trf3, m, bound_vec);
}
};

/// A functor to get the free-to-bound Jacobian
template <typename algebra_t>
struct free_to_bound_jacobian {

using transform3 = algebra_t;
using free_vector_type =
typename free_track_parameters<algebra_t>::vector_type;
using bound_vector_type =
typename bound_track_parameters<algebra_t>::vector_type;

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& trf3, const free_vector_type& free_vec) const {

const auto& m = mask_group[index];

return m.local_frame().free_to_bound_jacobian(trf3, free_vec);
}
};

/// A functor to get the bound-to-free Jacobian
template <typename algebra_t>
struct bound_to_free_jacobian {

using transform3 = algebra_t;
using free_vector_type =
typename free_track_parameters<algebra_t>::vector_type;
using bound_vector_type =
typename bound_track_parameters<algebra_t>::vector_type;

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& trf3, const bound_vector_type& bound_vec) const {

const auto& m = mask_group[index];

return m.local_frame().bound_to_free_jacobian(trf3, m, bound_vec);
}
};

/// A functor to get the path correction
template <typename algebra_t>
struct path_correction {

using transform3 = algebra_t;
using vector3 = typename algebra_t::vector3;
using free_vector_type =
typename free_track_parameters<algebra_t>::vector_type;
using bound_vector_type =
typename bound_track_parameters<algebra_t>::vector_type;
using matrix_operator = typename algebra_t::matrix_actor;
using size_type = typename matrix_operator::size_ty;
template <size_type ROWS, size_type COLS>
using matrix_type =
typename matrix_operator::template matrix_type<ROWS, COLS>;
using free_matrix = matrix_type<e_free_size, e_free_size>;

template <typename mask_group_t, typename index_t>
DETRAY_HOST_DEVICE inline free_matrix operator()(
const mask_group_t& mask_group, const index_t& index,
const transform3& trf3, const vector3& pos, const vector3& dir,
const vector3& dtds) const {

const auto& m = mask_group[index];

return m.local_frame().path_correction(pos, dir, dtds, trf3);
}
};

} // namespace detray::detail
Loading

0 comments on commit e9029f9

Please sign in to comment.