CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaussNoiseProducerFP420.cc
Go to the documentation of this file.
1 // File: GaussNoiseProducerFP420.cc
3 // Date: 12.2006
4 // Description: GaussNoiseFP420 for FP420
5 // Modifications:
7 #include "CLHEP/Random/RandFlat.h"
8 #include "CLHEP/Random/RandPoisson.h"
10 #include <gsl/gsl_randist.h>
11 #include <gsl/gsl_rng.h>
12 #include <gsl/gsl_sf_erf.h>
13 #include <gsl/gsl_sf_result.h>
14 
15 extern "C" float freq_(const float &x);
16 extern "C" float gausin_(const float &x);
17 
18 void GaussNoiseProducerFP420::generate(int NumberOfchannels,
19  float threshold,
20  float noiseRMS,
21  std::map<int, float, std::less<int>> &theMap) {
22  // estimale mean number of noisy channels with amplidudes above $AdcThreshold$
23 
24  // Gauss is centered at 0 with sigma=1
25  // Gaussian tail probability higher threshold(=5sigma for instance):
26  gsl_sf_result result;
27  int status = gsl_sf_erf_Q_e(threshold, &result);
28  // MP
29  // if (status != 0) throw DetLogicError("GaussNoiseProducerFP420::could not
30  // compute gaussian tail probability for the threshold chosen");
31  if (status != 0)
32  std::cerr << "GaussNoiseProducerFP420::could not compute gaussian tail "
33  "probability for the threshold chosen"
34  << std::endl;
35  float probabilityLeft = result.val;
36 
37  // with known probability higher threshold compute number of noisy channels
38  // distributed in Poisson:
39  float meanNumberOfNoisyChannels = probabilityLeft * NumberOfchannels;
40  int numberOfNoisyChannels = CLHEP::RandPoisson::shoot(meanNumberOfNoisyChannels);
41 
42  // draw noise at random according to Gaussian tail
43 
44  // initialise default gsl uniform generator engine
45  static gsl_rng const *const mt19937 = gsl_rng_alloc(gsl_rng_mt19937);
46 
47  float lowLimit = threshold * noiseRMS;
48  for (int i = 0; i < numberOfNoisyChannels; i++) {
49  // Find a random channel number
50  int theChannelNumber = (int)CLHEP::RandFlat::shootInt(NumberOfchannels);
51 
52  // Find random noise value: random mt19937 over Gaussian tail above
53  // threshold:
54  float noise = gsl_ran_gaussian_tail(mt19937, lowLimit, noiseRMS);
55 
56  // Fill in map
57  theMap[theChannelNumber] = noise;
58  }
59 }
list status
Definition: mps_update.py:107
tuple result
Definition: mps_fire.py:311
__shared__ int noise
float freq_(const float &x)
float x
float gausin_(const float &x)
void generate(int NumberOfchannels, float threshold, float noiseRMS, std::map< int, float, std::less< int >> &theMap)