File indexing completed on 2026-05-27 07:24:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "detray/test/validation/detector_scanner.hpp"
0011
0012 #include "detray/definitions/units.hpp"
0013 #include "detray/tracks/tracks.hpp"
0014 #include "detray/tracks/trajectories.hpp"
0015
0016
0017 #include "detray/test/common/build_toy_detector.hpp"
0018 #include "detray/test/common/track_generators.hpp"
0019 #include "detray/test/framework/types.hpp"
0020
0021
0022 #include <vecmem/memory/host_memory_resource.hpp>
0023
0024
0025 #include <gtest/gtest.h>
0026
0027 using namespace detray;
0028
0029 using test_algebra = test::algebra;
0030 using scalar = test::scalar;
0031 using vector3 = test::vector3;
0032
0033 constexpr const scalar tol{1e-7f};
0034
0035
0036
0037 GTEST_TEST(detray_simulation, detector_scanner) {
0038
0039 const vector3 B{0.f * unit<scalar>::T, 0.f * unit<scalar>::T,
0040 tol * unit<scalar>::T};
0041
0042
0043 vecmem::host_memory_resource host_mr;
0044 auto [toy_det, names] = build_toy_detector<test_algebra>(host_mr);
0045
0046 unsigned int theta_steps{50u};
0047 unsigned int phi_steps{50u};
0048
0049
0050 using detector_t = decltype(toy_det);
0051 using intersection_trace_t = typename detray::ray_scan<
0052 test_algebra>::template intersection_trace_type<detector_t>;
0053
0054 detector_t::geometry_context gctx{};
0055
0056 std::vector<intersection_trace_t> expected;
0057
0058
0059 for (const auto test_ray : uniform_track_generator<detail::ray<test_algebra>>(
0060 phi_steps, theta_steps)) {
0061
0062 const auto intersection_record =
0063 detector_scanner::run<ray_scan>(gctx, toy_det, test_ray);
0064
0065 expected.push_back(intersection_record);
0066 }
0067
0068
0069 std::size_t n_tracks{0u};
0070 for (const auto track :
0071 uniform_track_generator<free_track_parameters<test_algebra>>(
0072 phi_steps, theta_steps)) {
0073 const detail::helix test_helix(track, B);
0074
0075
0076 const auto intersection_trace =
0077 detector_scanner::run<helix_scan>(gctx, toy_det, test_helix);
0078
0079
0080
0081 EXPECT_EQ(expected[n_tracks].size(), intersection_trace.size())
0082 << "track: " << n_tracks << "\n"
0083 << test_helix;
0084
0085
0086 const std::size_t n_ray_inters{expected[n_tracks].size()};
0087 const std::size_t n_helix_inters{intersection_trace.size()};
0088 EXPECT_EQ(n_ray_inters, n_helix_inters)
0089 << "track: " << n_tracks << "\n"
0090 << "Ray scan: " << n_ray_inters << ", helix scan: " << n_helix_inters
0091 << std::endl;
0092
0093
0094 for (std::size_t i = 0u; i < std::min(n_ray_inters, n_helix_inters); ++i) {
0095 if (expected[n_tracks][i].vol_idx != intersection_trace[i].vol_idx) {
0096
0097
0098 if (expected[n_tracks][i].vol_idx ==
0099 intersection_trace[i + 1u].vol_idx &&
0100 expected[n_tracks][i + 1u].vol_idx ==
0101 intersection_trace[i].vol_idx) {
0102
0103 ++i;
0104 continue;
0105 }
0106 }
0107 EXPECT_EQ(expected[n_tracks][i].vol_idx, intersection_trace[i].vol_idx)
0108 << "track: " << n_tracks << ", intersection: " << i
0109 << "\n - ray: " << expected[n_tracks][i].intersection
0110 << "\n - helix: " << intersection_trace[i].intersection;
0111 }
0112
0113 ++n_tracks;
0114 }
0115 }