CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESElectronicsSimFast.cc
Go to the documentation of this file.
4 
7 #include "CLHEP/Random/RandFlat.h"
8 #include "CLHEP/Random/RandGaussQ.h"
9 #include "CLHEP/Random/RandGeneral.h"
11 #include <iostream>
12 
14  addNoise_(addNoise), peds_(0), mips_(0)
15 {
16  // Preshower "Fast" Electronics Simulation
17  // gain = 1 : low gain for data taking
18  // gain = 2 : high gain for calibration and low energy runs
19  // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
20 }
21 
22 void ESElectronicsSimFast::analogToDigital(const CaloSamples& cs, ESDataFrame& df, bool wasEmpty, CLHEP::RandGeneral *histoDistribution, double hInf, double hSup, double hBin) const
23 {
24  std::vector<ESSample> essamples;
25  if (!wasEmpty) essamples = standEncode(cs);
26  if ( wasEmpty) essamples = fastEncode(cs, histoDistribution, hInf, hSup, hBin);
27 
28  df.setSize(cs.size());
29  for(int i=0; i<df.size(); i++) {
30  df.setSample(i, essamples[i]);
31  }
32 }
33 
35 {
36  for(int i = 0; i < df.size(); i++) {
37  cs[i] = decode(df[i], df.id());
38  }
39 }
40 
41 std::vector<ESSample>
43 {
45  if ( ! rng.isAvailable()) {
46  throw cms::Exception("Configuration")
47  << "ESElectroncSimFast requires the RandomNumberGeneratorService\n"
48  "which is not present in the configuration file. You must add the service\n"
49  "in the configuration file or remove the modules that require it.";
50  }
51 
52  std::vector<ESSample> results;
53  results.reserve(timeframe.size());
54 
55  ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
57  int baseline_ = (int) it_ped->getMean();
58  double sigma_ = (double) it_ped->getRms();
59  double MIPADC_ = (double) (*it_mip);
60 
61  int adc = 0;
62  double ADCGeV = MIPADC_/MIPToGeV_;
63  for (int i=0; i<timeframe.size(); i++) {
64 
65  double noi = 0;
66  double signal = 0;
67 
68  if (addNoise_) {
69  CLHEP::RandGaussQ gaussQDistribution(rng->getEngine(), 0, sigma_);
70  noi = gaussQDistribution.fire();
71  }
72 
73  signal = timeframe[i]*ADCGeV + noi + baseline_;
74 
75  if (signal>0)
76  signal += 0.5;
77  else if (signal<0)
78  signal -= 0.5;
79 
80  adc = int(signal);
81 
82  if (adc>MAXADC) adc = MAXADC;
83  if (adc<MINADC) adc = MINADC;
84 
85  results.push_back(ESSample(adc));
86  }
87 
88  return results;
89 }
90 
91 
92 std::vector<ESSample>
93 ESElectronicsSimFast::fastEncode(const CaloSamples& timeframe, CLHEP::RandGeneral *histoDistribution, double hInf, double hSup, double hBin) const
94 {
95  std::vector<ESSample> results;
96  results.reserve(timeframe.size());
97 
98  int bin[3];
99  double hBin2 = hBin*hBin;
100  double hBin3 = hBin*hBin*hBin;
101  double width = (hSup - hInf)/hBin;
102 
103  double thisRnd = histoDistribution->fire();
104  int thisRndCell = (int)((hBin3)*(thisRnd)/width);
105  bin[2] = (int)(thisRndCell/hBin2); // sample2 - bin [0,N-1]
106  bin[1] = (int)((thisRndCell - hBin2*bin[2])/hBin); // sample1
107  bin[0] = (int)(thisRndCell - hBin*(bin[1] + hBin*bin[2])); // sample0
108 
109  ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
110  int baseline_ = (int) it_ped->getMean();
111 
112  int adc[3];
113  double noi[3];
114  for(int ii=0; ii<3; ii++){
115 
116  noi[ii] = hInf + bin[ii]*width;
117  if (noi[ii]>0) noi[ii] += 0.5;
118  else if (noi[ii]<0) noi[ii] -= 0.5;
119 
120  adc[ii] = int(noi[ii]) - 1000 + baseline_;
121 
122  if (adc[ii]>MAXADC) adc[ii] = MAXADC;
123  if (adc[ii]<MINADC) adc[ii] = MINADC;
124 
125  results.push_back(ESSample(adc[ii]));
126  }
127 
128  return results;
129 }
130 
131 double ESElectronicsSimFast::decode(const ESSample & sample, const DetId & id) const
132 {
133  return 0. ;
134 }
135 
136 
137 
int adc(sample_type sample)
get the ADC sample (12 bits)
const ESPedestals * peds_
int i
Definition: DBlmapReader.cc:9
double decode(const ESSample &sample, const DetId &detId) const
const ESIntercalibConstants * mips_
const ESDetId & id() const
Definition: ESDataFrame.h:18
const self & getMap() const
int size() const
Definition: ESDataFrame.h:20
void digitalToAnalog(const ESDataFrame &df, CaloSamples &cs) const
void setSize(int size)
Definition: ESDataFrame.cc:16
virtual void analogToDigital(const CaloSamples &cs, ESDataFrame &df, bool wasEmpty, CLHEP::RandGeneral *histoDistribution, double hInf, double hSup, double hBin) const
const_iterator find(uint32_t rawId) const
bool isAvailable() const
Definition: Service.h:47
std::vector< ESSample > fastEncode(const CaloSamples &timeframe, CLHEP::RandGeneral *histoDistribution, double hInf, double hSup, double hBin) const
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
void setSample(int i, const ESSample &sam)
Definition: ESDataFrame.h:27
Definition: DetId.h:20
int size() const
get the size
Definition: CaloSamples.h:24
std::vector< Item >::const_iterator const_iterator
ESElectronicsSimFast(bool addNoise)
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
std::vector< ESSample > standEncode(const CaloSamples &timeframe) const