CMS 3D CMS Logo

GaussNoiseProducerFP420.cc

Go to the documentation of this file.
00001 
00002 // File: GaussNoiseProducerFP420.cc
00003 // Date: 12.2006
00004 // Description: GaussNoiseFP420 for FP420
00005 // Modifications: 
00007 #include "SimRomanPot/SimFP420/interface/GaussNoiseProducerFP420.h"
00008 #include "CLHEP/Random/RandPoisson.h"
00009 #include "CLHEP/Random/RandFlat.h"
00010 #include <gsl/gsl_sf_erf.h>
00011 #include <gsl/gsl_sf_result.h>
00012 #include <gsl/gsl_randist.h>
00013 #include <gsl/gsl_rng.h>
00014 
00015 extern "C"   float freq_(const float& x);   
00016 extern "C"   float gausin_(const float& x);
00017 
00018 void GaussNoiseProducerFP420::generate(int NumberOfchannels, 
00019                                        float threshold, 
00020                                        float noiseRMS, 
00021                                        std::map<int,float, std::less<int> >& theMap )
00022 {
00023   
00024   // estimale mean number of noisy channels with amplidudes above $AdcThreshold$
00025   
00026   // Gauss is centered at 0 with sigma=1
00027   // Gaussian tail probability higher threshold(=5sigma for instance):
00028   gsl_sf_result result;
00029   int status = gsl_sf_erf_Q_e(threshold, &result);
00030   //MP 
00031   //  if (status != 0) throw DetLogicError("GaussNoiseProducerFP420::could not compute gaussian tail probability for the threshold chosen");
00032   if (status != 0) std::cerr<<"GaussNoiseProducerFP420::could not compute gaussian tail probability for the threshold chosen"<<std::endl;
00033   float probabilityLeft = result.val;
00034   
00035   // with known probability higher threshold compute number of noisy channels distributed in Poisson:
00036   float meanNumberOfNoisyChannels = probabilityLeft * NumberOfchannels;
00037   int numberOfNoisyChannels = RandPoisson::shoot(meanNumberOfNoisyChannels);
00038   
00039   // draw noise at random according to Gaussian tail
00040   
00041   // initialise default gsl uniform generator engine
00042   static gsl_rng * mt19937 = gsl_rng_alloc (gsl_rng_mt19937);
00043   
00044   float lowLimit = threshold * noiseRMS;
00045   for (int i = 0; i < numberOfNoisyChannels; i++) {
00046     
00047     // Find a random channel number    
00048     int theChannelNumber = (int) RandFlat::shootInt(NumberOfchannels);
00049     
00050     // Find random noise value: random mt19937 over Gaussian tail above threshold:
00051     float noise = gsl_ran_gaussian_tail(mt19937, lowLimit, noiseRMS);
00052     
00053     // Fill in map
00054     theMap[theChannelNumber] = noise;
00055     
00056   }
00057 }

Generated on Tue Jun 9 17:47:52 2009 for CMSSW by  doxygen 1.5.4