11 #include "TDecompChol.h" 14 #include "CLHEP/Random/RandomEngine.h" 15 #include "CLHEP/Random/RandGaussQ.h" 18 std::vector<std::vector<double> >
WeightCalc::MultiGaussianSmearing(std::vector<double>
const& centralValue,
std::vector< std::vector<double> >
const& inputCovarianceMatrix,
int n_multisims,CLHEP::RandGaussQ& GaussRandom)
21 std::vector<std::vector<double> > setOfSmearedCentralValues;
24 unsigned int covarianceMatrix_dim = centralValue.size();
26 if (inputCovarianceMatrix.size() != covarianceMatrix_dim)
29 <<
"inputCovarianceMatrix rows " << inputCovarianceMatrix.size()
30 <<
" not equal to entries of centralValue[]: " << covarianceMatrix_dim;
33 for (
auto const & row : inputCovarianceMatrix )
35 if(row.size() != covarianceMatrix_dim)
38 <<
"inputCovarianceMatrix columns " << row.size()
39 <<
" not equal to entries of centralValue[]: " << covarianceMatrix_dim;
44 int dim = int(inputCovarianceMatrix.size());
45 TMatrixD covarianceMatrix(dim,dim);
47 for (
auto const & row : inputCovarianceMatrix)
50 for (
auto const & element : row)
52 covarianceMatrix[i][j] = element;
59 TDecompChol dc = TDecompChol(covarianceMatrix);
63 <<
"Cannot decompose covariance matrix to begin smearing.";
64 return setOfSmearedCentralValues;
69 TMatrixD U = dc.GetU();
72 for(
int n = 0;
n < n_multisims; ++
n)
76 int dim = centralValue.size();
78 std::vector<double> rands(dim);
79 GaussRandom.fireArray(dim, rands.data());
82 std::vector<double> smearedCentralValues;
86 double weightFromU = 0.;
87 for(
int row = 0; row <
col+1; ++row)
89 weightFromU += U(row,col)*rands[row];
94 smearedCentralValues.push_back(weightFromU + centralValue[col]);
98 setOfSmearedCentralValues.push_back(smearedCentralValues);
100 return setOfSmearedCentralValues;
110 std::vector<double> smearedCentralValues;
121 TDecompChol dc = TDecompChol(*(inputCovarianceMatrix));
125 <<
"Cannot decompose covariance matrix to begin smearing.";
126 return smearedCentralValues;
131 TMatrixD U = dc.GetU();
134 for(
unsigned int col = 0;
col < centralValue.size(); ++
col)
137 double weightFromU = 0.;
139 for(
unsigned int row = 0; row <
col+1; ++row)
141 weightFromU += U(row,col)*rand[row];
147 smearedCentralValues.push_back(weightFromU + centralValue[col]);
149 return smearedCentralValues;
163 std::vector<double>
WeightCalc::MultiGaussianSmearing(std::vector<double>
const& centralValue, TMatrixD*
const& LowerTriangleCovarianceMatrix,
bool isDecomposed, std::vector< double > rand)
167 std::vector<double> smearedCentralValues;
172 <<
"Must supply the decomposed lower triangular covariance matrix.";
173 return smearedCentralValues;
177 for(
unsigned int col = 0;
col < centralValue.size(); ++
col)
180 double weightFromU = 0.;
182 for(
unsigned int row = 0; row <
col+1; ++row)
184 weightFromU += LowerTriangleCovarianceMatrix[0][row][
col]*rand[row];
190 smearedCentralValues.push_back(weightFromU + centralValue[col]);
192 return smearedCentralValues;
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.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception