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());
75 Eigen::SelfAdjointEigenSolver<MatrixXd> sol(
m_covMat);
76 VectorXd vals = sol.eigenvalues();
77 MatrixXd vecs = sol.eigenvectors();
79 std::vector<VectorXd> vBase;
81 for (
int i = 0; i < vals.rows(); ++i)
83 vBase.push_back(
sqrt(vals[i]) * vecs.col(i));
86 if (vBase.size() == 0)
95 m_cOrt = getOrthogonalSpace(v0);
97 m_v0norm = v0.dot(v0) > 0 ? v0 / v0.dot(v0) : v0;
102 double dx0 = x0 -
m_mu[0];
110 for (
const VectorXd& co :
m_cOrt) {
111 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
Eigen::MatrixXd m_covMat
covariance matrix of the distribution
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.