61 : localEngine(&anEngine),
67 std::cerr <<
"In constructor of RandMultiGauss distribution: \n" <<
68 " Dimension of mu (" << mu.
num_row() <<
69 ") does not match dimension of S (" << S.
num_row() <<
")\n";
70 std::cerr <<
"---Exiting to System\n";
75 prepareUsigmas (S, defaultU, defaultSigmas);
81 : localEngine(anEngine),
87 std::cerr <<
"In constructor of RandMultiGauss distribution: \n" <<
88 " Dimension of mu (" << mu.
num_row() <<
89 ") does not match dimension of S (" << S.
num_row() <<
")\n";
90 std::cerr <<
"---Exiting to System\n";
95 prepareUsigmas (S, defaultU, defaultSigmas);
99 : localEngine(&anEngine),
107 defaultSigmas(1) = 1.;
108 defaultSigmas(2) = 1.;
112 : localEngine(anEngine),
120 defaultSigmas(1) = 1.;
121 defaultSigmas(2) = 1.;
125 if ( deleteEngine )
delete localEngine;
132 void RandMultiGauss::prepareUsigmas(
const HepSymMatrix & S,
141 for (
int i = 1; i <= S.
num_row(); i++) {
144 sigmas(i) = sqrt ( s2 );
146 std::cerr <<
"In RandMultiGauss distribution: \n" <<
147 " Matrix S is not positive definite. Eigenvalues are:\n";
148 for (
int ixx = 1; ixx <= S.
num_row(); ixx++) {
149 std::cerr <<
" " << D(ixx,ixx) << std::endl;
151 std::cerr <<
"---Exiting to System\n";
161 HepVector RandMultiGauss::deviates (
const HepMatrix & U,
162 const HepVector & sigmas,
163 HepRandomEngine * engine,
170 int n = sigmas.num_row();
184 v1 = 2.0 * engine->flat() - 1.0;
185 v2 = 2.0 * engine->flat() - 1.0;
188 fac = sqrt(-2.0*log(r)/r);
198 for ( i = 1; i <=
n; i++ ) {
214 return defaultMu + deviates ( defaultU, defaultSigmas,
215 localEngine, set, nextGaussian );
226 prepareUsigmas ( S, U, sigmas );
227 return mu + deviates ( U, sigmas, localEngine, set, nextGaussian );
229 std::cerr <<
"In firing RandMultiGauss distribution with explicit mu and S: \n"
230 <<
" Dimension of mu (" << mu.
num_row() <<
231 ") does not match dimension of S (" << S.
num_row() <<
")\n";
232 std::cerr <<
"---Exiting to System\n";
248 for (i = 0; i < size; ++i) {
249 array[i] = defaultMu + deviates ( defaultU, defaultSigmas,
250 localEngine, set, nextGaussian );
267 prepareUsigmas ( S, U, sigmas );
270 "In fireArray for RandMultiGauss distribution with explicit mu and S: \n"
271 <<
" Dimension of mu (" << mu.
num_row() <<
272 ") does not match dimension of S (" << S.
num_row() <<
")\n";
273 std::cerr <<
"---Exiting to System\n";
278 for (i=0; i<size; ++i) {
279 array[i] = mu_ + deviates(U, sigmas, localEngine, set, nextGaussian);
virtual int num_row() const
HepSymMatrix similarityT(const HepMatrix &hm1) const
virtual ~RandMultiGauss()
HepMatrix diagonalize(HepSymMatrix *s)
RandMultiGauss(HepRandomEngine &anEngine, const HepVector &mu, const HepSymMatrix &S)
void fireArray(const int size, HepVector *array)