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 #include "Utilities/Timing/interface/TimingReport.h"
00007
00008 SiGaussianTailNoiseAdder::SiGaussianTailNoiseAdder(float th,CLHEP::HepRandomEngine& eng):
00009 threshold(th),
00010 rndEngine(eng),
00011 gaussDistribution(0)
00012 {
00013 genNoise = new GaussianTailNoiseGenerator(rndEngine);
00014 gaussDistribution = new CLHEP::RandGaussQ(rndEngine);
00015 }
00016
00017 SiGaussianTailNoiseAdder::~SiGaussianTailNoiseAdder(){
00018 delete genNoise;
00019 delete gaussDistribution;
00020 }
00021
00022 void SiGaussianTailNoiseAdder::addNoise(std::vector<double> &in,
00023 unsigned int& minChannel, unsigned int& maxChannel,
00024 int ns, float nrms){
00025
00026 numStrips = ns;
00027 noiseRMS = nrms;
00028
00029 std::vector<std::pair<int,float> > generatedNoise;
00030
00031 genNoise->generate(numStrips,threshold,noiseRMS,generatedNoise);
00032
00033
00034
00035
00036 for (unsigned int iChannel=minChannel; iChannel<=maxChannel; iChannel++) {
00037 if(in[iChannel] != 0) {
00038 float noise = gaussDistribution->fire(0.,noiseRMS);
00039 in[iChannel] += noise;
00040 }
00041 }
00042
00043
00044
00045
00046 typedef std::vector<std::pair<int,float> >::const_iterator VI;
00047
00048 for(VI p = generatedNoise.begin(); p != generatedNoise.end(); p++){
00049 if(in[(*p).first] == 0) {
00050 in[(*p).first] += (*p).second;
00051 }
00052 }
00053
00054 }
00055
00056 void SiGaussianTailNoiseAdder::createRaw(std::vector<double> &in,
00057 unsigned int& minChannel, unsigned int& maxChannel,
00058 int ns, float nrms, float ped){
00059
00060 numStrips = ns;
00061 noiseRMS = nrms;
00062 pedValue = ped;
00063
00064 std::vector<std::pair<int,float> > generatedNoise;
00065
00066 genNoise->generateRaw(numStrips,noiseRMS,generatedNoise);
00067
00068
00069
00070
00071 for (unsigned int iChannel=minChannel; iChannel<=maxChannel; iChannel++) {
00072 if(in[iChannel] != 0) {
00073 float noise = gaussDistribution->fire(0.,noiseRMS);
00074 in[iChannel] += noise;
00075 }
00076 }
00077
00078
00079
00080
00081 typedef std::vector<std::pair<int,float> >::const_iterator VI;
00082
00083 for(VI p = generatedNoise.begin(); p != generatedNoise.end(); p++){
00084 if(in[(*p).first] == 0) {
00085 in[(*p).first] += (*p).second;
00086 }
00087 }
00088
00089
00090 for (unsigned int iChannel=0; iChannel!=in.size(); iChannel++) {
00091
00092 in[iChannel] += pedValue;
00093
00094 }
00095
00096 }