Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:18

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/Utilities/detail/periodic.hpp"
0013 
0014 #include <cmath>
0015 #include <random>
0016 #include <utility>
0017 
0018 namespace Acts::detail::Test {
0019 
0020 /// Generate a random parameters vector and covariance matrix.
0021 ///
0022 /// @return std:::pair<ParametersVector, CovarianceMatrix>
0023 template <typename scalar_t, std::size_t kSize, typename generator_t>
0024 inline auto generateParametersCovariance(generator_t& rng)
0025     -> std::pair<Eigen::Matrix<scalar_t, kSize, 1>,
0026                  Eigen::Matrix<scalar_t, kSize, kSize>> {
0027   using Scalar = scalar_t;
0028   using ParametersVector = Eigen::Matrix<scalar_t, kSize, 1>;
0029   using CovarianceMatrix = Eigen::Matrix<scalar_t, kSize, kSize>;
0030 
0031   std::normal_distribution<Scalar> distNormal(0, 1);
0032   std::uniform_real_distribution<Scalar> distCorr(-1, 1);
0033 
0034   // generate standard deviations
0035   ParametersVector stddev;
0036   for (auto i = 0u; i < kSize; ++i) {
0037     stddev[i] = std::abs(distNormal(rng));
0038   }
0039   // generate correlation matrix
0040   CovarianceMatrix corr;
0041   for (auto i = 0u; i < kSize; ++i) {
0042     corr(i, i) = 1;
0043     // only need generate the sub-diagonal elements
0044     for (auto j = 0u; j < i; ++j) {
0045       corr(i, j) = corr(j, i) = distCorr(rng);
0046     }
0047   }
0048   // construct the covariance matrix
0049   CovarianceMatrix cov = stddev.asDiagonal() * corr * stddev.asDiagonal();
0050 
0051   // generate random parameters
0052   // this is ignoring the correlations; since this does not need to generate
0053   // credible data, this should be fine.
0054   ParametersVector params;
0055   for (auto i = 0u; i < kSize; ++i) {
0056     params[i] = stddev[i] * distNormal(rng);
0057   }
0058 
0059   return std::make_pair(params, cov);
0060 }
0061 
0062 /// Generate a random bound parameters vector and covariance matrix.
0063 template <typename generator_t>
0064 inline auto generateBoundParametersCovariance(generator_t& rng) {
0065   auto parCov = generateParametersCovariance<ActsScalar, eBoundSize>(rng);
0066   auto [phi, theta] = detail::normalizePhiTheta(parCov.first[eBoundPhi],
0067                                                 parCov.first[eBoundTheta]);
0068   parCov.first[eBoundPhi] = phi;
0069   parCov.first[eBoundTheta] = theta;
0070   return parCov;
0071 }
0072 
0073 /// Generate a random free parameters vector and covariance matrix.
0074 template <typename generator_t>
0075 inline auto generateFreeParametersCovariance(generator_t& rng) {
0076   return generateParametersCovariance<ActsScalar, eFreeSize>(rng);
0077 }
0078 
0079 }  // namespace Acts::detail::Test