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