ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
random_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/math.hpp"
15#include "detray/definitions/units.hpp"
16
17// Detray test include(s)
18#include "detray/test/common/event_generator/random_numbers.hpp"
19
20// System include(s)
21#include <algorithm>
22#include <limits>
23#include <ostream>
24#include <random>
25
26namespace detray {
27
29template <concepts::scalar scalar_t>
32 using seed_t = std::uint64_t;
33
35 bool m_do_vtx_smearing = false;
36
39
41 std::size_t m_n_tracks{10u};
42
46
48
52
53 bool m_is_pT{false};
54
59
61 bool m_randomize_charge{false};
62
64 scalar_t m_time{0.f * unit<scalar_t>::us};
66 scalar_t m_charge{-1.f * unit<scalar_t>::e};
67
72 DETRAY_HOST_DEVICE random_track_generator_config& seed(const seed_t s) {
73 m_seed = s;
74 return *this;
75 }
76
80 return *this;
81 }
82
84 DETRAY_HOST_DEVICE random_track_generator_config& n_tracks(std::size_t n) {
85 assert(n > 0);
86 m_n_tracks = n;
87 return *this;
88 }
89
93 const scalar_t low, const scalar_t high) {
94 auto min_phi{
96 auto max_phi{
98
99 assert(min_phi <= max_phi);
100
101 m_phi_range = {min_phi, max_phi};
102 return *this;
103 }
104
106 template <typename o_scalar_t>
109 phi_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
110 return *this;
111 }
112
115 DETRAY_HOST_DEVICE random_track_generator_config& theta_range(scalar_t low,
116 scalar_t high) {
117 auto min_theta{std::clamp(low, scalar_t{0.f}, constant<scalar_t>::pi)};
118 auto max_theta{std::clamp(high, scalar_t{0.f}, constant<scalar_t>::pi)};
119
120 assert(min_theta <= max_theta);
121
122 m_theta_range = {min_theta, max_theta};
123 return *this;
124 }
125
127 template <typename o_scalar_t>
130 theta_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
131 return *this;
132 }
133
136 DETRAY_HOST_DEVICE random_track_generator_config& eta_range(scalar_t low,
137 scalar_t high) {
138 // This value is more or less random
139 constexpr auto num_max{0.001f * std::numeric_limits<scalar_t>::max()};
140 auto min_eta{low > -num_max ? low : -num_max};
141 auto max_eta{high < num_max ? high : num_max};
142
143 assert(min_eta <= max_eta);
144
145 auto get_theta = [](const scalar_t eta) {
146 return 2.f * math::atan(math::exp(-eta));
147 };
148
149 theta_range(get_theta(max_eta), get_theta(min_eta));
150 return *this;
151 }
152
154 template <typename o_scalar_t>
157 eta_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
158 return *this;
159 }
160
163 DETRAY_HOST_DEVICE random_track_generator_config& mom_range(scalar_t low,
164 scalar_t high) {
165 m_is_pT = false;
166 assert(low >= 0.f);
167 assert(low <= high);
168 m_mom_range = {low, high};
169 return *this;
170 }
171
173 template <typename o_scalar_t>
176 mom_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
177 return *this;
178 }
179
182 DETRAY_HOST_DEVICE random_track_generator_config& pT_range(scalar_t low,
183 scalar_t high) {
184 m_is_pT = true;
185 assert(low >= 0.f);
186 assert(low <= high);
187 m_mom_range = {low, high};
188 return *this;
189 }
190
192 template <typename o_scalar_t>
195 pT_range(static_cast<o_scalar_t>(r[0]), static_cast<o_scalar_t>(r[1]));
196 return *this;
197 }
198
200 DETRAY_HOST_DEVICE random_track_generator_config& p_tot(scalar_t p) {
201 mom_range(p, p);
202 return *this;
203 }
204
206 DETRAY_HOST_DEVICE random_track_generator_config& p_T(scalar_t p) {
207 pT_range(p, p);
208 return *this;
209 }
210
214 DETRAY_HOST_DEVICE random_track_generator_config& origin(const scalar_t x,
215 const scalar_t y,
216 const scalar_t z) {
217 m_origin = {x, y, z};
218 return *this;
219 }
220
222 template <concepts::point3D point3_t>
224 const point3_t& ori) {
225 return origin(ori[0], ori[1], ori[2]);
226 }
227
232 const scalar_t x, const scalar_t y, const scalar_t z) {
233 m_do_vtx_smearing = true;
234 m_origin_stddev = {x, y, z};
235 return *this;
236 }
237
239 template <concepts::point3D point3_t>
241 point3_t stddev) {
242 return origin_stddev(stddev[0], stddev[1], stddev[2]);
243 }
244
246 DETRAY_HOST_DEVICE
249 return *this;
250 }
251
253 DETRAY_HOST_DEVICE random_track_generator_config& time(scalar_t t) {
254 assert(t >= 0.f);
255 m_time = t;
256 return *this;
257 }
258
260 DETRAY_HOST_DEVICE random_track_generator_config& charge(scalar_t q) {
261 m_charge = q;
262 return *this;
263 }
264
265
269 DETRAY_HOST_DEVICE constexpr seed_t seed() const { return m_seed; }
271 DETRAY_HOST_DEVICE constexpr bool do_vertex_smearing() const {
272 return m_do_vtx_smearing;
273 }
274
275 DETRAY_HOST_DEVICE constexpr std::size_t n_tracks() const {
276 return m_n_tracks;
277 }
278
279 DETRAY_HOST_DEVICE constexpr const darray<scalar_t, 2>& phi_range() const {
280 return m_phi_range;
281 }
282
283 DETRAY_HOST_DEVICE constexpr const darray<scalar_t, 2>& theta_range() const {
284 return m_theta_range;
285 }
286
287 DETRAY_HOST_DEVICE constexpr const darray<scalar_t, 2>& mom_range() const {
288 return m_mom_range;
289 }
290
291 DETRAY_HOST_DEVICE constexpr const auto& origin() const { return m_origin; }
293 DETRAY_HOST_DEVICE constexpr const auto& origin_stddev() const {
294 return m_origin_stddev;
295 }
296
297 DETRAY_HOST_DEVICE constexpr bool is_pT() const { return m_is_pT; }
299 DETRAY_HOST_DEVICE constexpr bool randomize_charge() const {
300 return m_randomize_charge;
301 }
302
303 DETRAY_HOST_DEVICE constexpr scalar_t time() const { return m_time; }
305 DETRAY_HOST_DEVICE constexpr scalar_t charge() const { return m_charge; }
307
312 DETRAY_HOST
313 friend std::ostream& operator<<(std::ostream& out,
315 const auto& ori = cfg.origin();
316 const auto& mom_range = cfg.mom_range();
317 const auto& phi_range = cfg.phi_range();
318 const auto& theta_range = cfg.theta_range();
319
320 // General
321 out << "\nRandom track generator\n"
322 << "----------------------------\n"
323 << " Random seed : " << cfg.seed() << "\n"
324 << " No. tracks : " << cfg.n_tracks() << "\n"
325 << " Charge : "
326 << cfg.charge() / detray::unit<scalar_t>::e << " [e]\n"
327 << " Rand. charge : " << std::boolalpha
328 << cfg.randomize_charge() << std::noboolalpha << "\n";
329
330 // Momentum and direction
331 if (cfg.is_pT()) {
332 out << " Transverse mom. : [";
333 } else {
334 out << " Momentum : [";
335 }
336 out << mom_range[0] / detray::unit<scalar_t>::GeV << ", "
337 << mom_range[1] / detray::unit<scalar_t>::GeV << ") [GeV]\n"
338 << " Phi range : ["
340 << phi_range[1] / detray::unit<scalar_t>::rad << ") [rad]\n"
341 << " Theta range : ["
343 << theta_range[1] / detray::unit<scalar_t>::rad << ") [rad]\n"
344 << " Origin : [" << ori[0] / detray::unit<scalar_t>::mm
345 << ", " << ori[1] / detray::unit<scalar_t>::mm << ", "
346 << ori[2] / detray::unit<scalar_t>::mm << "] [mm]\n"
347 << " Do vertex smearing : " << std::boolalpha
348 << cfg.do_vertex_smearing() << "\n"
349 << std::noboolalpha;
350
351 if (cfg.do_vertex_smearing()) {
352 const auto& ori_stddev = cfg.origin_stddev();
353 out << " Origin stddev : ["
354 << ori_stddev[0] / detray::unit<scalar_t>::mm << ", "
355 << ori_stddev[1] / detray::unit<scalar_t>::mm << ", "
356 << ori_stddev[2] / detray::unit<scalar_t>::mm << "] [mm]\n";
357 }
358
359 return out;
360 }
361};
362
363} // 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 random track generator.
Definition random_track_generator_config.hpp:30
constexpr const darray< scalar_t, 2 > & phi_range() const
Definition random_track_generator_config.hpp:279
random_track_generator_config & mom_range(scalar_t low, scalar_t high)
Definition random_track_generator_config.hpp:163
scalar_t m_charge
Track charge.
Definition random_track_generator_config.hpp:66
random_track_generator_config & charge(scalar_t q)
Definition random_track_generator_config.hpp:260
darray< scalar_t, 2 > m_theta_range
Polar angle range.
Definition random_track_generator_config.hpp:47
random_track_generator_config & p_tot(scalar_t p)
Definition random_track_generator_config.hpp:200
scalar_t m_time
Time parameter and charge of the track.
Definition random_track_generator_config.hpp:64
random_track_generator_config & p_T(scalar_t p)
Definition random_track_generator_config.hpp:206
random_track_generator_config & pT_range(scalar_t low, scalar_t high)
Definition random_track_generator_config.hpp:182
friend std::ostream & operator<<(std::ostream &out, const random_track_generator_config &cfg)
Print the random track generator configuration.
Definition random_track_generator_config.hpp:313
random_track_generator_config & eta_range(scalar_t low, scalar_t high)
Definition random_track_generator_config.hpp:136
random_track_generator_config & origin(const point3_t &ori)
Definition random_track_generator_config.hpp:223
constexpr seed_t seed() const
Getters.
Definition random_track_generator_config.hpp:269
random_track_generator_config & mom_range(darray< o_scalar_t, 2 > r)
Definition random_track_generator_config.hpp:174
darray< scalar_t, 3 > m_origin
Track origin.
Definition random_track_generator_config.hpp:56
random_track_generator_config & pT_range(darray< o_scalar_t, 2 > r)
Definition random_track_generator_config.hpp:193
random_track_generator_config & phi_range(const scalar_t low, const scalar_t high)
Definition random_track_generator_config.hpp:92
constexpr scalar_t time() const
Definition random_track_generator_config.hpp:303
bool m_randomize_charge
Randomly flip the charge sign?
Definition random_track_generator_config.hpp:61
random_track_generator_config & theta_range(darray< o_scalar_t, 2 > r)
Definition random_track_generator_config.hpp:128
random_track_generator_config & seed(const seed_t s)
Setters.
Definition random_track_generator_config.hpp:72
darray< scalar_t, 3 > m_origin_stddev
Vertex smearing standard deviations.
Definition random_track_generator_config.hpp:58
constexpr bool randomize_charge() const
Definition random_track_generator_config.hpp:299
random_track_generator_config & origin(const scalar_t x, const scalar_t y, const scalar_t z)
Definition random_track_generator_config.hpp:214
random_track_generator_config & randomize_charge(bool rc)
Definition random_track_generator_config.hpp:247
constexpr const darray< scalar_t, 2 > & mom_range() const
Definition random_track_generator_config.hpp:287
random_track_generator_config & origin_stddev(point3_t stddev)
Definition random_track_generator_config.hpp:240
constexpr const darray< scalar_t, 2 > & theta_range() const
Definition random_track_generator_config.hpp:283
constexpr const auto & origin() const
Definition random_track_generator_config.hpp:291
std::uint64_t seed_t
Random engine seed type.
Definition random_track_generator_config.hpp:32
darray< scalar_t, 2 > m_phi_range
Range for phi [-pi, pi) and theta [0, pi).
Definition random_track_generator_config.hpp:44
random_track_generator_config & do_vertex_smearing(bool b)
Definition random_track_generator_config.hpp:78
darray< scalar_t, 2 > m_mom_range
Momentum range.
Definition random_track_generator_config.hpp:50
seed_t m_seed
Monte-Carlo seed.
Definition random_track_generator_config.hpp:38
constexpr bool is_pT() const
Definition random_track_generator_config.hpp:297
constexpr std::size_t n_tracks() const
Definition random_track_generator_config.hpp:275
random_track_generator_config & origin_stddev(const scalar_t x, const scalar_t y, const scalar_t z)
Definition random_track_generator_config.hpp:231
random_track_generator_config & phi_range(darray< o_scalar_t, 2 > r)
Definition random_track_generator_config.hpp:107
constexpr bool do_vertex_smearing() const
Definition random_track_generator_config.hpp:271
random_track_generator_config & n_tracks(std::size_t n)
Definition random_track_generator_config.hpp:84
bool m_do_vtx_smearing
Gaussian vertex smearing.
Definition random_track_generator_config.hpp:35
bool m_is_pT
Whether to interpret the momentum m_mom_range as p_T.
Definition random_track_generator_config.hpp:53
random_track_generator_config & theta_range(scalar_t low, scalar_t high)
Definition random_track_generator_config.hpp:115
constexpr const auto & origin_stddev() const
Definition random_track_generator_config.hpp:293
constexpr scalar_t charge() const
Definition random_track_generator_config.hpp:305
random_track_generator_config & eta_range(darray< o_scalar_t, 2 > r)
Definition random_track_generator_config.hpp:155
random_track_generator_config & time(scalar_t t)
Definition random_track_generator_config.hpp:253
std::size_t m_n_tracks
How many tracks will be generated.
Definition random_track_generator_config.hpp:41
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