48#include "CLHEP/RandomObjects/RandMultiGauss.h"
49#include "CLHEP/RandomObjects/defs.h"
62 : localEngine(&anEngine),
68 std::cerr <<
"In constructor of RandMultiGauss distribution: \n" <<
69 " Dimension of mu (" << mu.
num_row() <<
70 ") does not match dimension of S (" << S.
num_row() <<
")\n";
71 std::cerr <<
"---Exiting to System\n";
76 prepareUsigmas (S, defaultU, defaultSigmas);
82 : localEngine(anEngine),
88 std::cerr <<
"In constructor of RandMultiGauss distribution: \n" <<
89 " Dimension of mu (" << mu.
num_row() <<
90 ") does not match dimension of S (" << S.
num_row() <<
")\n";
91 std::cerr <<
"---Exiting to System\n";
96 prepareUsigmas (S, defaultU, defaultSigmas);
100 : localEngine(&anEngine),
108 defaultSigmas(1) = 1.;
109 defaultSigmas(2) = 1.;
113 : localEngine(anEngine),
121 defaultSigmas(1) = 1.;
122 defaultSigmas(2) = 1.;
126 if ( deleteEngine )
delete localEngine;
133void RandMultiGauss::prepareUsigmas(
const HepSymMatrix & S,
142 for (
int i = 1; i <= S.
num_row(); i++) {
145 sigmas(i) = sqrt ( s2 );
147 std::cerr <<
"In RandMultiGauss distribution: \n" <<
148 " Matrix S is not positive definite. Eigenvalues are:\n";
149 for (
int ixx = 1; ixx <= S.
num_row(); ixx++) {
150 std::cerr <<
" " <<
D(ixx,ixx) << std::endl;
152 std::cerr <<
"---Exiting to System\n";
162HepVector RandMultiGauss::deviates (
const HepMatrix & U,
163 const HepVector & sigmas,
164 HepRandomEngine * engine,
171 int n = sigmas.num_row();
185 v1 = 2.0 * engine->flat() - 1.0;
186 v2 = 2.0 * engine->flat() - 1.0;
189 fac = sqrt(-2.0*log(r)/r);
199 for ( i = 1; i <=
n; i++ ) {
215 return defaultMu + deviates ( defaultU, defaultSigmas,
216 localEngine, set, nextGaussian );
227 prepareUsigmas ( S, U, sigmas );
228 return mu + deviates ( U, sigmas, localEngine, set, nextGaussian );
230 std::cerr <<
"In firing RandMultiGauss distribution with explicit mu and S: \n"
231 <<
" Dimension of mu (" << mu.
num_row() <<
232 ") does not match dimension of S (" << S.
num_row() <<
")\n";
233 std::cerr <<
"---Exiting to System\n";
249 for (i = 0; i < size; ++i) {
250 array[i] = defaultMu + deviates ( defaultU, defaultSigmas,
251 localEngine, set, nextGaussian );
268 prepareUsigmas ( S, U, sigmas );
271 "In fireArray for RandMultiGauss distribution with explicit mu and S: \n"
272 <<
" Dimension of mu (" << mu.
num_row() <<
273 ") does not match dimension of S (" << S.
num_row() <<
")\n";
274 std::cerr <<
"---Exiting to System\n";
279 for (i=0; i<size; ++i) {
280 array[i] = mu_ + deviates(U, sigmas, localEngine, set, nextGaussian);
HepSymMatrix similarityT(const HepMatrix &hm1) const
virtual int num_row() const
void fireArray(const int size, HepVector *array)
RandMultiGauss(HepRandomEngine &anEngine, const HepVector &mu, const HepSymMatrix &S)
virtual ~RandMultiGauss()
HepMatrix diagonalize(HepSymMatrix *s)