CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiGaussianTailNoiseAdder.cc
Go to the documentation of this file.
4 #include "CLHEP/Random/RandGaussQ.h"
6 
7 SiGaussianTailNoiseAdder::SiGaussianTailNoiseAdder(float th,CLHEP::HepRandomEngine& eng):
8  threshold(th),
9  rndEngine(eng),
10  gaussDistribution(new CLHEP::RandGaussQ(rndEngine)),
11  genNoise(new GaussianTailNoiseGenerator(rndEngine))
12 {
13 }
14 
16 }
17 
18 void SiGaussianTailNoiseAdder::addNoise(std::vector<float> &in,
19  size_t& minChannel, size_t& maxChannel,
20  int numStrips, float noiseRMS) const {
21 
22  std::vector<std::pair<int,float> > generatedNoise;
23  genNoise->generate(numStrips,threshold,noiseRMS,generatedNoise);
24 
25  // noise on strips with signal:
26  for (size_t iChannel=minChannel; iChannel<maxChannel; iChannel++) {
27  if(in[iChannel] != 0) {
28  in[iChannel] += gaussDistribution->fire(0.,noiseRMS);
29  }
30  }
31 
32  // Noise on the other strips
33  typedef std::vector<std::pair<int,float> >::const_iterator VI;
34  for(VI p = generatedNoise.begin(); p != generatedNoise.end(); p++){
35  if(in[(*p).first] == 0) {
36  in[(*p).first] += (*p).second;
37  }
38  }
39 }
40 
41 void SiGaussianTailNoiseAdder::addNoiseVR(std::vector<float> &in, std::vector<float> &noiseRMS) const {
42  // Add noise
43  // Full Gaussian noise is added everywhere
44  for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
45  if(noiseRMS[iChannel] > 0.) in[iChannel] += gaussDistribution->fire(0.,noiseRMS[iChannel]);
46  }
47 }
48 
49 void SiGaussianTailNoiseAdder::addPedestals(std::vector<float> &in,std::vector<float> & ped) const {
50  for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
51  if(ped[iChannel]>0.) in[iChannel] += ped[iChannel];
52  }
53 }
54 
55 void SiGaussianTailNoiseAdder::addCMNoise(std::vector<float> &in, float cmnRMS, std::vector<bool> &badChannels) const {
56  int nAPVs = in.size()/128;
57  std::vector<float> CMNv;
58  for(int APVn =0; APVn < nAPVs; ++APVn) CMNv.push_back(gaussDistribution->fire(0.,cmnRMS));
59  for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
60  if(!badChannels[iChannel]) in[iChannel] += CMNv[(int)(iChannel/128)];
61  }
62 }
63 
64 void SiGaussianTailNoiseAdder::addBaselineShift(std::vector<float> &in, std::vector<bool> &badChannels) const {
65  size_t nAPVs = in.size()/128;
66  std::vector<float> vShift;
67  double apvCharge, apvMult;
68 
69  size_t iChannel;
70  for(size_t APVn =0; APVn < nAPVs; ++APVn){
71  apvMult=0; apvCharge=0;
72  for(iChannel=APVn*128; iChannel!=APVn*128+128; ++iChannel) {
73  if(in[iChannel]>0){
74  ++apvMult;
75  apvCharge+= in[iChannel];
76  }
77  if(apvMult==0) vShift.push_back(0);
78  else vShift.push_back(apvCharge/apvMult);
79  }
80  }
81 
82  for (iChannel=0; iChannel!=in.size(); ++iChannel) {
83  if(!badChannels[iChannel]) in[iChannel] -= vShift[(int)(iChannel/128)];
84  }
85 }
86 
87 
88 
89 
90 
void addPedestals(std::vector< float > &, std::vector< float > &) const
std::unique_ptr< GaussianTailNoiseGenerator > genNoise
SiGaussianTailNoiseAdder(float, CLHEP::HepRandomEngine &)
void addNoiseVR(std::vector< float > &, std::vector< float > &) const
void addBaselineShift(std::vector< float > &, std::vector< bool > &) const
std::unique_ptr< CLHEP::RandGaussQ > gaussDistribution
void addNoise(std::vector< float > &, size_t &, size_t &, int, float) const
void addCMNoise(std::vector< float > &, float, std::vector< bool > &) const