CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Private Attributes
GaussianTailNoiseGenerator Class Reference

#include <GaussianTailNoiseGenerator.h>

Public Member Functions

 GaussianTailNoiseGenerator (CLHEP::HepRandomEngine &eng)
 
void generate (int NumberOfchannels, float threshold, float noiseRMS, std::map< int, float > &theMap)
 
void generate (int NumberOfchannels, float threshold, float noiseRMS, std::vector< std::pair< int, float > > &)
 
void generateRaw (float noiseRMS, std::vector< double > &)
 

Protected Member Functions

double generate_gaussian_tail (const double, const double)
 
int * getRandomChannels (int, int)
 

Private Attributes

int channel512_ [512]
 
int channel768_ [768]
 
CLHEP::RandFlat flatDistribution_
 
CLHEP::RandGaussQ gaussDistribution_
 
CLHEP::RandPoissonQ poissonDistribution_
 

Detailed Description

Generation of random noise on "numberOfChannels" channels with a given threshold. The generated noise :

Initial author : Veronique Lefebure 08.10.98
according to the FORTRAN code tgreset.F from Pascal Vanlaer
Modified by C. Delaere 01.10.09

Fills in a map < channel number, generated noise >

Definition at line 29 of file GaussianTailNoiseGenerator.h.

Constructor & Destructor Documentation

GaussianTailNoiseGenerator::GaussianTailNoiseGenerator ( CLHEP::HepRandomEngine &  eng)

Definition at line 11 of file GaussianTailNoiseGenerator.cc.

References channel512_, channel768_, and i.

11  :
12  gaussDistribution_(eng),
15 {
16  // we have two cases: 512 and 768 channels
17  // other cases are not allowed so far (performances issue)
18  for(unsigned int i=0;i<512;++i) channel512_[i]=i;
19  for(unsigned int i=0;i<768;++i) channel768_[i]=i;
20 }
int i
Definition: DBlmapReader.cc:9

Member Function Documentation

void GaussianTailNoiseGenerator::generate ( int  NumberOfchannels,
float  threshold,
float  noiseRMS,
std::map< int, float > &  theMap 
)
void GaussianTailNoiseGenerator::generate ( int  NumberOfchannels,
float  threshold,
float  noiseRMS,
std::vector< std::pair< int, float > > &  theVector 
)

Definition at line 54 of file GaussianTailNoiseGenerator.cc.

References dtNoiseDBValidation_cfg::cerr, generate_gaussian_tail(), getRandomChannels(), i, poissonDistribution_, and query::result.

57  {
58  // Compute number of channels with noise above threshold
59  // Gaussian tail probability
60  gsl_sf_result result;
61  int status = gsl_sf_erf_Q_e(threshold, &result);
62  if (status != 0) std::cerr<<"GaussianTailNoiseGenerator::could not compute gaussian tail probability for the threshold chosen"<<std::endl;
63  double probabilityLeft = result.val;
64  double meanNumberOfNoisyChannels = probabilityLeft * NumberOfchannels;
65  int numberOfNoisyChannels = poissonDistribution_.fire(meanNumberOfNoisyChannels);
66  if(numberOfNoisyChannels>NumberOfchannels) numberOfNoisyChannels=NumberOfchannels;
67 
68  // Compute the list of noisy channels
69  theVector.reserve(numberOfNoisyChannels);
70  float lowLimit = threshold * noiseRMS;
71  int* channels = getRandomChannels(numberOfNoisyChannels,NumberOfchannels);
72 
73  for (int i = 0; i < numberOfNoisyChannels; i++) {
74  // Find random noise value
75  double noise = generate_gaussian_tail(lowLimit, noiseRMS);
76  // Fill in the vector
77  theVector.push_back(std::pair<int, float>(channels[i], noise));
78  }
79 }
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: query.py:137
double generate_gaussian_tail(const double, const double)
tuple status
Definition: ntuplemaker.py:245
double GaussianTailNoiseGenerator::generate_gaussian_tail ( const double  a,
const double  sigma 
)
protected

Definition at line 127 of file GaussianTailNoiseGenerator.cc.

References flatDistribution_, gaussDistribution_, create_public_lumi_plots::log, alignCSCRings::s, mathSSE::sqrt(), findQualityFiles::v, and x.

Referenced by generate().

127  {
128  /* Returns a gaussian random variable larger than a
129  * This implementation does one-sided upper-tailed deviates.
130  */
131 
132  double s = a/sigma;
133 
134  if (s < 1){
135  /*
136  For small s, use a direct rejection method. The limit s < 1
137  can be adjusted to optimise the overall efficiency
138  */
139  double x;
140 
141  do{
142  x = gaussDistribution_.fire(0.,1.0);
143  }
144  while (x < s);
145  return x * sigma;
146 
147  }else{
148 
149  /* Use the "supertail" deviates from the last two steps
150  * of Marsaglia's rectangle-wedge-tail method, as described
151  * in Knuth, v2, 3rd ed, pp 123-128. (See also exercise 11, p139,
152  * and the solution, p586.)
153  */
154 
155  double u, v, x;
156 
157  do{
158  u = flatDistribution_.fire();
159  do{
160  v = flatDistribution_.fire();
161  }while (v == 0.0);
162  x = sqrt(s * s - 2 * log(v));
163  }
164  while (x * u > s);
165  return x * sigma;
166  }
167 }
T sqrt(T t)
Definition: SSEVec.h:48
double a
Definition: hdecay.h:121
Definition: DDAxes.h:10
void GaussianTailNoiseGenerator::generateRaw ( float  noiseRMS,
std::vector< double > &  theVector 
)

Definition at line 97 of file GaussianTailNoiseGenerator.cc.

References gaussDistribution_, and i.

98  {
99  // it was shown that a complex approach, inspired from the ZS case,
100  // does not allow to gain much.
101  // A cut at 2 sigmas only saves 25% of the processing time, while the cost
102  // in terms of meaning is huge.
103  // We therefore use here the trivial approach (as in the early 2XX cycle)
104  unsigned int numberOfchannels = theVector.size();
105  for (unsigned int i = 0; i < numberOfchannels; ++i) {
106  if(theVector[i]==0) theVector[i] = gaussDistribution_.fire(0.,noiseRMS);
107  }
108 }
int i
Definition: DBlmapReader.cc:9
int * GaussianTailNoiseGenerator::getRandomChannels ( int  numberOfNoisyChannels,
int  numberOfchannels 
)
protected

Definition at line 111 of file GaussianTailNoiseGenerator.cc.

References b, channel512_, channel768_, flatDistribution_, and j.

Referenced by generate().

111  {
112  if(numberOfNoisyChannels>numberOfchannels) numberOfNoisyChannels = numberOfchannels;
113  int* array = channel512_;
114  if(numberOfchannels==768) array = channel768_;
115  int theChannelNumber;
116  for(int j=0;j<numberOfNoisyChannels;++j) {
117  theChannelNumber = (int)flatDistribution_.fire(numberOfchannels-j)+j;
118  // swap the two array elements... this is optimized by the compiler
119  int b = array[j];
120  array[j] = array[theChannelNumber];
121  array[theChannelNumber] = b;
122  }
123  return array;
124 }
int j
Definition: DBlmapReader.cc:9
double b
Definition: hdecay.h:120

Member Data Documentation

int GaussianTailNoiseGenerator::channel512_[512]
private

Definition at line 66 of file GaussianTailNoiseGenerator.h.

Referenced by GaussianTailNoiseGenerator(), and getRandomChannels().

int GaussianTailNoiseGenerator::channel768_[768]
private

Definition at line 67 of file GaussianTailNoiseGenerator.h.

Referenced by GaussianTailNoiseGenerator(), and getRandomChannels().

CLHEP::RandFlat GaussianTailNoiseGenerator::flatDistribution_
private

Definition at line 65 of file GaussianTailNoiseGenerator.h.

Referenced by generate_gaussian_tail(), and getRandomChannels().

CLHEP::RandGaussQ GaussianTailNoiseGenerator::gaussDistribution_
private

Definition at line 63 of file GaussianTailNoiseGenerator.h.

Referenced by generate_gaussian_tail(), and generateRaw().

CLHEP::RandPoissonQ GaussianTailNoiseGenerator::poissonDistribution_
private

Definition at line 64 of file GaussianTailNoiseGenerator.h.

Referenced by generate().