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 ()
 
void generate (int NumberOfchannels, float threshold, float noiseRMS, std::map< int, float > &theMap, CLHEP::HepRandomEngine *)
 
void generate (int NumberOfchannels, float threshold, float noiseRMS, std::vector< std::pair< int, float > > &, CLHEP::HepRandomEngine *)
 
void generateRaw (float noiseRMS, std::vector< double > &, CLHEP::HepRandomEngine *)
 

Protected Member Functions

double generate_gaussian_tail (const double, const double, CLHEP::HepRandomEngine *)
 
int * getRandomChannels (int, int, CLHEP::HepRandomEngine *)
 

Private Attributes

int channel512_ [512]
 
int channel768_ [768]
 

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 24 of file GaussianTailNoiseGenerator.h.

Constructor & Destructor Documentation

GaussianTailNoiseGenerator::GaussianTailNoiseGenerator ( )

Definition at line 11 of file GaussianTailNoiseGenerator.cc.

References channel512_, channel768_, and i.

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

Member Function Documentation

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

Definition at line 53 of file GaussianTailNoiseGenerator.cc.

References dtNoiseDBValidation_cfg::cerr, generate_gaussian_tail(), getRandomChannels(), i, HLT_25ns14e33_v1_cff::noise, 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 
66  CLHEP::RandPoissonQ randPoissonQ(*engine, meanNumberOfNoisyChannels);
67  int numberOfNoisyChannels = randPoissonQ.fire();
68 
69  if(numberOfNoisyChannels>NumberOfchannels) numberOfNoisyChannels=NumberOfchannels;
70 
71  // Compute the list of noisy channels
72  theVector.reserve(numberOfNoisyChannels);
73  float lowLimit = threshold * noiseRMS;
74  int* channels = getRandomChannels(numberOfNoisyChannels,NumberOfchannels, engine);
75 
76  for (int i = 0; i < numberOfNoisyChannels; i++) {
77  // Find random noise value
78  double noise = generate_gaussian_tail(lowLimit, noiseRMS, engine);
79  // Fill in the vector
80  theVector.push_back(std::pair<int, float>(channels[i], noise));
81  }
82 }
int i
Definition: DBlmapReader.cc:9
double generate_gaussian_tail(const double, const double, CLHEP::HepRandomEngine *)
tuple result
Definition: query.py:137
int * getRandomChannels(int, int, CLHEP::HepRandomEngine *)
tuple status
Definition: ntuplemaker.py:245
double GaussianTailNoiseGenerator::generate_gaussian_tail ( const double  a,
const double  sigma,
CLHEP::HepRandomEngine *  engine 
)
protected

Definition at line 132 of file GaussianTailNoiseGenerator.cc.

References cmsBatch::log, alignCSCRings::s, mathSSE::sqrt(), findQualityFiles::v, and x.

Referenced by generate().

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

Definition at line 101 of file GaussianTailNoiseGenerator.cc.

References i.

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

Definition at line 116 of file GaussianTailNoiseGenerator.cc.

References b, channel512_, channel768_, and j.

Referenced by generate().

116  {
117  if(numberOfNoisyChannels>numberOfchannels) numberOfNoisyChannels = numberOfchannels;
118  int* array = channel512_;
119  if(numberOfchannels==768) array = channel768_;
120  int theChannelNumber;
121  for(int j=0;j<numberOfNoisyChannels;++j) {
122  theChannelNumber = (int)CLHEP::RandFlat::shoot(engine, numberOfchannels-j) + j;
123  // swap the two array elements... this is optimized by the compiler
124  int b = array[j];
125  array[j] = array[theChannelNumber];
126  array[theChannelNumber] = b;
127  }
128  return array;
129 }
int j
Definition: DBlmapReader.cc:9
double b
Definition: hdecay.h:120

Member Data Documentation

int GaussianTailNoiseGenerator::channel512_[512]
private

Definition at line 62 of file GaussianTailNoiseGenerator.h.

Referenced by GaussianTailNoiseGenerator(), and getRandomChannels().

int GaussianTailNoiseGenerator::channel768_[768]
private

Definition at line 63 of file GaussianTailNoiseGenerator.h.

Referenced by GaussianTailNoiseGenerator(), and getRandomChannels().