8 #include "TDecompChol.h" 11 #include "CLHEP/Random/RandGaussQ.h" 14 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)
17 std::vector<std::vector<double> > setOfSmearedCentralValues;
20 unsigned int covarianceMatrix_dim = centralValue.size();
22 if (inputCovarianceMatrix.size() != covarianceMatrix_dim)
25 <<
"inputCovarianceMatrix rows " << inputCovarianceMatrix.size()
26 <<
" not equal to entries of centralValue[]: " << covarianceMatrix_dim;
29 for (
auto const &
row : inputCovarianceMatrix )
31 if(
row.size() != covarianceMatrix_dim)
34 <<
"inputCovarianceMatrix columns " <<
row.size()
35 <<
" not equal to entries of centralValue[]: " << covarianceMatrix_dim;
40 int dim =
int(inputCovarianceMatrix.size());
41 TMatrixD covarianceMatrix(dim,dim);
43 for (
auto const &
row : inputCovarianceMatrix)
46 for (
auto const & element :
row)
48 covarianceMatrix[i][j] = element;
55 TDecompChol dc = TDecompChol(covarianceMatrix);
59 <<
"Cannot decompose covariance matrix to begin smearing.";
60 return setOfSmearedCentralValues;
65 TMatrixD U = dc.GetU();
68 for(
int n = 0;
n < n_multisims; ++
n)
72 int dim = centralValue.size();
74 std::vector<double> rands(dim);
75 GaussRandom.fireArray(dim, rands.data());
78 std::vector<double> smearedCentralValues;
79 for(
int col = 0; col < dim; ++col)
82 double weightFromU = 0.;
85 weightFromU += U(
row,col)*rands[
row];
90 smearedCentralValues.push_back(weightFromU + centralValue[col]);
94 setOfSmearedCentralValues.push_back(smearedCentralValues);
96 return setOfSmearedCentralValues;
106 std::vector<double> smearedCentralValues;
117 TDecompChol dc = TDecompChol(*(inputCovarianceMatrix));
121 <<
"Cannot decompose covariance matrix to begin smearing.";
122 return smearedCentralValues;
127 TMatrixD U = dc.GetU();
130 for(
unsigned int col = 0; col < centralValue.size(); ++col)
133 double weightFromU = 0.;
135 for(
unsigned int row = 0;
row < col+1; ++
row)
137 weightFromU += U(
row,col)*rand[
row];
143 smearedCentralValues.push_back(weightFromU + centralValue[col]);
145 return smearedCentralValues;
159 std::vector<double>
WeightCalc::MultiGaussianSmearing(std::vector<double>
const& centralValue, TMatrixD*
const& LowerTriangleCovarianceMatrix,
bool isDecomposed, std::vector< double > rand)
163 std::vector<double> smearedCentralValues;
168 <<
"Must supply the decomposed lower triangular covariance matrix.";
169 return smearedCentralValues;
173 for(
unsigned int col = 0; col < centralValue.size(); ++col)
176 double weightFromU = 0.;
178 for(
unsigned int row = 0;
row < col+1; ++
row)
180 weightFromU += LowerTriangleCovarianceMatrix[0][
row][col]*rand[
row];
186 smearedCentralValues.push_back(weightFromU + centralValue[col]);
188 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.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception