Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:38

0001 #include "SimTracker/SiStripDigitizer/interface/SiGaussianTailNoiseAdder.h"
0002 #include "CLHEP/Random/RandGaussQ.h"
0003 
0004 SiGaussianTailNoiseAdder::SiGaussianTailNoiseAdder(float th)
0005     : threshold(th), genNoise(new GaussianTailNoiseGenerator()) {}
0006 
0007 SiGaussianTailNoiseAdder::~SiGaussianTailNoiseAdder() {}
0008 
0009 void SiGaussianTailNoiseAdder::addNoise(std::vector<float> &in,
0010                                         size_t &minChannel,
0011                                         size_t &maxChannel,
0012                                         int numStrips,
0013                                         float noiseRMS,
0014                                         CLHEP::HepRandomEngine *engine) const {
0015   std::vector<std::pair<int, float> > generatedNoise;
0016   genNoise->generate(numStrips, threshold, noiseRMS, generatedNoise, engine);
0017 
0018   // noise on strips with signal:
0019   for (size_t iChannel = minChannel; iChannel < maxChannel; iChannel++) {
0020     if (in[iChannel] != 0) {
0021       in[iChannel] += CLHEP::RandGaussQ::shoot(engine, 0., noiseRMS);
0022     }
0023   }
0024 
0025   // Noise on the other strips
0026   typedef std::vector<std::pair<int, float> >::const_iterator VI;
0027   for (VI p = generatedNoise.begin(); p != generatedNoise.end(); p++) {
0028     if (in[(*p).first] == 0) {
0029       in[(*p).first] += (*p).second;
0030     }
0031   }
0032 }
0033 
0034 void SiGaussianTailNoiseAdder::addNoiseVR(std::vector<float> &in,
0035                                           std::vector<float> &noiseRMS,
0036                                           CLHEP::HepRandomEngine *engine) const {
0037   // Add noise
0038   // Full Gaussian noise is added everywhere
0039   for (size_t iChannel = 0; iChannel != in.size(); iChannel++) {
0040     if (noiseRMS[iChannel] > 0.)
0041       in[iChannel] += CLHEP::RandGaussQ::shoot(engine, 0., noiseRMS[iChannel]);
0042   }
0043 }
0044 
0045 void SiGaussianTailNoiseAdder::addPedestals(std::vector<float> &in, std::vector<float> &ped) const {
0046   for (size_t iChannel = 0; iChannel != in.size(); iChannel++) {
0047     if (ped[iChannel] > 0.)
0048       in[iChannel] += ped[iChannel];
0049   }
0050 }
0051 
0052 void SiGaussianTailNoiseAdder::addCMNoise(std::vector<float> &in,
0053                                           float cmnRMS,
0054                                           std::vector<bool> &badChannels,
0055                                           CLHEP::HepRandomEngine *engine) const {
0056   int nAPVs = in.size() / 128;
0057   std::vector<float> CMNv;
0058   CMNv.reserve(nAPVs);
0059   for (int APVn = 0; APVn < nAPVs; ++APVn)
0060     CMNv.push_back(CLHEP::RandGaussQ::shoot(engine, 0., cmnRMS));
0061   for (size_t iChannel = 0; iChannel != in.size(); iChannel++) {
0062     if (!badChannels[iChannel])
0063       in[iChannel] += CMNv[(int)(iChannel / 128)];
0064   }
0065 }
0066 
0067 void SiGaussianTailNoiseAdder::addBaselineShift(std::vector<float> &in, std::vector<bool> &badChannels) const {
0068   size_t nAPVs = in.size() / 128;
0069   std::vector<float> vShift;
0070   double apvCharge, apvMult;
0071 
0072   size_t iChannel;
0073   for (size_t APVn = 0; APVn < nAPVs; ++APVn) {
0074     apvMult = 0;
0075     apvCharge = 0;
0076     for (iChannel = APVn * 128; iChannel != APVn * 128 + 128; ++iChannel) {
0077       if (in[iChannel] > 0) {
0078         ++apvMult;
0079         apvCharge += in[iChannel];
0080       }
0081       if (apvMult == 0)
0082         vShift.push_back(0);
0083       else
0084         vShift.push_back(apvCharge / apvMult);
0085     }
0086   }
0087 
0088   for (iChannel = 0; iChannel != in.size(); ++iChannel) {
0089     if (!badChannels[iChannel])
0090       in[iChannel] -= vShift[(int)(iChannel / 128)];
0091   }
0092 }