ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
ratio_test.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Detray tests include(s).
12#include "detray/geometry/shapes/cuboid3D.hpp"
13#include "detray/geometry/shapes/cylinder2D.hpp"
14
15// Detray test include(s)
16#include "detray/test/framework/types.hpp"
17
18// System include(s)
19#include <atomic>
20#include <random>
21#include <vector>
22
23namespace detray::test {
24
25template <typename shape_t>
26inline std::vector<point3> generate_regular_points(
27 const std::size_t /*unused*/, const std::vector<scalar> & /*unused*/);
28
31template <>
32inline std::vector<point3> generate_regular_points<cuboid3D>(
33 const std::size_t n_points, const std::vector<scalar> &world) {
34 const std::size_t n_steps{static_cast<std::size_t>(std::cbrt(n_points))};
35
36 const scalar world_x{world.at(0)};
37 const scalar world_y{(world.size() > 1 ? world[1] : world[0])};
38 const scalar world_z{(world.size() > 2 ? world[2] : world[0])};
39 const scalar dx{world_x / static_cast<scalar>(n_steps)};
40 const scalar dy{world_y / static_cast<scalar>(n_steps)};
41 const scalar dz{world_z / static_cast<scalar>(n_steps)};
42
43 std::vector<point3> points{};
44 points.reserve(n_points);
45
46 for (std::size_t ix = 0u; ix < n_steps; ++ix) {
47 scalar x{-0.5f * world_x + static_cast<scalar>(ix) * dx};
48
49 for (std::size_t iy = 0u; iy < n_steps; ++iy) {
50 scalar y{-0.5f * world_y + static_cast<scalar>(iy) * dy};
51
52 for (std::size_t iz = 0u; iz < n_steps; ++iz) {
53 scalar z{-0.5f * world_z + static_cast<scalar>(iz) * dz};
54
55 points.push_back({x, y, z});
56 }
57 }
58 }
59
60 return points;
61}
62
67template <>
68inline std::vector<point3> generate_regular_points<cylinder2D>(
69 const std::size_t n_points, const std::vector<scalar> &world) {
70 const std::size_t n_steps{static_cast<std::size_t>(std::sqrt(n_points))};
71
72 const scalar world_r{world.at(0)};
73 const scalar world_z{world.at(1)};
74 const scalar dphi{2.f * constant<scalar>::pi / static_cast<scalar>(n_steps)};
75 const scalar dz{world_z / static_cast<scalar>(n_steps)};
76
77 std::vector<point3> points{};
78 points.reserve(n_points);
79
80 for (std::size_t iphi = 0u; iphi < n_steps; ++iphi) {
81 scalar phi{-constant<scalar>::pi + static_cast<scalar>(iphi) * dphi};
82
83 for (std::size_t iz = 0u; iz < n_steps; ++iz) {
84 scalar z{-0.5f * world_z + static_cast<scalar>(iz) * dz};
85
86 points.push_back({world_r * std::cos(phi), world_r * std::sin(phi), z});
87 }
88 }
89
90 return points;
91}
92
94inline std::vector<point3> generate_random_points(
95 const scalar world, const std::size_t n_points,
96 const std::uint32_t seed = std::mt19937::default_seed) {
97 std::vector<point3> points{};
98 points.reserve(n_points);
99
100 std::random_device rd;
101 std::mt19937 mt(rd());
102 mt.seed(seed);
103 std::uniform_real_distribution<scalar> dist(-0.5f * world, 0.5f * world);
104
105 for (std::size_t i = 0u; i < n_points; ++i) {
106 points.push_back({dist(mt), dist(mt), dist(mt)});
107 }
108
109 return points;
110}
111
113template <typename predicate_t, typename... Args>
114inline scalar ratio_test(const std::vector<point3> &points, Args... args) {
115 std::atomic_ulong yes = 0u;
116
117 for (const auto &p : points) {
118 if (predicate_t{}(p, std::forward<Args>(args)...)) {
119 ++yes;
120 }
121 }
122
123 return static_cast<scalar>(yes) / static_cast<scalar>(points.size());
124}
125
126} // namespace detray::test
constexpr double u
atomic mass unit u
Definition Units.hpp:155
double scalar
Default scalar precision used for serialized geometry payloads.
Definition definitions.hpp:27
static constexpr scalar_t pi
π
Definition units.hpp:136