ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
data_generator.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 "algebra/array.hpp"
13#include "detray/algebra/concepts.hpp"
14
15// System include(s)
16#include <algorithm>
17#include <random>
18#include <vector>
19
20namespace detray::algebra {
21
23template <detray::concepts::vector vector_t>
24inline void fill_random_vec(std::vector<vector_t> &collection) {
25 // Generate a vector of the right type with random values
26 std::random_device rd;
27 std::mt19937 mt(rd());
28 std::uniform_real_distribution<typename vector_t::value_type> dist(0.f, 1.f);
29
30 auto rand_obj = [&]() {
31 vector_t tmp{};
32
33 for (std::size_t i = 0u; i < detray::traits::size<vector_t>; ++i) {
34 tmp[i] = dist(mt);
35 }
36
37 return tmp;
38 };
39
40 collection.resize(collection.capacity());
41 std::ranges::generate(collection, rand_obj);
42}
43
45template <detray::concepts::transform3D transform3_t>
46inline void fill_random_trf(std::vector<transform3_t> &collection) {
47 using vector_t = typename transform3_t::vector3;
48
49 // Generate a random, but valid affine transformation
50 std::random_device rd;
51 std::mt19937 mt(rd());
52 std::uniform_real_distribution<typename transform3_t::scalar_type> dist(0.f,
53 1.f);
54
55 auto rand_obj = [&]() {
56 vector_t x_axis;
57 vector_t z_axis;
58 vector_t t;
59
60 x_axis = detray::vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)});
61 z_axis = {dist(mt), dist(mt), dist(mt)};
62 t = detray::vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)});
63
64 // Gram-Schmidt projection
65 typename transform3_t::scalar_type coeff =
66 detray::vector::dot(x_axis, z_axis) / detray::vector::norm(x_axis);
67 z_axis = x_axis - coeff * z_axis;
68
69 return transform3_t{t, x_axis, detray::vector::normalize(z_axis)};
70 };
71
72 collection.resize(collection.capacity());
73 std::ranges::generate(collection, rand_obj);
74}
75
77template <detray::concepts::matrix matrix_t>
78inline void fill_random_matrix(std::vector<matrix_t> &collection) {
79 using scalar_t = typename matrix_t::value_type::value_type;
80
81 // Generate a random, but valid affine transformation
82 std::random_device rd;
83 std::mt19937 mt(rd());
84 std::uniform_real_distribution<scalar_t> dist(0.f, 1.f);
85 auto rand_obj = [&]() {
86 matrix_t m{};
87
88 for (std::size_t j = 0u; j < m.size(); ++j) {
89 for (std::size_t i = 0u; i < m[0].size(); ++i) {
90 m[j][i] = dist(mt);
91 }
92 }
93
94 return m;
95 };
96
97 collection.resize(collection.capacity());
98 std::ranges::generate(collection, rand_obj);
99}
100
101} // namespace detray::algebra
constexpr double m
Meter.
Definition Units.hpp:97