CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/SimRomanPot/SimFP420/src/GaussNoiseFP420.cc

Go to the documentation of this file.
00001 
00002 // File: GaussNoiseFP420.cc
00003 // Date: 12.2006
00004 // Description: GaussNoiseFP420 for FP420
00005 // Modifications: 
00007 #include "SimRomanPot/SimFP420/interface/GaussNoiseFP420.h"
00008 #include "SimRomanPot/SimFP420/interface/GaussNoiseProducerFP420.h"
00009 #include "CLHEP/Random/RandGauss.h"
00010 
00011 GaussNoiseFP420::GaussNoiseFP420(int ns, float nrms, float th, bool aNpixel, int verbosity):
00012   numPixels(ns), noiseRMS(nrms), threshold(th), addNoisyPixels(aNpixel), verbosi(verbosity){}
00013 
00014 
00015 PileUpFP420::signal_map_type 
00016 GaussNoiseFP420::addNoise(PileUpFP420::signal_map_type in){
00017   
00018   PileUpFP420::signal_map_type _signal;  
00019   
00020   // Add noise on non-hit pixels
00021   std::map<int,float,std::less<int> > generatedNoise;
00022   
00023   //  int numberOfPixels = (numRows * numColumns);// numPixels=numberOfPixels
00024   
00025   
00026   GaussNoiseProducerFP420 gen;
00027   gen.generate(numPixels,threshold,noiseRMS,generatedNoise);// threshold is thePixelThreshold
00028   
00029   // noise for channels with signal:
00030   // ----------------------------
00031   
00032   for (PileUpFP420::signal_map_type::const_iterator si  = in.begin();
00033        si != in.end()  ; si++){
00034     
00035     if(verbosi>0) {
00036       std::cout << " ***GaussNoiseFP420:  before noise:" << std::endl;
00037       std::cout << " for si->first=  " << si->first  << "    _signal[si->first]=  " << _signal[si->first] << "        si->second=      " << si->second  << std::endl;
00038     }
00039     // define Gaussian noise centered at 0. with sigma = noiseRMS:
00040     float noise( CLHEP::RandGauss::shoot(0.,noiseRMS) );           
00041     //    float noise  = CLHEP::RandGaussQ::shoot(0.,theNoiseInElectrons) ;
00042     // add noise to each channel with signal:
00043     _signal[si->first] = si->second + noise;
00044     
00045     if(verbosi>0) {
00046       std::cout << " ***GaussNoiseFP420: after noise added  = " << noise  << std::endl;
00047       std::cout << "after noise added the _signal[si->first]=  " << _signal[si->first] << std::endl;
00048     }
00049   }
00050   
00051   //                                                                                                    //
00052   if(addNoisyPixels){  // Option to skip noise in non-hit pixels
00053     // Noise on the other channels:
00054     typedef std::map<int,float,std::less<int> >::iterator MI;
00055     for(MI p = generatedNoise.begin(); p != generatedNoise.end(); p++){
00056       if(_signal[(*p).first] == 0) {
00057         _signal[(*p).first] += (*p).second;
00058       }
00059     }//for(MI
00060   }
00061   
00062   // or:
00063   //                                                                        //
00064   /*
00065     if(addNoisyPixels){  // Option to skip noise in non-hit pixels
00066     // Noise on the other channels:
00067     typedef std::map<int,float,std::less<int> >::iterator MI;
00068     for(MI p = generatedNoise.begin(); p != generatedNoise.end(); p++){
00069     int iy = ((*p).first) / numRows;
00070     int ix = ((*p).first) - (iy*numRows);
00071     // Keep for a while for testing.
00072     if( iy < 0 || iy > (numColumns-1) ) 
00073     LogWarning ("Pixel Geometry") << " error in iy " << iy ;
00074     if( ix < 0 || ix > (numRows-1) )
00075     LogWarning ("Pixel Geometry")  << " error in ix " << ix ;
00076     int chan = PixelDigi::pixelToChannel(ix, iy);
00077     LogDebug ("Pixel Digitizer")<<" Storing noise = " << (*mapI).first << " " << (*mapI).second 
00078     << " " << ix << " " << iy << " " << chan ;
00079     if(_signal[chan] == 0){
00080     _signal[(*p).first] += (*p).second;
00081     }//if
00082     }//for(MI
00083     }
00084   */    
00085   //                                                                        //
00086   //                                                                                                    //
00087   
00088   
00089   //
00090   return _signal;
00091   //
00092 }
00093 //
00094 
00095 
00096 
00097