12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14#include "detray/definitions/math.hpp"
15#include "detray/definitions/units.hpp"
16#include "detray/tracks/ray.hpp"
17#include "detray/utils/logging.hpp"
18#include "detray/utils/ranges/ranges.hpp"
21#include "detray/test/common/event_generator/uniform_track_generator_config.hpp"
40template <
typename track_t,
41 typename generator_t =
45 uniform_track_generator<track_t, generator_t>> {
46 using algebra_t =
typename track_t::algebra_type;
60 using difference_type = std::ptrdiff_t;
61 using value_type = track_t;
62 using pointer = track_t*;
63 using reference = track_t&;
64 using iterator_category = detray::ranges::input_iterator_tag;
66 constexpr iterator() =
default;
74 constexpr iterator(std::shared_ptr<generator_t> rand_gen,
configuration cfg,
75 std::size_t iph = 1u, std::size_t ith = 0u)
76 : m_rnd_numbers{std::move(rand_gen)},
83 static_cast<scalar_t
>(cfg.
eta_steps() - 1u)},
93 constexpr bool operator==(
const iterator& rhs)
const {
94 return rhs.i_phi == i_phi && rhs.i_theta == i_theta;
102 constexpr auto operator++() -> iterator& {
104 if (i_theta < m_cfg.theta_steps()) {
106 if (i_phi < m_cfg.phi_steps()) {
108 m_phi = m_cfg.phi_range()[0] +
109 static_cast<scalar_t
>(i_phi) * m_phi_step_size;
115 m_phi = m_cfg.phi_range()[0];
120 if (m_cfg.uniform_eta()) {
121 const scalar_t eta = m_cfg.eta_range()[0] +
122 static_cast<scalar_t
>(i_theta) * m_eta_step_size;
123 m_theta = get_theta(eta);
125 m_theta = m_cfg.theta_range()[0] +
126 static_cast<scalar_t
>(i_theta) * m_theta_step_size;
135 constexpr auto operator++(
int) -> iterator& {
145 if (!m_rnd_numbers) {
146 std::string err_str{
"Invalid random number generator"};
147 DETRAY_FATAL_HOST(err_str);
148 throw std::invalid_argument(err_str);
151 scalar_t sin_theta{math::sin(m_theta)};
154 vector3_t p{math::cos(m_phi) * sin_theta, math::sin(m_phi) * sin_theta,
158 if constexpr (std::is_same_v<track_t, detail::ray<algebra_t>>) {
159 p = vector::normalize(p);
161 sin_theta = (sin_theta == scalar_t{0.f})
162 ? std::numeric_limits<scalar_t>::epsilon()
164 p = (m_cfg.is_pT() ? 1.f / sin_theta : 1.f) * m_cfg.m_p_mag *
165 vector::normalize(p);
168 const auto& ori = m_cfg.origin();
172 const auto sign{
static_cast<scalar_t
>(
173 signs[m_cfg.randomize_charge() ? m_rnd_numbers->coin_toss() : 0u])};
176 {ori[0], ori[1], ori[2]}, m_cfg.time(), p, sign * m_cfg.charge()};
180 std::shared_ptr<generator_t> m_rnd_numbers;
186 scalar_t m_phi_step_size{0.f};
187 scalar_t m_theta_step_size{0.f};
188 scalar_t m_eta_step_size{0.f};
192 scalar_t m_theta{0.f};
195 std::size_t i_phi{0u};
196 std::size_t i_theta{0u};
203 scalar_t get_theta(
const scalar_t eta) {
204 return 2.f * math::atan(math::exp(-eta));
208 std::shared_ptr<generator_t> m_gen{
223 : m_gen{std::make_shared<generator_t>(cfg.seed())}, m_cfg{cfg} {}
237 bool uniform_eta =
false,
239 : m_gen{std::make_shared<generator_t>()} {
240 m_cfg.phi_steps(n_phi).theta_steps(n_theta);
241 m_cfg.uniform_eta(uniform_eta);
243 m_cfg.charge(charge);
250 : m_gen(std::move(other.m_gen)), m_cfg(std::move(other.m_cfg)) {}
272 constexpr auto begin() noexcept -> iterator {
return {m_gen, m_cfg, 1u, 0u}; }
277 constexpr auto end() noexcept -> iterator {
278 return {m_gen, m_cfg, 1u, m_cfg.theta_steps()};
284 constexpr auto size() const noexcept -> std::
size_t {
285 return m_cfg.phi_steps() * m_cfg.theta_steps();
Defines a detray 'view'.
Definition ranges.hpp:190
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
constexpr array_t< scalar1_t, 2 > operator*(const array_t< scalar1_t, 2 > &a, scalar2_t s)
Multiply an array-backed vector by a scalar.
Definition array_operators.hpp:26
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
get_vector3D_t< A, T > dvector3D
Three-dimensional vector type for algebra A and value type T.
Definition algebra.hpp:80
constexpr bool operator==(const Fastor::Tensor< S, N > &lhs, const Fastor::Tensor< S, N > &rhs)
Compare two Fastor vectors component-wise for exact equality.
Definition fastor.hpp:35
static constexpr scalar_t pi
π
Definition units.hpp:136
Wrapper for CPU random number generatrion for the random_track_generator.
Definition random_numbers.hpp:26
static constexpr scalar_t GeV
Native energy unit, the gigaelectronvolt.
Definition units.hpp:81
static constexpr scalar_t e
Charge, native unit e (elementary charge).
Definition units.hpp:105