CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESElectronicsSim.cc
Go to the documentation of this file.
4 
7 #include "CLHEP/Random/RandGaussQ.h"
9 #include <iostream>
10 
12  addNoise_(addNoise), peds_(0), mips_(0)
13 {
14  // Preshower Electronics Simulation
15  // gain = 1 : low gain for data taking
16  // gain = 2 : high gain for calibration and low energy runs
17  // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
18 }
19 
21 {
22 
23  std::vector<ESSample> essamples = encode(cs);
24 
25  df.setSize(cs.size());
26  for(int i=0; i<df.size(); i++) {
27  df.setSample(i, essamples[i]);
28  }
29 
30 }
31 
33 {
34 
35  for(int i = 0; i < df.size(); i++) {
36  cs[i] = decode(df[i], df.id());
37  }
38 
39 }
40 
41 std::vector<ESSample>
42 ESElectronicsSim::encode(const CaloSamples& timeframe) const
43 {
45  if ( ! rng.isAvailable()) {
46  throw cms::Exception("Configuration")
47  << "ESElectroncSim 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 
53  std::vector<ESSample> results;
54  results.reserve(timeframe.size());
55 
56  ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
58  int baseline_ = (int) it_ped->getMean();
59  double sigma_ = (double) it_ped->getRms();
60  double MIPADC_ = (double) (*it_mip);
61 
62  int adc = 0;
63  double ADCGeV = MIPADC_/MIPToGeV_;
64 
65  for (int i=0; i<timeframe.size(); i++) {
66 
67  double noi = 0;
68  double signal = 0;
69 
70  if (addNoise_) {
71  CLHEP::RandGaussQ gaussQDistribution(rng->getEngine(), 0., sigma_);
72  noi = gaussQDistribution.fire();
73  }
74 
75  signal = timeframe[i]*ADCGeV + noi + baseline_;
76 
77  if (signal>0)
78  signal += 0.5;
79  else if (signal<0)
80  signal -= 0.5;
81 
82  adc = int(signal);
83 
84  if (adc>MAXADC) adc = MAXADC;
85  if (adc<MINADC) adc = MINADC;
86 
87  results.push_back(ESSample(adc));
88  }
89 
90  return results;
91 }
92 
93 double ESElectronicsSim::decode(const ESSample & sample, const DetId & id) const
94 {
95  return 0. ;
96 }
97 
98 
99 
int adc(sample_type sample)
get the ADC sample (12 bits)
int i
Definition: DBlmapReader.cc:9
const ESIntercalibConstants * mips_
virtual void digitalToAnalog(const ESDataFrame &df, CaloSamples &cs) const
const ESDetId & id() const
Definition: ESDataFrame.h:18
const self & getMap() const
int size() const
Definition: ESDataFrame.h:20
std::vector< ESSample > encode(const CaloSamples &timeframe) const
void setSize(int size)
Definition: ESDataFrame.cc:16
ESElectronicsSim(bool addNoise)
const_iterator find(uint32_t rawId) const
double decode(const ESSample &sample, const DetId &detId) const
bool isAvailable() const
Definition: Service.h:47
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
virtual void analogToDigital(const CaloSamples &cs, ESDataFrame &df) const
Definition: DetId.h:20
int size() const
get the size
Definition: CaloSamples.h:24
std::vector< Item >::const_iterator const_iterator
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
const ESPedestals * peds_