Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenerateParameters.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GenerateParameters.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
13 
14 #include <cmath>
15 #include <random>
16 #include <utility>
17 
18 namespace Acts {
19 namespace Test {
20 
24 template <typename scalar_t, size_t kSize, typename generator_t>
25 inline auto generateParametersCovariance(generator_t& rng)
26  -> std::pair<Eigen::Matrix<scalar_t, kSize, 1>,
27  Eigen::Matrix<scalar_t, kSize, kSize>> {
28  using Scalar = scalar_t;
29  using ParametersVector = Eigen::Matrix<scalar_t, kSize, 1>;
30  using CovarianceMatrix = Eigen::Matrix<scalar_t, kSize, kSize>;
31 
32  std::normal_distribution<Scalar> distNormal(0, 1);
33  std::uniform_real_distribution<Scalar> distCorr(-1, 1);
34 
35  // generate standard deviations
36  ParametersVector stddev;
37  for (auto i = 0u; i < kSize; ++i) {
38  stddev[i] = std::abs(distNormal(rng));
39  }
40  // generate correlation matrix
41  CovarianceMatrix corr;
42  for (auto i = 0u; i < kSize; ++i) {
43  corr(i, i) = 1;
44  // only need generate the sub-diagonal elements
45  for (auto j = 0u; j < i; ++j) {
46  corr(i, j) = corr(j, i) = distCorr(rng);
47  }
48  }
49  // construct the covariance matrix
50  CovarianceMatrix cov = stddev.asDiagonal() * corr * stddev.asDiagonal();
51 
52  // generate random parameters
53  // this is ignoring the correlations; since this does not need to generate
54  // credible data, this should be fine.
55  ParametersVector params;
56  for (auto i = 0u; i < kSize; ++i) {
57  params[i] = stddev[i] * distNormal(rng);
58  }
59 
60  return std::make_pair(params, cov);
61 }
62 
64 template <typename generator_t>
65 inline auto generateBoundParametersCovariance(generator_t& rng) {
66  auto parCov = generateParametersCovariance<ActsScalar, eBoundSize>(rng);
67  auto [phi, theta] = detail::normalizePhiTheta(parCov.first[eBoundPhi],
68  parCov.first[eBoundTheta]);
69  parCov.first[eBoundPhi] = phi;
70  parCov.first[eBoundTheta] = theta;
71  return parCov;
72 }
73 
75 template <typename generator_t>
76 inline auto generateFreeParametersCovariance(generator_t& rng) {
77  return generateParametersCovariance<ActsScalar, eFreeSize>(rng);
78 }
79 
80 } // namespace Test
81 } // namespace Acts