CMS 3D CMS Logo

ESElectronicsSim.cc
Go to the documentation of this file.
4 
7 #include "CLHEP/Random/RandGaussQ.h"
9 #include <iostream>
10 
12  addNoise_(addNoise), peds_(nullptr), mips_(nullptr)
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 void ESElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, const CaloSamples& cs, ESDataFrame& df) const
24 {
25 
26  std::vector<ESSample> essamples = encode(cs, engine);
27 
28  df.setSize(cs.size());
29  for(int i=0; i<df.size(); i++) {
30  df.setSample(i, essamples[i]);
31  }
32 
33 }
34 
36 {
37 
38  for(int i = 0; i < df.size(); i++) {
39  cs[i] = decode(df[i], df.id());
40  }
41 
42 }
43 
44 std::vector<ESSample>
45 ESElectronicsSim::encode(const CaloSamples& timeframe, CLHEP::HepRandomEngine* engine) const
46 {
48  if ( ! rng.isAvailable()) {
49  throw cms::Exception("Configuration")
50  << "ESElectroncSim requires the RandomNumberGeneratorService\n"
51  "which is not present in the configuration file. You must add the service\n"
52  "in the configuration file or remove the modules that require it.";
53  }
54 
55 
56  std::vector<ESSample> results;
57  results.reserve(timeframe.size());
58 
59  ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
61  int baseline_ = (int) it_ped->getMean();
62  double sigma_ = (double) it_ped->getRms();
63  double MIPADC_ = (double) (*it_mip);
64 
65  int adc = 0;
66  double ADCGeV = MIPADC_/MIPToGeV_;
67 
68  for (int i=0; i<timeframe.size(); i++) {
69 
70  double noi = 0;
71  double signal = 0;
72 
73  if (addNoise_) {
74  noi = CLHEP::RandGaussQ::shoot(engine, 0., sigma_);
75  }
76 
77  signal = timeframe[i]*ADCGeV + noi + baseline_;
78 
79  if (signal>0)
80  signal += 0.5;
81  else if (signal<0)
82  signal -= 0.5;
83 
84  adc = int(signal);
85 
86  if (adc>MAXADC) adc = MAXADC;
87  if (adc<MINADC) adc = MINADC;
88 
89  results.emplace_back(adc);
90  }
91 
92  return results;
93 }
94 
95 double ESElectronicsSim::decode(const ESSample & sample, const DetId & id) const
96 {
97  return 0. ;
98 }
99 
100 
101 
int adc(sample_type sample)
get the ADC sample (12 bits)
auto_ptr< ClusterSequence > cs
const ESIntercalibConstants * mips_
virtual void digitalToAnalog(const ESDataFrame &df, CaloSamples &cs) const
const ESDetId & id() const
Definition: ESDataFrame.h:21
const self & getMap() const
int size() const
Definition: ESDataFrame.h:23
std::vector< ESSample > encode(const CaloSamples &timeframe, CLHEP::HepRandomEngine *) const
#define nullptr
virtual void analogToDigital(CLHEP::HepRandomEngine *, const CaloSamples &cs, ESDataFrame &df) const
void setSize(int size)
Definition: ESDataFrame.cc:27
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:46
void setSample(int i, const ESSample &sam)
Definition: ESDataFrame.h:30
Definition: DetId.h:18
int size() const
get the size
Definition: CaloSamples.h:24
std::vector< Item >::const_iterator const_iterator
virtual ~ESElectronicsSim()
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
const ESPedestals * peds_