7 #include "TDecompChol.h" 11 #include "CLHEP/Random/RandGaussQ.h" 15 std::vector<double>
const& centralValue,
16 std::vector<std::vector<double>>
const& inputCovarianceMatrix,
18 CLHEP::RandGaussQ& GaussRandom)
21 std::vector<std::vector<double>> setOfSmearedCentralValues;
24 unsigned int covarianceMatrix_dim = centralValue.size();
26 if (inputCovarianceMatrix.size() != covarianceMatrix_dim) {
28 <<
"inputCovarianceMatrix rows " << inputCovarianceMatrix.size()
29 <<
" not equal to entries of centralValue[]: " << covarianceMatrix_dim;
32 for (
auto const& row : inputCovarianceMatrix) {
33 if (row.size() != covarianceMatrix_dim) {
35 <<
"inputCovarianceMatrix columns " << row.size()
36 <<
" not equal to entries of centralValue[]: " << covarianceMatrix_dim;
41 int dim = int(inputCovarianceMatrix.size());
42 TMatrixD covarianceMatrix(dim, dim);
44 for (
auto const& row : inputCovarianceMatrix) {
46 for (
auto const& element : row) {
47 covarianceMatrix[i][j] = element;
54 TDecompChol dc = TDecompChol(covarianceMatrix);
55 if (!dc.Decompose()) {
57 <<
"Cannot decompose covariance matrix to begin smearing.";
58 return setOfSmearedCentralValues;
63 TMatrixD U = dc.GetU();
66 for (
int n = 0;
n < n_multisims; ++
n) {
69 int dim = centralValue.size();
71 std::vector<double> rands(dim);
72 GaussRandom.fireArray(dim, rands.data());
75 std::vector<double> smearedCentralValues;
78 double weightFromU = 0.;
79 for (
int row = 0; row <
col + 1; ++row) {
80 weightFromU += U(row, col) * rands[row];
85 smearedCentralValues.push_back(weightFromU + centralValue[col]);
89 setOfSmearedCentralValues.push_back(smearedCentralValues);
91 return setOfSmearedCentralValues;
98 TMatrixD*
const& inputCovarianceMatrix,
99 std::vector<double> rand)
103 std::vector<double> smearedCentralValues;
114 TDecompChol dc = TDecompChol(*(inputCovarianceMatrix));
115 if (!dc.Decompose()) {
117 <<
"Cannot decompose covariance matrix to begin smearing.";
118 return smearedCentralValues;
123 TMatrixD U = dc.GetU();
125 for (
unsigned int col = 0;
col < centralValue.size(); ++
col) {
127 double weightFromU = 0.;
129 for (
unsigned int row = 0; row <
col + 1; ++row) {
130 weightFromU += U(row, col) * rand[row];
136 smearedCentralValues.push_back(weightFromU + centralValue[col]);
138 return smearedCentralValues;
152 std::vector<double>
const& centralValue,
153 TMatrixD*
const& LowerTriangleCovarianceMatrix,
155 std::vector<double> rand)
159 std::vector<double> smearedCentralValues;
164 <<
"Must supply the decomposed lower triangular covariance matrix.";
165 return smearedCentralValues;
168 for (
unsigned int col = 0;
col < centralValue.size(); ++
col) {
170 double weightFromU = 0.;
172 for (
unsigned int row = 0; row <
col + 1; ++row) {
173 weightFromU += LowerTriangleCovarianceMatrix[0][row][
col] * rand[row];
179 smearedCentralValues.push_back(weightFromU + centralValue[col]);
181 return smearedCentralValues;
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
static std::vector< std::vector< double > > MultiGaussianSmearing(std::vector< double > const ¢ralValues, std::vector< std::vector< double >> const &inputCovarianceMatrix, int n_multisims, CLHEP::RandGaussQ &GaussRandom)
Applies Gaussian smearing to a set of data.