CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
RandomMultiGauss Class Reference

#include <RandomMultiGauss.h>

Public Member Functions

AlgebraicVector fire ()
 
 RandomMultiGauss (const AlgebraicVector &aVector, const AlgebraicSymMatrix &aMatrix)
 
 RandomMultiGauss (const AlgebraicSymMatrix &aMatrix)
 
 ~RandomMultiGauss ()
 

Private Member Functions

void initialise (const AlgebraicSymMatrix &)
 

Private Attributes

AlgebraicVector theMeans
 
int theSize
 
AlgebraicMatrix theTriangle
 

Detailed Description

Vector of random numbers according to covariance matrix. Generates vectors of random numbers given a vector of mean values (optional) and a covariance matrix. Will accept empty rows/columns in the input matrix. Uses CLHEP::RandGauss with default engine for generation.

Definition at line 14 of file RandomMultiGauss.h.

Constructor & Destructor Documentation

◆ RandomMultiGauss() [1/2]

RandomMultiGauss::RandomMultiGauss ( const AlgebraicVector aVector,
const AlgebraicSymMatrix aMatrix 
)

constructor with explicit vector of mean values

Definition at line 9 of file RandomMultiGauss.cc.

References initialise(), theMeans, and theSize.

10  : theSize(aMatrix.num_row()), theMeans(aVector), theTriangle(theSize, theSize, 0) {
11  //
12  // Check consistency
13  //
14  if (theMeans.num_row() == theSize) {
15  initialise(aMatrix);
16  } else {
17  // throw DetLogicError("RandomMultiGauss: size of vector and matrix do not match");
19  }
20 }
AlgebraicMatrix theTriangle
void initialise(const AlgebraicSymMatrix &)
AlgebraicVector theMeans
CLHEP::HepVector AlgebraicVector

◆ RandomMultiGauss() [2/2]

RandomMultiGauss::RandomMultiGauss ( const AlgebraicSymMatrix aMatrix)

constructor with covariance matrix only (all means = 0)

Definition at line 24 of file RandomMultiGauss.cc.

References initialise().

25  : theSize(aMatrix.num_row()), theMeans(theSize, 0), theTriangle(theSize, theSize, 0) {
26  //
27  initialise(aMatrix);
28 }
AlgebraicMatrix theTriangle
void initialise(const AlgebraicSymMatrix &)
AlgebraicVector theMeans

◆ ~RandomMultiGauss()

RandomMultiGauss::~RandomMultiGauss ( )
inline

Definition at line 23 of file RandomMultiGauss.h.

23 {}

Member Function Documentation

◆ fire()

AlgebraicVector RandomMultiGauss::fire ( )

Generation of a vector of random numbers.

Definition at line 71 of file RandomMultiGauss.cc.

References mps_fire::i, theMeans, theSize, and theTriangle.

71  {
72  AlgebraicVector vRandom(theSize, 0);
73  for (int i = 0; i < theSize; i++) {
74  if (theTriangle[i][i] != 0)
75  vRandom[i] = CLHEP::RandGauss::shoot();
76  }
77  return theTriangle * vRandom + theMeans;
78 }
AlgebraicMatrix theTriangle
AlgebraicVector theMeans
CLHEP::HepVector AlgebraicVector

◆ initialise()

void RandomMultiGauss::initialise ( const AlgebraicSymMatrix aMatrix)
private

generation of the cholesky decomposition

Definition at line 32 of file RandomMultiGauss.cc.

References testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, testProducerWithPsetDescEmpty_cfi::i3, mathSSE::sqrt(), theSize, and theTriangle.

Referenced by RandomMultiGauss().

32  {
33  //
34  // Cholesky decomposition with protection against empty rows/columns
35  //
36  for (int i1 = 0; i1 < theSize; i1++) {
37  if (fabs(aMatrix[i1][i1]) < FLT_MIN)
38  continue;
39 
40  for (int i2 = i1; i2 < theSize; i2++) {
41  if (fabs(aMatrix[i2][i2]) < FLT_MIN)
42  continue;
43 
44  double sum = aMatrix[i2][i1];
45  for (int i3 = i1 - 1; i3 >= 0; i3--) {
46  if (fabs(aMatrix[i3][i3]) < FLT_MIN)
47  continue;
48  sum -= theTriangle[i1][i3] * theTriangle[i2][i3];
49  }
50 
51  if (i1 == i2) {
52  //
53  // check for positive definite input matrix, but allow for effects
54  // due to finite precision
55  //
56  if (sum <= 0) {
57  // if ( sum<-FLT_MIN ) throw DetLogicError("RandomMultiGauss: input matrix is not positive definite");
58  sum = FLT_MIN;
59  }
60  theTriangle[i1][i1] = sqrt(sum);
61  } else {
62  theTriangle[i1][i2] = 0.;
63  theTriangle[i2][i1] = sum / theTriangle[i1][i1];
64  }
65  }
66  }
67 }
AlgebraicMatrix theTriangle
T sqrt(T t)
Definition: SSEVec.h:19

Member Data Documentation

◆ theMeans

AlgebraicVector RandomMultiGauss::theMeans
private

Definition at line 35 of file RandomMultiGauss.h.

Referenced by fire(), and RandomMultiGauss().

◆ theSize

int RandomMultiGauss::theSize
private

Definition at line 34 of file RandomMultiGauss.h.

Referenced by fire(), initialise(), and RandomMultiGauss().

◆ theTriangle

AlgebraicMatrix RandomMultiGauss::theTriangle
private

Definition at line 36 of file RandomMultiGauss.h.

Referenced by fire(), and initialise().