From 0d0b934c021bf2377a5f43934dcab4252fdbd279 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 25 Aug 2022 14:47:14 -0700 Subject: [PATCH 01/63] Backup --- .vscode/settings.json | 6 + core/CMakeLists.txt | 1 - .../include/detray/coordinates/cartesian2.hpp | 61 ++++---- .../detray/coordinates/coordinate_base.hpp | 132 +++++++++++++----- .../detray/coordinates/cylindrical2.hpp | 83 ++++++++++- core/include/detray/coordinates/line2.hpp | 47 ++++++- core/include/detray/coordinates/polar2.hpp | 98 ++++++++++--- .../detray/tracks/detail/track_helper.hpp | 26 ---- .../detray/tracks/detail/trigonometrics.hpp | 26 ---- 9 files changed, 341 insertions(+), 139 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 core/include/detray/tracks/detail/trigonometrics.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..0ee629843 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "*.sycl": "cpp", + "*.ipp": "cpp" + } +} \ No newline at end of file diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 85dba5e91..19650124f 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -93,7 +93,6 @@ detray_add_library( detray_core core "include/detray/tools/local_object_finder.hpp" # tracks include(s) "include/detray/tracks/detail/track_helper.hpp" - "include/detray/tracks/detail/trigonometrics.hpp" "include/detray/tracks/bound_track_parameters.hpp" "include/detray/tracks/free_track_parameters.hpp" "include/detray/tracks/tracks.hpp" diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index aa0cd6f4e..025ed40b6 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -21,26 +21,25 @@ struct cartesian2 final : public coordinate_base { /// @name Type definitions for the struct /// @{ - /// Base type + // Base type using base_type = coordinate_base; - /// Sclar type + // Sclar type using scalar_type = typename base_type::scalar_type; - /// Point in 2D space + // Point in 2D space using point2 = typename base_type::point2; - /// Point in 3D space + // Point in 3D space using point3 = typename base_type::point3; - /// Vector in 3D space + // Vector in 3D space using vector3 = typename base_type::vector3; - /// Matrix actor + // Matrix actor using matrix_actor = typename base_type::matrix_actor; - /// Matrix size type + // Rotation Matrix + using rotation_matrix = typename base_type::rotation_matrix; + // Matrix size type using size_type = typename base_type::size_type; - /// 2D matrix type + // 2D matrix type template using matrix_type = typename base_type::template matrix_type; - - // Trigonometrics - using trigonometrics = typename base_type::trigonometrics; // Vector types using bound_vector = typename base_type::bound_vector; using free_vector = typename base_type::free_vector; @@ -66,9 +65,9 @@ struct cartesian2 final : public coordinate_base { /** This method transform from a point from global cartesian 3D frame to a * local 2D cartesian point */ DETRAY_HOST_DEVICE - inline point2 global_to_local(const transform3_t &trf, const point3 &p, + inline point2 global_to_local(const transform3_t &trf3, const point3 &p, const vector3 & /*d*/) const { - const auto local3 = trf.point_to_local(p); + const auto local3 = trf3.point_to_local(p); return this->operator()(local3); } @@ -76,30 +75,40 @@ struct cartesian2 final : public coordinate_base { * cartesian 3D frame*/ template DETRAY_HOST_DEVICE inline point3 local_to_global( - const transform3_t &trf, const mask_t & /*mask*/, const point2 &p, + const transform3_t &trf3, const mask_t & /*mask*/, const point2 &p, const vector3 & /*d*/) const { - return trf.point_to_global(point3{p[0], p[1], 0.}); + return trf3.point_to_global(point3{p[0], p[1], 0.}); } - DETRAY_HOST_DEVICE - inline matrix_type<3, 2> bound_to_free_rotation( - const transform3_t &trf3, const trigonometrics & /*t*/) { + template + DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( + const transform3_t &trf3, const mask_t &mask, const point3 & /*pos*/, + const vector3 & /*dir*/) const { + return trf3.rotation(); + } + + template + DETRAY_HOST_DEVICE inline matrix_type<3, 2> bound_to_free_rotation( + const transform3_t &trf3, const mask_t &mask, const point3 &pos, + const vector3 &dir) const { + + const auto frame = reference_frame(trf3, mask, pos, dir); // Get d(x,y,z)/d(loc0, loc1) - return matrix_actor().template block<3, 2>(trf3.matrix(), 0, 0); + return matrix_actor().template block<3, 2>(frame, 0, 0); } - DETRAY_HOST_DEVICE - inline matrix_type<2, 3> free_to_bound_rotation( - const transform3_t &trf3, const trigonometrics & /*t*/) { + template + DETRAY_HOST_DEVICE inline matrix_type<2, 3> free_to_bound_rotation( + const transform3_t &trf3, const mask_t &mask, const point3 &pos, + const vector3 &dir) const { - // Get transpose of transform3 matrix - const auto trf3T = matrix_actor().transpose(trf3); + const auto frame = reference_frame(trf3, mask, pos, dir); + const auto frameT = matrix_actor().transpose(frame); // Get d(loc0, loc1)/d(x,y,z) - return matrix_actor().template block<2, 3>(trf3T.matrix(), 0, 0); + return matrix_actor().template block<2, 3>(frameT, 0, 0); } - }; // struct cartesian2 } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index de572c925..1d8195bdb 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -21,25 +21,27 @@ struct coordinate_base { /// @name Type definitions for the struct /// @{ - /// Scalar type + // Scalar type using scalar_type = typename transform3_t::scalar_type; - /// Point in 2D space + // Point in 2D space using point2 = typename transform3_t::point2; - /// Point in 3D space + // Point in 3D space using point3 = typename transform3_t::point3; - /// Vector in 3D space + // Vector in 3D space using vector3 = typename transform3_t::vector3; - /// Matrix actor + // Matrix actor using matrix_actor = typename transform3_t::matrix_actor; - /// Matrix size type + // Matrix size type using size_type = typename matrix_actor::size_ty; - /// 2D matrix type + // 2D matrix type template using matrix_type = typename matrix_actor::template matrix_type; - /// Shorthand vector/matrix types related to bound track parameters. + // Rotation Matrix + using rotation_matrix = matrix_type<3, 3>; + // Shorthand vector/matrix types related to bound track parameters. using bound_vector = matrix_type; using bound_matrix = matrix_type; - /// Mapping from bound track parameters. + // Mapping from bound track parameters. using bound_to_free_matrix = matrix_type; // Shorthand vector/matrix types related to free track parameters. using free_vector = matrix_type; @@ -49,8 +51,6 @@ struct coordinate_base { using free_to_path_matrix = matrix_type<1, e_free_size>; // Track helper using track_helper = detail::track_helper; - // Trigonometrics - using trigonometrics = typename track_helper::trigonometrics; /// @} @@ -103,81 +103,145 @@ struct coordinate_base { return free_vec; } + template DETRAY_HOST_DEVICE inline bound_to_free_matrix bound_to_free_jacobian( - const transform3_t& trf3, const bound_vector& bound_vec) { + const transform3_t& trf3, const mask_t& mask, + const bound_vector& bound_vec) const { // Declare jacobian for bound to free coordinate transform bound_to_free_matrix jac_to_global = matrix_actor().template zero(); // Get trigonometric values - const auto t = track_helper().get_trigonometrics(bound_vec); + const scalar_type theta = + matrix_actor().element(bound_vec, e_bound_theta, 0); + const scalar_type phi = + matrix_actor().element(bound_vec, e_bound_phi, 0); + + const scalar_type cos_theta = std::cos(theta); + const scalar_type sin_theta = std::sin(theta); + const scalar_type cos_phi = std::cos(phi); + const scalar_type sin_phi = std::sin(phi); + + // Global position and direction + const vector3 pos = track_helper().pos(bound_vec); + const vector3 dir = track_helper().dir(bound_vec); // Get d(x,y,z)/d(loc0, loc1) const matrix_type<3, 2> bound_to_free_rotation = - Derived().bound_to_free_rotation(trf3, t); + Derived().bound_to_free_rotation(trf3, mask, pos, + dir); matrix_actor().template set_block(jac_to_global, bound_to_free_rotation, e_free_pos0, e_bound_loc0); + // Set d(bound time)/d(free time) matrix_actor().element(jac_to_global, e_free_time, e_bound_time) = 1; + + // Set d(n_x,n_y,n_z)/d(phi, theta) matrix_actor().element(jac_to_global, e_free_dir0, e_bound_phi) = - -1 * t.sin_theta * t.sin_phi; + -1 * sin_theta * sin_phi; matrix_actor().element(jac_to_global, e_free_dir0, e_bound_theta) = - t.cos_theta * t.cos_phi; + cos_theta * cos_phi; matrix_actor().element(jac_to_global, e_free_dir1, e_bound_phi) = - t.sin_theta * t.cos_phi; + sin_theta * cos_phi; matrix_actor().element(jac_to_global, e_free_dir1, e_bound_theta) = - t.cos_theta * t.sin_phi; + cos_theta * sin_phi; matrix_actor().element(jac_to_global, e_free_dir2, e_bound_theta) = - -1 * t.sin_theta; + -1 * sin_theta; matrix_actor().element(jac_to_global, e_free_qoverp, e_bound_qoverp) = 1; + // Get d(x,y,z)/d(phi, theta) + /* + const matrix_type<3, 2> bound_angle_to_free_pos_jacobian = + Derived().bound_angle_to_free_pos_jacobian(); + */ + return jac_to_global; } - DETRAY_HOST_DEVICE - inline free_to_bound_matrix free_to_bound_jacobian( - const transform3_t& trf3, const free_vector& free_vec) { + template + DETRAY_HOST_DEVICE inline free_to_bound_matrix free_to_bound_jacobian( + const transform3_t& trf3, const mask_t& mask, + const free_vector& free_vec) const { // Declare jacobian for bound to free coordinate transform free_to_bound_matrix jac_to_local = matrix_actor().template zero(); - // Free direction + // Global position and direction + const vector3 pos = track_helper().pos(free_vec); const vector3 dir = track_helper().dir(free_vec); - // Get trigonometric values - const auto t = track_helper().get_trigonometrics(free_vec); + const scalar_type theta = getter::theta(dir); + const scalar_type phi = getter::phi(dir); + + const scalar_type cos_theta = std::cos(theta); + const scalar_type sin_theta = std::sin(theta); + const scalar_type cos_phi = std::cos(phi); + const scalar_type sin_phi = std::sin(phi); // Get d(loc0, loc1)/d(x,y,z) const matrix_type<2, 3> free_to_bound_rotation = - Derived().free_to_bound_rotation(trf3, t); - + Derived().free_to_bound_rotation(trf3, mask, pos, + dir); matrix_actor().template set_block(jac_to_local, free_to_bound_rotation, e_bound_loc0, e_free_pos0); - // Set d(Free time)/d(Bound time) + // Set d(free time)/d(bound time) matrix_actor().element(jac_to_local, e_bound_time, e_free_time) = 1; - // Set d(phi, theta)/d(free dir) + // Set d(phi, theta)/d(n_x, n_y, n_z) matrix_actor().element(jac_to_local, e_bound_phi, e_free_dir0) = - -1. * t.sin_phi / t.sin_theta; + -1. * sin_phi / sin_theta; matrix_actor().element(jac_to_local, e_bound_phi, e_free_dir1) = - t.cos_phi / t.sin_theta; + cos_phi / sin_theta; matrix_actor().element(jac_to_local, e_bound_theta, e_free_dir0) = - t.cos_phi * t.cos_theta; + cos_phi * cos_theta; matrix_actor().element(jac_to_local, e_bound_theta, e_free_dir1) = - t.sin_phi * t.cos_theta; + sin_phi * cos_theta; matrix_actor().element(jac_to_local, e_bound_theta, e_free_dir2) = - -1 * t.sin_theta; + -1 * sin_theta; // Set d(Free Qop)/d(Bound Qop) matrix_actor().element(jac_to_local, e_bound_qoverp, e_free_qoverp) = 1; return jac_to_local; } + + template + DETRAY_HOST_DEVICE inline free_to_path_matrix free_to_path_correction( + const transform3_t& trf3, const mask_t& mask, + const free_vector& free_vec) const { + + // Declare free to path correction + free_to_path_matrix free_to_path = + matrix_actor().template zero<1, e_free_size>(); + + // Global position and direction + const vector3 pos = track_helper().pos(free_vec); + const vector3 dir = track_helper().dir(free_vec); + + // The measurement frame z axis + const auto frame = + Derived().reference_frame(trf3, mask, pos, dir); + const matrix_type<3, 1> ref_z_axis = + matrix_actor()().template block<3, 1>(frame, 0, 2); + + // cosine angle between momentum direction and the measurement frame z + // axis + const scalar_type dz = vector::dot(ref_z_axis, dir); + + // Correction term + const matrix_type<1, 3> correction_term = + -1. / dz * matrix_actor().transpose(ref_z_axis); + + matrix_actor().template set_block<1, 3>(free_to_path, correction_term, + 0, e_free_pos0); + + return free_to_path; + } }; } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/cylindrical2.hpp b/core/include/detray/coordinates/cylindrical2.hpp index 528076d4d..d1e9a1ab9 100644 --- a/core/include/detray/coordinates/cylindrical2.hpp +++ b/core/include/detray/coordinates/cylindrical2.hpp @@ -24,16 +24,28 @@ struct cylindrical2 : public coordinate_base { /// @name Type definitions for the struct /// @{ - /// Base type + // Base type using base_type = coordinate_base; - /// Sclar type + // Sclar type using scalar_type = typename transform3_t::scalar_type; - /// Point in 2D space + // Point in 2D space using point2 = typename transform3_t::point2; - /// Point in 3D space + // Point in 3D space using point3 = typename transform3_t::point3; - /// Vector in 3D space + // Vector in 3D space using vector3 = typename transform3_t::vector3; + // Matrix actor + using matrix_actor = typename base_type::matrix_actor; + // Matrix size type + using size_type = typename base_type::size_type; + // 2D matrix type + template + using matrix_type = typename base_type::template matrix_type; + // Rotation Matrix + using rotation_matrix = typename base_type::rotation_matrix; + // Vector types + using bound_vector = typename base_type::bound_vector; + using free_vector = typename base_type::free_vector; /// @} @@ -69,6 +81,67 @@ struct cylindrical2 : public coordinate_base { return trf.point_to_global(point3{x, y, z}); } + template + DETRAY_HOST_DEVICE inline vector3 normal(const transform3_t &trf3, + const mask_t &mask, + const point3 &pos) const { + const point2 local2 = this->operator()(pos); + const scalar_type r = mask.radius(); + const scalar_type phi = p[0] / r; + + // normal vector in local coordinate + const vector3 local_normal{std::cos(phi), std::sin(phi), 0}; + + // normal vector in global coordinate + return trf3.rotation() * local_normal; + } + + template + DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( + const transform3_t &trf3, const mask_t &mask, const point3 &pos, + const vector3 & /*dir*/) const { + + rotation_matrix rot = matrix_actor().template zero<3, 3>(); + + // y axis of the new frame is the z axis of cylindrical coordinate + const auto new_yaxis = matrix_actor().template block<3, 1>(trf3, 0, 2); + + // z axis of the new frame is the vector normal to the cylinder surface + const vector3 new_zaxis = normal(trf3, mask, pos); + + // x axis + const vector3 new_xaxis = vector::cross(new_yaxis, new_zaxis); + + matrix_actor().set_block<3, 1>(rot, new_xaxis, 0, 0); + matrix_actor().set_block<3, 1>(rot, new_yaxis, 0, 1); + matrix_actor().set_block<3, 1>(rot, new_zaxis, 0, 2); + + return rot; + } + + template + DETRAY_HOST_DEVICE inline matrix_type<3, 2> bound_to_free_rotation( + const transform3_t &trf3, const mask_t &mask, const point3 &pos, + const vector3 &dir) const { + + const auto frame = reference_frame(trf3, mask, pos, dir); + + // Get d(x,y,z)/d(loc0, loc1) + return matrix_actor().template block<3, 2>(frame, 0, 0); + } + + template + DETRAY_HOST_DEVICE inline matrix_type<2, 3> free_to_bound_rotation( + const transform3_t &trf3, const mask_t &mask, const point3 &pos, + const vector3 &dir) const { + + const auto frame = reference_frame(trf3, mask, pos, dir); + const auto frameT = matrix_actor().transpose(frame); + + // Get d(loc0, loc1)/d(x,y,z) + return matrix_actor().template block<2, 3>(frameT, 0, 0); + } + }; // struct cylindrical2 } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/line2.hpp b/core/include/detray/coordinates/line2.hpp index 2238fb09a..ca22ad2e8 100644 --- a/core/include/detray/coordinates/line2.hpp +++ b/core/include/detray/coordinates/line2.hpp @@ -19,16 +19,30 @@ struct line2 : public coordinate_base { /// @name Type definitions for the struct /// @{ - /// Base type + // Base type using base_type = coordinate_base; - /// Sclar type + // Sclar type using scalar_type = typename base_type::scalar_type; - /// Point in 2D space + // Point in 2D space using point2 = typename base_type::point2; - /// Point in 3D space + // Point in 3D space using point3 = typename base_type::point3; - /// Vector in 3D space + // Vector in 3D space using vector3 = typename base_type::vector3; + // Matrix actor + using matrix_actor = typename base_type::matrix_actor; + // Matrix size type + using size_type = typename base_type::size_type; + // 2D matrix type + template + using matrix_type = typename base_type::template matrix_type; + // Rotation Matrix + using rotation_matrix = typename base_type::rotation_matrix; + // Vector types + using bound_vector = typename base_type::bound_vector; + using free_vector = typename base_type::free_vector; + // Track Helper + using track_helper = typename base_type::track_helper; /// @} @@ -85,6 +99,29 @@ struct line2 : public coordinate_base { return locZ_in_global + p[0] * vector::normalize(r); } + + template + DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( + const transform3_t &trf3, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 &dir) const { + + rotation_matrix rot = matrix_actor().template zero<3, 3>(); + + // y axis of the new frame is the z axis of line coordinate + const auto new_yaxis = matrix_actor().template block<3, 1>(trf3, 0, 2); + + // x axis of the new frame is (yaxis x track direction) + const auto new_xaxis = vector::cross(new_yaxis, dir); + + // z axis + const auto new_zaxis = vector::cross(new_xaxis, new_yaxis); + + matrix_actor().set_block<3, 1>(rot, new_xaxis, 0, 0); + matrix_actor().set_block<3, 1>(rot, new_yaxis, 0, 1); + matrix_actor().set_block<3, 1>(rot, new_zaxis, 0, 2); + + return rot; + } }; } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index 60ac274a6..0b602fb1a 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -22,28 +22,30 @@ struct polar2 : public coordinate_base { /// @name Type definitions for the struct /// @{ - /// Base type + // Base type using base_type = coordinate_base; - /// Sclar type + // Sclar type using scalar_type = typename base_type::scalar_type; - /// Point in 2D space + // Point in 2D space using point2 = typename base_type::point2; - /// Point in 3D space + // Point in 3D space using point3 = typename base_type::point3; - /// Vector in 3D space + // Vector in 3D space using vector3 = typename base_type::vector3; - /// Matrix actor + // Matrix actor using matrix_actor = typename base_type::matrix_actor; - /// Matrix size type + // Matrix size type using size_type = typename base_type::size_type; - /// 2D matrix type + // 2D matrix type template using matrix_type = typename base_type::template matrix_type; - // Trigonometrics - using trigonometrics = typename base_type::trigonometrics; + // Rotation Matrix + using rotation_matrix = typename base_type::rotation_matrix; // Vector types using bound_vector = typename base_type::bound_vector; using free_vector = typename base_type::free_vector; + // Track Helper + using track_helper = typename base_type::track_helper; /** This method transform from a point from 2D cartesian frame to a 2D * polar point */ @@ -80,18 +82,82 @@ struct polar2 : public coordinate_base { return trf.point_to_global(point3{x, y, 0.}); } - DETRAY_HOST_DEVICE - inline matrix_type<3, 2> bound_to_free_rotation( - const transform3_t & /*trf3*/, const trigonometrics & /*t*/) { + template + DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( + const transform3_t &trf3, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const { + return trf3.rotation(); + } + + template + DETRAY_HOST_DEVICE inline matrix_type<3, 2> bound_to_free_rotation( + const transform3_t &trf3, const mask_t &mask, const point3 &pos, + const vector3 &dir) const { - /* matrix_type<3, 2> bound_to_free_rotation = matrix_actor().template zero<3, 2>(); - */ + + const point2 local2 = this->operator()(pos); + const scalar_type lrad = local2[0]; + const scalar_type lphi = local2[1]; + + const scalar_type lcos_phi = std::cos(lphi); + const scalar_type lsin_phi = std::sin(lphi); + + // reference matrix + const auto frame = reference_frame(trf3, pos, dir); + + // dxdL = dx/d(u,v,w) + const auto dxdL = matrix_actor().template block<3, 1>(frame, 0, 0); + // dydL = dy/d(u,v,w) + const auto dydL = matrix_actor().template block<3, 1>(frame, 0, 1); + + const auto col0 = dxdL * lcos_phi + dydL * lsin_phi; + const auto col1 = (dydL * lcos_phi - dxdL * lsin_phi) * lrad; + + matrix_actor().set_block<3, 1>(bound_to_free_rotation, col0, + e_free_pos0, e_bound_loc0); + matrix_actor().set_block<3, 1>(bound_to_free_rotation, col1, + e_free_pos0, e_bound_loc1); + + return bound_to_free_rotation; } + template DETRAY_HOST_DEVICE inline matrix_type<2, 3> free_to_bound_rotation( - const transform3_t & /*trf3*/, const trigonometrics & /*t*/) {} + const transform3_t &trf3, const mask_t &mask, const point3 &pos, + const vector3 &dir) const { + + matrix_type<2, 3> free_to_bound_rotation = + matrix_actor().template zero<2, 3>(); + + const auto local = this->global_to_local(trf3, pos, dir); + + const scalar_type lrad = local[0]; + const scalar_type lphi = local[1]; + + const scalar_type lcos_phi = std::cos(lphi); + const scalar_type lsin_phi = std::sin(lphi); + + // reference matrix + const auto frame = reference_frame(trf3, pos, dir); + const auto frameT = matrix_actor().transpose(frame); + + // dudG = du/d(x,y,z) + const auto dudG = matrix_actor().template block<3, 1>(frameT, 0, 0); + // dvdG = dv/d(x,y,z) + const auto dvdG = matrix_actor().template block<3, 1>(frameT, 0, 1); + + const auto row0 = dudG * lcos_phi + dvdG * lsin_phi; + const auto row1 = (dvdG * lcos_phi - dudG * lsin_phi) * 1. / lrad; + + matrix_actor().set_block<1, 3>(free_to_bound_rotation, row0, + e_bound_loc0, e_free_pos0); + matrix_actor().set_block<1, 3>(free_to_bound_rotation, row1, + e_bound_loc1, e_free_pos0); + + return free_to_bound_rotation; + } }; } // namespace detray \ No newline at end of file diff --git a/core/include/detray/tracks/detail/track_helper.hpp b/core/include/detray/tracks/detail/track_helper.hpp index f74b05fd7..61e8c283a 100644 --- a/core/include/detray/tracks/detail/track_helper.hpp +++ b/core/include/detray/tracks/detail/track_helper.hpp @@ -10,7 +10,6 @@ // Project include(s). #include "detray/definitions/qualifiers.hpp" #include "detray/definitions/track_parametrization.hpp" -#include "detray/tracks/detail/trigonometrics.hpp" // System include(s). #include @@ -38,8 +37,6 @@ struct track_helper { using point3 = vector3; /// Point in 2D space using point2 = array_type<2>; - /// Trigonometrics - using trigonometrics = detail::trigonometrics; /// Track vector types using bound_vector = matrix_type; @@ -88,29 +85,6 @@ struct track_helper { return {std::cos(phi) * sinTheta, std::sin(phi) * sinTheta, cosTheta}; } - - DETRAY_HOST_DEVICE - inline trigonometrics get_trigonometrics( - const bound_vector& bound_vec) const { - const scalar_type theta = - matrix_actor().element(bound_vec, e_bound_theta, 0); - const scalar_type phi = - matrix_actor().element(bound_vec, e_bound_phi, 0); - - return {std::cos(theta), std::sin(theta), std::cos(phi), std::sin(phi)}; - } - - DETRAY_HOST_DEVICE - inline trigonometrics get_trigonometrics( - const free_vector& free_vec) const { - - const vector3 dir = this->dir(free_vec); - - const scalar_type theta = getter::theta(dir); - const scalar_type phi = getter::phi(dir); - - return {std::cos(theta), std::sin(theta), std::cos(phi), std::sin(phi)}; - } }; } // namespace detray::detail diff --git a/core/include/detray/tracks/detail/trigonometrics.hpp b/core/include/detray/tracks/detail/trigonometrics.hpp deleted file mode 100644 index e5e7dcd7c..000000000 --- a/core/include/detray/tracks/detail/trigonometrics.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/** Algebra plugins library, part of the ACTS project - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "detray/definitions/qualifiers.hpp" - -// System include(s). -#include - -namespace detray::detail { - -template -struct trigonometrics { - scalar_t cos_theta; - scalar_t sin_theta; - scalar_t cos_phi; - scalar_t sin_phi; -}; - -} // namespace detray::detail \ No newline at end of file From 262e36f6595cf69e71bc154076db6139062278c8 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 25 Aug 2022 15:22:45 -0700 Subject: [PATCH 02/63] Backup --- .../include/detray/coordinates/cartesian2.hpp | 14 +++++---- .../detray/coordinates/coordinate_base.hpp | 18 ++++++----- .../detray/coordinates/cylindrical2.hpp | 16 +++++----- core/include/detray/coordinates/polar2.hpp | 30 ++++++++++--------- .../propagator/detail/jacobian_engine.ipp | 10 ++++--- 5 files changed, 49 insertions(+), 39 deletions(-) diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index 025ed40b6..83832b0de 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -88,9 +88,10 @@ struct cartesian2 final : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<3, 2> bound_to_free_rotation( - const transform3_t &trf3, const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline matrix_type<3, 2> + bound_pos_to_free_pos_derivative(const transform3_t &trf3, + const mask_t &mask, const point3 &pos, + const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); @@ -99,9 +100,10 @@ struct cartesian2 final : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<2, 3> free_to_bound_rotation( - const transform3_t &trf3, const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline matrix_type<2, 3> + free_pos_to_bound_pos_derivative(const transform3_t &trf3, + const mask_t &mask, const point3 &pos, + const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); const auto frameT = matrix_actor().transpose(frame); diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 1d8195bdb..454526a2d 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -128,11 +128,12 @@ struct coordinate_base { const vector3 dir = track_helper().dir(bound_vec); // Get d(x,y,z)/d(loc0, loc1) - const matrix_type<3, 2> bound_to_free_rotation = - Derived().bound_to_free_rotation(trf3, mask, pos, - dir); + const matrix_type<3, 2> bound_pos_to_free_pos_derivative = + Derived().bound_pos_to_free_pos_derivative(trf3, mask, + pos, dir); - matrix_actor().template set_block(jac_to_global, bound_to_free_rotation, + matrix_actor().template set_block(jac_to_global, + bound_pos_to_free_pos_derivative, e_free_pos0, e_bound_loc0); // Set d(bound time)/d(free time) @@ -183,10 +184,11 @@ struct coordinate_base { const scalar_type sin_phi = std::sin(phi); // Get d(loc0, loc1)/d(x,y,z) - const matrix_type<2, 3> free_to_bound_rotation = - Derived().free_to_bound_rotation(trf3, mask, pos, - dir); - matrix_actor().template set_block(jac_to_local, free_to_bound_rotation, + const matrix_type<2, 3> free_pos_to_bound_pos_derivative = + Derived().free_pos_to_bound_pos_derivative(trf3, mask, + pos, dir); + matrix_actor().template set_block(jac_to_local, + free_pos_to_bound_pos_derivative, e_bound_loc0, e_free_pos0); // Set d(free time)/d(bound time) diff --git a/core/include/detray/coordinates/cylindrical2.hpp b/core/include/detray/coordinates/cylindrical2.hpp index d1e9a1ab9..5fbd27738 100644 --- a/core/include/detray/coordinates/cylindrical2.hpp +++ b/core/include/detray/coordinates/cylindrical2.hpp @@ -87,7 +87,7 @@ struct cylindrical2 : public coordinate_base { const point3 &pos) const { const point2 local2 = this->operator()(pos); const scalar_type r = mask.radius(); - const scalar_type phi = p[0] / r; + const scalar_type phi = local2[0] / r; // normal vector in local coordinate const vector3 local_normal{std::cos(phi), std::sin(phi), 0}; @@ -120,9 +120,10 @@ struct cylindrical2 : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<3, 2> bound_to_free_rotation( - const transform3_t &trf3, const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline matrix_type<3, 2> + bound_pos_to_free_pos_derivative(const transform3_t &trf3, + const mask_t &mask, const point3 &pos, + const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); @@ -131,9 +132,10 @@ struct cylindrical2 : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<2, 3> free_to_bound_rotation( - const transform3_t &trf3, const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline matrix_type<2, 3> + free_pos_to_bound_pos_derivative(const transform3_t &trf3, + const mask_t &mask, const point3 &pos, + const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); const auto frameT = matrix_actor().transpose(frame); diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index 0b602fb1a..02455f66d 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -90,11 +90,12 @@ struct polar2 : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<3, 2> bound_to_free_rotation( - const transform3_t &trf3, const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline matrix_type<3, 2> + bound_pos_to_free_pos_derivative(const transform3_t &trf3, + const mask_t &mask, const point3 &pos, + const vector3 &dir) const { - matrix_type<3, 2> bound_to_free_rotation = + matrix_type<3, 2> bound_pos_to_free_pos_derivative = matrix_actor().template zero<3, 2>(); const point2 local2 = this->operator()(pos); @@ -115,20 +116,21 @@ struct polar2 : public coordinate_base { const auto col0 = dxdL * lcos_phi + dydL * lsin_phi; const auto col1 = (dydL * lcos_phi - dxdL * lsin_phi) * lrad; - matrix_actor().set_block<3, 1>(bound_to_free_rotation, col0, + matrix_actor().set_block<3, 1>(bound_pos_to_free_pos_derivative, col0, e_free_pos0, e_bound_loc0); - matrix_actor().set_block<3, 1>(bound_to_free_rotation, col1, + matrix_actor().set_block<3, 1>(bound_pos_to_free_pos_derivative, col1, e_free_pos0, e_bound_loc1); - return bound_to_free_rotation; + return bound_pos_to_free_pos_derivative; } template - DETRAY_HOST_DEVICE inline matrix_type<2, 3> free_to_bound_rotation( - const transform3_t &trf3, const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline matrix_type<2, 3> + free_pos_to_bound_pos_derivative(const transform3_t &trf3, + const mask_t &mask, const point3 &pos, + const vector3 &dir) const { - matrix_type<2, 3> free_to_bound_rotation = + matrix_type<2, 3> free_pos_to_bound_pos_derivative = matrix_actor().template zero<2, 3>(); const auto local = this->global_to_local(trf3, pos, dir); @@ -151,12 +153,12 @@ struct polar2 : public coordinate_base { const auto row0 = dudG * lcos_phi + dvdG * lsin_phi; const auto row1 = (dvdG * lcos_phi - dudG * lsin_phi) * 1. / lrad; - matrix_actor().set_block<1, 3>(free_to_bound_rotation, row0, + matrix_actor().set_block<1, 3>(free_pos_to_bound_pos_derivative, row0, e_bound_loc0, e_free_pos0); - matrix_actor().set_block<1, 3>(free_to_bound_rotation, row1, + matrix_actor().set_block<1, 3>(free_pos_to_bound_pos_derivative, row1, e_bound_loc1, e_free_pos0); - return free_to_bound_rotation; + return free_pos_to_bound_pos_derivative; } }; diff --git a/core/include/detray/propagator/detail/jacobian_engine.ipp b/core/include/detray/propagator/detail/jacobian_engine.ipp index a9a21176f..1385d4cb7 100644 --- a/core/include/detray/propagator/detail/jacobian_engine.ipp +++ b/core/include/detray/propagator/detail/jacobian_engine.ipp @@ -26,10 +26,11 @@ detray::detail::jacobian_engine::bound_to_free_coordinate( const scalar_type sin_phi = std::sin(phi); // Set d(x,y,z)/d(loc0,loc1) - const matrix_type<3, 2> bound_to_free_rotation = + const matrix_type<3, 2> bound_pos_to_free_pos_derivative = matrix_operator().template block<3, 2>(trf3.matrix(), 0, 0); - matrix_operator().template set_block(jac_to_global, bound_to_free_rotation, + matrix_operator().template set_block(jac_to_global, + bound_pos_to_free_pos_derivative, e_free_pos0, e_bound_loc0); matrix_operator().element(jac_to_global, e_free_time, e_bound_time) = 1; @@ -71,10 +72,11 @@ detray::detail::jacobian_engine::free_to_bound_coordinate( const scalar_type sin_phi = std::sin(phi); // Set d(loc0,loc1)/d(x,y,z) - const matrix_type<2, 3> free_to_bound_rotation = + const matrix_type<2, 3> free_pos_to_bound_pos_derivative = matrix_operator().template block<2, 3>(trf3.matrix_inverse(), 0, 0); - matrix_operator().template set_block(jac_to_local, free_to_bound_rotation, + matrix_operator().template set_block(jac_to_local, + free_pos_to_bound_pos_derivative, e_bound_loc0, e_free_pos0); // Set d(Free time)/d(Bound time) From 9a063e91e7520cdac446e7ada0d9fa996bf05318 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 29 Aug 2022 10:19:39 -0700 Subject: [PATCH 03/63] Backup --- .../include/detray/coordinates/cartesian2.hpp | 39 ++++++-- .../detray/coordinates/coordinate_base.hpp | 29 ++---- .../detray/coordinates/cylindrical2.hpp | 47 +++++++--- core/include/detray/coordinates/line2.hpp | 93 +++++++++++++++++++ core/include/detray/coordinates/polar2.hpp | 40 +++++--- .../intersection/detail/trajectories.hpp | 21 +++-- 6 files changed, 203 insertions(+), 66 deletions(-) diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index 83832b0de..9dc2a50cf 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -43,6 +43,9 @@ struct cartesian2 final : public coordinate_base { // Vector types using bound_vector = typename base_type::bound_vector; using free_vector = typename base_type::free_vector; + // Matrix types + using free_to_bound_matrix = typename base_type::free_to_bound_matrix; + using bound_to_free_matrix = typename base_type::bound_to_free_matrix; /// @} @@ -88,29 +91,45 @@ struct cartesian2 final : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<3, 2> - bound_pos_to_free_pos_derivative(const transform3_t &trf3, - const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( + bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); // Get d(x,y,z)/d(loc0, loc1) - return matrix_actor().template block<3, 2>(frame, 0, 0); + const auto bound_pos_to_free_pos_derivative = + matrix_actor().template block<3, 2>(frame, 0, 0); + + matrix_actor().template set_block(free_to_bound_jacobian, + bound_pos_to_free_pos_derivative, + e_free_pos0, e_bound_loc0); } template - DETRAY_HOST_DEVICE inline matrix_type<2, 3> - free_pos_to_bound_pos_derivative(const transform3_t &trf3, - const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( + free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); const auto frameT = matrix_actor().transpose(frame); // Get d(loc0, loc1)/d(x,y,z) - return matrix_actor().template block<2, 3>(frameT, 0, 0); + const auto free_pos_to_bound_pos_derivative = + matrix_actor().template block<2, 3>(frameT, 0, 0); + + matrix_actor().template set_block(bound_to_free_jacobian, + free_pos_to_bound_pos_derivative, + e_bound_loc0, e_free_pos0); + } + + template + DETRAY_HOST_DEVICE inline void set_bound_angle_to_free_pos_derivative( + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { + // Do nothing } + }; // struct cartesian2 } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 454526a2d..34c6571c8 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -127,14 +127,9 @@ struct coordinate_base { const vector3 pos = track_helper().pos(bound_vec); const vector3 dir = track_helper().dir(bound_vec); - // Get d(x,y,z)/d(loc0, loc1) - const matrix_type<3, 2> bound_pos_to_free_pos_derivative = - Derived().bound_pos_to_free_pos_derivative(trf3, mask, - pos, dir); - - matrix_actor().template set_block(jac_to_global, - bound_pos_to_free_pos_derivative, - e_free_pos0, e_bound_loc0); + // Set d(x,y,z)/d(loc0, loc1) + Derived().set_bound_pos_to_free_pos_derivative( + jac_to_global, trf3, mask, pos, dir); // Set d(bound time)/d(free time) matrix_actor().element(jac_to_global, e_free_time, e_bound_time) = 1; @@ -153,11 +148,9 @@ struct coordinate_base { matrix_actor().element(jac_to_global, e_free_qoverp, e_bound_qoverp) = 1; - // Get d(x,y,z)/d(phi, theta) - /* - const matrix_type<3, 2> bound_angle_to_free_pos_jacobian = - Derived().bound_angle_to_free_pos_jacobian(); - */ + // Set d(x,y,z)/d(phi, theta) + Derived().set_bound_angle_to_free_pos_derivative( + jac_to_global, trf3, mask, pos, dir); return jac_to_global; } @@ -183,13 +176,9 @@ struct coordinate_base { const scalar_type cos_phi = std::cos(phi); const scalar_type sin_phi = std::sin(phi); - // Get d(loc0, loc1)/d(x,y,z) - const matrix_type<2, 3> free_pos_to_bound_pos_derivative = - Derived().free_pos_to_bound_pos_derivative(trf3, mask, - pos, dir); - matrix_actor().template set_block(jac_to_local, - free_pos_to_bound_pos_derivative, - e_bound_loc0, e_free_pos0); + // Set d(loc0, loc1)/d(x,y,z) + Derived().set_free_pos_to_bound_pos_derivative( + jac_to_local, trf3, mask, pos, dir); // Set d(free time)/d(bound time) matrix_actor().element(jac_to_local, e_bound_time, e_free_time) = 1; diff --git a/core/include/detray/coordinates/cylindrical2.hpp b/core/include/detray/coordinates/cylindrical2.hpp index 5fbd27738..103aba0f7 100644 --- a/core/include/detray/coordinates/cylindrical2.hpp +++ b/core/include/detray/coordinates/cylindrical2.hpp @@ -46,6 +46,9 @@ struct cylindrical2 : public coordinate_base { // Vector types using bound_vector = typename base_type::bound_vector; using free_vector = typename base_type::free_vector; + // Matrix types + using free_to_bound_matrix = typename base_type::free_to_bound_matrix; + using bound_to_free_matrix = typename base_type::bound_to_free_matrix; /// @} @@ -84,8 +87,9 @@ struct cylindrical2 : public coordinate_base { template DETRAY_HOST_DEVICE inline vector3 normal(const transform3_t &trf3, const mask_t &mask, - const point3 &pos) const { - const point2 local2 = this->operator()(pos); + const point3 &pos, + const vector3 &dir) const { + const point2 local2 = this->global_to_local(trf3, pos, dir); const scalar_type r = mask.radius(); const scalar_type phi = local2[0] / r; @@ -99,7 +103,7 @@ struct cylindrical2 : public coordinate_base { template DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( const transform3_t &trf3, const mask_t &mask, const point3 &pos, - const vector3 & /*dir*/) const { + const vector3 &dir) const { rotation_matrix rot = matrix_actor().template zero<3, 3>(); @@ -107,7 +111,7 @@ struct cylindrical2 : public coordinate_base { const auto new_yaxis = matrix_actor().template block<3, 1>(trf3, 0, 2); // z axis of the new frame is the vector normal to the cylinder surface - const vector3 new_zaxis = normal(trf3, mask, pos); + const vector3 new_zaxis = normal(trf3, mask, pos, dir); // x axis const vector3 new_xaxis = vector::cross(new_yaxis, new_zaxis); @@ -120,28 +124,43 @@ struct cylindrical2 : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<3, 2> - bound_pos_to_free_pos_derivative(const transform3_t &trf3, - const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( + bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); // Get d(x,y,z)/d(loc0, loc1) - return matrix_actor().template block<3, 2>(frame, 0, 0); + const auto bound_pos_to_free_pos_derivative = + matrix_actor().template block<3, 2>(frame, 0, 0); + + matrix_actor().template set_block(free_to_bound_jacobian, + bound_pos_to_free_pos_derivative, + e_free_pos0, e_bound_loc0); } template - DETRAY_HOST_DEVICE inline matrix_type<2, 3> - free_pos_to_bound_pos_derivative(const transform3_t &trf3, - const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( + free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); const auto frameT = matrix_actor().transpose(frame); // Get d(loc0, loc1)/d(x,y,z) - return matrix_actor().template block<2, 3>(frameT, 0, 0); + const auto free_pos_to_bound_pos_derivative = + matrix_actor().template block<2, 3>(frameT, 0, 0); + + matrix_actor().template set_block(bound_to_free_jacobian, + free_pos_to_bound_pos_derivative, + e_bound_loc0, e_free_pos0); + } + + template + DETRAY_HOST_DEVICE inline void set_bound_angle_to_free_pos_derivative( + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { + // Do nothing } }; // struct cylindrical2 diff --git a/core/include/detray/coordinates/line2.hpp b/core/include/detray/coordinates/line2.hpp index ca22ad2e8..53e54798f 100644 --- a/core/include/detray/coordinates/line2.hpp +++ b/core/include/detray/coordinates/line2.hpp @@ -43,6 +43,9 @@ struct line2 : public coordinate_base { using free_vector = typename base_type::free_vector; // Track Helper using track_helper = typename base_type::track_helper; + // Matrix types + using free_to_bound_matrix = typename base_type::free_to_bound_matrix; + using bound_to_free_matrix = typename base_type::bound_to_free_matrix; /// @} @@ -122,6 +125,96 @@ struct line2 : public coordinate_base { return rot; } + + template + DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( + bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { + + const auto frame = reference_frame(trf3, mask, pos, dir); + + // Get d(x,y,z)/d(loc0, loc1) + const auto bound_pos_to_free_pos_derivative = + matrix_actor().template block<3, 2>(frame, 0, 0); + + matrix_actor().template set_block(free_to_bound_jacobian, + bound_pos_to_free_pos_derivative, + e_free_pos0, e_bound_loc0); + } + + template + DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( + free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { + + const auto frame = reference_frame(trf3, mask, pos, dir); + const auto frameT = matrix_actor().transpose(frame); + + // Get d(loc0, loc1)/d(x,y,z) + const auto free_pos_to_bound_pos_derivative = + matrix_actor().template block<2, 3>(frameT, 0, 0); + + matrix_actor().template set_block(bound_to_free_jacobian, + free_pos_to_bound_pos_derivative, + e_bound_loc0, e_free_pos0); + } + + template + DETRAY_HOST_DEVICE inline void set_bound_angle_to_free_pos_derivative( + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { + + // local2 + const auto local2 = this->global_to_local(trf3, pos, dir); + + // Reference frame + const auto frame = reference_frame(trf3, mask, pos, dir); + + // new x_axis + const auto new_xaxis = matrix_actor().template block<3, 1>(frame, 0, 0); + + // new y_axis + const auto new_yaxis = matrix_actor().template block<3, 1>(frame, 0, 1); + + // new z_axis + const auto new_zaxis = matrix_actor().template block<3, 1>(frame, 0, 2); + + // the projection of direction onto ref frame normal + scalar_type ipdn = 1. / vector::dot(dir, new_zaxis); + + // d(n_x,n_y,n_z)/dPhi + const auto dNdPhi = matrix_actor().template block<3, 1>( + bound_to_free_jacobian, e_free_dir0, e_bound_phi); + + // Get new_yaxis X d(n_x,n_y,n_z)/dPhi + auto y_cross_dNdPhi = vector::cross(new_yaxis, dNdPhi); + + // d(n_x,n_y,n_z)/dTheta + const auto dNdTheta = matrix_actor().template block<3, 1>( + bound_to_free_jacobian, e_free_dir0, e_bound_theta); + + // build the cross product of d(D)/d(eBoundPhi) components with y axis + auto y_cross_dNdTheta = vector::cross(new_yaxis, dNdTheta); + + // and correct for the x axis components + auto phi_to_free_pos_derivative = + y_cross_dNdPhi - new_xaxis * vector::dot(new_xaxis, y_cross_dNdPhi); + phi_to_free_pos_derivative *= ipdn * local2[0]; + + auto theta_to_free_pos_derivative = + y_cross_dNdTheta - + new_xaxis * vector::dot(new_xaxis, y_cross_dNdTheta); + theta_to_free_pos_derivative *= ipdn * local2[0]; + + // Set the jacobian components + matrix_actor().set_block<3, 1>(bound_to_free_jacobian, + phi_to_free_pos_derivative, e_free_pos0, + e_bound_phi); + + matrix_actor().set_block<3, 1>(bound_to_free_jacobian, + theta_to_free_pos_derivative, + e_free_pos0, e_bound_theta); + } }; } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index 02455f66d..95944df19 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -46,6 +46,9 @@ struct polar2 : public coordinate_base { using free_vector = typename base_type::free_vector; // Track Helper using track_helper = typename base_type::track_helper; + // Matrix types + using free_to_bound_matrix = typename base_type::free_to_bound_matrix; + using bound_to_free_matrix = typename base_type::bound_to_free_matrix; /** This method transform from a point from 2D cartesian frame to a 2D * polar point */ @@ -90,10 +93,9 @@ struct polar2 : public coordinate_base { } template - DETRAY_HOST_DEVICE inline matrix_type<3, 2> - bound_pos_to_free_pos_derivative(const transform3_t &trf3, - const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( + bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { matrix_type<3, 2> bound_pos_to_free_pos_derivative = matrix_actor().template zero<3, 2>(); @@ -108,9 +110,9 @@ struct polar2 : public coordinate_base { // reference matrix const auto frame = reference_frame(trf3, pos, dir); - // dxdL = dx/d(u,v,w) + // dxdu = d(x,y,z)/du const auto dxdL = matrix_actor().template block<3, 1>(frame, 0, 0); - // dydL = dy/d(u,v,w) + // dxdv = d(x,y,z)/dv const auto dydL = matrix_actor().template block<3, 1>(frame, 0, 1); const auto col0 = dxdL * lcos_phi + dydL * lsin_phi; @@ -121,14 +123,15 @@ struct polar2 : public coordinate_base { matrix_actor().set_block<3, 1>(bound_pos_to_free_pos_derivative, col1, e_free_pos0, e_bound_loc1); - return bound_pos_to_free_pos_derivative; + matrix_actor().template set_block(free_to_bound_jacobian, + bound_pos_to_free_pos_derivative, + e_free_pos0, e_bound_loc0); } template - DETRAY_HOST_DEVICE inline matrix_type<2, 3> - free_pos_to_bound_pos_derivative(const transform3_t &trf3, - const mask_t &mask, const point3 &pos, - const vector3 &dir) const { + DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( + free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { matrix_type<2, 3> free_pos_to_bound_pos_derivative = matrix_actor().template zero<2, 3>(); @@ -146,9 +149,9 @@ struct polar2 : public coordinate_base { const auto frameT = matrix_actor().transpose(frame); // dudG = du/d(x,y,z) - const auto dudG = matrix_actor().template block<3, 1>(frameT, 0, 0); + const auto dudG = matrix_actor().template block<1, 3>(frameT, 0, 0); // dvdG = dv/d(x,y,z) - const auto dvdG = matrix_actor().template block<3, 1>(frameT, 0, 1); + const auto dvdG = matrix_actor().template block<1, 3>(frameT, 0, 1); const auto row0 = dudG * lcos_phi + dvdG * lsin_phi; const auto row1 = (dvdG * lcos_phi - dudG * lsin_phi) * 1. / lrad; @@ -158,7 +161,16 @@ struct polar2 : public coordinate_base { matrix_actor().set_block<1, 3>(free_pos_to_bound_pos_derivative, row1, e_bound_loc1, e_free_pos0); - return free_pos_to_bound_pos_derivative; + matrix_actor().template set_block(bound_to_free_jacobian, + free_pos_to_bound_pos_derivative, + e_bound_loc0, e_free_pos0); + } + + template + DETRAY_HOST_DEVICE inline void set_bound_angle_to_free_pos_derivative( + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, + const mask_t &mask, const point3 &pos, const vector3 &dir) const { + // Do nothing } }; diff --git a/core/include/detray/intersection/detail/trajectories.hpp b/core/include/detray/intersection/detail/trajectories.hpp index e8da94b27..419bf40dd 100644 --- a/core/include/detray/intersection/detail/trajectories.hpp +++ b/core/include/detray/intersection/detail/trajectories.hpp @@ -221,13 +221,18 @@ class helix : public free_track_parameters { const matrix_type<3, 3> I33 = matrix_actor().template identity<3, 3>(); const matrix_type<3, 3> Z33 = matrix_actor().template zero<3, 3>(); + // Notations + // r = position + // t = direction + // l = qoverp + // Get drdr auto drdr = I33; - matrix_actor().set_block(ret, drdr, 0, 0); + matrix_actor().set_block(ret, drdr, e_free_pos0, e_free_pos0); // Get dtdr auto dtdr = Z33; - matrix_actor().set_block(ret, dtdr, 4, 0); + matrix_actor().set_block(ret, dtdr, e_free_dir0, e_free_pos0); // Get drdt auto drdt = Z33; @@ -242,7 +247,7 @@ class helix : public free_track_parameters { drdt = drdt + (std::cos(_K * s) - 1) / _K * column_wise_op().cross(I33, _h0); - matrix_actor().set_block(ret, drdt, 0, 4); + matrix_actor().set_block(ret, drdt, e_free_pos0, e_free_dir0); // Get dtdt auto dtdt = Z33; @@ -252,24 +257,24 @@ class helix : public free_track_parameters { column_wise_op().multiply(matrix_actor().transpose(H0), _h0); dtdt = dtdt - std::sin(_K * s) * column_wise_op().cross(I33, _h0); - matrix_actor().set_block(ret, dtdt, 4, 4); + matrix_actor().set_block(ret, dtdt, e_free_dir0, e_free_dir0); // Get drdl vector3 drdl = 1 / free_track_parameters_type::qop() * (s * this->dir(s) + free_track_parameters_type::pos() - this->pos(s)); - matrix_actor().set_block(ret, drdl, 0, 7); + matrix_actor().set_block(ret, drdl, e_free_pos0, e_free_qoverp); // Get dtdl vector3 dtdl = _alpha * _K * s / free_track_parameters_type::qop() * _n0; - matrix_actor().set_block(ret, dtdl, 4, 7); + matrix_actor().set_block(ret, dtdl, e_free_dir0, e_free_qoverp); // 3x3 and 7x7 element is 1 (Maybe?) - matrix_actor().element(ret, 3, 3) = 1; - matrix_actor().element(ret, 7, 7) = 1; + matrix_actor().element(ret, e_free_time, e_free_time) = 1; + matrix_actor().element(ret, e_free_qoverp, e_free_qoverp) = 1; return ret; } From c4d5fd1544f6a4e5792d1de9fb3d06db37ead2f4 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 29 Aug 2022 17:07:37 -0700 Subject: [PATCH 04/63] backup --- .vscode/settings.json | 37 +++++- core/CMakeLists.txt | 1 + .../detray/intersection/intersection.hpp | 3 + .../intersection/intersection_kernel.hpp | 4 +- .../propagator/detail/covariance_kernel.hpp | 110 ++++++++++++++++++ 5 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 core/include/detray/propagator/detail/covariance_kernel.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json index 0ee629843..7f280ff4a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,41 @@ { "files.associations": { "*.sycl": "cpp", - "*.ipp": "cpp" + "*.ipp": "cpp", + "array": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "memory": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "type_traits": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "utility": "cpp" } } \ No newline at end of file diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 19650124f..f2278b102 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -78,6 +78,7 @@ detray_add_library( detray_core core "include/detray/propagator/base_actor.hpp" "include/detray/propagator/base_stepper.hpp" "include/detray/propagator/constrained_step.hpp" + "include/detray/propagator/detail/covariance_kernel.hpp" "include/detray/propagator/detail/covariance_engine.hpp" "include/detray/propagator/detail/jacobian_engine.hpp" "include/detray/propagator/line_stepper.hpp" diff --git a/core/include/detray/intersection/intersection.hpp b/core/include/detray/intersection/intersection.hpp index 2d36f8acc..0bd3c3bb7 100644 --- a/core/include/detray/intersection/intersection.hpp +++ b/core/include/detray/intersection/intersection.hpp @@ -59,6 +59,9 @@ struct line_plane_intersection { intersection::status status = intersection::status::e_missed; intersection::direction direction = intersection::direction::e_undefined; + // Mask index + dindex mask_index = dindex_invalid; + // Primitive this intersection belongs to // TODO: rename the variable properly dindex index = dindex_invalid; diff --git a/core/include/detray/intersection/intersection_kernel.hpp b/core/include/detray/intersection/intersection_kernel.hpp index 5152be72b..2e4cb2365 100644 --- a/core/include/detray/intersection/intersection_kernel.hpp +++ b/core/include/detray/intersection/intersection_kernel.hpp @@ -51,7 +51,8 @@ struct intersection_initialize { const auto &ctf = contextual_transforms[surface.transform()]; // Run over the masks belonged to the surface - for (const auto &mask : range(mask_group, mask_range)) { + for (const auto [mask_index, mask] : + enumerate(mask_group, mask_range)) { auto sfi = std::move(mask.intersector()( traj, mask, ctf, mask_tolerance, traj.overstep_tolerance())); @@ -59,6 +60,7 @@ struct intersection_initialize { for (auto &is : sfi) { if (is.status == intersection::status::e_inside && is.path >= traj.overstep_tolerance()) { + is.mask_index = mask_index; is.index = surface.volume(); is_container.push_back(is); count++; diff --git a/core/include/detray/propagator/detail/covariance_kernel.hpp b/core/include/detray/propagator/detail/covariance_kernel.hpp new file mode 100644 index 000000000..c4049a9ef --- /dev/null +++ b/core/include/detray/propagator/detail/covariance_kernel.hpp @@ -0,0 +1,110 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Detray include(s) +#include "detray/definitions/qualifiers.hpp" + +namespace detray { + +namespace detail { + +template +struct bound_to_bound_covariance_update { + + /// @name Type definitions for the struct + /// @{ + + // Matrix actor + using matrix_actor = typename transform3_t::matrix_actor; + // 2D matrix type + template + using matrix_type = typename matrix_actor::template matrix_type; + // Shorthand vector/matrix types related to bound track parameters. + using bound_vector = matrix_type; + using bound_matrix = matrix_type; + // Mapping from bound track parameters. + using bound_to_free_matrix = matrix_type; + // Shorthand vector/matrix types related to free track parameters. + using free_vector = matrix_type; + using free_matrix = matrix_type; + // Mapping from free track parameters. + using free_to_bound_matrix = matrix_type; + using free_to_path_matrix = matrix_type<1, e_free_size>; + // Track helper + using track_helper = detail::track_helper; + + /// @} + + using output_type = bool; + + template + DETRAY_HOST_DEVICE inline output_type operator()( + const mask_group_t& mask_group, propagator_state_t& propagation) const { + + /* + auto& navigation = propagation._navigation; + auto& stepping = propagation._stepping; + + const auto& is = navigation.current(); + + // mask and transform index + const auto& mask_index = is->mask_index; + const auto& surface_index = is->index; + + const auto& mask_range = surface.mask_range(); + const auto& ctf = contextual_transforms[surface.transform()]; + + // Get the free vector + const auto& free_vector = stepping().vector(); + + // Run over the masks belonged to the surface + for (const auto& mask : range(mask_group, mask_range)) { + + auto local_coordinate = mask.local_type(); + + local_coordinate. + } + + return true; + */ + } + + /** Function to get the full jacobian for surface-to-surface propagation + * + * @param trf3 is the transform matrix of the destination surface + * @param mask is the mask of the destination surface + * @param free_vec is the input free vector at the destination surface + * @param bound_to_free_jacobian is the coordinate transform jacobian + * at departure surface. + * @param free_transport_jacobian is the transport jacobian + * @param free_to_path_derivative is the derivative of free parameter w.r.t + * path + * @returns bound to bound jacobian + */ + template + DETRAY_HOST_DEVICE inline bound_matrix bound_to_bound_jacobian( + const transform3_t& trf3, const mask_t& mask, + const free_vector& free_vec, + const bound_to_free_matrix& bound_to_free_jacobian, + const free_matrix& free_transport_jacobian, + const free_matrix& path_correction) { + + using local_type = typename mask_t::local_type; + + const auto free_to_bound_matrix free_to_bound_jacobian = + local_type().free_to_bound_jacobian(trf3, mask, free_vec); + + return free_to_bound_jacobian * free_transport_jacobian * + bound_to_free_jacobian; + } +}; + +} // namespace detail + +} // namespace detray \ No newline at end of file From 48c85c3fbf6db5440ed9685afda2d6277e1c6084 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 30 Aug 2022 11:42:15 -0700 Subject: [PATCH 05/63] Backup --- .../detray/coordinates/coordinate_base.hpp | 16 +++++++++++++++- core/include/detray/propagator/rk_stepper.hpp | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 8525f5068..edf85e02e 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -239,12 +239,26 @@ struct coordinate_base { template DETRAY_HOST_DEVICE inline free_matrix path_correction( const stepper_state_t& stepping, const transform3_t& trf3, - const mask_t& mask, const free_vector& free_vec) { + const mask_t& mask) { + + using field = typename stepper_state_t::magnetic_field; + using helix = detail::helix; free_matrix path_correction = matrix_actor().template zero(); + sd.b_first = + _magnetic_field.get_field(stepping().pos(), context_type{}); + + /* + // Direction at the surface + const vector3& t = stepping._step_data.k4; + + // B field at the surface + field B(stepping._step_data.b_last); + */ // Use Helix + detail::helix helix hlx(trf3, &B); /* // Direction at the surface diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index 7295921ce..04404032f 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -12,6 +12,7 @@ #include "detray/definitions/units.hpp" #include "detray/propagator/base_stepper.hpp" #include "detray/propagator/detail/covariance_engine.hpp" +#include "detray/propagator/detail/covariance_kernel.hpp" #include "detray/propagator/navigation_policies.hpp" #include "detray/tracks/tracks.hpp" #include "detray/utils/column_wise_operator.hpp" @@ -37,6 +38,7 @@ class rk_stepper final using point3 = typename transform3_type::point3; using vector2 = typename transform3_type::point2; using vector3 = typename transform3_type::vector3; + using magnetic_field = magnetic_field_t; using context_type = typename magnetic_field_t::context_type; using matrix_operator = typename base_type::matrix_operator; using covariance_engine = typename base_type::covariance_engine; From 43180dd979c2373053eb52016c4cddc979a7666e Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 30 Aug 2022 14:36:16 -0700 Subject: [PATCH 06/63] backup --- .../detray/propagator/line_stepper.hpp | 3 +++ core/include/detray/propagator/propagator.hpp | 23 ++++++++++++++++--- core/include/detray/propagator/rk_stepper.hpp | 18 +++++++++------ core/include/detray/propagator/rk_stepper.ipp | 7 +++--- .../cuda/benchmark_propagator_cuda.cpp | 4 ++-- .../common/check_geometry_navigation.inl | 4 ++-- .../tests/common/test_telescope_detector.inl | 22 ++++++++++-------- .../tests/common/tools_guided_navigator.inl | 5 ++-- .../include/tests/common/tools_propagator.inl | 6 ++--- .../include/tests/common/tools_stepper.inl | 18 ++++++++------- 10 files changed, 70 insertions(+), 40 deletions(-) diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index ccd6010dc..1b6985550 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -33,6 +33,9 @@ class line_stepper final using policy_type = policy_t; struct state : public base_type::state { + + using field_type = int; + DETRAY_HOST_DEVICE state(const track_t &t) : base_type::state(t) {} diff --git a/core/include/detray/propagator/propagator.hpp b/core/include/detray/propagator/propagator.hpp index 4b2ba1610..a072b3259 100644 --- a/core/include/detray/propagator/propagator.hpp +++ b/core/include/detray/propagator/propagator.hpp @@ -11,6 +11,9 @@ #include "detray/intersection/intersection.hpp" #include "detray/propagator/track.hpp" +// System include(s) +#include + namespace detray { /// Templated propagator class, using a stepper and a navigator object in @@ -45,7 +48,9 @@ struct propagator { /// also keeps references to the actor states. struct state { - using context_type = typename navigator_t::detector_type::context; + using detector_type = typename navigator_t::detector_type; + using context_type = typename detector_type::context; + using field_type = typename stepper_t::state::field_type; /// Construct the propagation state. /// @@ -54,18 +59,30 @@ struct propagator { /// @param candidates buffer for intersections in the navigator template DETRAY_HOST_DEVICE state( - const track_t &t_in, const typename navigator_t::detector_type &det, + const track_t &t_in, const detector_type &det, typename actor_chain_t::state actor_states = {}, vector_type &&candidates = {}) : _stepping(t_in), _navigation(det, std::move(candidates)), _actor_states(actor_states) {} + template < + typename track_t, + std::enable_if_t, bool> = true> + DETRAY_HOST_DEVICE state( + const track_t &t_in, const field_type &magnetic_field, + const detector_type &det, + typename actor_chain_t::state actor_states = {}, + vector_type &&candidates = {}) + : _stepping(t_in, magnetic_field), + _navigation(det, std::move(candidates)), + _actor_states(actor_states) {} + /// Construct the propagation state with bound parameter DETRAY_HOST_DEVICE state( const bound_track_parameters ¶m, const typename stepper_t::transform3 &trf3, - const typename navigator_t::detector_type &det, + const detector_type &det, typename actor_chain_t::state actor_states = {}, vector_type &&candidates = {}) : _stepping(param, trf3), diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index eaa4b4f7a..6034f6305 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -41,16 +41,21 @@ class rk_stepper final : public base_stepper { using transform3 = typename covariance_engine::transform3; DETRAY_HOST_DEVICE - rk_stepper(const magnetic_field_t mag_field) : _magnetic_field(mag_field) {} + rk_stepper() {} struct state : public base_type::state { + + using field_type = magnetic_field_t; + DETRAY_HOST_DEVICE - state(const track_t& t) : base_type::state(t) {} + state(const track_t& t, const magnetic_field_t mag_field) + : base_type::state(t), _magnetic_field(mag_field) {} DETRAY_HOST_DEVICE state(const bound_track_parameters& bound_params, - const transform3& trf3) - : base_type::state(bound_params, trf3) {} + const transform3& trf3, const field_type mag_field) + : base_type::state(bound_params, trf3), + _magnetic_field(mag_field) {} /// error tolerance scalar _tolerance = 1e-4; @@ -68,6 +73,8 @@ class rk_stepper final : public base_stepper { array_t k_qop; } _step_data; + const magnetic_field_t _magnetic_field; + // Set the local error tolerenace DETRAY_HOST_DEVICE inline void set_tolerance(scalar tol) { _tolerance = tol; }; @@ -104,9 +111,6 @@ class rk_stepper final : public base_stepper { template DETRAY_HOST_DEVICE bound_track_parameters bound_state(propagation_state_t& propagation, const transform3& trf); - - private: - const magnetic_field_t _magnetic_field; }; } // namespace detray diff --git a/core/include/detray/propagator/rk_stepper.ipp b/core/include/detray/propagator/rk_stepper.ipp index 7ed05e7d8..1743791d6 100644 --- a/core/include/detray/propagator/rk_stepper.ipp +++ b/core/include/detray/propagator/rk_stepper.ipp @@ -175,6 +175,7 @@ bool detray::rk_stepper::step(propagation_state_t& propagation) { // Get stepper and navigator states state& stepping = propagation._stepping; + auto& magnetic_field = stepping._magnetic_field; auto& navigation = propagation._navigation; auto& sd = stepping._step_data; @@ -182,7 +183,7 @@ bool detray::rk_stepper bool { @@ -194,7 +195,7 @@ bool detray::rk_stepper; // dummy propagator state template struct prop_state { + stepping_t _stepping; navigation_t _navigation; + using field_type = typename stepping_t::field_type; template - prop_state(const track_t &t_in, + prop_state(const track_t &t_in, const field_type &field, const typename navigation_t::detector_type &det) - : _stepping(t_in), _navigation(det) {} + : _stepping(t_in, field), _navigation(det) {} }; } // anonymous namespace @@ -67,9 +69,9 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { b_field_t b_field_x{B_x}; // steppers - rk_stepper_t rk_stepper_z{b_field_z}; - rk_stepper_t rk_stepper_x{b_field_x}; - ln_stepper_t ln_stepper{}; + rk_stepper_t rk_stepper_z; + rk_stepper_t rk_stepper_x; + ln_stepper_t ln_stepper; // // telescope along z @@ -128,11 +130,11 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { // propagation states prop_state propgation_z1( - test_track_z1, z_tel_det1); + test_track_z1, b_field_z, z_tel_det1); prop_state propgation_z2( - test_track_z2, z_tel_det2); - prop_state propgation_x(test_track_x, - x_tel_det); + test_track_z2, b_field_z, z_tel_det2); + prop_state propgation_x( + test_track_x, b_field_x, x_tel_det); stepping_state_t &stepping_z1 = propgation_z1._stepping; stepping_state_t &stepping_z2 = propgation_z2._stepping; @@ -206,7 +208,7 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { navigator tel_navigator; prop_state tel_propagation( - pilot_track, tel_detector); + pilot_track, b_field_z, tel_detector); navigation_state_t &tel_navigation = tel_propagation._navigation; // run propagation diff --git a/tests/common/include/tests/common/tools_guided_navigator.inl b/tests/common/include/tests/common/tools_guided_navigator.inl index 2f7cbb76f..13dcc6fb8 100644 --- a/tests/common/include/tests/common/tools_guided_navigator.inl +++ b/tests/common/include/tests/common/tools_guided_navigator.inl @@ -62,8 +62,9 @@ TEST(ALGEBRA_PLUGIN, guided_navigator) { pathlimit_aborter::state pathlimit{200. * unit_constants::cm}; // Propagator - propagator_t p(runge_kutta_stepper{b_field}, guided_navigator{}); - propagator_t::state guided_state(track, telescope_det, std::tie(pathlimit)); + propagator_t p(runge_kutta_stepper{}, guided_navigator{}); + propagator_t::state guided_state(track, b_field, telescope_det, + std::tie(pathlimit)); // Propagate p.propagate(guided_state); diff --git a/tests/common/include/tests/common/tools_propagator.inl b/tests/common/include/tests/common/tools_propagator.inl index b513c35d4..d35e3f485 100644 --- a/tests/common/include/tests/common/tools_propagator.inl +++ b/tests/common/include/tests/common/tools_propagator.inl @@ -141,7 +141,7 @@ TEST_P(PropagatorWithRkStepper, propagator_rk_stepper) { const b_field_t b_field(B); // Propagator is built from the stepper and navigator - propagator_t p(stepper_t{b_field}, navigator_t{}); + propagator_t p(stepper_t{}, navigator_t{}); // Iterate through uniformly distributed momentum directions for (auto track : @@ -166,8 +166,8 @@ TEST_P(PropagatorWithRkStepper, propagator_rk_stepper) { helix_insp_state, lim_print_insp_state, pathlimit_aborter_state); // Init propagator states - propagator_t::state state(track, d, actor_states); - propagator_t::state lim_state(lim_track, d, lim_actor_states); + propagator_t::state state(track, b_field, d, actor_states); + propagator_t::state lim_state(lim_track, b_field, d, lim_actor_states); // Set step constraints state._stepping.template set_constraint( diff --git a/tests/common/include/tests/common/tools_stepper.inl b/tests/common/include/tests/common/tools_stepper.inl index 9ce96d3a0..abf1841cf 100644 --- a/tests/common/include/tests/common/tools_stepper.inl +++ b/tests/common/include/tests/common/tools_stepper.inl @@ -149,8 +149,8 @@ TEST(ALGEBRA_PLUGIN, rk_stepper) { mag_field_t mag_field(B); // RK stepper - rk_stepper_t rk_stepper(mag_field); - crk_stepper_t crk_stepper(mag_field); + rk_stepper_t rk_stepper; + crk_stepper_t crk_stepper; // Set origin position of tracks const point3 ori{0., 0., 0.}; @@ -167,9 +167,9 @@ TEST(ALGEBRA_PLUGIN, rk_stepper) { // RK Stepping into forward direction prop_state propagation{ - rk_stepper_t::state{track}, nav_state{}}; + rk_stepper_t::state{track, mag_field}, nav_state{}}; prop_state c_propagation{ - crk_stepper_t::state{c_track}, nav_state{}}; + crk_stepper_t::state{c_track, mag_field}, nav_state{}}; rk_stepper_t::state &rk_state = propagation._stepping; crk_stepper_t::state &crk_state = c_propagation._stepping; @@ -266,11 +266,15 @@ TEST(ALGEBRA_PLUGIN, covariance_transport) { getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + // B field + vector3 B{0, 0, 1. * unit_constants::T}; + mag_field_t mag_field(B); + // bound track parameter const bound_track_parameters bound_param0(0, bound_vector, bound_cov); prop_state propagation{ - crk_stepper_t::state(bound_param0, trf), nav_state{}}; + crk_stepper_t::state(bound_param0, trf, mag_field), nav_state{}}; crk_stepper_t::state &crk_state = propagation._stepping; nav_state &n_state = propagation._navigation; @@ -278,9 +282,7 @@ TEST(ALGEBRA_PLUGIN, covariance_transport) { crk_state._tolerance = 1e-8; // RK stepper and its state - vector3 B{0, 0, 1. * unit_constants::T}; - mag_field_t mag_field(B); - crk_stepper_t crk_stepper(mag_field); + crk_stepper_t crk_stepper; ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); From 86db88fe7c226e3bb8988ec2f39e3c9ecfddb950 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 30 Aug 2022 15:43:37 -0700 Subject: [PATCH 07/63] Backup --- .../detray/propagator/base_stepper.hpp | 2 + .../detray/propagator/line_stepper.hpp | 2 + .../cuda/benchmark_propagator_cuda.cpp | 4 +- .../cuda/benchmark_propagator_cuda_kernel.cu | 7 ++-- .../tests/common/test_telescope_detector.inl | 8 +++- .../tools/create_telescope_detector.hpp | 42 +++++++++---------- tests/unit_tests/cuda/propagator_cuda.cpp | 5 ++- .../unit_tests/cuda/propagator_cuda_kernel.cu | 4 +- tests/unit_tests/cuda/rk_stepper_cuda.cpp | 4 +- .../unit_tests/cuda/rk_stepper_cuda_kernel.cu | 4 +- 10 files changed, 46 insertions(+), 36 deletions(-) diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index 5d70d37f5..cfbca1b7f 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -39,6 +39,8 @@ class base_stepper { */ struct state { + state(){}; + /// Sets track parameters. DETRAY_HOST_DEVICE state(const track_t &t) : _track(t) {} diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index 1b6985550..be1d0dfa2 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -36,6 +36,8 @@ class line_stepper final using field_type = int; + state(){}; + DETRAY_HOST_DEVICE state(const track_t &t) : base_type::state(t) {} diff --git a/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp b/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp index eba6507a1..a00023437 100644 --- a/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp +++ b/tests/benchmarks/cuda/benchmark_propagator_cuda.cpp @@ -59,7 +59,7 @@ static void BM_PROPAGATOR_CPU(benchmark::State &state) { navigator_host_type n; // Create propagator - propagator_host_type p(std::move(s), B_field, std::move(n)); + propagator_host_type p(std::move(s), std::move(n)); for (auto _ : state) { @@ -75,7 +75,7 @@ static void BM_PROPAGATOR_CPU(benchmark::State &state) { for (auto &track : tracks) { // Create the propagator state - propagator_host_type::state p_state(track, det); + propagator_host_type::state p_state(track, B_field, det); // Run propagation p.propagate(p_state); diff --git a/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu b/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu index 2a6f48e6a..375b0b42b 100644 --- a/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu +++ b/tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.cu @@ -30,7 +30,7 @@ __global__ void propagator_benchmark_kernel( field_type B_field(B); // Create RK stepper - rk_stepper_type s(B_field); + rk_stepper_type s; // Create navigator navigator_device_type n; @@ -39,8 +39,9 @@ __global__ void propagator_benchmark_kernel( propagator_device_type p(std::move(s), std::move(n)); // Create the propagator state - propagator_device_type::state p_state( - tracks.at(gid), det, actor_chain<>::state{}, candidates.at(gid)); + propagator_device_type::state p_state(tracks.at(gid), B_field, det, + actor_chain<>::state{}, + candidates.at(gid)); // Run propagation p.propagate(p_state); diff --git a/tests/common/include/tests/common/test_telescope_detector.inl b/tests/common/include/tests/common/test_telescope_detector.inl index 483718cad..42782810d 100644 --- a/tests/common/include/tests/common/test_telescope_detector.inl +++ b/tests/common/include/tests/common/test_telescope_detector.inl @@ -105,9 +105,10 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { point3 pos{0., 0., 0.}; vector3 mom{1., 0., 0.}; free_track_parameters pilot_track(pos, 0, mom, -1); + typename ln_stepper_t::state ln_stepping(pilot_track); const auto x_tel_det = create_telescope_detector( - host_mr, n_surfaces, tel_length, pilot_track, ln_stepper); + host_mr, n_surfaces, tel_length, ln_stepper, ln_stepping); // // test propagation in all telescope detector instances @@ -201,8 +202,11 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { pilot_track = free_track_parameters(pos, 0, mom, -1); pilot_track.set_overstep_tolerance(-10 * unit_constants::um); + typename rk_stepper_t::state rk_stepping_z(pilot_track, b_field_z); + typename rk_stepper_t::state rk_stepping_x(pilot_track, b_field_x); + const auto tel_detector = create_telescope_detector( - host_mr, n_surfaces, tel_length, pilot_track, rk_stepper_z); + host_mr, n_surfaces, tel_length, rk_stepper_z, rk_stepping_z); // make at least sure it is navigatable navigator tel_navigator; diff --git a/tests/common/include/tests/common/tools/create_telescope_detector.hpp b/tests/common/include/tests/common/tools/create_telescope_detector.hpp index a7e3832b9..ccc836efe 100644 --- a/tests/common/include/tests/common/tools/create_telescope_detector.hpp +++ b/tests/common/include/tests/common/tools/create_telescope_detector.hpp @@ -50,9 +50,10 @@ struct module_placement { /// @param n_surfaces the number of plane surfaces /// /// @return a vector of the module positions along the trajectory -template +template inline std::vector module_positions( - track_t &track, stepper_t &stepper, std::vector &steps) { + stepper_t stepper, typename stepper_t::state &stepping, + std::vector &steps) { // dummy navigation struct struct navigation_state { scalar operator()() const { return _step_size; } @@ -76,8 +77,7 @@ inline std::vector module_positions( m_positions.reserve(steps.size()); // Find exact position by walking along track - prop_state propagation{typename stepper_t::state{track}, - navigation_state{}}; + prop_state propagation{stepping, navigation_state{}}; // Calculate step size from module positions. The modules will only be // placed at the given position if the b-field allows for it. Otherwise, by @@ -108,11 +108,12 @@ inline std::vector module_positions( /// @param transforms container to add new transform to /// @param cfg config struct for module creation template -inline void create_telescope(context_t &ctx, track_t &track, stepper_t &stepper, +inline void create_telescope(context_t &ctx, stepper_t &stepper, + typename stepper_t::state &stepping, volume_type &volume, surface_container_t &surfaces, mask_container_t &masks, material_container_t &materials, @@ -129,7 +130,7 @@ inline void create_telescope(context_t &ctx, track_t &track, stepper_t &stepper, // Create the module centers const std::vector m_placements = - module_positions(track, stepper, cfg.pos); + module_positions(stepper, stepping, cfg.pos); // Create geometry data for (const auto &m_placement : m_placements) { @@ -193,18 +194,18 @@ inline void create_telescope(context_t &ctx, track_t &track, stepper_t &stepper, /// @param n_surfaces the number of surfaces that are placed in the geometry /// @param tel_length the total length of the steps by the stepper template , + typename stepper_t = line_stepper, template class array_t = darray, template class tuple_t = dtuple, template class vector_t = dvector, template class jagged_vector_t = djagged_vector> -auto create_telescope_detector( - vecmem::memory_resource &resource, dindex n_surfaces = 10, - scalar tel_length = 500. * unit_constants::mm, - track_t track = {{0., 0., 0.}, 0., {0., 0., 1.}, -1.}, - stepper_t stepper = {}, scalar half_x = 20. * unit_constants::mm, - scalar half_y = 20. * unit_constants::mm) { +auto create_telescope_detector(vecmem::memory_resource &resource, + dindex n_surfaces = 10, + scalar tel_length = 500. * unit_constants::mm, + stepper_t stepper = {}, + typename stepper_t::state stepping = {}, + scalar half_x = 20. * unit_constants::mm, + scalar half_y = 20. * unit_constants::mm) { // Generate equidistant positions std::vector positions = {}; scalar pos = 0.; @@ -216,7 +217,7 @@ auto create_telescope_detector( // Build the geometry return create_telescope_detector( - resource, positions, track, stepper, half_x, half_y); + resource, positions, stepper, stepping, half_x, half_y); } /// Builds a detray geometry that contains only one volume with plane surfaces, @@ -241,15 +242,14 @@ auto create_telescope_detector( /// /// @returns a complete detector object template , + typename stepper_t = line_stepper, template class array_t = darray, template class tuple_t = dtuple, template class vector_t = dvector, template class jagged_vector_t = djagged_vector> auto create_telescope_detector( vecmem::memory_resource &resource, std::vector pos = {}, - track_t track = {{0, 0, 0}, 0, {0, 0, 1}, -1}, stepper_t stepper = {}, + stepper_t stepper = {}, typename stepper_t::state stepping = {}, scalar half_x = 20. * unit_constants::mm, scalar half_y = 20. * unit_constants::mm, const material mat = silicon_tml(), @@ -286,11 +286,11 @@ auto create_telescope_detector( if constexpr (unbounded_planes) { create_telescope( - ctx, track, stepper, vol, surfaces, masks, materials, transforms, + ctx, stepper, stepping, vol, surfaces, masks, materials, transforms, pl_config); } else { create_telescope( - ctx, track, stepper, vol, surfaces, masks, materials, transforms, + ctx, stepper, stepping, vol, surfaces, masks, materials, transforms, pl_config); } diff --git a/tests/unit_tests/cuda/propagator_cuda.cpp b/tests/unit_tests/cuda/propagator_cuda.cpp index 1e3b4aadd..fcfc37601 100644 --- a/tests/unit_tests/cuda/propagator_cuda.cpp +++ b/tests/unit_tests/cuda/propagator_cuda.cpp @@ -57,7 +57,7 @@ TEST_P(CudaPropagatorWithRkStepper, propagator) { field_type B_field(B); // Create RK stepper - rk_stepper_type s(B_field); + rk_stepper_type s; // Create navigator navigator_host_type n; // Create propagator @@ -75,7 +75,8 @@ TEST_P(CudaPropagatorWithRkStepper, propagator) { pathlimit_aborter::state pathlimit_state{path_limit}; propagator_host_type::state state( - tracks_host[i], det, thrust::tie(insp_state, pathlimit_state)); + tracks_host[i], B_field, det, + thrust::tie(insp_state, pathlimit_state)); state._stepping.template set_constraint( constrainted_step_size); diff --git a/tests/unit_tests/cuda/propagator_cuda_kernel.cu b/tests/unit_tests/cuda/propagator_cuda_kernel.cu index 24a1758b1..90519ce1d 100644 --- a/tests/unit_tests/cuda/propagator_cuda_kernel.cu +++ b/tests/unit_tests/cuda/propagator_cuda_kernel.cu @@ -36,7 +36,7 @@ __global__ void propagator_test_kernel( field_type B_field(B); // Create RK stepper - rk_stepper_type s(B_field); + rk_stepper_type s; // Create navigator navigator_device_type n; @@ -50,7 +50,7 @@ __global__ void propagator_test_kernel( pathlimit_aborter::state aborter_state{path_limit}; // Create the propagator state - propagator_device_type::state state(tracks[gid], det, + propagator_device_type::state state(tracks[gid], B_field, det, thrust::tie(insp_state, aborter_state), candidates.at(gid)); diff --git a/tests/unit_tests/cuda/rk_stepper_cuda.cpp b/tests/unit_tests/cuda/rk_stepper_cuda.cpp index ad43ddf41..be4d30751 100644 --- a/tests/unit_tests/cuda/rk_stepper_cuda.cpp +++ b/tests/unit_tests/cuda/rk_stepper_cuda.cpp @@ -59,7 +59,7 @@ TEST(rk_stepper_cuda, bound_state) { mag_field_t mag_field(B); prop_state propagation{ - crk_stepper_t::state(in_param, trf), nav_state{}}; + crk_stepper_t::state(in_param, trf, mag_field), nav_state{}}; crk_stepper_t::state &crk_state = propagation._stepping; nav_state &n_state = propagation._navigation; @@ -67,7 +67,7 @@ TEST(rk_stepper_cuda, bound_state) { crk_state.set_tolerance(rk_tolerance); // RK stepper and its state - crk_stepper_t crk_stepper(mag_field); + crk_stepper_t crk_stepper; // Path length per turn scalar S = 2. * std::fabs(1. / in_param.qop()) / getter::norm(B) * M_PI; diff --git a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu index ae0cffa41..138341c9d 100644 --- a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu +++ b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu @@ -21,7 +21,7 @@ __global__ void bound_state_test_kernel( mag_field_t mag_field(B); prop_state propagation{ - crk_stepper_t::state(in_param, trf), nav_state{}}; + crk_stepper_t::state(in_param, trf, mag_field), nav_state{}}; crk_stepper_t::state &crk_state = propagation._stepping; nav_state &n_state = propagation._navigation; @@ -29,7 +29,7 @@ __global__ void bound_state_test_kernel( crk_state.set_tolerance(rk_tolerance); // RK stepper and its state - crk_stepper_t crk_stepper(mag_field); + crk_stepper_t crk_stepper; // Path length per turn scalar S = 2. * std::fabs(1. / in_param.qop()) / getter::norm(B) * M_PI; From 3ed761f72d8f5041e52683a2f270fcc391e7592b Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 30 Aug 2022 16:01:28 -0700 Subject: [PATCH 08/63] Put field into the state --- core/include/detray/propagator/line_stepper.hpp | 1 + .../include/tests/common/test_telescope_detector.inl | 11 +++++++---- .../include/tests/common/tools_guided_navigator.inl | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index be1d0dfa2..d19c02488 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -31,6 +31,7 @@ class line_stepper final public: using base_type = base_stepper; using policy_type = policy_t; + using track_type = track_t; struct state : public base_type::state { diff --git a/tests/common/include/tests/common/test_telescope_detector.inl b/tests/common/include/tests/common/test_telescope_detector.inl index 42782810d..b63835604 100644 --- a/tests/common/include/tests/common/test_telescope_detector.inl +++ b/tests/common/include/tests/common/test_telescope_detector.inl @@ -72,6 +72,7 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { rk_stepper_t rk_stepper_z; rk_stepper_t rk_stepper_x; ln_stepper_t ln_stepper; + typename ln_stepper_t::track_type default_trk{{0, 0, 0}, 0, {0, 0, 1}, -1}; // // telescope along z @@ -81,15 +82,17 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { std::vector positions = {0., 50., 100., 150., 200., 250., 300., 350, 400, 450., 500.}; // Build telescope detector with unbounded planes - const auto z_tel_det1 = - create_telescope_detector(host_mr, positions); + const auto z_tel_det1 = create_telescope_detector( + host_mr, positions, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}); // Build the same telescope detector with rectangular planes and given // length/number of surfaces dindex n_surfaces = 11; scalar tel_length = 500. * unit_constants::mm; - const auto z_tel_det2 = - create_telescope_detector(host_mr, n_surfaces, tel_length); + const auto z_tel_det2 = create_telescope_detector( + host_mr, n_surfaces, tel_length, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}); // Compare for (std::size_t i = 0; i < z_tel_det1.surfaces().size(); ++i) { diff --git a/tests/common/include/tests/common/tools_guided_navigator.inl b/tests/common/include/tests/common/tools_guided_navigator.inl index 13dcc6fb8..455b00fdc 100644 --- a/tests/common/include/tests/common/tools_guided_navigator.inl +++ b/tests/common/include/tests/common/tools_guided_navigator.inl @@ -31,12 +31,15 @@ TEST(ALGEBRA_PLUGIN, guided_navigator) { // Use unbounded surfaces constexpr bool unbounded = true; + using ln_stepper_t = line_stepper; + typename ln_stepper_t::track_type default_trk{{0, 0, 0}, 0, {0, 0, 1}, -1}; + // Module positions along z-axis const std::vector positions = {0., 10., 20., 30., 40., 50., 60., 70, 80, 90., 100.}; // Build telescope detector with unbounded planes - const auto telescope_det = - create_telescope_detector(host_mr, positions); + const auto telescope_det = create_telescope_detector( + host_mr, positions, ln_stepper_t(), default_trk); // Inspectors are optional, of course using object_tracer_t = From f1d9ce058ab25fd2980845bb248585a74898ebd1 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 30 Aug 2022 16:06:08 -0700 Subject: [PATCH 09/63] remove default constructor --- core/include/detray/propagator/base_stepper.hpp | 2 -- core/include/detray/propagator/line_stepper.hpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index cfbca1b7f..5d70d37f5 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -39,8 +39,6 @@ class base_stepper { */ struct state { - state(){}; - /// Sets track parameters. DETRAY_HOST_DEVICE state(const track_t &t) : _track(t) {} diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index d19c02488..1a3ccd9b9 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -37,8 +37,6 @@ class line_stepper final using field_type = int; - state(){}; - DETRAY_HOST_DEVICE state(const track_t &t) : base_type::state(t) {} From 09426a7e8bd48023e3c684a674a9d3b7cbe14905 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 31 Aug 2022 23:07:10 -0700 Subject: [PATCH 10/63] Backup --- core/CMakeLists.txt | 5 +- .../include/detray/coordinates/cartesian2.hpp | 8 + .../detray/coordinates/coordinate_base.hpp | 137 +++++++++++------- core/include/detray/coordinates/polar2.hpp | 8 + .../propagator/{ => actors}/aborters.hpp | 0 .../actors/bound_to_bound_updater.hpp | 135 +++++++++++++++++ .../detray/propagator/actors/resetter.hpp | 85 +++++++++++ .../detray/propagator/base_stepper.hpp | 4 + .../propagator/detail/covariance_kernel.hpp | 50 ++----- core/include/detray/propagator/rk_stepper.ipp | 1 + .../tests/common/covariance_engine.inl | 2 +- .../tests/common/tools_guided_navigator.inl | 2 +- .../include/tests/common/tools_propagator.inl | 2 +- .../include/tests/common/tools_stepper.inl | 77 +++++++++- .../cuda/propagator_cuda_kernel.hpp | 2 +- 15 files changed, 415 insertions(+), 103 deletions(-) rename core/include/detray/propagator/{ => actors}/aborters.hpp (100%) create mode 100644 core/include/detray/propagator/actors/bound_to_bound_updater.hpp create mode 100644 core/include/detray/propagator/actors/resetter.hpp diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index f2278b102..1caeead17 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -73,12 +73,13 @@ detray_add_library( detray_core core "include/detray/materials/material_slab.hpp" "include/detray/materials/predefined_materials.hpp" # propagator include(s) - "include/detray/propagator/aborters.hpp" + "include/detray/propagator/actors/aborters.hpp" + "include/detray/propagator/actors/resetter.hpp" + "include/detray/propagator/actors/bound_to_bound_updater.hpp" "include/detray/propagator/actor_chain.hpp" "include/detray/propagator/base_actor.hpp" "include/detray/propagator/base_stepper.hpp" "include/detray/propagator/constrained_step.hpp" - "include/detray/propagator/detail/covariance_kernel.hpp" "include/detray/propagator/detail/covariance_engine.hpp" "include/detray/propagator/detail/jacobian_engine.hpp" "include/detray/propagator/line_stepper.hpp" diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index 9dc2a50cf..d583c43de 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -83,6 +83,14 @@ struct cartesian2 final : public coordinate_base { return trf3.point_to_global(point3{p[0], p[1], 0.}); } + template + DETRAY_HOST_DEVICE inline vector3 normal(const transform3_t &trf3, + const mask_t & /*mask*/, + const point3 & /*pos*/, + const vector3 & /*dir*/) { + return matrix_actor().block<3, 1>(trf3, 0, 2); + } + template DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( const transform3_t &trf3, const mask_t &mask, const point3 & /*pos*/, diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 4b6999efc..07f6fa621 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -9,6 +9,7 @@ // Project include(s). #include "detray/definitions/qualifiers.hpp" +#include "detray/intersection/detail/trajectories.hpp" #include "detray/tracks/detail/track_helper.hpp" namespace detray { @@ -201,90 +202,114 @@ struct coordinate_base { return jac_to_local; } - /* - template - DETRAY_HOST_DEVICE inline free_to_path_matrix free_to_path_correction( - const transform3_t& trf3, const mask_t& mask, - const free_vector& free_vec) const { + template + DETRAY_HOST_DEVICE inline free_matrix path_correction( + const stepper_state_t& stepping, const transform3_t& trf3, + const mask_t& mask) { - // Declare free to path correction - free_to_path_matrix free_to_path = - matrix_actor().template zero<1, e_free_size>(); + free_matrix path_correction = + matrix_actor().template zero(); - // Global position and direction - const vector3 pos = track_helper().pos(free_vec); - const vector3 dir = track_helper().dir(free_vec); + using helix = detail::helix; - // The measurement frame z axis - const auto frame = - Derived().reference_frame(trf3, mask, pos, dir); - const matrix_type<3, 1> ref_z_axis = - matrix_actor()().template block<3, 1>(frame, 0, 2); + // Path length + const auto s = stepping._s; - // cosine angle between momentum direction and the measurement frame z - // axis - const scalar_type dz = vector::dot(ref_z_axis, dir); + // helix + helix hlx(stepping(), stepping._step_data.b_last); - // Correction term - const matrix_type<1, 3> correction_term = - -1. / dz * matrix_actor().transpose(ref_z_axis); + // B field at the destination surface + const matrix_type<1, 3> h; + matrix_actor().set_block(h, hlx._h0, 0, 0); - matrix_actor().template set_block<1, 3>(free_to_path, correction_term, - 0, e_free_pos0); + // dir + const matrix_type<1, 3> t; + matrix_actor().set_block(t, hlx._t0, 0, 0); - return free_to_path; - } - */ + // Normalized vector of h X t + const matrix_type<1, 3> n; + matrix_actor().set_block(n, hlx._n0, 0, 0); - template - DETRAY_HOST_DEVICE inline free_matrix path_correction( - const stepper_state_t& stepping, const transform3_t& trf3, - const mask_t& mask) { + // Surface normal vector (w) + const matrix_type<1, 3> w; + const auto normal = + Derived().normal(trf3, mask, hlx.pos(), hlx._t0); + matrix_actor().set_block(w, normal, 0, 0); - /* - using field = typename stepper_state_t::magnetic_field; - using helix = detail::helix; + // w cross h + const matrix_type<1, 3> wh; + matrix_actor().set_block(w, vector::cross(w, h), 0, 0); - free_matrix path_correction = - matrix_actor().template zero(); + // Alpha + const scalar_type A = hlx._alpha; - sd.b_first = - _magnetic_field.get_field(stepping().pos(), context_type{}); - */ - /* - // Direction at the surface - const vector3& t = stepping._step_data.k4; + // K + const scalar_type K = hlx._K; - // B field at the surface - field B(stepping._step_data.b_last); - */ - // Use Helix - // detail::helix helix hlx(trf3, &B); + // Ks = K*s + const scalar_type Ks = K * s; - /* - // Direction at the surface - const vector3& t = stepping._step_data.k4; + // w dot t + const scalar_type wt = vector::dot(normal, hlx._t0); - // B field at the surface - const vector3& h = stepping._step_data.b_last; + // r correction term + const matrix_type<1, 3> r_term = -1. / wt * w; - // Normalized vector of h X t - const vector3& n = vector::normalize(vector::cross(h,t)); - */ + // t correction term + matrix_type<1, 3> t_term = matrix_actor().template zero<1, 3>(); + t_term = t_term + (Ks - std::sin(Ks)) / K * vector::dot(h, w) * h; + t_term = t_term + std::sin(Ks) / K * w; + t_term = t_term + (1 - std::cos(Ks)) / K * wh; + t_term = -1. / wt * t_term; + + // qoverp correction term + const scalar_type L_term = + -1. / wt * A * Ks / hlx.qop() * vector::dot(w, n); + + // transpose of t + const matrix_type<3, 1> t_T = matrix_actor().transpose(t); // dr/dr0 + const matrix_type<3, 3> drdr0 = t_T * r_term; // dr/dt0 + const matrix_type<3, 3> drdt0 = t_T * t_term; // dr/dL0 (L = qoverp) + const matrix_type<3, 1> drdL0 = t_T * L_term; + + // transpose of n + const matrix_type<3, 1> n_T = matrix_actor().transpose(n); // dt/dr0 + const scalar_type AK = A * K; + const matrix_type<3, 3> dtdr0 = AK * n_T * r_term; // dt/dt0 + const matrix_type<3, 3> dtdt0 = AK * n_T * t_term; // dt/dL0 + const matrix_type<3, 1> dtdL0 = AK * n_T * L_term; + + matrix_actor().template set_block<3, 3>(path_correction, drdr0, + e_free_pos0, e_free_pos0); + + matrix_actor().template set_block<3, 3>(path_correction, drdt0, + e_free_pos0, e_free_dir0); + + matrix_actor().template set_block<3, 1>(path_correction, drdL0, + e_free_pos0, e_free_qoverp); + + matrix_actor().template set_block<3, 3>(path_correction, dtdr0, + e_free_dir0, e_free_pos0); + + matrix_actor().template set_block<3, 3>(path_correction, dtdt0, + e_free_dir0, e_free_dir0); + + matrix_actor().template set_block<3, 1>(path_correction, dtdL0, + e_free_dir0, e_free_qoverp); - // return path_correction; + return path_correction; } }; diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index 95944df19..6da15d944 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -85,6 +85,14 @@ struct polar2 : public coordinate_base { return trf.point_to_global(point3{x, y, 0.}); } + template + DETRAY_HOST_DEVICE inline vector3 normal(const transform3_t &trf3, + const mask_t & /*mask*/, + const point3 & /*pos*/, + const vector3 & /*dir*/) { + return matrix_actor().block<3, 1>(trf3, 0, 2); + } + template DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( const transform3_t &trf3, const mask_t & /*mask*/, diff --git a/core/include/detray/propagator/aborters.hpp b/core/include/detray/propagator/actors/aborters.hpp similarity index 100% rename from core/include/detray/propagator/aborters.hpp rename to core/include/detray/propagator/actors/aborters.hpp diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp new file mode 100644 index 000000000..be5494137 --- /dev/null +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -0,0 +1,135 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "detray/definitions/qualifiers.hpp" +#include "detray/definitions/track_parametrization.hpp" +#include "detray/propagator/base_actor.hpp" +#include "detray/tracks/detail/track_helper.hpp" + +namespace detray { + +template +struct bound_to_bound_updater : actor { + + struct state {}; + + struct kernel { + + /// @name Type definitions for the struct + /// @{ + + // Transformation matching this struct + using transform3_type = transform3_t; + // scalar_type + using scalar_type = typename transform3_type::scalar_type; + // size type + using size_type = typename transform3_type::size_type; + // Matrix actor + using matrix_actor = typename transform3_t::matrix_actor; + // 2D matrix type + template + using matrix_type = + typename matrix_actor::template matrix_type; + // Shorthand vector/matrix types related to bound track parameters. + using bound_vector = matrix_type; + using bound_matrix = matrix_type; + // Mapping from bound track parameters. + using bound_to_free_matrix = matrix_type; + // Shorthand vector/matrix types related to free track parameters. + using free_vector = matrix_type; + using free_matrix = matrix_type; + // Mapping from free track parameters. + using free_to_bound_matrix = matrix_type; + using free_to_path_matrix = matrix_type<1, e_free_size>; + // Track helper + using track_helper = detail::track_helper; + + /// @} + + using output_type = bool; + + template + DETRAY_HOST_DEVICE inline output_type operator()( + const mask_group_t& mask_group, const surface_t& surface, + propagator_state_t& propagation) const { + + // Stepper and Navigator states + auto& navigation = propagation._navigation; + auto& stepping = propagation._stepping; + + // Retrieve surfaces and transform store + const auto& det = navigation.detector(); + const auto& transform_store = det->transform_store(); + + // Intersection + const auto& is = navigation.current(); + + // Transform + const auto& trf3 = transform_store[surface.transform()]; + + // Mask + const auto& mask = mask_group[is->mask_index]; + auto local_coordinate = mask.local_type(); + + // Free vector + const auto& free_vec = stepping().vector(); + + // Convert free to bound vector + const auto bound_vec = + local_coordinate.free_to_bound_vector(trf3, free_vec); + + // Free to bound jacobian at the destination surface + const free_to_bound_matrix free_to_bound_jacobian = + local_coordinate.free_to_bound_jacobian(trf3, mask, free_vec); + + // Transport jacobian in free coordinate + free_matrix& free_transport_jacobian = stepping._jac_transport; + + // Path correction factor + free_matrix path_correction = + local_coordinate.path_correction(stepping, trf3, mask); + + // Bound to free jacobian at the departure surface + const bound_to_free_matrix& bound_to_free_jacobian = + stepping._jac_to_global; + + // Calculate surface-to-surface covariance transport + stepping._bound_covariance = + free_to_bound_jacobian * + (path_correction + free_transport_jacobian) * + bound_to_free_jacobian; + + return true; + } + }; + + template + DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const { + + auto& navigation = propagation._navigation; + + // Do covariance transport when the track is on surface + if (navigation.is_on_module()) { + + const auto& det = navigation.detector(); + const auto& surface_container = det->surfaces(); + const auto& mask_store = det->mask_store(); + + // Surface + const auto& surface = surface_container[is->index]; + + auto succeed = mask_store.template execute( + surface.mask_type(), surface, propagation); + } + } +}; + +} // namespace detray \ No newline at end of file diff --git a/core/include/detray/propagator/actors/resetter.hpp b/core/include/detray/propagator/actors/resetter.hpp new file mode 100644 index 000000000..6e36cc23d --- /dev/null +++ b/core/include/detray/propagator/actors/resetter.hpp @@ -0,0 +1,85 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "detray/definitions/qualifiers.hpp" +#include "detray/definitions/track_parametrization.hpp" +#include "detray/propagator/base_actor.hpp" +#include "detray/tracks/detail/track_helper.hpp" + +namespace detray { + +template +struct resetter : actor { + + struct state {}; + + struct kernel { + + using output_type = bool; + + template + DETRAY_HOST_DEVICE inline output_type operator()( + const mask_group_t& mask_group, const surface_t& surface, + propagator_state_t& propagation) const { + + // Stepper and Navigator states + auto& navigation = propagation._navigation; + auto& stepping = propagation._stepping; + + // Intersection + const auto& is = navigation.current(); + + // Transform + const auto& trf3 = transform_store[surface.transform()]; + + // Mask + const auto& mask = mask_group[is->mask_index]; + auto local_coordinate = mask.local_type(); + + // Reset the path length + stepping._s = 0; + + /* + // Reset jacobian coordinate transformation at the current surface + stepping._jac_to_global = local_coordinate.bound_to_free_jacobian( + trf3, mask, stepping._bound_vec); + + // Reset jacobian transport to identity matrix + matrix_operator().set_identity(free_transport_jacobian); + + // Reset derivative of position and direction to zero matrix + matrix_operator().set_zero(free_to_path_derivative); + */ + } + }; + + template + DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const { + + auto& navigation = propagation._navigation; + + // Do covariance transport when the track is on surface + if (navigation.is_on_module()) { + + const auto& det = navigation.detector(); + const auto& surface_container = det->surfaces(); + const auto& mask_store = det->mask_store(); + + // Surface + const auto& surface = surface_container[is->index]; + + auto succeed = mask_store.template execute( + surface.mask_type(), surface, propagation); + } + } +}; + +} // namespace detray diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index 246f95a47..a7fdb3bcf 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -117,6 +117,10 @@ class base_stepper { /// Track path length scalar _path_length{0.}; + /// Track path length from the last surface. It will be reset to 0 when + /// the track reaches a new surface + scalar _s{0.}; + /// Current step size scalar _step_size{0.}; diff --git a/core/include/detray/propagator/detail/covariance_kernel.hpp b/core/include/detray/propagator/detail/covariance_kernel.hpp index a508bd1fa..07862e5f4 100644 --- a/core/include/detray/propagator/detail/covariance_kernel.hpp +++ b/core/include/detray/propagator/detail/covariance_kernel.hpp @@ -7,8 +7,10 @@ #pragma once -// Detray include(s) +// Project include(s) #include "detray/definitions/qualifiers.hpp" +#include "detray/definitions/track_parametrization.hpp" +#include "detray/tracks/detail/track_helper.hpp" namespace detray { @@ -90,53 +92,21 @@ struct bound_to_bound_covariance_update { free_matrix& free_transport_jacobian = stepping._jac_transport; // Path correction factor + free_matrix path_correction = + local_coordinate.path_correction(stepping, trf3, mask); // Bound to free jacobian at the departure surface const bound_to_free_matrix& bound_to_free_jacobian = stepping._jac_to_global; - /* - // Run over the masks belonged to the surface - for (const auto& mask : range(mask_group, mask_range)) { + // Calculate surface-to-surface covariance transport + stepping._bound_covariance = + free_to_bound_jacobian * + (path_correction + free_transport_jacobian) * + bound_to_free_jacobian; - auto local_coordinate = mask.local_type(); - - local_coordinate. - } - */ return true; } - - /** Function to get the full jacobian for surface-to-surface propagation - * - * @param trf3 is the transform matrix of the destination surface - * @param mask is the mask of the destination surface - * @param free_vec is the input free vector at the destination surface - * @param bound_to_free_jacobian is the coordinate transform jacobian - * at departure surface. - * @param free_transport_jacobian is the transport jacobian - * @param free_to_path_derivative is the derivative of free parameter w.r.t - * path - * @returns bound to bound jacobian - */ - /* - template - DETRAY_HOST_DEVICE inline bound_matrix bound_to_bound_jacobian( - const transform3_t& trf3, const mask_t& mask, - const free_vector& free_vec, - const bound_to_free_matrix& bound_to_free_jacobian, - const free_matrix& free_transport_jacobian, - const free_matrix& path_correction) { - - using local_type = typename mask_t::local_type; - - const auto free_to_bound_matrix free_to_bound_jacobian = - local_type().free_to_bound_jacobian(trf3, mask, free_vec); - - return free_to_bound_jacobian * free_transport_jacobian * - bound_to_free_jacobian; - } - */ }; } // namespace detail diff --git a/core/include/detray/propagator/rk_stepper.ipp b/core/include/detray/propagator/rk_stepper.ipp index e944f061d..0de9ec2f4 100644 --- a/core/include/detray/propagator/rk_stepper.ipp +++ b/core/include/detray/propagator/rk_stepper.ipp @@ -48,6 +48,7 @@ void detray::rk_stepper_path_length += h; + this->_s += h; } template + // google-test include(s) #include @@ -231,6 +235,77 @@ TEST(ALGEBRA_PLUGIN, rk_stepper) { // This tests the covariance transport in rk stepper TEST(ALGEBRA_PLUGIN, covariance_transport) { + vecmem::host_memory_resource host_mr; + + using ln_stepper_t = line_stepper; + + // Use rectangular surfaces + constexpr bool rectangular = false; + + // Create telescope detector with a single plane + typename ln_stepper_t::free_track_parameters_type default_trk{ + {0, 0, 0}, 0, {1, 0, 0}, -1}; + std::vector positions = {0.}; + + const auto det = create_telescope_detector( + host_mr, positions, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}); + + // Generate track starting point + vector2 local{2, 3}; + vector3 mom{0.02, 0., 0.}; + scalar time = 0.; + scalar q = -1.; + + // bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = local[0]; + getter::element(bound_vector, e_bound_loc1, 0) = local[1]; + getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); + getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); + getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); + getter::element(bound_vector, e_bound_time, 0) = time; + + // bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; + getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; + + // Note: Set theta error as ZERO, to constrain the loc1 divergence + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; + getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + + // B field + vector3 B{0, 0, 1. * unit_constants::T}; + mag_field_t mag_field(B); + + /* + // bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + prop_state propagation{ + crk_stepper_t::state(bound_param0, trf, mag_field), nav_state{det}}; + crk_stepper_t::state &crk_state = propagation._stepping; + nav_state &n_state = propagation._navigation; + + // Decrease tolerance down to 1e-8 + crk_state._tolerance = 1e-8; + + // RK stepper and its state + crk_stepper_t crk_stepper; + + ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); + ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); + ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); + ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); + ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); + ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); + */ + /* // test surface diff --git a/tests/unit_tests/cuda/propagator_cuda_kernel.hpp b/tests/unit_tests/cuda/propagator_cuda_kernel.hpp index 23cd43c96..fec072370 100644 --- a/tests/unit_tests/cuda/propagator_cuda_kernel.hpp +++ b/tests/unit_tests/cuda/propagator_cuda_kernel.hpp @@ -19,8 +19,8 @@ #include "detray/definitions/units.hpp" #include "detray/field/constant_magnetic_field.hpp" -#include "detray/propagator/aborters.hpp" #include "detray/propagator/actor_chain.hpp" +#include "detray/propagator/actors/aborters.hpp" #include "detray/propagator/base_actor.hpp" #include "detray/propagator/navigator.hpp" #include "detray/propagator/propagator.hpp" From 9d381a5175879642b13194085e72167d4a86e2b6 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 1 Sep 2022 18:31:32 -0700 Subject: [PATCH 11/63] Add unit test for jacobian transformation --- .../include/detray/coordinates/cartesian2.hpp | 18 +- .../detray/coordinates/coordinate_base.hpp | 6 +- .../detray/coordinates/cylindrical2.hpp | 18 +- core/include/detray/coordinates/polar2.hpp | 41 ++- .../actors/bound_to_bound_updater.hpp | 11 +- .../detray/propagator/actors/resetter.hpp | 24 +- .../detray/propagator/base_stepper.hpp | 28 +- core/include/detray/propagator/propagator.hpp | 6 +- core/include/detray/propagator/rk_stepper.hpp | 5 +- core/include/detray/propagator/rk_stepper.ipp | 18 - .../tests/common/coordinate_cartesian2.inl | 104 ++++++ .../tests/common/coordinate_cartesian3.inl | 54 +++ .../tests/common/coordinate_cylindrical2.inl | 114 ++++++ .../tests/common/coordinate_cylindrical3.inl | 54 +++ .../include/tests/common/coordinate_line2.inl | 79 +++++ .../tests/common/coordinate_polar2.inl | 104 ++++++ .../include/tests/common/coordinates.inl | 328 ------------------ .../tests/common/covariance_engine.inl | 231 +++++++++++- .../include/tests/common/tools_stepper.inl | 206 ----------- tests/unit_tests/array/CMakeLists.txt | 4 +- .../array/array_coordinate_cartesian2.cpp | 9 + .../array/array_coordinate_cartesian3.cpp | 9 + .../array/array_coordinate_cylindrical2.cpp | 9 + .../array/array_coordinate_cylindrical3.cpp | 9 + ...dinates.cpp => array_coordinate_line2.cpp} | 2 +- .../array/array_coordinate_polar2.cpp | 9 + tests/unit_tests/cuda/rk_stepper_cuda.cpp | 2 +- .../unit_tests/cuda/rk_stepper_cuda_kernel.cu | 2 +- tests/unit_tests/eigen/CMakeLists.txt | 4 +- .../eigen/eigen_coordinate_cartesian2.cpp | 9 + .../eigen/eigen_coordinate_cartesian3.cpp | 9 + .../eigen/eigen_coordinate_cylindrical2.cpp | 9 + .../eigen/eigen_coordinate_cylindrical3.cpp | 9 + ...dinates.cpp => eigen_coordinate_line2.cpp} | 2 +- .../eigen/eigen_coordinate_polar2.cpp | 9 + tests/unit_tests/smatrix/CMakeLists.txt | 4 +- .../smatrix/smatrix_coordinate_cartesian2.cpp | 9 + .../smatrix/smatrix_coordinate_cartesian3.cpp | 9 + .../smatrix_coordinate_cylindrical2.cpp | 9 + .../smatrix_coordinate_cylindrical3.cpp | 9 + ...nates.cpp => smatrix_coordinate_line2.cpp} | 2 +- .../smatrix/smatrix_coordinate_polar2.cpp | 9 + tests/unit_tests/vc/CMakeLists.txt | 6 +- .../vc/vc_array_coordinate_cartesian2.cpp | 9 + .../vc/vc_array_coordinate_cartesian3.cpp | 9 + .../vc/vc_array_coordinate_cylindrical2.cpp | 9 + .../vc/vc_array_coordinate_cylindrical3.cpp | 9 + ...ates.cpp => vc_array_coordinate_line2.cpp} | 2 +- .../vc/vc_array_coordinate_polar2.cpp | 9 + 49 files changed, 1022 insertions(+), 637 deletions(-) create mode 100644 tests/common/include/tests/common/coordinate_cartesian2.inl create mode 100644 tests/common/include/tests/common/coordinate_cartesian3.inl create mode 100644 tests/common/include/tests/common/coordinate_cylindrical2.inl create mode 100644 tests/common/include/tests/common/coordinate_cylindrical3.inl create mode 100644 tests/common/include/tests/common/coordinate_line2.inl create mode 100644 tests/common/include/tests/common/coordinate_polar2.inl delete mode 100644 tests/common/include/tests/common/coordinates.inl create mode 100644 tests/unit_tests/array/array_coordinate_cartesian2.cpp create mode 100644 tests/unit_tests/array/array_coordinate_cartesian3.cpp create mode 100644 tests/unit_tests/array/array_coordinate_cylindrical2.cpp create mode 100644 tests/unit_tests/array/array_coordinate_cylindrical3.cpp rename tests/unit_tests/array/{array_coordinates.cpp => array_coordinate_line2.cpp} (82%) create mode 100644 tests/unit_tests/array/array_coordinate_polar2.cpp create mode 100644 tests/unit_tests/eigen/eigen_coordinate_cartesian2.cpp create mode 100644 tests/unit_tests/eigen/eigen_coordinate_cartesian3.cpp create mode 100644 tests/unit_tests/eigen/eigen_coordinate_cylindrical2.cpp create mode 100644 tests/unit_tests/eigen/eigen_coordinate_cylindrical3.cpp rename tests/unit_tests/eigen/{eigen_coordinates.cpp => eigen_coordinate_line2.cpp} (82%) create mode 100644 tests/unit_tests/eigen/eigen_coordinate_polar2.cpp create mode 100644 tests/unit_tests/smatrix/smatrix_coordinate_cartesian2.cpp create mode 100644 tests/unit_tests/smatrix/smatrix_coordinate_cartesian3.cpp create mode 100644 tests/unit_tests/smatrix/smatrix_coordinate_cylindrical2.cpp create mode 100644 tests/unit_tests/smatrix/smatrix_coordinate_cylindrical3.cpp rename tests/unit_tests/smatrix/{smatrix_coordinates.cpp => smatrix_coordinate_line2.cpp} (83%) create mode 100644 tests/unit_tests/smatrix/smatrix_coordinate_polar2.cpp create mode 100644 tests/unit_tests/vc/vc_array_coordinate_cartesian2.cpp create mode 100644 tests/unit_tests/vc/vc_array_coordinate_cartesian3.cpp create mode 100644 tests/unit_tests/vc/vc_array_coordinate_cylindrical2.cpp create mode 100644 tests/unit_tests/vc/vc_array_coordinate_cylindrical3.cpp rename tests/unit_tests/vc/{vc_array_coordinates.cpp => vc_array_coordinate_line2.cpp} (83%) create mode 100644 tests/unit_tests/vc/vc_array_coordinate_polar2.cpp diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index d583c43de..36ba78f97 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -87,14 +87,19 @@ struct cartesian2 final : public coordinate_base { DETRAY_HOST_DEVICE inline vector3 normal(const transform3_t &trf3, const mask_t & /*mask*/, const point3 & /*pos*/, - const vector3 & /*dir*/) { - return matrix_actor().block<3, 1>(trf3, 0, 2); + const vector3 & /*dir*/) const { + vector3 ret; + const auto n = matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); + ret[0] = matrix_actor().element(n, 0, 0); + ret[1] = matrix_actor().element(n, 1, 0); + ret[2] = matrix_actor().element(n, 2, 0); + return ret; } template DETRAY_HOST_DEVICE inline rotation_matrix reference_frame( - const transform3_t &trf3, const mask_t &mask, const point3 & /*pos*/, - const vector3 & /*dir*/) const { + const transform3_t &trf3, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const { return trf3.rotation(); } @@ -133,8 +138,9 @@ struct cartesian2 final : public coordinate_base { template DETRAY_HOST_DEVICE inline void set_bound_angle_to_free_pos_derivative( - bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, - const mask_t &mask, const point3 &pos, const vector3 &dir) const { + bound_to_free_matrix & /*bound_to_free_jacobian*/, + const transform3_t & /*trf3*/, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const { // Do nothing } diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 07f6fa621..f1d57bda9 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -125,8 +125,10 @@ struct coordinate_base { const scalar_type sin_phi = std::sin(phi); // Global position and direction - const vector3 pos = track_helper().pos(bound_vec); - const vector3 dir = track_helper().dir(bound_vec); + const auto free_vec = bound_to_free_vector(trf3, mask, bound_vec); + + const vector3 pos = track_helper().pos(free_vec); + const vector3 dir = track_helper().dir(free_vec); // Set d(x,y,z)/d(loc0, loc1) Derived().set_bound_pos_to_free_pos_derivative( diff --git a/core/include/detray/coordinates/cylindrical2.hpp b/core/include/detray/coordinates/cylindrical2.hpp index 103aba0f7..fb0ccbaee 100644 --- a/core/include/detray/coordinates/cylindrical2.hpp +++ b/core/include/detray/coordinates/cylindrical2.hpp @@ -108,7 +108,8 @@ struct cylindrical2 : public coordinate_base { rotation_matrix rot = matrix_actor().template zero<3, 3>(); // y axis of the new frame is the z axis of cylindrical coordinate - const auto new_yaxis = matrix_actor().template block<3, 1>(trf3, 0, 2); + const auto new_yaxis = + matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); // z axis of the new frame is the vector normal to the cylinder surface const vector3 new_zaxis = normal(trf3, mask, pos, dir); @@ -116,9 +117,13 @@ struct cylindrical2 : public coordinate_base { // x axis const vector3 new_xaxis = vector::cross(new_yaxis, new_zaxis); - matrix_actor().set_block<3, 1>(rot, new_xaxis, 0, 0); - matrix_actor().set_block<3, 1>(rot, new_yaxis, 0, 1); - matrix_actor().set_block<3, 1>(rot, new_zaxis, 0, 2); + matrix_actor().element(rot, 0, 0) = new_xaxis[0]; + matrix_actor().element(rot, 1, 0) = new_xaxis[1]; + matrix_actor().element(rot, 2, 0) = new_xaxis[2]; + matrix_actor().template set_block<3, 1>(rot, new_yaxis, 0, 1); + matrix_actor().element(rot, 0, 2) = new_zaxis[0]; + matrix_actor().element(rot, 1, 2) = new_zaxis[1]; + matrix_actor().element(rot, 2, 2) = new_zaxis[2]; return rot; } @@ -158,8 +163,9 @@ struct cylindrical2 : public coordinate_base { template DETRAY_HOST_DEVICE inline void set_bound_angle_to_free_pos_derivative( - bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, - const mask_t &mask, const point3 &pos, const vector3 &dir) const { + bound_to_free_matrix & /*bound_to_free_jacobian*/, + const transform3_t & /*trf3*/, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const { // Do nothing } diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index 6da15d944..b4403f76b 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -89,8 +89,13 @@ struct polar2 : public coordinate_base { DETRAY_HOST_DEVICE inline vector3 normal(const transform3_t &trf3, const mask_t & /*mask*/, const point3 & /*pos*/, - const vector3 & /*dir*/) { - return matrix_actor().block<3, 1>(trf3, 0, 2); + const vector3 & /*dir*/) const { + vector3 ret; + const auto n = matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); + ret[0] = matrix_actor().element(n, 0, 0); + ret[1] = matrix_actor().element(n, 1, 0); + ret[2] = matrix_actor().element(n, 2, 0); + return ret; } template @@ -108,7 +113,8 @@ struct polar2 : public coordinate_base { matrix_type<3, 2> bound_pos_to_free_pos_derivative = matrix_actor().template zero<3, 2>(); - const point2 local2 = this->operator()(pos); + const point2 local2 = this->global_to_local(trf3, pos, dir); + // this->operator()(pos); const scalar_type lrad = local2[0]; const scalar_type lphi = local2[1]; @@ -116,7 +122,7 @@ struct polar2 : public coordinate_base { const scalar_type lsin_phi = std::sin(lphi); // reference matrix - const auto frame = reference_frame(trf3, pos, dir); + const auto frame = reference_frame(trf3, mask, pos, dir); // dxdu = d(x,y,z)/du const auto dxdL = matrix_actor().template block<3, 1>(frame, 0, 0); @@ -126,10 +132,10 @@ struct polar2 : public coordinate_base { const auto col0 = dxdL * lcos_phi + dydL * lsin_phi; const auto col1 = (dydL * lcos_phi - dxdL * lsin_phi) * lrad; - matrix_actor().set_block<3, 1>(bound_pos_to_free_pos_derivative, col0, - e_free_pos0, e_bound_loc0); - matrix_actor().set_block<3, 1>(bound_pos_to_free_pos_derivative, col1, - e_free_pos0, e_bound_loc1); + matrix_actor().template set_block<3, 1>( + bound_pos_to_free_pos_derivative, col0, e_free_pos0, e_bound_loc0); + matrix_actor().template set_block<3, 1>( + bound_pos_to_free_pos_derivative, col1, e_free_pos0, e_bound_loc1); matrix_actor().template set_block(free_to_bound_jacobian, bound_pos_to_free_pos_derivative, @@ -153,21 +159,21 @@ struct polar2 : public coordinate_base { const scalar_type lsin_phi = std::sin(lphi); // reference matrix - const auto frame = reference_frame(trf3, pos, dir); + const auto frame = reference_frame(trf3, mask, pos, dir); const auto frameT = matrix_actor().transpose(frame); // dudG = du/d(x,y,z) const auto dudG = matrix_actor().template block<1, 3>(frameT, 0, 0); // dvdG = dv/d(x,y,z) - const auto dvdG = matrix_actor().template block<1, 3>(frameT, 0, 1); + const auto dvdG = matrix_actor().template block<1, 3>(frameT, 1, 0); const auto row0 = dudG * lcos_phi + dvdG * lsin_phi; - const auto row1 = (dvdG * lcos_phi - dudG * lsin_phi) * 1. / lrad; + const auto row1 = 1. / lrad * (lcos_phi * dvdG - lsin_phi * dudG); - matrix_actor().set_block<1, 3>(free_pos_to_bound_pos_derivative, row0, - e_bound_loc0, e_free_pos0); - matrix_actor().set_block<1, 3>(free_pos_to_bound_pos_derivative, row1, - e_bound_loc1, e_free_pos0); + matrix_actor().template set_block<1, 3>( + free_pos_to_bound_pos_derivative, row0, e_bound_loc0, e_free_pos0); + matrix_actor().template set_block<1, 3>( + free_pos_to_bound_pos_derivative, row1, e_bound_loc1, e_free_pos0); matrix_actor().template set_block(bound_to_free_jacobian, free_pos_to_bound_pos_derivative, @@ -176,8 +182,9 @@ struct polar2 : public coordinate_base { template DETRAY_HOST_DEVICE inline void set_bound_angle_to_free_pos_derivative( - bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, - const mask_t &mask, const point3 &pos, const vector3 &dir) const { + bound_to_free_matrix & /*bound_to_free_jacobian*/, + const transform3_t & /*trf3*/, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const { // Do nothing } }; diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp index be5494137..72a78d40c 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -83,8 +83,8 @@ struct bound_to_bound_updater : actor { const auto& free_vec = stepping().vector(); // Convert free to bound vector - const auto bound_vec = - local_coordinate.free_to_bound_vector(trf3, free_vec); + stepping._bound_params.set_vector( + local_coordinate.free_to_bound_vector(trf3, free_vec)); // Free to bound jacobian at the destination surface const free_to_bound_matrix free_to_bound_jacobian = @@ -102,10 +102,10 @@ struct bound_to_bound_updater : actor { stepping._jac_to_global; // Calculate surface-to-surface covariance transport - stepping._bound_covariance = + stepping._bound_params.set_covaraince( free_to_bound_jacobian * (path_correction + free_transport_jacobian) * - bound_to_free_jacobian; + bound_to_free_jacobian); return true; } @@ -123,6 +123,9 @@ struct bound_to_bound_updater : actor { const auto& surface_container = det->surfaces(); const auto& mask_store = det->mask_store(); + // Intersection + const auto& is = navigation.current(); + // Surface const auto& surface = surface_container[is->index]; diff --git a/core/include/detray/propagator/actors/resetter.hpp b/core/include/detray/propagator/actors/resetter.hpp index 6e36cc23d..ea6e4e50b 100644 --- a/core/include/detray/propagator/actors/resetter.hpp +++ b/core/include/detray/propagator/actors/resetter.hpp @@ -22,6 +22,14 @@ struct resetter : actor { struct kernel { + /// @name Type definitions for the struct + /// @{ + + // Matrix actor + using matrix_actor = typename transform3_t::matrix_actor; + + /// @} + using output_type = bool; template transform_store(); + // Intersection const auto& is = navigation.current(); @@ -47,17 +59,14 @@ struct resetter : actor { // Reset the path length stepping._s = 0; - /* // Reset jacobian coordinate transformation at the current surface stepping._jac_to_global = local_coordinate.bound_to_free_jacobian( - trf3, mask, stepping._bound_vec); + trf3, mask, stepping._bound_params.vector()); // Reset jacobian transport to identity matrix - matrix_operator().set_identity(free_transport_jacobian); + matrix_actor().set_identity(stepping._jac_transport); - // Reset derivative of position and direction to zero matrix - matrix_operator().set_zero(free_to_path_derivative); - */ + return true; } }; @@ -73,6 +82,9 @@ struct resetter : actor { const auto& surface_container = det->surfaces(); const auto& mask_store = det->mask_store(); + // Intersection + const auto& is = navigation.current(); + // Surface const auto& surface = surface_container[is->index]; diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index a7fdb3bcf..7c13271b6 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -59,25 +59,8 @@ class base_stepper { /// Sets track parameters from bound track parameter. DETRAY_HOST_DEVICE - state(const bound_track_parameters_type & /*bound_params*/, - const transform3_type & /*trf3*/) { - - // @TODO: Rewrite with kernel - - /* - // Set the free vector - _track.set_vector(vector_engine().bound_to_free_vector( - trf3, bound_params.vector())); - - // Set the bound covariance - _bound_covariance = bound_params.covariance(); - - // Reset the jacobians - covariance_engine().reinitialize_jacobians( - trf3, bound_params.vector(), _jac_to_global, _jac_transport, - _derivative); - */ - } + state(const bound_track_parameters_type &bound_params) + : _bound_params(bound_params) {} /// free track parameter free_track_parameters_type _track; @@ -86,17 +69,12 @@ class base_stepper { free_matrix _jac_transport = matrix_operator().template identity(); - /// The free parameter derivative defined at destination surface - free_vector _derivative = - matrix_operator().template zero(); - /// bound-to-free jacobian from departure surface bound_to_free_matrix _jac_to_global = matrix_operator().template zero(); /// bound covariance - bound_matrix _bound_covariance = - matrix_operator().template zero(); + bound_track_parameters_type _bound_params; /// @returns track parameters - const access DETRAY_HOST_DEVICE diff --git a/core/include/detray/propagator/propagator.hpp b/core/include/detray/propagator/propagator.hpp index 18c60cfbf..93af00c17 100644 --- a/core/include/detray/propagator/propagator.hpp +++ b/core/include/detray/propagator/propagator.hpp @@ -85,12 +85,14 @@ struct propagator { _actor_states(actor_states) {} /// Construct the propagation state with bound parameter + template < + std::enable_if_t, bool> = true> DETRAY_HOST_DEVICE state( const bound_track_parameters_type ¶m, - const transform3_type &trf3, const detector_type &det, + const field_type &magnetic_field, const detector_type &det, typename actor_chain_t::state actor_states = {}, vector_type &&candidates = {}) - : _stepping(param, trf3), + : _stepping(param, magnetic_field), _navigation(det, std::move(candidates)), _actor_states(actor_states) {} diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index 01b0a8776..f1372f5c0 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -62,9 +62,8 @@ class rk_stepper final DETRAY_HOST_DEVICE state(const bound_track_parameters_type& bound_params, - const transform3_type& trf3, const field_type mag_field) - : base_type::state(bound_params, trf3), - _magnetic_field(mag_field) {} + const field_type mag_field) + : base_type::state(bound_params), _magnetic_field(mag_field) {} /// error tolerance scalar _tolerance = 1e-4; diff --git a/core/include/detray/propagator/rk_stepper.ipp b/core/include/detray/propagator/rk_stepper.ipp index 0de9ec2f4..ebdd410a4 100644 --- a/core/include/detray/propagator/rk_stepper.ipp +++ b/core/include/detray/propagator/rk_stepper.ipp @@ -11,21 +11,6 @@ // System include(s) #include -template class array_t> -void detray::rk_stepper::state::advance_derivative() { - - // The derivative of position = direction - matrix_operator().set_block(this->_derivative, this->_track.dir(), - e_free_pos0, 0); - - // The derivative of direction = k4 - matrix_operator().set_block(this->_derivative, this->_step_data.k4, - e_free_dir0, 0); -} - template class array_t> @@ -273,9 +258,6 @@ bool detray::rk_stepper(stepping.direction())); } - // Advance derivative of position and direction w.r.t path length - stepping.advance_derivative(); - // Advance track state stepping.advance_track(); diff --git a/tests/common/include/tests/common/coordinate_cartesian2.inl b/tests/common/include/tests/common/coordinate_cartesian2.inl new file mode 100644 index 000000000..ed4db8212 --- /dev/null +++ b/tests/common/include/tests/common/coordinate_cartesian2.inl @@ -0,0 +1,104 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2020-2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/coordinates/cartesian2.hpp" +#include "detray/tracks/tracks.hpp" + +// GTest include(s). +#include + +using namespace detray; +using point2 = __plugin::point2; +using point3 = __plugin::point3; +using vector3 = __plugin::vector3; +using transform3 = __plugin::transform3; +using matrix_operator = typename transform3::matrix_actor; +using size_type = typename matrix_operator::size_ty; +template +using matrix_type = typename matrix_operator::template matrix_type; + +const scalar isclose = 1e-5; + +// This test cartesian2 coordinate +TEST(coordinate, cartesian2) { + + // Preparation work + const vector3 z = {0., 0., 1.}; + const vector3 x = {1., 0., 0.}; + const point3 t = {2., 3., 4.}; + const transform3 trf(t, z, x); + const cartesian2 c2; + const point3 global1 = {4., 7., 4.}; + const vector3 mom = {1., 2., 3.}; + const vector3 d = vector::normalize(mom); + const scalar time = 0.1; + const scalar charge = -1.; + struct dummy_mask { + } mask; + + // Global to local transformation + const point2 local = c2.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], 2., isclose); + ASSERT_NEAR(local[1], 4., isclose); + + // Local to global transformation + const point3 global2 = c2.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); + + // Free track parameter + const free_track_parameters free_params(global1, time, mom, + charge); + const auto free_vec1 = free_params.vector(); + + const auto bound_vec = c2.free_to_bound_vector(trf, free_vec1); + const auto free_vec2 = c2.bound_to_free_vector(trf, mask, bound_vec); + + const matrix_operator m; + + // Check if the bound vector is correct + ASSERT_NEAR(m.element(bound_vec, 0, 0), 2., isclose); + ASSERT_NEAR(m.element(bound_vec, 1, 0), 4., isclose); + ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, + isclose); // atan(2) + ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, + isclose); // atan(sqrt(5)/3) + ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); + ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); + + // Check if the same free vector is obtained + for (int i = 0; i < 8; i++) { + ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), + isclose); + } + + // Normal vector + const vector3 n = + c2.normal(trf, mask, free_params.pos(), free_params.dir()); + ASSERT_EQ(n, vector3({0., 0., 1.})); + + // Test Jacobian transformation + const matrix_type<6, 6> J = + c2.free_to_bound_jacobian(trf, mask, free_vec1) * + c2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 6; j++) { + if (i == j) { + EXPECT_NEAR(m.element(J, i, j), 1., isclose); + } else { + EXPECT_NEAR(m.element(J, i, j), 0., isclose); + } + } + } +} diff --git a/tests/common/include/tests/common/coordinate_cartesian3.inl b/tests/common/include/tests/common/coordinate_cartesian3.inl new file mode 100644 index 000000000..b15fe1a52 --- /dev/null +++ b/tests/common/include/tests/common/coordinate_cartesian3.inl @@ -0,0 +1,54 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2020-2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/coordinates/cartesian3.hpp" +#include "detray/tracks/tracks.hpp" + +// GTest include(s). +#include + +using namespace detray; +using point2 = __plugin::point2; +using point3 = __plugin::point3; +using vector3 = __plugin::vector3; +using transform3 = __plugin::transform3; +using matrix_operator = typename transform3::matrix_actor; + +const scalar isclose = 1e-5; + +// This test cartesian3 coordinate +TEST(coordinate, cartesian3) { + + // Preparation work + const vector3 z = {0., 0., 1.}; + const vector3 x = {1., 0., 0.}; + const point3 t = {2., 3., 4.}; + const transform3 trf(t, z, x); + const cartesian3 c3; + const point3 global1 = {4., 7., 5.}; + const vector3 mom = {1., 2., 3.}; + const vector3 d = vector::normalize(mom); + struct dummy_mask { + } mask; + + // Global to local transformation + const point3 local = c3.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], 2., isclose); + ASSERT_NEAR(local[1], 4., isclose); + ASSERT_NEAR(local[2], 1., isclose); + + // Local to global transformation + const point3 global2 = c3.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); +} diff --git a/tests/common/include/tests/common/coordinate_cylindrical2.inl b/tests/common/include/tests/common/coordinate_cylindrical2.inl new file mode 100644 index 000000000..3a4408795 --- /dev/null +++ b/tests/common/include/tests/common/coordinate_cylindrical2.inl @@ -0,0 +1,114 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2020-2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/coordinates/cylindrical2.hpp" +#include "detray/tracks/tracks.hpp" + +// GTest include(s). +#include + +using namespace detray; +using point2 = __plugin::point2; +using point3 = __plugin::point3; +using vector3 = __plugin::vector3; +using transform3 = __plugin::transform3; +using matrix_operator = typename transform3::matrix_actor; +using size_type = typename matrix_operator::size_ty; +template +using matrix_type = typename matrix_operator::template matrix_type; + +const scalar isclose = 1e-5; + +// This test cylindrical2 coordinate +TEST(coordinate, cylindrical2) { + + // Preparation work + const vector3 z = {0., 0., 1.}; + const vector3 x = {1., 0., 0.}; + const point3 t = {2., 3., 4.}; + const transform3 trf(t, z, x); + const cylindrical2 c2; + // Global position on surface + const point3 global1 = {scalar{3.4142136}, scalar{4.4142136}, scalar{9.}}; + const vector3 mom = {1., 2., 3.}; + const vector3 d = vector::normalize(mom); + const scalar time = 0.1; + const scalar charge = -1.; + + // Define cylinder mask + struct cylinder_mask { + scalar r = 0.; + scalar radius() const { return r; } + }; + + const scalar r = 2.; + const cylinder_mask mask{r}; + + // Global to local transformation + const point2 local = c2.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], r * scalar{M_PI_4}, isclose); + ASSERT_NEAR(local[1], 5., isclose); + + // Local to global transformation + const point3 global2 = c2.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); + + // Free track parameter + const free_track_parameters free_params(global1, time, mom, + charge); + const auto free_vec1 = free_params.vector(); + + const auto bound_vec = c2.free_to_bound_vector(trf, free_vec1); + const auto free_vec2 = c2.bound_to_free_vector(trf, mask, bound_vec); + + const matrix_operator m; + + // Check if the bound vector is correct + ASSERT_NEAR(m.element(bound_vec, 0, 0), r * scalar{M_PI_4}, isclose); + ASSERT_NEAR(m.element(bound_vec, 1, 0), 5, isclose); + ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, + isclose); // atan(2) + ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, + isclose); // atan(sqrt(5)/3) + ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); + ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); + + // Check if the same free vector is obtained + for (int i = 0; i < 8; i++) { + ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), + isclose); + } + + // Normal vector + const vector3 n = + c2.normal(trf, mask, free_params.pos(), free_params.dir()); + ASSERT_NEAR(n[0], 1. / std::sqrt(2), isclose); + ASSERT_NEAR(n[1], 1. / std::sqrt(2), isclose); + ASSERT_NEAR(n[2], 0., isclose); + + // Test Jacobian transformation + const matrix_type<6, 6> J = + c2.free_to_bound_jacobian(trf, mask, free_vec1) * + c2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 6; j++) { + if (i == j) { + EXPECT_NEAR(m.element(J, i, j), 1., isclose); + } else { + EXPECT_NEAR(m.element(J, i, j), 0., isclose); + } + } + } +} diff --git a/tests/common/include/tests/common/coordinate_cylindrical3.inl b/tests/common/include/tests/common/coordinate_cylindrical3.inl new file mode 100644 index 000000000..de3bf4d7d --- /dev/null +++ b/tests/common/include/tests/common/coordinate_cylindrical3.inl @@ -0,0 +1,54 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2020-2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/coordinates/cylindrical3.hpp" +#include "detray/tracks/tracks.hpp" + +// GTest include(s). +#include + +using namespace detray; +using point2 = __plugin::point2; +using point3 = __plugin::point3; +using vector3 = __plugin::vector3; +using transform3 = __plugin::transform3; +using matrix_operator = typename transform3::matrix_actor; + +const scalar isclose = 1e-5; + +// This test cylindrical3 coordinate +TEST(coordinate, cylindrical3) { + + // Preparation work + const vector3 z = {0., 0., 1.}; + const vector3 x = {1., 0., 0.}; + const point3 t = {2., 3., 4.}; + const transform3 trf(t, z, x); + const cylindrical3 c3; + const point3 global1 = {scalar{3.4142136}, scalar{4.4142136}, scalar{9.}}; + const vector3 mom = {1., 2., 3.}; + const vector3 d = vector::normalize(mom); + struct dummy_mask { + } mask; + + // Global to local transformation + const point3 local = c3.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], 2, isclose); + ASSERT_NEAR(local[1], M_PI_4, isclose); + ASSERT_NEAR(local[2], 5., isclose); + + // Local to global transformation + const point3 global2 = c3.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); +} diff --git a/tests/common/include/tests/common/coordinate_line2.inl b/tests/common/include/tests/common/coordinate_line2.inl new file mode 100644 index 000000000..0437bd159 --- /dev/null +++ b/tests/common/include/tests/common/coordinate_line2.inl @@ -0,0 +1,79 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2020-2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/coordinates/line2.hpp" +#include "detray/tracks/tracks.hpp" + +// GTest include(s). +#include + +using namespace detray; +using point2 = __plugin::point2; +using point3 = __plugin::point3; +using vector3 = __plugin::vector3; +using transform3 = __plugin::transform3; +using matrix_operator = typename transform3::matrix_actor; + +const scalar isclose = 1e-5; + +// This test line2 coordinate +TEST(coordinate, line2) { + + // Preparation work + const vector3 z = {0., 0., 1.}; + const vector3 x = {1., 0., 0.}; + const point3 t = {2., 3., 4.}; + const transform3 trf(t, z, x); + const line2 l2; + const point3 global1 = {3., 3., 9.}; + const vector3 mom = {0., 2., 0.}; + const vector3 d = vector::normalize(mom); + const scalar time = 0.1; + const scalar charge = -1.; + struct dummy_mask { + } mask; + + // Global to local transformation + const point2 local = l2.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], -1., isclose); + ASSERT_NEAR(local[1], 5., isclose); + + // Local to global transformation + const point3 global2 = l2.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); + + // Free track parameter + const free_track_parameters free_params(global1, time, mom, + charge); + const auto free_vec1 = free_params.vector(); + + const auto bound_vec = l2.free_to_bound_vector(trf, free_vec1); + const auto free_vec2 = l2.bound_to_free_vector(trf, mask, bound_vec); + + const matrix_operator m; + + // Check if the bound vector is correct + ASSERT_NEAR(m.element(bound_vec, 0, 0), -1., isclose); + ASSERT_NEAR(m.element(bound_vec, 1, 0), 5, isclose); + ASSERT_NEAR(m.element(bound_vec, 2, 0), M_PI_2, isclose); + ASSERT_NEAR(m.element(bound_vec, 3, 0), M_PI_2, isclose); + ASSERT_NEAR(m.element(bound_vec, 4, 0), -0.5, isclose); + ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); + + // Check if the same free vector is obtained + for (int i = 0; i < 8; i++) { + ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), + isclose); + } +} \ No newline at end of file diff --git a/tests/common/include/tests/common/coordinate_polar2.inl b/tests/common/include/tests/common/coordinate_polar2.inl new file mode 100644 index 000000000..0294121d0 --- /dev/null +++ b/tests/common/include/tests/common/coordinate_polar2.inl @@ -0,0 +1,104 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2020-2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/coordinates/polar2.hpp" +#include "detray/tracks/tracks.hpp" + +// GTest include(s). +#include + +using namespace detray; +using point2 = __plugin::point2; +using point3 = __plugin::point3; +using vector3 = __plugin::vector3; +using transform3 = __plugin::transform3; +using matrix_operator = typename transform3::matrix_actor; +using size_type = typename matrix_operator::size_ty; +template +using matrix_type = typename matrix_operator::template matrix_type; + +const scalar isclose = 1e-5; + +// This test polar2 coordinate +TEST(coordinate, polar2) { + + // Preparation work + const vector3 z = {0., 0., 1.}; + const vector3 x = {1., 0., 0.}; + const point3 t = {2., 3., 4.}; + const transform3 trf(t, z, x); + const polar2 p2; + const point3 global1 = {4., 7., 4.}; + const vector3 mom = {1., 2., 3.}; + const vector3 d = vector::normalize(mom); + const scalar time = 0.1; + const scalar charge = -1.; + struct dummy_mask { + } mask; + + // Global to local transformation + const point2 local = p2.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], std::sqrt(20.), isclose); + ASSERT_NEAR(local[1], atan2(4., 2.), isclose); + + // Local to global transformation + const point3 global2 = p2.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); + + // Free track parameter + const free_track_parameters free_params(global1, time, mom, + charge); + const auto free_vec1 = free_params.vector(); + + const auto bound_vec = p2.free_to_bound_vector(trf, free_vec1); + const auto free_vec2 = p2.bound_to_free_vector(trf, mask, bound_vec); + + const matrix_operator m; + + // Check if the bound vector is correct + ASSERT_NEAR(m.element(bound_vec, 0, 0), std::sqrt(20.), isclose); + ASSERT_NEAR(m.element(bound_vec, 1, 0), atan2(4., 2.), isclose); + ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, + isclose); // atan(2) + ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, + isclose); // atan(sqrt(5)/3) + ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); + ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); + + // Check if the same free vector is obtained + for (int i = 0; i < 8; i++) { + ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), + isclose); + } + + // Normal vector + const vector3 n = + p2.normal(trf, mask, free_params.pos(), free_params.dir()); + ASSERT_EQ(n, vector3({0., 0., 1.})); + + // Test Jacobian transformation + const matrix_type<6, 6> J = + p2.free_to_bound_jacobian(trf, mask, free_vec1) * + p2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 6; j++) { + if (i == j) { + EXPECT_NEAR(m.element(J, i, j), 1., isclose); + } else { + EXPECT_NEAR(m.element(J, i, j), 0., isclose); + } + } + } +} \ No newline at end of file diff --git a/tests/common/include/tests/common/coordinates.inl b/tests/common/include/tests/common/coordinates.inl deleted file mode 100644 index db64df2b8..000000000 --- a/tests/common/include/tests/common/coordinates.inl +++ /dev/null @@ -1,328 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -// Project include(s). -#include "detray/coordinates/coordinates.hpp" -#include "detray/tracks/tracks.hpp" - -// GTest include(s). -#include - -using namespace detray; -using point2 = __plugin::point2; -using point3 = __plugin::point3; -using vector3 = __plugin::vector3; -using transform3 = __plugin::transform3; -using matrix_operator = typename transform3::matrix_actor; - -const scalar isclose = 1e-5; - -// This test cartesian2 coordinate -TEST(test_host_basics, cartesian2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cartesian2 c2; - const point3 global1 = {4., 7., 4.}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = c2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], 2., isclose); - ASSERT_NEAR(local[1], 4., isclose); - - // Local to global transformation - const point3 global2 = c2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = c2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = c2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), 2., isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), 4., isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, - isclose); // atan(2) - ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, - isclose); // atan(sqrt(5)/3) - ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} - -// This test cartesian3 coordinate -TEST(test_host_basics, cartesian3) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cartesian3 c3; - const point3 global1 = {4., 7., 5.}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - struct dummy_mask { - } mask; - - // Global to local transformation - const point3 local = c3.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], 2., isclose); - ASSERT_NEAR(local[1], 4., isclose); - ASSERT_NEAR(local[2], 1., isclose); - - // Local to global transformation - const point3 global2 = c3.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); -} - -// This test polar2 coordinate -TEST(test_host_basics, polar2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const polar2 p2; - const point3 global1 = {4., 7., 4.}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = p2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], std::sqrt(20.), isclose); - ASSERT_NEAR(local[1], atan2(4., 2.), isclose); - - // Local to global transformation - const point3 global2 = p2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = p2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = p2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), std::sqrt(20.), isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), atan2(4., 2.), isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, - isclose); // atan(2) - ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, - isclose); // atan(sqrt(5)/3) - ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} - -// This test cylindrical2 coordinate -TEST(test_host_basics, cylindrical2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cylindrical2 c2; - // Global position on surface - const point3 global1 = {scalar{3.4142136}, scalar{4.4142136}, scalar{9.}}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - - // Define cylinder mask - struct cylinder_mask { - scalar r = 0.; - scalar radius() const { return r; } - }; - - const scalar r = 2.; - const cylinder_mask mask{r}; - - // Global to local transformation - const point2 local = c2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], r * scalar{M_PI_4}, isclose); - ASSERT_NEAR(local[1], 5., isclose); - - // Local to global transformation - const point3 global2 = c2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = c2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = c2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), r * scalar{M_PI_4}, isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), 5, isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, - isclose); // atan(2) - ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, - isclose); // atan(sqrt(5)/3) - ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} - -// This test cylindrical2 coordinate -TEST(test_host_basics, cylindrical3) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cylindrical3 c3; - const point3 global1 = {scalar{3.4142136}, scalar{4.4142136}, scalar{9.}}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - struct dummy_mask { - } mask; - - // Global to local transformation - const point3 local = c3.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], 2, isclose); - ASSERT_NEAR(local[1], M_PI_4, isclose); - ASSERT_NEAR(local[2], 5., isclose); - - // Local to global transformation - const point3 global2 = c3.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); -} - -// This test line2 coordinate -TEST(test_host_basics, line2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const line2 l2; - const point3 global1 = {3., 3., 9.}; - const vector3 mom = {0., 2., 0.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = l2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], -1., isclose); - ASSERT_NEAR(local[1], 5., isclose); - - // Local to global transformation - const point3 global2 = l2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = l2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = l2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), -1., isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), 5, isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 3, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 4, 0), -0.5, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} \ No newline at end of file diff --git a/tests/common/include/tests/common/covariance_engine.inl b/tests/common/include/tests/common/covariance_engine.inl index 386d6761a..81f60c612 100644 --- a/tests/common/include/tests/common/covariance_engine.inl +++ b/tests/common/include/tests/common/covariance_engine.inl @@ -5,12 +5,237 @@ * Mozilla Public License Version 2.0 */ -// detray include(s) +// Project include(s) #include "detray/definitions/units.hpp" -#include "detray/propagator/detail/covariance_kernel.hpp" +#include "detray/field/constant_magnetic_field.hpp" +#include "detray/propagator/actor_chain.hpp" +#include "detray/propagator/actors/bound_to_bound_updater.hpp" +#include "detray/propagator/actors/resetter.hpp" +#include "detray/propagator/line_stepper.hpp" +#include "detray/propagator/navigator.hpp" +#include "detray/propagator/propagator.hpp" +#include "detray/propagator/rk_stepper.hpp" #include "detray/tracks/tracks.hpp" +#include "tests/common/tools/create_telescope_detector.hpp" + +// Vecmem include(s). +#include // google-test include(s) #include -TEST(covariance_engine, jacobian_coordinate) {} \ No newline at end of file +using namespace detray; +using vector2 = __plugin::vector2; +using vector3 = __plugin::vector3; +using point3 = __plugin::point3; +using transform3 = __plugin::transform3; +using matrix_operator = standard_matrix_operator; +using mag_field_t = constant_magnetic_field<>; + +constexpr scalar epsilon = 1e-3; +constexpr scalar path_limit = 100 * unit_constants::cm; + +// This tests the covariance transport in rk stepper +TEST(covariance_transport, cartesian) { + + vecmem::host_memory_resource host_mr; + + using ln_stepper_t = line_stepper; + + // Use rectangular surfaces + constexpr bool rectangular = false; + + // Create telescope detector with a single plane + typename ln_stepper_t::free_track_parameters_type default_trk{ + {0, 0, 0}, 0, {1, 0, 0}, -1}; + std::vector positions = {0.}; + + const auto det = create_telescope_detector( + host_mr, positions, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}); + + using navigator_t = navigator; + using crk_stepper_t = + rk_stepper>; + using propagator_t = propagator>; + + // Generate track starting point + vector2 local{2, 3}; + vector3 mom{0.02, 0., 0.}; + scalar time = 0.; + scalar q = -1.; + + // bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = local[0]; + getter::element(bound_vector, e_bound_loc1, 0) = local[1]; + getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); + getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); + getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); + getter::element(bound_vector, e_bound_time, 0) = time; + + // bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; + getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; + + // Note: Set theta error as ZERO, to constrain the loc1 divergence + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; + getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + + // B field + vector3 B{0, 0, 1. * unit_constants::T}; + mag_field_t mag_field(B); + + // bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + typename propagator_t::state propagation{bound_param0, mag_field, det}; + crk_stepper_t::state &crk_state = propagation._stepping; + navigator_t::state &n_state = propagation._navigation; + + // Decrease tolerance down to 1e-8 + crk_state._tolerance = 1e-8; + + // RK stepper and its state + crk_stepper_t crk_stepper; + + /* + ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); + ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); + ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); + ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); + ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); + ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); + */ + /* + + // test surface + const vector3 u{0, 1, 0}; + const vector3 w{1, 0, 0}; + const vector3 t{0, 0, 0}; + const transform3 trf(t, w, u); + + // Generate track starting point + vector3 local{2, 3, 0}; + vector3 mom{0.02, 0., 0.}; + scalar time = 0.; + scalar q = -1.; + + // bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = local[0]; + getter::element(bound_vector, e_bound_loc1, 0) = local[1]; + getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); + getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); + getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); + getter::element(bound_vector, e_bound_time, 0) = time; + + // bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; + getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; + + // Note: Set theta error as ZERO, to constrain the loc1 divergence + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; + getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + + // B field + vector3 B{0, 0, 1. * unit_constants::T}; + mag_field_t mag_field(B); + + // bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + prop_state propagation{ + crk_stepper_t::state(bound_param0, trf, mag_field), nav_state{}}; + crk_stepper_t::state &crk_state = propagation._stepping; + nav_state &n_state = propagation._navigation; + + // Decrease tolerance down to 1e-8 + crk_state._tolerance = 1e-8; + + // RK stepper and its state + crk_stepper_t crk_stepper; + + ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); + ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); + ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); + ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); + ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); + ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); + + // helix trajectory + detail::helix helix(crk_state(), &B); + + // Path length per turn + scalar S = 2. * getter::norm(mom) / getter::norm(B) * M_PI; + + // Run stepper for one turn + unsigned int max_steps = 1e4; + for (unsigned int i = 0; i < max_steps; i++) { + + crk_state.set_constraint(S - crk_state.path_length()); + + n_state._step_size = S; + + crk_stepper.step(propagation); + + if (std::abs(S - crk_state.path_length()) < 1e-6) { + break; + } + + // Make sure that we didn't reach the end of for loop + ASSERT_TRUE(i < max_steps - 1); + } + + // Transport jacobian check + + auto jac_transport = crk_state._jac_transport; + auto true_J = helix.jacobian(crk_state.path_length()); + + for (std::size_t i = 0; i < e_free_size; i++) { + for (std::size_t j = 0; j < e_free_size; j++) { + EXPECT_NEAR(matrix_operator().element(jac_transport, i, j), + matrix_operator().element(true_J, i, j), + crk_state.path_length() * epsilon); + } + } + + // Bound parameters check + + // Bound state after one turn propagation + const auto bound_param1 = crk_stepper.bound_state(propagation, trf); + + const auto bound_vec0 = bound_param0.vector(); + const auto bound_vec1 = bound_param1.vector(); + + const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); + + // Check if the bound state stays the same after one turn propagation + + // vector + for (size_type i = 0; i < e_bound_size; i++) { + EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), + matrix_operator().element(bound_vec1, i, 0), epsilon); + } + + // covaraince + for (size_type i = 0; i < e_bound_size; i++) { + for (size_type j = 0; j < e_bound_size; j++) { + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), + crk_state.path_length() * epsilon); + } + } + */ +} \ No newline at end of file diff --git a/tests/common/include/tests/common/tools_stepper.inl b/tests/common/include/tests/common/tools_stepper.inl index 3a068039e..f7ed50c15 100644 --- a/tests/common/include/tests/common/tools_stepper.inl +++ b/tests/common/include/tests/common/tools_stepper.inl @@ -16,12 +16,8 @@ #include "detray/propagator/line_stepper.hpp" #include "detray/propagator/rk_stepper.hpp" #include "detray/tracks/tracks.hpp" -#include "tests/common/tools/create_telescope_detector.hpp" #include "tests/common/tools/track_generators.hpp" -// Vecmem include(s). -#include - // google-test include(s) #include @@ -230,206 +226,4 @@ TEST(ALGEBRA_PLUGIN, rk_stepper) { // Make sure that relative error is smaller than epsion EXPECT_NEAR(getter::norm(backward_relative_error), 0, epsilon); } -} - -// This tests the covariance transport in rk stepper -TEST(ALGEBRA_PLUGIN, covariance_transport) { - - vecmem::host_memory_resource host_mr; - - using ln_stepper_t = line_stepper; - - // Use rectangular surfaces - constexpr bool rectangular = false; - - // Create telescope detector with a single plane - typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {1, 0, 0}, -1}; - std::vector positions = {0.}; - - const auto det = create_telescope_detector( - host_mr, positions, ln_stepper_t(), - typename ln_stepper_t::state{default_trk}); - - // Generate track starting point - vector2 local{2, 3}; - vector3 mom{0.02, 0., 0.}; - scalar time = 0.; - scalar q = -1.; - - // bound vector - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = local[0]; - getter::element(bound_vector, e_bound_loc1, 0) = local[1]; - getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); - getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); - getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); - getter::element(bound_vector, e_bound_time, 0) = time; - - // bound covariance - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template zero(); - getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; - getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; - getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; - - // Note: Set theta error as ZERO, to constrain the loc1 divergence - getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; - getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; - getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; - - // B field - vector3 B{0, 0, 1. * unit_constants::T}; - mag_field_t mag_field(B); - - /* - // bound track parameter - const bound_track_parameters bound_param0(0, bound_vector, - bound_cov); - - prop_state propagation{ - crk_stepper_t::state(bound_param0, trf, mag_field), nav_state{det}}; - crk_stepper_t::state &crk_state = propagation._stepping; - nav_state &n_state = propagation._navigation; - - // Decrease tolerance down to 1e-8 - crk_state._tolerance = 1e-8; - - // RK stepper and its state - crk_stepper_t crk_stepper; - - ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); - ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); - ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); - ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); - ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); - ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); - */ - - /* - - // test surface - const vector3 u{0, 1, 0}; - const vector3 w{1, 0, 0}; - const vector3 t{0, 0, 0}; - const transform3 trf(t, w, u); - - // Generate track starting point - vector3 local{2, 3, 0}; - vector3 mom{0.02, 0., 0.}; - scalar time = 0.; - scalar q = -1.; - - // bound vector - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = local[0]; - getter::element(bound_vector, e_bound_loc1, 0) = local[1]; - getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); - getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); - getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); - getter::element(bound_vector, e_bound_time, 0) = time; - - // bound covariance - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template zero(); - getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; - getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; - getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; - - // Note: Set theta error as ZERO, to constrain the loc1 divergence - getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; - getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; - getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; - - // B field - vector3 B{0, 0, 1. * unit_constants::T}; - mag_field_t mag_field(B); - - // bound track parameter - const bound_track_parameters bound_param0(0, bound_vector, - bound_cov); - - prop_state propagation{ - crk_stepper_t::state(bound_param0, trf, mag_field), nav_state{}}; - crk_stepper_t::state &crk_state = propagation._stepping; - nav_state &n_state = propagation._navigation; - - // Decrease tolerance down to 1e-8 - crk_state._tolerance = 1e-8; - - // RK stepper and its state - crk_stepper_t crk_stepper; - - ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); - ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); - ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); - ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); - ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); - ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); - - // helix trajectory - detail::helix helix(crk_state(), &B); - - // Path length per turn - scalar S = 2. * getter::norm(mom) / getter::norm(B) * M_PI; - - // Run stepper for one turn - unsigned int max_steps = 1e4; - for (unsigned int i = 0; i < max_steps; i++) { - - crk_state.set_constraint(S - crk_state.path_length()); - - n_state._step_size = S; - - crk_stepper.step(propagation); - - if (std::abs(S - crk_state.path_length()) < 1e-6) { - break; - } - - // Make sure that we didn't reach the end of for loop - ASSERT_TRUE(i < max_steps - 1); - } - - // Transport jacobian check - - auto jac_transport = crk_state._jac_transport; - auto true_J = helix.jacobian(crk_state.path_length()); - - for (std::size_t i = 0; i < e_free_size; i++) { - for (std::size_t j = 0; j < e_free_size; j++) { - EXPECT_NEAR(matrix_operator().element(jac_transport, i, j), - matrix_operator().element(true_J, i, j), - crk_state.path_length() * epsilon); - } - } - - // Bound parameters check - - // Bound state after one turn propagation - const auto bound_param1 = crk_stepper.bound_state(propagation, trf); - - const auto bound_vec0 = bound_param0.vector(); - const auto bound_vec1 = bound_param1.vector(); - - const auto bound_cov0 = bound_param0.covariance(); - const auto bound_cov1 = bound_param1.covariance(); - - // Check if the bound state stays the same after one turn propagation - - // vector - for (size_type i = 0; i < e_bound_size; i++) { - EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), - matrix_operator().element(bound_vec1, i, 0), epsilon); - } - - // covaraince - for (size_type i = 0; i < e_bound_size; i++) { - for (size_type j = 0; j < e_bound_size; j++) { - EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), - matrix_operator().element(bound_cov1, i, j), - crk_state.path_length() * epsilon); - } - } - */ } \ No newline at end of file diff --git a/tests/unit_tests/array/CMakeLists.txt b/tests/unit_tests/array/CMakeLists.txt index 1e3f7cce3..7959f124b 100644 --- a/tests/unit_tests/array/CMakeLists.txt +++ b/tests/unit_tests/array/CMakeLists.txt @@ -6,7 +6,9 @@ # Set up all of the "standard" tests. detray_add_test( array - "array_actor_chain.cpp" "array_annulus2.cpp" "array_container.cpp" "array_coordinates.cpp" + "array_actor_chain.cpp" "array_annulus2.cpp" "array_container.cpp" + "array_coordinate_cartesian2.cpp" "array_coordinate_cartesian3.cpp" "array_coordinate_cylindrical2.cpp" + "array_coordinate_cylindrical3.cpp" "array_coordinate_line2.cpp" "array_coordinate_polar2.cpp" "array_core.cpp" "array_covariance_engine.cpp" "array_cylinder_intersection.cpp" "array_cylinder3.cpp" "array_detector.cpp" "array_geometry_volume_graph.cpp" "array_geometry_linking.cpp" diff --git a/tests/unit_tests/array/array_coordinate_cartesian2.cpp b/tests/unit_tests/array/array_coordinate_cartesian2.cpp new file mode 100644 index 000000000..f6a1ca99c --- /dev/null +++ b/tests/unit_tests/array/array_coordinate_cartesian2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/array_definitions.hpp" +#include "tests/common/coordinate_cartesian2.inl" \ No newline at end of file diff --git a/tests/unit_tests/array/array_coordinate_cartesian3.cpp b/tests/unit_tests/array/array_coordinate_cartesian3.cpp new file mode 100644 index 000000000..07da64154 --- /dev/null +++ b/tests/unit_tests/array/array_coordinate_cartesian3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/array_definitions.hpp" +#include "tests/common/coordinate_cartesian3.inl" \ No newline at end of file diff --git a/tests/unit_tests/array/array_coordinate_cylindrical2.cpp b/tests/unit_tests/array/array_coordinate_cylindrical2.cpp new file mode 100644 index 000000000..0b981467b --- /dev/null +++ b/tests/unit_tests/array/array_coordinate_cylindrical2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/array_definitions.hpp" +#include "tests/common/coordinate_cylindrical2.inl" \ No newline at end of file diff --git a/tests/unit_tests/array/array_coordinate_cylindrical3.cpp b/tests/unit_tests/array/array_coordinate_cylindrical3.cpp new file mode 100644 index 000000000..31195c45a --- /dev/null +++ b/tests/unit_tests/array/array_coordinate_cylindrical3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/array_definitions.hpp" +#include "tests/common/coordinate_cylindrical3.inl" \ No newline at end of file diff --git a/tests/unit_tests/array/array_coordinates.cpp b/tests/unit_tests/array/array_coordinate_line2.cpp similarity index 82% rename from tests/unit_tests/array/array_coordinates.cpp rename to tests/unit_tests/array/array_coordinate_line2.cpp index 4d3e112ed..b87112ab6 100644 --- a/tests/unit_tests/array/array_coordinates.cpp +++ b/tests/unit_tests/array/array_coordinate_line2.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/array_definitions.hpp" -#include "tests/common/coordinates.inl" +#include "tests/common/coordinate_line2.inl" \ No newline at end of file diff --git a/tests/unit_tests/array/array_coordinate_polar2.cpp b/tests/unit_tests/array/array_coordinate_polar2.cpp new file mode 100644 index 000000000..2d06429e5 --- /dev/null +++ b/tests/unit_tests/array/array_coordinate_polar2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/array_definitions.hpp" +#include "tests/common/coordinate_polar2.inl" \ No newline at end of file diff --git a/tests/unit_tests/cuda/rk_stepper_cuda.cpp b/tests/unit_tests/cuda/rk_stepper_cuda.cpp index 77df05161..58063c775 100644 --- a/tests/unit_tests/cuda/rk_stepper_cuda.cpp +++ b/tests/unit_tests/cuda/rk_stepper_cuda.cpp @@ -60,7 +60,7 @@ TEST(rk_stepper_cuda, bound_state) { mag_field_t mag_field(B); prop_state propagation{ - crk_stepper_t::state(in_param, trf, mag_field), nav_state{}}; + crk_stepper_t::state(in_param, mag_field), nav_state{}}; crk_stepper_t::state &crk_state = propagation._stepping; nav_state &n_state = propagation._navigation; diff --git a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu index 107acee81..7f2095391 100644 --- a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu +++ b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu @@ -22,7 +22,7 @@ __global__ void bound_state_test_kernel( mag_field_t mag_field(B); prop_state propagation{ - crk_stepper_t::state(in_param, trf, mag_field), nav_state{}}; + crk_stepper_t::state(in_param, mag_field), nav_state{}}; crk_stepper_t::state &crk_state = propagation._stepping; nav_state &n_state = propagation._navigation; diff --git a/tests/unit_tests/eigen/CMakeLists.txt b/tests/unit_tests/eigen/CMakeLists.txt index 7dd1f3b60..89d03313c 100644 --- a/tests/unit_tests/eigen/CMakeLists.txt +++ b/tests/unit_tests/eigen/CMakeLists.txt @@ -6,7 +6,9 @@ # Set up all of the "standard" tests. detray_add_test( eigen - "eigen_actor_chain.cpp" "eigen_annulus2.cpp" "eigen_container.cpp" "eigen_coordinates.cpp" + "eigen_actor_chain.cpp" "eigen_annulus2.cpp" "eigen_container.cpp" + "eigen_coordinate_cartesian2.cpp" "eigen_coordinate_cartesian3.cpp" "eigen_coordinate_cylindrical2.cpp" + "eigen_coordinate_cylindrical3.cpp" "eigen_coordinate_line2.cpp" "eigen_coordinate_polar2.cpp" "eigen_core.cpp" "eigen_covariance_engine.cpp" "eigen_cylinder_intersection.cpp" "eigen_cylinder3.cpp" "eigen_detector.cpp" "eigen_geometry_volume_graph.cpp" "eigen_geometry_linking.cpp" diff --git a/tests/unit_tests/eigen/eigen_coordinate_cartesian2.cpp b/tests/unit_tests/eigen/eigen_coordinate_cartesian2.cpp new file mode 100644 index 000000000..8ff588882 --- /dev/null +++ b/tests/unit_tests/eigen/eigen_coordinate_cartesian2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/eigen_definitions.hpp" +#include "tests/common/coordinate_cartesian2.inl" \ No newline at end of file diff --git a/tests/unit_tests/eigen/eigen_coordinate_cartesian3.cpp b/tests/unit_tests/eigen/eigen_coordinate_cartesian3.cpp new file mode 100644 index 000000000..ff767ecfe --- /dev/null +++ b/tests/unit_tests/eigen/eigen_coordinate_cartesian3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/eigen_definitions.hpp" +#include "tests/common/coordinate_cartesian3.inl" \ No newline at end of file diff --git a/tests/unit_tests/eigen/eigen_coordinate_cylindrical2.cpp b/tests/unit_tests/eigen/eigen_coordinate_cylindrical2.cpp new file mode 100644 index 000000000..aa4f0ae3c --- /dev/null +++ b/tests/unit_tests/eigen/eigen_coordinate_cylindrical2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/eigen_definitions.hpp" +#include "tests/common/coordinate_cylindrical2.inl" \ No newline at end of file diff --git a/tests/unit_tests/eigen/eigen_coordinate_cylindrical3.cpp b/tests/unit_tests/eigen/eigen_coordinate_cylindrical3.cpp new file mode 100644 index 000000000..7a67e3857 --- /dev/null +++ b/tests/unit_tests/eigen/eigen_coordinate_cylindrical3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/eigen_definitions.hpp" +#include "tests/common/coordinate_cylindrical3.inl" \ No newline at end of file diff --git a/tests/unit_tests/eigen/eigen_coordinates.cpp b/tests/unit_tests/eigen/eigen_coordinate_line2.cpp similarity index 82% rename from tests/unit_tests/eigen/eigen_coordinates.cpp rename to tests/unit_tests/eigen/eigen_coordinate_line2.cpp index a4a961581..017406573 100644 --- a/tests/unit_tests/eigen/eigen_coordinates.cpp +++ b/tests/unit_tests/eigen/eigen_coordinate_line2.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/eigen_definitions.hpp" -#include "tests/common/coordinates.inl" \ No newline at end of file +#include "tests/common/coordinate_line2.inl" \ No newline at end of file diff --git a/tests/unit_tests/eigen/eigen_coordinate_polar2.cpp b/tests/unit_tests/eigen/eigen_coordinate_polar2.cpp new file mode 100644 index 000000000..f148e848f --- /dev/null +++ b/tests/unit_tests/eigen/eigen_coordinate_polar2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/eigen_definitions.hpp" +#include "tests/common/coordinate_polar2.inl" \ No newline at end of file diff --git a/tests/unit_tests/smatrix/CMakeLists.txt b/tests/unit_tests/smatrix/CMakeLists.txt index 48da55964..4d9b78314 100644 --- a/tests/unit_tests/smatrix/CMakeLists.txt +++ b/tests/unit_tests/smatrix/CMakeLists.txt @@ -6,7 +6,9 @@ # Set up all of the "standard" tests. detray_add_test( smatrix - "smatrix_actor_chain.cpp" "smatrix_annulus2.cpp" "smatrix_container.cpp" "smatrix_coordinates.cpp" + "smatrix_actor_chain.cpp" "smatrix_annulus2.cpp" "smatrix_container.cpp" + "smatrix_coordinate_cartesian2.cpp" "smatrix_coordinate_cartesian3.cpp" "smatrix_coordinate_cylindrical.cpp" + "vc_array_coordinate_cylindrical3.cpp" "smatrix_coordinate_line2.cpp" "smatrix_coordinate_polar2.cpp" "smatrix_core.cpp" "smatrix_covariance_engine.cpp" "smatrix_cylinder_intersection.cpp" "smatrix_cylinder3.cpp" "smatrix_detector.cpp" "smatrix_geometry_volume_graph.cpp" diff --git a/tests/unit_tests/smatrix/smatrix_coordinate_cartesian2.cpp b/tests/unit_tests/smatrix/smatrix_coordinate_cartesian2.cpp new file mode 100644 index 000000000..671a55218 --- /dev/null +++ b/tests/unit_tests/smatrix/smatrix_coordinate_cartesian2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/smatrix_definitions.hpp" +#include "tests/common/coordinate_cartesian2.inl" \ No newline at end of file diff --git a/tests/unit_tests/smatrix/smatrix_coordinate_cartesian3.cpp b/tests/unit_tests/smatrix/smatrix_coordinate_cartesian3.cpp new file mode 100644 index 000000000..d3aba71ae --- /dev/null +++ b/tests/unit_tests/smatrix/smatrix_coordinate_cartesian3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/smatrix_definitions.hpp" +#include "tests/common/coordinate_cartesian3.inl" \ No newline at end of file diff --git a/tests/unit_tests/smatrix/smatrix_coordinate_cylindrical2.cpp b/tests/unit_tests/smatrix/smatrix_coordinate_cylindrical2.cpp new file mode 100644 index 000000000..769044bd9 --- /dev/null +++ b/tests/unit_tests/smatrix/smatrix_coordinate_cylindrical2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/smatrix_definitions.hpp" +#include "tests/common/coordinate_cylindrical2.inl" \ No newline at end of file diff --git a/tests/unit_tests/smatrix/smatrix_coordinate_cylindrical3.cpp b/tests/unit_tests/smatrix/smatrix_coordinate_cylindrical3.cpp new file mode 100644 index 000000000..4385c315b --- /dev/null +++ b/tests/unit_tests/smatrix/smatrix_coordinate_cylindrical3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/smatrix_definitions.hpp" +#include "tests/common/coordinate_cylindrical3.inl" \ No newline at end of file diff --git a/tests/unit_tests/smatrix/smatrix_coordinates.cpp b/tests/unit_tests/smatrix/smatrix_coordinate_line2.cpp similarity index 83% rename from tests/unit_tests/smatrix/smatrix_coordinates.cpp rename to tests/unit_tests/smatrix/smatrix_coordinate_line2.cpp index b35385cc4..26d8a9170 100644 --- a/tests/unit_tests/smatrix/smatrix_coordinates.cpp +++ b/tests/unit_tests/smatrix/smatrix_coordinate_line2.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/smatrix_definitions.hpp" -#include "tests/common/coordinates.inl" \ No newline at end of file +#include "tests/common/coordinate_line2.inl" \ No newline at end of file diff --git a/tests/unit_tests/smatrix/smatrix_coordinate_polar2.cpp b/tests/unit_tests/smatrix/smatrix_coordinate_polar2.cpp new file mode 100644 index 000000000..cd1563a69 --- /dev/null +++ b/tests/unit_tests/smatrix/smatrix_coordinate_polar2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/smatrix_definitions.hpp" +#include "tests/common/coordinate_polar2.inl" \ No newline at end of file diff --git a/tests/unit_tests/vc/CMakeLists.txt b/tests/unit_tests/vc/CMakeLists.txt index 2ac4cf172..5c7a47f98 100644 --- a/tests/unit_tests/vc/CMakeLists.txt +++ b/tests/unit_tests/vc/CMakeLists.txt @@ -6,8 +6,10 @@ # Set up all of the "standard" tests. detray_add_test( vc_array - "vc_array_actor_chain.cpp" "vc_array_annulus2.cpp" "vc_array_container.cpp" "vc_array_coordinates.cpp" "vc_array_core.cpp" - "vc_array_covariance_engine.cpp" "vc_array_cylinder_intersection.cpp" + "vc_array_actor_chain.cpp" "vc_array_annulus2.cpp" "vc_array_container.cpp" + "vc_array_coordinate_cartesian2.cpp" "vc_array_coordinate_cartesian3.cpp" "vc_array_coordinate_cylindrical2.cpp" + "vc_array_coordinate_cylindrical3.cpp" "vc_array_coordinate_line2.cpp" "vc_array_coordinate_polar2.cpp" + "vc_array_core.cpp" "vc_array_covariance_engine.cpp" "vc_array_cylinder_intersection.cpp" "vc_array_cylinder3.cpp" "vc_array_detector.cpp" "vc_array_geometry_volume_graph.cpp" "vc_array_geometry_linking.cpp" "vc_array_geometry_navigation.cpp" "vc_array_geometry_scan.cpp" "vc_array_guided_navigator.cpp" diff --git a/tests/unit_tests/vc/vc_array_coordinate_cartesian2.cpp b/tests/unit_tests/vc/vc_array_coordinate_cartesian2.cpp new file mode 100644 index 000000000..b7930f78d --- /dev/null +++ b/tests/unit_tests/vc/vc_array_coordinate_cartesian2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/vc_array_definitions.hpp" +#include "tests/common/coordinate_cartesian2.inl" \ No newline at end of file diff --git a/tests/unit_tests/vc/vc_array_coordinate_cartesian3.cpp b/tests/unit_tests/vc/vc_array_coordinate_cartesian3.cpp new file mode 100644 index 000000000..7c07bb0b9 --- /dev/null +++ b/tests/unit_tests/vc/vc_array_coordinate_cartesian3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/vc_array_definitions.hpp" +#include "tests/common/coordinate_cartesian3.inl" \ No newline at end of file diff --git a/tests/unit_tests/vc/vc_array_coordinate_cylindrical2.cpp b/tests/unit_tests/vc/vc_array_coordinate_cylindrical2.cpp new file mode 100644 index 000000000..cfb3612c1 --- /dev/null +++ b/tests/unit_tests/vc/vc_array_coordinate_cylindrical2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/vc_array_definitions.hpp" +#include "tests/common/coordinate_cylindrical2.inl" \ No newline at end of file diff --git a/tests/unit_tests/vc/vc_array_coordinate_cylindrical3.cpp b/tests/unit_tests/vc/vc_array_coordinate_cylindrical3.cpp new file mode 100644 index 000000000..8535f838b --- /dev/null +++ b/tests/unit_tests/vc/vc_array_coordinate_cylindrical3.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/vc_array_definitions.hpp" +#include "tests/common/coordinate_cylindrical3.inl" \ No newline at end of file diff --git a/tests/unit_tests/vc/vc_array_coordinates.cpp b/tests/unit_tests/vc/vc_array_coordinate_line2.cpp similarity index 83% rename from tests/unit_tests/vc/vc_array_coordinates.cpp rename to tests/unit_tests/vc/vc_array_coordinate_line2.cpp index c9471ae18..971485af7 100644 --- a/tests/unit_tests/vc/vc_array_coordinates.cpp +++ b/tests/unit_tests/vc/vc_array_coordinate_line2.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/vc_array_definitions.hpp" -#include "tests/common/coordinates.inl" \ No newline at end of file +#include "tests/common/coordinate_line2.inl" \ No newline at end of file diff --git a/tests/unit_tests/vc/vc_array_coordinate_polar2.cpp b/tests/unit_tests/vc/vc_array_coordinate_polar2.cpp new file mode 100644 index 000000000..3cfc52775 --- /dev/null +++ b/tests/unit_tests/vc/vc_array_coordinate_polar2.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/vc_array_definitions.hpp" +#include "tests/common/coordinate_polar2.inl" \ No newline at end of file From 913f605ba3df8a35ab664aa2da9c286182355942 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 1 Sep 2022 20:54:40 -0700 Subject: [PATCH 12/63] Backup --- .../detray/propagator/actors/resetter.hpp | 36 ++++++++++++++++++- core/include/detray/propagator/propagator.hpp | 2 +- core/include/detray/propagator/rk_stepper.hpp | 21 ++++++++--- .../tests/common/covariance_engine.inl | 27 ++++++++++++-- tests/unit_tests/cuda/rk_stepper_cuda.cpp | 19 +++++----- .../unit_tests/cuda/rk_stepper_cuda_kernel.cu | 3 +- 6 files changed, 88 insertions(+), 20 deletions(-) diff --git a/core/include/detray/propagator/actors/resetter.hpp b/core/include/detray/propagator/actors/resetter.hpp index ea6e4e50b..591e6d888 100644 --- a/core/include/detray/propagator/actors/resetter.hpp +++ b/core/include/detray/propagator/actors/resetter.hpp @@ -32,6 +32,37 @@ struct resetter : actor { using output_type = bool; + template + DETRAY_HOST_DEVICE inline output_type operator()( + const mask_group_t& mask_group, const transform_store_t& trf_store, + const surface_t& surface, stepper_state_t& stepping) { + + const auto& trf3 = trf_store[surface.transform()]; + + // Note: How is it possible with "range"??? + const auto& mask = mask_group[surface.mask_range()]; + + auto local_coordinate = mask.local(); + + // Reset the free vector + stepping().set_vector(local_coordinate.bound_to_free_vector( + trf3, mask, stepping._bound_params.vector())); + + // Reset the path length + stepping._s = 0; + + // Reset jacobian coordinate transformation at the current surface + stepping._jac_to_global = local_coordinate.bound_to_free_jacobian( + trf3, mask, stepping._bound_params.vector()); + + // Reset jacobian transport to identity matrix + matrix_actor().set_identity(stepping._jac_transport); + + return true; + } + + /* template DETRAY_HOST_DEVICE inline output_type operator()( @@ -68,18 +99,21 @@ struct resetter : actor { return true; } + */ }; template DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const { auto& navigation = propagation._navigation; + auto& stepping = propagation._stepping; // Do covariance transport when the track is on surface if (navigation.is_on_module()) { const auto& det = navigation.detector(); const auto& surface_container = det->surfaces(); + const auto& trf_store = det->transform_store(); const auto& mask_store = det->mask_store(); // Intersection @@ -89,7 +123,7 @@ struct resetter : actor { const auto& surface = surface_container[is->index]; auto succeed = mask_store.template execute( - surface.mask_type(), surface, propagation); + surface.mask_type(), trf_store, surface, stepping); } } }; diff --git a/core/include/detray/propagator/propagator.hpp b/core/include/detray/propagator/propagator.hpp index 93af00c17..5ac2dfef2 100644 --- a/core/include/detray/propagator/propagator.hpp +++ b/core/include/detray/propagator/propagator.hpp @@ -92,7 +92,7 @@ struct propagator { const field_type &magnetic_field, const detector_type &det, typename actor_chain_t::state actor_states = {}, vector_type &&candidates = {}) - : _stepping(param, magnetic_field), + : _stepping(param, magnetic_field, det), _navigation(det, std::move(candidates)), _actor_states(actor_states) {} diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index f1372f5c0..9c4321211 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -10,6 +10,7 @@ // Project include(s). #include "detray/definitions/qualifiers.hpp" #include "detray/definitions/units.hpp" +#include "detray/propagator/actors/resetter.hpp" #include "detray/propagator/base_stepper.hpp" #include "detray/propagator/detail/covariance_engine.hpp" #include "detray/propagator/detail/covariance_kernel.hpp" @@ -60,10 +61,22 @@ class rk_stepper final const magnetic_field_t mag_field) : base_type::state(t), _magnetic_field(mag_field) {} - DETRAY_HOST_DEVICE - state(const bound_track_parameters_type& bound_params, - const field_type mag_field) - : base_type::state(bound_params), _magnetic_field(mag_field) {} + template + DETRAY_HOST_DEVICE state( + const bound_track_parameters_type& bound_params, + const field_type mag_field, const detector_t& det) + : base_type::state(bound_params), _magnetic_field(mag_field) { + + const auto& surface_container = det.surfaces(); + const auto& trf_store = det.transform_store(); + const auto& mask_store = det.mask_store(); + const auto& surface = + surface_container[bound_params.surface_link()]; + + mask_store + .template execute::kernel>( + surface.mask_type(), trf_store, surface, *this); + } /// error tolerance scalar _tolerance = 1e-4; diff --git a/tests/common/include/tests/common/covariance_engine.inl b/tests/common/include/tests/common/covariance_engine.inl index 81f60c612..96ee158c6 100644 --- a/tests/common/include/tests/common/covariance_engine.inl +++ b/tests/common/include/tests/common/covariance_engine.inl @@ -104,14 +104,37 @@ TEST(covariance_transport, cartesian) { // RK stepper and its state crk_stepper_t crk_stepper; - /* ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); - */ + + // helix trajectory + detail::helix helix(crk_state(), &B); + + // Path length per turn + scalar S = 2. * getter::norm(mom) / getter::norm(B) * M_PI; + + // Run stepper for one turn + unsigned int max_steps = 1e4; + for (unsigned int i = 0; i < max_steps; i++) { + + crk_state.set_constraint(S - crk_state.path_length()); + + // n_state._step_size = S; + + crk_stepper.step(propagation); + + if (std::abs(S - crk_state._s) < 1e-6) { + break; + } + + // Make sure that we didn't reach the end of for loop + ASSERT_TRUE(i < max_steps - 1); + } + /* // test surface diff --git a/tests/unit_tests/cuda/rk_stepper_cuda.cpp b/tests/unit_tests/cuda/rk_stepper_cuda.cpp index 58063c775..2e8eb6a9f 100644 --- a/tests/unit_tests/cuda/rk_stepper_cuda.cpp +++ b/tests/unit_tests/cuda/rk_stepper_cuda.cpp @@ -13,7 +13,7 @@ #include "rk_stepper_cuda_kernel.hpp" TEST(rk_stepper_cuda, bound_state) { - + /* // VecMem memory resource(s) vecmem::cuda::managed_memory_resource mng_mr; @@ -54,9 +54,7 @@ TEST(rk_stepper_cuda, bound_state) { bound_cov); const vector3 B{0, 0, 1. * unit_constants::T}; - /** - * Get CPU bound parameter after one turn - */ + // Get CPU bound parameter after one turn mag_field_t mag_field(B); prop_state propagation{ @@ -95,17 +93,15 @@ TEST(rk_stepper_cuda, bound_state) { // Bound state after one turn propagation const auto out_param_cpu = crk_stepper.bound_state(propagation, trf); - /** - * Get CUDA bound parameter after one turn - */ + // Get CUDA bound parameter after one turn + vecmem::vector> out_param_cuda(1, &mng_mr); bound_state_test(vecmem::get_data(out_param_cuda), in_param, B, trf); - /** - * Compare CPU and CUDA - */ + // Compare CPU and CUDA + const auto bvec_cpu = out_param_cpu.vector(); const auto bcov_cpu = out_param_cpu.covariance(); @@ -122,5 +118,6 @@ TEST(rk_stepper_cuda, bound_state) { EXPECT_NEAR(matrix_operator().element(bcov_cpu, i, j), matrix_operator().element(bcov_cuda, i, j), epsilon); } - } + } + */ } \ No newline at end of file diff --git a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu index 7f2095391..bf4dabc0c 100644 --- a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu +++ b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu @@ -16,7 +16,7 @@ __global__ void bound_state_test_kernel( vecmem::data::vector_view> out_param, const bound_track_parameters in_param, const vector3 B, const transform3 trf) { - + /* vecmem::device_vector> out_param_cuda( out_param); @@ -52,6 +52,7 @@ __global__ void bound_state_test_kernel( // Bound state after one turn propagation out_param_cuda[0] = crk_stepper.bound_state(propagation, trf); + */ } void bound_state_test( From 20933ccf71a80dfb03f7eaf85452f566f3fccc21 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Fri, 2 Sep 2022 17:01:58 -0700 Subject: [PATCH 13/63] Backup --- .../detray/coordinates/coordinate_base.hpp | 31 +++++-- .../intersection/detail/trajectories.hpp | 3 +- .../detray/propagator/actors/aborters.hpp | 41 +++++++++ .../actors/bound_to_bound_updater.hpp | 31 +++++-- core/include/detray/propagator/navigator.hpp | 32 ++++++- core/include/detray/propagator/propagator.hpp | 2 + core/include/detray/propagator/rk_stepper.ipp | 1 + .../detray/tracks/bound_track_parameters.hpp | 4 +- .../tests/common/covariance_engine.inl | 91 +++++++++++++++---- 9 files changed, 199 insertions(+), 37 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index f1d57bda9..e3cb64e85 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -218,29 +218,29 @@ struct coordinate_base { const auto s = stepping._s; // helix - helix hlx(stepping(), stepping._step_data.b_last); + helix hlx(stepping(), &stepping._step_data.b_last); // B field at the destination surface - const matrix_type<1, 3> h; + matrix_type<1, 3> h; matrix_actor().set_block(h, hlx._h0, 0, 0); // dir - const matrix_type<1, 3> t; + matrix_type<1, 3> t; matrix_actor().set_block(t, hlx._t0, 0, 0); // Normalized vector of h X t - const matrix_type<1, 3> n; + matrix_type<1, 3> n; matrix_actor().set_block(n, hlx._n0, 0, 0); // Surface normal vector (w) - const matrix_type<1, 3> w; + matrix_type<1, 3> w; const auto normal = Derived().normal(trf3, mask, hlx.pos(), hlx._t0); matrix_actor().set_block(w, normal, 0, 0); // w cross h - const matrix_type<1, 3> wh; - matrix_actor().set_block(w, vector::cross(w, h), 0, 0); + matrix_type<1, 3> wh; + matrix_actor().set_block(wh, vector::cross(normal, hlx._h0), 0, 0); // Alpha const scalar_type A = hlx._alpha; @@ -259,14 +259,19 @@ struct coordinate_base { // t correction term matrix_type<1, 3> t_term = matrix_actor().template zero<1, 3>(); - t_term = t_term + (Ks - std::sin(Ks)) / K * vector::dot(h, w) * h; + t_term = + t_term + (Ks - std::sin(Ks)) / K * vector::dot(hlx._h0, normal) * h; t_term = t_term + std::sin(Ks) / K * w; t_term = t_term + (1 - std::cos(Ks)) / K * wh; t_term = -1. / wt * t_term; + printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), + matrix_actor().element(t_term, 0, 1), + matrix_actor().element(t_term, 0, 2)); + // qoverp correction term const scalar_type L_term = - -1. / wt * A * Ks / hlx.qop() * vector::dot(w, n); + -1. / wt * A * Ks / hlx.qop() * vector::dot(normal, hlx._n0); // transpose of t const matrix_type<3, 1> t_T = matrix_actor().transpose(t); @@ -293,6 +298,14 @@ struct coordinate_base { // dt/dL0 const matrix_type<3, 1> dtdL0 = AK * n_T * L_term; + for (std::size_t i = 0; i < 3; i++) { + for (std::size_t j = 0; j < 3; j++) { + printf("%f ", matrix_actor().element(drdt0, i, j)); + } + printf("\n"); + } + printf("\n"); + matrix_actor().template set_block<3, 3>(path_correction, drdr0, e_free_pos0, e_free_pos0); diff --git a/core/include/detray/intersection/detail/trajectories.hpp b/core/include/detray/intersection/detail/trajectories.hpp index 419bf40dd..f7ec11667 100644 --- a/core/include/detray/intersection/detail/trajectories.hpp +++ b/core/include/detray/intersection/detail/trajectories.hpp @@ -106,6 +106,8 @@ class helix : public free_track_parameters { // Column wise operator using column_wise_op = column_wise_operator; + using free_track_parameters_type::pos; + DETRAY_HOST_DEVICE helix() = delete; @@ -279,7 +281,6 @@ class helix : public free_track_parameters { return ret; } - private: /// B field vector3 const *_mag_field; diff --git a/core/include/detray/propagator/actors/aborters.hpp b/core/include/detray/propagator/actors/aborters.hpp index f074eba7c..2c5aaed4a 100644 --- a/core/include/detray/propagator/actors/aborters.hpp +++ b/core/include/detray/propagator/actors/aborters.hpp @@ -62,4 +62,45 @@ struct pathlimit_aborter : actor { } }; +struct looper : actor { + + struct state { + scalar loop_length = 0; + dindex target_surface_index = dindex_invalid; + }; + + /// Enforces the path limit on a stepper state + /// + /// @param abrt_state contains the path limit + /// @param prop_state state of the propagation + template + DETRAY_HOST_DEVICE void operator()(state &actor_state, + propagator_state_t &prop_state) const { + + prop_state._heartbeat = true; + auto &navigation = prop_state._navigation; + auto &stepping = prop_state._stepping; + navigation.set_full_trust(); + + scalar residual = actor_state.loop_length - stepping.path_length(); + stepping.set_constraint(residual); + + typename propagator_state_t::navigator_state_type::intersection_t is; + is.index = actor_state.target_surface_index; + is.path = residual; + auto &candidates = navigation.candidates(); + candidates.clear(); + candidates.push_back(is); + navigation.set_next(candidates.begin()); + navigation.set_unknown(); + + if (residual < std::abs(1e-5)) { + prop_state._heartbeat = false; + candidates.push_back({}); + navigation.next()++; + navigation.set_on_module(); + } + } +}; + } // namespace detray diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp index 72a78d40c..0a503f477 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -77,7 +77,7 @@ struct bound_to_bound_updater : actor { // Mask const auto& mask = mask_group[is->mask_index]; - auto local_coordinate = mask.local_type(); + auto local_coordinate = mask.local(); // Free vector const auto& free_vec = stepping().vector(); @@ -97,22 +97,39 @@ struct bound_to_bound_updater : actor { free_matrix path_correction = local_coordinate.path_correction(stepping, trf3, mask); + for (std::size_t i = 0; i < e_free_size; i++) { + for (std::size_t j = 0; j < e_free_size; j++) { + printf("%f ", + matrix_actor().element(path_correction, i, j)); + } + printf("\n"); + } + + printf("\n"); + // Bound to free jacobian at the departure surface const bound_to_free_matrix& bound_to_free_jacobian = stepping._jac_to_global; - // Calculate surface-to-surface covariance transport - stepping._bound_params.set_covaraince( + const bound_matrix full_jacobian = free_to_bound_jacobian * (path_correction + free_transport_jacobian) * - bound_to_free_jacobian); + bound_to_free_jacobian; + + const bound_matrix new_cov = + full_jacobian * stepping._bound_params.covariance() * + matrix_actor().transpose(full_jacobian); + + // Calculate surface-to-surface covariance transport + stepping._bound_params.set_covariance(new_cov); return true; } }; template - DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const { + DETRAY_HOST_DEVICE void operator()(state& /*actor_state*/, + propagator_state_t& propagation) const { auto& navigation = propagation._navigation; @@ -129,8 +146,8 @@ struct bound_to_bound_updater : actor { // Surface const auto& surface = surface_container[is->index]; - auto succeed = mask_store.template execute( - surface.mask_type(), surface, propagation); + mask_store.template execute(surface.mask_type(), surface, + propagation); } } }; diff --git a/core/include/detray/propagator/navigator.hpp b/core/include/detray/propagator/navigator.hpp index 0b4cf0197..fdae8494c 100644 --- a/core/include/detray/propagator/navigator.hpp +++ b/core/include/detray/propagator/navigator.hpp @@ -110,6 +110,7 @@ class navigator { public: using detector_type = navigator::detector_type; + using intersection_t = typename navigator::intersection_type; /// Default constructor state() = default; @@ -136,6 +137,30 @@ class navigator { DETRAY_HOST_DEVICE scalar operator()() const { return _next->path; } + DETRAY_HOST_DEVICE + inline void set_unknown() { _status = navigation::status::e_unknown; } + + DETRAY_HOST_DEVICE + inline void set_on_module() { + _status = navigation::status::e_on_module; + } + + /// Updates the iterator position of the last valid candidate + DETRAY_HOST_DEVICE + inline void set_next(candidate_itr_t &&new_next) { + _next = std::move(new_next); + } + + /// @returns next object that we want to reach (current target) + DETRAY_HOST_DEVICE + inline auto next() -> candidate_itr_t & { return _next; } + + /// @returns next object that we want to reach (current target) - const + DETRAY_HOST_DEVICE + inline auto next() const -> const const_candidate_itr_t & { + return _next; + } + /// @returns currently cached candidates - const DETRAY_HOST_DEVICE inline auto candidates() const @@ -162,11 +187,13 @@ class navigator { return _next - 1; } + /* /// @returns next object that we want to reach (current target) - const DETRAY_HOST_DEVICE inline auto next() const -> const const_candidate_itr_t & { return _next; } + */ /// @returns last valid candidate (by position in the cache) - const DETRAY_HOST_DEVICE @@ -322,15 +349,18 @@ class navigator { candidate.path >= track.overstep_tolerance(); } + /* /// @returns next object that we want to reach (current target) DETRAY_HOST_DEVICE inline auto next() -> candidate_itr_t & { return _next; } - + */ + /* /// Updates the iterator position of the last valid candidate DETRAY_HOST_DEVICE inline void set_next(candidate_itr_t &&new_next) { _next = std::move(new_next); } + */ /// Updates the iterator position of the last valid candidate DETRAY_HOST_DEVICE diff --git a/core/include/detray/propagator/propagator.hpp b/core/include/detray/propagator/propagator.hpp index 5ac2dfef2..4c026d5df 100644 --- a/core/include/detray/propagator/propagator.hpp +++ b/core/include/detray/propagator/propagator.hpp @@ -58,6 +58,8 @@ struct propagator { using detector_type = typename navigator_t::detector_type; using context_type = typename detector_type::context; using field_type = typename stepper_t::state::field_type; + using stepper_state_type = typename stepper_t::state; + using navigator_state_type = typename navigator_t::state; /// Construct the propagation state. /// diff --git a/core/include/detray/propagator/rk_stepper.ipp b/core/include/detray/propagator/rk_stepper.ipp index ebdd410a4..78d77139b 100644 --- a/core/include/detray/propagator/rk_stepper.ipp +++ b/core/include/detray/propagator/rk_stepper.ipp @@ -164,6 +164,7 @@ template bool detray::rk_stepper::step(propagation_state_t& propagation) { + // Get stepper and navigator states state& stepping = propagation._stepping; auto& magnetic_field = stepping._magnetic_field; diff --git a/core/include/detray/tracks/bound_track_parameters.hpp b/core/include/detray/tracks/bound_track_parameters.hpp index f88086ae8..be7bb63c0 100644 --- a/core/include/detray/tracks/bound_track_parameters.hpp +++ b/core/include/detray/tracks/bound_track_parameters.hpp @@ -8,6 +8,7 @@ #pragma once // Project include(s). +#include "detray/definitions/indexing.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/definitions/track_parametrization.hpp" #include "detray/tracks/detail/track_helper.hpp" @@ -43,7 +44,8 @@ struct bound_track_parameters { DETRAY_HOST_DEVICE bound_track_parameters() - : m_vector(matrix_actor().template zero()), + : m_surface_link(dindex_invalid), + m_vector(matrix_actor().template zero()), m_covariance( matrix_actor().template zero()) {} diff --git a/tests/common/include/tests/common/covariance_engine.inl b/tests/common/include/tests/common/covariance_engine.inl index 96ee158c6..ad04dfaf4 100644 --- a/tests/common/include/tests/common/covariance_engine.inl +++ b/tests/common/include/tests/common/covariance_engine.inl @@ -9,6 +9,7 @@ #include "detray/definitions/units.hpp" #include "detray/field/constant_magnetic_field.hpp" #include "detray/propagator/actor_chain.hpp" +#include "detray/propagator/actors/aborters.hpp" #include "detray/propagator/actors/bound_to_bound_updater.hpp" #include "detray/propagator/actors/resetter.hpp" #include "detray/propagator/line_stepper.hpp" @@ -24,6 +25,9 @@ // google-test include(s) #include +// System include(s) +#include + using namespace detray; using vector2 = __plugin::vector2; using vector3 = __plugin::vector3; @@ -33,7 +37,6 @@ using matrix_operator = standard_matrix_operator; using mag_field_t = constant_magnetic_field<>; constexpr scalar epsilon = 1e-3; -constexpr scalar path_limit = 100 * unit_constants::cm; // This tests the covariance transport in rk stepper TEST(covariance_transport, cartesian) { @@ -48,7 +51,8 @@ TEST(covariance_transport, cartesian) { // Create telescope detector with a single plane typename ln_stepper_t::free_track_parameters_type default_trk{ {0, 0, 0}, 0, {1, 0, 0}, -1}; - std::vector positions = {0.}; + std::vector positions = {0., + std::numeric_limits::infinity()}; const auto det = create_telescope_detector( host_mr, positions, ln_stepper_t(), @@ -57,7 +61,9 @@ TEST(covariance_transport, cartesian) { using navigator_t = navigator; using crk_stepper_t = rk_stepper>; - using propagator_t = propagator>; + using actor_chain_t = + actor_chain>; + using propagator_t = propagator; // Generate track starting point vector2 local{2, 3}; @@ -90,19 +96,29 @@ TEST(covariance_transport, cartesian) { vector3 B{0, 0, 1. * unit_constants::T}; mag_field_t mag_field(B); + // Path length per turn + scalar S = 2. * getter::norm(mom) / getter::norm(B) * M_PI; + + // Actors + looper::state loop{S, 0}; + bound_to_bound_updater::state bound_updater{}; + actor_chain_t::state actor_states = std::tie(loop, bound_updater); + // bound track parameter const bound_track_parameters bound_param0(0, bound_vector, bound_cov); - typename propagator_t::state propagation{bound_param0, mag_field, det}; + propagator_t p{{}, {}}; + propagator_t::state propagation(bound_param0, mag_field, det, actor_states); + crk_stepper_t::state &crk_state = propagation._stepping; - navigator_t::state &n_state = propagation._navigation; + // navigator_t::state &n_state = propagation._navigation; // Decrease tolerance down to 1e-8 crk_state._tolerance = 1e-8; // RK stepper and its state - crk_stepper_t crk_stepper; + // crk_stepper_t crk_stepper; ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); @@ -111,28 +127,67 @@ TEST(covariance_transport, cartesian) { ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); + // Run propagator + p.propagate(propagation); + // helix trajectory detail::helix helix(crk_state(), &B); - // Path length per turn - scalar S = 2. * getter::norm(mom) / getter::norm(B) * M_PI; + // Transport jacobian check + auto true_J = helix.jacobian(crk_state.path_length()); - // Run stepper for one turn - unsigned int max_steps = 1e4; - for (unsigned int i = 0; i < max_steps; i++) { + for (std::size_t i = 0; i < e_free_size; i++) { + for (std::size_t j = 0; j < e_free_size; j++) { + EXPECT_NEAR( + matrix_operator().element(crk_state._jac_transport, i, j), + matrix_operator().element(true_J, i, j), + crk_state.path_length() * epsilon); + } + } - crk_state.set_constraint(S - crk_state.path_length()); + // Bound parameters check - // n_state._step_size = S; + // Bound state after one turn propagation + const auto bound_param1 = crk_state._bound_params; - crk_stepper.step(propagation); + const auto bound_vec0 = bound_param0.vector(); + const auto bound_vec1 = bound_param1.vector(); - if (std::abs(S - crk_state._s) < 1e-6) { - break; + const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); + + // Check if the bound state stays the same after one turn propagation + + // vector + for (std::size_t i = 0; i < e_bound_size; i++) { + EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), + matrix_operator().element(bound_vec1, i, 0), epsilon); + } + + // covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), + crk_state.path_length() * epsilon); } + } - // Make sure that we didn't reach the end of for loop - ASSERT_TRUE(i < max_steps - 1); + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + printf("%f ", matrix_operator().element(bound_cov0, i, j)); + } + printf("\n"); + } + + printf("\n"); + printf("\n"); + + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + printf("%f ", matrix_operator().element(bound_cov1, i, j)); + } + printf("\n"); } /* From 172aecb34cdc9272bb78a83a417fa35839276848 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 6 Sep 2022 14:46:26 -0700 Subject: [PATCH 14/63] Backup --- .../detray/coordinates/coordinate_base.hpp | 33 +++++++++++++++++++ .../actors/bound_to_bound_updater.hpp | 23 +++++++++++++ 2 files changed, 56 insertions(+) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index e3cb64e85..e163f177a 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -257,12 +257,45 @@ struct coordinate_base { // r correction term const matrix_type<1, 3> r_term = -1. / wt * w; + printf("step size %f \n", s); + + printf("K %f \n", K); + + printf("Ks %f \n", Ks); + printf("w %f %f %f \n", matrix_actor().element(w, 0, 0), + matrix_actor().element(w, 0, 1), + matrix_actor().element(w, 0, 2)); + + printf("wt %f \n", wt); + + printf("wh %f %f %f \n", matrix_actor().element(wh, 0, 0), + matrix_actor().element(wh, 0, 1), + matrix_actor().element(wh, 0, 2)); + + auto a = std::sin(Ks); + printf("sinKs: %f %f %f \n", a); + // t correction term matrix_type<1, 3> t_term = matrix_actor().template zero<1, 3>(); t_term = t_term + (Ks - std::sin(Ks)) / K * vector::dot(hlx._h0, normal) * h; + + printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), + matrix_actor().element(t_term, 0, 1), + matrix_actor().element(t_term, 0, 2)); + t_term = t_term + std::sin(Ks) / K * w; + + printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), + matrix_actor().element(t_term, 0, 1), + matrix_actor().element(t_term, 0, 2)); + t_term = t_term + (1 - std::cos(Ks)) / K * wh; + + printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), + matrix_actor().element(t_term, 0, 1), + matrix_actor().element(t_term, 0, 2)); + t_term = -1. / wt * t_term; printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp index 0a503f477..7ae904b01 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -116,6 +116,29 @@ struct bound_to_bound_updater : actor { (path_correction + free_transport_jacobian) * bound_to_free_jacobian; + const bound_matrix full_jacobian_no_correction = + free_to_bound_jacobian * + (free_transport_jacobian)*bound_to_free_jacobian; + + printf("w/ correction \n"); + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + printf("%f ", matrix_actor().element(full_jacobian, i, j)); + } + printf("\n"); + } + printf("\n"); + + printf("w/o correction \n"); + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + printf("%f ", matrix_actor().element( + full_jacobian_no_correction, i, j)); + } + printf("\n"); + } + printf("\n"); + const bound_matrix new_cov = full_jacobian * stepping._bound_params.covariance() * matrix_actor().transpose(full_jacobian); From 39d6334aa5908e67a2538d940651dfc9d4c74d7b Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 6 Sep 2022 20:36:43 -0700 Subject: [PATCH 15/63] Backup --- .../detray/coordinates/coordinate_base.hpp | 42 ---- .../detray/propagator/actors/aborters.hpp | 11 +- .../actors/bound_to_bound_updater.hpp | 47 ++-- .../detray/propagator/actors/resetter.hpp | 46 +--- .../tests/common/covariance_engine.inl | 211 +++--------------- 5 files changed, 59 insertions(+), 298 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index e163f177a..b4d59eac1 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -257,51 +257,17 @@ struct coordinate_base { // r correction term const matrix_type<1, 3> r_term = -1. / wt * w; - printf("step size %f \n", s); - - printf("K %f \n", K); - - printf("Ks %f \n", Ks); - printf("w %f %f %f \n", matrix_actor().element(w, 0, 0), - matrix_actor().element(w, 0, 1), - matrix_actor().element(w, 0, 2)); - - printf("wt %f \n", wt); - - printf("wh %f %f %f \n", matrix_actor().element(wh, 0, 0), - matrix_actor().element(wh, 0, 1), - matrix_actor().element(wh, 0, 2)); - - auto a = std::sin(Ks); - printf("sinKs: %f %f %f \n", a); - // t correction term matrix_type<1, 3> t_term = matrix_actor().template zero<1, 3>(); t_term = t_term + (Ks - std::sin(Ks)) / K * vector::dot(hlx._h0, normal) * h; - printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), - matrix_actor().element(t_term, 0, 1), - matrix_actor().element(t_term, 0, 2)); - t_term = t_term + std::sin(Ks) / K * w; - printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), - matrix_actor().element(t_term, 0, 1), - matrix_actor().element(t_term, 0, 2)); - t_term = t_term + (1 - std::cos(Ks)) / K * wh; - printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), - matrix_actor().element(t_term, 0, 1), - matrix_actor().element(t_term, 0, 2)); - t_term = -1. / wt * t_term; - printf("%f %f %f, \n", matrix_actor().element(t_term, 0, 0), - matrix_actor().element(t_term, 0, 1), - matrix_actor().element(t_term, 0, 2)); - // qoverp correction term const scalar_type L_term = -1. / wt * A * Ks / hlx.qop() * vector::dot(normal, hlx._n0); @@ -331,14 +297,6 @@ struct coordinate_base { // dt/dL0 const matrix_type<3, 1> dtdL0 = AK * n_T * L_term; - for (std::size_t i = 0; i < 3; i++) { - for (std::size_t j = 0; j < 3; j++) { - printf("%f ", matrix_actor().element(drdt0, i, j)); - } - printf("\n"); - } - printf("\n"); - matrix_actor().template set_block<3, 3>(path_correction, drdr0, e_free_pos0, e_free_pos0); diff --git a/core/include/detray/propagator/actors/aborters.hpp b/core/include/detray/propagator/actors/aborters.hpp index 2c5aaed4a..166e46962 100644 --- a/core/include/detray/propagator/actors/aborters.hpp +++ b/core/include/detray/propagator/actors/aborters.hpp @@ -62,11 +62,12 @@ struct pathlimit_aborter : actor { } }; -struct looper : actor { +struct ignorer : actor { struct state { - scalar loop_length = 0; - dindex target_surface_index = dindex_invalid; + + scalar _path_limit; + dindex _target_surface_index = dindex_invalid; }; /// Enforces the path limit on a stepper state @@ -82,11 +83,11 @@ struct looper : actor { auto &stepping = prop_state._stepping; navigation.set_full_trust(); - scalar residual = actor_state.loop_length - stepping.path_length(); + scalar residual = actor_state._path_limit - stepping.path_length(); stepping.set_constraint(residual); typename propagator_state_t::navigator_state_type::intersection_t is; - is.index = actor_state.target_surface_index; + is.index = actor_state._target_surface_index; is.path = residual; auto &candidates = navigation.candidates(); candidates.clear(); diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp index 7ae904b01..ee19f3f84 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -97,47 +97,30 @@ struct bound_to_bound_updater : actor { free_matrix path_correction = local_coordinate.path_correction(stepping, trf3, mask); - for (std::size_t i = 0; i < e_free_size; i++) { - for (std::size_t j = 0; j < e_free_size; j++) { - printf("%f ", - matrix_actor().element(path_correction, i, j)); - } - printf("\n"); - } - - printf("\n"); - // Bound to free jacobian at the departure surface const bound_to_free_matrix& bound_to_free_jacobian = stepping._jac_to_global; + /* const bound_matrix full_jacobian = free_to_bound_jacobian * (path_correction + free_transport_jacobian) * bound_to_free_jacobian; - - const bound_matrix full_jacobian_no_correction = + */ + // Acts version + /* + const bound_matrix full_jacobian = free_to_bound_jacobian * - (free_transport_jacobian)*bound_to_free_jacobian; - - printf("w/ correction \n"); - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - printf("%f ", matrix_actor().element(full_jacobian, i, j)); - } - printf("\n"); - } - printf("\n"); - - printf("w/o correction \n"); - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - printf("%f ", matrix_actor().element( - full_jacobian_no_correction, i, j)); - } - printf("\n"); - } - printf("\n"); + (matrix_actor().template identity() + + path_correction) * + free_transport_jacobian * bound_to_free_jacobian; + */ + + // No path correction + + const bound_matrix full_jacobian = free_to_bound_jacobian * + free_transport_jacobian * + bound_to_free_jacobian; const bound_matrix new_cov = full_jacobian * stepping._bound_params.covariance() * diff --git a/core/include/detray/propagator/actors/resetter.hpp b/core/include/detray/propagator/actors/resetter.hpp index 591e6d888..49622bd8a 100644 --- a/core/include/detray/propagator/actors/resetter.hpp +++ b/core/include/detray/propagator/actors/resetter.hpp @@ -61,49 +61,11 @@ struct resetter : actor { return true; } - - /* - template - DETRAY_HOST_DEVICE inline output_type operator()( - const mask_group_t& mask_group, const surface_t& surface, - propagator_state_t& propagation) const { - - // Stepper and Navigator states - auto& navigation = propagation._navigation; - auto& stepping = propagation._stepping; - - // Retrieve surfaces and transform store - const auto& det = navigation.detector(); - const auto& transform_store = det->transform_store(); - - // Intersection - const auto& is = navigation.current(); - - // Transform - const auto& trf3 = transform_store[surface.transform()]; - - // Mask - const auto& mask = mask_group[is->mask_index]; - auto local_coordinate = mask.local_type(); - - // Reset the path length - stepping._s = 0; - - // Reset jacobian coordinate transformation at the current surface - stepping._jac_to_global = local_coordinate.bound_to_free_jacobian( - trf3, mask, stepping._bound_params.vector()); - - // Reset jacobian transport to identity matrix - matrix_actor().set_identity(stepping._jac_transport); - - return true; - } - */ }; template - DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const { + DETRAY_HOST_DEVICE void operator()(state& /*actor_state*/, + propagator_state_t& propagation) const { auto& navigation = propagation._navigation; auto& stepping = propagation._stepping; @@ -122,8 +84,8 @@ struct resetter : actor { // Surface const auto& surface = surface_container[is->index]; - auto succeed = mask_store.template execute( - surface.mask_type(), trf_store, surface, stepping); + mask_store.template execute(surface.mask_type(), trf_store, + surface, stepping); } } }; diff --git a/tests/common/include/tests/common/covariance_engine.inl b/tests/common/include/tests/common/covariance_engine.inl index ad04dfaf4..a1dd8b3f5 100644 --- a/tests/common/include/tests/common/covariance_engine.inl +++ b/tests/common/include/tests/common/covariance_engine.inl @@ -27,6 +27,7 @@ // System include(s) #include +#include using namespace detray; using vector2 = __plugin::vector2; @@ -62,12 +63,17 @@ TEST(covariance_transport, cartesian) { using crk_stepper_t = rk_stepper>; using actor_chain_t = - actor_chain>; + actor_chain, + resetter>; using propagator_t = propagator; // Generate track starting point vector2 local{2, 3}; - vector3 mom{0.02, 0., 0.}; + vector3 mom{0.001, 0., 0.}; + // vector3 mom{0.02, 0.02, 0.}; + vector3 dir = vector::normalize(mom); + + // vector3 mom{0.01, 0.01, 0.01}; scalar time = 0.; scalar q = -1.; @@ -89,63 +95,58 @@ TEST(covariance_transport, cartesian) { // Note: Set theta error as ZERO, to constrain the loc1 divergence getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + // getter::element(bound_cov, e_bound_theta, e_bound_theta) = 1.; getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + // bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + // B field vector3 B{0, 0, 1. * unit_constants::T}; mag_field_t mag_field(B); // Path length per turn - scalar S = 2. * getter::norm(mom) / getter::norm(B) * M_PI; + scalar S = 2. * getter::perp(mom) / getter::norm(B) * M_PI; // Actors - looper::state loop{S, 0}; + ignorer::state loop{S, 0}; bound_to_bound_updater::state bound_updater{}; - actor_chain_t::state actor_states = std::tie(loop, bound_updater); + resetter::state rst{}; - // bound track parameter - const bound_track_parameters bound_param0(0, bound_vector, - bound_cov); + actor_chain_t::state actor_states = std::tie(loop, bound_updater, rst); - propagator_t p{{}, {}}; + propagator_t p({}, {}); propagator_t::state propagation(bound_param0, mag_field, det, actor_states); crk_stepper_t::state &crk_state = propagation._stepping; - // navigator_t::state &n_state = propagation._navigation; // Decrease tolerance down to 1e-8 crk_state._tolerance = 1e-8; // RK stepper and its state - // crk_stepper_t crk_stepper; - - ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); - ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); - ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); - ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); - ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); - ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); - - // Run propagator - p.propagate(propagation); + EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); + EXPECT_FLOAT_EQ(crk_state().pos()[1], local[0]); // y + EXPECT_FLOAT_EQ(crk_state().pos()[2], local[1]); // z + EXPECT_NEAR(crk_state().dir()[0], dir[0], epsilon); + EXPECT_NEAR(crk_state().dir()[1], dir[1], epsilon); + EXPECT_NEAR(crk_state().dir()[2], dir[2], epsilon); // helix trajectory detail::helix helix(crk_state(), &B); - // Transport jacobian check - auto true_J = helix.jacobian(crk_state.path_length()); - - for (std::size_t i = 0; i < e_free_size; i++) { - for (std::size_t j = 0; j < e_free_size; j++) { - EXPECT_NEAR( - matrix_operator().element(crk_state._jac_transport, i, j), - matrix_operator().element(true_J, i, j), - crk_state.path_length() * epsilon); - } - } + // Run propagator + p.propagate(propagation); - // Bound parameters check + // RK stepper and its state + EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); + EXPECT_FLOAT_EQ(crk_state().pos()[1], local[0]); // y + EXPECT_FLOAT_EQ(crk_state().pos()[2], local[1]); // z + EXPECT_NEAR(crk_state().dir()[0], dir[0], epsilon); + EXPECT_NEAR(crk_state().dir()[1], dir[1], epsilon); + EXPECT_NEAR(crk_state().dir()[2], dir[2], epsilon); + EXPECT_NEAR(crk_state.path_length(), loop._path_limit, epsilon); // Bound state after one turn propagation const auto bound_param1 = crk_state._bound_params; @@ -172,148 +173,4 @@ TEST(covariance_transport, cartesian) { crk_state.path_length() * epsilon); } } - - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - printf("%f ", matrix_operator().element(bound_cov0, i, j)); - } - printf("\n"); - } - - printf("\n"); - printf("\n"); - - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - printf("%f ", matrix_operator().element(bound_cov1, i, j)); - } - printf("\n"); - } - - /* - - // test surface - const vector3 u{0, 1, 0}; - const vector3 w{1, 0, 0}; - const vector3 t{0, 0, 0}; - const transform3 trf(t, w, u); - - // Generate track starting point - vector3 local{2, 3, 0}; - vector3 mom{0.02, 0., 0.}; - scalar time = 0.; - scalar q = -1.; - - // bound vector - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = local[0]; - getter::element(bound_vector, e_bound_loc1, 0) = local[1]; - getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); - getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); - getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); - getter::element(bound_vector, e_bound_time, 0) = time; - - // bound covariance - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template zero(); - getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; - getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; - getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; - - // Note: Set theta error as ZERO, to constrain the loc1 divergence - getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; - getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; - getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; - - // B field - vector3 B{0, 0, 1. * unit_constants::T}; - mag_field_t mag_field(B); - - // bound track parameter - const bound_track_parameters bound_param0(0, bound_vector, - bound_cov); - - prop_state propagation{ - crk_stepper_t::state(bound_param0, trf, mag_field), nav_state{}}; - crk_stepper_t::state &crk_state = propagation._stepping; - nav_state &n_state = propagation._navigation; - - // Decrease tolerance down to 1e-8 - crk_state._tolerance = 1e-8; - - // RK stepper and its state - crk_stepper_t crk_stepper; - - ASSERT_FLOAT_EQ(crk_state().pos()[0], 0); - ASSERT_FLOAT_EQ(crk_state().pos()[1], local[0]); - ASSERT_FLOAT_EQ(crk_state().pos()[2], local[1]); - ASSERT_NEAR(crk_state().dir()[0], 1, epsilon); - ASSERT_NEAR(crk_state().dir()[1], 0, epsilon); - ASSERT_NEAR(crk_state().dir()[2], 0, epsilon); - - // helix trajectory - detail::helix helix(crk_state(), &B); - - // Path length per turn - scalar S = 2. * getter::norm(mom) / getter::norm(B) * M_PI; - - // Run stepper for one turn - unsigned int max_steps = 1e4; - for (unsigned int i = 0; i < max_steps; i++) { - - crk_state.set_constraint(S - crk_state.path_length()); - - n_state._step_size = S; - - crk_stepper.step(propagation); - - if (std::abs(S - crk_state.path_length()) < 1e-6) { - break; - } - - // Make sure that we didn't reach the end of for loop - ASSERT_TRUE(i < max_steps - 1); - } - - // Transport jacobian check - - auto jac_transport = crk_state._jac_transport; - auto true_J = helix.jacobian(crk_state.path_length()); - - for (std::size_t i = 0; i < e_free_size; i++) { - for (std::size_t j = 0; j < e_free_size; j++) { - EXPECT_NEAR(matrix_operator().element(jac_transport, i, j), - matrix_operator().element(true_J, i, j), - crk_state.path_length() * epsilon); - } - } - - // Bound parameters check - - // Bound state after one turn propagation - const auto bound_param1 = crk_stepper.bound_state(propagation, trf); - - const auto bound_vec0 = bound_param0.vector(); - const auto bound_vec1 = bound_param1.vector(); - - const auto bound_cov0 = bound_param0.covariance(); - const auto bound_cov1 = bound_param1.covariance(); - - // Check if the bound state stays the same after one turn propagation - - // vector - for (size_type i = 0; i < e_bound_size; i++) { - EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), - matrix_operator().element(bound_vec1, i, 0), epsilon); - } - - // covaraince - for (size_type i = 0; i < e_bound_size; i++) { - for (size_type j = 0; j < e_bound_size; j++) { - EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), - matrix_operator().element(bound_cov1, i, j), - crk_state.path_length() * epsilon); - } - } - */ } \ No newline at end of file From dc516e8272b6b4eff7754477f01afbd561a39ccf Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 6 Sep 2022 20:42:04 -0700 Subject: [PATCH 16/63] Remove unused files --- core/CMakeLists.txt | 2 - .../actors/bound_to_bound_updater.hpp | 6 +- .../detray/propagator/base_stepper.hpp | 2 - .../propagator/detail/covariance_engine.hpp | 101 -------------- .../propagator/detail/covariance_engine.ipp | 71 ---------- .../propagator/detail/covariance_kernel.hpp | 114 --------------- .../propagator/detail/jacobian_engine.hpp | 80 ----------- .../propagator/detail/jacobian_engine.ipp | 131 ------------------ core/include/detray/propagator/rk_stepper.hpp | 3 - 9 files changed, 3 insertions(+), 507 deletions(-) delete mode 100644 core/include/detray/propagator/detail/covariance_engine.hpp delete mode 100644 core/include/detray/propagator/detail/covariance_engine.ipp delete mode 100644 core/include/detray/propagator/detail/covariance_kernel.hpp delete mode 100644 core/include/detray/propagator/detail/jacobian_engine.hpp delete mode 100644 core/include/detray/propagator/detail/jacobian_engine.ipp diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 1caeead17..073816267 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -80,8 +80,6 @@ detray_add_library( detray_core core "include/detray/propagator/base_actor.hpp" "include/detray/propagator/base_stepper.hpp" "include/detray/propagator/constrained_step.hpp" - "include/detray/propagator/detail/covariance_engine.hpp" - "include/detray/propagator/detail/jacobian_engine.hpp" "include/detray/propagator/line_stepper.hpp" "include/detray/propagator/navigation_policies.hpp" "include/detray/propagator/navigator.hpp" diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp index ee19f3f84..8dd2ef2a9 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -107,20 +107,20 @@ struct bound_to_bound_updater : actor { (path_correction + free_transport_jacobian) * bound_to_free_jacobian; */ + // Acts version - /* const bound_matrix full_jacobian = free_to_bound_jacobian * (matrix_actor().template identity() + path_correction) * free_transport_jacobian * bound_to_free_jacobian; - */ // No path correction - + /* const bound_matrix full_jacobian = free_to_bound_jacobian * free_transport_jacobian * bound_to_free_jacobian; + */ const bound_matrix new_cov = full_jacobian * stepping._bound_params.covariance() * diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index 7c13271b6..7c7a93424 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -11,7 +11,6 @@ #include "detray/definitions/qualifiers.hpp" #include "detray/definitions/units.hpp" #include "detray/propagator/constrained_step.hpp" -#include "detray/propagator/detail/covariance_engine.hpp" #include "detray/tracks/tracks.hpp" namespace detray { @@ -25,7 +24,6 @@ class base_stepper { using free_track_parameters_type = free_track_parameters; using bound_track_parameters_type = bound_track_parameters; using matrix_operator = typename transform3_t::matrix_actor; - using covariance_engine = detail::covariance_engine; using track_helper = detail::track_helper; using size_type = typename transform3_type::size_type; diff --git a/core/include/detray/propagator/detail/covariance_engine.hpp b/core/include/detray/propagator/detail/covariance_engine.hpp deleted file mode 100644 index 817d5d8ca..000000000 --- a/core/include/detray/propagator/detail/covariance_engine.hpp +++ /dev/null @@ -1,101 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Detray include(s) -#include "detray/definitions/qualifiers.hpp" -#include "detray/propagator/detail/jacobian_engine.hpp" - -namespace detray { - -namespace detail { - -// Covariance engine agnostic to surface type -template -struct covariance_engine { - - /// Transformation matching this struct - using transform3_type = transform3_t; - using jacobian_engine = detail::jacobian_engine; - using track_helper = typename jacobian_engine::track_helper; - using matrix_operator = typename jacobian_engine::matrix_operator; - using size_type = typename transform3_type::size_type; - /// 2D matrix type - template - using matrix_type = - typename matrix_operator::template matrix_type; - /// Shorthand vector types related to track parameters. - using bound_vector = matrix_type; - using free_vector = matrix_type; - /// Shorthand matrix types related to track parameters. - using bound_matrix = matrix_type; - using free_matrix = matrix_type; - /// Mapping matrix - using bound_to_free_matrix = matrix_type; - using free_to_bound_matrix = matrix_type; - using free_to_path_matrix = matrix_type<1, e_free_size>; - - /** Function to get the full jacobian for surface-to-surface propagation - * - * @param trf3 is the transform matrix of the destination surface - * @param free_vec is the input free vector at the destination surface - * @param bound_to_free_jacobian is the coordinate transform jacobian - * at departure surface. - * @param free_transport_jacobian is the transport jacobian - * @param free_to_path_derivative is the derivative of free parameter w.r.t - * path - * @returns bound to bound jacobian - */ - DETRAY_HOST_DEVICE inline bound_matrix bound_to_bound_jacobian( - const transform3_type& trf3, const free_vector& free_vec, - const bound_to_free_matrix& bound_to_free_jacobian, - const free_matrix& free_transport_jacobian, - const free_vector& free_to_path_derivative) const; - - /** Function to update the covariance matrix for surface-to-surface - * propagation - * - * @param trf3 is the transform matrix of the destination surface - * @param bound_covariance is the covariance at the departure surface, which - * is to be updated for the destination surface - * @param free_vec is the input free vector at the destination surface - * @param bound_to_free_jacobian is the coordinate transform jacobian - * at the departure surface. - * @param free_transport_jacobian is the transport jacobian - * @param free_to_path_derivative is the derivative of free parameter w.r.t - * path at the destination surface - */ - DETRAY_HOST_DEVICE inline void bound_to_bound_covariance_update( - const transform3_type& trf3, bound_matrix& bound_covariance, - const free_vector& free_vec, - const bound_to_free_matrix& bound_to_free_jacobian, - const free_matrix& free_transport_jacobian, - const free_vector& free_to_path_derivative) const; - - /** Function to reinitialize the jacobian after updating covariance - * - * @param trf3 is the transform matrix of the destination surface - * @param bound_vec is the input bound vector at the destination surface - * @param bound_to_free_jacobian is the coordinate transform jacobian - * at the destination surface - * @param free_transport_jacobian is the transport jacobian - * @param free_to_path_derivative is the derivative of free parameter w.r.t - * path at the destination surface - */ - DETRAY_HOST_DEVICE inline void reinitialize_jacobians( - const transform3_type& trf3, const bound_vector& bound_vec, - bound_to_free_matrix& bound_to_free_jacobian, - free_matrix& free_transport_jacobian, - free_vector& free_to_path_derivative) const; -}; - -} // namespace detail - -} // namespace detray - -#include "detray/propagator/detail/covariance_engine.ipp" \ No newline at end of file diff --git a/core/include/detray/propagator/detail/covariance_engine.ipp b/core/include/detray/propagator/detail/covariance_engine.ipp deleted file mode 100644 index 5ae5cd6d4..000000000 --- a/core/include/detray/propagator/detail/covariance_engine.ipp +++ /dev/null @@ -1,71 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -template -typename detray::detail::template covariance_engine::bound_matrix -detray::detail::covariance_engine::bound_to_bound_jacobian( - const transform3_type& trf3, const free_vector& free_vec, - const bound_to_free_matrix& bound_to_free_jacobian, - const free_matrix& free_transport_jacobian, - const free_vector& free_to_path_derivative) const { - - // Calculate the path correction term - free_to_path_matrix path_correction_term = - jacobian_engine().free_to_path_correction(trf3, free_vec); - - // Calculate the free-to-bound coordinate transform jacobian - free_to_bound_matrix free_to_bound_jacobian = - jacobian_engine().free_to_bound_coordinate(trf3, free_vec); - - // Calculate the full jacobian from the local/bound parameters at the start - // surface to local/bound parameters at the final surface - // @note jac(locA->locB) = jac(gloB->locB)*(1+ - // pathCorrectionFactor(gloB))*jacTransport(gloA->gloB) *jac(locA->gloA) - const auto I = - matrix_operator().template identity(); - - return free_to_bound_jacobian * - (I + free_to_path_derivative * path_correction_term) * - free_transport_jacobian * bound_to_free_jacobian; -} - -template -void detray::detail::covariance_engine:: - bound_to_bound_covariance_update( - const transform3_type& trf3, bound_matrix& bound_covariance, - const free_vector& free_vec, - const bound_to_free_matrix& bound_to_free_jacobian, - const free_matrix& free_transport_jacobian, - const free_vector& free_to_path_derivative) const { - - // Get the full jacobian - bound_matrix full_jacobian = this->bound_to_bound_jacobian( - trf3, free_vec, bound_to_free_jacobian, free_transport_jacobian, - free_to_path_derivative); - - // Update the bound covariance - bound_covariance = full_jacobian * bound_covariance * - matrix_operator().transpose(full_jacobian); -} - -template -void detray::detail::covariance_engine::reinitialize_jacobians( - const transform3_type& trf3, const bound_vector& bound_vec, - bound_to_free_matrix& bound_to_free_jacobian, - free_matrix& free_transport_jacobian, - free_vector& free_to_path_derivative) const { - - // Reset jacobian coordinate transformation at the current surface - bound_to_free_jacobian = - jacobian_engine().bound_to_free_coordinate(trf3, bound_vec); - - // Reset jacobian transport to identity matrix - matrix_operator().set_identity(free_transport_jacobian); - - // Reset derivative of position and direction to zero matrix - matrix_operator().set_zero(free_to_path_derivative); -} \ No newline at end of file diff --git a/core/include/detray/propagator/detail/covariance_kernel.hpp b/core/include/detray/propagator/detail/covariance_kernel.hpp deleted file mode 100644 index 07862e5f4..000000000 --- a/core/include/detray/propagator/detail/covariance_kernel.hpp +++ /dev/null @@ -1,114 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s) -#include "detray/definitions/qualifiers.hpp" -#include "detray/definitions/track_parametrization.hpp" -#include "detray/tracks/detail/track_helper.hpp" - -namespace detray { - -namespace detail { - -template -struct bound_to_bound_covariance_update { - - /// @name Type definitions for the struct - /// @{ - - // Transformation matching this struct - using transform3_type = transform3_t; - // scalar_type - using scalar_type = typename transform3_type::scalar_type; - // size type - using size_type = typename transform3_type::size_type; - // Matrix actor - using matrix_actor = typename transform3_t::matrix_actor; - // 2D matrix type - template - using matrix_type = typename matrix_actor::template matrix_type; - // Shorthand vector/matrix types related to bound track parameters. - using bound_vector = matrix_type; - using bound_matrix = matrix_type; - // Mapping from bound track parameters. - using bound_to_free_matrix = matrix_type; - // Shorthand vector/matrix types related to free track parameters. - using free_vector = matrix_type; - using free_matrix = matrix_type; - // Mapping from free track parameters. - using free_to_bound_matrix = matrix_type; - using free_to_path_matrix = matrix_type<1, e_free_size>; - // Track helper - using track_helper = detail::track_helper; - - /// @} - - using output_type = bool; - - template - DETRAY_HOST_DEVICE inline output_type operator()( - const mask_group_t& mask_group, propagator_state_t& propagation) const { - - // Stepper and Navigator states - auto& navigation = propagation._navigation; - auto& stepping = propagation._stepping; - - // Retrieve surfaces and transform store - const auto& det = navigation.detector(); - const auto& surface_container = det->surfaces(); - const auto& tf_store = det->transform_store(); - - // Intersection - const auto& is = navigation.current(); - - // Surface - const auto& sf = surface_container[is->index]; - - // Transform - const auto& trf3 = tf_store[sf.transform()]; - - // Mask - const auto& mask = mask_group[is->mask_index]; - auto local_coordinate = mask.local_type(); - - // Free vector - const auto& free_vec = stepping().vector(); - - // Convert free to bound vector - const auto bound_vec = - local_coordinate.free_to_bound_vector(trf3, free_vec); - - // Free to bound jacobian at the destination surface - const free_to_bound_matrix free_to_bound_jacobian = - local_coordinate.free_to_bound_jacobian(trf3, mask, free_vec); - - // Transport jacobian in free coordinate - free_matrix& free_transport_jacobian = stepping._jac_transport; - - // Path correction factor - free_matrix path_correction = - local_coordinate.path_correction(stepping, trf3, mask); - - // Bound to free jacobian at the departure surface - const bound_to_free_matrix& bound_to_free_jacobian = - stepping._jac_to_global; - - // Calculate surface-to-surface covariance transport - stepping._bound_covariance = - free_to_bound_jacobian * - (path_correction + free_transport_jacobian) * - bound_to_free_jacobian; - - return true; - } -}; - -} // namespace detail - -} // namespace detray \ No newline at end of file diff --git a/core/include/detray/propagator/detail/jacobian_engine.hpp b/core/include/detray/propagator/detail/jacobian_engine.hpp deleted file mode 100644 index 52f5c8317..000000000 --- a/core/include/detray/propagator/detail/jacobian_engine.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Detray include(s) -#include "detray/definitions/qualifiers.hpp" -#include "detray/tracks/detail/track_helper.hpp" - -namespace detray { - -namespace detail { - -// Jacobian engine assuming "Planar Surface with Cartesian coordinate" -// NOTE: We may inherit jacobian engine to address different -// types of surface, if required -template -struct jacobian_engine { - - /// Transformation matching this struct - using transform3_type = transform3_t; - /// scalar_type - using scalar_type = typename transform3_type::scalar_type; - /// Vector in 3D space - using vector3 = typename transform3_type::vector3; - /// Matrix operator - using matrix_operator = typename transform3_type::matrix_actor; - // Track helper - using track_helper = detail::track_helper; - using size_type = typename transform3_type::size_type; - /// 2D matrix type - template - using matrix_type = - typename matrix_operator::template matrix_type; - /// Shorthand vector types related to track parameters. - using bound_vector = matrix_type; - using free_vector = matrix_type; - /// Mapping matrix - using bound_to_free_matrix = matrix_type; - using free_to_bound_matrix = matrix_type; - using free_to_path_matrix = matrix_type<1, e_free_size>; - - /** Function to get the jacobian for bound to free coordinate transform - * - * @param trf3 is the transform matrix - * @param bound_vec is the input bound vector - * @returns bound to free jacobian - */ - DETRAY_HOST_DEVICE inline bound_to_free_matrix bound_to_free_coordinate( - const transform3_type& trf3, const bound_vector& bound_vec) const; - - /** Function to get the jacobian for free to bound coordinate transform - * - * @param trf3 is the transform matrix - * @param free_vec is the input free vector - * @returns free to bound jacobian - */ - DETRAY_HOST_DEVICE inline free_to_bound_matrix free_to_bound_coordinate( - const transform3_type& trf3, const free_vector& free_vec) const; - - /** Function to calculate the path correction term for transport jacobian, - * which is caused by the geometry constraint. - * - * @param trf3 is the transform matrix - * @param free_vec is the input free vector - * @returns free to path matrix - */ - DETRAY_HOST_DEVICE inline free_to_path_matrix free_to_path_correction( - const transform3_type& trf3, const free_vector& free_vec) const; -}; - -} // namespace detail - -} // namespace detray - -#include "detray/propagator/detail/jacobian_engine.ipp" \ No newline at end of file diff --git a/core/include/detray/propagator/detail/jacobian_engine.ipp b/core/include/detray/propagator/detail/jacobian_engine.ipp deleted file mode 100644 index 1385d4cb7..000000000 --- a/core/include/detray/propagator/detail/jacobian_engine.ipp +++ /dev/null @@ -1,131 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -template -typename detray::detail::template jacobian_engine< - transform3_t>::bound_to_free_matrix -detray::detail::jacobian_engine::bound_to_free_coordinate( - const transform3_type& trf3, const bound_vector& bound_vec) const { - - // Declare jacobian for bound to free coordinate transform - bound_to_free_matrix jac_to_global = - matrix_operator().template zero(); - - // Get trigonometric values - const scalar_type theta = - matrix_operator().element(bound_vec, e_bound_theta, 0); - const scalar_type phi = - matrix_operator().element(bound_vec, e_bound_phi, 0); - const scalar_type cos_theta = std::cos(theta); - const scalar_type sin_theta = std::sin(theta); - const scalar_type cos_phi = std::cos(phi); - const scalar_type sin_phi = std::sin(phi); - - // Set d(x,y,z)/d(loc0,loc1) - const matrix_type<3, 2> bound_pos_to_free_pos_derivative = - matrix_operator().template block<3, 2>(trf3.matrix(), 0, 0); - - matrix_operator().template set_block(jac_to_global, - bound_pos_to_free_pos_derivative, - e_free_pos0, e_bound_loc0); - - matrix_operator().element(jac_to_global, e_free_time, e_bound_time) = 1; - matrix_operator().element(jac_to_global, e_free_dir0, e_bound_phi) = - -1 * sin_theta * sin_phi; - matrix_operator().element(jac_to_global, e_free_dir0, e_bound_theta) = - cos_theta * cos_phi; - matrix_operator().element(jac_to_global, e_free_dir1, e_bound_phi) = - sin_theta * cos_phi; - matrix_operator().element(jac_to_global, e_free_dir1, e_bound_theta) = - cos_theta * sin_phi; - matrix_operator().element(jac_to_global, e_free_dir2, e_bound_theta) = - -1 * sin_theta; - matrix_operator().element(jac_to_global, e_free_qoverp, e_bound_qoverp) = 1; - - return jac_to_global; -} - -template -typename detray::detail::template jacobian_engine< - transform3_t>::free_to_bound_matrix -detray::detail::jacobian_engine::free_to_bound_coordinate( - const transform3_type& trf3, const free_vector& free_vec) const { - - // Declare jacobian for free to bound coordinate transform - free_to_bound_matrix jac_to_local = - matrix_operator().template zero(); - - // Free direction - const vector3 dir = track_helper().dir(free_vec); - - // Get trigonometric values - const scalar_type theta = getter::theta(dir); - const scalar_type phi = getter::phi(dir); - const scalar_type cos_theta = std::cos(theta); - const scalar_type sin_theta = std::sin(theta); - const scalar_type inv_sin_theta = 1. / sin_theta; - const scalar_type cos_phi = std::cos(phi); - const scalar_type sin_phi = std::sin(phi); - - // Set d(loc0,loc1)/d(x,y,z) - const matrix_type<2, 3> free_pos_to_bound_pos_derivative = - matrix_operator().template block<2, 3>(trf3.matrix_inverse(), 0, 0); - - matrix_operator().template set_block(jac_to_local, - free_pos_to_bound_pos_derivative, - e_bound_loc0, e_free_pos0); - - // Set d(Free time)/d(Bound time) - matrix_operator().element(jac_to_local, e_bound_time, e_free_time) = 1; - - // Set d(phi, theta)/d(free dir) - matrix_operator().element(jac_to_local, e_bound_phi, e_free_dir0) = - -1. * sin_phi * inv_sin_theta; - matrix_operator().element(jac_to_local, e_bound_phi, e_free_dir1) = - cos_phi * inv_sin_theta; - matrix_operator().element(jac_to_local, e_bound_theta, e_free_dir0) = - cos_phi * cos_theta; - matrix_operator().element(jac_to_local, e_bound_theta, e_free_dir1) = - sin_phi * cos_theta; - matrix_operator().element(jac_to_local, e_bound_theta, e_free_dir2) = - -1 * sin_theta; - - // Set d(Free Qop)/d(Bound Qop) - matrix_operator().element(jac_to_local, e_bound_qoverp, e_free_qoverp) = 1; - - return jac_to_local; -} - -template -typename detray::detail::template jacobian_engine< - transform3_t>::free_to_path_matrix -detray::detail::jacobian_engine::free_to_path_correction( - const transform3_type& trf3, const free_vector& free_vec) const { - - // Declare free to path correction - free_to_path_matrix free_to_path = - matrix_operator().template zero<1, e_free_size>(); - - // Free direction - const vector3 dir = track_helper().dir(free_vec); - - // The measurement frame z axis - const matrix_type<3, 1> ref_z_axis = - matrix_operator().template block<3, 1>(trf3.matrix(), 0, 2); - - // cosine angle between momentum direction and the measurement frame z axis - const scalar_type dz = vector::dot(ref_z_axis, dir); - - // Correction term - const matrix_type<1, 3> correction_term = - -1. / dz * matrix_operator().transpose(ref_z_axis); - - matrix_operator().template set_block<1, 3>(free_to_path, correction_term, 0, - e_free_pos0); - - return free_to_path; -} \ No newline at end of file diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index 9c4321211..00ec36fba 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -12,8 +12,6 @@ #include "detray/definitions/units.hpp" #include "detray/propagator/actors/resetter.hpp" #include "detray/propagator/base_stepper.hpp" -#include "detray/propagator/detail/covariance_engine.hpp" -#include "detray/propagator/detail/covariance_kernel.hpp" #include "detray/propagator/navigation_policies.hpp" #include "detray/tracks/tracks.hpp" #include "detray/utils/column_wise_operator.hpp" @@ -41,7 +39,6 @@ class rk_stepper final using vector3 = typename transform3_type::vector3; using context_type = typename magnetic_field_t::context_type; using matrix_operator = typename base_type::matrix_operator; - using covariance_engine = typename base_type::covariance_engine; using column_wise_op = column_wise_operator; using free_track_parameters_type = From c18ea8ddb7a47166444b7dd9f15e2632f455704d Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 6 Sep 2022 20:42:17 -0700 Subject: [PATCH 17/63] Remove unused files --- .vscode/settings.json | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7f280ff4a..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "files.associations": { - "*.sycl": "cpp", - "*.ipp": "cpp", - "array": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "memory": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "type_traits": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "utility": "cpp" - } -} \ No newline at end of file From 933527b4dd928e3d28d4b8fb582c201e407131a1 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 6 Sep 2022 21:07:20 -0700 Subject: [PATCH 18/63] Fix some --- core/CMakeLists.txt | 3 +- .../detray/propagator/actors/aborters.hpp | 42 ------------- .../propagator/actors/surface_targeter.hpp | 59 +++++++++++++++++++ .../tests/common/covariance_engine.inl | 12 ++-- tests/unit_tests/smatrix/CMakeLists.txt | 4 +- 5 files changed, 69 insertions(+), 51 deletions(-) create mode 100644 core/include/detray/propagator/actors/surface_targeter.hpp diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 073816267..4e46c09ac 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -74,8 +74,9 @@ detray_add_library( detray_core core "include/detray/materials/predefined_materials.hpp" # propagator include(s) "include/detray/propagator/actors/aborters.hpp" - "include/detray/propagator/actors/resetter.hpp" "include/detray/propagator/actors/bound_to_bound_updater.hpp" + "include/detray/propagator/actors/resetter.hpp" + "include/detray/propagator/actors/surface_targeter.hpp" "include/detray/propagator/actor_chain.hpp" "include/detray/propagator/base_actor.hpp" "include/detray/propagator/base_stepper.hpp" diff --git a/core/include/detray/propagator/actors/aborters.hpp b/core/include/detray/propagator/actors/aborters.hpp index 166e46962..f074eba7c 100644 --- a/core/include/detray/propagator/actors/aborters.hpp +++ b/core/include/detray/propagator/actors/aborters.hpp @@ -62,46 +62,4 @@ struct pathlimit_aborter : actor { } }; -struct ignorer : actor { - - struct state { - - scalar _path_limit; - dindex _target_surface_index = dindex_invalid; - }; - - /// Enforces the path limit on a stepper state - /// - /// @param abrt_state contains the path limit - /// @param prop_state state of the propagation - template - DETRAY_HOST_DEVICE void operator()(state &actor_state, - propagator_state_t &prop_state) const { - - prop_state._heartbeat = true; - auto &navigation = prop_state._navigation; - auto &stepping = prop_state._stepping; - navigation.set_full_trust(); - - scalar residual = actor_state._path_limit - stepping.path_length(); - stepping.set_constraint(residual); - - typename propagator_state_t::navigator_state_type::intersection_t is; - is.index = actor_state._target_surface_index; - is.path = residual; - auto &candidates = navigation.candidates(); - candidates.clear(); - candidates.push_back(is); - navigation.set_next(candidates.begin()); - navigation.set_unknown(); - - if (residual < std::abs(1e-5)) { - prop_state._heartbeat = false; - candidates.push_back({}); - navigation.next()++; - navigation.set_on_module(); - } - } -}; - } // namespace detray diff --git a/core/include/detray/propagator/actors/surface_targeter.hpp b/core/include/detray/propagator/actors/surface_targeter.hpp new file mode 100644 index 000000000..1a54689fc --- /dev/null +++ b/core/include/detray/propagator/actors/surface_targeter.hpp @@ -0,0 +1,59 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "detray/definitions/qualifiers.hpp" +#include "detray/propagator/base_actor.hpp" +#include "detray/propagator/base_stepper.hpp" + +namespace detray { + +struct surface_targeter : actor { + + struct state { + + scalar _path; + dindex _target_surface_index = dindex_invalid; + }; + + /// Enforces thepath limit on a stepper state + /// + /// @param abrt_state contains the path limit + /// @param prop_state state of the propagation + template + DETRAY_HOST_DEVICE void operator()(state &actor_state, + propagator_state_t &prop_state) const { + + prop_state._heartbeat = true; + auto &navigation = prop_state._navigation; + auto &stepping = prop_state._stepping; + navigation.set_full_trust(); + + scalar residual = actor_state._path - stepping.path_length(); + stepping.set_constraint(residual); + + typename propagator_state_t::navigator_state_type::intersection_t is; + is.index = actor_state._target_surface_index; + is.path = residual; + auto &candidates = navigation.candidates(); + candidates.clear(); + candidates.push_back(is); + navigation.set_next(candidates.begin()); + navigation.set_unknown(); + + if (residual < std::abs(1e-5)) { + prop_state._heartbeat = false; + candidates.push_back({}); + navigation.next()++; + navigation.set_on_module(); + } + } +}; + +} // namespace detray \ No newline at end of file diff --git a/tests/common/include/tests/common/covariance_engine.inl b/tests/common/include/tests/common/covariance_engine.inl index a1dd8b3f5..27cb27860 100644 --- a/tests/common/include/tests/common/covariance_engine.inl +++ b/tests/common/include/tests/common/covariance_engine.inl @@ -9,9 +9,9 @@ #include "detray/definitions/units.hpp" #include "detray/field/constant_magnetic_field.hpp" #include "detray/propagator/actor_chain.hpp" -#include "detray/propagator/actors/aborters.hpp" #include "detray/propagator/actors/bound_to_bound_updater.hpp" #include "detray/propagator/actors/resetter.hpp" +#include "detray/propagator/actors/surface_targeter.hpp" #include "detray/propagator/line_stepper.hpp" #include "detray/propagator/navigator.hpp" #include "detray/propagator/propagator.hpp" @@ -63,8 +63,8 @@ TEST(covariance_transport, cartesian) { using crk_stepper_t = rk_stepper>; using actor_chain_t = - actor_chain, - resetter>; + actor_chain, resetter>; using propagator_t = propagator; // Generate track starting point @@ -111,11 +111,11 @@ TEST(covariance_transport, cartesian) { scalar S = 2. * getter::perp(mom) / getter::norm(B) * M_PI; // Actors - ignorer::state loop{S, 0}; + surface_targeter::state targeter{S, 0}; bound_to_bound_updater::state bound_updater{}; resetter::state rst{}; - actor_chain_t::state actor_states = std::tie(loop, bound_updater, rst); + actor_chain_t::state actor_states = std::tie(targeter, bound_updater, rst); propagator_t p({}, {}); propagator_t::state propagation(bound_param0, mag_field, det, actor_states); @@ -146,7 +146,7 @@ TEST(covariance_transport, cartesian) { EXPECT_NEAR(crk_state().dir()[0], dir[0], epsilon); EXPECT_NEAR(crk_state().dir()[1], dir[1], epsilon); EXPECT_NEAR(crk_state().dir()[2], dir[2], epsilon); - EXPECT_NEAR(crk_state.path_length(), loop._path_limit, epsilon); + EXPECT_NEAR(crk_state.path_length(), targeter._path, epsilon); // Bound state after one turn propagation const auto bound_param1 = crk_state._bound_params; diff --git a/tests/unit_tests/smatrix/CMakeLists.txt b/tests/unit_tests/smatrix/CMakeLists.txt index 4d9b78314..e8e5c469e 100644 --- a/tests/unit_tests/smatrix/CMakeLists.txt +++ b/tests/unit_tests/smatrix/CMakeLists.txt @@ -7,8 +7,8 @@ # Set up all of the "standard" tests. detray_add_test( smatrix "smatrix_actor_chain.cpp" "smatrix_annulus2.cpp" "smatrix_container.cpp" - "smatrix_coordinate_cartesian2.cpp" "smatrix_coordinate_cartesian3.cpp" "smatrix_coordinate_cylindrical.cpp" - "vc_array_coordinate_cylindrical3.cpp" "smatrix_coordinate_line2.cpp" "smatrix_coordinate_polar2.cpp" + "smatrix_coordinate_cartesian2.cpp" "smatrix_coordinate_cartesian3.cpp" "smatrix_coordinate_cylindrical2.cpp" + "smatrix_coordinate_cylindrical3.cpp" "smatrix_coordinate_line2.cpp" "smatrix_coordinate_polar2.cpp" "smatrix_core.cpp" "smatrix_covariance_engine.cpp" "smatrix_cylinder_intersection.cpp" "smatrix_cylinder3.cpp" "smatrix_detector.cpp" "smatrix_geometry_volume_graph.cpp" From e5c0272f37e12bf34aaf58487a8cef32a5487f10 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 6 Sep 2022 21:17:08 -0700 Subject: [PATCH 19/63] Change some file names --- core/include/detray/propagator/rk_stepper.hpp | 8 ---- core/include/detray/propagator/rk_stepper.ipp | 40 ------------------- ...ce_engine.inl => covariance_transport.inl} | 2 - tests/unit_tests/array/CMakeLists.txt | 2 +- ...ine.cpp => array_covariance_transport.cpp} | 2 +- tests/unit_tests/eigen/CMakeLists.txt | 2 +- ...ine.cpp => eigen_covariance_transport.cpp} | 2 +- tests/unit_tests/smatrix/CMakeLists.txt | 2 +- ...e.cpp => smatrix_covariance_transport.cpp} | 2 +- tests/unit_tests/vc/CMakeLists.txt | 2 +- ....cpp => vc_array_covariance_transport.cpp} | 2 +- 11 files changed, 8 insertions(+), 58 deletions(-) rename tests/common/include/tests/common/{covariance_engine.inl => covariance_transport.inl} (98%) rename tests/unit_tests/array/{array_covariance_engine.cpp => array_covariance_transport.cpp} (81%) rename tests/unit_tests/eigen/{eigen_covariance_engine.cpp => eigen_covariance_transport.cpp} (81%) rename tests/unit_tests/smatrix/{smatrix_covariance_engine.cpp => smatrix_covariance_transport.cpp} (81%) rename tests/unit_tests/vc/{vc_array_covariance_engine.cpp => vc_array_covariance_transport.cpp} (81%) diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index 00ec36fba..c9871fe2d 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -121,14 +121,6 @@ class rk_stepper final */ template DETRAY_HOST_DEVICE bool step(propagation_state_t& propagation); - - /** Get the bound state at the surface - * - * @return returning the bound track parameter - */ - template - DETRAY_HOST_DEVICE bound_track_parameters_type bound_state( - propagation_state_t& /*propagation*/, const transform3_type& /*trf*/); }; } // namespace detray diff --git a/core/include/detray/propagator/rk_stepper.ipp b/core/include/detray/propagator/rk_stepper.ipp index 78d77139b..f2388363b 100644 --- a/core/include/detray/propagator/rk_stepper.ipp +++ b/core/include/detray/propagator/rk_stepper.ipp @@ -270,43 +270,3 @@ bool detray::rk_stepper class array_t> -template -typename detray::template rk_stepper::bound_track_parameters_type -detray::rk_stepper::bound_state(propagation_state_t& /*propagation*/, - const transform3_t& /*trf3*/) { - - return detray::bound_track_parameters(); - - // @TODO: Use detector kernel - /* - auto& stepping = propagation._stepping; - auto& navigation = propagation._navigation; - - // Get the free vector - const auto& free_vector = stepping().vector(); - - // Get the bound vector - const auto bound_vector = - vector_engine().free_to_bound_vector(trf3, free_vector); - - // Get the bound covariance - covariance_engine().bound_to_bound_covariance_update( - trf3, stepping._bound_covariance, free_vector, stepping._jac_to_global, - stepping._jac_transport, stepping._derivative); - - // Reset the jacobians in RK stepper state - covariance_engine().reinitialize_jacobians( - trf3, bound_vector, stepping._jac_to_global, stepping._jac_transport, - stepping._derivative); - - return detray::bound_track_parameters( - navigation.current_object(), bound_vector, stepping._bound_covariance); - */ -} diff --git a/tests/common/include/tests/common/covariance_engine.inl b/tests/common/include/tests/common/covariance_transport.inl similarity index 98% rename from tests/common/include/tests/common/covariance_engine.inl rename to tests/common/include/tests/common/covariance_transport.inl index 27cb27860..f0cdf5b48 100644 --- a/tests/common/include/tests/common/covariance_engine.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -31,8 +31,6 @@ using namespace detray; using vector2 = __plugin::vector2; -using vector3 = __plugin::vector3; -using point3 = __plugin::point3; using transform3 = __plugin::transform3; using matrix_operator = standard_matrix_operator; using mag_field_t = constant_magnetic_field<>; diff --git a/tests/unit_tests/array/CMakeLists.txt b/tests/unit_tests/array/CMakeLists.txt index 7959f124b..1df2e3a3b 100644 --- a/tests/unit_tests/array/CMakeLists.txt +++ b/tests/unit_tests/array/CMakeLists.txt @@ -9,7 +9,7 @@ detray_add_test( array "array_actor_chain.cpp" "array_annulus2.cpp" "array_container.cpp" "array_coordinate_cartesian2.cpp" "array_coordinate_cartesian3.cpp" "array_coordinate_cylindrical2.cpp" "array_coordinate_cylindrical3.cpp" "array_coordinate_line2.cpp" "array_coordinate_polar2.cpp" - "array_core.cpp" "array_covariance_engine.cpp" + "array_core.cpp" "array_covariance_transport.cpp" "array_cylinder_intersection.cpp" "array_cylinder3.cpp" "array_detector.cpp" "array_geometry_volume_graph.cpp" "array_geometry_linking.cpp" "array_geometry_navigation.cpp" "array_geometry_scan.cpp" diff --git a/tests/unit_tests/array/array_covariance_engine.cpp b/tests/unit_tests/array/array_covariance_transport.cpp similarity index 81% rename from tests/unit_tests/array/array_covariance_engine.cpp rename to tests/unit_tests/array/array_covariance_transport.cpp index 1bf23ee84..9a0ea844b 100644 --- a/tests/unit_tests/array/array_covariance_engine.cpp +++ b/tests/unit_tests/array/array_covariance_transport.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/array_definitions.hpp" -#include "tests/common/covariance_engine.inl" +#include "tests/common/covariance_transport.inl" diff --git a/tests/unit_tests/eigen/CMakeLists.txt b/tests/unit_tests/eigen/CMakeLists.txt index 89d03313c..257b121c5 100644 --- a/tests/unit_tests/eigen/CMakeLists.txt +++ b/tests/unit_tests/eigen/CMakeLists.txt @@ -9,7 +9,7 @@ detray_add_test( eigen "eigen_actor_chain.cpp" "eigen_annulus2.cpp" "eigen_container.cpp" "eigen_coordinate_cartesian2.cpp" "eigen_coordinate_cartesian3.cpp" "eigen_coordinate_cylindrical2.cpp" "eigen_coordinate_cylindrical3.cpp" "eigen_coordinate_line2.cpp" "eigen_coordinate_polar2.cpp" - "eigen_core.cpp" "eigen_covariance_engine.cpp" + "eigen_core.cpp" "eigen_covariance_transport.cpp" "eigen_cylinder_intersection.cpp" "eigen_cylinder3.cpp" "eigen_detector.cpp" "eigen_geometry_volume_graph.cpp" "eigen_geometry_linking.cpp" "eigen_geometry_navigation.cpp" "eigen_geometry_scan.cpp" diff --git a/tests/unit_tests/eigen/eigen_covariance_engine.cpp b/tests/unit_tests/eigen/eigen_covariance_transport.cpp similarity index 81% rename from tests/unit_tests/eigen/eigen_covariance_engine.cpp rename to tests/unit_tests/eigen/eigen_covariance_transport.cpp index 724ae9ca6..ea47ced77 100644 --- a/tests/unit_tests/eigen/eigen_covariance_engine.cpp +++ b/tests/unit_tests/eigen/eigen_covariance_transport.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/eigen_definitions.hpp" -#include "tests/common/covariance_engine.inl" +#include "tests/common/covariance_transport.inl" diff --git a/tests/unit_tests/smatrix/CMakeLists.txt b/tests/unit_tests/smatrix/CMakeLists.txt index e8e5c469e..e3531f4c9 100644 --- a/tests/unit_tests/smatrix/CMakeLists.txt +++ b/tests/unit_tests/smatrix/CMakeLists.txt @@ -9,7 +9,7 @@ detray_add_test( smatrix "smatrix_actor_chain.cpp" "smatrix_annulus2.cpp" "smatrix_container.cpp" "smatrix_coordinate_cartesian2.cpp" "smatrix_coordinate_cartesian3.cpp" "smatrix_coordinate_cylindrical2.cpp" "smatrix_coordinate_cylindrical3.cpp" "smatrix_coordinate_line2.cpp" "smatrix_coordinate_polar2.cpp" - "smatrix_core.cpp" "smatrix_covariance_engine.cpp" + "smatrix_core.cpp" "smatrix_covariance_transport.cpp" "smatrix_cylinder_intersection.cpp" "smatrix_cylinder3.cpp" "smatrix_detector.cpp" "smatrix_geometry_volume_graph.cpp" "smatrix_geometry_linking.cpp" "smatrix_geometry_navigation.cpp" diff --git a/tests/unit_tests/smatrix/smatrix_covariance_engine.cpp b/tests/unit_tests/smatrix/smatrix_covariance_transport.cpp similarity index 81% rename from tests/unit_tests/smatrix/smatrix_covariance_engine.cpp rename to tests/unit_tests/smatrix/smatrix_covariance_transport.cpp index 86658c813..6ee31244a 100644 --- a/tests/unit_tests/smatrix/smatrix_covariance_engine.cpp +++ b/tests/unit_tests/smatrix/smatrix_covariance_transport.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/smatrix_definitions.hpp" -#include "tests/common/covariance_engine.inl" +#include "tests/common/covariance_transport.inl" diff --git a/tests/unit_tests/vc/CMakeLists.txt b/tests/unit_tests/vc/CMakeLists.txt index 5c7a47f98..27824df7b 100644 --- a/tests/unit_tests/vc/CMakeLists.txt +++ b/tests/unit_tests/vc/CMakeLists.txt @@ -9,7 +9,7 @@ detray_add_test( vc_array "vc_array_actor_chain.cpp" "vc_array_annulus2.cpp" "vc_array_container.cpp" "vc_array_coordinate_cartesian2.cpp" "vc_array_coordinate_cartesian3.cpp" "vc_array_coordinate_cylindrical2.cpp" "vc_array_coordinate_cylindrical3.cpp" "vc_array_coordinate_line2.cpp" "vc_array_coordinate_polar2.cpp" - "vc_array_core.cpp" "vc_array_covariance_engine.cpp" "vc_array_cylinder_intersection.cpp" + "vc_array_core.cpp" "vc_array_covariance_transport.cpp" "vc_array_cylinder_intersection.cpp" "vc_array_cylinder3.cpp" "vc_array_detector.cpp" "vc_array_geometry_volume_graph.cpp" "vc_array_geometry_linking.cpp" "vc_array_geometry_navigation.cpp" "vc_array_geometry_scan.cpp" "vc_array_guided_navigator.cpp" diff --git a/tests/unit_tests/vc/vc_array_covariance_engine.cpp b/tests/unit_tests/vc/vc_array_covariance_transport.cpp similarity index 81% rename from tests/unit_tests/vc/vc_array_covariance_engine.cpp rename to tests/unit_tests/vc/vc_array_covariance_transport.cpp index f28ae08e7..310d1fd30 100644 --- a/tests/unit_tests/vc/vc_array_covariance_engine.cpp +++ b/tests/unit_tests/vc/vc_array_covariance_transport.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/vc_array_definitions.hpp" -#include "tests/common/covariance_engine.inl" \ No newline at end of file +#include "tests/common/covariance_transport.inl" \ No newline at end of file From bc3c55250312ee86485dc681b5b48df04bf45fdd Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 7 Sep 2022 12:03:44 -0700 Subject: [PATCH 20/63] Fix bug --- core/include/detray/coordinates/polar2.hpp | 22 ++++++++++++------- .../tests/common/coordinate_polar2.inl | 1 + .../tests/common/covariance_transport.inl | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index b4403f76b..3ccf94da3 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -125,12 +125,15 @@ struct polar2 : public coordinate_base { const auto frame = reference_frame(trf3, mask, pos, dir); // dxdu = d(x,y,z)/du - const auto dxdL = matrix_actor().template block<3, 1>(frame, 0, 0); + const matrix_type<3, 1> dxdL = + matrix_actor().template block<3, 1>(frame, 0, 0); // dxdv = d(x,y,z)/dv - const auto dydL = matrix_actor().template block<3, 1>(frame, 0, 1); + const matrix_type<3, 1> dydL = + matrix_actor().template block<3, 1>(frame, 0, 1); - const auto col0 = dxdL * lcos_phi + dydL * lsin_phi; - const auto col1 = (dydL * lcos_phi - dxdL * lsin_phi) * lrad; + const matrix_type<3, 1> col0 = dxdL * lcos_phi + dydL * lsin_phi; + const matrix_type<3, 1> col1 = + (dydL * lcos_phi - dxdL * lsin_phi) * lrad; matrix_actor().template set_block<3, 1>( bound_pos_to_free_pos_derivative, col0, e_free_pos0, e_bound_loc0); @@ -163,12 +166,15 @@ struct polar2 : public coordinate_base { const auto frameT = matrix_actor().transpose(frame); // dudG = du/d(x,y,z) - const auto dudG = matrix_actor().template block<1, 3>(frameT, 0, 0); + const matrix_type<1, 3> dudG = + matrix_actor().template block<1, 3>(frameT, 0, 0); // dvdG = dv/d(x,y,z) - const auto dvdG = matrix_actor().template block<1, 3>(frameT, 1, 0); + const matrix_type<1, 3> dvdG = + matrix_actor().template block<1, 3>(frameT, 1, 0); - const auto row0 = dudG * lcos_phi + dvdG * lsin_phi; - const auto row1 = 1. / lrad * (lcos_phi * dvdG - lsin_phi * dudG); + const matrix_type<1, 3> row0 = dudG * lcos_phi + dvdG * lsin_phi; + const matrix_type<1, 3> row1 = + 1. / lrad * (lcos_phi * dvdG - lsin_phi * dudG); matrix_actor().template set_block<1, 3>( free_pos_to_bound_pos_derivative, row0, e_bound_loc0, e_free_pos0); diff --git a/tests/common/include/tests/common/coordinate_polar2.inl b/tests/common/include/tests/common/coordinate_polar2.inl index 0294121d0..ead064cab 100644 --- a/tests/common/include/tests/common/coordinate_polar2.inl +++ b/tests/common/include/tests/common/coordinate_polar2.inl @@ -94,6 +94,7 @@ TEST(coordinate, polar2) { for (std::size_t i = 0; i < 6; i++) { for (std::size_t j = 0; j < 6; j++) { + if (i == j) { EXPECT_NEAR(m.element(J, i, j), 1., isclose); } else { diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index f0cdf5b48..b58ec7360 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -139,8 +139,8 @@ TEST(covariance_transport, cartesian) { // RK stepper and its state EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); - EXPECT_FLOAT_EQ(crk_state().pos()[1], local[0]); // y - EXPECT_FLOAT_EQ(crk_state().pos()[2], local[1]); // z + EXPECT_NEAR(crk_state().pos()[1], local[0], epsilon); // y + EXPECT_NEAR(crk_state().pos()[2], local[1], epsilon); // z EXPECT_NEAR(crk_state().dir()[0], dir[0], epsilon); EXPECT_NEAR(crk_state().dir()[1], dir[1], epsilon); EXPECT_NEAR(crk_state().dir()[2], dir[2], epsilon); From fc81a0e19ae276dc99f187eed261064a596fedad Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 7 Sep 2022 13:43:52 -0700 Subject: [PATCH 21/63] Pass the test --- tests/unit_tests/cuda/propagator_cuda.cpp | 4 ++++ tests/unit_tests/cuda/propagator_cuda_kernel.hpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/cuda/propagator_cuda.cpp b/tests/unit_tests/cuda/propagator_cuda.cpp index eb463b6e5..0b703e8a8 100644 --- a/tests/unit_tests/cuda/propagator_cuda.cpp +++ b/tests/unit_tests/cuda/propagator_cuda.cpp @@ -7,6 +7,7 @@ #include +#include #include #include @@ -150,9 +151,12 @@ TEST_P(CudaPropagatorWithRkStepper, propagator) { // ASSERT_NEAR((host_pl - device_pl) / host_pl, 0, is_close); + /* ASSERT_EQ(host_positions[i].size(), device_positions[i].size()); ASSERT_NEAR(host_pl, device_pl, host_pl * is_close); + */ + // std::cout << host_pl << " " << device_pl << std::endl; auto& host_pos = host_positions[i][j]; auto& device_pos = device_positions[i][j]; diff --git a/tests/unit_tests/cuda/propagator_cuda_kernel.hpp b/tests/unit_tests/cuda/propagator_cuda_kernel.hpp index fec072370..8f1793d18 100644 --- a/tests/unit_tests/cuda/propagator_cuda_kernel.hpp +++ b/tests/unit_tests/cuda/propagator_cuda_kernel.hpp @@ -59,8 +59,8 @@ constexpr unsigned int theta_steps{10}; constexpr unsigned int phi_steps{10}; constexpr scalar rk_tolerance{1e-4}; -constexpr scalar overstep_tolerance{-7 * unit_constants::um}; -constexpr scalar constrainted_step_size{1. * unit_constants::mm}; +constexpr scalar overstep_tolerance{-3 * unit_constants::um}; +constexpr scalar constrainted_step_size{2. * unit_constants::mm}; constexpr scalar is_close{1e-4}; constexpr scalar path_limit{2 * unit_constants::m}; From 56b8952be7dbf1ffeac968bb61f44cd1eaee1b34 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 7 Sep 2022 14:05:21 -0700 Subject: [PATCH 22/63] Fix some --- tests/unit_tests/cuda/propagator_cuda.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/unit_tests/cuda/propagator_cuda.cpp b/tests/unit_tests/cuda/propagator_cuda.cpp index 0b703e8a8..7018df745 100644 --- a/tests/unit_tests/cuda/propagator_cuda.cpp +++ b/tests/unit_tests/cuda/propagator_cuda.cpp @@ -7,7 +7,6 @@ #include -#include #include #include @@ -151,12 +150,8 @@ TEST_P(CudaPropagatorWithRkStepper, propagator) { // ASSERT_NEAR((host_pl - device_pl) / host_pl, 0, is_close); - /* ASSERT_EQ(host_positions[i].size(), device_positions[i].size()); - ASSERT_NEAR(host_pl, device_pl, host_pl * is_close); - */ - // std::cout << host_pl << " " << device_pl << std::endl; auto& host_pos = host_positions[i][j]; auto& device_pos = device_positions[i][j]; From e4eb991e423a8ff275e1177b5776526be9ca4b73 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 7 Sep 2022 15:26:51 -0700 Subject: [PATCH 23/63] FIx a bug --- core/include/detray/coordinates/cartesian2.hpp | 13 +++++++------ .../propagator/actors/bound_to_bound_updater.hpp | 16 +++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index 36ba78f97..4ad5ed893 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -89,7 +89,8 @@ struct cartesian2 final : public coordinate_base { const point3 & /*pos*/, const vector3 & /*dir*/) const { vector3 ret; - const auto n = matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); + const matrix_type<3, 1> n = + matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); ret[0] = matrix_actor().element(n, 0, 0); ret[1] = matrix_actor().element(n, 1, 0); ret[2] = matrix_actor().element(n, 2, 0); @@ -108,10 +109,10 @@ struct cartesian2 final : public coordinate_base { bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { - const auto frame = reference_frame(trf3, mask, pos, dir); + const rotation_matrix frame = reference_frame(trf3, mask, pos, dir); // Get d(x,y,z)/d(loc0, loc1) - const auto bound_pos_to_free_pos_derivative = + const matrix_type<3, 2> bound_pos_to_free_pos_derivative = matrix_actor().template block<3, 2>(frame, 0, 0); matrix_actor().template set_block(free_to_bound_jacobian, @@ -124,11 +125,11 @@ struct cartesian2 final : public coordinate_base { free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { - const auto frame = reference_frame(trf3, mask, pos, dir); - const auto frameT = matrix_actor().transpose(frame); + const rotation_matrix frame = reference_frame(trf3, mask, pos, dir); + const rotation_matrix frameT = matrix_actor().transpose(frame); // Get d(loc0, loc1)/d(x,y,z) - const auto free_pos_to_bound_pos_derivative = + const matrix_type<2, 3> free_pos_to_bound_pos_derivative = matrix_actor().template block<2, 3>(frameT, 0, 0); matrix_actor().template set_block(bound_to_free_jacobian, diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp index 8dd2ef2a9..2bad0c28d 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -101,6 +101,15 @@ struct bound_to_bound_updater : actor { const bound_to_free_matrix& bound_to_free_jacobian = stepping._jac_to_global; + // Acts version + const free_matrix correction_term = + matrix_actor().template identity() + + path_correction; + + const bound_matrix full_jacobian = + free_to_bound_jacobian * correction_term * + free_transport_jacobian * bound_to_free_jacobian; + /* const bound_matrix full_jacobian = free_to_bound_jacobian * @@ -108,13 +117,6 @@ struct bound_to_bound_updater : actor { bound_to_free_jacobian; */ - // Acts version - const bound_matrix full_jacobian = - free_to_bound_jacobian * - (matrix_actor().template identity() + - path_correction) * - free_transport_jacobian * bound_to_free_jacobian; - // No path correction /* const bound_matrix full_jacobian = free_to_bound_jacobian * From a9b33a0c5b93260bfe3741ad8810b1f4bcec79b1 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Fri, 9 Sep 2022 19:52:37 -0700 Subject: [PATCH 24/63] Backup --- .../detray/coordinates/coordinate_base.hpp | 136 +++++++++--------- .../detray/propagator/base_stepper.hpp | 29 +++- .../detray/propagator/line_stepper.hpp | 10 +- core/include/detray/propagator/propagator.hpp | 23 +-- core/include/detray/propagator/rk_stepper.hpp | 19 +-- .../tests/common/covariance_transport.inl | 81 ++++++++++- .../tests/common/test_telescope_detector.inl | 5 +- 7 files changed, 202 insertions(+), 101 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index b4d59eac1..e1bb44b79 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -10,6 +10,7 @@ // Project include(s). #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/detail/trajectories.hpp" +#include "detray/propagator/base_stepper.hpp" #include "detray/tracks/detail/track_helper.hpp" namespace detray { @@ -217,103 +218,110 @@ struct coordinate_base { // Path length const auto s = stepping._s; - // helix - helix hlx(stepping(), &stepping._step_data.b_last); - - // B field at the destination surface - matrix_type<1, 3> h; - matrix_actor().set_block(h, hlx._h0, 0, 0); + // Position and direction + const auto pos = stepping().pos(); + const auto dir = stepping().dir(); // dir matrix_type<1, 3> t; - matrix_actor().set_block(t, hlx._t0, 0, 0); - - // Normalized vector of h X t - matrix_type<1, 3> n; - matrix_actor().set_block(n, hlx._n0, 0, 0); + matrix_actor().set_block(t, dir, 0, 0); // Surface normal vector (w) matrix_type<1, 3> w; const auto normal = - Derived().normal(trf3, mask, hlx.pos(), hlx._t0); + Derived().normal(trf3, mask, pos, dir); matrix_actor().set_block(w, normal, 0, 0); - // w cross h - matrix_type<1, 3> wh; - matrix_actor().set_block(wh, vector::cross(normal, hlx._h0), 0, 0); + // w dot t + const scalar_type wt = vector::dot(normal, dir); - // Alpha - const scalar_type A = hlx._alpha; + // transpose of t + const matrix_type<3, 1> t_T = matrix_actor().transpose(t); - // K - const scalar_type K = hlx._K; + // r correction term + const matrix_type<1, 3> r_term = -1. / wt * w; - // Ks = K*s - const scalar_type Ks = K * s; + // dr/dr0 + const matrix_type<3, 3> drdr0 = t_T * r_term; - // w dot t - const scalar_type wt = vector::dot(normal, hlx._t0); + matrix_actor().template set_block<3, 3>(path_correction, drdr0, + e_free_pos0, e_free_pos0); - // r correction term - const matrix_type<1, 3> r_term = -1. / wt * w; + if constexpr (stepper_state_t::id == stepping::id::e_rk) { - // t correction term - matrix_type<1, 3> t_term = matrix_actor().template zero<1, 3>(); - t_term = - t_term + (Ks - std::sin(Ks)) / K * vector::dot(hlx._h0, normal) * h; + // helix + helix hlx(stepping(), &stepping._step_data.b_last); - t_term = t_term + std::sin(Ks) / K * w; + // B field at the destination surface + matrix_type<1, 3> h; + matrix_actor().set_block(h, hlx._h0, 0, 0); - t_term = t_term + (1 - std::cos(Ks)) / K * wh; + // Normalized vector of h X t + matrix_type<1, 3> n; + matrix_actor().set_block(n, hlx._n0, 0, 0); - t_term = -1. / wt * t_term; + // w cross h + matrix_type<1, 3> wh; + matrix_actor().set_block(wh, vector::cross(normal, hlx._h0), 0, 0); - // qoverp correction term - const scalar_type L_term = - -1. / wt * A * Ks / hlx.qop() * vector::dot(normal, hlx._n0); + // Alpha + const scalar_type A = hlx._alpha; - // transpose of t - const matrix_type<3, 1> t_T = matrix_actor().transpose(t); + // K + const scalar_type K = hlx._K; - // dr/dr0 - const matrix_type<3, 3> drdr0 = t_T * r_term; + // Ks = K*s + const scalar_type Ks = K * s; - // dr/dt0 - const matrix_type<3, 3> drdt0 = t_T * t_term; + // t correction term + matrix_type<1, 3> t_term = matrix_actor().template zero<1, 3>(); + t_term = t_term + + (Ks - std::sin(Ks)) / K * vector::dot(hlx._h0, normal) * h; - // dr/dL0 (L = qoverp) - const matrix_type<3, 1> drdL0 = t_T * L_term; + t_term = t_term + std::sin(Ks) / K * w; - // transpose of n - const matrix_type<3, 1> n_T = matrix_actor().transpose(n); + t_term = t_term + (1 - std::cos(Ks)) / K * wh; - // dt/dr0 - const scalar_type AK = A * K; - const matrix_type<3, 3> dtdr0 = AK * n_T * r_term; + t_term = -1. / wt * t_term; - // dt/dt0 - const matrix_type<3, 3> dtdt0 = AK * n_T * t_term; + // qoverp correction term + const scalar_type L_term = + -1. / wt * A * Ks / hlx.qop() * vector::dot(normal, hlx._n0); - // dt/dL0 - const matrix_type<3, 1> dtdL0 = AK * n_T * L_term; + // dr/dt0 + const matrix_type<3, 3> drdt0 = t_T * t_term; - matrix_actor().template set_block<3, 3>(path_correction, drdr0, - e_free_pos0, e_free_pos0); + // dr/dL0 (L = qoverp) + const matrix_type<3, 1> drdL0 = t_T * L_term; + + // transpose of n + const matrix_type<3, 1> n_T = matrix_actor().transpose(n); + + // dt/dr0 + const scalar_type AK = A * K; + const matrix_type<3, 3> dtdr0 = AK * n_T * r_term; + + // dt/dt0 + const matrix_type<3, 3> dtdt0 = AK * n_T * t_term; + + // dt/dL0 + const matrix_type<3, 1> dtdL0 = AK * n_T * L_term; - matrix_actor().template set_block<3, 3>(path_correction, drdt0, - e_free_pos0, e_free_dir0); + matrix_actor().template set_block<3, 3>(path_correction, drdt0, + e_free_pos0, e_free_dir0); - matrix_actor().template set_block<3, 1>(path_correction, drdL0, - e_free_pos0, e_free_qoverp); + matrix_actor().template set_block<3, 1>(path_correction, drdL0, + e_free_pos0, e_free_qoverp); - matrix_actor().template set_block<3, 3>(path_correction, dtdr0, - e_free_dir0, e_free_pos0); + matrix_actor().template set_block<3, 3>(path_correction, dtdr0, + e_free_dir0, e_free_pos0); - matrix_actor().template set_block<3, 3>(path_correction, dtdt0, - e_free_dir0, e_free_dir0); + matrix_actor().template set_block<3, 3>(path_correction, dtdt0, + e_free_dir0, e_free_dir0); - matrix_actor().template set_block<3, 1>(path_correction, dtdL0, - e_free_dir0, e_free_qoverp); + matrix_actor().template set_block<3, 1>(path_correction, dtdL0, + e_free_dir0, e_free_qoverp); + } return path_correction; } diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index 7c7a93424..3b27b9988 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -10,11 +10,21 @@ // Project include(s). #include "detray/definitions/qualifiers.hpp" #include "detray/definitions/units.hpp" +#include "detray/propagator/actors/resetter.hpp" #include "detray/propagator/constrained_step.hpp" #include "detray/tracks/tracks.hpp" namespace detray { +namespace stepping { + +enum class id { + e_linear = 0, + e_rk = 1, +}; + +} // namespace stepping + /// Base stepper implementation template class base_stepper { @@ -56,9 +66,22 @@ class base_stepper { state(const free_track_parameters_type &t) : _track(t) {} /// Sets track parameters from bound track parameter. - DETRAY_HOST_DEVICE - state(const bound_track_parameters_type &bound_params) - : _bound_params(bound_params) {} + template + DETRAY_HOST_DEVICE state( + const bound_track_parameters_type &bound_params, + const detector_t &det) + : _bound_params(bound_params) { + + const auto &surface_container = det.surfaces(); + const auto &trf_store = det.transform_store(); + const auto &mask_store = det.mask_store(); + const auto &surface = + surface_container[bound_params.surface_link()]; + + mask_store + .template execute::kernel>( + surface.mask_type(), trf_store, surface, *this); + } /// free track parameter free_track_parameters_type _track; diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index 91f2efa71..2534c2417 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -30,15 +30,23 @@ class line_stepper final using policy_type = policy_t; using free_track_parameters_type = typename base_type::free_track_parameters_type; + using bound_track_parameters_type = + typename base_type::bound_track_parameters_type; using transform3_type = transform3_t; struct state : public base_type::state { - using field_type = int; + static constexpr const stepping::id id = stepping::id::e_linear; DETRAY_HOST_DEVICE state(const free_track_parameters_type &t) : base_type::state(t) {} + template + DETRAY_HOST_DEVICE state( + const bound_track_parameters_type &bound_params, + const detector_t &det) + : base_type::template state(bound_params, det) {} + /// Update the track state in a straight line. DETRAY_HOST_DEVICE inline void advance_track() { diff --git a/core/include/detray/propagator/propagator.hpp b/core/include/detray/propagator/propagator.hpp index 4c026d5df..bb0908f50 100644 --- a/core/include/detray/propagator/propagator.hpp +++ b/core/include/detray/propagator/propagator.hpp @@ -57,7 +57,6 @@ struct propagator { using detector_type = typename navigator_t::detector_type; using context_type = typename detector_type::context; - using field_type = typename stepper_t::state::field_type; using stepper_state_type = typename stepper_t::state; using navigator_state_type = typename navigator_t::state; @@ -74,12 +73,10 @@ struct propagator { _navigation(det, std::move(candidates)), _actor_states(actor_states) {} - template < - typename track_t, - std::enable_if_t, bool> = true> + template DETRAY_HOST_DEVICE state( - const track_t &t_in, const field_type &magnetic_field, - const detector_type &det, + const free_track_parameters_type &t_in, + const field_t &magnetic_field, const detector_type &det, typename actor_chain_t::state actor_states = {}, vector_type &&candidates = {}) : _stepping(t_in, magnetic_field), @@ -87,11 +84,19 @@ struct propagator { _actor_states(actor_states) {} /// Construct the propagation state with bound parameter - template < - std::enable_if_t, bool> = true> + DETRAY_HOST_DEVICE state( + const bound_track_parameters_type ¶m, const detector_type &det, + typename actor_chain_t::state actor_states = {}, + vector_type &&candidates = {}) + : _stepping(param, det), + _navigation(det, std::move(candidates)), + _actor_states(actor_states) {} + + /// Construct the propagation state with bound parameter + template DETRAY_HOST_DEVICE state( const bound_track_parameters_type ¶m, - const field_type &magnetic_field, const detector_type &det, + const field_t &magnetic_field, const detector_type &det, typename actor_chain_t::state actor_states = {}, vector_type &&candidates = {}) : _stepping(param, magnetic_field, det), diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index c9871fe2d..867eed1e2 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -10,7 +10,6 @@ // Project include(s). #include "detray/definitions/qualifiers.hpp" #include "detray/definitions/units.hpp" -#include "detray/propagator/actors/resetter.hpp" #include "detray/propagator/base_stepper.hpp" #include "detray/propagator/navigation_policies.hpp" #include "detray/tracks/tracks.hpp" @@ -51,7 +50,7 @@ class rk_stepper final struct state : public base_type::state { - using field_type = magnetic_field_t; + static constexpr const stepping::id id = stepping::id::e_rk; DETRAY_HOST_DEVICE state(const free_track_parameters_type& t, @@ -61,19 +60,9 @@ class rk_stepper final template DETRAY_HOST_DEVICE state( const bound_track_parameters_type& bound_params, - const field_type mag_field, const detector_t& det) - : base_type::state(bound_params), _magnetic_field(mag_field) { - - const auto& surface_container = det.surfaces(); - const auto& trf_store = det.transform_store(); - const auto& mask_store = det.mask_store(); - const auto& surface = - surface_container[bound_params.surface_link()]; - - mask_store - .template execute::kernel>( - surface.mask_type(), trf_store, surface, *this); - } + const magnetic_field_t mag_field, const detector_t& det) + : base_type::template state(bound_params, det), + _magnetic_field(mag_field) {} /// error tolerance scalar _tolerance = 1e-4; diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index b58ec7360..7b34d35fa 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -38,7 +38,7 @@ using mag_field_t = constant_magnetic_field<>; constexpr scalar epsilon = 1e-3; // This tests the covariance transport in rk stepper -TEST(covariance_transport, cartesian) { +TEST(covariance_transport, rk_stepper_cartesian) { vecmem::host_memory_resource host_mr; @@ -68,10 +68,8 @@ TEST(covariance_transport, cartesian) { // Generate track starting point vector2 local{2, 3}; vector3 mom{0.001, 0., 0.}; - // vector3 mom{0.02, 0.02, 0.}; vector3 dir = vector::normalize(mom); - // vector3 mom{0.01, 0.01, 0.01}; scalar time = 0.; scalar q = -1.; @@ -90,10 +88,8 @@ TEST(covariance_transport, cartesian) { getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; - // Note: Set theta error as ZERO, to constrain the loc1 divergence getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; - // getter::element(bound_cov, e_bound_theta, e_bound_theta) = 1.; getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; @@ -171,4 +167,77 @@ TEST(covariance_transport, cartesian) { crk_state.path_length() * epsilon); } } -} \ No newline at end of file + + // covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + printf("%f ", matrix_operator().element(bound_cov0, i, j)); + } + printf("\n"); + } + printf("\n"); + + // covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + printf("%f ", matrix_operator().element(bound_cov1, i, j)); + } + printf("\n"); + } + printf("\n"); +} + +TEST(covariance_transport, linear_stepper_cartesian) { + + vecmem::host_memory_resource host_mr; + + using ln_stepper_t = line_stepper; + + // Use rectangular surfaces + constexpr bool rectangular = false; + + // Create telescope detector with a single plane + typename ln_stepper_t::free_track_parameters_type default_trk{ + {0, 0, 0}, 0, {0, 0, 1}, -1}; + std::vector positions = {0., 10., 20., 30., 40., 50., 60.}; + + const auto det = create_telescope_detector( + host_mr, positions, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}); + + using navigator_t = navigator; + using cline_stepper_t = line_stepper>; + using actor_chain_t = + actor_chain, + resetter>; + using propagator_t = + propagator; + + // Bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = 0.; + getter::element(bound_vector, e_bound_loc1, 0) = 0.; + getter::element(bound_vector, e_bound_phi, 0) = 0.; + getter::element(bound_vector, e_bound_theta, 0) = 0.; + getter::element(bound_vector, e_bound_qoverp, 0) = -1. / 10.; + getter::element(bound_vector, e_bound_time, 0) = 0.; + + // Bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template identity(); + + // Bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + // Actors + bound_to_bound_updater::state bound_updater{}; + resetter::state rst{}; + actor_chain_t::state actor_states = std::tie(bound_updater, rst); + + propagator_t p({}, {}); + // propagator_t::state propagation(bound_param0, det, actor_states); + + // Run propagator + // p.propagate(propagation); +} diff --git a/tests/common/include/tests/common/test_telescope_detector.inl b/tests/common/include/tests/common/test_telescope_detector.inl index 71074315a..55c5c8754 100644 --- a/tests/common/include/tests/common/test_telescope_detector.inl +++ b/tests/common/include/tests/common/test_telescope_detector.inl @@ -33,10 +33,9 @@ struct prop_state { stepping_t _stepping; navigation_t _navigation; - using field_type = typename stepping_t::field_type; - template - prop_state(const track_t &t_in, const field_type &field, + template + prop_state(const track_t &t_in, const field_t &field, const typename navigation_t::detector_type &det) : _stepping(t_in, field), _navigation(det) {} }; From 945266bf4a73d7191ca6f667dbeea295e3de1881 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 12 Sep 2022 14:07:22 -0700 Subject: [PATCH 25/63] Add line stepper covariance transport --- .../detray/coordinates/coordinate_base.hpp | 4 ++ .../actors/bound_to_bound_updater.hpp | 4 ++ .../detray/propagator/line_stepper.hpp | 23 +++++++++++ .../detray/tracks/bound_track_parameters.hpp | 3 ++ .../tests/common/covariance_transport.inl | 41 +++++++++++++++---- 5 files changed, 68 insertions(+), 7 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index e1bb44b79..c66d9c5c2 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -13,6 +13,9 @@ #include "detray/propagator/base_stepper.hpp" #include "detray/tracks/detail/track_helper.hpp" +// System include(s). +#include + namespace detray { /** Coordinate base struct @@ -188,6 +191,7 @@ struct coordinate_base { matrix_actor().element(jac_to_local, e_bound_time, e_free_time) = 1; // Set d(phi, theta)/d(n_x, n_y, n_z) + // @note This codes have a serious bug when theta is equal to zero... matrix_actor().element(jac_to_local, e_bound_phi, e_free_dir0) = -1. * sin_phi / sin_theta; matrix_actor().element(jac_to_local, e_bound_phi, e_free_dir1) = diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp index 2bad0c28d..c6d08eb60 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp @@ -140,6 +140,7 @@ struct bound_to_bound_updater : actor { propagator_state_t& propagation) const { auto& navigation = propagation._navigation; + auto& stepping = propagation._stepping; // Do covariance transport when the track is on surface if (navigation.is_on_module()) { @@ -154,6 +155,9 @@ struct bound_to_bound_updater : actor { // Surface const auto& surface = surface_container[is->index]; + // Set surface link + stepping._bound_params.set_surface_link(is->index); + mask_store.template execute(surface.mask_type(), surface, propagation); } diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index 2534c2417..78f33e9bb 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -33,6 +33,7 @@ class line_stepper final using bound_track_parameters_type = typename base_type::bound_track_parameters_type; using transform3_type = transform3_t; + using matrix_operator = typename base_type::matrix_operator; struct state : public base_type::state { @@ -55,6 +56,25 @@ class line_stepper final this->_path_length += this->_step_size; } + + DETRAY_HOST_DEVICE + inline void advance_jacobian() { + + // The step transport matrix in global coordinates + auto D = + matrix_operator().template identity(); + + // d(x,y,z)/d(n_x,n_y,n_z) + auto dxdn = + this->_step_size * matrix_operator().template identity<3, 3>(); + matrix_operator().template set_block<3, 3>(D, dxdn, e_free_pos0, + e_free_dir0); + + /// NOTE: Let's skip the element for d(time)/d(qoverp) for the + /// moment.. + + this->_jac_transport = D * this->_jac_transport; + } }; /// Take a step, regulared by a constrained step @@ -89,6 +109,9 @@ class line_stepper final // Update track state stepping.advance_track(); + // Advance jacobian transport + stepping.advance_jacobian(); + // Call navigation update policy policy_t{}(stepping.policy_state(), propagation); diff --git a/core/include/detray/tracks/bound_track_parameters.hpp b/core/include/detray/tracks/bound_track_parameters.hpp index be7bb63c0..a675816c8 100644 --- a/core/include/detray/tracks/bound_track_parameters.hpp +++ b/core/include/detray/tracks/bound_track_parameters.hpp @@ -57,6 +57,9 @@ struct bound_track_parameters { DETRAY_HOST_DEVICE const std::size_t& surface_link() const { return m_surface_link; } + DETRAY_HOST_DEVICE + void set_surface_link(std::size_t link) { m_surface_link = link; } + DETRAY_HOST_DEVICE const vector_type& vector() const { return m_vector; } diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index 7b34d35fa..88747057d 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -114,7 +114,7 @@ TEST(covariance_transport, rk_stepper_cartesian) { propagator_t p({}, {}); propagator_t::state propagation(bound_param0, mag_field, det, actor_states); - crk_stepper_t::state &crk_state = propagation._stepping; + crk_stepper_t::state& crk_state = propagation._stepping; // Decrease tolerance down to 1e-8 crk_state._tolerance = 1e-8; @@ -169,6 +169,7 @@ TEST(covariance_transport, rk_stepper_cartesian) { } // covaraince + /* for (std::size_t i = 0; i < e_bound_size; i++) { for (std::size_t j = 0; j < e_bound_size; j++) { printf("%f ", matrix_operator().element(bound_cov0, i, j)); @@ -185,6 +186,7 @@ TEST(covariance_transport, rk_stepper_cartesian) { printf("\n"); } printf("\n"); + */ } TEST(covariance_transport, linear_stepper_cartesian) { @@ -194,14 +196,14 @@ TEST(covariance_transport, linear_stepper_cartesian) { using ln_stepper_t = line_stepper; // Use rectangular surfaces - constexpr bool rectangular = false; + constexpr bool unbounded = true; // Create telescope detector with a single plane typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {0, 0, 1}, -1}; + {0, 0, 0}, 0, {1, 0, 0}, -1}; std::vector positions = {0., 10., 20., 30., 40., 50., 60.}; - const auto det = create_telescope_detector( + const auto det = create_telescope_detector( host_mr, positions, ln_stepper_t(), typename ln_stepper_t::state{default_trk}); @@ -218,7 +220,7 @@ TEST(covariance_transport, linear_stepper_cartesian) { getter::element(bound_vector, e_bound_loc0, 0) = 0.; getter::element(bound_vector, e_bound_loc1, 0) = 0.; getter::element(bound_vector, e_bound_phi, 0) = 0.; - getter::element(bound_vector, e_bound_theta, 0) = 0.; + getter::element(bound_vector, e_bound_theta, 0) = M_PI / 4.; getter::element(bound_vector, e_bound_qoverp, 0) = -1. / 10.; getter::element(bound_vector, e_bound_time, 0) = 0.; @@ -226,6 +228,10 @@ TEST(covariance_transport, linear_stepper_cartesian) { typename bound_track_parameters::covariance_type bound_cov = matrix_operator().template identity(); + // Note: Set angle error as ZERO, to constrain the loc0 and loc1 divergence + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 0.; + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + // Bound track parameter const bound_track_parameters bound_param0(0, bound_vector, bound_cov); @@ -236,8 +242,29 @@ TEST(covariance_transport, linear_stepper_cartesian) { actor_chain_t::state actor_states = std::tie(bound_updater, rst); propagator_t p({}, {}); - // propagator_t::state propagation(bound_param0, det, actor_states); + propagator_t::state propagation(bound_param0, det, actor_states); // Run propagator - // p.propagate(propagation); + p.propagate(propagation); + + // Bound state after one turn propagation + const auto& bound_param1 = propagation._stepping._bound_params; + + // const auto bound_vec0 = bound_param0.vector(); + // const auto bound_vec1 = bound_param1.vector(); + + const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); + + // Check if the track reaches the final surface + EXPECT_EQ(bound_param0.surface_link(), 0); + EXPECT_EQ(bound_param1.surface_link(), 5); + + // Check covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), epsilon); + } + } } From f559af71ac02f3a0b2ac45bcf1fdaf461a10eff7 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 12 Sep 2022 14:22:10 -0700 Subject: [PATCH 26/63] Remove comments --- .../tests/common/covariance_transport.inl | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index 88747057d..614ef5d07 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -167,26 +167,6 @@ TEST(covariance_transport, rk_stepper_cartesian) { crk_state.path_length() * epsilon); } } - - // covaraince - /* - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - printf("%f ", matrix_operator().element(bound_cov0, i, j)); - } - printf("\n"); - } - printf("\n"); - - // covaraince - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - printf("%f ", matrix_operator().element(bound_cov1, i, j)); - } - printf("\n"); - } - printf("\n"); - */ } TEST(covariance_transport, linear_stepper_cartesian) { From 2bc61917ba91ee5953598954b3b25756dbaa134e Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 12 Sep 2022 15:00:06 -0700 Subject: [PATCH 27/63] FIx unused parameter --- core/include/detray/coordinates/coordinate_base.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index c66d9c5c2..9b3f438d1 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -219,9 +219,6 @@ struct coordinate_base { using helix = detail::helix; - // Path length - const auto s = stepping._s; - // Position and direction const auto pos = stepping().pos(); const auto dir = stepping().dir(); @@ -253,6 +250,9 @@ struct coordinate_base { if constexpr (stepper_state_t::id == stepping::id::e_rk) { + // Path length + const auto s = stepping._s; + // helix helix hlx(stepping(), &stepping._step_data.b_last); From 8b99787d2980467a7716c51f6c1420309725e3d7 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 14 Sep 2022 11:59:53 -0700 Subject: [PATCH 28/63] Backup --- .../include/detray/coordinates/cartesian2.hpp | 5 + .../detray/coordinates/coordinate_base.hpp | 4 + .../detray/coordinates/cylindrical2.hpp | 6 + core/include/detray/coordinates/line2.hpp | 161 ++++++++-- core/include/detray/coordinates/polar2.hpp | 6 + core/include/detray/masks/annulus2.hpp | 3 +- core/include/detray/masks/cylinder3.hpp | 2 +- core/include/detray/masks/line.hpp | 2 +- core/include/detray/masks/rectangle2.hpp | 2 +- core/include/detray/masks/ring2.hpp | 2 +- core/include/detray/masks/single3.hpp | 2 +- core/include/detray/masks/trapezoid2.hpp | 2 +- core/include/detray/masks/unmasked.hpp | 2 +- .../include/tests/common/coordinate_line2.inl | 302 +++++++++++++++++- 14 files changed, 473 insertions(+), 28 deletions(-) diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index 4ad5ed893..efb026c20 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -145,6 +145,11 @@ struct cartesian2 final : public coordinate_base { // Do nothing } + template + DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( + free_to_bound_matrix & /*free_to_bound_jacobian*/, + const transform3_t & /*trf3*/, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const {} }; // struct cartesian2 } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 9b3f438d1..dec5c95cd 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -206,6 +206,10 @@ struct coordinate_base { // Set d(Free Qop)/d(Bound Qop) matrix_actor().element(jac_to_local, e_bound_qoverp, e_free_qoverp) = 1; + // Set d(loc0, loc1)/d(n_x, n_y, n_z) + Derived().set_free_dir_to_bound_pos_derivative( + jac_to_local, trf3, mask, pos, dir); + return jac_to_local; } diff --git a/core/include/detray/coordinates/cylindrical2.hpp b/core/include/detray/coordinates/cylindrical2.hpp index fb0ccbaee..6515f478c 100644 --- a/core/include/detray/coordinates/cylindrical2.hpp +++ b/core/include/detray/coordinates/cylindrical2.hpp @@ -169,6 +169,12 @@ struct cylindrical2 : public coordinate_base { // Do nothing } + template + DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( + free_to_bound_matrix & /*free_to_bound_jacobian*/, + const transform3_t & /*trf3*/, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const {} + }; // struct cylindrical2 } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/line2.hpp b/core/include/detray/coordinates/line2.hpp index 53e54798f..0756e4861 100644 --- a/core/include/detray/coordinates/line2.hpp +++ b/core/include/detray/coordinates/line2.hpp @@ -111,17 +111,34 @@ struct line2 : public coordinate_base { rotation_matrix rot = matrix_actor().template zero<3, 3>(); // y axis of the new frame is the z axis of line coordinate - const auto new_yaxis = matrix_actor().template block<3, 1>(trf3, 0, 2); + const auto new_yaxis = + matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); // x axis of the new frame is (yaxis x track direction) - const auto new_xaxis = vector::cross(new_yaxis, dir); + auto new_xaxis = vector::cross(new_yaxis, dir); + new_xaxis = vector::normalize(new_xaxis); // z axis const auto new_zaxis = vector::cross(new_xaxis, new_yaxis); - matrix_actor().set_block<3, 1>(rot, new_xaxis, 0, 0); - matrix_actor().set_block<3, 1>(rot, new_yaxis, 0, 1); - matrix_actor().set_block<3, 1>(rot, new_zaxis, 0, 2); + printf("new xaxis: %f %f %f \n", new_xaxis[0], new_xaxis[1], + new_xaxis[2]); + + printf("new yaxis: %f %f %f \n", + matrix_actor().element(new_yaxis, 0, 0), + matrix_actor().element(new_yaxis, 1, 0), + matrix_actor().element(new_yaxis, 2, 0)); + + printf("new zaxis: %f %f %f \n", new_zaxis[0], new_zaxis[1], + new_zaxis[2]); + + matrix_actor().element(rot, 0, 0) = new_xaxis[0]; + matrix_actor().element(rot, 1, 0) = new_xaxis[1]; + matrix_actor().element(rot, 2, 0) = new_xaxis[2]; + matrix_actor().template set_block<3, 1>(rot, new_yaxis, 0, 1); + matrix_actor().element(rot, 0, 2) = new_zaxis[0]; + matrix_actor().element(rot, 1, 2) = new_zaxis[1]; + matrix_actor().element(rot, 2, 2) = new_zaxis[2]; return rot; } @@ -171,13 +188,19 @@ struct line2 : public coordinate_base { const auto frame = reference_frame(trf3, mask, pos, dir); // new x_axis - const auto new_xaxis = matrix_actor().template block<3, 1>(frame, 0, 0); + // const auto new_xaxis = matrix_actor().template block<3, 1>(frame, 0, + // 0); + const auto new_xaxis = getter::vector<3>(frame, 0, 0); // new y_axis - const auto new_yaxis = matrix_actor().template block<3, 1>(frame, 0, 1); + // const auto new_yaxis = matrix_actor().template block<3, 1>(frame, 0, + // 1); + const auto new_yaxis = getter::vector<3>(frame, 0, 1); // new z_axis - const auto new_zaxis = matrix_actor().template block<3, 1>(frame, 0, 2); + // const auto new_zaxis = matrix_actor().template block<3, 1>(frame, 0, + // 2); + const auto new_zaxis = getter::vector<3>(frame, 0, 2); // the projection of direction onto ref frame normal scalar_type ipdn = 1. / vector::dot(dir, new_zaxis); @@ -196,24 +219,126 @@ struct line2 : public coordinate_base { // build the cross product of d(D)/d(eBoundPhi) components with y axis auto y_cross_dNdTheta = vector::cross(new_yaxis, dNdTheta); + const scalar_type C = ipdn * local2[0]; // and correct for the x axis components - auto phi_to_free_pos_derivative = + vector3 phi_to_free_pos_derivative = y_cross_dNdPhi - new_xaxis * vector::dot(new_xaxis, y_cross_dNdPhi); - phi_to_free_pos_derivative *= ipdn * local2[0]; - auto theta_to_free_pos_derivative = + phi_to_free_pos_derivative = C * phi_to_free_pos_derivative; + + vector3 theta_to_free_pos_derivative = y_cross_dNdTheta - new_xaxis * vector::dot(new_xaxis, y_cross_dNdTheta); - theta_to_free_pos_derivative *= ipdn * local2[0]; + + printf("y_cross_dNdTheta: %f %f %f \n", y_cross_dNdTheta[0], + y_cross_dNdTheta[1], y_cross_dNdTheta[2]); + + theta_to_free_pos_derivative = C * theta_to_free_pos_derivative; // Set the jacobian components - matrix_actor().set_block<3, 1>(bound_to_free_jacobian, - phi_to_free_pos_derivative, e_free_pos0, - e_bound_phi); + matrix_actor().element(bound_to_free_jacobian, e_free_pos0, + e_bound_phi) = phi_to_free_pos_derivative[0]; + matrix_actor().element(bound_to_free_jacobian, e_free_pos1, + e_bound_phi) = phi_to_free_pos_derivative[1]; + matrix_actor().element(bound_to_free_jacobian, e_free_pos2, + e_bound_phi) = phi_to_free_pos_derivative[2]; + matrix_actor().element(bound_to_free_jacobian, e_free_pos0, + e_bound_theta) = theta_to_free_pos_derivative[0]; + matrix_actor().element(bound_to_free_jacobian, e_free_pos1, + e_bound_theta) = theta_to_free_pos_derivative[1]; + matrix_actor().element(bound_to_free_jacobian, e_free_pos2, + e_bound_theta) = theta_to_free_pos_derivative[2]; + } - matrix_actor().set_block<3, 1>(bound_to_free_jacobian, - theta_to_free_pos_derivative, - e_free_pos0, e_bound_theta); + template + DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( + free_to_bound_matrix &free_to_bound_jacobian, const transform3_t &trf3, + const mask_t & /*mask*/, const point3 &pos, const vector3 &dir) const { + + // Position in matrix + matrix_type<3, 1> P; + matrix_actor().element(P, 0, 0) = pos[0]; + matrix_actor().element(P, 1, 0) = pos[1]; + matrix_actor().element(P, 2, 0) = pos[2]; + + // Direction in matrix + matrix_type<3, 1> d; + matrix_actor().element(d, 0, 0) = dir[0]; + matrix_actor().element(d, 1, 0) = dir[1]; + matrix_actor().element(d, 2, 0) = dir[2]; + + printf("dir %f %f %f \n", dir[0], dir[1], dir[2]); + + // line direction + const matrix_type<3, 1> w = + matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); + + // line center + const matrix_type<3, 1> T = + matrix_actor().template block<3, 1>(trf3.matrix(), 0, 3); + + // Projection of line to track direction + const scalar wd = vector::dot(w, d); + + const scalar_type denom = scalar_type{1.} - (wd * wd); + + // vector from track position to line center + const matrix_type<3, 1> trk_to_line = T - P; + + printf("T %f %f %f \n", matrix_actor().element(T, 0, 0), + matrix_actor().element(T, 1, 0), + matrix_actor().element(T, 2, 0)); + + printf("P %f %f %f \n", matrix_actor().element(P, 0, 0), + matrix_actor().element(P, 1, 0), + matrix_actor().element(P, 2, 0)); + + printf("w %f %f %f \n", matrix_actor().element(w, 0, 0), + matrix_actor().element(w, 1, 0), + matrix_actor().element(w, 2, 0)); + + printf("wd %f \n", wd); + + printf("trk_to_line %f %f %f \n", + matrix_actor().element(trk_to_line, 0, 0), + matrix_actor().element(trk_to_line, 1, 0), + matrix_actor().element(trk_to_line, 2, 0)); + + // track to line projection on line direction + const scalar_type trk_to_line_proj_on_line = + vector::dot(trk_to_line, w); + + // track to line projection on track direction + const scalar_type trk_to_line_proj_on_dir = vector::dot(trk_to_line, d); + + // dA/d(n_x,n_y,n_z) + + // d(n_x,n_y,n_z)/d(n_x,n_y,n_z) + matrix_type<3, 3> dndn = matrix_actor().template identity<3, 3>(); + matrix_actor().element(dndn, 0, 1) = -dir[1] / dir[0]; + matrix_actor().element(dndn, 0, 2) = -dir[2] / dir[0]; + matrix_actor().element(dndn, 1, 0) = -dir[0] / dir[1]; + matrix_actor().element(dndn, 1, 2) = -dir[2] / dir[1]; + matrix_actor().element(dndn, 2, 0) = -dir[0] / dir[2]; + matrix_actor().element(dndn, 2, 1) = -dir[1] / dir[2]; + + matrix_type<3, 3> dndn_T = matrix_actor().transpose(dndn); + + matrix_type<3, 1> Q = + 1. / denom * (trk_to_line - trk_to_line_proj_on_line * w); + + // dA/d(n_x,n_y,n_z) + const matrix_type<3, 1> dBdn = wd * dndn_T * Q; + + matrix_actor().element(free_to_bound_jacobian, e_bound_loc1, + e_free_dir0) = + matrix_actor().element(dBdn, 0, 0); + matrix_actor().element(free_to_bound_jacobian, e_bound_loc1, + e_free_dir1) = + matrix_actor().element(dBdn, 1, 0); + matrix_actor().element(free_to_bound_jacobian, e_bound_loc1, + e_free_dir2) = + matrix_actor().element(dBdn, 2, 0); } }; diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index 3ccf94da3..8cea4482f 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -193,6 +193,12 @@ struct polar2 : public coordinate_base { const point3 & /*pos*/, const vector3 & /*dir*/) const { // Do nothing } + + template + DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( + free_to_bound_matrix & /*free_to_bound_jacobian*/, + const transform3_t & /*trf3*/, const mask_t & /*mask*/, + const point3 & /*pos*/, const vector3 & /*dir*/) const {} }; } // namespace detray \ No newline at end of file diff --git a/core/include/detray/masks/annulus2.hpp b/core/include/detray/masks/annulus2.hpp index 725254bc0..a71fa9607 100644 --- a/core/include/detray/masks/annulus2.hpp +++ b/core/include/detray/masks/annulus2.hpp @@ -8,7 +8,8 @@ #pragma once // Project include(s). -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" +#include "detray/coordinates/polar2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/intersection.hpp" #include "detray/intersection/plane_intersector.hpp" diff --git a/core/include/detray/masks/cylinder3.hpp b/core/include/detray/masks/cylinder3.hpp index d223a6bef..832acd408 100644 --- a/core/include/detray/masks/cylinder3.hpp +++ b/core/include/detray/masks/cylinder3.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/cylinder_intersector.hpp" #include "detray/intersection/intersection.hpp" diff --git a/core/include/detray/masks/line.hpp b/core/include/detray/masks/line.hpp index 616b1c9b6..81cc139a7 100644 --- a/core/include/detray/masks/line.hpp +++ b/core/include/detray/masks/line.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s). -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/intersection.hpp" #include "detray/intersection/line_intersector.hpp" diff --git a/core/include/detray/masks/rectangle2.hpp b/core/include/detray/masks/rectangle2.hpp index 3df451c96..77cea0866 100644 --- a/core/include/detray/masks/rectangle2.hpp +++ b/core/include/detray/masks/rectangle2.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s). -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/intersection.hpp" #include "detray/intersection/plane_intersector.hpp" diff --git a/core/include/detray/masks/ring2.hpp b/core/include/detray/masks/ring2.hpp index 422ce7f20..b253fbcda 100644 --- a/core/include/detray/masks/ring2.hpp +++ b/core/include/detray/masks/ring2.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/intersection.hpp" #include "detray/intersection/plane_intersector.hpp" diff --git a/core/include/detray/masks/single3.hpp b/core/include/detray/masks/single3.hpp index 681801143..a47e3fec1 100644 --- a/core/include/detray/masks/single3.hpp +++ b/core/include/detray/masks/single3.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/intersection.hpp" #include "detray/intersection/plane_intersector.hpp" diff --git a/core/include/detray/masks/trapezoid2.hpp b/core/include/detray/masks/trapezoid2.hpp index 9c44e14ae..2fd742464 100644 --- a/core/include/detray/masks/trapezoid2.hpp +++ b/core/include/detray/masks/trapezoid2.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/intersection.hpp" #include "detray/intersection/plane_intersector.hpp" diff --git a/core/include/detray/masks/unmasked.hpp b/core/include/detray/masks/unmasked.hpp index 7484b1052..b033f266c 100644 --- a/core/include/detray/masks/unmasked.hpp +++ b/core/include/detray/masks/unmasked.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/coordinates/coordinates.hpp" +#include "detray/coordinates/cartesian2.hpp" #include "detray/intersection/intersection.hpp" #include "detray/intersection/plane_intersector.hpp" #include "detray/masks/mask_base.hpp" diff --git a/tests/common/include/tests/common/coordinate_line2.inl b/tests/common/include/tests/common/coordinate_line2.inl index 0437bd159..15302c263 100644 --- a/tests/common/include/tests/common/coordinate_line2.inl +++ b/tests/common/include/tests/common/coordinate_line2.inl @@ -18,12 +18,191 @@ using point3 = __plugin::point3; using vector3 = __plugin::vector3; using transform3 = __plugin::transform3; using matrix_operator = typename transform3::matrix_actor; +using size_type = typename matrix_operator::size_ty; +template +using matrix_type = typename matrix_operator::template matrix_type; const scalar isclose = 1e-5; -// This test line2 coordinate -TEST(coordinate, line2) { +TEST(coordinate, line2_case1) { + + // Preparation work + vector3 z = {1., 1., 1.}; + z = vector::normalize(z); + vector3 x = {1., 0., -1.}; + x = vector::normalize(x); + const point3 t = {0., 0., 0.}; + const transform3 trf(t, z, x); + const line2 l2; + const point3 global1 = {1, 1.5, 0.5}; + const vector3 mom = {0., 1., 1.}; + const vector3 d = vector::normalize(mom); + const scalar time = 0.1; + const scalar charge = -1.; + struct dummy_mask { + } mask; + + // Global to local transformation + const point2 local = l2.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], -1. / sqrt(2), isclose); + ASSERT_NEAR(local[1], sqrt(3), isclose); + + // Local to global transformation + const point3 global2 = l2.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); + + // Free track parameter + const free_track_parameters free_params(global1, time, mom, + charge); + const auto free_vec1 = free_params.vector(); + + const auto bound_vec = l2.free_to_bound_vector(trf, free_vec1); + const auto free_vec2 = l2.bound_to_free_vector(trf, mask, bound_vec); + + const matrix_operator m; + + // Check if the bound vector is correct + ASSERT_NEAR(m.element(bound_vec, 0, 0), -1. / sqrt(2), isclose); + ASSERT_NEAR(m.element(bound_vec, 1, 0), sqrt(3), isclose); + ASSERT_NEAR(m.element(bound_vec, 2, 0), M_PI_2, isclose); + ASSERT_NEAR(m.element(bound_vec, 3, 0), M_PI_4, isclose); + ASSERT_NEAR(m.element(bound_vec, 4, 0), -1. / sqrt(2), isclose); + ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); + + // Check if the same free vector is obtained + for (int i = 0; i < 8; i++) { + ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), + isclose); + } + + // Test Jacobian transformation + const matrix_type<6, 6> J = + l2.free_to_bound_jacobian(trf, mask, free_vec1) * + l2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 6; j++) { + if (i == j) { + EXPECT_NEAR(m.element(J, i, j), 1., isclose); + } else { + EXPECT_NEAR(m.element(J, i, j), 0., isclose); + } + } + } + + const auto free_to_bound = l2.free_to_bound_jacobian(trf, mask, free_vec1); + const auto bound_to_free = l2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 8; i++) { + for (std::size_t j = 0; j < 8; j++) { + printf("%f ", m.element(J, i, j)); + } + printf("\n"); + } + printf("\n"); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 8; j++) { + printf("%f ", m.element(free_to_bound, i, j)); + } + printf("\n"); + } + printf("\n"); + + for (std::size_t i = 0; i < 8; i++) { + for (std::size_t j = 0; j < 6; j++) { + printf("%f ", m.element(bound_to_free, i, j)); + } + printf("\n"); + } +} + +TEST(coordinate, line2_case2) { + + // Preparation work + vector3 z = {1., 2., 3.}; + z = vector::normalize(z); + vector3 x = {2., -4., 2.}; + x = vector::normalize(x); + const point3 t = {0., 0., 0.}; + const transform3 trf(t, z, x); + const line2 l2; + const point2 local1 = {1, 2}; + const vector3 mom = {1., 6., -2.}; + const vector3 d = vector::normalize(mom); + const scalar time = 0.1; + const scalar charge = -1.; + struct dummy_mask { + } mask; + + // local to global transformation + const point3 global = l2.local_to_global(trf, mask, local1, d); + + // global to local transform + const point2 local2 = l2.global_to_local(trf, global, d); + + // Check if the same local position is obtained + ASSERT_NEAR(local1[0], local2[0], isclose); + ASSERT_NEAR(local1[1], local2[1], isclose); + + // Free track parameter + const free_track_parameters free_params(global, time, mom, + charge); + const auto free_vec = free_params.vector(); + const auto bound_vec = l2.free_to_bound_vector(trf, free_vec); + + // Test Jacobian transformation + const matrix_type<6, 6> J = l2.free_to_bound_jacobian(trf, mask, free_vec) * + l2.bound_to_free_jacobian(trf, mask, bound_vec); + + const matrix_operator m; + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 6; j++) { + if (i == j) { + EXPECT_NEAR(m.element(J, i, j), 1., isclose); + } else { + EXPECT_NEAR(m.element(J, i, j), 0., isclose); + } + } + } + + const auto free_to_bound = l2.free_to_bound_jacobian(trf, mask, free_vec); + const auto bound_to_free = l2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 8; i++) { + for (std::size_t j = 0; j < 8; j++) { + printf("%f ", m.element(J, i, j)); + } + printf("\n"); + } + printf("\n"); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 8; j++) { + printf("%f ", m.element(free_to_bound, i, j)); + } + printf("\n"); + } + printf("\n"); + + for (std::size_t i = 0; i < 8; i++) { + for (std::size_t j = 0; j < 6; j++) { + printf("%f ", m.element(bound_to_free, i, j)); + } + printf("\n"); + } +} + +// This test line2 coordinate +TEST(coordinate, line2_case3) { + /* // Preparation work const vector3 z = {0., 0., 1.}; const vector3 x = {1., 0., 0.}; @@ -76,4 +255,123 @@ TEST(coordinate, line2) { ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), isclose); } + + // Test Jacobian transformation + const matrix_type<6, 6> J = + l2.free_to_bound_jacobian(trf, mask, free_vec1) * + l2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 6; j++) { + if (i == j) { + EXPECT_NEAR(m.element(J, i, j), 1., isclose); + } else { + EXPECT_NEAR(m.element(J, i, j), 0., isclose); + } + } + } + */ +} + +// This test line2 coordinate +TEST(coordinate, line2_case4) { + /* + // Preparation work + vector3 z = {0., 1., 1.}; + z = vector::normalize(z); + const vector3 x = {1., 0., 0.}; + // const point3 t = {0., 0., 0.}; + const point3 t = {0., -1., -1.}; + const transform3 trf(t, z, x); + const line2 l2; + const point3 global1 = {1., 0., 0.}; + const vector3 mom = {0., 2., 0.}; + const vector3 d = vector::normalize(mom); + const scalar time = 0.1; + const scalar charge = -1.; + struct dummy_mask { + } mask; + + // Global to local transformation + const point2 local = l2.global_to_local(trf, global1, d); + + // Check if the local position is correct + ASSERT_NEAR(local[0], -1., isclose); + // ASSERT_NEAR(local[1], 0., isclose); + ASSERT_NEAR(local[1], std::sqrt(2), isclose); + + // Local to global transformation + const point3 global2 = l2.local_to_global(trf, mask, local, d); + + // Check if the same global position is obtained + ASSERT_NEAR(global1[0], global2[0], isclose); + ASSERT_NEAR(global1[1], global2[1], isclose); + ASSERT_NEAR(global1[2], global2[2], isclose); + + // Free track parameter + const free_track_parameters free_params(global1, time, mom, + charge); + const auto free_vec1 = free_params.vector(); + + const auto bound_vec = l2.free_to_bound_vector(trf, free_vec1); + const auto free_vec2 = l2.bound_to_free_vector(trf, mask, bound_vec); + + const matrix_operator m; + + // Check if the bound vector is correct + ASSERT_NEAR(m.element(bound_vec, 0, 0), -1., isclose); + // ASSERT_NEAR(m.element(bound_vec, 1, 0), 0, isclose); + ASSERT_NEAR(m.element(bound_vec, 1, 0), std::sqrt(2), isclose); + ASSERT_NEAR(m.element(bound_vec, 2, 0), M_PI_2, isclose); + ASSERT_NEAR(m.element(bound_vec, 3, 0), M_PI_2, isclose); + ASSERT_NEAR(m.element(bound_vec, 4, 0), -0.5, isclose); + ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); + + // Check if the same free vector is obtained + for (int i = 0; i < 8; i++) { + ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), + isclose); + } + + // Test Jacobian transformation + const matrix_type<6, 6> J = + l2.free_to_bound_jacobian(trf, mask, free_vec1) * + l2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 6; j++) { + if (i == j) { + EXPECT_NEAR(m.element(J, i, j), 1., isclose); + } else { + EXPECT_NEAR(m.element(J, i, j), 0., isclose); + } + } + } + + const auto free_to_bound = l2.free_to_bound_jacobian(trf, mask, free_vec1); + const auto bound_to_free = l2.bound_to_free_jacobian(trf, mask, bound_vec); + + for (std::size_t i = 0; i < 8; i++) { + for (std::size_t j = 0; j < 8; j++) { + printf("%f ", m.element(J, i, j)); + } + printf("\n"); + } + printf("\n"); + + for (std::size_t i = 0; i < 6; i++) { + for (std::size_t j = 0; j < 8; j++) { + printf("%f ", m.element(free_to_bound, i, j)); + } + printf("\n"); + } + printf("\n"); + + for (std::size_t i = 0; i < 8; i++) { + for (std::size_t j = 0; j < 6; j++) { + printf("%f ", m.element(bound_to_free, i, j)); + } + printf("\n"); + } + */ } \ No newline at end of file From 30e7647128a90488784ff48296e3de4bb76cf417 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 14 Sep 2022 12:38:10 -0700 Subject: [PATCH 29/63] Remove free dir to bound pos derivative --- .../include/detray/coordinates/cartesian2.hpp | 6 - .../detray/coordinates/coordinate_base.hpp | 4 - .../detray/coordinates/cylindrical2.hpp | 7 - core/include/detray/coordinates/line2.hpp | 111 --------- core/include/detray/coordinates/polar2.hpp | 6 - core/include/detray/masks/cylinder3.hpp | 2 +- .../include/tests/common/coordinate_line2.inl | 228 ------------------ .../include/tests/common/masks_cylinder3.inl | 1 + .../include/tests/common/masks_ring2.inl | 1 + 9 files changed, 3 insertions(+), 363 deletions(-) diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index efb026c20..aadd70c80 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -144,12 +144,6 @@ struct cartesian2 final : public coordinate_base { const point3 & /*pos*/, const vector3 & /*dir*/) const { // Do nothing } - - template - DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( - free_to_bound_matrix & /*free_to_bound_jacobian*/, - const transform3_t & /*trf3*/, const mask_t & /*mask*/, - const point3 & /*pos*/, const vector3 & /*dir*/) const {} }; // struct cartesian2 } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index dec5c95cd..9b3f438d1 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -206,10 +206,6 @@ struct coordinate_base { // Set d(Free Qop)/d(Bound Qop) matrix_actor().element(jac_to_local, e_bound_qoverp, e_free_qoverp) = 1; - // Set d(loc0, loc1)/d(n_x, n_y, n_z) - Derived().set_free_dir_to_bound_pos_derivative( - jac_to_local, trf3, mask, pos, dir); - return jac_to_local; } diff --git a/core/include/detray/coordinates/cylindrical2.hpp b/core/include/detray/coordinates/cylindrical2.hpp index 6515f478c..6fd3de492 100644 --- a/core/include/detray/coordinates/cylindrical2.hpp +++ b/core/include/detray/coordinates/cylindrical2.hpp @@ -168,13 +168,6 @@ struct cylindrical2 : public coordinate_base { const point3 & /*pos*/, const vector3 & /*dir*/) const { // Do nothing } - - template - DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( - free_to_bound_matrix & /*free_to_bound_jacobian*/, - const transform3_t & /*trf3*/, const mask_t & /*mask*/, - const point3 & /*pos*/, const vector3 & /*dir*/) const {} - }; // struct cylindrical2 } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/line2.hpp b/core/include/detray/coordinates/line2.hpp index 0756e4861..a076d226d 100644 --- a/core/include/detray/coordinates/line2.hpp +++ b/core/include/detray/coordinates/line2.hpp @@ -121,17 +121,6 @@ struct line2 : public coordinate_base { // z axis const auto new_zaxis = vector::cross(new_xaxis, new_yaxis); - printf("new xaxis: %f %f %f \n", new_xaxis[0], new_xaxis[1], - new_xaxis[2]); - - printf("new yaxis: %f %f %f \n", - matrix_actor().element(new_yaxis, 0, 0), - matrix_actor().element(new_yaxis, 1, 0), - matrix_actor().element(new_yaxis, 2, 0)); - - printf("new zaxis: %f %f %f \n", new_zaxis[0], new_zaxis[1], - new_zaxis[2]); - matrix_actor().element(rot, 0, 0) = new_xaxis[0]; matrix_actor().element(rot, 1, 0) = new_xaxis[1]; matrix_actor().element(rot, 2, 0) = new_xaxis[2]; @@ -188,18 +177,12 @@ struct line2 : public coordinate_base { const auto frame = reference_frame(trf3, mask, pos, dir); // new x_axis - // const auto new_xaxis = matrix_actor().template block<3, 1>(frame, 0, - // 0); const auto new_xaxis = getter::vector<3>(frame, 0, 0); // new y_axis - // const auto new_yaxis = matrix_actor().template block<3, 1>(frame, 0, - // 1); const auto new_yaxis = getter::vector<3>(frame, 0, 1); // new z_axis - // const auto new_zaxis = matrix_actor().template block<3, 1>(frame, 0, - // 2); const auto new_zaxis = getter::vector<3>(frame, 0, 2); // the projection of direction onto ref frame normal @@ -230,9 +213,6 @@ struct line2 : public coordinate_base { y_cross_dNdTheta - new_xaxis * vector::dot(new_xaxis, y_cross_dNdTheta); - printf("y_cross_dNdTheta: %f %f %f \n", y_cross_dNdTheta[0], - y_cross_dNdTheta[1], y_cross_dNdTheta[2]); - theta_to_free_pos_derivative = C * theta_to_free_pos_derivative; // Set the jacobian components @@ -249,97 +229,6 @@ struct line2 : public coordinate_base { matrix_actor().element(bound_to_free_jacobian, e_free_pos2, e_bound_theta) = theta_to_free_pos_derivative[2]; } - - template - DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( - free_to_bound_matrix &free_to_bound_jacobian, const transform3_t &trf3, - const mask_t & /*mask*/, const point3 &pos, const vector3 &dir) const { - - // Position in matrix - matrix_type<3, 1> P; - matrix_actor().element(P, 0, 0) = pos[0]; - matrix_actor().element(P, 1, 0) = pos[1]; - matrix_actor().element(P, 2, 0) = pos[2]; - - // Direction in matrix - matrix_type<3, 1> d; - matrix_actor().element(d, 0, 0) = dir[0]; - matrix_actor().element(d, 1, 0) = dir[1]; - matrix_actor().element(d, 2, 0) = dir[2]; - - printf("dir %f %f %f \n", dir[0], dir[1], dir[2]); - - // line direction - const matrix_type<3, 1> w = - matrix_actor().template block<3, 1>(trf3.matrix(), 0, 2); - - // line center - const matrix_type<3, 1> T = - matrix_actor().template block<3, 1>(trf3.matrix(), 0, 3); - - // Projection of line to track direction - const scalar wd = vector::dot(w, d); - - const scalar_type denom = scalar_type{1.} - (wd * wd); - - // vector from track position to line center - const matrix_type<3, 1> trk_to_line = T - P; - - printf("T %f %f %f \n", matrix_actor().element(T, 0, 0), - matrix_actor().element(T, 1, 0), - matrix_actor().element(T, 2, 0)); - - printf("P %f %f %f \n", matrix_actor().element(P, 0, 0), - matrix_actor().element(P, 1, 0), - matrix_actor().element(P, 2, 0)); - - printf("w %f %f %f \n", matrix_actor().element(w, 0, 0), - matrix_actor().element(w, 1, 0), - matrix_actor().element(w, 2, 0)); - - printf("wd %f \n", wd); - - printf("trk_to_line %f %f %f \n", - matrix_actor().element(trk_to_line, 0, 0), - matrix_actor().element(trk_to_line, 1, 0), - matrix_actor().element(trk_to_line, 2, 0)); - - // track to line projection on line direction - const scalar_type trk_to_line_proj_on_line = - vector::dot(trk_to_line, w); - - // track to line projection on track direction - const scalar_type trk_to_line_proj_on_dir = vector::dot(trk_to_line, d); - - // dA/d(n_x,n_y,n_z) - - // d(n_x,n_y,n_z)/d(n_x,n_y,n_z) - matrix_type<3, 3> dndn = matrix_actor().template identity<3, 3>(); - matrix_actor().element(dndn, 0, 1) = -dir[1] / dir[0]; - matrix_actor().element(dndn, 0, 2) = -dir[2] / dir[0]; - matrix_actor().element(dndn, 1, 0) = -dir[0] / dir[1]; - matrix_actor().element(dndn, 1, 2) = -dir[2] / dir[1]; - matrix_actor().element(dndn, 2, 0) = -dir[0] / dir[2]; - matrix_actor().element(dndn, 2, 1) = -dir[1] / dir[2]; - - matrix_type<3, 3> dndn_T = matrix_actor().transpose(dndn); - - matrix_type<3, 1> Q = - 1. / denom * (trk_to_line - trk_to_line_proj_on_line * w); - - // dA/d(n_x,n_y,n_z) - const matrix_type<3, 1> dBdn = wd * dndn_T * Q; - - matrix_actor().element(free_to_bound_jacobian, e_bound_loc1, - e_free_dir0) = - matrix_actor().element(dBdn, 0, 0); - matrix_actor().element(free_to_bound_jacobian, e_bound_loc1, - e_free_dir1) = - matrix_actor().element(dBdn, 1, 0); - matrix_actor().element(free_to_bound_jacobian, e_bound_loc1, - e_free_dir2) = - matrix_actor().element(dBdn, 2, 0); - } }; } // namespace detray \ No newline at end of file diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index 8cea4482f..3ccf94da3 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -193,12 +193,6 @@ struct polar2 : public coordinate_base { const point3 & /*pos*/, const vector3 & /*dir*/) const { // Do nothing } - - template - DETRAY_HOST_DEVICE inline void set_free_dir_to_bound_pos_derivative( - free_to_bound_matrix & /*free_to_bound_jacobian*/, - const transform3_t & /*trf3*/, const mask_t & /*mask*/, - const point3 & /*pos*/, const vector3 & /*dir*/) const {} }; } // namespace detray \ No newline at end of file diff --git a/core/include/detray/masks/cylinder3.hpp b/core/include/detray/masks/cylinder3.hpp index 832acd408..19949a936 100644 --- a/core/include/detray/masks/cylinder3.hpp +++ b/core/include/detray/masks/cylinder3.hpp @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "detray/coordinates/cartesian2.hpp" +#include "detray/coordinates/cylindrical2.hpp" #include "detray/definitions/qualifiers.hpp" #include "detray/intersection/cylinder_intersector.hpp" #include "detray/intersection/intersection.hpp" diff --git a/tests/common/include/tests/common/coordinate_line2.inl b/tests/common/include/tests/common/coordinate_line2.inl index 15302c263..bac23620f 100644 --- a/tests/common/include/tests/common/coordinate_line2.inl +++ b/tests/common/include/tests/common/coordinate_line2.inl @@ -95,32 +95,6 @@ TEST(coordinate, line2_case1) { } } } - - const auto free_to_bound = l2.free_to_bound_jacobian(trf, mask, free_vec1); - const auto bound_to_free = l2.bound_to_free_jacobian(trf, mask, bound_vec); - - for (std::size_t i = 0; i < 8; i++) { - for (std::size_t j = 0; j < 8; j++) { - printf("%f ", m.element(J, i, j)); - } - printf("\n"); - } - printf("\n"); - - for (std::size_t i = 0; i < 6; i++) { - for (std::size_t j = 0; j < 8; j++) { - printf("%f ", m.element(free_to_bound, i, j)); - } - printf("\n"); - } - printf("\n"); - - for (std::size_t i = 0; i < 8; i++) { - for (std::size_t j = 0; j < 6; j++) { - printf("%f ", m.element(bound_to_free, i, j)); - } - printf("\n"); - } } TEST(coordinate, line2_case2) { @@ -172,206 +146,4 @@ TEST(coordinate, line2_case2) { } } } - - const auto free_to_bound = l2.free_to_bound_jacobian(trf, mask, free_vec); - const auto bound_to_free = l2.bound_to_free_jacobian(trf, mask, bound_vec); - - for (std::size_t i = 0; i < 8; i++) { - for (std::size_t j = 0; j < 8; j++) { - printf("%f ", m.element(J, i, j)); - } - printf("\n"); - } - printf("\n"); - - for (std::size_t i = 0; i < 6; i++) { - for (std::size_t j = 0; j < 8; j++) { - printf("%f ", m.element(free_to_bound, i, j)); - } - printf("\n"); - } - printf("\n"); - - for (std::size_t i = 0; i < 8; i++) { - for (std::size_t j = 0; j < 6; j++) { - printf("%f ", m.element(bound_to_free, i, j)); - } - printf("\n"); - } -} - -// This test line2 coordinate -TEST(coordinate, line2_case3) { - /* - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const line2 l2; - const point3 global1 = {3., 3., 9.}; - const vector3 mom = {0., 2., 0.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = l2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], -1., isclose); - ASSERT_NEAR(local[1], 5., isclose); - - // Local to global transformation - const point3 global2 = l2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = l2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = l2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), -1., isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), 5, isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 3, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 4, 0), -0.5, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } - - // Test Jacobian transformation - const matrix_type<6, 6> J = - l2.free_to_bound_jacobian(trf, mask, free_vec1) * - l2.bound_to_free_jacobian(trf, mask, bound_vec); - - for (std::size_t i = 0; i < 6; i++) { - for (std::size_t j = 0; j < 6; j++) { - if (i == j) { - EXPECT_NEAR(m.element(J, i, j), 1., isclose); - } else { - EXPECT_NEAR(m.element(J, i, j), 0., isclose); - } - } - } - */ -} - -// This test line2 coordinate -TEST(coordinate, line2_case4) { - /* - // Preparation work - vector3 z = {0., 1., 1.}; - z = vector::normalize(z); - const vector3 x = {1., 0., 0.}; - // const point3 t = {0., 0., 0.}; - const point3 t = {0., -1., -1.}; - const transform3 trf(t, z, x); - const line2 l2; - const point3 global1 = {1., 0., 0.}; - const vector3 mom = {0., 2., 0.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = l2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], -1., isclose); - // ASSERT_NEAR(local[1], 0., isclose); - ASSERT_NEAR(local[1], std::sqrt(2), isclose); - - // Local to global transformation - const point3 global2 = l2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = l2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = l2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), -1., isclose); - // ASSERT_NEAR(m.element(bound_vec, 1, 0), 0, isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), std::sqrt(2), isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 3, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 4, 0), -0.5, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } - - // Test Jacobian transformation - const matrix_type<6, 6> J = - l2.free_to_bound_jacobian(trf, mask, free_vec1) * - l2.bound_to_free_jacobian(trf, mask, bound_vec); - - for (std::size_t i = 0; i < 6; i++) { - for (std::size_t j = 0; j < 6; j++) { - if (i == j) { - EXPECT_NEAR(m.element(J, i, j), 1., isclose); - } else { - EXPECT_NEAR(m.element(J, i, j), 0., isclose); - } - } - } - - const auto free_to_bound = l2.free_to_bound_jacobian(trf, mask, free_vec1); - const auto bound_to_free = l2.bound_to_free_jacobian(trf, mask, bound_vec); - - for (std::size_t i = 0; i < 8; i++) { - for (std::size_t j = 0; j < 8; j++) { - printf("%f ", m.element(J, i, j)); - } - printf("\n"); - } - printf("\n"); - - for (std::size_t i = 0; i < 6; i++) { - for (std::size_t j = 0; j < 8; j++) { - printf("%f ", m.element(free_to_bound, i, j)); - } - printf("\n"); - } - printf("\n"); - - for (std::size_t i = 0; i < 8; i++) { - for (std::size_t j = 0; j < 6; j++) { - printf("%f ", m.element(bound_to_free, i, j)); - } - printf("\n"); - } - */ } \ No newline at end of file diff --git a/tests/common/include/tests/common/masks_cylinder3.inl b/tests/common/include/tests/common/masks_cylinder3.inl index 1057fc7d8..03c0ebb03 100644 --- a/tests/common/include/tests/common/masks_cylinder3.inl +++ b/tests/common/include/tests/common/masks_cylinder3.inl @@ -7,6 +7,7 @@ #include +#include "detray/coordinates/cartesian2.hpp" #include "detray/intersection/cylinder_intersector.hpp" #include "detray/masks/cylinder3.hpp" diff --git a/tests/common/include/tests/common/masks_ring2.inl b/tests/common/include/tests/common/masks_ring2.inl index d2e001827..b65fa8a51 100644 --- a/tests/common/include/tests/common/masks_ring2.inl +++ b/tests/common/include/tests/common/masks_ring2.inl @@ -7,6 +7,7 @@ #include +#include "detray/coordinates/polar2.hpp" #include "detray/masks/ring2.hpp" using namespace detray; From 221664996f95890b678d4014c0ae9819d7ca138d Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 14 Sep 2022 12:56:14 -0700 Subject: [PATCH 30/63] Fix warning --- core/include/detray/propagator/line_stepper.hpp | 2 +- core/include/detray/propagator/rk_stepper.hpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index 78f33e9bb..814a49234 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -46,7 +46,7 @@ class line_stepper final DETRAY_HOST_DEVICE state( const bound_track_parameters_type &bound_params, const detector_t &det) - : base_type::template state(bound_params, det) {} + : base_type::state(bound_params, det) {} /// Update the track state in a straight line. DETRAY_HOST_DEVICE diff --git a/core/include/detray/propagator/rk_stepper.hpp b/core/include/detray/propagator/rk_stepper.hpp index 867eed1e2..2e590b912 100644 --- a/core/include/detray/propagator/rk_stepper.hpp +++ b/core/include/detray/propagator/rk_stepper.hpp @@ -61,8 +61,7 @@ class rk_stepper final DETRAY_HOST_DEVICE state( const bound_track_parameters_type& bound_params, const magnetic_field_t mag_field, const detector_t& det) - : base_type::template state(bound_params, det), - _magnetic_field(mag_field) {} + : base_type::state(bound_params, det), _magnetic_field(mag_field) {} /// error tolerance scalar _tolerance = 1e-4; From f532715a9218bfb24d17a26836732c95e165117a Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 14 Sep 2022 15:25:59 -0700 Subject: [PATCH 31/63] Fix a bug --- .../detray/coordinates/coordinate_base.hpp | 11 ++-- .../detray/propagator/line_stepper.hpp | 52 ++++++++++++++++++- .../tests/common/covariance_transport.inl | 9 ++++ 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 9b3f438d1..c21aefbb9 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -217,21 +217,23 @@ struct coordinate_base { free_matrix path_correction = matrix_actor().template zero(); - using helix = detail::helix; - // Position and direction const auto pos = stepping().pos(); const auto dir = stepping().dir(); // dir matrix_type<1, 3> t; - matrix_actor().set_block(t, dir, 0, 0); + matrix_actor().element(t, 0, 0) = dir[0]; + matrix_actor().element(t, 0, 1) = dir[1]; + matrix_actor().element(t, 0, 2) = dir[2]; // Surface normal vector (w) matrix_type<1, 3> w; const auto normal = Derived().normal(trf3, mask, pos, dir); - matrix_actor().set_block(w, normal, 0, 0); + matrix_actor().element(w, 0, 0) = normal[0]; + matrix_actor().element(w, 0, 1) = normal[1]; + matrix_actor().element(w, 0, 2) = normal[2]; // w dot t const scalar_type wt = vector::dot(normal, dir); @@ -249,6 +251,7 @@ struct coordinate_base { e_free_pos0, e_free_pos0); if constexpr (stepper_state_t::id == stepping::id::e_rk) { + using helix = detail::helix; // Path length const auto s = stepping._s; diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index 814a49234..4a61d0504 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -34,6 +34,12 @@ class line_stepper final typename base_type::bound_track_parameters_type; using transform3_type = transform3_t; using matrix_operator = typename base_type::matrix_operator; + // Matrix size type + using size_type = typename matrix_operator::size_ty; + // 2D matrix type + template + using matrix_type = + typename matrix_operator::template matrix_type; struct state : public base_type::state { @@ -61,19 +67,61 @@ class line_stepper final inline void advance_jacobian() { // The step transport matrix in global coordinates - auto D = + matrix_type D = matrix_operator().template identity(); // d(x,y,z)/d(n_x,n_y,n_z) - auto dxdn = + matrix_type<3, 3> dxdn = this->_step_size * matrix_operator().template identity<3, 3>(); matrix_operator().template set_block<3, 3>(D, dxdn, e_free_pos0, e_free_dir0); + /* + printf("%f %f %f \n", matrix_operator().element(dxdn, 0, 0), + matrix_operator().element(dxdn, 1, 0), + matrix_operator().element(dxdn, 2, 0)); + printf("%f %f %f \n", matrix_operator().element(dxdn, 0, 1), + matrix_operator().element(dxdn, 1, 1), + matrix_operator().element(dxdn, 2, 1)); + printf("%f %f %f \n", matrix_operator().element(dxdn, 0, 2), + matrix_operator().element(dxdn, 1, 2), + matrix_operator().element(dxdn, 2, 2)); + */ + /* + printf("%f %f %f \n", matrix_operator().element(D, e_free_pos0, + e_free_dir0), matrix_operator().element(dxdn, e_free_pos1, + e_free_dir0), matrix_operator().element(dxdn, e_free_pos2, + e_free_dir0)); printf("%f %f %f \n", matrix_operator().element(D, + e_free_pos0, e_free_dir1), matrix_operator().element(dxdn, + e_free_pos1, e_free_dir1), matrix_operator().element(dxdn, + e_free_pos2, e_free_dir1)); printf("%f %f %f \n", + matrix_operator().element(D, e_free_pos0, e_free_dir2), + matrix_operator().element(dxdn, e_free_pos1, e_free_dir2), + matrix_operator().element(dxdn, e_free_pos2, e_free_dir2)); + */ /// NOTE: Let's skip the element for d(time)/d(qoverp) for the /// moment.. this->_jac_transport = D * this->_jac_transport; + + /* + printf("%f %f %f \n", + matrix_operator().element(this->_jac_transport, e_free_pos0, + e_free_dir0), matrix_operator().element(this->_jac_transport, + e_free_pos1, e_free_dir0), + matrix_operator().element(this->_jac_transport, e_free_pos2, + e_free_dir0)); printf("%f %f %f \n", + matrix_operator().element(this->_jac_transport, e_free_pos0, + e_free_dir1), matrix_operator().element(this->_jac_transport, + e_free_pos1, e_free_dir1), + matrix_operator().element(this->_jac_transport, e_free_pos2, + e_free_dir1)); printf("%f %f %f \n", + matrix_operator().element(this->_jac_transport, e_free_pos0, + e_free_dir2), matrix_operator().element(this->_jac_transport, + e_free_pos1, e_free_dir2), + matrix_operator().element(this->_jac_transport, e_free_pos2, + e_free_dir2)); + */ } }; diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index 614ef5d07..2cbd4f295 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -247,4 +247,13 @@ TEST(covariance_transport, linear_stepper_cartesian) { matrix_operator().element(bound_cov1, i, j), epsilon); } } + + // Check covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), epsilon); + } + } } From 5010589f742d47e7cdffeb73ab50f8475a8aa4b4 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 14 Sep 2022 15:54:44 -0700 Subject: [PATCH 32/63] Some fix --- .../detray/coordinates/coordinate_base.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index c21aefbb9..610424041 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -261,15 +261,26 @@ struct coordinate_base { // B field at the destination surface matrix_type<1, 3> h; - matrix_actor().set_block(h, hlx._h0, 0, 0); + matrix_actor().element(h, 0, 0) = hlx._h0[0]; + matrix_actor().element(h, 0, 1) = hlx._h0[1]; + matrix_actor().element(h, 0, 2) = hlx._h0[2]; + // matrix_actor().set_block(h, hlx._h0, 0, 0); // Normalized vector of h X t matrix_type<1, 3> n; - matrix_actor().set_block(n, hlx._n0, 0, 0); + matrix_actor().element(n, 0, 0) = hlx._n0[0]; + matrix_actor().element(n, 0, 1) = hlx._n0[1]; + matrix_actor().element(n, 0, 2) = hlx._n0[2]; + // matrix_actor().set_block(n, hlx._n0, 0, 0); // w cross h matrix_type<1, 3> wh; - matrix_actor().set_block(wh, vector::cross(normal, hlx._h0), 0, 0); + const auto _wh = vector::cross(normal, hlx._h0); + matrix_actor().element(wh, 0, 0) = _wh[0]; + matrix_actor().element(wh, 0, 1) = _wh[1]; + matrix_actor().element(wh, 0, 2) = _wh[2]; + // matrix_actor().set_block(wh, vector::cross(normal, hlx._h0), 0, + // 0); // Alpha const scalar_type A = hlx._alpha; From 6a4d3e2b191834aecb4f10daabfca49c13500c2e Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 14 Sep 2022 16:31:00 -0700 Subject: [PATCH 33/63] Remove comments --- .../detray/propagator/line_stepper.hpp | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index 4a61d0504..3607c302e 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -76,52 +76,10 @@ class line_stepper final matrix_operator().template set_block<3, 3>(D, dxdn, e_free_pos0, e_free_dir0); - /* - printf("%f %f %f \n", matrix_operator().element(dxdn, 0, 0), - matrix_operator().element(dxdn, 1, 0), - matrix_operator().element(dxdn, 2, 0)); - printf("%f %f %f \n", matrix_operator().element(dxdn, 0, 1), - matrix_operator().element(dxdn, 1, 1), - matrix_operator().element(dxdn, 2, 1)); - printf("%f %f %f \n", matrix_operator().element(dxdn, 0, 2), - matrix_operator().element(dxdn, 1, 2), - matrix_operator().element(dxdn, 2, 2)); - */ - /* - printf("%f %f %f \n", matrix_operator().element(D, e_free_pos0, - e_free_dir0), matrix_operator().element(dxdn, e_free_pos1, - e_free_dir0), matrix_operator().element(dxdn, e_free_pos2, - e_free_dir0)); printf("%f %f %f \n", matrix_operator().element(D, - e_free_pos0, e_free_dir1), matrix_operator().element(dxdn, - e_free_pos1, e_free_dir1), matrix_operator().element(dxdn, - e_free_pos2, e_free_dir1)); printf("%f %f %f \n", - matrix_operator().element(D, e_free_pos0, e_free_dir2), - matrix_operator().element(dxdn, e_free_pos1, e_free_dir2), - matrix_operator().element(dxdn, e_free_pos2, e_free_dir2)); - */ /// NOTE: Let's skip the element for d(time)/d(qoverp) for the /// moment.. this->_jac_transport = D * this->_jac_transport; - - /* - printf("%f %f %f \n", - matrix_operator().element(this->_jac_transport, e_free_pos0, - e_free_dir0), matrix_operator().element(this->_jac_transport, - e_free_pos1, e_free_dir0), - matrix_operator().element(this->_jac_transport, e_free_pos2, - e_free_dir0)); printf("%f %f %f \n", - matrix_operator().element(this->_jac_transport, e_free_pos0, - e_free_dir1), matrix_operator().element(this->_jac_transport, - e_free_pos1, e_free_dir1), - matrix_operator().element(this->_jac_transport, e_free_pos2, - e_free_dir1)); printf("%f %f %f \n", - matrix_operator().element(this->_jac_transport, e_free_pos0, - e_free_dir2), matrix_operator().element(this->_jac_transport, - e_free_pos1, e_free_dir2), - matrix_operator().element(this->_jac_transport, e_free_pos2, - e_free_dir2)); - */ } }; From 08fdfe1b3f6a6b86f7f665d63b96a1a20be840fb Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 20 Sep 2022 08:36:22 -0700 Subject: [PATCH 34/63] Change actor name --- .vscode/settings.json | 6 ++++++ core/CMakeLists.txt | 2 +- ...ound_updater.hpp => parameter_transporter.hpp} | 2 +- .../include/tests/common/covariance_transport.inl | 15 +++++++-------- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 .vscode/settings.json rename core/include/detray/propagator/actors/{bound_to_bound_updater.hpp => parameter_transporter.hpp} (99%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..3cd9f3244 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "*.sycl": "cpp", + "*.tcc": "cpp" + } +} \ No newline at end of file diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 4e46c09ac..f1098b4b1 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -74,7 +74,7 @@ detray_add_library( detray_core core "include/detray/materials/predefined_materials.hpp" # propagator include(s) "include/detray/propagator/actors/aborters.hpp" - "include/detray/propagator/actors/bound_to_bound_updater.hpp" + "include/detray/propagator/actors/parameter_transporter.hpp" "include/detray/propagator/actors/resetter.hpp" "include/detray/propagator/actors/surface_targeter.hpp" "include/detray/propagator/actor_chain.hpp" diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/parameter_transporter.hpp similarity index 99% rename from core/include/detray/propagator/actors/bound_to_bound_updater.hpp rename to core/include/detray/propagator/actors/parameter_transporter.hpp index c6d08eb60..1070bcbc3 100644 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ b/core/include/detray/propagator/actors/parameter_transporter.hpp @@ -16,7 +16,7 @@ namespace detray { template -struct bound_to_bound_updater : actor { +struct parameter_transporter : actor { struct state {}; diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index 2cbd4f295..faee056de 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -9,7 +9,7 @@ #include "detray/definitions/units.hpp" #include "detray/field/constant_magnetic_field.hpp" #include "detray/propagator/actor_chain.hpp" -#include "detray/propagator/actors/bound_to_bound_updater.hpp" +#include "detray/propagator/actors/parameter_transporter.hpp" #include "detray/propagator/actors/resetter.hpp" #include "detray/propagator/actors/surface_targeter.hpp" #include "detray/propagator/line_stepper.hpp" @@ -61,8 +61,8 @@ TEST(covariance_transport, rk_stepper_cartesian) { using crk_stepper_t = rk_stepper>; using actor_chain_t = - actor_chain, resetter>; + actor_chain, + resetter>; using propagator_t = propagator; // Generate track starting point @@ -106,7 +106,7 @@ TEST(covariance_transport, rk_stepper_cartesian) { // Actors surface_targeter::state targeter{S, 0}; - bound_to_bound_updater::state bound_updater{}; + parameter_transporter::state bound_updater{}; resetter::state rst{}; actor_chain_t::state actor_states = std::tie(targeter, bound_updater, rst); @@ -189,9 +189,8 @@ TEST(covariance_transport, linear_stepper_cartesian) { using navigator_t = navigator; using cline_stepper_t = line_stepper>; - using actor_chain_t = - actor_chain, - resetter>; + using actor_chain_t = actor_chain, + resetter>; using propagator_t = propagator; @@ -217,7 +216,7 @@ TEST(covariance_transport, linear_stepper_cartesian) { bound_cov); // Actors - bound_to_bound_updater::state bound_updater{}; + parameter_transporter::state bound_updater{}; resetter::state rst{}; actor_chain_t::state actor_states = std::tie(bound_updater, rst); From b4ac3b02276ba61ba906ef268ce9ccf33c83b1b2 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 20 Sep 2022 08:40:07 -0700 Subject: [PATCH 35/63] remove file --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 3cd9f3244..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.associations": { - "*.sycl": "cpp", - "*.tcc": "cpp" - } -} \ No newline at end of file From 49673ff797dd32601101d9feb283b6437cf3adae Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 21 Sep 2022 10:05:39 -0700 Subject: [PATCH 36/63] Small fix --- .../include/detray/propagator/actors/parameter_transporter.hpp | 3 +-- core/include/detray/propagator/actors/resetter.hpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/include/detray/propagator/actors/parameter_transporter.hpp b/core/include/detray/propagator/actors/parameter_transporter.hpp index 1070bcbc3..b9f76ede5 100644 --- a/core/include/detray/propagator/actors/parameter_transporter.hpp +++ b/core/include/detray/propagator/actors/parameter_transporter.hpp @@ -146,14 +146,13 @@ struct parameter_transporter : actor { if (navigation.is_on_module()) { const auto& det = navigation.detector(); - const auto& surface_container = det->surfaces(); const auto& mask_store = det->mask_store(); // Intersection const auto& is = navigation.current(); // Surface - const auto& surface = surface_container[is->index]; + const auto& surface = det->surface_by_index(is->index); // Set surface link stepping._bound_params.set_surface_link(is->index); diff --git a/core/include/detray/propagator/actors/resetter.hpp b/core/include/detray/propagator/actors/resetter.hpp index 49622bd8a..d9dc769d8 100644 --- a/core/include/detray/propagator/actors/resetter.hpp +++ b/core/include/detray/propagator/actors/resetter.hpp @@ -74,7 +74,6 @@ struct resetter : actor { if (navigation.is_on_module()) { const auto& det = navigation.detector(); - const auto& surface_container = det->surfaces(); const auto& trf_store = det->transform_store(); const auto& mask_store = det->mask_store(); @@ -82,7 +81,7 @@ struct resetter : actor { const auto& is = navigation.current(); // Surface - const auto& surface = surface_container[is->index]; + const auto& surface = det->surface_by_index(is->index); mask_store.template execute(surface.mask_type(), trf_store, surface, stepping); From 4fc888f3538ba497cbdc04a32eab6239eee9c0fc Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Fri, 23 Sep 2022 19:19:40 -0700 Subject: [PATCH 37/63] Fix constructor --- core/include/detray/propagator/line_stepper.hpp | 2 -- core/include/detray/propagator/propagator.hpp | 9 +++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index 6cdeb5d56..b4eb90d7e 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -33,8 +33,6 @@ class line_stepper final struct state : public base_type::state { - using field_type = int; - DETRAY_HOST_DEVICE state(const free_track_parameters_type &t) : base_type::state(t) {} diff --git a/core/include/detray/propagator/propagator.hpp b/core/include/detray/propagator/propagator.hpp index 1b9f8a0f3..68bcb7878 100644 --- a/core/include/detray/propagator/propagator.hpp +++ b/core/include/detray/propagator/propagator.hpp @@ -56,7 +56,6 @@ struct propagator { struct state { using detector_type = typename navigator_t::detector_type; - using field_type = typename stepper_t::state::field_type; /// Construct the propagation state. /// @@ -71,12 +70,10 @@ struct propagator { _navigation(det, std::move(candidates)), _actor_states(actor_states) {} - template < - typename track_t, - std::enable_if_t, bool> = true> + template DETRAY_HOST_DEVICE state( - const track_t &t_in, const field_type &magnetic_field, - const detector_type &det, + const free_track_parameters_type &t_in, + const field_t &magnetic_field, const detector_type &det, typename actor_chain_t::state actor_states = {}, vector_type &&candidates = {}) : _stepping(t_in, magnetic_field), From 14e723016ee972d3c89017c262f9c3e752a42bd2 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Fri, 23 Sep 2022 23:11:39 -0700 Subject: [PATCH 38/63] FIx bug --- core/include/detray/tracks/free_track_parameters.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/include/detray/tracks/free_track_parameters.hpp b/core/include/detray/tracks/free_track_parameters.hpp index 55a2b817b..6dffb451b 100644 --- a/core/include/detray/tracks/free_track_parameters.hpp +++ b/core/include/detray/tracks/free_track_parameters.hpp @@ -110,8 +110,8 @@ struct free_track_parameters { DETRAY_HOST_DEVICE scalar_type charge() const { - return -1 ? matrix_operator().element(m_vector, e_free_qoverp, 0) < 0 - : 1.; + return matrix_operator().element(m_vector, e_free_qoverp, 0) < 0 ? -1. + : 1.; } DETRAY_HOST_DEVICE From 367b7b77680b83ea5a70986dcb437f26f2f80d71 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 26 Sep 2022 13:47:24 -0700 Subject: [PATCH 39/63] Remove unused file --- .../propagator/detail/covariance_engine.hpp | 101 ------------------ 1 file changed, 101 deletions(-) delete mode 100644 core/include/detray/propagator/detail/covariance_engine.hpp diff --git a/core/include/detray/propagator/detail/covariance_engine.hpp b/core/include/detray/propagator/detail/covariance_engine.hpp deleted file mode 100644 index 817d5d8ca..000000000 --- a/core/include/detray/propagator/detail/covariance_engine.hpp +++ /dev/null @@ -1,101 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Detray include(s) -#include "detray/definitions/qualifiers.hpp" -#include "detray/propagator/detail/jacobian_engine.hpp" - -namespace detray { - -namespace detail { - -// Covariance engine agnostic to surface type -template -struct covariance_engine { - - /// Transformation matching this struct - using transform3_type = transform3_t; - using jacobian_engine = detail::jacobian_engine; - using track_helper = typename jacobian_engine::track_helper; - using matrix_operator = typename jacobian_engine::matrix_operator; - using size_type = typename transform3_type::size_type; - /// 2D matrix type - template - using matrix_type = - typename matrix_operator::template matrix_type; - /// Shorthand vector types related to track parameters. - using bound_vector = matrix_type; - using free_vector = matrix_type; - /// Shorthand matrix types related to track parameters. - using bound_matrix = matrix_type; - using free_matrix = matrix_type; - /// Mapping matrix - using bound_to_free_matrix = matrix_type; - using free_to_bound_matrix = matrix_type; - using free_to_path_matrix = matrix_type<1, e_free_size>; - - /** Function to get the full jacobian for surface-to-surface propagation - * - * @param trf3 is the transform matrix of the destination surface - * @param free_vec is the input free vector at the destination surface - * @param bound_to_free_jacobian is the coordinate transform jacobian - * at departure surface. - * @param free_transport_jacobian is the transport jacobian - * @param free_to_path_derivative is the derivative of free parameter w.r.t - * path - * @returns bound to bound jacobian - */ - DETRAY_HOST_DEVICE inline bound_matrix bound_to_bound_jacobian( - const transform3_type& trf3, const free_vector& free_vec, - const bound_to_free_matrix& bound_to_free_jacobian, - const free_matrix& free_transport_jacobian, - const free_vector& free_to_path_derivative) const; - - /** Function to update the covariance matrix for surface-to-surface - * propagation - * - * @param trf3 is the transform matrix of the destination surface - * @param bound_covariance is the covariance at the departure surface, which - * is to be updated for the destination surface - * @param free_vec is the input free vector at the destination surface - * @param bound_to_free_jacobian is the coordinate transform jacobian - * at the departure surface. - * @param free_transport_jacobian is the transport jacobian - * @param free_to_path_derivative is the derivative of free parameter w.r.t - * path at the destination surface - */ - DETRAY_HOST_DEVICE inline void bound_to_bound_covariance_update( - const transform3_type& trf3, bound_matrix& bound_covariance, - const free_vector& free_vec, - const bound_to_free_matrix& bound_to_free_jacobian, - const free_matrix& free_transport_jacobian, - const free_vector& free_to_path_derivative) const; - - /** Function to reinitialize the jacobian after updating covariance - * - * @param trf3 is the transform matrix of the destination surface - * @param bound_vec is the input bound vector at the destination surface - * @param bound_to_free_jacobian is the coordinate transform jacobian - * at the destination surface - * @param free_transport_jacobian is the transport jacobian - * @param free_to_path_derivative is the derivative of free parameter w.r.t - * path at the destination surface - */ - DETRAY_HOST_DEVICE inline void reinitialize_jacobians( - const transform3_type& trf3, const bound_vector& bound_vec, - bound_to_free_matrix& bound_to_free_jacobian, - free_matrix& free_transport_jacobian, - free_vector& free_to_path_derivative) const; -}; - -} // namespace detail - -} // namespace detray - -#include "detray/propagator/detail/covariance_engine.ipp" \ No newline at end of file From ad404f86bd5cc9aa0b8107b1ae75f9dfcd4f462f Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 28 Sep 2022 15:15:22 -0700 Subject: [PATCH 40/63] Editing create telescope detector --- .vscode/settings.json | 7 ++ .../detray/propagator/line_stepper.hpp | 1 - core/include/detray/propagator/propagator.hpp | 3 - .../tools/create_telescope_detector.hpp | 75 +++++-------------- 4 files changed, 27 insertions(+), 59 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..8fef4b2cd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "*.sycl": "cpp", + "iosfwd": "cpp", + "limits": "cpp" + } +} \ No newline at end of file diff --git a/core/include/detray/propagator/line_stepper.hpp b/core/include/detray/propagator/line_stepper.hpp index b4eb90d7e..89db5575c 100644 --- a/core/include/detray/propagator/line_stepper.hpp +++ b/core/include/detray/propagator/line_stepper.hpp @@ -32,7 +32,6 @@ class line_stepper final typename base_type::free_track_parameters_type; struct state : public base_type::state { - DETRAY_HOST_DEVICE state(const free_track_parameters_type &t) : base_type::state(t) {} diff --git a/core/include/detray/propagator/propagator.hpp b/core/include/detray/propagator/propagator.hpp index 68bcb7878..591857767 100644 --- a/core/include/detray/propagator/propagator.hpp +++ b/core/include/detray/propagator/propagator.hpp @@ -12,9 +12,6 @@ #include "detray/intersection/intersection.hpp" #include "detray/tracks/tracks.hpp" -// System include(s) -#include - namespace detray { /// Templated propagator class, using a stepper and a navigator object in diff --git a/tests/common/include/tests/common/tools/create_telescope_detector.hpp b/tests/common/include/tests/common/tools/create_telescope_detector.hpp index d679b9c6b..dd276addc 100644 --- a/tests/common/include/tests/common/tools/create_telescope_detector.hpp +++ b/tests/common/include/tests/common/tools/create_telescope_detector.hpp @@ -24,6 +24,7 @@ namespace detray { namespace { +// @Note: These type definitions should be removed at some point using point3 = __plugin::point3; using vector3 = __plugin::vector3; using point2 = __plugin::point2; @@ -50,50 +51,19 @@ struct module_placement { /// @param n_surfaces the number of plane surfaces /// /// @return a vector of the module positions along the trajectory -template +template inline std::vector module_positions( - stepper_t stepper, typename stepper_t::state &stepping, - std::vector &steps) { - // dummy navigation struct - struct navigation_state { - scalar operator()() const { return _step_size; } - inline void set_full_trust() {} - inline void set_high_trust() {} - inline void set_fair_trust() {} - inline void set_no_trust() {} - inline bool abort() { return false; } - - scalar _step_size = 0; - }; + const trajectory_t &traj, std::vector &steps) { - // dummy propagator state - struct prop_state { - typename stepper_t::state _stepping; - navigation_state _navigation; - }; + // create and fill the module placements + std::vector placements; + placements.reserve(steps.size()); - // create and fill the positions - std::vector m_positions; - m_positions.reserve(steps.size()); - - // Find exact position by walking along track - prop_state propagation{stepping, navigation_state{}}; - - // Calculate step size from module positions. The modules will only be - // placed at the given position if the b-field allows for it. Otherwise, by - // virtue of the stepper, the distance will be shorter and the surface - // remains reachable in a single step. - scalar prev_dist = 0.; - for (const auto &dist : steps) { - // advance the track state to the next plane position - propagation._navigation._step_size = dist - prev_dist; - stepper.step(propagation); - m_positions.push_back( - {propagation._stepping().pos(), propagation._stepping().dir()}); - prev_dist = dist; + for (const auto s : steps) { + placements.push_back(traj.pos(s), traj.dir(s)); } - return m_positions; + return placements; } /// Helper function that creates the telescope surfaces. @@ -108,12 +78,11 @@ inline std::vector module_positions( /// @param transforms container to add new transform to /// @param cfg config struct for module creation template -inline void create_telescope(context_t &ctx, stepper_t &stepper, - typename stepper_t::state &stepping, +inline void create_telescope(context_t &ctx, const trajectory_t &traj, volume_type &volume, surface_container_t &surfaces, mask_container_t &masks, material_container_t &materials, @@ -130,7 +99,7 @@ inline void create_telescope(context_t &ctx, stepper_t &stepper, // Create the module centers const std::vector m_placements = - module_positions(stepper, stepping, cfg.pos); + module_positions(traj, cfg.pos); // Create geometry data for (const auto &m_placement : m_placements) { @@ -194,7 +163,7 @@ inline void create_telescope(context_t &ctx, stepper_t &stepper, /// @param n_surfaces the number of surfaces that are placed in the geometry /// @param tel_length the total length of the steps by the stepper template >, + typename trajectory_t = detail::ray<__plugin::transform3>, template class array_t = darray, template class tuple_t = dtuple, template class vector_t = dvector, @@ -202,8 +171,7 @@ template ( - resource, positions, stepper, stepping, half_x, half_y); + return create_telescope_detector(resource, positions, + traj, half_x, half_y); } /// Builds a detray geometry that contains only one volume with plane surfaces, @@ -242,15 +210,14 @@ auto create_telescope_detector(vecmem::memory_resource &resource, /// /// @returns a complete detector object template >, + typename trajectory_t = detail::ray<__plugin::transform3>, template class array_t = darray, template class tuple_t = dtuple, template class vector_t = dvector, template class jagged_vector_t = djagged_vector> auto create_telescope_detector( vecmem::memory_resource &resource, std::vector pos = {}, - stepper_t stepper = {}, typename stepper_t::state stepping = {}, - scalar half_x = 20. * unit_constants::mm, + trajectory_t traj, scalar half_x = 20. * unit_constants::mm, scalar half_y = 20. * unit_constants::mm, const material mat = silicon_tml(), const scalar thickness = 80 * unit_constants::um) { @@ -286,12 +253,10 @@ auto create_telescope_detector( if constexpr (unbounded_planes) { create_telescope( - ctx, stepper, stepping, vol, surfaces, masks, materials, transforms, - pl_config); + ctx, traj, vol, surfaces, masks, materials, transforms, pl_config); } else { create_telescope( - ctx, stepper, stepping, vol, surfaces, masks, materials, transforms, - pl_config); + ctx, traj, vol, surfaces, masks, materials, transforms, pl_config); } det.add_objects_per_volume(ctx, vol, surfaces, masks, materials, From 8c9ced79b2366616a0f3745589ac12ff070be410 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 28 Sep 2022 15:15:36 -0700 Subject: [PATCH 41/63] Remove unused file --- .vscode/settings.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 8fef4b2cd..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "files.associations": { - "*.sycl": "cpp", - "iosfwd": "cpp", - "limits": "cpp" - } -} \ No newline at end of file From 03b4a3db67c92e38d24b28953394a257af7e7a33 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 28 Sep 2022 19:42:11 -0700 Subject: [PATCH 42/63] Use ray/helix for telescope geometry --- .../tests/common/test_telescope_detector.inl | 33 ++++----- .../tools/create_telescope_detector.hpp | 67 ++++++++++--------- .../tests/common/tools_guided_navigator.inl | 8 +-- 3 files changed, 49 insertions(+), 59 deletions(-) diff --git a/tests/common/include/tests/common/test_telescope_detector.inl b/tests/common/include/tests/common/test_telescope_detector.inl index 71074315a..64ffd272a 100644 --- a/tests/common/include/tests/common/test_telescope_detector.inl +++ b/tests/common/include/tests/common/test_telescope_detector.inl @@ -51,7 +51,6 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { using namespace detray; using b_field_t = constant_magnetic_field<>; - using ln_stepper_t = line_stepper; using rk_stepper_t = rk_stepper; using inspector_t = navigation::print_inspector; @@ -72,9 +71,6 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { // steppers rk_stepper_t rk_stepper_z; rk_stepper_t rk_stepper_x; - ln_stepper_t ln_stepper; - typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {0, 0, 1}, -1}; // // telescope along z @@ -84,17 +80,15 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { std::vector positions = {0., 50., 100., 150., 200., 250., 300., 350, 400, 450., 500.}; // Build telescope detector with unbounded planes - const auto z_tel_det1 = create_telescope_detector( - host_mr, positions, ln_stepper_t(), - typename ln_stepper_t::state{default_trk}); + const auto z_tel_det1 = + create_telescope_detector(host_mr, positions); // Build the same telescope detector with rectangular planes and given // length/number of surfaces dindex n_surfaces = 11; scalar tel_length = 500. * unit_constants::mm; - const auto z_tel_det2 = create_telescope_detector( - host_mr, n_surfaces, tel_length, ln_stepper_t(), - typename ln_stepper_t::state{default_trk}); + const auto z_tel_det2 = + create_telescope_detector(host_mr, n_surfaces, tel_length); // Compare for (std::size_t i = 0; i < z_tel_det1.surfaces().size(); ++i) { @@ -107,21 +101,18 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { // // Same telescope, but in x direction and created from custom stepper - point3 pos{0., 0., 0.}; - vector3 mom{1., 0., 0.}; - free_track_parameters pilot_track(pos, 0, mom, -1); - typename ln_stepper_t::state ln_stepping(pilot_track); + detail::ray x_track({0, 0, 0}, 0, {1, 0, 0}, -1); const auto x_tel_det = create_telescope_detector( - host_mr, n_surfaces, tel_length, ln_stepper, ln_stepping); + host_mr, n_surfaces, tel_length, x_track); // // test propagation in all telescope detector instances // // Telescope navigation should be symmetric in x and z - pos = {0., 0., 0.}; - mom = {0., 0., 1.}; + vector3 pos = {0., 0., 0.}; + vector3 mom = {0., 0., 1.}; free_track_parameters test_track_z1(pos, 0, mom, -1); free_track_parameters test_track_z2(pos, 0, mom, -1); mom = {1., 0., 0.}; @@ -204,14 +195,14 @@ TEST(ALGEBRA_PLUGIN, telescope_detector) { // pos = {0., 0., 0.}; mom = {0., 1., 0.}; - pilot_track = free_track_parameters(pos, 0, mom, -1); + + auto pilot_track = free_track_parameters(pos, 0, mom, -1); pilot_track.set_overstep_tolerance(-10 * unit_constants::um); - typename rk_stepper_t::state rk_stepping_z(pilot_track, b_field_z); - typename rk_stepper_t::state rk_stepping_x(pilot_track, b_field_x); + detail::helix helix_bz(pilot_track, &B_z); const auto tel_detector = create_telescope_detector( - host_mr, n_surfaces, tel_length, rk_stepper_z, rk_stepping_z); + host_mr, n_surfaces, tel_length, helix_bz); // make at least sure it is navigatable navigator tel_navigator; diff --git a/tests/common/include/tests/common/tools/create_telescope_detector.hpp b/tests/common/include/tests/common/tools/create_telescope_detector.hpp index dd276addc..65aa90634 100644 --- a/tests/common/include/tests/common/tools/create_telescope_detector.hpp +++ b/tests/common/include/tests/common/tools/create_telescope_detector.hpp @@ -60,7 +60,7 @@ inline std::vector module_positions( placements.reserve(steps.size()); for (const auto s : steps) { - placements.push_back(traj.pos(s), traj.dir(s)); + placements.push_back({traj.pos(s), traj.dir(s)}); } return placements; @@ -158,36 +158,6 @@ inline void create_telescope(context_t &ctx, const trajectory_t &traj, } // namespace -/// Build the telescope geometry from a fixed length and number of surfaces. -/// -/// @param n_surfaces the number of surfaces that are placed in the geometry -/// @param tel_length the total length of the steps by the stepper -template >, - template class array_t = darray, - template class tuple_t = dtuple, - template class vector_t = dvector, - template class jagged_vector_t = djagged_vector> -auto create_telescope_detector(vecmem::memory_resource &resource, - dindex n_surfaces = 10, - scalar tel_length = 500. * unit_constants::mm, - trajectory_t traj, - scalar half_x = 20. * unit_constants::mm, - scalar half_y = 20. * unit_constants::mm) { - // Generate equidistant positions - std::vector positions = {}; - scalar pos = 0.; - scalar dist = tel_length / (n_surfaces - 1); - for (std::size_t i = 0; i < n_surfaces; ++i) { - positions.push_back(pos); - pos += dist; - } - - // Build the geometry - return create_telescope_detector(resource, positions, - traj, half_x, half_y); -} - /// Builds a detray geometry that contains only one volume with plane surfaces, /// where the last surface is the portal that leaves the telescope. The /// detector is auto-constructed by following a track state through space with @@ -216,8 +186,9 @@ template class vector_t = dvector, template class jagged_vector_t = djagged_vector> auto create_telescope_detector( - vecmem::memory_resource &resource, std::vector pos = {}, - trajectory_t traj, scalar half_x = 20. * unit_constants::mm, + vecmem::memory_resource &resource, std::vector pos, + trajectory_t traj = {{0, 0, 0}, 0, {0, 0, 1}, -1}, + scalar half_x = 20. * unit_constants::mm, scalar half_y = 20. * unit_constants::mm, const material mat = silicon_tml(), const scalar thickness = 80 * unit_constants::um) { @@ -265,4 +236,34 @@ auto create_telescope_detector( return det; } +/// Build the telescope geometry from a fixed length and number of surfaces. +/// +/// @param n_surfaces the number of surfaces that are placed in the geometry +/// @param tel_length the total length of the steps by the stepper +template >, + template class array_t = darray, + template class tuple_t = dtuple, + template class vector_t = dvector, + template class jagged_vector_t = djagged_vector> +auto create_telescope_detector( + vecmem::memory_resource &resource, dindex n_surfaces = 10, + scalar tel_length = 500. * unit_constants::mm, + trajectory_t traj = {{0, 0, 0}, 0, {0, 0, 1}, -1}, + scalar half_x = 20. * unit_constants::mm, + scalar half_y = 20. * unit_constants::mm) { + // Generate equidistant positions + std::vector positions = {}; + scalar pos = 0.; + scalar dist = tel_length / (n_surfaces - 1); + for (std::size_t i = 0; i < n_surfaces; ++i) { + positions.push_back(pos); + pos += dist; + } + + // Build the geometry + return create_telescope_detector(resource, positions, + traj, half_x, half_y); +} + } // namespace detray \ No newline at end of file diff --git a/tests/common/include/tests/common/tools_guided_navigator.inl b/tests/common/include/tests/common/tools_guided_navigator.inl index 2ea432c45..e1a4fe138 100644 --- a/tests/common/include/tests/common/tools_guided_navigator.inl +++ b/tests/common/include/tests/common/tools_guided_navigator.inl @@ -32,16 +32,14 @@ TEST(ALGEBRA_PLUGIN, guided_navigator) { // Use unbounded surfaces constexpr bool unbounded = true; - using ln_stepper_t = line_stepper; - typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {0, 0, 1}, -1}; + detail::ray default_trk({0, 0, 0}, 0, {0, 0, 1}, -1); // Module positions along z-axis const std::vector positions = {0., 10., 20., 30., 40., 50., 60., 70, 80, 90., 100.}; // Build telescope detector with unbounded planes - const auto telescope_det = create_telescope_detector( - host_mr, positions, ln_stepper_t(), default_trk); + const auto telescope_det = + create_telescope_detector(host_mr, positions, default_trk); // Inspectors are optional, of course using object_tracer_t = From 35da5e198be4d633e50ed069584e91af729ec98c Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 28 Sep 2022 20:48:23 -0700 Subject: [PATCH 43/63] Change actor name --- core/CMakeLists.txt | 3 +- .../actors/bound_to_bound_updater.hpp | 164 ------- .../{resetter.hpp => parameter_resetter.hpp} | 2 +- .../propagator/actors/surface_targeter.hpp | 59 --- .../detray/propagator/base_stepper.hpp | 4 +- .../tests/common/covariance_transport.inl | 53 ++- .../tests/common/material_interaction.inl | 450 ++++++++++++++++++ 7 files changed, 501 insertions(+), 234 deletions(-) delete mode 100644 core/include/detray/propagator/actors/bound_to_bound_updater.hpp rename core/include/detray/propagator/actors/{resetter.hpp => parameter_resetter.hpp} (98%) delete mode 100644 core/include/detray/propagator/actors/surface_targeter.hpp create mode 100644 tests/common/include/tests/common/material_interaction.inl diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index f1098b4b1..79eecc74b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -75,8 +75,7 @@ detray_add_library( detray_core core # propagator include(s) "include/detray/propagator/actors/aborters.hpp" "include/detray/propagator/actors/parameter_transporter.hpp" - "include/detray/propagator/actors/resetter.hpp" - "include/detray/propagator/actors/surface_targeter.hpp" + "include/detray/propagator/actors/parameter_resetter.hpp" "include/detray/propagator/actor_chain.hpp" "include/detray/propagator/base_actor.hpp" "include/detray/propagator/base_stepper.hpp" diff --git a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp b/core/include/detray/propagator/actors/bound_to_bound_updater.hpp deleted file mode 100644 index bc215e090..000000000 --- a/core/include/detray/propagator/actors/bound_to_bound_updater.hpp +++ /dev/null @@ -1,164 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "detray/definitions/qualifiers.hpp" -#include "detray/definitions/track_parametrization.hpp" -#include "detray/propagator/base_actor.hpp" -#include "detray/tracks/detail/track_helper.hpp" - -namespace detray { - -template -struct bound_to_bound_updater : actor { - - struct state {}; - - struct kernel { - - /// @name Type definitions for the struct - /// @{ - - // Transformation matching this struct - using transform3_type = transform3_t; - // scalar_type - using scalar_type = typename transform3_type::scalar_type; - // size type - using size_type = typename transform3_type::size_type; - // Matrix actor - using matrix_operator = typename transform3_t::matrix_actor; - // 2D matrix type - template - using matrix_type = - typename matrix_operator::template matrix_type; - // Shorthand vector/matrix types related to bound track parameters. - using bound_vector = matrix_type; - using bound_matrix = matrix_type; - // Mapping from bound track parameters. - using bound_to_free_matrix = matrix_type; - // Shorthand vector/matrix types related to free track parameters. - using free_vector = matrix_type; - using free_matrix = matrix_type; - // Mapping from free track parameters. - using free_to_bound_matrix = matrix_type; - using free_to_path_matrix = matrix_type<1, e_free_size>; - // Track helper - using track_helper = detail::track_helper; - - /// @} - - using output_type = bool; - - template - DETRAY_HOST_DEVICE inline output_type operator()( - const mask_group_t& mask_group, const surface_t& surface, - propagator_state_t& propagation) const { - - // Stepper and Navigator states - auto& navigation = propagation._navigation; - auto& stepping = propagation._stepping; - - // Retrieve surfaces and transform store - const auto& det = navigation.detector(); - const auto& transform_store = det->transform_store(); - - // Intersection - const auto& is = navigation.current(); - - // Transform - const auto& trf3 = transform_store[surface.transform()]; - - // Mask - const auto& mask = mask_group[is->mask_index]; - auto local_coordinate = mask.local(); - - // Free vector - const auto& free_vec = stepping().vector(); - - // Convert free to bound vector - stepping._bound_params.set_vector( - local_coordinate.free_to_bound_vector(trf3, free_vec)); - - // Free to bound jacobian at the destination surface - const free_to_bound_matrix free_to_bound_jacobian = - local_coordinate.free_to_bound_jacobian(trf3, mask, free_vec); - - // Transport jacobian in free coordinate - free_matrix& free_transport_jacobian = stepping._jac_transport; - - // Path correction factor - free_matrix path_correction = - local_coordinate.path_correction(stepping, trf3, mask); - - // Bound to free jacobian at the departure surface - const bound_to_free_matrix& bound_to_free_jacobian = - stepping._jac_to_global; - - // Acts version - const free_matrix correction_term = - matrix_operator() - .template identity() + - path_correction; - - const bound_matrix full_jacobian = - free_to_bound_jacobian * correction_term * - free_transport_jacobian * bound_to_free_jacobian; - - /* - const bound_matrix full_jacobian = - free_to_bound_jacobian * - (path_correction + free_transport_jacobian) * - bound_to_free_jacobian; - */ - - // No path correction - /* - const bound_matrix full_jacobian = free_to_bound_jacobian * - free_transport_jacobian * - bound_to_free_jacobian; - */ - - const bound_matrix new_cov = - full_jacobian * stepping._bound_params.covariance() * - matrix_operator().transpose(full_jacobian); - - // Calculate surface-to-surface covariance transport - stepping._bound_params.set_covariance(new_cov); - - return true; - } - }; - - template - DETRAY_HOST_DEVICE void operator()(state& /*actor_state*/, - propagator_state_t& propagation) const { - - auto& navigation = propagation._navigation; - - // Do covariance transport when the track is on surface - if (navigation.is_on_module()) { - - const auto& det = navigation.detector(); - const auto& surface_container = det->surfaces(); - const auto& mask_store = det->mask_store(); - - // Intersection - const auto& is = navigation.current(); - - // Surface - const auto& surface = surface_container[is->index]; - - mask_store.template execute(surface.mask_type(), surface, - propagation); - } - } -}; - -} // namespace detray \ No newline at end of file diff --git a/core/include/detray/propagator/actors/resetter.hpp b/core/include/detray/propagator/actors/parameter_resetter.hpp similarity index 98% rename from core/include/detray/propagator/actors/resetter.hpp rename to core/include/detray/propagator/actors/parameter_resetter.hpp index 3ec91ff6f..f291fb812 100644 --- a/core/include/detray/propagator/actors/resetter.hpp +++ b/core/include/detray/propagator/actors/parameter_resetter.hpp @@ -16,7 +16,7 @@ namespace detray { template -struct resetter : actor { +struct parameter_resetter : actor { struct state {}; diff --git a/core/include/detray/propagator/actors/surface_targeter.hpp b/core/include/detray/propagator/actors/surface_targeter.hpp deleted file mode 100644 index 1a54689fc..000000000 --- a/core/include/detray/propagator/actors/surface_targeter.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "detray/definitions/qualifiers.hpp" -#include "detray/propagator/base_actor.hpp" -#include "detray/propagator/base_stepper.hpp" - -namespace detray { - -struct surface_targeter : actor { - - struct state { - - scalar _path; - dindex _target_surface_index = dindex_invalid; - }; - - /// Enforces thepath limit on a stepper state - /// - /// @param abrt_state contains the path limit - /// @param prop_state state of the propagation - template - DETRAY_HOST_DEVICE void operator()(state &actor_state, - propagator_state_t &prop_state) const { - - prop_state._heartbeat = true; - auto &navigation = prop_state._navigation; - auto &stepping = prop_state._stepping; - navigation.set_full_trust(); - - scalar residual = actor_state._path - stepping.path_length(); - stepping.set_constraint(residual); - - typename propagator_state_t::navigator_state_type::intersection_t is; - is.index = actor_state._target_surface_index; - is.path = residual; - auto &candidates = navigation.candidates(); - candidates.clear(); - candidates.push_back(is); - navigation.set_next(candidates.begin()); - navigation.set_unknown(); - - if (residual < std::abs(1e-5)) { - prop_state._heartbeat = false; - candidates.push_back({}); - navigation.next()++; - navigation.set_on_module(); - } - } -}; - -} // namespace detray \ No newline at end of file diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index 3b27b9988..2c70d095b 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -10,7 +10,7 @@ // Project include(s). #include "detray/definitions/qualifiers.hpp" #include "detray/definitions/units.hpp" -#include "detray/propagator/actors/resetter.hpp" +#include "detray/propagator/actors/parameter_resetter.hpp" #include "detray/propagator/constrained_step.hpp" #include "detray/tracks/tracks.hpp" @@ -79,7 +79,7 @@ class base_stepper { surface_container[bound_params.surface_link()]; mask_store - .template execute::kernel>( + .template execute::kernel>( surface.mask_type(), trf_store, surface, *this); } diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index faee056de..61f931704 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -10,8 +10,7 @@ #include "detray/field/constant_magnetic_field.hpp" #include "detray/propagator/actor_chain.hpp" #include "detray/propagator/actors/parameter_transporter.hpp" -#include "detray/propagator/actors/resetter.hpp" -#include "detray/propagator/actors/surface_targeter.hpp" +#include "detray/propagator/actors/parameter_resetter.hpp" #include "detray/propagator/line_stepper.hpp" #include "detray/propagator/navigator.hpp" #include "detray/propagator/propagator.hpp" @@ -37,6 +36,48 @@ using mag_field_t = constant_magnetic_field<>; constexpr scalar epsilon = 1e-3; +struct surface_targeter : actor { + + struct state { + + scalar _path; + dindex _target_surface_index = dindex_invalid; + }; + + /// Enforces thepath limit on a stepper state + /// + /// @param abrt_state contains the path limit + /// @param prop_state state of the propagation + template + DETRAY_HOST_DEVICE void operator()(state &actor_state, + propagator_state_t &prop_state) const { + + prop_state._heartbeat = true; + auto &navigation = prop_state._navigation; + auto &stepping = prop_state._stepping; + navigation.set_full_trust(); + + scalar residual = actor_state._path - stepping.path_length(); + stepping.set_constraint(residual); + + typename propagator_state_t::navigator_state_type::intersection_t is; + is.index = actor_state._target_surface_index; + is.path = residual; + auto &candidates = navigation.candidates(); + candidates.clear(); + candidates.push_back(is); + navigation.set_next(candidates.begin()); + navigation.set_unknown(); + + if (residual < std::abs(1e-5)) { + prop_state._heartbeat = false; + candidates.push_back({}); + navigation.next()++; + navigation.set_on_module(); + } + } +}; + // This tests the covariance transport in rk stepper TEST(covariance_transport, rk_stepper_cartesian) { @@ -62,7 +103,7 @@ TEST(covariance_transport, rk_stepper_cartesian) { rk_stepper>; using actor_chain_t = actor_chain, - resetter>; + parameter_resetter>; using propagator_t = propagator; // Generate track starting point @@ -107,7 +148,7 @@ TEST(covariance_transport, rk_stepper_cartesian) { // Actors surface_targeter::state targeter{S, 0}; parameter_transporter::state bound_updater{}; - resetter::state rst{}; + parameter_resetter::state rst{}; actor_chain_t::state actor_states = std::tie(targeter, bound_updater, rst); @@ -190,7 +231,7 @@ TEST(covariance_transport, linear_stepper_cartesian) { using navigator_t = navigator; using cline_stepper_t = line_stepper>; using actor_chain_t = actor_chain, - resetter>; + parameter_resetter>; using propagator_t = propagator; @@ -217,7 +258,7 @@ TEST(covariance_transport, linear_stepper_cartesian) { // Actors parameter_transporter::state bound_updater{}; - resetter::state rst{}; + parameter_resetter::state rst{}; actor_chain_t::state actor_states = std::tie(bound_updater, rst); propagator_t p({}, {}); diff --git a/tests/common/include/tests/common/material_interaction.inl b/tests/common/include/tests/common/material_interaction.inl new file mode 100644 index 000000000..410f794c0 --- /dev/null +++ b/tests/common/include/tests/common/material_interaction.inl @@ -0,0 +1,450 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/definitions/pdg_particle.hpp" +#include "detray/definitions/units.hpp" +#include "detray/field/constant_magnetic_field.hpp" +#include "detray/materials/interaction.hpp" +#include "detray/materials/material.hpp" +#include "detray/materials/material_slab.hpp" +#include "detray/materials/predefined_materials.hpp" +#include "detray/propagator/actor_chain.hpp" +#include "detray/propagator/actors/aborters.hpp" +#include "detray/propagator/actors/parameter_transporter.hpp" +#include "detray/propagator/actors/pointwise_material_interactor.hpp" +#include "detray/propagator/actors/parameter_resetter.hpp" +#include "detray/propagator/actors/scattering_simulator.hpp" +#include "detray/propagator/navigator.hpp" +#include "detray/propagator/propagator.hpp" +#include "detray/propagator/rk_stepper.hpp" +#include "tests/common/tools/create_telescope_detector.hpp" +#include "tests/common/tools/inspectors.hpp" + +// VecMem include(s). +#include + +// GTest include(s). +#include + +using namespace detray; + +using transform3 = __plugin::transform3; +using matrix_operator = typename transform3::matrix_actor; + +// Test class for MUON energy loss with Bethe function +// Input tuple: < material / energy / expected output from +// https://pdg.lbl.gov/2022/AtomicNuclearProperties for Muon dEdX and range > +class EnergyLossBetheValidation + : public ::testing::TestWithParam< + std::tuple, scalar, scalar>> {}; + +// This tests the material functionalities +TEST_P(EnergyLossBetheValidation, bethe_energy_loss) { + + // Interaction object + interaction I; + + // intersection with a zero incidence angle + line_plane_intersection is; + + // H2 liquid with a unit thickness + material_slab slab(std::get<0>(GetParam()), 1 * unit_constants::cm); + + // muon + const int pdg = pdg_particle::eMuon; + + // mass + const scalar m = 105.7 * unit_constants::MeV; + + // qOverP + const scalar qOverP = -1. / std::get<1>(GetParam()); + + // Bethe Stopping power in MeV * cm^2 / g + const scalar dEdx = + I.compute_energy_loss_bethe(is, slab, pdg, m, qOverP, -1.) / + slab.path_segment(is) / slab.get_material().mass_density() / + (unit_constants::MeV * unit_constants::cm2 / unit_constants::g); + + // Check if difference is within 5% error + EXPECT_TRUE(std::abs(std::get<2>(GetParam()) - dEdx) / dEdx < 0.05); +} + +INSTANTIATE_TEST_SUITE_P( + Bethe_0p1GeV_H2Liquid, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(hydrogen_liquid(), + 0.1003 * unit_constants::GeV, 6.539))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_1GeV_H2Liquid, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(hydrogen_liquid(), + 1.101 * unit_constants::GeV, 4.182))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_10GeV_H2Liquid, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(hydrogen_liquid(), + 10.11 * unit_constants::GeV, 4.777))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_100GeV_H2Liquid, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(hydrogen_liquid(), + 100.1 * unit_constants::GeV, 5.305))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_0p1GeV_HeGas, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(helium_gas(), + 0.1003 * unit_constants::GeV, 3.082))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_1GeV_HeGas, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(helium_gas(), + 1.101 * unit_constants::GeV, 2.133))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_10GeV_HeGas, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(helium_gas(), + 10.11 * unit_constants::GeV, 2.768))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_100GeV_HeGas, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(helium_gas(), + 100.1 * unit_constants::GeV, 3.188))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_0p1GeV_Al, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(aluminium(), + 0.1003 * unit_constants::GeV, 2.533))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_1GeV_Al, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(aluminium(), + 1.101 * unit_constants::GeV, 1.744))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_10GeV_Al, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(aluminium(), + 10.11 * unit_constants::GeV, 2.097))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_100GeV_Al, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(aluminium(), + 100.1 * unit_constants::GeV, 2.360))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_0p1GeV_Si, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(silicon(), + 0.1003 * unit_constants::GeV, 2.608))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_1GeV_Si, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(silicon(), + 1.101 * unit_constants::GeV, 1.803))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_10GeV_Si, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(silicon(), + 10.11 * unit_constants::GeV, 2.177))); + +INSTANTIATE_TEST_SUITE_P( + Bethe_100GeV_Si, EnergyLossBetheValidation, + ::testing::Values(std::make_tuple(silicon(), + 100.1 * unit_constants::GeV, 2.451))); + +// Test class for MUON energy loss with Landau function +// Input tuple: < material / energy / expected energy loss / expected fwhm > +class EnergyLossLandauValidation + : public ::testing::TestWithParam< + std::tuple, scalar, scalar, scalar>> {}; + +TEST_P(EnergyLossLandauValidation, landau_energy_loss) { + + // Interaction object + interaction I; + + // intersection with a zero incidence angle + line_plane_intersection is; + + // H2 liquid with a unit thickness + material_slab slab(std::get<0>(GetParam()), + 0.17 * unit_constants::cm); + + // muon + const int pdg = pdg_particle::eMuon; + + // mass + const scalar m = 105.7 * unit_constants::MeV; + + // qOverP + const scalar qOverP = -1. / std::get<1>(GetParam()); + + // Landau Energy loss in MeV + const scalar dE = + I.compute_energy_loss_landau(is, slab, pdg, m, qOverP, -1) / + (unit_constants::MeV); + + // Check if difference is within 5% error + EXPECT_TRUE(std::abs(std::get<2>(GetParam()) - dE) / dE < 0.05); + + // Landau Energy loss Fluctuation + const scalar fwhm = + I.compute_energy_loss_landau_fwhm(is, slab, pdg, m, qOverP, -1) / + (unit_constants::MeV); + + // Check if difference is within 10% error + EXPECT_TRUE(std::abs(std::get<3>(GetParam()) - fwhm) / fwhm < 0.1); +} + +// Expected output from Fig 33.7 in RPP2018 +INSTANTIATE_TEST_SUITE_P( + Landau_10GeV_Silicon, EnergyLossLandauValidation, + ::testing::Values(std::make_tuple(silicon(), + 10. * unit_constants::GeV, 0.525, 0.13))); + +// Material interaction test with telescope Geometry +TEST(material_interaction, telescope_geometry_energy_loss) { + + vecmem::host_memory_resource host_mr; + + using ln_stepper_t = line_stepper; + + typename ln_stepper_t::free_track_parameters_type default_trk{ + {0, 0, 0}, 0, {1, 0, 0}, -1}; + + // Build from given module positions + std::vector positions = {0., 50., 100., 150., 200., 250., + 300., 350, 400, 450., 500.}; + + const auto mat = silicon_tml(); + const scalar thickness = 0.17 * unit_constants::cm; + + const auto det = create_telescope_detector( + host_mr, positions, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}, 20. * unit_constants::mm, + 20. * unit_constants::mm, mat, thickness); + + using navigator_t = navigator; + using constraints_t = constrained_step<>; + using policy_t = stepper_default_policy; + using stepper_t = line_stepper; + using interactor_t = pointwise_material_interactor; + using actor_chain_t = + actor_chain, interactor_t, + parameter_resetter>; + using propagator_t = propagator; + + // Propagator is built from the stepper and navigator + propagator_t p({}, {}); + + const scalar q = -1.; + const scalar iniP = 10 * unit_constants::GeV; + + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = 0.; + getter::element(bound_vector, e_bound_loc1, 0) = 0.; + getter::element(bound_vector, e_bound_phi, 0) = 0.; + getter::element(bound_vector, e_bound_theta, 0) = M_PI / 2.; + getter::element(bound_vector, e_bound_qoverp, 0) = q / iniP; + getter::element(bound_vector, e_bound_time, 0) = 0.; + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + + // bound track parameter + const bound_track_parameters bound_param(0, bound_vector, + bound_cov); + + propagation::print_inspector::state print_insp_state{}; + pathlimit_aborter::state aborter_state{}; + parameter_transporter::state bound_updater{}; + interactor_t::state interactor_state{}; + parameter_resetter::state parameter_resetter_state{}; + + // Create actor states tuples + actor_chain_t::state actor_states = + std::tie(print_insp_state, aborter_state, bound_updater, + interactor_state, parameter_resetter_state); + + propagator_t::state state(bound_param, det, actor_states); + + // Propagate the entire detector + ASSERT_TRUE(p.propagate(state)) + << print_insp_state.to_string() << std::endl; + + // muon + const int pdg = interactor_state.pdg; + + // mass + const scalar mass = interactor_state.mass; + + // new momentum + const scalar newP = state._stepping._bound_params.charge() / + state._stepping._bound_params.qop(); + + // new energy + const scalar newE = std::sqrt(newP * newP + mass * mass); + + // Initial energy + const scalar iniE = std::sqrt(iniP * iniP + mass * mass); + + // New qop variance + const scalar new_var_qop = + matrix_operator().element(state._stepping._bound_params.covariance(), + e_bound_qoverp, e_bound_qoverp); + + // Interaction object + interaction I; + + // intersection with a zero incidence angle + line_plane_intersection is; + + // Same material used for default telescope detector + material_slab slab(mat, thickness); + + // Expected Bethe Stopping power for telescope geometry is estimated + // as (number of planes * energy loss per plane assuming 1 GeV muon). + // It is not perfectly precise as the track loses its energy during + // propagation. However, since the energy loss << the track momentum, + // the assumption is not very bad + + // -1 is required because the last surface is a portal + const scalar dE = + I.compute_energy_loss_bethe(is, slab, pdg, mass, q / iniP, q) * + (positions.size() - 1); + + // Check if the new energy after propagation is enough close to the + // expected value + EXPECT_NEAR(newE, iniE - dE, 1e-5); + + const scalar sigma_qop = I.compute_energy_loss_landau_sigma_QOverP( + is, slab, pdg, mass, q / iniP, q); + + const scalar dvar_qop = sigma_qop * sigma_qop * (positions.size() - 1); + + EXPECT_NEAR(new_var_qop, dvar_qop, 1e-10); + + // @todo: Validate the backward direction case as well? +} + +scalar get_variance(const std::vector& v) { + scalar sum = std::accumulate(v.begin(), v.end(), 0.0); + scalar mean = sum / v.size(); + std::vector diff(v.size()); + std::transform(v.begin(), v.end(), diff.begin(), + [mean](double x) { return x - mean; }); + scalar sq_sum = + std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0); + scalar variance = sq_sum / v.size(); + return variance; +} + +// Material interaction test with telescope Geometry +TEST(material_interaction, telescope_geometry_scattering_angle) { + vecmem::host_memory_resource host_mr; + + using ln_stepper_t = line_stepper; + + typename ln_stepper_t::free_track_parameters_type default_trk{ + {0, 0, 0}, 0, {1, 0, 0}, -1}; + + // Build from given module positions + std::vector positions = {0., 1000. * unit_constants::cm}; + + const auto mat = silicon_tml(); + const scalar thickness = 500 * unit_constants::cm; + // Use unbounded surfaces + constexpr bool unbounded = true; + + const auto det = create_telescope_detector( + host_mr, positions, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}, 2000. * unit_constants::mm, + 2000. * unit_constants::mm, mat, thickness); + + using navigator_t = navigator; + using constraints_t = constrained_step<>; + using policy_t = stepper_default_policy; + using stepper_t = line_stepper; + using interactor_t = pointwise_material_interactor; + using simulator_t = scattering_simulator; + using actor_chain_t = + actor_chain, interactor_t, + simulator_t, parameter_resetter>; + using propagator_t = propagator; + + // Propagator is built from the stepper and navigator + propagator_t p({}, {}); + + const scalar q = -1.; + const scalar iniP = 10 * unit_constants::GeV; + + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = 0.; + getter::element(bound_vector, e_bound_loc1, 0) = 0.; + getter::element(bound_vector, e_bound_phi, 0) = 0; + getter::element(bound_vector, e_bound_theta, 0) = M_PI_2; + getter::element(bound_vector, e_bound_qoverp, 0) = q / iniP; + getter::element(bound_vector, e_bound_time, 0) = 0.; + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + + // bound track parameter + const bound_track_parameters bound_param(0, bound_vector, + bound_cov); + + int n_samples = 100000; + std::vector phi_vec; + std::vector theta_vec; + + scalar ref_phi_var(0); + scalar ref_theta_var(0); + + for (int i = 0; i < n_samples; i++) { + + propagation::print_inspector::state print_insp_state{}; + pathlimit_aborter::state aborter_state{}; + parameter_transporter::state bound_updater{}; + interactor_t::state interactor_state{}; + interactor_state.do_energy_loss = false; + simulator_t::state simulator_state(interactor_state); + parameter_resetter::state parameter_resetter_state{}; + + // Create actor states tuples + actor_chain_t::state actor_states = + std::tie(print_insp_state, aborter_state, bound_updater, + interactor_state, simulator_state, parameter_resetter_state); + + propagator_t::state state(bound_param, det, actor_states); + + state._stepping().set_overstep_tolerance(-1000. * unit_constants::um); + + // Propagate the entire detector + ASSERT_TRUE(p.propagate(state)) + << print_insp_state.to_string() << std::endl; + + const auto& final_params = state._stepping._bound_params; + + if (i == 0) { + const auto& covariance = final_params.covariance(); + ref_phi_var = + matrix_operator().element(covariance, e_bound_phi, e_bound_phi); + ref_theta_var = matrix_operator().element(covariance, e_bound_theta, + e_bound_theta); + } + + phi_vec.push_back(final_params.phi()); + theta_vec.push_back(final_params.theta()); + } + + scalar phi_var = get_variance(phi_vec); + scalar theta_var = get_variance(theta_vec); + + EXPECT_NEAR((phi_var - ref_phi_var) / ref_phi_var, 0, 0.05); + EXPECT_NEAR((theta_var - ref_theta_var) / ref_theta_var, 0, 0.05); + + // To make sure that the varainces are zero + EXPECT_TRUE(ref_phi_var > 1e-4 && ref_theta_var > 1e-4); +} From 9169aa0f64322b192f11f92705a6a95be54b90c9 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 28 Sep 2022 20:49:35 -0700 Subject: [PATCH 44/63] Clang format --- core/include/detray/propagator/base_stepper.hpp | 6 +++--- .../common/include/tests/common/covariance_transport.inl | 6 +++--- .../common/include/tests/common/material_interaction.inl | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index 2c70d095b..88c55eb7e 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -78,9 +78,9 @@ class base_stepper { const auto &surface = surface_container[bound_params.surface_link()]; - mask_store - .template execute::kernel>( - surface.mask_type(), trf_store, surface, *this); + mask_store.template execute< + typename parameter_resetter::kernel>( + surface.mask_type(), trf_store, surface, *this); } /// free track parameter diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl index 61f931704..86597c672 100644 --- a/tests/common/include/tests/common/covariance_transport.inl +++ b/tests/common/include/tests/common/covariance_transport.inl @@ -9,8 +9,8 @@ #include "detray/definitions/units.hpp" #include "detray/field/constant_magnetic_field.hpp" #include "detray/propagator/actor_chain.hpp" -#include "detray/propagator/actors/parameter_transporter.hpp" #include "detray/propagator/actors/parameter_resetter.hpp" +#include "detray/propagator/actors/parameter_transporter.hpp" #include "detray/propagator/line_stepper.hpp" #include "detray/propagator/navigator.hpp" #include "detray/propagator/propagator.hpp" @@ -155,7 +155,7 @@ TEST(covariance_transport, rk_stepper_cartesian) { propagator_t p({}, {}); propagator_t::state propagation(bound_param0, mag_field, det, actor_states); - crk_stepper_t::state& crk_state = propagation._stepping; + crk_stepper_t::state &crk_state = propagation._stepping; // Decrease tolerance down to 1e-8 crk_state._tolerance = 1e-8; @@ -268,7 +268,7 @@ TEST(covariance_transport, linear_stepper_cartesian) { p.propagate(propagation); // Bound state after one turn propagation - const auto& bound_param1 = propagation._stepping._bound_params; + const auto &bound_param1 = propagation._stepping._bound_params; // const auto bound_vec0 = bound_param0.vector(); // const auto bound_vec1 = bound_param1.vector(); diff --git a/tests/common/include/tests/common/material_interaction.inl b/tests/common/include/tests/common/material_interaction.inl index 410f794c0..3756f19fb 100644 --- a/tests/common/include/tests/common/material_interaction.inl +++ b/tests/common/include/tests/common/material_interaction.inl @@ -15,9 +15,9 @@ #include "detray/materials/predefined_materials.hpp" #include "detray/propagator/actor_chain.hpp" #include "detray/propagator/actors/aborters.hpp" +#include "detray/propagator/actors/parameter_resetter.hpp" #include "detray/propagator/actors/parameter_transporter.hpp" #include "detray/propagator/actors/pointwise_material_interactor.hpp" -#include "detray/propagator/actors/parameter_resetter.hpp" #include "detray/propagator/actors/scattering_simulator.hpp" #include "detray/propagator/navigator.hpp" #include "detray/propagator/propagator.hpp" @@ -413,9 +413,9 @@ TEST(material_interaction, telescope_geometry_scattering_angle) { parameter_resetter::state parameter_resetter_state{}; // Create actor states tuples - actor_chain_t::state actor_states = - std::tie(print_insp_state, aborter_state, bound_updater, - interactor_state, simulator_state, parameter_resetter_state); + actor_chain_t::state actor_states = std::tie( + print_insp_state, aborter_state, bound_updater, interactor_state, + simulator_state, parameter_resetter_state); propagator_t::state state(bound_param, det, actor_states); From 1c38ba2fe886fca259e1b2d8c1123fb6308abf44 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Fri, 7 Oct 2022 00:55:34 -0700 Subject: [PATCH 45/63] Rewrite tests --- core/include/detray/masks/cylinder3.hpp | 4 + .../tests/common/covariance_transport.inl | 299 ------------------ .../include/tests/common/line_stepper.inl | 117 +++++++ .../include/tests/common/path_correction.inl | 257 +++++++++++++++ tests/unit_tests/array/CMakeLists.txt | 4 +- ...e_transport.cpp => array_line_stepper.cpp} | 2 +- .../array/array_path_correction.cpp | 9 + tests/unit_tests/eigen/CMakeLists.txt | 4 +- tests/unit_tests/eigen/eigen_line_stepper.cpp | 0 ...ransport.cpp => eigen_path_correction.cpp} | 2 +- tests/unit_tests/smatrix/CMakeLists.txt | 4 +- ...transport.cpp => smatrix_line_stepper.cpp} | 2 +- .../smatrix/smatrix_path_correction.cpp | 9 + tests/unit_tests/vc/CMakeLists.txt | 4 +- ...ransport.cpp => vc_array_line_stepper.cpp} | 2 +- .../vc/vc_array_path_correction.cpp | 9 + 16 files changed, 417 insertions(+), 311 deletions(-) delete mode 100644 tests/common/include/tests/common/covariance_transport.inl create mode 100644 tests/common/include/tests/common/line_stepper.inl create mode 100644 tests/common/include/tests/common/path_correction.inl rename tests/unit_tests/array/{array_covariance_transport.cpp => array_line_stepper.cpp} (81%) create mode 100644 tests/unit_tests/array/array_path_correction.cpp create mode 100644 tests/unit_tests/eigen/eigen_line_stepper.cpp rename tests/unit_tests/eigen/{eigen_covariance_transport.cpp => eigen_path_correction.cpp} (81%) rename tests/unit_tests/smatrix/{smatrix_covariance_transport.cpp => smatrix_line_stepper.cpp} (81%) create mode 100644 tests/unit_tests/smatrix/smatrix_path_correction.cpp rename tests/unit_tests/vc/{vc_array_covariance_transport.cpp => vc_array_line_stepper.cpp} (81%) create mode 100644 tests/unit_tests/vc/vc_array_path_correction.cpp diff --git a/core/include/detray/masks/cylinder3.hpp b/core/include/detray/masks/cylinder3.hpp index 19949a936..66d908ca8 100644 --- a/core/include/detray/masks/cylinder3.hpp +++ b/core/include/detray/masks/cylinder3.hpp @@ -71,6 +71,10 @@ class cylinder3 final : public mask_baseoperator[](0); } + /** Mask operation * * @tparam inside_local_type::point3 is the deduced type of the point to be diff --git a/tests/common/include/tests/common/covariance_transport.inl b/tests/common/include/tests/common/covariance_transport.inl deleted file mode 100644 index 86597c672..000000000 --- a/tests/common/include/tests/common/covariance_transport.inl +++ /dev/null @@ -1,299 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -// Project include(s) -#include "detray/definitions/units.hpp" -#include "detray/field/constant_magnetic_field.hpp" -#include "detray/propagator/actor_chain.hpp" -#include "detray/propagator/actors/parameter_resetter.hpp" -#include "detray/propagator/actors/parameter_transporter.hpp" -#include "detray/propagator/line_stepper.hpp" -#include "detray/propagator/navigator.hpp" -#include "detray/propagator/propagator.hpp" -#include "detray/propagator/rk_stepper.hpp" -#include "detray/tracks/tracks.hpp" -#include "tests/common/tools/create_telescope_detector.hpp" - -// Vecmem include(s). -#include - -// google-test include(s) -#include - -// System include(s) -#include -#include - -using namespace detray; -using vector2 = __plugin::vector2; -using transform3 = __plugin::transform3; -using matrix_operator = standard_matrix_operator; -using mag_field_t = constant_magnetic_field<>; - -constexpr scalar epsilon = 1e-3; - -struct surface_targeter : actor { - - struct state { - - scalar _path; - dindex _target_surface_index = dindex_invalid; - }; - - /// Enforces thepath limit on a stepper state - /// - /// @param abrt_state contains the path limit - /// @param prop_state state of the propagation - template - DETRAY_HOST_DEVICE void operator()(state &actor_state, - propagator_state_t &prop_state) const { - - prop_state._heartbeat = true; - auto &navigation = prop_state._navigation; - auto &stepping = prop_state._stepping; - navigation.set_full_trust(); - - scalar residual = actor_state._path - stepping.path_length(); - stepping.set_constraint(residual); - - typename propagator_state_t::navigator_state_type::intersection_t is; - is.index = actor_state._target_surface_index; - is.path = residual; - auto &candidates = navigation.candidates(); - candidates.clear(); - candidates.push_back(is); - navigation.set_next(candidates.begin()); - navigation.set_unknown(); - - if (residual < std::abs(1e-5)) { - prop_state._heartbeat = false; - candidates.push_back({}); - navigation.next()++; - navigation.set_on_module(); - } - } -}; - -// This tests the covariance transport in rk stepper -TEST(covariance_transport, rk_stepper_cartesian) { - - vecmem::host_memory_resource host_mr; - - using ln_stepper_t = line_stepper; - - // Use rectangular surfaces - constexpr bool rectangular = false; - - // Create telescope detector with a single plane - typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {1, 0, 0}, -1}; - std::vector positions = {0., - std::numeric_limits::infinity()}; - - const auto det = create_telescope_detector( - host_mr, positions, ln_stepper_t(), - typename ln_stepper_t::state{default_trk}); - - using navigator_t = navigator; - using crk_stepper_t = - rk_stepper>; - using actor_chain_t = - actor_chain, - parameter_resetter>; - using propagator_t = propagator; - - // Generate track starting point - vector2 local{2, 3}; - vector3 mom{0.001, 0., 0.}; - vector3 dir = vector::normalize(mom); - - scalar time = 0.; - scalar q = -1.; - - // bound vector - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = local[0]; - getter::element(bound_vector, e_bound_loc1, 0) = local[1]; - getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); - getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); - getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); - getter::element(bound_vector, e_bound_time, 0) = time; - - // bound covariance - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template zero(); - getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; - getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; - getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; - // Note: Set theta error as ZERO, to constrain the loc1 divergence - getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; - getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; - getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; - - // bound track parameter - const bound_track_parameters bound_param0(0, bound_vector, - bound_cov); - - // B field - vector3 B{0, 0, 1. * unit_constants::T}; - mag_field_t mag_field(B); - - // Path length per turn - scalar S = 2. * getter::perp(mom) / getter::norm(B) * M_PI; - - // Actors - surface_targeter::state targeter{S, 0}; - parameter_transporter::state bound_updater{}; - parameter_resetter::state rst{}; - - actor_chain_t::state actor_states = std::tie(targeter, bound_updater, rst); - - propagator_t p({}, {}); - propagator_t::state propagation(bound_param0, mag_field, det, actor_states); - - crk_stepper_t::state &crk_state = propagation._stepping; - - // Decrease tolerance down to 1e-8 - crk_state._tolerance = 1e-8; - - // RK stepper and its state - EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); - EXPECT_FLOAT_EQ(crk_state().pos()[1], local[0]); // y - EXPECT_FLOAT_EQ(crk_state().pos()[2], local[1]); // z - EXPECT_NEAR(crk_state().dir()[0], dir[0], epsilon); - EXPECT_NEAR(crk_state().dir()[1], dir[1], epsilon); - EXPECT_NEAR(crk_state().dir()[2], dir[2], epsilon); - - // helix trajectory - detail::helix helix(crk_state(), &B); - - // Run propagator - p.propagate(propagation); - - // RK stepper and its state - EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); - EXPECT_NEAR(crk_state().pos()[1], local[0], epsilon); // y - EXPECT_NEAR(crk_state().pos()[2], local[1], epsilon); // z - EXPECT_NEAR(crk_state().dir()[0], dir[0], epsilon); - EXPECT_NEAR(crk_state().dir()[1], dir[1], epsilon); - EXPECT_NEAR(crk_state().dir()[2], dir[2], epsilon); - EXPECT_NEAR(crk_state.path_length(), targeter._path, epsilon); - - // Bound state after one turn propagation - const auto bound_param1 = crk_state._bound_params; - - const auto bound_vec0 = bound_param0.vector(); - const auto bound_vec1 = bound_param1.vector(); - - const auto bound_cov0 = bound_param0.covariance(); - const auto bound_cov1 = bound_param1.covariance(); - - // Check if the bound state stays the same after one turn propagation - - // vector - for (std::size_t i = 0; i < e_bound_size; i++) { - EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), - matrix_operator().element(bound_vec1, i, 0), epsilon); - } - - // covaraince - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), - matrix_operator().element(bound_cov1, i, j), - crk_state.path_length() * epsilon); - } - } -} - -TEST(covariance_transport, linear_stepper_cartesian) { - - vecmem::host_memory_resource host_mr; - - using ln_stepper_t = line_stepper; - - // Use rectangular surfaces - constexpr bool unbounded = true; - - // Create telescope detector with a single plane - typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {1, 0, 0}, -1}; - std::vector positions = {0., 10., 20., 30., 40., 50., 60.}; - - const auto det = create_telescope_detector( - host_mr, positions, ln_stepper_t(), - typename ln_stepper_t::state{default_trk}); - - using navigator_t = navigator; - using cline_stepper_t = line_stepper>; - using actor_chain_t = actor_chain, - parameter_resetter>; - using propagator_t = - propagator; - - // Bound vector - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = 0.; - getter::element(bound_vector, e_bound_loc1, 0) = 0.; - getter::element(bound_vector, e_bound_phi, 0) = 0.; - getter::element(bound_vector, e_bound_theta, 0) = M_PI / 4.; - getter::element(bound_vector, e_bound_qoverp, 0) = -1. / 10.; - getter::element(bound_vector, e_bound_time, 0) = 0.; - - // Bound covariance - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template identity(); - - // Note: Set angle error as ZERO, to constrain the loc0 and loc1 divergence - getter::element(bound_cov, e_bound_phi, e_bound_phi) = 0.; - getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; - - // Bound track parameter - const bound_track_parameters bound_param0(0, bound_vector, - bound_cov); - - // Actors - parameter_transporter::state bound_updater{}; - parameter_resetter::state rst{}; - actor_chain_t::state actor_states = std::tie(bound_updater, rst); - - propagator_t p({}, {}); - propagator_t::state propagation(bound_param0, det, actor_states); - - // Run propagator - p.propagate(propagation); - - // Bound state after one turn propagation - const auto &bound_param1 = propagation._stepping._bound_params; - - // const auto bound_vec0 = bound_param0.vector(); - // const auto bound_vec1 = bound_param1.vector(); - - const auto bound_cov0 = bound_param0.covariance(); - const auto bound_cov1 = bound_param1.covariance(); - - // Check if the track reaches the final surface - EXPECT_EQ(bound_param0.surface_link(), 0); - EXPECT_EQ(bound_param1.surface_link(), 5); - - // Check covaraince - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), - matrix_operator().element(bound_cov1, i, j), epsilon); - } - } - - // Check covaraince - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - - EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), - matrix_operator().element(bound_cov1, i, j), epsilon); - } - } -} diff --git a/tests/common/include/tests/common/line_stepper.inl b/tests/common/include/tests/common/line_stepper.inl new file mode 100644 index 000000000..b151b8896 --- /dev/null +++ b/tests/common/include/tests/common/line_stepper.inl @@ -0,0 +1,117 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/definitions/units.hpp" +#include "detray/field/constant_magnetic_field.hpp" +#include "detray/propagator/actor_chain.hpp" +#include "detray/propagator/actors/parameter_resetter.hpp" +#include "detray/propagator/actors/parameter_transporter.hpp" +#include "detray/propagator/line_stepper.hpp" +#include "detray/propagator/navigator.hpp" +#include "detray/propagator/propagator.hpp" +#include "tests/common/tools/create_telescope_detector.hpp" + +// Vecmem include(s). +#include + +// google-test include(s). +#include + +using namespace detray; +using matrix_operator = standard_matrix_operator; +constexpr scalar epsilon = 1e-6; + +using transform3 = __plugin::transform3; + +TEST(line_stepper, covariance_transport) { + + vecmem::host_memory_resource host_mr; + + using ln_stepper_t = line_stepper; + + // Use rectangular surfaces + constexpr bool unbounded = true; + + // Create telescope detector with a single plane + typename ln_stepper_t::free_track_parameters_type default_trk{ + {0, 0, 0}, 0, {1, 0, 0}, -1}; + std::vector positions = {0., 10., 20., 30., 40., 50., 60.}; + + const auto det = create_telescope_detector( + host_mr, positions, ln_stepper_t(), + typename ln_stepper_t::state{default_trk}); + + using navigator_t = navigator; + using cline_stepper_t = line_stepper>; + using actor_chain_t = actor_chain, + parameter_resetter>; + using propagator_t = + propagator; + + // Bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = 0.; + getter::element(bound_vector, e_bound_loc1, 0) = 0.; + getter::element(bound_vector, e_bound_phi, 0) = 0.; + getter::element(bound_vector, e_bound_theta, 0) = M_PI / 4.; + getter::element(bound_vector, e_bound_qoverp, 0) = -1. / 10.; + getter::element(bound_vector, e_bound_time, 0) = 0.; + + // Bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template identity(); + + // Note: Set angle error as ZERO, to constrain the loc0 and loc1 divergence + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 0.; + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + + // Bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + // Actors + parameter_transporter::state bound_updater{}; + parameter_resetter::state rst{}; + actor_chain_t::state actor_states = std::tie(bound_updater, rst); + + propagator_t p({}, {}); + propagator_t::state propagation(bound_param0, det, actor_states); + + // Run propagator + p.propagate(propagation); + + // Bound state after one turn propagation + const auto &bound_param1 = propagation._stepping._bound_params; + + // const auto bound_vec0 = bound_param0.vector(); + // const auto bound_vec1 = bound_param1.vector(); + + // Check if the track reaches the final surface + EXPECT_EQ(bound_param0.surface_link(), 0); + EXPECT_EQ(bound_param1.surface_link(), 5); + + const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); + + // Check covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), epsilon); + } + } + + // Check covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), epsilon); + } + } +} diff --git a/tests/common/include/tests/common/path_correction.inl b/tests/common/include/tests/common/path_correction.inl new file mode 100644 index 000000000..5b6cf35d7 --- /dev/null +++ b/tests/common/include/tests/common/path_correction.inl @@ -0,0 +1,257 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s). +#include "detray/definitions/units.hpp" +#include "detray/field/constant_magnetic_field.hpp" +#include "detray/materials/predefined_materials.hpp" +#include "detray/propagator/actor_chain.hpp" +#include "detray/propagator/actors/parameter_resetter.hpp" +#include "detray/propagator/actors/parameter_transporter.hpp" +#include "detray/propagator/line_stepper.hpp" +#include "detray/propagator/navigator.hpp" +#include "detray/propagator/propagator.hpp" +#include "detray/propagator/rk_stepper.hpp" +#include "detray/tracks/tracks.hpp" +#include "tests/common/tools/detector_metadata.hpp" + +// Vecmem include(s). +#include + +// google-test include(s). +#include + +using namespace detray; + +struct surface_targeter : actor { + + struct state { + scalar _path; + dindex _target_surface_index = dindex_invalid; + }; + + /// Enforces thepath limit on a stepper state + /// + /// @param abrt_state contains the path limit + /// @param prop_state state of the propagation + template + DETRAY_HOST_DEVICE void operator()(state &actor_state, + propagator_state_t &prop_state) const { + + prop_state._heartbeat = true; + auto &navigation = prop_state._navigation; + auto &stepping = prop_state._stepping; + navigation.set_full_trust(); + + scalar residual = actor_state._path - stepping.path_length(); + stepping.set_constraint(residual); + + typename propagator_state_t::navigator_state_type::intersection_t is; + is.index = actor_state._target_surface_index; + is.path = residual; + auto &candidates = navigation.candidates(); + candidates.clear(); + candidates.push_back(is); + navigation.set_next(candidates.begin()); + navigation.set_unknown(); + + if (residual < std::abs(1e-5)) { + prop_state._heartbeat = false; + candidates.push_back({}); + navigation.next()++; + navigation.set_on_module(); + } + } +}; + +// Type Definitions +using vector2 = __plugin::vector2; +using vector3 = __plugin::vector3; +using matrix_operator = standard_matrix_operator; +using registry_type = detector_registry::default_detector; +using detector_type = detector; +using mask_container = typename detector_type::mask_container; +using material_container = typename detector_type::material_container; +using transform3 = typename detector_type::transform3; +using surface_type = typename detector_type::surface_container::value_type; +using edge_type = typename surface_type::edge_type; +using mask_link_type = typename surface_type::mask_link; +using material_link_type = typename surface_type::material_link; +using mag_field_t = constant_magnetic_field<>; +using navigator_t = navigator; +using crk_stepper_t = rk_stepper>; +using actor_chain_t = + actor_chain, + parameter_resetter>; +using propagator_t = propagator; + +namespace env { + +constexpr scalar epsilon = 1e-3; +constexpr scalar rk_tolerance = 1e-8; + +// B field +const vector3 B{0, 0, 1. * unit_constants::T}; +const mag_field_t mag_field(B); + +// memory resource +vecmem::host_memory_resource resource; + +// Context +const typename detector_type::context ctx{}; + +} // namespace env + +// This tests the path correction of cartesian coordinate +TEST(path_correction, cartesian) { + + // Create a detector + detector_type det(env::resource); + + // Mask and material ID + constexpr registry_type::mask_ids mask_id = + registry_type::mask_ids::e_rectangle2; + constexpr registry_type::material_ids material_id = + registry_type::material_ids::e_slab; + + // Add a volume + det.new_volume({0., 0., 0., 0., -M_PI, M_PI}); + + typename detector_type::surface_container surfaces(&env::resource); + typename detector_type::transform_container transforms(env::resource); + typename detector_type::mask_container masks(env::resource); + typename detector_type::material_container materials(env::resource); + + // Add a surface + const auto trf_index = transforms.size(env::ctx); + mask_link_type mask_link{mask_id, masks.template size()}; + material_link_type material_link{material_id, + materials.template size()}; + surfaces.emplace_back(trf_index, mask_link, material_link, 0, + dindex_invalid, false); + + // Add a transform + const vector3 t{0, 0, 0}; + const vector3 z{1, 0, 0}; + const vector3 x{0, 1, 0}; + transforms.emplace_back(env::ctx, t, z, x); + + // Add a mask + const scalar hx = 100. * unit_constants::mm; + const scalar hy = 100. * unit_constants::mm; + masks.template add_value(hx, hy, edge_type{0, dindex_invalid}); + + // Add a material + const material mat = silicon(); + const scalar thickness = 2 * unit_constants::mm; + materials.template add_value(mat, thickness); + + typename detector_type::volume_type &vol = det.volume_by_index(0); + det.add_objects_per_volume(env::ctx, vol, surfaces, masks, materials, + transforms); + + // Generate track starting point + vector2 local{2, 3}; + vector3 mom{1 * unit_constants::MeV, 0., 0.}; + vector3 dir = vector::normalize(mom); + + scalar time = 0.; + scalar q = -1.; + + // bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = local[0]; + getter::element(bound_vector, e_bound_loc1, 0) = local[1]; + getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); + getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); + getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); + getter::element(bound_vector, e_bound_time, 0) = time; + + // bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; + getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; + // Note: Set theta error as ZERO, to constrain the loc1 divergence + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; + getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + + // bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + // Path length per turn + scalar S = 2. * getter::perp(mom) / getter::norm(env::B) * M_PI; + + // Actors + surface_targeter::state targeter{S, 0}; + parameter_transporter::state bound_updater{}; + parameter_resetter::state rst{}; + + actor_chain_t::state actor_states = std::tie(targeter, bound_updater, rst); + + propagator_t p({}, {}); + propagator_t::state propagation(bound_param0, env::mag_field, det, + actor_states); + + crk_stepper_t::state &crk_state = propagation._stepping; + + // Decrease tolerance down to 1e-8 + crk_state._tolerance = env::rk_tolerance; + + // RK stepper and its state + EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); + EXPECT_FLOAT_EQ(crk_state().pos()[1], local[0]); // y + EXPECT_FLOAT_EQ(crk_state().pos()[2], local[1]); // z + EXPECT_NEAR(crk_state().dir()[0], dir[0], env::epsilon); + EXPECT_NEAR(crk_state().dir()[1], dir[1], env::epsilon); + EXPECT_NEAR(crk_state().dir()[2], dir[2], env::epsilon); + + // helix trajectory + detail::helix helix(crk_state(), &env::B); + + // Run propagator + p.propagate(propagation); + + // RK stepper and its state + EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); + EXPECT_NEAR(crk_state().pos()[1], local[0], env::epsilon); // y + EXPECT_NEAR(crk_state().pos()[2], local[1], env::epsilon); // z + EXPECT_NEAR(crk_state().dir()[0], dir[0], env::epsilon); + EXPECT_NEAR(crk_state().dir()[1], dir[1], env::epsilon); + EXPECT_NEAR(crk_state().dir()[2], dir[2], env::epsilon); + EXPECT_NEAR(crk_state.path_length(), targeter._path, env::epsilon); + + // Bound state after one turn propagation + const auto bound_param1 = crk_state._bound_params; + + const auto bound_vec0 = bound_param0.vector(); + const auto bound_vec1 = bound_param1.vector(); + + const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); + + // Check if the bound state stays the same after one turn propagation + + // vector + for (std::size_t i = 0; i < e_bound_size; i++) { + EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), + matrix_operator().element(bound_vec1, i, 0), env::epsilon); + } + + // covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), + crk_state.path_length() * env::epsilon); + } + } +} \ No newline at end of file diff --git a/tests/unit_tests/array/CMakeLists.txt b/tests/unit_tests/array/CMakeLists.txt index 1df2e3a3b..21948e9e6 100644 --- a/tests/unit_tests/array/CMakeLists.txt +++ b/tests/unit_tests/array/CMakeLists.txt @@ -9,13 +9,13 @@ detray_add_test( array "array_actor_chain.cpp" "array_annulus2.cpp" "array_container.cpp" "array_coordinate_cartesian2.cpp" "array_coordinate_cartesian3.cpp" "array_coordinate_cylindrical2.cpp" "array_coordinate_cylindrical3.cpp" "array_coordinate_line2.cpp" "array_coordinate_polar2.cpp" - "array_core.cpp" "array_covariance_transport.cpp" + "array_core.cpp" "array_path_correction.cpp" "array_cylinder_intersection.cpp" "array_cylinder3.cpp" "array_detector.cpp" "array_geometry_volume_graph.cpp" "array_geometry_linking.cpp" "array_geometry_navigation.cpp" "array_geometry_scan.cpp" "array_guided_navigator.cpp" "array_helix_trajectory.cpp" "array_intersection_kernel.cpp" "array_particle_gun.cpp" - "array_mask_store.cpp" "array_materials.cpp" "array_navigator.cpp" + "array_line_stepper.cpp" "array_mask_store.cpp" "array_materials.cpp" "array_navigator.cpp" "array_planar_intersection.cpp" "array_line_intersection.cpp" "array_line.cpp" "array_propagator.cpp" "array_rectangle2.cpp" "array_ring2.cpp" "array_single3.cpp" "array_stepper.cpp" "array_surfaces_finder.cpp" diff --git a/tests/unit_tests/array/array_covariance_transport.cpp b/tests/unit_tests/array/array_line_stepper.cpp similarity index 81% rename from tests/unit_tests/array/array_covariance_transport.cpp rename to tests/unit_tests/array/array_line_stepper.cpp index 9a0ea844b..d55d144fa 100644 --- a/tests/unit_tests/array/array_covariance_transport.cpp +++ b/tests/unit_tests/array/array_line_stepper.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/array_definitions.hpp" -#include "tests/common/covariance_transport.inl" +#include "tests/common/line_stepper.inl" diff --git a/tests/unit_tests/array/array_path_correction.cpp b/tests/unit_tests/array/array_path_correction.cpp new file mode 100644 index 000000000..9344e0349 --- /dev/null +++ b/tests/unit_tests/array/array_path_correction.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/array_definitions.hpp" +#include "tests/common/path_correction.inl" \ No newline at end of file diff --git a/tests/unit_tests/eigen/CMakeLists.txt b/tests/unit_tests/eigen/CMakeLists.txt index 257b121c5..b4a201a86 100644 --- a/tests/unit_tests/eigen/CMakeLists.txt +++ b/tests/unit_tests/eigen/CMakeLists.txt @@ -9,12 +9,12 @@ detray_add_test( eigen "eigen_actor_chain.cpp" "eigen_annulus2.cpp" "eigen_container.cpp" "eigen_coordinate_cartesian2.cpp" "eigen_coordinate_cartesian3.cpp" "eigen_coordinate_cylindrical2.cpp" "eigen_coordinate_cylindrical3.cpp" "eigen_coordinate_line2.cpp" "eigen_coordinate_polar2.cpp" - "eigen_core.cpp" "eigen_covariance_transport.cpp" + "eigen_core.cpp" "eigen_path_correction.cpp" "eigen_cylinder_intersection.cpp" "eigen_cylinder3.cpp" "eigen_detector.cpp" "eigen_geometry_volume_graph.cpp" "eigen_geometry_linking.cpp" "eigen_geometry_navigation.cpp" "eigen_geometry_scan.cpp" "eigen_guided_navigator.cpp" "eigen_helix_trajectory.cpp" - "eigen_intersection_kernel.cpp" "eigen_mask_store.cpp" "eigen_materials.cpp" + "eigen_intersection_kernel.cpp" "eigen_line_stepper.cpp" "eigen_mask_store.cpp" "eigen_materials.cpp" "eigen_navigator.cpp" "eigen_particle_gun.cpp" "eigen_planar_intersection.cpp" "eigen_line_intersection.cpp" "eigen_line.cpp" "eigen_propagator.cpp" "eigen_rectangle2.cpp" "eigen_ring2.cpp" "eigen_single3.cpp" diff --git a/tests/unit_tests/eigen/eigen_line_stepper.cpp b/tests/unit_tests/eigen/eigen_line_stepper.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit_tests/eigen/eigen_covariance_transport.cpp b/tests/unit_tests/eigen/eigen_path_correction.cpp similarity index 81% rename from tests/unit_tests/eigen/eigen_covariance_transport.cpp rename to tests/unit_tests/eigen/eigen_path_correction.cpp index ea47ced77..5592a0628 100644 --- a/tests/unit_tests/eigen/eigen_covariance_transport.cpp +++ b/tests/unit_tests/eigen/eigen_path_correction.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/eigen_definitions.hpp" -#include "tests/common/covariance_transport.inl" +#include "tests/common/line_stepper.inl" \ No newline at end of file diff --git a/tests/unit_tests/smatrix/CMakeLists.txt b/tests/unit_tests/smatrix/CMakeLists.txt index e3531f4c9..1698012f5 100644 --- a/tests/unit_tests/smatrix/CMakeLists.txt +++ b/tests/unit_tests/smatrix/CMakeLists.txt @@ -9,13 +9,13 @@ detray_add_test( smatrix "smatrix_actor_chain.cpp" "smatrix_annulus2.cpp" "smatrix_container.cpp" "smatrix_coordinate_cartesian2.cpp" "smatrix_coordinate_cartesian3.cpp" "smatrix_coordinate_cylindrical2.cpp" "smatrix_coordinate_cylindrical3.cpp" "smatrix_coordinate_line2.cpp" "smatrix_coordinate_polar2.cpp" - "smatrix_core.cpp" "smatrix_covariance_transport.cpp" + "smatrix_core.cpp" "smatrix_path_correction.cpp" "smatrix_cylinder_intersection.cpp" "smatrix_cylinder3.cpp" "smatrix_detector.cpp" "smatrix_geometry_volume_graph.cpp" "smatrix_geometry_linking.cpp" "smatrix_geometry_navigation.cpp" "smatrix_geometry_scan.cpp" "smatrix_guided_navigator.cpp" "smatrix_helix_trajectory.cpp" "smatrix_intersection_kernel.cpp" - "smatrix_mask_store.cpp" "smatrix_materials.cpp" "smatrix_navigator.cpp" + "smatrix_line_stepper.cpp" "smatrix_mask_store.cpp" "smatrix_materials.cpp" "smatrix_navigator.cpp" "smatrix_particle_gun.cpp" "smatrix_line_intersection.cpp" "smatrix_line.cpp" "smatrix_planar_intersection.cpp" "smatrix_propagator.cpp" "smatrix_rectangle2.cpp" "smatrix_ring2.cpp" "smatrix_single3.cpp" "smatrix_stepper.cpp" "smatrix_surfaces_finder.cpp" diff --git a/tests/unit_tests/smatrix/smatrix_covariance_transport.cpp b/tests/unit_tests/smatrix/smatrix_line_stepper.cpp similarity index 81% rename from tests/unit_tests/smatrix/smatrix_covariance_transport.cpp rename to tests/unit_tests/smatrix/smatrix_line_stepper.cpp index 6ee31244a..ca05895f4 100644 --- a/tests/unit_tests/smatrix/smatrix_covariance_transport.cpp +++ b/tests/unit_tests/smatrix/smatrix_line_stepper.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/smatrix_definitions.hpp" -#include "tests/common/covariance_transport.inl" +#include "tests/common/line_stepper.inl" diff --git a/tests/unit_tests/smatrix/smatrix_path_correction.cpp b/tests/unit_tests/smatrix/smatrix_path_correction.cpp new file mode 100644 index 000000000..fe2905e40 --- /dev/null +++ b/tests/unit_tests/smatrix/smatrix_path_correction.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/smatrix_definitions.hpp" +#include "tests/common/path_correction.inl" diff --git a/tests/unit_tests/vc/CMakeLists.txt b/tests/unit_tests/vc/CMakeLists.txt index 27824df7b..07a5bc13d 100644 --- a/tests/unit_tests/vc/CMakeLists.txt +++ b/tests/unit_tests/vc/CMakeLists.txt @@ -9,12 +9,12 @@ detray_add_test( vc_array "vc_array_actor_chain.cpp" "vc_array_annulus2.cpp" "vc_array_container.cpp" "vc_array_coordinate_cartesian2.cpp" "vc_array_coordinate_cartesian3.cpp" "vc_array_coordinate_cylindrical2.cpp" "vc_array_coordinate_cylindrical3.cpp" "vc_array_coordinate_line2.cpp" "vc_array_coordinate_polar2.cpp" - "vc_array_core.cpp" "vc_array_covariance_transport.cpp" "vc_array_cylinder_intersection.cpp" + "vc_array_core.cpp" "vc_array_path_correction.cpp" "vc_array_cylinder_intersection.cpp" "vc_array_cylinder3.cpp" "vc_array_detector.cpp" "vc_array_geometry_volume_graph.cpp" "vc_array_geometry_linking.cpp" "vc_array_geometry_navigation.cpp" "vc_array_geometry_scan.cpp" "vc_array_guided_navigator.cpp" "vc_array_helix_trajectory.cpp" "vc_array_intersection_kernel.cpp" "vc_array_line_intersection.cpp" "vc_array_line.cpp" - "vc_array_mask_store.cpp" "vc_array_materials.cpp" "vc_array_navigator.cpp" + "vc_array_line_stepper.cpp" "vc_array_mask_store.cpp" "vc_array_materials.cpp" "vc_array_navigator.cpp" "vc_array_particle_gun.cpp" "vc_array_planar_intersection.cpp" "vc_array_propagator.cpp" "vc_array_rectangle2.cpp" "vc_array_ring2.cpp" "vc_array_single3.cpp" "vc_array_stepper.cpp" diff --git a/tests/unit_tests/vc/vc_array_covariance_transport.cpp b/tests/unit_tests/vc/vc_array_line_stepper.cpp similarity index 81% rename from tests/unit_tests/vc/vc_array_covariance_transport.cpp rename to tests/unit_tests/vc/vc_array_line_stepper.cpp index 310d1fd30..eeb43ed24 100644 --- a/tests/unit_tests/vc/vc_array_covariance_transport.cpp +++ b/tests/unit_tests/vc/vc_array_line_stepper.cpp @@ -6,4 +6,4 @@ */ #include "detray/plugins/algebra/vc_array_definitions.hpp" -#include "tests/common/covariance_transport.inl" \ No newline at end of file +#include "tests/common/line_stepper.inl" diff --git a/tests/unit_tests/vc/vc_array_path_correction.cpp b/tests/unit_tests/vc/vc_array_path_correction.cpp new file mode 100644 index 000000000..fd89ef298 --- /dev/null +++ b/tests/unit_tests/vc/vc_array_path_correction.cpp @@ -0,0 +1,9 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include "detray/plugins/algebra/vc_array_definitions.hpp" +#include "tests/common/path_correction.inl" \ No newline at end of file From d1083690fd91aa5afa5c21949945fe7cf0b0d0ac Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Fri, 7 Oct 2022 01:45:40 -0700 Subject: [PATCH 46/63] Fix a bug --- tests/common/include/tests/common/path_correction.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/include/tests/common/path_correction.inl b/tests/common/include/tests/common/path_correction.inl index 5b6cf35d7..c0e1b4e0f 100644 --- a/tests/common/include/tests/common/path_correction.inl +++ b/tests/common/include/tests/common/path_correction.inl @@ -79,7 +79,6 @@ using mask_container = typename detector_type::mask_container; using material_container = typename detector_type::material_container; using transform3 = typename detector_type::transform3; using surface_type = typename detector_type::surface_container::value_type; -using edge_type = typename surface_type::edge_type; using mask_link_type = typename surface_type::mask_link; using material_link_type = typename surface_type::material_link; using mag_field_t = constant_magnetic_field<>; @@ -144,7 +143,8 @@ TEST(path_correction, cartesian) { // Add a mask const scalar hx = 100. * unit_constants::mm; const scalar hy = 100. * unit_constants::mm; - masks.template add_value(hx, hy, edge_type{0, dindex_invalid}); + masks.template add_value( + hx, hy, typename surface_type::edge_type{0, dindex_invalid}); // Add a material const material mat = silicon(); From 9e7b64a141f4ba771271d258827217fdd5af6b8b Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Fri, 7 Oct 2022 20:31:37 -0700 Subject: [PATCH 47/63] Add path correction unit test for polar and cylindrical coordinate --- .../propagator/actors/parameter_resetter.hpp | 3 + .../actors/parameter_transporter.hpp | 9 +- .../include/tests/common/path_correction.inl | 278 +++++++++++++++++- 3 files changed, 267 insertions(+), 23 deletions(-) diff --git a/core/include/detray/propagator/actors/parameter_resetter.hpp b/core/include/detray/propagator/actors/parameter_resetter.hpp index f291fb812..bbfe0166b 100644 --- a/core/include/detray/propagator/actors/parameter_resetter.hpp +++ b/core/include/detray/propagator/actors/parameter_resetter.hpp @@ -83,6 +83,9 @@ struct parameter_resetter : actor { // Surface const auto& surface = det->surface_by_index(is->index); + // Set surface link + stepping._bound_params.set_surface_link(is->index); + mask_store.template execute(surface.mask_type(), trf_store, surface, stepping); } diff --git a/core/include/detray/propagator/actors/parameter_transporter.hpp b/core/include/detray/propagator/actors/parameter_transporter.hpp index 89c9f20b6..c035dad90 100644 --- a/core/include/detray/propagator/actors/parameter_transporter.hpp +++ b/core/include/detray/propagator/actors/parameter_transporter.hpp @@ -70,13 +70,13 @@ struct parameter_transporter : actor { const auto& transform_store = det->transform_store(); // Intersection - const auto& is = navigation.current(); + // const auto& is = navigation.current(); // Transform const auto& trf3 = transform_store[surface.transform()]; // Mask - const auto& mask = mask_group[is->mask_index]; + const auto& mask = mask_group[surface.mask_range()]; auto local_coordinate = mask.local(); // Free vector @@ -139,9 +139,7 @@ struct parameter_transporter : actor { template DETRAY_HOST_DEVICE void operator()(state& /*actor_state*/, propagator_state_t& propagation) const { - auto& navigation = propagation._navigation; - auto& stepping = propagation._stepping; // Do covariance transport when the track is on surface if (navigation.is_on_module()) { @@ -155,9 +153,6 @@ struct parameter_transporter : actor { // Surface const auto& surface = det->surface_by_index(is->index); - // Set surface link - stepping._bound_params.set_surface_link(is->index); - mask_store.template execute(surface.mask_type(), surface, propagation); } diff --git a/tests/common/include/tests/common/path_correction.inl b/tests/common/include/tests/common/path_correction.inl index c0e1b4e0f..8676b074d 100644 --- a/tests/common/include/tests/common/path_correction.inl +++ b/tests/common/include/tests/common/path_correction.inl @@ -59,7 +59,7 @@ struct surface_targeter : actor { navigation.set_next(candidates.begin()); navigation.set_unknown(); - if (residual < std::abs(1e-5)) { + if (residual < std::abs(1e-6)) { prop_state._heartbeat = false; candidates.push_back({}); navigation.next()++; @@ -158,7 +158,6 @@ TEST(path_correction, cartesian) { // Generate track starting point vector2 local{2, 3}; vector3 mom{1 * unit_constants::MeV, 0., 0.}; - vector3 dir = vector::normalize(mom); scalar time = 0.; scalar q = -1.; @@ -206,35 +205,282 @@ TEST(path_correction, cartesian) { // Decrease tolerance down to 1e-8 crk_state._tolerance = env::rk_tolerance; + // Run propagator + p.propagate(propagation); + + EXPECT_NEAR(crk_state.path_length(), targeter._path, env::epsilon); + + // Bound state after one turn propagation + const auto bound_param1 = crk_state._bound_params; + const auto bound_vec0 = bound_param0.vector(); + const auto bound_vec1 = bound_param1.vector(); + const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); + + // Check if the bound state stays the same after one turn propagation + + // vector + for (std::size_t i = 0; i < e_bound_size; i++) { + EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), + matrix_operator().element(bound_vec1, i, 0), env::epsilon); + } + + // covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), + crk_state.path_length() * env::epsilon); + } + } +} + +TEST(path_correction, polar) { + + // Create a detector + detector_type det(env::resource); + + // Mask and material ID + constexpr registry_type::mask_ids mask_id = + registry_type::mask_ids::e_ring2; + constexpr registry_type::material_ids material_id = + registry_type::material_ids::e_slab; + + // Add a volume + det.new_volume({0., 0., 0., 0., -M_PI, M_PI}); + + typename detector_type::surface_container surfaces(&env::resource); + typename detector_type::transform_container transforms(env::resource); + typename detector_type::mask_container masks(env::resource); + typename detector_type::material_container materials(env::resource); + + // Add a surface + const auto trf_index = transforms.size(env::ctx); + mask_link_type mask_link{mask_id, masks.template size()}; + material_link_type material_link{material_id, + materials.template size()}; + surfaces.emplace_back(trf_index, mask_link, material_link, 0, + dindex_invalid, false); + + // Add a transform + const vector3 t{0, 0, 0}; + const vector3 z{1, 0, 0}; + const vector3 x{0, 1, 0}; + transforms.emplace_back(env::ctx, t, z, x); + + // Add a mask + const scalar r_low = 0. * unit_constants::mm; + const scalar r_high = 100. * unit_constants::mm; + masks.template add_value( + r_low, r_high, typename surface_type::edge_type{0, dindex_invalid}); + + // Add a material + const material mat = silicon(); + const scalar thickness = 2 * unit_constants::mm; + materials.template add_value(mat, thickness); + + typename detector_type::volume_type &vol = det.volume_by_index(0); + det.add_objects_per_volume(env::ctx, vol, surfaces, masks, materials, + transforms); + + // Generate track starting point + vector2 local{2, M_PI / 6.}; + vector3 mom{1 * unit_constants::MeV, 0., 0.}; + + scalar time = 0.; + scalar q = -1.; + + // bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = local[0]; + getter::element(bound_vector, e_bound_loc1, 0) = local[1]; + getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); + getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); + getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); + getter::element(bound_vector, e_bound_time, 0) = time; + + // bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; + getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; + // Note: Set theta error as ZERO, to constrain the loc1 divergence + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; + getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + + // bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + // Path length per turn + scalar S = 2. * getter::perp(mom) / getter::norm(env::B) * M_PI; + + // Actors + surface_targeter::state targeter{S, 0}; + parameter_transporter::state bound_updater{}; + parameter_resetter::state rst{}; + + actor_chain_t::state actor_states = std::tie(targeter, bound_updater, rst); + + propagator_t p({}, {}); + propagator_t::state propagation(bound_param0, env::mag_field, det, + actor_states); + + crk_stepper_t::state &crk_state = propagation._stepping; + // RK stepper and its state EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); - EXPECT_FLOAT_EQ(crk_state().pos()[1], local[0]); // y - EXPECT_FLOAT_EQ(crk_state().pos()[2], local[1]); // z - EXPECT_NEAR(crk_state().dir()[0], dir[0], env::epsilon); - EXPECT_NEAR(crk_state().dir()[1], dir[1], env::epsilon); - EXPECT_NEAR(crk_state().dir()[2], dir[2], env::epsilon); + EXPECT_FLOAT_EQ(crk_state().pos()[1], 2 * std::cos(M_PI / 6.)); + EXPECT_FLOAT_EQ(crk_state().pos()[2], 2 * std::sin(M_PI / 6.)); - // helix trajectory - detail::helix helix(crk_state(), &env::B); + // Decrease tolerance down to 1e-8 + crk_state._tolerance = env::rk_tolerance; // Run propagator p.propagate(propagation); + EXPECT_NEAR(crk_state.path_length(), targeter._path, env::epsilon); + + // Bound state after one turn propagation + const auto bound_param1 = crk_state._bound_params; + const auto bound_vec0 = bound_param0.vector(); + const auto bound_vec1 = bound_param1.vector(); + const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); + + // Check if the bound state stays the same after one turn propagation + + // vector + for (std::size_t i = 0; i < e_bound_size; i++) { + EXPECT_NEAR(matrix_operator().element(bound_vec0, i, 0), + matrix_operator().element(bound_vec1, i, 0), env::epsilon); + } + + // covaraince + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), + matrix_operator().element(bound_cov1, i, j), + crk_state.path_length() * env::epsilon); + } + } +} + +TEST(path_correction, cylindrical) { + + // Create a detector + detector_type det(env::resource); + + // Mask and material ID + constexpr registry_type::mask_ids mask_id = + registry_type::mask_ids::e_cylinder3; + constexpr registry_type::material_ids material_id = + registry_type::material_ids::e_slab; + + // Add a volume + det.new_volume({0., 0., 0., 0., -M_PI, M_PI}); + + typename detector_type::surface_container surfaces(&env::resource); + typename detector_type::transform_container transforms(env::resource); + typename detector_type::mask_container masks(env::resource); + typename detector_type::material_container materials(env::resource); + + // Add a surface + const auto trf_index = transforms.size(env::ctx); + mask_link_type mask_link{mask_id, masks.template size()}; + material_link_type material_link{material_id, + materials.template size()}; + surfaces.emplace_back(trf_index, mask_link, material_link, 0, + dindex_invalid, false); + + // Add a transform + const vector3 t{-50 * unit_constants::mm, 0, 0}; + const vector3 z{0, 0, 1}; + const vector3 x{1, 0, 0}; + transforms.emplace_back(env::ctx, t, z, x); + + // Add a mask + const scalar r = 50 * unit_constants::mm; + const scalar half_length_1 = 1000. * unit_constants::mm; + const scalar half_length_2 = 1000. * unit_constants::mm; + masks.template add_value( + r, half_length_1, half_length_2, + typename surface_type::edge_type{0, dindex_invalid}); + + // Add a material + const material mat = silicon(); + const scalar thickness = 2 * unit_constants::mm; + materials.template add_value(mat, thickness); + + typename detector_type::volume_type &vol = det.volume_by_index(0); + det.add_objects_per_volume(env::ctx, vol, surfaces, masks, materials, + transforms); + + // Generate track starting point + vector2 local{0., 0.}; + vector3 mom{1 * unit_constants::MeV, 0., 0.}; + scalar time = 0.; + scalar q = -1.; + + // bound vector + typename bound_track_parameters::vector_type bound_vector; + getter::element(bound_vector, e_bound_loc0, 0) = local[0]; + getter::element(bound_vector, e_bound_loc1, 0) = local[1]; + getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); + getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); + getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); + getter::element(bound_vector, e_bound_time, 0) = time; + + // bound covariance + typename bound_track_parameters::covariance_type bound_cov = + matrix_operator().template zero(); + getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; + getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; + getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; + // Note: Set theta error as ZERO, to constrain the loc1 divergence + getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; + getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; + getter::element(bound_cov, e_bound_time, e_bound_time) = 1.; + + // bound track parameter + const bound_track_parameters bound_param0(0, bound_vector, + bound_cov); + + // Path length per turn + scalar S = 2. * getter::perp(mom) / getter::norm(env::B) * M_PI; + + // Actors + surface_targeter::state targeter{S, 0}; + parameter_transporter::state bound_updater{}; + parameter_resetter::state rst{}; + + actor_chain_t::state actor_states = std::tie(targeter, bound_updater, rst); + + propagator_t p({}, {}); + propagator_t::state propagation(bound_param0, env::mag_field, det, + actor_states); + + crk_stepper_t::state &crk_state = propagation._stepping; + // RK stepper and its state EXPECT_FLOAT_EQ(crk_state().pos()[0], 0); - EXPECT_NEAR(crk_state().pos()[1], local[0], env::epsilon); // y - EXPECT_NEAR(crk_state().pos()[2], local[1], env::epsilon); // z - EXPECT_NEAR(crk_state().dir()[0], dir[0], env::epsilon); - EXPECT_NEAR(crk_state().dir()[1], dir[1], env::epsilon); - EXPECT_NEAR(crk_state().dir()[2], dir[2], env::epsilon); + EXPECT_FLOAT_EQ(crk_state().pos()[1], 0); // y + EXPECT_FLOAT_EQ(crk_state().pos()[2], 0); // z + + // Decrease tolerance down to 1e-8 + crk_state._tolerance = env::rk_tolerance; + + // Run propagator + p.propagate(propagation); + EXPECT_NEAR(crk_state.path_length(), targeter._path, env::epsilon); // Bound state after one turn propagation const auto bound_param1 = crk_state._bound_params; - const auto bound_vec0 = bound_param0.vector(); const auto bound_vec1 = bound_param1.vector(); - const auto bound_cov0 = bound_param0.covariance(); const auto bound_cov1 = bound_param1.covariance(); From 53dd622e764fb73d7125d6d99349c4f55b8ce2cf Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 10 Oct 2022 23:02:30 -0700 Subject: [PATCH 48/63] Remove unused file --- .vscode/settings.json | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f0daa8f9c..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "files.associations": { - "*.sycl": "cpp", - "algorithm": "cpp", - "allocator": "cpp", - "array": "cpp", - "limits": "cpp" - } -} \ No newline at end of file From f9295fedba1b2dae3ee9b069d076602ba6947434 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 10 Oct 2022 23:05:28 -0700 Subject: [PATCH 49/63] Remove leftovers --- core/include/detray/masks/annulus2.hpp | 173 ----------------------- core/include/detray/masks/cylinder3.hpp | 117 --------------- core/include/detray/masks/rectangle2.hpp | 104 -------------- core/include/detray/masks/ring2.hpp | 106 -------------- core/include/detray/masks/single3.hpp | 93 ------------ core/include/detray/masks/trapezoid2.hpp | 113 --------------- 6 files changed, 706 deletions(-) delete mode 100644 core/include/detray/masks/annulus2.hpp delete mode 100644 core/include/detray/masks/cylinder3.hpp delete mode 100644 core/include/detray/masks/rectangle2.hpp delete mode 100644 core/include/detray/masks/ring2.hpp delete mode 100644 core/include/detray/masks/single3.hpp delete mode 100644 core/include/detray/masks/trapezoid2.hpp diff --git a/core/include/detray/masks/annulus2.hpp b/core/include/detray/masks/annulus2.hpp deleted file mode 100644 index cd9b769c4..000000000 --- a/core/include/detray/masks/annulus2.hpp +++ /dev/null @@ -1,173 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "detray/coordinates/cartesian2.hpp" -#include "detray/coordinates/polar2.hpp" -#include "detray/definitions/qualifiers.hpp" -#include "detray/intersection/intersection.hpp" -#include "detray/intersection/plane_intersector.hpp" -#include "detray/masks/mask_base.hpp" - -// System include(s). -#include -#include -#include -#include - -namespace detray { -/** This is a 2-dimensional mask for the annulus geometry that is - * e.g. used for the itk strip endcaps. - * - * @tparam intersector_type is a struct used for intersecting this cylinder - * @tparam local_type is the default local type for this mask - * @tparam links_type is an object where the mask can link to - * @tparam kMaskContext is a unique mask identifier in a certain context - * - * It is defined by the two radii _values[0] and _values[1] in the polar - * coordinate system of and endcap strip module, as well as the two phi - * boundaries, _values[2] and _values[3], that are only easily definable in - * the local strips system (relative to the average Phi along the - * strips r coordinate). Using a conversion between the two coordinate - * systems, these boundaries can be checked with a tolerance in r (t[0] and - * t[1]), as well as phi (t[3] and t[3]). - * Due to the local polar coordinate system of the strips needing a - * different origin from the discs polar one, three additional conversion - * parameters are included (_values[4], values[5], _values[6]). - * Here, the first two are the origin shift in xy, while _values[6] is the - * average Phi angle mentioned above. - * - * @note While the mask_context can change depending on the typed container - * structure the mask_identifier is a const expression that determines the - * mask type once for all. - * - **/ - -template , - template typename intersector_t = plane_intersector, - template typename local_t = polar2, typename links_t = dindex, - template class array_t = darray> -class annulus2 final : public mask_base { - public: - using base_type = - mask_base; - using base_type::base_type; - using mask_values = typename base_type::mask_values; - using links_type = typename base_type::links_type; - using local_type = typename base_type::local_type; - using intersector_type = typename base_type::intersector_type; - using point2 = typename transform3_t::point2; - - /* Default constructor */ - annulus2() - : base_type({0., std::numeric_limits::y(), - -std::numeric_limits::infinity(), - std::numeric_limits::infinity(), 0., 0., 0.}, - {}) {} - - /** Construction from boundary values - * - * @param r_low lower r boundary - * @param r_high upper r boundary - * @param phi_low lower phi boundary - * @param phi_high upper phi boundary - * @param shift_x origin shift loc0 - * @param shift_y origin shift loc1 - * @param avg_phi average phi value - */ - DETRAY_HOST_DEVICE annulus2(scalar r_low, scalar r_high, scalar phi_low, - scalar phi_high, scalar shift_x, scalar shift_y, - scalar avg_phi, links_type links) - : base_type( - {r_low, r_high, phi_low, phi_high, shift_x, shift_y, avg_phi}, - links) {} - - /** Mask operation - * - * @tparam inside_local_t is the local type for checking, needs to be - * specificed - * - * @param p the point to be checked in local polar coord - * @param t is the tolerance in (r, phi) - * - * @return an intersection status e_inside / e_outside - **/ - template - DETRAY_HOST_DEVICE intersection::status is_inside( - const point2 &p, - const scalar t = std::numeric_limits::epsilon()) const { - // The two quantities to check: r^2 in module system, phi in strips - // system - - // In cartesian coordinates go to modules system by shifting origin - if constexpr (std::is_same_v>) { - // Calculate radial coordinate in module system: - scalar x_mod = p[0] - this->_values[4]; - scalar y_mod = p[1] - this->_values[5]; - scalar r_mod2 = x_mod * x_mod + y_mod * y_mod; - - // apply tolerances - scalar minR_tol = this->_values[0] - t; - scalar maxR_tol = this->_values[1] + t; - - if (r_mod2 < minR_tol * minR_tol or r_mod2 > maxR_tol * maxR_tol) - return intersection::status::e_outside; - - scalar phi_strp = getter::phi(p) - this->_values[6]; - // Check phi boundaries, which are well def. in local frame - return (phi_strp >= this->_values[2] - t and - phi_strp <= this->_values[3] + t) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - // polar strip coordinates given - else { - // For a point p in local polar coordinates, rotate by avr phi - scalar phi_strp = p[1] - this->_values[6]; - - // Check phi boundaries, which are well def. in local frame - if (phi_strp < this->_values[2] - t || - phi_strp > this->_values[3] + t) - return intersection::status::e_outside; - - // Now go to module frame to check r boundaries. Use the origin - // shift in polar coordinates for that - point2 shift_xy = {-1 * this->_values[4], -1 * this->_values[5]}; - scalar shift_r = getter::perp(shift_xy); - scalar shift_phi = getter::phi(shift_xy); - - scalar r_mod2 = shift_r * shift_r + p[0] * p[0] + - 2 * shift_r * p[0] * std::cos(phi_strp - shift_phi); - - // Apply tolerances - scalar minR_tol = this->_values[0] - t; - scalar maxR_tol = this->_values[1] + t; - - return (r_mod2 >= minR_tol * minR_tol and - r_mod2 <= maxR_tol * maxR_tol) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - } - - /// Transform to a string for output debugging - DETRAY_HOST - std::string to_string() const { - std::stringstream ss; - ss << "annulus2"; - for (const auto &v : this->_values) { - ss << ", " << v; - } - return ss.str(); - } -}; - -} // namespace detray diff --git a/core/include/detray/masks/cylinder3.hpp b/core/include/detray/masks/cylinder3.hpp deleted file mode 100644 index 66d908ca8..000000000 --- a/core/include/detray/masks/cylinder3.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s) -#include "detray/coordinates/cylindrical2.hpp" -#include "detray/definitions/qualifiers.hpp" -#include "detray/intersection/cylinder_intersector.hpp" -#include "detray/intersection/intersection.hpp" -#include "detray/masks/mask_base.hpp" - -// System include(s) -#include -#include -#include -#include - -namespace detray { -/** This is a simple mask for a full cylinder - * - * @tparam kRadialCheck is a boolean to steer wheter the radius compatibility - *needs to be checked - * @tparam intersector_t is a struct used for intersecting this cylinder - * @tparam links_type is an object where the mask can link to - * @tparam kMaskContext is a unique mask identifier in a certain context - * - * It is defined by r and the half length. - * - * @note While the mask_context can change depending on the typed container - * structure the mask_identifier is a const expression that determines the - * mask type once for all. - * - **/ -template , - template typename intersector_t = cylinder_intersector, - template typename local_t = cylindrical2, - typename links_t = dindex, bool kRadialCheck = false, - template class array_t = darray> -class cylinder3 final : public mask_base { - public: - using base_type = - mask_base; - using base_type::base_type; - using mask_values = typename base_type::mask_values; - using links_type = typename base_type::links_type; - using local_type = typename base_type::local_type; - using intersector_type = typename base_type::intersector_type; - using point3 = typename transform3_t::point3; - - /* Default constructor */ - cylinder3() - : base_type({std::numeric_limits::infinity(), - -std::numeric_limits::infinity(), - std::numeric_limits::infinity()}, - {}) {} - - /** Construction from boundary values - * - * @param r radius - * @param half_length_1 half_length - * @param half_length_2 half length - */ - DETRAY_HOST_DEVICE - cylinder3(scalar r, scalar half_length_1, scalar half_length_2, - links_type links) - : base_type({r, half_length_1, half_length_2}, links) {} - - /// Get radius - DETRAY_HOST_DEVICE - scalar radius() const { return this->operator[](0); } - - /** Mask operation - * - * @tparam inside_local_type::point3 is the deduced type of the point to be - *checked w.r.t. to the mask bounds, it's assumed to be within the cylinder - *3D frame - * - * @param p the point to be checked - * @param t is the tolerance tuple in (radius, z) - * - * @return an intersection status e_inside / e_outside - **/ - template - DETRAY_HOST_DEVICE intersection::status is_inside( - const point3 &p, - const scalar t = std::numeric_limits::epsilon()) const { - if constexpr (is_rad_check) { - scalar r = getter::perp(p); - if (std::abs(r - this->_values[0]) >= - t + 5 * std::numeric_limits::epsilon()) { - return intersection::status::e_missed; - } - } - return (this->_values[1] - t <= p[2] and p[2] <= this->_values[2] + t) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - - /** Transform to a string for output debugging */ - DETRAY_HOST - std::string to_string() const { - std::stringstream ss; - ss << "cylinder3"; - for (const auto &v : this->_values) { - ss << ", " << v; - } - return ss.str(); - } -}; - -} // namespace detray diff --git a/core/include/detray/masks/rectangle2.hpp b/core/include/detray/masks/rectangle2.hpp deleted file mode 100644 index 77cea0866..000000000 --- a/core/include/detray/masks/rectangle2.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "detray/coordinates/cartesian2.hpp" -#include "detray/definitions/qualifiers.hpp" -#include "detray/intersection/intersection.hpp" -#include "detray/intersection/plane_intersector.hpp" -#include "detray/masks/mask_base.hpp" - -// System include(s). -#include -#include -#include -#include - -namespace detray { - -/** This is a simple 2-dimensional mask for a regular rectangle - * - * @tparam intersector_t is a struct used for intersecting this cylinder - * @tparam local_type is the default local frame definition type - * @tparam links_type is an object where the mask can link to - * @tparam kMaskContext is a unique mask identifier in a certain context - * - * It is defined by half length in local0 coordinates _values[0] and _values[1], - * and can be checked with a tolerance in t[0] and t[1]. - * - * @note While the mask_context can change depending on the typed container - * structure the mask_identifier is a const expression that determines the - * mask type once for all. - * - **/ - -template , - template typename intersector_t = plane_intersector, - template typename local_t = cartesian2, - typename links_t = dindex, - template class array_t = darray> -class rectangle2 final : public mask_base { - public: - using base_type = - mask_base; - using base_type::base_type; - using mask_values = typename base_type::mask_values; - using links_type = typename base_type::links_type; - using local_type = typename base_type::local_type; - using intersector_type = typename base_type::intersector_type; - using point2 = typename transform3_t::point2; - - /* Default constructor */ - rectangle2() - : base_type({std::numeric_limits::infinity(), - std::numeric_limits::infinity()}, - {}) {} - - /** Construction from boundary values - * - * @param half_length_0 half length in loc0 - * @param half_length_1 half length in loc1 - */ - DETRAY_HOST_DEVICE - rectangle2(scalar half_length_0, scalar half_length_1, links_type links) - : base_type({half_length_0, half_length_1}, links) {} - - /** Mask operation - * - * @tparam inside_local_t is the local type for inside checking - * - * @param p the point to be checked - * @param t is the tolerance tuple in (l0, l1) - * - * @return an intersection status e_inside / e_outside - **/ - template - DETRAY_HOST_DEVICE intersection::status is_inside( - const point2 &p, - const scalar t = std::numeric_limits::epsilon()) const { - return (std::abs(p[0]) <= this->_values[0] + t and - std::abs(p[1]) <= this->_values[1] + t) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - - /** Transform to a string for output debugging */ - DETRAY_HOST - std::string to_string() const { - std::stringstream ss; - ss << "rectangle2"; - for (const auto &v : this->_values) { - ss << ", " << v; - } - return ss.str(); - } -}; - -} // namespace detray diff --git a/core/include/detray/masks/ring2.hpp b/core/include/detray/masks/ring2.hpp deleted file mode 100644 index b253fbcda..000000000 --- a/core/include/detray/masks/ring2.hpp +++ /dev/null @@ -1,106 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s) -#include "detray/coordinates/cartesian2.hpp" -#include "detray/definitions/qualifiers.hpp" -#include "detray/intersection/intersection.hpp" -#include "detray/intersection/plane_intersector.hpp" -#include "detray/masks/mask_base.hpp" - -// System include(s) -#include -#include -#include -#include - -namespace detray { -/** This is a simple 2-dimensional mask for a closed ring - * - * @tparam intersector_t is a struct used for intersecting this cylinder - * @tparam local_type is the default local frame type - * @tparam links_type is an object where the mask can link to - * @tparam kMaskContext is a unique mask identifier in a certain context - * - * It is defined by the two radii _values[0] and _values[1], - * and can be checked with a tolerance in t[0] and t[1]. - * - * @note While the mask_context can change depending on the typed container - * structure the mask_identifier is a const expression that determines the - * mask type once for all. - * - **/ -template , - template typename intersector_t = plane_intersector, - template typename local_t = cartesian2, - typename links_t = dindex, - template class array_t = darray> -class ring2 final : public mask_base { - public: - using base_type = - mask_base; - using base_type::base_type; - using mask_values = typename base_type::mask_values; - using links_type = typename base_type::links_type; - using local_type = typename base_type::local_type; - using intersector_type = typename base_type::intersector_type; - using point2 = typename transform3_t::point2; - - /* Default constructor */ - ring2() : base_type({0., std::numeric_limits::infinity()}, {}) {} - - /** Construction from boundary values - * - * @param r_low lower radial bound - * @param r_high upper radial bound - */ - DETRAY_HOST_DEVICE - ring2(scalar r_low, scalar r_high, links_type links) - : base_type({r_low, r_high}, links) {} - - /** Mask operation - * - * @tparam inside_local_t is the local type for inside checking - * - * @param p the point to be checked - * @param t is the tolerance in r - * - * @return an intersection status e_inside / e_outside - **/ - template - DETRAY_HOST_DEVICE intersection::status is_inside( - const point2 &p, - const scalar t = std::numeric_limits::epsilon()) const { - if constexpr (std::is_same_v>) { - scalar r = getter::perp(p); - return (r + t >= this->_values[0] and r <= this->_values[1] + t) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - - return (p[0] + t >= this->_values[0] and p[0] <= this->_values[1] + t) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - - /** Transform to a string for output debugging */ - DETRAY_HOST - std::string to_string() const { - std::stringstream ss; - ss << "ring2"; - for (const auto &v : this->_values) { - ss << ", " << v; - } - return ss.str(); - } -}; - -} // namespace detray diff --git a/core/include/detray/masks/single3.hpp b/core/include/detray/masks/single3.hpp deleted file mode 100644 index a47e3fec1..000000000 --- a/core/include/detray/masks/single3.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s) -#include "detray/coordinates/cartesian2.hpp" -#include "detray/definitions/qualifiers.hpp" -#include "detray/intersection/intersection.hpp" -#include "detray/intersection/plane_intersector.hpp" -#include "detray/masks/mask_base.hpp" - -// System include(s) -#include -#include -#include -#include - -namespace detray { -/** This is a simple mask for single parameter bound mask - * - * @tparam kCheckIndex is the index of the position on which the mask is applied - * @tparam intersector_t is a struct used for intersecting this cylinder - * @tparam local_type is the default local frame definition type - * @tparam links_type is an object where the mask can link to - * @tparam kMaskContext is a unique mask identifier in a certain context - * - * @note While the mask_context can change depending on the typed container - * structure the mask_identifier is a const expression that determines the - * mask type once for all. - * - **/ -template , - template typename intersector_t = plane_intersector, - template typename local_t = cartesian2, - typename links_t = dindex, - template class array_t = darray> -class single3 final : public mask_base { - public: - using base_type = - mask_base; - using base_type::base_type; - using mask_values = typename base_type::mask_values; - using links_type = typename base_type::links_type; - using local_type = typename base_type::local_type; - using intersector_type = typename base_type::intersector_type; - using point3 = typename transform3_t::point3; - - /* Default constructor */ - single3() : base_type({std::numeric_limits::infinity()}, {}) {} - - /** Construction from boundary values **/ - DETRAY_HOST_DEVICE - single3(scalar x, scalar y, links_type links) : base_type({x, y}, links) {} - - /** Mask operation - * - * @tparam inside_local_type is the global type for checking (ignored) - * - * @param p the point to be checked - * @param t is the tolerance of the single parameter - * - * @return an intersection status e_inside / e_outside - **/ - template - DETRAY_HOST_DEVICE intersection::status is_inside( - const point3 &p, - const scalar t = std::numeric_limits::epsilon()) const { - return (this->_values[0] - t <= p[kCheckIndex] and - p[kCheckIndex] <= this->_values[1] + t) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - - /** Transform to a string for output debugging */ - DETRAY_HOST - std::string to_string() const { - std::stringstream ss; - ss << "single3"; - for (const auto &v : this->_values) { - ss << ", " << v; - } - return ss.str(); - } -}; - -} // namespace detray diff --git a/core/include/detray/masks/trapezoid2.hpp b/core/include/detray/masks/trapezoid2.hpp deleted file mode 100644 index 2fd742464..000000000 --- a/core/include/detray/masks/trapezoid2.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s) -#include "detray/coordinates/cartesian2.hpp" -#include "detray/definitions/qualifiers.hpp" -#include "detray/intersection/intersection.hpp" -#include "detray/intersection/plane_intersector.hpp" -#include "detray/masks/mask_base.hpp" - -// System include(s) -#include -#include -#include -#include - -namespace detray { -/** This is a simple 2-dimensional mask for a regular trapezoid - * - * @tparam intersector_t is a struct used for intersecting this cylinder - * @tparam local_type is the default local frame definition type - * @tparam links_type is an object where the mask can link to - * @tparam kMaskContext is a unique mask identifier in a certain context - * - * It is defined by half lengths in local0 coordinate _values[0] and _values[1] - * at -/+ half length in the local1 coordinate _values[2]. _values[3] contains - * the precomputed value of 1 / (2 * _values[2]), which avoids - * excessive floating point divisions. - * - * @note While the mask_context can change depending on the typed container - * structure the mask_identifier is a const expression that determines the - * mask type once for all. - * - **/ -template , - template typename intersector_t = plane_intersector, - template typename local_t = cartesian2, - typename links_t = dindex, - template class array_t = darray> -class trapezoid2 final : public mask_base { - public: - using base_type = - mask_base; - using base_type::base_type; - using mask_values = typename base_type::mask_values; - using links_type = typename base_type::links_type; - using local_type = typename base_type::local_type; - using intersector_type = typename base_type::intersector_type; - using point2 = typename transform3_t::point2; - - /* Default constructor */ - trapezoid2() - : base_type({std::numeric_limits::infinity(), - std::numeric_limits::infinity(), - std::numeric_limits::infinity(), - std::numeric_limits::infinity()}, - {}) {} - - /** Construction from boundary values - * - * @param half_length_0 first half length in loc0 - * @param half_length_1 second half length in loc0 - * @param half_length_2 half length in loc1 - */ - DETRAY_HOST_DEVICE - trapezoid2(scalar half_length_0, scalar half_length_1, scalar half_length_2, - links_type links) - : base_type({half_length_0, half_length_1, half_length_2, - static_cast(1. / (2. * half_length_2))}, - links) {} - - /** Mask operation - * - * @tparam inside_local_t is the type of the local frame (ignored here) - * - * @param p the point to be checked - * @param t us the tolerance tuple (l0,l1) - * - * @return an intersection status e_inside / e_outside - **/ - template - DETRAY_HOST_DEVICE intersection::status is_inside( - const point2 &p, - const scalar t = std::numeric_limits::epsilon()) const { - scalar rel_y = (this->_values[2] + p[1]) * this->_values[3]; - return (std::abs(p[0]) <= - this->_values[0] + - rel_y * (this->_values[1] - this->_values[0]) + t and - std::abs(p[1]) <= this->_values[2] + t) - ? intersection::status::e_inside - : intersection::status::e_outside; - } - - /** Transform to a string for output debugging */ - DETRAY_HOST - std::string to_string() const { - std::stringstream ss; - ss << "trapezoid2"; - for (const auto &v : this->_values) { - ss << ", " << v; - } - return ss.str(); - } -}; - -} // namespace detray From 38a36fbd62fff530dab19345168727a9bc4ea3e1 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 10 Oct 2022 23:09:50 -0700 Subject: [PATCH 50/63] Remove leftover --- .../include/tests/common/coordinates.inl | 328 ------------------ 1 file changed, 328 deletions(-) delete mode 100644 tests/common/include/tests/common/coordinates.inl diff --git a/tests/common/include/tests/common/coordinates.inl b/tests/common/include/tests/common/coordinates.inl deleted file mode 100644 index ca8e91d37..000000000 --- a/tests/common/include/tests/common/coordinates.inl +++ /dev/null @@ -1,328 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -// Project include(s). -#include "detray/coordinates/coordinates.hpp" -#include "detray/tracks/tracks.hpp" - -// GTest include(s). -#include - -using namespace detray; -using point2 = __plugin::point2; -using point3 = __plugin::point3; -using vector3 = __plugin::vector3; -using transform3 = __plugin::transform3; -using matrix_operator = typename transform3::matrix_actor; - -const scalar isclose = 1e-5; - -// This test cartesian2 coordinate -TEST(test_host_basics, cartesian2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cartesian2 c2; - const point3 global1 = {4., 7., 4.}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = c2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], 2., isclose); - ASSERT_NEAR(local[1], 4., isclose); - - // Local to global transformation - const point3 global2 = c2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = c2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = c2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), 2., isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), 4., isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, - isclose); // atan(2) - ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, - isclose); // atan(sqrt(5)/3) - ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} - -// This test cartesian3 coordinate -TEST(test_host_basics, cartesian3) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cartesian3 c3; - const point3 global1 = {4., 7., 5.}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - struct dummy_mask { - } mask; - - // Global to local transformation - const point3 local = c3.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], 2., isclose); - ASSERT_NEAR(local[1], 4., isclose); - ASSERT_NEAR(local[2], 1., isclose); - - // Local to global transformation - const point3 global2 = c3.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); -} - -// This test polar2 coordinate -TEST(test_host_basics, polar2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const polar2 p2; - const point3 global1 = {4., 7., 4.}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = p2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], std::sqrt(20.), isclose); - ASSERT_NEAR(local[1], atan2(4., 2.), isclose); - - // Local to global transformation - const point3 global2 = p2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = p2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = p2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), std::sqrt(20.), isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), atan2(4., 2.), isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, - isclose); // atan(2) - ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, - isclose); // atan(sqrt(5)/3) - ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} - -// This test cylindrical2 coordinate -TEST(test_host_basics, cylindrical2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cylindrical2 c2; - // Global position on surface - const point3 global1 = {scalar{3.4142136}, scalar{4.4142136}, scalar{9.}}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - - // Define cylinder mask - struct cylinder_mask { - scalar r = 0.; - scalar operator[](dindex) const { return r; } - }; - - const scalar r = 2.; - const cylinder_mask mask{r}; - - // Global to local transformation - const point2 local = c2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], r * scalar{M_PI_4}, isclose); - ASSERT_NEAR(local[1], 5., isclose); - - // Local to global transformation - const point3 global2 = c2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = c2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = c2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), r * scalar{M_PI_4}, isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), 5, isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), 1.1071487, - isclose); // atan(2) - ASSERT_NEAR(m.element(bound_vec, 3, 0), 0.64052231, - isclose); // atan(sqrt(5)/3) - ASSERT_NEAR(m.element(bound_vec, 4, 0), -1 / 3.7416574, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} - -// This test cylindrical2 coordinate -TEST(test_host_basics, cylindrical3) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const cylindrical3 c3; - const point3 global1 = {scalar{3.4142136}, scalar{4.4142136}, scalar{9.}}; - const vector3 mom = {1., 2., 3.}; - const vector3 d = vector::normalize(mom); - struct dummy_mask { - } mask; - - // Global to local transformation - const point3 local = c3.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], 2, isclose); - ASSERT_NEAR(local[1], M_PI_4, isclose); - ASSERT_NEAR(local[2], 5., isclose); - - // Local to global transformation - const point3 global2 = c3.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); -} - -// This test line2 coordinate -TEST(test_host_basics, line2) { - - // Preparation work - const vector3 z = {0., 0., 1.}; - const vector3 x = {1., 0., 0.}; - const point3 t = {2., 3., 4.}; - const transform3 trf(t, z, x); - const line2 l2; - const point3 global1 = {3., 3., 9.}; - const vector3 mom = {0., 2., 0.}; - const vector3 d = vector::normalize(mom); - const scalar time = 0.1; - const scalar charge = -1.; - struct dummy_mask { - } mask; - - // Global to local transformation - const point2 local = l2.global_to_local(trf, global1, d); - - // Check if the local position is correct - ASSERT_NEAR(local[0], -1., isclose); - ASSERT_NEAR(local[1], 5., isclose); - - // Local to global transformation - const point3 global2 = l2.local_to_global(trf, mask, local, d); - - // Check if the same global position is obtained - ASSERT_NEAR(global1[0], global2[0], isclose); - ASSERT_NEAR(global1[1], global2[1], isclose); - ASSERT_NEAR(global1[2], global2[2], isclose); - - // Free track parameter - const free_track_parameters free_params(global1, time, mom, - charge); - const auto free_vec1 = free_params.vector(); - - const auto bound_vec = l2.free_to_bound_vector(trf, free_vec1); - const auto free_vec2 = l2.bound_to_free_vector(trf, mask, bound_vec); - - const matrix_operator m; - - // Check if the bound vector is correct - ASSERT_NEAR(m.element(bound_vec, 0, 0), -1., isclose); - ASSERT_NEAR(m.element(bound_vec, 1, 0), 5, isclose); - ASSERT_NEAR(m.element(bound_vec, 2, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 3, 0), M_PI_2, isclose); - ASSERT_NEAR(m.element(bound_vec, 4, 0), -0.5, isclose); - ASSERT_NEAR(m.element(bound_vec, 5, 0), 0.1, isclose); - - // Check if the same free vector is obtained - for (int i = 0; i < 8; i++) { - ASSERT_NEAR(m.element(free_vec1, i, 0), m.element(free_vec2, i, 0), - isclose); - } -} \ No newline at end of file From 1a6c847248edefef057c03b8a2712a9657fa8cb1 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Mon, 10 Oct 2022 23:53:30 -0700 Subject: [PATCH 51/63] Remove left over --- .../tests/common/material_interaction.inl | 450 ------------------ 1 file changed, 450 deletions(-) delete mode 100644 tests/common/include/tests/common/material_interaction.inl diff --git a/tests/common/include/tests/common/material_interaction.inl b/tests/common/include/tests/common/material_interaction.inl deleted file mode 100644 index 3756f19fb..000000000 --- a/tests/common/include/tests/common/material_interaction.inl +++ /dev/null @@ -1,450 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -// Project include(s). -#include "detray/definitions/pdg_particle.hpp" -#include "detray/definitions/units.hpp" -#include "detray/field/constant_magnetic_field.hpp" -#include "detray/materials/interaction.hpp" -#include "detray/materials/material.hpp" -#include "detray/materials/material_slab.hpp" -#include "detray/materials/predefined_materials.hpp" -#include "detray/propagator/actor_chain.hpp" -#include "detray/propagator/actors/aborters.hpp" -#include "detray/propagator/actors/parameter_resetter.hpp" -#include "detray/propagator/actors/parameter_transporter.hpp" -#include "detray/propagator/actors/pointwise_material_interactor.hpp" -#include "detray/propagator/actors/scattering_simulator.hpp" -#include "detray/propagator/navigator.hpp" -#include "detray/propagator/propagator.hpp" -#include "detray/propagator/rk_stepper.hpp" -#include "tests/common/tools/create_telescope_detector.hpp" -#include "tests/common/tools/inspectors.hpp" - -// VecMem include(s). -#include - -// GTest include(s). -#include - -using namespace detray; - -using transform3 = __plugin::transform3; -using matrix_operator = typename transform3::matrix_actor; - -// Test class for MUON energy loss with Bethe function -// Input tuple: < material / energy / expected output from -// https://pdg.lbl.gov/2022/AtomicNuclearProperties for Muon dEdX and range > -class EnergyLossBetheValidation - : public ::testing::TestWithParam< - std::tuple, scalar, scalar>> {}; - -// This tests the material functionalities -TEST_P(EnergyLossBetheValidation, bethe_energy_loss) { - - // Interaction object - interaction I; - - // intersection with a zero incidence angle - line_plane_intersection is; - - // H2 liquid with a unit thickness - material_slab slab(std::get<0>(GetParam()), 1 * unit_constants::cm); - - // muon - const int pdg = pdg_particle::eMuon; - - // mass - const scalar m = 105.7 * unit_constants::MeV; - - // qOverP - const scalar qOverP = -1. / std::get<1>(GetParam()); - - // Bethe Stopping power in MeV * cm^2 / g - const scalar dEdx = - I.compute_energy_loss_bethe(is, slab, pdg, m, qOverP, -1.) / - slab.path_segment(is) / slab.get_material().mass_density() / - (unit_constants::MeV * unit_constants::cm2 / unit_constants::g); - - // Check if difference is within 5% error - EXPECT_TRUE(std::abs(std::get<2>(GetParam()) - dEdx) / dEdx < 0.05); -} - -INSTANTIATE_TEST_SUITE_P( - Bethe_0p1GeV_H2Liquid, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(hydrogen_liquid(), - 0.1003 * unit_constants::GeV, 6.539))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_1GeV_H2Liquid, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(hydrogen_liquid(), - 1.101 * unit_constants::GeV, 4.182))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_10GeV_H2Liquid, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(hydrogen_liquid(), - 10.11 * unit_constants::GeV, 4.777))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_100GeV_H2Liquid, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(hydrogen_liquid(), - 100.1 * unit_constants::GeV, 5.305))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_0p1GeV_HeGas, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(helium_gas(), - 0.1003 * unit_constants::GeV, 3.082))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_1GeV_HeGas, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(helium_gas(), - 1.101 * unit_constants::GeV, 2.133))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_10GeV_HeGas, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(helium_gas(), - 10.11 * unit_constants::GeV, 2.768))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_100GeV_HeGas, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(helium_gas(), - 100.1 * unit_constants::GeV, 3.188))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_0p1GeV_Al, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(aluminium(), - 0.1003 * unit_constants::GeV, 2.533))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_1GeV_Al, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(aluminium(), - 1.101 * unit_constants::GeV, 1.744))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_10GeV_Al, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(aluminium(), - 10.11 * unit_constants::GeV, 2.097))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_100GeV_Al, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(aluminium(), - 100.1 * unit_constants::GeV, 2.360))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_0p1GeV_Si, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(silicon(), - 0.1003 * unit_constants::GeV, 2.608))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_1GeV_Si, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(silicon(), - 1.101 * unit_constants::GeV, 1.803))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_10GeV_Si, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(silicon(), - 10.11 * unit_constants::GeV, 2.177))); - -INSTANTIATE_TEST_SUITE_P( - Bethe_100GeV_Si, EnergyLossBetheValidation, - ::testing::Values(std::make_tuple(silicon(), - 100.1 * unit_constants::GeV, 2.451))); - -// Test class for MUON energy loss with Landau function -// Input tuple: < material / energy / expected energy loss / expected fwhm > -class EnergyLossLandauValidation - : public ::testing::TestWithParam< - std::tuple, scalar, scalar, scalar>> {}; - -TEST_P(EnergyLossLandauValidation, landau_energy_loss) { - - // Interaction object - interaction I; - - // intersection with a zero incidence angle - line_plane_intersection is; - - // H2 liquid with a unit thickness - material_slab slab(std::get<0>(GetParam()), - 0.17 * unit_constants::cm); - - // muon - const int pdg = pdg_particle::eMuon; - - // mass - const scalar m = 105.7 * unit_constants::MeV; - - // qOverP - const scalar qOverP = -1. / std::get<1>(GetParam()); - - // Landau Energy loss in MeV - const scalar dE = - I.compute_energy_loss_landau(is, slab, pdg, m, qOverP, -1) / - (unit_constants::MeV); - - // Check if difference is within 5% error - EXPECT_TRUE(std::abs(std::get<2>(GetParam()) - dE) / dE < 0.05); - - // Landau Energy loss Fluctuation - const scalar fwhm = - I.compute_energy_loss_landau_fwhm(is, slab, pdg, m, qOverP, -1) / - (unit_constants::MeV); - - // Check if difference is within 10% error - EXPECT_TRUE(std::abs(std::get<3>(GetParam()) - fwhm) / fwhm < 0.1); -} - -// Expected output from Fig 33.7 in RPP2018 -INSTANTIATE_TEST_SUITE_P( - Landau_10GeV_Silicon, EnergyLossLandauValidation, - ::testing::Values(std::make_tuple(silicon(), - 10. * unit_constants::GeV, 0.525, 0.13))); - -// Material interaction test with telescope Geometry -TEST(material_interaction, telescope_geometry_energy_loss) { - - vecmem::host_memory_resource host_mr; - - using ln_stepper_t = line_stepper; - - typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {1, 0, 0}, -1}; - - // Build from given module positions - std::vector positions = {0., 50., 100., 150., 200., 250., - 300., 350, 400, 450., 500.}; - - const auto mat = silicon_tml(); - const scalar thickness = 0.17 * unit_constants::cm; - - const auto det = create_telescope_detector( - host_mr, positions, ln_stepper_t(), - typename ln_stepper_t::state{default_trk}, 20. * unit_constants::mm, - 20. * unit_constants::mm, mat, thickness); - - using navigator_t = navigator; - using constraints_t = constrained_step<>; - using policy_t = stepper_default_policy; - using stepper_t = line_stepper; - using interactor_t = pointwise_material_interactor; - using actor_chain_t = - actor_chain, interactor_t, - parameter_resetter>; - using propagator_t = propagator; - - // Propagator is built from the stepper and navigator - propagator_t p({}, {}); - - const scalar q = -1.; - const scalar iniP = 10 * unit_constants::GeV; - - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = 0.; - getter::element(bound_vector, e_bound_loc1, 0) = 0.; - getter::element(bound_vector, e_bound_phi, 0) = 0.; - getter::element(bound_vector, e_bound_theta, 0) = M_PI / 2.; - getter::element(bound_vector, e_bound_qoverp, 0) = q / iniP; - getter::element(bound_vector, e_bound_time, 0) = 0.; - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template zero(); - - // bound track parameter - const bound_track_parameters bound_param(0, bound_vector, - bound_cov); - - propagation::print_inspector::state print_insp_state{}; - pathlimit_aborter::state aborter_state{}; - parameter_transporter::state bound_updater{}; - interactor_t::state interactor_state{}; - parameter_resetter::state parameter_resetter_state{}; - - // Create actor states tuples - actor_chain_t::state actor_states = - std::tie(print_insp_state, aborter_state, bound_updater, - interactor_state, parameter_resetter_state); - - propagator_t::state state(bound_param, det, actor_states); - - // Propagate the entire detector - ASSERT_TRUE(p.propagate(state)) - << print_insp_state.to_string() << std::endl; - - // muon - const int pdg = interactor_state.pdg; - - // mass - const scalar mass = interactor_state.mass; - - // new momentum - const scalar newP = state._stepping._bound_params.charge() / - state._stepping._bound_params.qop(); - - // new energy - const scalar newE = std::sqrt(newP * newP + mass * mass); - - // Initial energy - const scalar iniE = std::sqrt(iniP * iniP + mass * mass); - - // New qop variance - const scalar new_var_qop = - matrix_operator().element(state._stepping._bound_params.covariance(), - e_bound_qoverp, e_bound_qoverp); - - // Interaction object - interaction I; - - // intersection with a zero incidence angle - line_plane_intersection is; - - // Same material used for default telescope detector - material_slab slab(mat, thickness); - - // Expected Bethe Stopping power for telescope geometry is estimated - // as (number of planes * energy loss per plane assuming 1 GeV muon). - // It is not perfectly precise as the track loses its energy during - // propagation. However, since the energy loss << the track momentum, - // the assumption is not very bad - - // -1 is required because the last surface is a portal - const scalar dE = - I.compute_energy_loss_bethe(is, slab, pdg, mass, q / iniP, q) * - (positions.size() - 1); - - // Check if the new energy after propagation is enough close to the - // expected value - EXPECT_NEAR(newE, iniE - dE, 1e-5); - - const scalar sigma_qop = I.compute_energy_loss_landau_sigma_QOverP( - is, slab, pdg, mass, q / iniP, q); - - const scalar dvar_qop = sigma_qop * sigma_qop * (positions.size() - 1); - - EXPECT_NEAR(new_var_qop, dvar_qop, 1e-10); - - // @todo: Validate the backward direction case as well? -} - -scalar get_variance(const std::vector& v) { - scalar sum = std::accumulate(v.begin(), v.end(), 0.0); - scalar mean = sum / v.size(); - std::vector diff(v.size()); - std::transform(v.begin(), v.end(), diff.begin(), - [mean](double x) { return x - mean; }); - scalar sq_sum = - std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0); - scalar variance = sq_sum / v.size(); - return variance; -} - -// Material interaction test with telescope Geometry -TEST(material_interaction, telescope_geometry_scattering_angle) { - vecmem::host_memory_resource host_mr; - - using ln_stepper_t = line_stepper; - - typename ln_stepper_t::free_track_parameters_type default_trk{ - {0, 0, 0}, 0, {1, 0, 0}, -1}; - - // Build from given module positions - std::vector positions = {0., 1000. * unit_constants::cm}; - - const auto mat = silicon_tml(); - const scalar thickness = 500 * unit_constants::cm; - // Use unbounded surfaces - constexpr bool unbounded = true; - - const auto det = create_telescope_detector( - host_mr, positions, ln_stepper_t(), - typename ln_stepper_t::state{default_trk}, 2000. * unit_constants::mm, - 2000. * unit_constants::mm, mat, thickness); - - using navigator_t = navigator; - using constraints_t = constrained_step<>; - using policy_t = stepper_default_policy; - using stepper_t = line_stepper; - using interactor_t = pointwise_material_interactor; - using simulator_t = scattering_simulator; - using actor_chain_t = - actor_chain, interactor_t, - simulator_t, parameter_resetter>; - using propagator_t = propagator; - - // Propagator is built from the stepper and navigator - propagator_t p({}, {}); - - const scalar q = -1.; - const scalar iniP = 10 * unit_constants::GeV; - - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = 0.; - getter::element(bound_vector, e_bound_loc1, 0) = 0.; - getter::element(bound_vector, e_bound_phi, 0) = 0; - getter::element(bound_vector, e_bound_theta, 0) = M_PI_2; - getter::element(bound_vector, e_bound_qoverp, 0) = q / iniP; - getter::element(bound_vector, e_bound_time, 0) = 0.; - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template zero(); - - // bound track parameter - const bound_track_parameters bound_param(0, bound_vector, - bound_cov); - - int n_samples = 100000; - std::vector phi_vec; - std::vector theta_vec; - - scalar ref_phi_var(0); - scalar ref_theta_var(0); - - for (int i = 0; i < n_samples; i++) { - - propagation::print_inspector::state print_insp_state{}; - pathlimit_aborter::state aborter_state{}; - parameter_transporter::state bound_updater{}; - interactor_t::state interactor_state{}; - interactor_state.do_energy_loss = false; - simulator_t::state simulator_state(interactor_state); - parameter_resetter::state parameter_resetter_state{}; - - // Create actor states tuples - actor_chain_t::state actor_states = std::tie( - print_insp_state, aborter_state, bound_updater, interactor_state, - simulator_state, parameter_resetter_state); - - propagator_t::state state(bound_param, det, actor_states); - - state._stepping().set_overstep_tolerance(-1000. * unit_constants::um); - - // Propagate the entire detector - ASSERT_TRUE(p.propagate(state)) - << print_insp_state.to_string() << std::endl; - - const auto& final_params = state._stepping._bound_params; - - if (i == 0) { - const auto& covariance = final_params.covariance(); - ref_phi_var = - matrix_operator().element(covariance, e_bound_phi, e_bound_phi); - ref_theta_var = matrix_operator().element(covariance, e_bound_theta, - e_bound_theta); - } - - phi_vec.push_back(final_params.phi()); - theta_vec.push_back(final_params.theta()); - } - - scalar phi_var = get_variance(phi_vec); - scalar theta_var = get_variance(theta_vec); - - EXPECT_NEAR((phi_var - ref_phi_var) / ref_phi_var, 0, 0.05); - EXPECT_NEAR((theta_var - ref_theta_var) / ref_theta_var, 0, 0.05); - - // To make sure that the varainces are zero - EXPECT_TRUE(ref_phi_var > 1e-4 && ref_theta_var > 1e-4); -} From 112e9c0cd28dbde80cdb122e5f1892cd2de44274 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 11 Oct 2022 00:19:58 -0700 Subject: [PATCH 52/63] Fix a warning --- core/include/detray/propagator/base_stepper.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index 81a6aae39..aef59f5f1 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -72,14 +72,14 @@ class base_stepper { const detector_t &det) : _bound_params(bound_params) { - const auto &surface_container = det.surfaces(); const auto &trf_store = det.transform_store(); const auto &mask_store = det.mask_store(); const auto &surface = - surface_container[bound_params.surface_link()]; + det.surface_by_index(bound_params.surface_link()); mask_store.template call< - typename parameter_resetter::kernel>( + typename parameter_resetter::kernel, + typename detector_t::masks::link_type>( surface.mask_type(), trf_store, surface, *this); } From bfc3ac72d418a6ca89395baf670d96803cba6f2f Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Tue, 11 Oct 2022 23:39:56 -0700 Subject: [PATCH 53/63] const qualifier --- core/include/detray/propagator/actors/parameter_resetter.hpp | 2 +- core/include/detray/propagator/base_stepper.hpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/include/detray/propagator/actors/parameter_resetter.hpp b/core/include/detray/propagator/actors/parameter_resetter.hpp index d4608ebab..84783f03f 100644 --- a/core/include/detray/propagator/actors/parameter_resetter.hpp +++ b/core/include/detray/propagator/actors/parameter_resetter.hpp @@ -38,7 +38,7 @@ struct parameter_resetter : actor { DETRAY_HOST_DEVICE inline output_type operator()( const mask_group_t& mask_group, const index_t& /*index*/, const transform_store_t& trf_store, const surface_t& surface, - stepper_state_t& stepping) { + stepper_state_t& stepping) const { const auto& trf3 = trf_store[surface.transform()]; diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index aef59f5f1..fb00b58f4 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -78,8 +78,7 @@ class base_stepper { det.surface_by_index(bound_params.surface_link()); mask_store.template call< - typename parameter_resetter::kernel, - typename detector_t::masks::link_type>( + typename parameter_resetter::kernel>( surface.mask_type(), trf_store, surface, *this); } From 6b439f5e986c593fe8f480bdaf31f2cd2b846fe0 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 12 Oct 2022 07:53:09 +0000 Subject: [PATCH 54/63] Fix a warning --- .../include/detray/propagator/actors/parameter_resetter.hpp | 6 +++--- .../detray/propagator/actors/parameter_transporter.hpp | 4 ++-- core/include/detray/propagator/base_stepper.hpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/include/detray/propagator/actors/parameter_resetter.hpp b/core/include/detray/propagator/actors/parameter_resetter.hpp index 84783f03f..e649a1e95 100644 --- a/core/include/detray/propagator/actors/parameter_resetter.hpp +++ b/core/include/detray/propagator/actors/parameter_resetter.hpp @@ -37,7 +37,7 @@ struct parameter_resetter : actor { typename stepper_state_t> DETRAY_HOST_DEVICE inline output_type operator()( const mask_group_t& mask_group, const index_t& /*index*/, - const transform_store_t& trf_store, const surface_t& surface, + transform_store_t& trf_store, surface_t& surface, stepper_state_t& stepping) const { const auto& trf3 = trf_store[surface.transform()]; @@ -75,7 +75,7 @@ struct parameter_resetter : actor { // Do covariance transport when the track is on surface if (navigation.is_on_module()) { - const auto& det = navigation.detector(); + auto det = navigation.detector(); const auto& trf_store = det->transform_store(); const auto& mask_store = det->mask_store(); @@ -88,7 +88,7 @@ struct parameter_resetter : actor { // Set surface link stepping._bound_params.set_surface_link(is->index); - mask_store.template call(surface.mask_type(), trf_store, + mask_store.template call(surface.mask(), trf_store, surface, stepping); } } diff --git a/core/include/detray/propagator/actors/parameter_transporter.hpp b/core/include/detray/propagator/actors/parameter_transporter.hpp index b0f45c47f..b8a136edf 100644 --- a/core/include/detray/propagator/actors/parameter_transporter.hpp +++ b/core/include/detray/propagator/actors/parameter_transporter.hpp @@ -141,7 +141,7 @@ struct parameter_transporter : actor { // Do covariance transport when the track is on surface if (navigation.is_on_module()) { - const auto& det = navigation.detector(); + auto det = navigation.detector(); const auto& mask_store = det->mask_store(); // Intersection @@ -150,7 +150,7 @@ struct parameter_transporter : actor { // Surface const auto& surface = det->surface_by_index(is->index); - mask_store.template call(surface.mask_type(), surface, + mask_store.template call(surface.mask(), surface, propagation); } } diff --git a/core/include/detray/propagator/base_stepper.hpp b/core/include/detray/propagator/base_stepper.hpp index fb00b58f4..4bca31e55 100644 --- a/core/include/detray/propagator/base_stepper.hpp +++ b/core/include/detray/propagator/base_stepper.hpp @@ -79,7 +79,7 @@ class base_stepper { mask_store.template call< typename parameter_resetter::kernel>( - surface.mask_type(), trf_store, surface, *this); + surface.mask(), trf_store, surface, *this); } /// free track parameter From 578d113497a0aacc952662598589896f0785721c Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Wed, 12 Oct 2022 00:58:06 -0700 Subject: [PATCH 55/63] Clang format --- core/include/detray/propagator/actors/parameter_resetter.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/include/detray/propagator/actors/parameter_resetter.hpp b/core/include/detray/propagator/actors/parameter_resetter.hpp index e649a1e95..2c8a30e79 100644 --- a/core/include/detray/propagator/actors/parameter_resetter.hpp +++ b/core/include/detray/propagator/actors/parameter_resetter.hpp @@ -88,8 +88,8 @@ struct parameter_resetter : actor { // Set surface link stepping._bound_params.set_surface_link(is->index); - mask_store.template call(surface.mask(), trf_store, - surface, stepping); + mask_store.template call(surface.mask(), trf_store, surface, + stepping); } } }; From 3e9eaeb7f856b41b1dbb5ef7bd9df4b7566234ab Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 13 Oct 2022 10:48:51 -0700 Subject: [PATCH 56/63] Remove unused tests --- .../include/tests/common/masks_cylinder3.inl | 53 ------------------- .../include/tests/common/masks_ring2.inl | 52 ------------------ 2 files changed, 105 deletions(-) delete mode 100644 tests/common/include/tests/common/masks_cylinder3.inl delete mode 100644 tests/common/include/tests/common/masks_ring2.inl diff --git a/tests/common/include/tests/common/masks_cylinder3.inl b/tests/common/include/tests/common/masks_cylinder3.inl deleted file mode 100644 index 03c0ebb03..000000000 --- a/tests/common/include/tests/common/masks_cylinder3.inl +++ /dev/null @@ -1,53 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#include - -#include "detray/coordinates/cartesian2.hpp" -#include "detray/intersection/cylinder_intersector.hpp" -#include "detray/masks/cylinder3.hpp" - -using namespace detray; -using transform3_type = __plugin::transform3; -using vector3 = __plugin::vector3; -using point3 = __plugin::point3; -using scalar_type = typename transform3_type::scalar_type; -using local_type = cartesian2; - -// This tests the basic function of a rectangle -TEST(mask, cylinder3) { - - scalar_type r = 3.; - scalar_type hz = 4.; - - point3 p3_in = {r, 0., -1.}; - point3 p3_edge = {0., r, hz}; - point3 p3_out = {static_cast(r / std::sqrt(2.)), - static_cast(r / std::sqrt(2.)), 4.5}; - point3 p3_off = {1., 1., -9.}; - - // Test radius to be on surface, too - cylinder3 - c{r, -hz, hz, 0u}; - - ASSERT_EQ(c[0], r); - ASSERT_EQ(c[1], -hz); - ASSERT_EQ(c[2], hz); - - ASSERT_TRUE(c.is_inside(p3_in) == - intersection::status::e_inside); - ASSERT_TRUE(c.is_inside(p3_edge) == - intersection::status::e_inside); - ASSERT_TRUE(c.is_inside(p3_out) == - intersection::status::e_outside); - ASSERT_TRUE(c.is_inside(p3_off) == - intersection::status::e_missed); - // Move outside point inside using a tolerance - ASSERT_TRUE(c.is_inside(p3_out, 0.6) == - intersection::status::e_inside); -} diff --git a/tests/common/include/tests/common/masks_ring2.inl b/tests/common/include/tests/common/masks_ring2.inl deleted file mode 100644 index b65fa8a51..000000000 --- a/tests/common/include/tests/common/masks_ring2.inl +++ /dev/null @@ -1,52 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#include - -#include "detray/coordinates/polar2.hpp" -#include "detray/masks/ring2.hpp" - -using namespace detray; -using point2 = __plugin::point2; -using transform3 = __plugin::transform3; - -// This tests the basic function of a rectangle -TEST(mask, ring2) { - - point2 p2_pl_in = {0.5, -2.}; - point2 p2_pl_edge = {0., 3.5}; - point2 p2_pl_out = {3.6, 5.}; - - point2 p2_c_in = {0.5, -2.}; - point2 p2_c_edge = {0., 3.5}; - point2 p2_c_out = {3.5, 3.5}; - - ring2<> r2{0., 3.5, 0u}; - - ASSERT_EQ(r2[0], 0.); - ASSERT_EQ(r2[1], 3.5); - - ASSERT_TRUE(r2.is_inside>(p2_pl_in) == - intersection::status::e_inside); - ASSERT_TRUE(r2.is_inside>(p2_pl_edge) == - intersection::status::e_inside); - ASSERT_TRUE(r2.is_inside>(p2_pl_out) == - intersection::status::e_outside); - // Move outside point inside using a tolerance - ASSERT_TRUE(r2.is_inside>(p2_pl_out, 1.2) == - intersection::status::e_inside); - - ASSERT_TRUE(r2.is_inside>(p2_c_in) == - intersection::status::e_inside); - ASSERT_TRUE(r2.is_inside>(p2_c_edge) == - intersection::status::e_inside); - ASSERT_TRUE(r2.is_inside>(p2_c_out) == - intersection::status::e_outside); - // Move outside point inside using a tolerance - ASSERT_TRUE(r2.is_inside>(p2_c_out, 1.45) == - intersection::status::e_inside); -} From a5c784d067efa71c9197e41a1a7563975dfaff96 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 13 Oct 2022 10:49:18 -0700 Subject: [PATCH 57/63] Remove unused cuda tests --- tests/unit_tests/cuda/CMakeLists.txt | 2 - tests/unit_tests/cuda/rk_stepper_cuda.cpp | 124 ------------------ .../unit_tests/cuda/rk_stepper_cuda_kernel.cu | 88 ------------- .../cuda/rk_stepper_cuda_kernel.hpp | 97 -------------- 4 files changed, 311 deletions(-) delete mode 100644 tests/unit_tests/cuda/rk_stepper_cuda.cpp delete mode 100644 tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu delete mode 100644 tests/unit_tests/cuda/rk_stepper_cuda_kernel.hpp diff --git a/tests/unit_tests/cuda/CMakeLists.txt b/tests/unit_tests/cuda/CMakeLists.txt index cea15f475..c833d2290 100644 --- a/tests/unit_tests/cuda/CMakeLists.txt +++ b/tests/unit_tests/cuda/CMakeLists.txt @@ -42,8 +42,6 @@ foreach(algebra ${algebras}) "detector_cuda_kernel.cu" "navigator_cuda.cpp" "navigator_cuda_kernel.hpp" "navigator_cuda_kernel.cu" - "rk_stepper_cuda.cpp" "rk_stepper_cuda_kernel.hpp" - "rk_stepper_cuda_kernel.cu" "sf_finders_grid_cuda.cpp" "sf_finders_grid_cuda_kernel.hpp" "sf_finders_grid_cuda_kernel.cu" "propagator_cuda.cpp" "propagator_cuda_kernel.hpp" diff --git a/tests/unit_tests/cuda/rk_stepper_cuda.cpp b/tests/unit_tests/cuda/rk_stepper_cuda.cpp deleted file mode 100644 index f1ac6789d..000000000 --- a/tests/unit_tests/cuda/rk_stepper_cuda.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#include - -#include -#include - -#include "rk_stepper_cuda_kernel.hpp" - -TEST(rk_stepper_cuda, bound_state) { - /* - // VecMem memory resource(s) - vecmem::cuda::managed_memory_resource mng_mr; - - // test surface - const vector3 u{0, 1, 0}; - const vector3 w{1, 0, 0}; - const vector3 t{0, 0, 0}; - const transform3 trf(t, w, u); - - // Generate track starting point - vector3 local{2, 3, 0}; - vector3 mom{0.02, 0., 0.}; - scalar time = 0.; - scalar q = -1.; - - // bound vector - typename bound_track_parameters::vector_type bound_vector; - getter::element(bound_vector, e_bound_loc0, 0) = local[0]; - getter::element(bound_vector, e_bound_loc1, 0) = local[1]; - getter::element(bound_vector, e_bound_phi, 0) = getter::phi(mom); - getter::element(bound_vector, e_bound_theta, 0) = getter::theta(mom); - getter::element(bound_vector, e_bound_qoverp, 0) = q / getter::norm(mom); - getter::element(bound_vector, e_bound_time, 0) = time; - - // bound covariance - typename bound_track_parameters::covariance_type bound_cov = - matrix_operator().template zero(); - getter::element(bound_cov, e_bound_loc0, e_bound_loc0) = 1.; - getter::element(bound_cov, e_bound_loc1, e_bound_loc1) = 1.; - getter::element(bound_cov, e_bound_phi, e_bound_phi) = 1.; - - // Note: Set theta error as ZERO, to constrain the loc1 divergence - getter::element(bound_cov, e_bound_theta, e_bound_theta) = 0.; - getter::element(bound_cov, e_bound_qoverp, e_bound_qoverp) = 1.; - - // bound track parameter - const bound_track_parameters in_param(0, bound_vector, - bound_cov); - const vector3 B{0, 0, 1. * unit_constants::T}; - - // Get CPU bound parameter after one turn - - mag_field_t mag_field( - mag_field_t::backend_t::configuration_t{B[0], B[1], B[2]}); - prop_state propagation{ - crk_stepper_t::state(in_param, trf, mag_field), nav_state{}}; - crk_stepper_t::state &crk_state = propagation._stepping; - nav_state &n_state = propagation._navigation; - - // Decrease tolerance down to 1e-8 - crk_state.set_tolerance(rk_tolerance); - - // RK stepper and its state - crk_stepper_t crk_stepper; - - // Path length per turn - scalar S = 2. * std::fabs(1. / in_param.qop()) / getter::norm(B) * M_PI; - - // Run stepper for half turn - unsigned int max_steps = 1e4; - - for (unsigned int i = 0; i < max_steps; i++) { - - crk_state.set_constraint(S - crk_state.path_length()); - - n_state._step_size = S; - - crk_stepper.step(propagation); - - if (std::abs(S - crk_state.path_length()) < 1e-6) { - break; - } - - // Make sure that we didn't reach the end of for loop - ASSERT_TRUE(i < max_steps - 1); - } - - // Bound state after one turn propagation - const auto out_param_cpu = crk_stepper.bound_state(propagation, trf); - - // Get CUDA bound parameter after one turn - - vecmem::vector> out_param_cuda(1, - &mng_mr); - - bound_state_test(vecmem::get_data(out_param_cuda), in_param, B, trf); - - // Compare CPU and CUDA - - const auto bvec_cpu = out_param_cpu.vector(); - const auto bcov_cpu = out_param_cpu.covariance(); - - const auto bvec_cuda = out_param_cuda[0].vector(); - const auto bcov_cuda = out_param_cuda[0].covariance(); - - for (std::size_t i = 0; i < e_bound_size; i++) { - EXPECT_NEAR(matrix_operator().element(bvec_cpu, i, 0), - matrix_operator().element(bvec_cuda, i, 0), epsilon); - } - - for (std::size_t i = 0; i < e_bound_size; i++) { - for (std::size_t j = 0; j < e_bound_size; j++) { - EXPECT_NEAR(matrix_operator().element(bcov_cpu, i, j), - matrix_operator().element(bcov_cuda, i, j), epsilon); - } - } - */ -} diff --git a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu deleted file mode 100644 index b9db8b1f9..000000000 --- a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.cu +++ /dev/null @@ -1,88 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#include -#include -#include -#include -#include - -#include "detray/definitions/cuda_definitions.hpp" -#include "rk_stepper_cuda_kernel.hpp" - -namespace { -using field_t = covfie::field< - covfie::backend::constant, - covfie::vector::vector_d>>; -} - -namespace detray { - -__global__ void bound_state_test_kernel( - vecmem::data::vector_view> out_param, - const bound_track_parameters in_param, const field_t::view_t B, - const transform3 trf) { - /* - vecmem::device_vector> out_param_cuda( - out_param); - - prop_state propagation{ - crk_stepper_t::state(in_param, trf, B), nav_state{}}; - crk_stepper_t::state &crk_state = propagation._stepping; - nav_state &n_state = propagation._navigation; - - // Decrease tolerance down to 1e-8 - crk_state.set_tolerance(rk_tolerance); - - // RK stepper and its state - crk_stepper_t crk_stepper; - vector3 Bv{B.at(0.f, 0.f, 0.f)[0], B.at(0.f, 0.f, 0.f)[1], - B.at(0.f, 0.f, 0.f)[2]}; - - // Path length per turn - scalar S = 2. * std::fabs(1. / in_param.qop()) / getter::norm(Bv) * M_PI; - - // Run stepper for one turn - unsigned int max_steps = 1e4; - for (unsigned int i = 0; i < max_steps; i++) { - - crk_state.set_constraint(S - crk_state.path_length()); - - n_state._step_size = S; - - crk_stepper.step(propagation); - - if (std::abs(S - crk_state.path_length()) < 1e-6) { - break; - } - } - - // Bound state after one turn propagation - out_param_cuda[0] = crk_stepper.bound_state(propagation, trf); - */ -} - -void bound_state_test( - vecmem::data::vector_view> out_param, - const bound_track_parameters in_param, const vector3 B, - const transform3 trf) { - - constexpr int thread_dim = 1; - constexpr int block_dim = 1; - - field_t f(field_t::backend_t::configuration_t{B[0], B[1], B[2]}); - - // run the test kernel - bound_state_test_kernel<<>>(out_param, in_param, f, - trf); - - // cuda error check - DETRAY_CUDA_ERROR_CHECK(cudaGetLastError()); - DETRAY_CUDA_ERROR_CHECK(cudaDeviceSynchronize()); -} - -} // namespace detray diff --git a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.hpp b/tests/unit_tests/cuda/rk_stepper_cuda_kernel.hpp deleted file mode 100644 index 2cca70132..000000000 --- a/tests/unit_tests/cuda/rk_stepper_cuda_kernel.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/** Detray library, part of the ACTS project (R&D line) - * - * (c) 2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -#if defined(array) -#include "detray/plugins/algebra/array_definitions.hpp" -#elif defined(eigen) -#include "detray/plugins/algebra/eigen_definitions.hpp" -#elif defined(smatrix) -#include "detray/plugins/algebra/smatrix_definitions.hpp" -#elif defined(vc_array) -#include "detray/plugins/algebra/vc_array_definitions.hpp" -#endif - -#include -#include -#include - -#include "detray/definitions/qualifiers.hpp" -#include "detray/definitions/units.hpp" -#include "detray/propagator/rk_stepper.hpp" -#include "detray/tracks/tracks.hpp" - -using namespace detray; - -namespace { - -// type definitions -using vector3 = __plugin::vector3; -using point3 = __plugin::point3; -using transform3 = __plugin::transform3; -using mag_field_t = covfie::field, covfie::vector::vector_d>>; -using rk_stepper_t = rk_stepper; -using crk_stepper_t = - rk_stepper>; -using matrix_operator = standard_matrix_operator; - -// geomery navigation configurations -constexpr unsigned int theta_steps = 100; -constexpr unsigned int phi_steps = 100; -constexpr unsigned int rk_steps = 100; - -constexpr scalar epsilon = 1e-3; -constexpr scalar rk_tolerance = 1e-4; - -// dummy navigation struct -struct nav_state { - - DETRAY_HOST_DEVICE - scalar operator()() const { return _step_size; } - - DETRAY_HOST_DEVICE - inline auto current_object() const -> dindex { return dindex_invalid; } - - DETRAY_HOST_DEVICE - inline void set_full_trust() {} - - DETRAY_HOST_DEVICE - inline void set_high_trust() {} - - DETRAY_HOST_DEVICE - inline void set_fair_trust() {} - - DETRAY_HOST_DEVICE - inline void set_no_trust() {} - - DETRAY_HOST_DEVICE - inline bool abort() { return false; } - - scalar _step_size = 1. * unit_constants::mm; -}; - -// dummy propagator state -template -struct prop_state { - stepping_t _stepping; - navigation_t _navigation; -}; - -} // anonymous namespace - -namespace detray { - -// Test function for Runge-Kutta stepper bound state -// This test investigates only one track -void bound_state_test( - vecmem::data::vector_view> out_param, - const bound_track_parameters in_param, const vector3 B, - const transform3 trf); - -} // namespace detray From 8ff718687d900229b24f7926b255f85cb553d3b4 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 13 Oct 2022 11:51:50 -0700 Subject: [PATCH 58/63] Change the varaibles name --- core/include/detray/coordinates/cartesian2.hpp | 8 ++++---- core/include/detray/coordinates/cylindrical2.hpp | 8 ++++---- core/include/detray/coordinates/line2.hpp | 8 ++++---- core/include/detray/coordinates/polar2.hpp | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/include/detray/coordinates/cartesian2.hpp b/core/include/detray/coordinates/cartesian2.hpp index 3f567f2fe..4d957056c 100644 --- a/core/include/detray/coordinates/cartesian2.hpp +++ b/core/include/detray/coordinates/cartesian2.hpp @@ -103,7 +103,7 @@ struct cartesian2 final : public coordinate_base { template DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( - bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { const rotation_matrix frame = reference_frame(trf3, mask, pos, dir); @@ -112,14 +112,14 @@ struct cartesian2 final : public coordinate_base { const matrix_type<3, 2> bound_pos_to_free_pos_derivative = matrix_operator().template block<3, 2>(frame, 0, 0); - matrix_operator().template set_block(free_to_bound_jacobian, + matrix_operator().template set_block(bound_to_free_jacobian, bound_pos_to_free_pos_derivative, e_free_pos0, e_bound_loc0); } template DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( - free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + free_to_bound_matrix &free_to_bound_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { const rotation_matrix frame = reference_frame(trf3, mask, pos, dir); @@ -129,7 +129,7 @@ struct cartesian2 final : public coordinate_base { const matrix_type<2, 3> free_pos_to_bound_pos_derivative = matrix_operator().template block<2, 3>(frameT, 0, 0); - matrix_operator().template set_block(bound_to_free_jacobian, + matrix_operator().template set_block(free_to_bound_jacobian, free_pos_to_bound_pos_derivative, e_bound_loc0, e_free_pos0); } diff --git a/core/include/detray/coordinates/cylindrical2.hpp b/core/include/detray/coordinates/cylindrical2.hpp index 8be6d693f..9d83d1429 100644 --- a/core/include/detray/coordinates/cylindrical2.hpp +++ b/core/include/detray/coordinates/cylindrical2.hpp @@ -130,7 +130,7 @@ struct cylindrical2 : public coordinate_base { template DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( - bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); @@ -139,14 +139,14 @@ struct cylindrical2 : public coordinate_base { const auto bound_pos_to_free_pos_derivative = matrix_operator().template block<3, 2>(frame, 0, 0); - matrix_operator().template set_block(free_to_bound_jacobian, + matrix_operator().template set_block(bound_to_free_jacobian, bound_pos_to_free_pos_derivative, e_free_pos0, e_bound_loc0); } template DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( - free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + free_to_bound_matrix &free_to_bound_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); @@ -156,7 +156,7 @@ struct cylindrical2 : public coordinate_base { const auto free_pos_to_bound_pos_derivative = matrix_operator().template block<2, 3>(frameT, 0, 0); - matrix_operator().template set_block(bound_to_free_jacobian, + matrix_operator().template set_block(free_to_bound_jacobian, free_pos_to_bound_pos_derivative, e_bound_loc0, e_free_pos0); } diff --git a/core/include/detray/coordinates/line2.hpp b/core/include/detray/coordinates/line2.hpp index ceb728711..c5119ed7e 100644 --- a/core/include/detray/coordinates/line2.hpp +++ b/core/include/detray/coordinates/line2.hpp @@ -134,7 +134,7 @@ struct line2 : public coordinate_base { template DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( - bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); @@ -143,14 +143,14 @@ struct line2 : public coordinate_base { const auto bound_pos_to_free_pos_derivative = matrix_operator().template block<3, 2>(frame, 0, 0); - matrix_operator().template set_block(free_to_bound_jacobian, + matrix_operator().template set_block(bound_to_free_jacobian, bound_pos_to_free_pos_derivative, e_free_pos0, e_bound_loc0); } template DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( - free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + free_to_bound_matrix &free_to_bound_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { const auto frame = reference_frame(trf3, mask, pos, dir); @@ -160,7 +160,7 @@ struct line2 : public coordinate_base { const auto free_pos_to_bound_pos_derivative = matrix_operator().template block<2, 3>(frameT, 0, 0); - matrix_operator().template set_block(bound_to_free_jacobian, + matrix_operator().template set_block(free_to_bound_jacobian, free_pos_to_bound_pos_derivative, e_bound_loc0, e_free_pos0); } diff --git a/core/include/detray/coordinates/polar2.hpp b/core/include/detray/coordinates/polar2.hpp index abf89b1b8..ec2cb38f6 100644 --- a/core/include/detray/coordinates/polar2.hpp +++ b/core/include/detray/coordinates/polar2.hpp @@ -108,7 +108,7 @@ struct polar2 : public coordinate_base { template DETRAY_HOST_DEVICE inline void set_bound_pos_to_free_pos_derivative( - bound_to_free_matrix &free_to_bound_jacobian, const transform3_t &trf3, + bound_to_free_matrix &bound_to_free_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { matrix_type<3, 2> bound_pos_to_free_pos_derivative = @@ -140,14 +140,14 @@ struct polar2 : public coordinate_base { matrix_operator().template set_block<3, 1>( bound_pos_to_free_pos_derivative, col1, e_free_pos0, e_bound_loc1); - matrix_operator().template set_block(free_to_bound_jacobian, + matrix_operator().template set_block(bound_to_free_jacobian, bound_pos_to_free_pos_derivative, e_free_pos0, e_bound_loc0); } template DETRAY_HOST_DEVICE inline void set_free_pos_to_bound_pos_derivative( - free_to_bound_matrix &bound_to_free_jacobian, const transform3_t &trf3, + free_to_bound_matrix &free_to_bound_jacobian, const transform3_t &trf3, const mask_t &mask, const point3 &pos, const vector3 &dir) const { matrix_type<2, 3> free_pos_to_bound_pos_derivative = @@ -181,7 +181,7 @@ struct polar2 : public coordinate_base { matrix_operator().template set_block<1, 3>( free_pos_to_bound_pos_derivative, row1, e_bound_loc1, e_free_pos0); - matrix_operator().template set_block(bound_to_free_jacobian, + matrix_operator().template set_block(free_to_bound_jacobian, free_pos_to_bound_pos_derivative, e_bound_loc0, e_free_pos0); } From 1028072bc0c4948437e006e8b66db5e7a4390f7f Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 13 Oct 2022 12:02:40 -0700 Subject: [PATCH 59/63] Small fixes --- .../include/tests/common/path_correction.inl | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/common/include/tests/common/path_correction.inl b/tests/common/include/tests/common/path_correction.inl index 9a766c240..ae00200c6 100644 --- a/tests/common/include/tests/common/path_correction.inl +++ b/tests/common/include/tests/common/path_correction.inl @@ -235,9 +235,28 @@ TEST(path_correction, cartesian) { for (std::size_t j = 0; j < e_bound_size; j++) { EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), matrix_operator().element(bound_cov1, i, j), - crk_state.path_length() * env::epsilon); + env::epsilon); } } + + /* + // Print the matrix elements + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + std::cout << matrix_operator().element(bound_cov0, i, j) << " "; + } + std::cout << std::endl; + } + std::cout << std::endl; + + for (std::size_t i = 0; i < e_bound_size; i++) { + for (std::size_t j = 0; j < e_bound_size; j++) { + std::cout << matrix_operator().element(bound_cov1, i, j) << " "; + } + std::cout << std::endl; + } + std::cout << std::endl; + */ } TEST(path_correction, polar) { @@ -367,7 +386,7 @@ TEST(path_correction, polar) { for (std::size_t j = 0; j < e_bound_size; j++) { EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), matrix_operator().element(bound_cov1, i, j), - crk_state.path_length() * env::epsilon); + env::epsilon); } } } @@ -499,7 +518,7 @@ TEST(path_correction, cylindrical) { for (std::size_t j = 0; j < e_bound_size; j++) { EXPECT_NEAR(matrix_operator().element(bound_cov0, i, j), matrix_operator().element(bound_cov1, i, j), - crk_state.path_length() * env::epsilon); + env::epsilon); } } } \ No newline at end of file From 95321e6c3e821fbf59c169e2352dc48985e366e2 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Sat, 15 Oct 2022 01:03:25 -0700 Subject: [PATCH 60/63] Comment out print --- .../detray/coordinates/coordinate_base.hpp | 1 + .../propagator/actors/parameter_transporter.hpp | 17 ++--------------- .../include/tests/common/path_correction.inl | 12 ++++++------ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/core/include/detray/coordinates/coordinate_base.hpp b/core/include/detray/coordinates/coordinate_base.hpp index 632d76295..dea9b866a 100644 --- a/core/include/detray/coordinates/coordinate_base.hpp +++ b/core/include/detray/coordinates/coordinate_base.hpp @@ -252,6 +252,7 @@ struct coordinate_base { matrix_operator().template set_block<3, 3>(path_correction, drdr0, e_free_pos0, e_free_pos0); + // @note: Helical correction which doesn't exist in ACTS main if constexpr (stepper_state_t::id == stepping::id::e_rk) { using helix = detail::helix; diff --git a/core/include/detray/propagator/actors/parameter_transporter.hpp b/core/include/detray/propagator/actors/parameter_transporter.hpp index b8a136edf..46c96298d 100644 --- a/core/include/detray/propagator/actors/parameter_transporter.hpp +++ b/core/include/detray/propagator/actors/parameter_transporter.hpp @@ -98,7 +98,8 @@ struct parameter_transporter : actor { const bound_to_free_matrix& bound_to_free_jacobian = stepping._jac_to_global; - // Acts version + // @note: (Beomki) I really don't understand why the identity matrix + // should be added here but it makes result better :/ const free_matrix correction_term = matrix_operator() .template identity() + @@ -108,20 +109,6 @@ struct parameter_transporter : actor { free_to_bound_jacobian * correction_term * free_transport_jacobian * bound_to_free_jacobian; - /* - const bound_matrix full_jacobian = - free_to_bound_jacobian * - (path_correction + free_transport_jacobian) * - bound_to_free_jacobian; - */ - - // No path correction - /* - const bound_matrix full_jacobian = free_to_bound_jacobian * - free_transport_jacobian * - bound_to_free_jacobian; - */ - const bound_matrix new_cov = full_jacobian * stepping._bound_params.covariance() * matrix_operator().transpose(full_jacobian); diff --git a/tests/common/include/tests/common/path_correction.inl b/tests/common/include/tests/common/path_correction.inl index ae00200c6..08ed4e066 100644 --- a/tests/common/include/tests/common/path_correction.inl +++ b/tests/common/include/tests/common/path_correction.inl @@ -243,19 +243,19 @@ TEST(path_correction, cartesian) { // Print the matrix elements for (std::size_t i = 0; i < e_bound_size; i++) { for (std::size_t j = 0; j < e_bound_size; j++) { - std::cout << matrix_operator().element(bound_cov0, i, j) << " "; + printf("%f ", matrix_operator().element(bound_cov0, i, j)); } - std::cout << std::endl; + printf("\n"); } - std::cout << std::endl; + printf("\n"); for (std::size_t i = 0; i < e_bound_size; i++) { for (std::size_t j = 0; j < e_bound_size; j++) { - std::cout << matrix_operator().element(bound_cov1, i, j) << " "; + printf("%f ", matrix_operator().element(bound_cov1, i, j)); } - std::cout << std::endl; + printf("\n"); } - std::cout << std::endl; + printf("\n"); */ } From 228dd1c69afa03215f4db7515d94264a1e76a054 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Sun, 16 Oct 2022 00:16:20 -0700 Subject: [PATCH 61/63] Add a qualifier to invalid_values --- core/include/detray/propagator/actors/kalman_filter.hpp | 0 core/include/detray/utils/invalid_values.hpp | 3 +++ 2 files changed, 3 insertions(+) create mode 100644 core/include/detray/propagator/actors/kalman_filter.hpp diff --git a/core/include/detray/propagator/actors/kalman_filter.hpp b/core/include/detray/propagator/actors/kalman_filter.hpp new file mode 100644 index 000000000..e69de29bb diff --git a/core/include/detray/utils/invalid_values.hpp b/core/include/detray/utils/invalid_values.hpp index 04fa39b18..cf9ea3c2f 100644 --- a/core/include/detray/utils/invalid_values.hpp +++ b/core/include/detray/utils/invalid_values.hpp @@ -7,6 +7,9 @@ #pragma once +// Project include(s). +#include "detray/definitions/qualifiers.hpp" + // System include(s) #include #include From 7fd96b46fdbb5e3ec547119b86dae1d9f50704a4 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Sun, 16 Oct 2022 00:17:37 -0700 Subject: [PATCH 62/63] Remove unused file --- .vscode/settings.json | 6 ++++++ core/include/detray/propagator/actors/kalman_filter.hpp | 0 2 files changed, 6 insertions(+) create mode 100644 .vscode/settings.json delete mode 100644 core/include/detray/propagator/actors/kalman_filter.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..637304315 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "*.sycl": "cpp", + "type_traits": "cpp" + } +} \ No newline at end of file diff --git a/core/include/detray/propagator/actors/kalman_filter.hpp b/core/include/detray/propagator/actors/kalman_filter.hpp deleted file mode 100644 index e69de29bb..000000000 From 34a3a3f2c4cb0e44e9ce9040a0922b1ed4f3c0a0 Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Sun, 16 Oct 2022 00:17:46 -0700 Subject: [PATCH 63/63] Remove unused file --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 637304315..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.associations": { - "*.sycl": "cpp", - "type_traits": "cpp" - } -} \ No newline at end of file