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(0)
11 {
13  gaussDistribution = new CLHEP::RandGaussQ(rndEngine);
14 }
15 
17  delete genNoise;
18  delete gaussDistribution;
19 }
20 
21 void SiGaussianTailNoiseAdder::addNoise(std::vector<double> &in,
22  size_t& minChannel, size_t& maxChannel,
23  int numStrips, float noiseRMS){
24 
25  std::vector<std::pair<int,float> > generatedNoise;
26  genNoise->generate(numStrips,threshold,noiseRMS,generatedNoise);
27 
28  // noise on strips with signal:
29  for (size_t iChannel=minChannel; iChannel<maxChannel; iChannel++) {
30  if(in[iChannel] != 0) {
31  in[iChannel] += gaussDistribution->fire(0.,noiseRMS);
32  }
33  }
34 
35  // Noise on the other strips
36  typedef std::vector<std::pair<int,float> >::const_iterator VI;
37  for(VI p = generatedNoise.begin(); p != generatedNoise.end(); p++){
38  if(in[(*p).first] == 0) {
39  in[(*p).first] += (*p).second;
40  }
41  }
42 }
43 
44 void SiGaussianTailNoiseAdder::addNoiseVR(std::vector<double> &in, std::vector<float> &noiseRMS){
45  // Add noise
46  // Full Gaussian noise is added everywhere
47  for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
48  if(noiseRMS[iChannel] > 0.) in[iChannel] += gaussDistribution->fire(0.,noiseRMS[iChannel]);
49  }
50 }
51 
52 void SiGaussianTailNoiseAdder::addPedestals(std::vector<double> &in,std::vector<float> & ped){
53  for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
54  if(ped[iChannel]>0.) in[iChannel] += ped[iChannel];
55  }
56 }
57 
58 void SiGaussianTailNoiseAdder::addCMNoise(std::vector<double> &in, float cmnRMS, std::vector<bool> &badChannels){
59  int nAPVs = in.size()/128;
60  std::vector<float> CMNv;
61  for(int APVn =0; APVn < nAPVs; ++APVn) CMNv.push_back(gaussDistribution->fire(0.,cmnRMS));
62  for (size_t iChannel=0; iChannel!=in.size(); iChannel++) {
63  if(!badChannels[iChannel]) in[iChannel] += CMNv[(int)(iChannel/128)];
64  }
65 }
66 
67 void SiGaussianTailNoiseAdder::addBaselineShift(std::vector<double> &in, std::vector<bool> &badChannels){
68  size_t nAPVs = in.size()/128;
69  std::vector<float> vShift;
70  double apvCharge, apvMult;
71 
72  size_t iChannel;
73  for(size_t APVn =0; APVn < nAPVs; ++APVn){
74  apvMult=0; apvCharge=0;
75  for(iChannel=APVn*128; iChannel!=APVn*128+128; ++iChannel) {
76  if(in[iChannel]>0){
77  ++apvMult;
78  apvCharge+= in[iChannel];
79  }
80  if(apvMult==0) vShift.push_back(0);
81  else vShift.push_back(apvCharge/apvMult);
82  }
83  }
84 
85  for (iChannel=0; iChannel!=in.size(); ++iChannel) {
86  if(!badChannels[iChannel]) in[iChannel] -= vShift[(int)(iChannel/128)];
87  }
88 }
89 
90 
91 
92 
93 
GaussianTailNoiseGenerator * genNoise
void addCMNoise(std::vector< double > &, float, std::vector< bool > &)
CLHEP::HepRandomEngine & rndEngine
void addBaselineShift(std::vector< double > &, std::vector< bool > &)
void addNoiseVR(std::vector< double > &, std::vector< float > &)
SiGaussianTailNoiseAdder(float, CLHEP::HepRandomEngine &)
CLHEP::RandGaussQ * gaussDistribution
void addNoise(std::vector< double > &, size_t &, size_t &, int, float)
void generate(int NumberOfchannels, float threshold, float noiseRMS, std::map< int, float > &theMap)
void addPedestals(std::vector< double > &, std::vector< float > &)