CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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:
8 #include "CLHEP/Random/RandPoisson.h"
9 #include "CLHEP/Random/RandFlat.h"
10 #include <gsl/gsl_sf_erf.h>
11 #include <gsl/gsl_sf_result.h>
12 #include <gsl/gsl_randist.h>
13 #include <gsl/gsl_rng.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 {
23 
24  // estimale mean number of noisy channels with amplidudes above $AdcThreshold$
25 
26  // Gauss is centered at 0 with sigma=1
27  // Gaussian tail probability higher threshold(=5sigma for instance):
28  gsl_sf_result result;
29  int status = gsl_sf_erf_Q_e(threshold, &result);
30  //MP
31  // if (status != 0) throw DetLogicError("GaussNoiseProducerFP420::could not compute gaussian tail probability for the threshold chosen");
32  if (status != 0) std::cerr<<"GaussNoiseProducerFP420::could not compute gaussian tail probability for the threshold chosen"<<std::endl;
33  float probabilityLeft = result.val;
34 
35  // with known probability higher threshold compute number of noisy channels distributed in Poisson:
36  float meanNumberOfNoisyChannels = probabilityLeft * NumberOfchannels;
37  int numberOfNoisyChannels = CLHEP::RandPoisson::shoot(meanNumberOfNoisyChannels);
38 
39  // draw noise at random according to Gaussian tail
40 
41  // initialise default gsl uniform generator engine
42  static gsl_rng const * const mt19937 = gsl_rng_alloc (gsl_rng_mt19937);
43 
44  float lowLimit = threshold * noiseRMS;
45  for (int i = 0; i < numberOfNoisyChannels; i++) {
46 
47  // Find a random channel number
48  int theChannelNumber = (int) CLHEP::RandFlat::shootInt(NumberOfchannels);
49 
50  // Find random noise value: random mt19937 over Gaussian tail above threshold:
51  float noise = gsl_ran_gaussian_tail(mt19937, lowLimit, noiseRMS);
52 
53  // Fill in map
54  theMap[theChannelNumber] = noise;
55 
56  }
57 }
int i
Definition: DBlmapReader.cc:9
T x() const
Cartesian x coordinate.
tuple result
Definition: query.py:137
float freq_(const float &x)
void generate(int NumberOfchannels, float threshold, float noiseRMS, std::map< int, float, std::less< int > > &theMap)
float gausin_(const float &x)
tuple status
Definition: ntuplemaker.py:245