ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
uniform_track_generator_config.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// Project include(s)
12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14#include "detray/definitions/units.hpp"
15
16// Detray test include(s)
17#include "detray/test/common/event_generator/random_numbers.hpp"
18
19// System include(s)
20#include <algorithm>
21#include <limits>
22#include <ostream>
23
24namespace detray {
25
27template <concepts::scalar scalar_t>
30 using seed_t = std::uint64_t;
31
34
36 static constexpr scalar_t k_max_pi{constant<scalar_t>::pi -
37 std::numeric_limits<scalar_t>::epsilon()};
38
45
47 std::size_t m_phi_steps{50u};
49 std::size_t m_theta_steps{50u};
50
53 bool m_uniform_eta{false};
54
57
62 bool m_is_pT{false};
63
65 bool m_randomize_charge{false};
66
68 scalar_t m_time{0.f * unit<scalar_t>::us};
70 scalar_t m_charge{-1.f * unit<scalar_t>::e};
71
76 DETRAY_HOST_DEVICE uniform_track_generator_config& seed(const seed_t s) {
77 m_seed = s;
78 return *this;
79 }
80
83 DETRAY_HOST_DEVICE uniform_track_generator_config& phi_range(scalar_t low,
84 scalar_t high) {
85 auto min_phi{std::clamp(low, -constant<scalar_t>::pi, k_max_pi)};
86 auto max_phi{std::clamp(high, -constant<scalar_t>::pi, k_max_pi)};
87
88 assert(min_phi <= max_phi);
89
90 m_phi_range = {min_phi, max_phi};
91 return *this;
92 }
93
95 template <typename o_scalar_t>
98 phi_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
99 return *this;
100 }
101
105 scalar_t low, scalar_t high) {
106 auto min_theta{std::clamp(low, scalar_t{0.f}, k_max_pi)};
107 auto max_theta{std::clamp(high, scalar_t{0.f}, k_max_pi)};
108
109 assert(min_theta <= max_theta);
110
111 m_theta_range = {min_theta, max_theta};
112 m_uniform_eta = false;
113 return *this;
114 }
115
117 template <typename o_scalar_t>
120 theta_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
121 return *this;
122 }
123
126 DETRAY_HOST_DEVICE uniform_track_generator_config& eta_range(scalar_t low,
127 scalar_t high) {
128 // This value is more or less random
129 constexpr auto num_max{0.001f * std::numeric_limits<scalar_t>::max()};
130 auto min_eta{low > -num_max ? low : -num_max};
131 auto max_eta{high < num_max ? high : num_max};
132
133 assert(min_eta <= max_eta);
134
135 m_eta_range = {min_eta, max_eta};
136 m_uniform_eta = true;
137 return *this;
138 }
139
141 template <typename o_scalar_t>
144 eta_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
145 return *this;
146 }
147
149 DETRAY_HOST_DEVICE uniform_track_generator_config& phi_steps(std::size_t n) {
150 assert(n > 0);
151 m_phi_steps = n;
152 return *this;
153 }
154
157 std::size_t n) {
158 assert(n > 0);
159 m_theta_steps = n;
160 m_uniform_eta = false;
161 return *this;
162 }
163
165 DETRAY_HOST_DEVICE uniform_track_generator_config& eta_steps(std::size_t n) {
166 assert(n > 0);
167 m_theta_steps = n;
168 m_uniform_eta = true;
169 return *this;
170 }
171
173 DETRAY_HOST_DEVICE uniform_track_generator_config& uniform_eta(bool b) {
174 m_uniform_eta = b;
175 return *this;
176 }
177
181 DETRAY_HOST_DEVICE uniform_track_generator_config& origin(const scalar_t x,
182 const scalar_t y,
183 const scalar_t z) {
184 m_origin = {x, y, z};
185 return *this;
186 }
187
189 template <concepts::point3D point3_t>
191 const point3_t& ori) {
192 return origin(ori[0], ori[1], ori[2]);
193 }
194
196 DETRAY_HOST_DEVICE uniform_track_generator_config& p_tot(scalar_t p) {
197 assert(p > 0.f);
198 m_is_pT = false;
199 m_p_mag = p;
200 return *this;
201 }
202
204 DETRAY_HOST_DEVICE uniform_track_generator_config& p_T(scalar_t p) {
205 assert(p > 0.f);
206 m_is_pT = true;
207 m_p_mag = p;
208 return *this;
209 }
210
212 DETRAY_HOST_DEVICE
215 return *this;
216 }
217
219 DETRAY_HOST_DEVICE uniform_track_generator_config& time(scalar_t t) {
220 m_time = t;
221 return *this;
222 }
223
225 DETRAY_HOST_DEVICE uniform_track_generator_config& charge(scalar_t q) {
226 m_charge = q;
227 return *this;
228 }
229
230
234 DETRAY_HOST_DEVICE constexpr seed_t seed() const { return m_seed; }
236 DETRAY_HOST_DEVICE constexpr std::size_t n_tracks() const {
237 return phi_steps() * theta_steps();
238 }
239
240 DETRAY_HOST_DEVICE constexpr darray<scalar_t, 2> phi_range() const {
241 return m_phi_range;
242 }
243
244 DETRAY_HOST_DEVICE constexpr darray<scalar_t, 2> theta_range() const {
245 return m_theta_range;
246 }
247
248 DETRAY_HOST_DEVICE constexpr darray<scalar_t, 2> eta_range() const {
249 return m_eta_range;
250 }
251
252 DETRAY_HOST_DEVICE constexpr darray<scalar_t, 2> mom_range() const {
253 return {m_p_mag, m_p_mag};
254 }
255
256 DETRAY_HOST_DEVICE constexpr std::size_t phi_steps() const {
257 return m_phi_steps;
258 }
259
260 DETRAY_HOST_DEVICE constexpr std::size_t theta_steps() const {
261 return m_theta_steps;
262 }
263
264 DETRAY_HOST_DEVICE constexpr std::size_t eta_steps() const {
265 return m_theta_steps;
266 }
267
268 DETRAY_HOST_DEVICE constexpr bool uniform_eta() const {
269 return m_uniform_eta;
270 }
271
272 DETRAY_HOST_DEVICE constexpr const auto& origin() const { return m_origin; }
274 DETRAY_HOST_DEVICE constexpr bool is_pT() const { return m_is_pT; }
276 DETRAY_HOST_DEVICE constexpr bool randomize_charge() const {
277 return m_randomize_charge;
278 }
279
280 DETRAY_HOST_DEVICE constexpr scalar_t time() const { return m_time; }
282 DETRAY_HOST_DEVICE constexpr scalar_t charge() const { return m_charge; }
284
289 DETRAY_HOST
290 friend std::ostream& operator<<(std::ostream& out,
292 const auto& ori = cfg.origin();
293 const auto& phi_range = cfg.phi_range();
294
295 // General
296 out << "\nUniform track generator\n"
297 << "----------------------------\n"
298 << " Random seed : " << cfg.seed() << "\n"
299 << " No. tracks : " << cfg.n_tracks() << "\n"
300 << " -> phi steps : " << cfg.phi_steps() << "\n"
301 << " -> theta/eta steps : " << cfg.theta_steps() << "\n"
302 << " Charge : "
303 << cfg.charge() / detray::unit<scalar_t>::e << " [e]\n"
304 << " Rand. charge : " << std::boolalpha
305 << cfg.randomize_charge() << std::noboolalpha << "\n";
306
307 // Momentum
308 if (cfg.is_pT()) {
309 out << " Transverse mom. : "
310 << cfg.m_p_mag / detray::unit<scalar_t>::GeV << " [GeV]\n";
311 } else {
312 out << " Momentum : "
313 << cfg.m_p_mag / detray::unit<scalar_t>::GeV << " [GeV]\n";
314 }
315
316 // Direction
317 out << " Phi range : ["
319 << phi_range[1] / detray::unit<scalar_t>::rad << ") [rad]\n";
320 if (cfg.uniform_eta()) {
321 const auto& eta_range = cfg.eta_range();
322 out << " Eta range : [" << eta_range[0] << ", "
323 << eta_range[1] << "]\n";
324 } else {
325 const auto& theta_range = cfg.theta_range();
326 out << " Theta range : ["
328 << theta_range[1] / detray::unit<scalar_t>::rad << ") [rad]\n";
329 }
330
331 // Origin
332 out << " Origin : [" << ori[0] / detray::unit<scalar_t>::mm
333 << ", " << ori[1] / detray::unit<scalar_t>::mm << ", "
334 << ori[2] / detray::unit<scalar_t>::mm << "] [mm]\n";
335
336 return out;
337 }
338};
339
340} // namespace detray
Detray include(s).
Definition array_operators.hpp:18
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
static constexpr scalar_t pi
π
Definition units.hpp:136
static constexpr seed_type default_seed()
Get the default seed of the engine.
Definition random_numbers.hpp:102
Configuration for the uniform track generator.
Definition uniform_track_generator_config.hpp:28
uniform_track_generator_config & time(scalar_t t)
Definition uniform_track_generator_config.hpp:219
friend std::ostream & operator<<(std::ostream &out, const uniform_track_generator_config &cfg)
Print the uniform track generator configuration.
Definition uniform_track_generator_config.hpp:290
uniform_track_generator_config & origin(const point3_t &ori)
Definition uniform_track_generator_config.hpp:190
uniform_track_generator_config & uniform_eta(bool b)
Definition uniform_track_generator_config.hpp:173
constexpr darray< scalar_t, 2 > mom_range() const
Definition uniform_track_generator_config.hpp:252
scalar_t m_charge
Track charge.
Definition uniform_track_generator_config.hpp:70
uniform_track_generator_config & p_tot(scalar_t p)
Definition uniform_track_generator_config.hpp:196
static constexpr scalar_t k_max_pi
Ensure same angle space as random track generator.
Definition uniform_track_generator_config.hpp:36
std::size_t m_phi_steps
Angular step size.
Definition uniform_track_generator_config.hpp:47
uniform_track_generator_config & p_T(scalar_t p)
Definition uniform_track_generator_config.hpp:204
bool m_is_pT
Whether to interpret the momentum m_p_mag as p_T.
Definition uniform_track_generator_config.hpp:62
darray< scalar_t, 3 > m_origin
Track origin.
Definition uniform_track_generator_config.hpp:56
uniform_track_generator_config & eta_range(scalar_t low, scalar_t high)
Definition uniform_track_generator_config.hpp:126
scalar_t m_time
Time parameter and charge of the track.
Definition uniform_track_generator_config.hpp:68
uniform_track_generator_config & charge(scalar_t q)
Definition uniform_track_generator_config.hpp:225
bool m_randomize_charge
Randomly flip the charge sign?
Definition uniform_track_generator_config.hpp:65
uniform_track_generator_config & randomize_charge(bool rc)
Definition uniform_track_generator_config.hpp:213
scalar_t m_p_mag
Magnitude of momentum: Default is one to keep directions normalized if no momentum information is nee...
Definition uniform_track_generator_config.hpp:60
uniform_track_generator_config & theta_range(darray< o_scalar_t, 2 > r)
Definition uniform_track_generator_config.hpp:118
constexpr std::size_t eta_steps() const
Definition uniform_track_generator_config.hpp:264
uniform_track_generator_config & theta_steps(std::size_t n)
Definition uniform_track_generator_config.hpp:156
constexpr std::size_t phi_steps() const
Definition uniform_track_generator_config.hpp:256
constexpr darray< scalar_t, 2 > phi_range() const
Definition uniform_track_generator_config.hpp:240
darray< scalar_t, 2 > m_theta_range
Polar angle range.
Definition uniform_track_generator_config.hpp:42
uniform_track_generator_config & phi_steps(std::size_t n)
Definition uniform_track_generator_config.hpp:149
constexpr std::size_t theta_steps() const
Definition uniform_track_generator_config.hpp:260
uniform_track_generator_config & theta_range(scalar_t low, scalar_t high)
Definition uniform_track_generator_config.hpp:104
darray< scalar_t, 2 > m_phi_range
Range for phi [-pi, pi) and theta [0, pi).
Definition uniform_track_generator_config.hpp:40
uniform_track_generator_config & origin(const scalar_t x, const scalar_t y, const scalar_t z)
Definition uniform_track_generator_config.hpp:181
uniform_track_generator_config & phi_range(scalar_t low, scalar_t high)
Definition uniform_track_generator_config.hpp:83
constexpr std::size_t n_tracks() const
Definition uniform_track_generator_config.hpp:236
seed_t m_seed
Monte-Carlo seed.
Definition uniform_track_generator_config.hpp:33
darray< scalar_t, 2 > m_eta_range
Pseudorapidity range.
Definition uniform_track_generator_config.hpp:44
uniform_track_generator_config & seed(const seed_t s)
Setters.
Definition uniform_track_generator_config.hpp:76
constexpr bool randomize_charge() const
Definition uniform_track_generator_config.hpp:276
constexpr darray< scalar_t, 2 > eta_range() const
Definition uniform_track_generator_config.hpp:248
std::uint64_t seed_t
Random engine seed type.
Definition uniform_track_generator_config.hpp:30
bool m_uniform_eta
Do uniform eta steps instead of uniform theta steps (use same number of steps and range).
Definition uniform_track_generator_config.hpp:53
constexpr scalar_t charge() const
Definition uniform_track_generator_config.hpp:282
uniform_track_generator_config & eta_steps(std::size_t n)
Definition uniform_track_generator_config.hpp:165
constexpr scalar_t time() const
Definition uniform_track_generator_config.hpp:280
constexpr darray< scalar_t, 2 > theta_range() const
Definition uniform_track_generator_config.hpp:244
std::size_t m_theta_steps
Number of polar angle or pseudorapidity steps.
Definition uniform_track_generator_config.hpp:49
uniform_track_generator_config & eta_range(darray< o_scalar_t, 2 > r)
Definition uniform_track_generator_config.hpp:142
constexpr const auto & origin() const
Definition uniform_track_generator_config.hpp:272
constexpr seed_t seed() const
Getters.
Definition uniform_track_generator_config.hpp:234
uniform_track_generator_config & phi_range(darray< o_scalar_t, 2 > r)
Definition uniform_track_generator_config.hpp:96
constexpr bool uniform_eta() const
Definition uniform_track_generator_config.hpp:268
constexpr bool is_pT() const
Definition uniform_track_generator_config.hpp:274
static constexpr scalar_t mm
Native length unit, the millimetre.
Definition units.hpp:27
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
static constexpr scalar_t rad
Native angular unit, the radian.
Definition units.hpp:115
static constexpr scalar_t us
Microsecond expressed in the internal length-equivalent time unit.
Definition units.hpp:64