CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/SimTracker/SiStripDigitizer/src/SiGaussianTailNoiseAdder.cc

Go to the documentation of this file.
00001 #include "SimTracker/SiStripDigitizer/interface/SiGaussianTailNoiseAdder.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00004 #include "CLHEP/Random/RandGaussQ.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 
00007 SiGaussianTailNoiseAdder::SiGaussianTailNoiseAdder(float th,CLHEP::HepRandomEngine& eng):
00008   threshold(th),
00009   rndEngine(eng),
00010   gaussDistribution(0)
00011 {
00012   genNoise = new GaussianTailNoiseGenerator(rndEngine);
00013   gaussDistribution = new CLHEP::RandGaussQ(rndEngine);
00014 }
00015 
00016 SiGaussianTailNoiseAdder::~SiGaussianTailNoiseAdder(){
00017   delete genNoise;
00018   delete gaussDistribution;
00019 }
00020 
00021 void SiGaussianTailNoiseAdder::addNoise(std::vector<double> &in,
00022                                         size_t& minChannel, size_t& maxChannel,
00023                                         int numStrips, float noiseRMS){
00024  
00025   std::vector<std::pair<int,float> > generatedNoise;
00026   genNoise->generate(numStrips,threshold,noiseRMS,generatedNoise);
00027   
00028   // noise on strips with signal:
00029   for (size_t iChannel=minChannel; iChannel<maxChannel; iChannel++) {
00030     if(in[iChannel] != 0) {
00031       in[iChannel] += gaussDistribution->fire(0.,noiseRMS);
00032     }
00033   }
00034 
00035   // Noise on the other strips
00036   typedef std::vector<std::pair<int,float> >::const_iterator VI;  
00037   for(VI p = generatedNoise.begin(); p != generatedNoise.end(); p++){
00038     if(in[(*p).first] == 0) {
00039       in[(*p).first] += (*p).second;
00040     }
00041   }
00042 }
00043 
00044 void SiGaussianTailNoiseAdder::addNoiseVR(std::vector<double> &in, std::vector<float> &noiseRMS){
00045   // Add noise
00046   // Full Gaussian noise is added everywhere
00047   for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
00048      if(noiseRMS[iChannel] > 0.) in[iChannel] += gaussDistribution->fire(0.,noiseRMS[iChannel]);
00049   }
00050 }
00051 
00052 void SiGaussianTailNoiseAdder::addPedestals(std::vector<double> &in,std::vector<float> & ped){
00053         for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
00054       if(ped[iChannel]>0.) in[iChannel] += ped[iChannel];      
00055     }
00056 }
00057 
00058 void SiGaussianTailNoiseAdder::addCMNoise(std::vector<double> &in, float cmnRMS, std::vector<bool> &badChannels){
00059   int nAPVs = in.size()/128;
00060   std::vector<float> CMNv;
00061   for(int APVn =0; APVn < nAPVs; ++APVn) CMNv.push_back(gaussDistribution->fire(0.,cmnRMS));
00062   for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
00063      if(!badChannels[iChannel]) in[iChannel] += CMNv[(int)(iChannel/128)];
00064   }
00065 }
00066 
00067 void SiGaussianTailNoiseAdder::addBaselineShift(std::vector<double> &in, std::vector<bool> &badChannels){
00068   size_t nAPVs = in.size()/128;
00069   std::vector<float> vShift;
00070   double apvCharge, apvMult;
00071   
00072   size_t iChannel;
00073   for(size_t APVn =0; APVn < nAPVs; ++APVn){
00074         apvMult=0; apvCharge=0;
00075         for(iChannel=APVn*128; iChannel!=APVn*128+128; ++iChannel) {
00076            if(in[iChannel]>0){
00077                  ++apvMult;
00078                   apvCharge+= in[iChannel];
00079            }
00080            if(apvMult==0) vShift.push_back(0);
00081            else vShift.push_back(apvCharge/apvMult);
00082         }
00083   }
00084      
00085   for (iChannel=0; iChannel!=in.size(); ++iChannel) {
00086      if(!badChannels[iChannel]) in[iChannel] -= vShift[(int)(iChannel/128)];
00087   }
00088 }
00089 
00090 
00091 
00092 
00093