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/vc_aos.hpp"
13#include "detray/algebra/concepts.hpp"
14
15// System include(s)
16#include <algorithm>
17#include <vector>
18
19namespace detray::algebra {
20
22template <detray::concepts::vector vector_aos_t>
23inline void fill_random_vec(std::vector<vector_aos_t> &collection) {
24 // Generate a vector of the right type with random values
25 auto rand_obj = [&]() {
26 return vector_aos_t{vector_aos_t::array_type::Random()};
27 };
28
29 collection.resize(collection.capacity());
30 std::ranges::generate(collection, rand_obj);
31}
32
34template <detray::concepts::transform3D transform3_t>
35inline void fill_random_trf(std::vector<transform3_t> &collection) {
36 // Generate a random, but valid affine transformation
37 auto rand_obj = []() {
38 using vector_t = typename transform3_t::vector3;
39 vector_t x_axis;
40 vector_t z_axis;
41 vector_t t;
42
43 x_axis = vector_t{vector_t::array_type::Random()};
44 x_axis = detray::vector::normalize(x_axis);
45
46 z_axis = vector_t{vector_t::array_type::Random()};
47 z_axis = detray::vector::normalize(z_axis);
48
49 t = vector_t{vector_t::array_type::Random()};
50 t = detray::vector::normalize(t);
51
52 // Gram-Schmidt projection
53 typename transform3_t::scalar_type coeff =
54 detray::vector::dot(x_axis, z_axis) / detray::vector::norm(x_axis);
55 z_axis = x_axis - coeff * z_axis;
56
57 return transform3_t{t, x_axis, detray::vector::normalize(z_axis)};
58 };
59
60 collection.resize(collection.capacity());
61 std::ranges::generate(collection, rand_obj);
62}
63
65template <detray::concepts::matrix matrix_t>
66inline void fill_random_matrix(std::vector<matrix_t> &collection) {
67 // Generate a random, but valid affine transformation
68 auto rand_obj = []() {
69 using vector_t = typename matrix_t::vector_type;
70 vector_t x_axis;
71 vector_t z_axis;
72 vector_t t;
73
74 matrix_t m;
75 for (std::size_t j = 0u; j < matrix_t::columns(); ++j) {
76 m[j] = vector_t::array_type::Random();
77 }
78
79 return m;
80 };
81
82 collection.resize(collection.capacity());
83 std::ranges::generate(collection, rand_obj);
84}
85
86} // namespace detray::algebra
constexpr double m
Meter.
Definition Units.hpp:97