Skip to content

Commit

Permalink
Merge branch 'main' into refactor-simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
beomki-yeo authored Aug 30, 2023
2 parents 03d09bf + cd3adc8 commit ef1171a
Show file tree
Hide file tree
Showing 29 changed files with 692 additions and 76 deletions.
5 changes: 3 additions & 2 deletions core/include/detray/coordinates/cartesian2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ struct cartesian2 final : public coordinate_base<cartesian2, transform3_t> {
// Do nothing
}

template <size_type meas_dim, bool normal_order>
template <size_type meas_dim>
DETRAY_HOST_DEVICE inline void unsigned_local(
matrix_type<meas_dim, e_bound_size> & /*projection_matrix*/,
const bound_track_parameters<transform3_t> & /*bound_params*/) {
const bound_track_parameters<transform3_t> & /*bound_params*/,
const bool /*normal_order*/) {
// Do nothing
return;
}
Expand Down
12 changes: 6 additions & 6 deletions core/include/detray/coordinates/coordinate_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ struct coordinate_base {
}

/// @returns the projection matrix for measurement
template <size_type meas_dim, bool normal_order>
template <size_type meas_dim>
DETRAY_HOST_DEVICE inline matrix_type<meas_dim, e_bound_size>
projection_matrix(
const bound_track_parameters<transform3_t>& bound_params) {
projection_matrix(const bound_track_parameters<transform3_t>& bound_params,
const bool normal_order) {

matrix_type<meas_dim, e_bound_size> proj =
matrix_operator().template zero<meas_dim, e_bound_size>();
// For normal ordering
if constexpr (normal_order == true) {
if (normal_order == true) {
// For meas_dim == 1, Return:
// [ 1 0 0 0 0 0 ]
if constexpr (meas_dim == 1u) {
Expand Down Expand Up @@ -279,8 +279,8 @@ struct coordinate_base {
}
}

Derived<transform3_t>().template unsigned_local<meas_dim, normal_order>(
proj, bound_params);
Derived<transform3_t>().template unsigned_local<meas_dim>(
proj, bound_params, normal_order);

return proj;
}
Expand Down
5 changes: 3 additions & 2 deletions core/include/detray/coordinates/cylindrical2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ struct cylindrical2 : public coordinate_base<cylindrical2, transform3_t> {
// Do nothing
}

template <size_type meas_dim, bool normal_order>
template <size_type meas_dim>
DETRAY_HOST_DEVICE inline void unsigned_local(
matrix_type<meas_dim, e_bound_size> & /*projection_matrix*/,
const bound_track_parameters<transform3_t> & /*bound_params*/) {
const bound_track_parameters<transform3_t> & /*bound_params*/,
const bool /*normal_order*/) {
// Do nothing
return;
}
Expand Down
7 changes: 4 additions & 3 deletions core/include/detray/coordinates/line2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,17 @@ struct line2 : public coordinate_base<line2, transform3_t> {
theta_to_free_pos_derivative[2];
}

template <size_type meas_dim, bool normal_order>
template <size_type meas_dim>
DETRAY_HOST_DEVICE inline void unsigned_local(
matrix_type<meas_dim, e_bound_size> &projection_matrix,
const bound_track_parameters<transform3_t> &bound_params) {
const bound_track_parameters<transform3_t> &bound_params,
const bool normal_order) {

const auto bound_local = bound_params.bound_local();

// Change the sign of radial distance if it is negative
if (bound_local[0] < 0.f) {
if constexpr (normal_order == true) {
if (normal_order == true) {
matrix_operator().element(projection_matrix, 0u, 0u) = -1.f;
} else {
if constexpr (meas_dim == 2u) {
Expand Down
5 changes: 3 additions & 2 deletions core/include/detray/coordinates/polar2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ struct polar2 : public coordinate_base<polar2, transform3_t> {
// Do nothing
}

template <size_type meas_dim, bool normal_order>
template <size_type meas_dim>
DETRAY_HOST_DEVICE inline void unsigned_local(
matrix_type<meas_dim, e_bound_size> & /*projection_matrix*/,
const bound_track_parameters<transform3_t> & /*bound_params*/) {
const bound_track_parameters<transform3_t> & /*bound_params*/,
const bool /*normal_order*/) {
// Do nothing
return;
}
Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/masks/annulus2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace detray {
/// included (bounds[4], bounds[5]). These are the origin shift in x and y
/// respectively.
template <template <typename> class intersector_t = plane_intersector,
unsigned int kMeasDim = 1u, bool kNormalOrder = false>
unsigned int kMeasDim = 1u>
class annulus2D {
public:
/// The name for this shape
Expand All @@ -59,9 +59,6 @@ class annulus2D {
/// The measurement dimension
inline static constexpr const unsigned int meas_dim{kMeasDim};

/// Normal ordering
inline static constexpr const bool normal_order{kNormalOrder};

// Measurement dimension check
static_assert(meas_dim == 1u || meas_dim == 2u,
"Only 1D or 2D measurement is allowed");
Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/masks/cylinder2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace detray {
/// It is defined by r and the two half lengths rel to the coordinate center.
template <bool kRadialCheck = false,
template <typename> class intersector_t = cylinder_intersector,
unsigned int kMeasDim = 2u, bool kNormalOrder = true>
unsigned int kMeasDim = 2u>
class cylinder2D {
public:
/// The name for this shape
Expand All @@ -49,9 +49,6 @@ class cylinder2D {
/// The measurement dimension
inline static constexpr const unsigned int meas_dim{kMeasDim};

/// Normal ordering
inline static constexpr const bool normal_order{kNormalOrder};

// Measurement dimension check
static_assert(meas_dim == 1u || meas_dim == 2u,
"Only 1D or 2D measurement is allowed");
Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/masks/line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace detray {
/// in z.
template <bool kSquareCrossSect = false,
template <typename> class intersector_t = line_intersector,
unsigned int kMeasDim = 1u, bool kNormalOrder = true>
unsigned int kMeasDim = 1u>
class line {
public:
/// The name for this shape
Expand All @@ -53,9 +53,6 @@ class line {
/// The measurement dimension
inline static constexpr const unsigned int meas_dim{kMeasDim};

/// Normal ordering
inline static constexpr const bool normal_order{kNormalOrder};

// Measurement dimension check
static_assert(meas_dim == 1u || meas_dim == 2u,
"Only 1D or 2D measurement is allowed");
Expand Down
18 changes: 10 additions & 8 deletions core/include/detray/masks/masks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class mask {
using matrix_type = typename algebra_t::template matrix_type<ROWS, COLS>;
using projection_matrix_type = matrix_type<shape::meas_dim, e_bound_size>;

// Measurement ordering
bool normal_order = true;

/// Default constructor
constexpr mask() = default;

Expand Down Expand Up @@ -197,9 +200,8 @@ class mask {
/// @returns the projection matrix for measurement
DETRAY_HOST_DEVICE projection_matrix_type projection_matrix(
const bound_track_parameters<algebra_t>& bound_params) const {
return this->local_frame()
.template projection_matrix<shape::meas_dim, shape::normal_order>(
bound_params);
return this->local_frame().template projection_matrix<shape::meas_dim>(
bound_params, normal_order);
}

/// @brief Lower and upper point for minimum axis aligned bounding box.
Expand All @@ -225,11 +227,11 @@ class mask {
template <typename transform3_t>
auto global_min_bounds_center(const transform3_t& trf) const {
const auto m = local_min_bounds();
const auto cuboid = m.get_shape();
const auto center{0.5f * (point3_t{m[cuboid.e_max_x], m[cuboid.e_max_y],
m[cuboid.e_max_z]} +
point3_t{m[cuboid.e_min_x], m[cuboid.e_min_y],
m[cuboid.e_min_z]})};
const auto center{
0.5f * (point3_t{m[cuboid3D<>::e_max_x], m[cuboid3D<>::e_max_y],
m[cuboid3D<>::e_max_z]} +
point3_t{m[cuboid3D<>::e_min_x], m[cuboid3D<>::e_min_y],
m[cuboid3D<>::e_min_z]})};
return trf.point_to_global(center);
}

Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/masks/rectangle2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace detray {
///
/// It is defined by half length in local0 coordinates bounds[0] and bounds[1]
template <template <typename> class intersector_t = plane_intersector,
unsigned int kMeasDim = 2u, bool kNormalOrder = true>
unsigned int kMeasDim = 2u>
class rectangle2D {
public:
/// The name for this shape
Expand All @@ -42,9 +42,6 @@ class rectangle2D {
/// The measurement dimension
inline static constexpr const unsigned int meas_dim{kMeasDim};

/// Normal ordering
inline static constexpr const bool normal_order{kNormalOrder};

// Measurement dimension check
static_assert(meas_dim == 1u || meas_dim == 2u,
"Only 1D or 2D measurement is allowed");
Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/masks/ring2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace detray {
/// It is defined by the two radii bounds[0] and bounds[1],
/// and can be checked with a tolerance in t[0] and t[1].
template <template <typename> class intersector_t = plane_intersector,
unsigned int kMeasDim = 2u, bool kNormalOrder = true>
unsigned int kMeasDim = 2u>
class ring2D {
public:
/// The name for this shape
Expand All @@ -43,9 +43,6 @@ class ring2D {
/// The measurement dimension
inline static constexpr const unsigned int meas_dim{kMeasDim};

/// Normal ordering
inline static constexpr const bool normal_order{kNormalOrder};

// Measurement dimension check
static_assert(meas_dim == 1u || meas_dim == 2u,
"Only 1D or 2D measurement is allowed");
Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/masks/single3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace detray {
/// the local coordinate system
template <unsigned int kCheckIndex = 0u,
template <typename> class intersector_t = plane_intersector,
unsigned int kMeasDim = 2u, bool kNormalOrder = true>
unsigned int kMeasDim = 2u>
class single3D {
public:
/// The name for this shape
Expand All @@ -44,9 +44,6 @@ class single3D {
/// The measurement dimension
inline static constexpr const unsigned int meas_dim{kMeasDim};

/// Normal ordering
inline static constexpr const bool normal_order{kNormalOrder};

enum boundaries : unsigned int {
e_lower = 0u,
e_upper = 1u,
Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/masks/trapezoid2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace detray {
/// the precomputed value of 1 / (2 * bounds[2]), which avoids
/// excessive floating point divisions.
template <template <typename> class intersector_t = plane_intersector,
unsigned int kMeasDim = 2u, bool kNormalOrder = true>
unsigned int kMeasDim = 2u>
class trapezoid2D {
public:
/// The name for this shape
Expand All @@ -45,9 +45,6 @@ class trapezoid2D {
/// The measurement dimension
inline static constexpr const unsigned int meas_dim{kMeasDim};

/// Normal ordering
inline static constexpr const bool normal_order{kNormalOrder};

// Measurement dimension check
static_assert(meas_dim == 1u || meas_dim == 2u,
"Only 1D or 2D measurement is allowed");
Expand Down
3 changes: 0 additions & 3 deletions core/include/detray/masks/unbounded.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class unbounded {
/// The measurement dimension
inline static constexpr const std::size_t meas_dim = shape::meas_dim;

/// normal ordering
inline static constexpr const bool normal_order = shape::normal_order;

/// Local coordinate frame for boundary checks
template <typename algebra_t>
using local_frame_type =
Expand Down
2 changes: 1 addition & 1 deletion extern/algebra-plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ message(STATUS "Building Algebra Plugins as part of the Detray project")

# Declare where to get Algebra Plugins from.
set( DETRAY_ALGEBRA_PLUGINS_SOURCE
"URL;https://github.com/acts-project/algebra-plugins/archive/refs/tags/v0.20.0.tar.gz;URL_MD5;c28cb43e07c7d4f21a1eb5bf659c7a98"
"URL;https://github.com/acts-project/algebra-plugins/archive/refs/tags/v0.21.0.tar.gz;URL_MD5;0fde9e5069c597eb5eccff4c35d0ddd9"
CACHE STRING "Source for Algebra Plugins, when built as part of this project" )
mark_as_advanced(DETRAY_ALGEBRA_PLUGINS_SOURCE)
FetchContent_Declare(AlgebraPlugins ${DETRAY_ALGEBRA_PLUGINS_SOURCE})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/** 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/geometry/detector_volume.hpp"
#include "detray/plugins/svgtools/conversion/portal.hpp"
#include "detray/plugins/svgtools/conversion/surface.hpp"
#include "detray/plugins/svgtools/utils/volume_utils.hpp"

// Actsvg include(s)
#include "actsvg/proto/portal.hpp"
#include "actsvg/proto/surface.hpp"
#include "actsvg/proto/volume.hpp"

// System include(s)
#include <vector>

namespace detray::svgtools::conversion {

/// @brief Calculates the proto volume of a collection of detray surfaces.
///
/// @param context The context.
/// @param d_surfaces The detray surfaces.
///
/// @returns An actsvg proto volume representing the volume.
template <typename point3_container_t, typename detector_t>
auto volume(const typename detector_t::geometry_context& context,
const detector_t& detector,
const std::vector<detray::surface<detector_t>>& d_surfaces) {
using p_volume_t = actsvg::proto::volume<point3_container_t>;
using p_portal_t = actsvg::proto::portal<point3_container_t>;
using p_surface_t = actsvg::proto::surface<point3_container_t>;
p_volume_t p_volume;
std::vector<p_surface_t> surfaces;
std::vector<p_portal_t> portals;
for (const auto& item : d_surfaces) {
if (item.is_portal()) {
auto portal = svgtools::conversion::portal<point3_container_t>(
context, detector, item);
portals.push_back(portal);
} else {
auto surface = svgtools::conversion::surface<point3_container_t>(
context, item);
surfaces.push_back(surface);
}
}
p_volume._v_surfaces = surfaces;
p_volume._portals = portals;
return p_volume;
}

/// @brief Calculates the proto volume of a detray volume.
///
/// @param context The context.
/// @param d_volume The detray volume.
///
/// @returns An actsvg proto volume representing the volume.
template <typename point3_container_t, typename detector_t>
auto volume(const typename detector_t::geometry_context& context,
const detector_t& detector,
const detray::detector_volume<detector_t>& d_volume) {
std::vector<detray::surface<detector_t>> surfaces{};
const auto descriptors =
svgtools::utils::surface_lookup(detector, d_volume);
for (const auto& desc : descriptors) {
surfaces.push_back(detray::surface{detector, desc});
}
return svgtools::conversion::volume<point3_container_t>(context, detector,
surfaces);
}

} // namespace detray::svgtools::conversion
Loading

0 comments on commit ef1171a

Please sign in to comment.