#include <SimGeneral/NoiseGenerators/interface/CorrelatedNoisifier.h>
Public Member Functions | |
void | computeDecomposition () |
CorrelatedNoisifier (M &matrix, CLHEP::HepRandomEngine &engine) | |
CorrelatedNoisifier (M &matrix) | |
const M & | covmatrix () |
template<class T> | |
void | noisify (T &frame) |
void | setDiagonal (double value) |
sets all elements along the diagonal of the correlation matrix to be value | |
void | setOffDiagonal (int neighbor, double value) |
void | setRandomEngine (CLHEP::HepRandomEngine &engine) |
void | setRandomEngine () |
virtual | ~CorrelatedNoisifier () |
Private Member Functions | |
void | checkOffDiagonal () |
void | init () |
Private Attributes | |
bool | isDiagonal_ |
bool | isIdentity_ |
const M | theCovarianceMatrix |
M | theMatrix |
RandGaussQ * | theRandomGaussian |
unsigned int | theSize |
Definition at line 23 of file CorrelatedNoisifier.h.
CorrelatedNoisifier< M >::CorrelatedNoisifier | ( | M & | matrix | ) | [inline, explicit] |
Definition at line 115 of file CorrelatedNoisifier.h.
References CorrelatedNoisifier< M >::init(), and CorrelatedNoisifier< M >::setRandomEngine().
00116 : theCovarianceMatrix(matrix), 00117 theRandomGaussian(0), 00118 theSize(matrix.kRows), 00119 isDiagonal_(true), 00120 isIdentity_(true) 00121 { 00122 init(); 00123 setRandomEngine(); 00124 }
CorrelatedNoisifier< M >::CorrelatedNoisifier | ( | M & | matrix, | |
CLHEP::HepRandomEngine & | engine | |||
) | [inline] |
Definition at line 127 of file CorrelatedNoisifier.h.
References CorrelatedNoisifier< M >::init(), and CorrelatedNoisifier< M >::setRandomEngine().
00128 : theCovarianceMatrix(matrix), 00129 theRandomGaussian(0), 00130 theSize(matrix.kRows), 00131 isDiagonal_(true), 00132 isIdentity_(true) 00133 { 00134 init(); 00135 setRandomEngine(engine); 00136 }
virtual CorrelatedNoisifier< M >::~CorrelatedNoisifier | ( | ) | [inline, virtual] |
void CorrelatedNoisifier< M >::checkOffDiagonal | ( | ) | [inline, private] |
Definition at line 251 of file CorrelatedNoisifier.h.
References Exception, false, i, CorrelatedNoisifier< M >::isDiagonal_, CorrelatedNoisifier< M >::isIdentity_, j, CorrelatedNoisifier< M >::theCovarianceMatrix, and CorrelatedNoisifier< M >::theSize.
Referenced by CorrelatedNoisifier< M >::init(), CorrelatedNoisifier< M >::setDiagonal(), and CorrelatedNoisifier< M >::setOffDiagonal().
00251 { 00252 00253 isDiagonal_ = true; 00254 isIdentity_ = true; 00255 00256 for ( unsigned int i = 0 ; i < theSize ; i++ ) { 00257 for ( unsigned int j = 0 ; j < theSize ; j++ ) { 00258 if ( i == j ) 00259 { 00260 if( theCovarianceMatrix(i,j) != 1.) 00261 { 00262 isIdentity_ = false; 00263 } 00264 if( theCovarianceMatrix(i,j) < 0.) 00265 { 00266 throw cms::Exception("CorrelatedNoisifier") 00267 << "Bad correlation matrix. Negative diagonal"; 00268 } 00269 } 00270 if ( i != j && theCovarianceMatrix(i,j) != 0. ) 00271 { 00272 isDiagonal_ = false ; 00273 isIdentity_ = false; 00274 return ; 00275 } 00276 } 00277 } 00278 00279 }
void CorrelatedNoisifier< M >::computeDecomposition | ( | ) | [inline] |
Definition at line 207 of file CorrelatedNoisifier.h.
References Exception, i, j, k, funct::sqrt(), CorrelatedNoisifier< M >::theCovarianceMatrix, CorrelatedNoisifier< M >::theMatrix, and CorrelatedNoisifier< M >::theSize.
Referenced by CorrelatedNoisifier< M >::init(), CorrelatedNoisifier< M >::setDiagonal(), and CorrelatedNoisifier< M >::setOffDiagonal().
00208 { 00209 00210 for ( unsigned int i = 0 ; i < theSize ; i++ ) { 00211 for ( unsigned int j = 0 ; j < theSize ; j++ ) { 00212 theMatrix(i,j) = 0.; 00213 } 00214 } 00215 00216 double sqrtSigma00 = theCovarianceMatrix(0,0); 00217 if ( sqrtSigma00 <= 0. ) { 00218 throw cms::Exception("CorrelatedNoisifier") << "non positive variance."; 00219 } 00220 sqrtSigma00 = std::sqrt(sqrtSigma00); 00221 00222 for ( unsigned int i = 0 ; i < theSize ; i++ ) 00223 { 00224 double hi0 = theCovarianceMatrix(i,0)/sqrtSigma00; 00225 theMatrix(i,0) = hi0; 00226 } 00227 00228 for ( unsigned int i = 1 ; i < theSize ; i++ ) 00229 { 00230 00231 for ( unsigned int j = 1 ; j < i ; j++ ) 00232 { 00233 double hij = theCovarianceMatrix(i,j); 00234 for ( unsigned int k = 0 ; k <= j-1 ; k++ ) hij -= theMatrix(i,k)*theMatrix(j,k); 00235 hij /= theMatrix(j,j); 00236 theMatrix(i,j) = hij; 00237 } 00238 00239 double hii = theCovarianceMatrix(i,i); 00240 for ( unsigned int j = 0 ; j <= i-1 ; j++ ) { 00241 double hij = theMatrix(i,j); 00242 hii -= hij*hij; 00243 } 00244 hii = sqrt(hii); 00245 theMatrix(i,i) = hii; 00246 00247 } 00248 }
const M& CorrelatedNoisifier< M >::covmatrix | ( | ) | [inline] |
Definition at line 91 of file CorrelatedNoisifier.h.
00091 { 00092 return theCovarianceMatrix; 00093 }
void CorrelatedNoisifier< M >::init | ( | void | ) | [inline, private] |
Definition at line 140 of file CorrelatedNoisifier.h.
References CorrelatedNoisifier< M >::checkOffDiagonal(), CorrelatedNoisifier< M >::computeDecomposition(), i, CorrelatedNoisifier< M >::isDiagonal_, j, CorrelatedNoisifier< M >::theMatrix, and CorrelatedNoisifier< M >::theSize.
Referenced by CorrelatedNoisifier< M >::CorrelatedNoisifier().
00141 { 00142 for ( unsigned int i = 0 ; i < theSize ; i++ ) { 00143 theMatrix(i,i) = 0.; 00144 for ( unsigned int j = 0 ; j < theSize ; j++ ) { 00145 theMatrix(i,j) = 0.; 00146 theMatrix(j,i) = 0.; 00147 } 00148 } 00149 00150 checkOffDiagonal(); 00151 00152 if ( ! isDiagonal_ ) computeDecomposition(); 00153 }
Definition at line 42 of file CorrelatedNoisifier.h.
Referenced by CSCStripConditions::noisify().
00043 { 00044 // make a vector of random values 00045 assert(frame.size() == theSize); 00046 std::valarray<double> uncorrelated(0.,theSize); 00047 for (unsigned int i=0; i<theSize; i++) 00048 uncorrelated[i]=theRandomGaussian->fire(); 00049 if ( isIdentity_ ) 00050 { 00051 for(unsigned int i = 0; i < theSize; ++i) 00052 { 00053 frame[i] += uncorrelated[i]; 00054 } 00055 } 00056 else if ( isDiagonal_ ) 00057 { 00058 for(unsigned int i = 0; i < theSize; ++i) 00059 { 00060 frame[i] += uncorrelated[i] * std::sqrt(theCovarianceMatrix(i,i)); 00061 } 00062 } 00063 else 00064 { 00065 00066 // rotate them to make a correlated noise vector 00067 //std::valarray<double> correlated = theMatrix * uncorrelated; 00068 std::valarray<double> correlated(0., theSize); 00069 for (unsigned int i = 0; i < theSize; ++i) 00070 { 00071 //@@ Not sure why the old version only used the lower half, but it worked 00072 for (unsigned int j = 0; j <= i; ++j) 00073 { 00074 correlated[i] += theMatrix(i,j)*uncorrelated[j]; 00075 } 00076 } 00077 00078 // stuff 'em in the frame 00079 for(unsigned int i = 0; i < theSize; ++i) 00080 { 00081 frame[i] += correlated[i]; 00082 } 00083 } 00084 }
void CorrelatedNoisifier< M >::setDiagonal | ( | double | value | ) | [inline] |
sets all elements along the diagonal of the correlation matrix to be value
Definition at line 176 of file CorrelatedNoisifier.h.
References CorrelatedNoisifier< M >::checkOffDiagonal(), CorrelatedNoisifier< M >::computeDecomposition(), i, CorrelatedNoisifier< M >::isDiagonal_, CorrelatedNoisifier< M >::theCovarianceMatrix, and CorrelatedNoisifier< M >::theSize.
00177 { 00178 for(unsigned int i = 0; i < theSize; ++i) 00179 { 00180 theCovarianceMatrix(i,i) = value; 00181 } 00182 00183 checkOffDiagonal(); 00184 00185 if ( ! isDiagonal_ ) computeDecomposition(); 00186 00187 }
void CorrelatedNoisifier< M >::setOffDiagonal | ( | int | neighbor, | |
double | value | |||
) | [inline] |
Definition at line 189 of file CorrelatedNoisifier.h.
References CorrelatedNoisifier< M >::checkOffDiagonal(), CorrelatedNoisifier< M >::computeDecomposition(), CorrelatedNoisifier< M >::isDiagonal_, row, CorrelatedNoisifier< M >::theCovarianceMatrix, and CorrelatedNoisifier< M >::theSize.
00190 { 00191 for(unsigned int column = 0; column < theSize; ++column) 00192 { 00193 unsigned int row = column - distance; 00194 if(row < 0) continue; 00195 theCovarianceMatrix(row,column) = value; 00196 theCovarianceMatrix(column,row) = value; 00197 00198 } 00199 00200 checkOffDiagonal(); 00201 00202 if ( ! isDiagonal_ ) computeDecomposition(); 00203 00204 }
void CorrelatedNoisifier< M >::setRandomEngine | ( | CLHEP::HepRandomEngine & | engine | ) | [inline] |
Definition at line 169 of file CorrelatedNoisifier.h.
References CorrelatedNoisifier< M >::theRandomGaussian.
00170 { 00171 if(theRandomGaussian) delete theRandomGaussian; 00172 theRandomGaussian = new CLHEP::RandGaussQ(engine); 00173 }
void CorrelatedNoisifier< M >::setRandomEngine | ( | ) | [inline] |
Definition at line 156 of file CorrelatedNoisifier.h.
References Exception, and edm::Service< T >::isAvailable().
Referenced by CorrelatedNoisifier< M >::CorrelatedNoisifier().
00157 { 00158 edm::Service<edm::RandomNumberGenerator> rng; 00159 if ( ! rng.isAvailable()) { 00160 throw cms::Exception("Configuration") 00161 << "CorrelatedNoisifier requires the RandomNumberGeneratorService\n" 00162 "which is not present in the configuration file. You must add the service\n" 00163 "in the configuration file or remove the modules that require it."; 00164 } 00165 setRandomEngine(rng->getEngine()); 00166 }
bool CorrelatedNoisifier< M >::isDiagonal_ [private] |
Definition at line 103 of file CorrelatedNoisifier.h.
Referenced by CorrelatedNoisifier< M >::checkOffDiagonal(), CorrelatedNoisifier< M >::init(), CorrelatedNoisifier< math::ErrorD< CaloSamples::MAXSAMPLES >::type >::noisify(), CorrelatedNoisifier< M >::setDiagonal(), and CorrelatedNoisifier< M >::setOffDiagonal().
bool CorrelatedNoisifier< M >::isIdentity_ [private] |
Definition at line 104 of file CorrelatedNoisifier.h.
Referenced by CorrelatedNoisifier< M >::checkOffDiagonal(), and CorrelatedNoisifier< math::ErrorD< CaloSamples::MAXSAMPLES >::type >::noisify().
const M CorrelatedNoisifier< M >::theCovarianceMatrix [private] |
Definition at line 99 of file CorrelatedNoisifier.h.
Referenced by CorrelatedNoisifier< M >::checkOffDiagonal(), CorrelatedNoisifier< M >::computeDecomposition(), CorrelatedNoisifier< math::ErrorD< CaloSamples::MAXSAMPLES >::type >::covmatrix(), CorrelatedNoisifier< math::ErrorD< CaloSamples::MAXSAMPLES >::type >::noisify(), CorrelatedNoisifier< M >::setDiagonal(), and CorrelatedNoisifier< M >::setOffDiagonal().
M CorrelatedNoisifier< M >::theMatrix [private] |
Definition at line 100 of file CorrelatedNoisifier.h.
Referenced by CorrelatedNoisifier< M >::computeDecomposition(), CorrelatedNoisifier< M >::init(), and CorrelatedNoisifier< math::ErrorD< CaloSamples::MAXSAMPLES >::type >::noisify().
RandGaussQ* CorrelatedNoisifier< M >::theRandomGaussian [mutable, private] |
unsigned int CorrelatedNoisifier< M >::theSize [private] |
Definition at line 102 of file CorrelatedNoisifier.h.
Referenced by CorrelatedNoisifier< M >::checkOffDiagonal(), CorrelatedNoisifier< M >::computeDecomposition(), CorrelatedNoisifier< M >::init(), CorrelatedNoisifier< math::ErrorD< CaloSamples::MAXSAMPLES >::type >::noisify(), CorrelatedNoisifier< M >::setDiagonal(), and CorrelatedNoisifier< M >::setOffDiagonal().