9#include <framework/utilities/ConditionalGaussGenerator.h>
19static std::vector<VectorXd> toVectors(
const MatrixXd& mat)
21 std::vector<VectorXd> vList;
22 for (
int j = 0; j < mat.cols(); ++j)
23 vList.push_back(mat.col(j));
29static MatrixXd toMatrix(
const std::vector<VectorXd>& vList)
31 if (vList.size() == 0)
34 MatrixXd mat(vList[0].rows(), vList.size());
35 for (
unsigned j = 0; j < vList.size(); ++j)
36 mat.col(j) = vList[j];
42static std::vector<VectorXd> getOrthogonalSpace(VectorXd v0)
45 return toVectors(MatrixXd::Identity(v0.rows(), v0.rows()));
47 VectorXd v0Norm = v0.normalized();
49 std::vector<VectorXd> vList;
50 vList.push_back(v0Norm);
52 while (
int(vList.size()) < v0.rows()) {
56 VectorXd v(v0.rows());
57 for (
int i = 0; i < v.rows(); ++i)
58 v(i) = gRandom->Uniform(-1, 1);
60 for (
const VectorXd& vi : vList)
61 v -= vi.dot(v) * vi / vi.dot(vi);
64 vList.push_back(v.normalized());
68 vList.erase(vList.begin());
74 Eigen::SelfAdjointEigenSolver<MatrixXd> sol(m_covMat);
75 VectorXd vals = sol.eigenvalues();
76 MatrixXd vecs = sol.eigenvectors();
78 std::vector<VectorXd> vBase;
80 for (
int i = 0; i < vals.rows(); ++i)
82 vBase.push_back(sqrt(vals[i]) * vecs.col(i));
85 if (vBase.size() == 0)
88 m_vBaseMat = toMatrix(vBase);
91 VectorXd v0 = m_vBaseMat.row(0);
94 m_cOrt = getOrthogonalSpace(v0);
96 m_v0norm = v0.dot(v0) > 0 ? v0 / v0.dot(v0) : v0;
101 double dx0 = x0 -
m_mu[0];
109 for (
const VectorXd& co :
m_cOrt) {
110 double rr = gRandom->Gaus();
Eigen::VectorXd generate(double x0) const
generate random vector based on the provided first component x0
Eigen::VectorXd m_mu
central values of the distribution
Eigen::MatrixXd m_vBaseMat
transformation matrix between eigen-system of m_covMat and nominal system
std::vector< Eigen::VectorXd > m_cOrt
array of vectors describing free degrees of freedom of random generator
Eigen::VectorXd m_v0norm
vector which scales with dx0
ConditionalGaussGenerator()
dummy constructor without arguments
Abstract base class for different kinds of events.