CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ESElectronicsSim.cc
Go to the documentation of this file.
4 
7 #include "CLHEP/Random/RandGaussQ.h"
9 #include <iostream>
10 
11 ESElectronicsSim::ESElectronicsSim(bool addNoise) : addNoise_(addNoise), peds_(nullptr), mips_(nullptr) {
12  // Preshower Electronics Simulation
13  // gain = 1 : low gain for data taking
14  // gain = 2 : high gain for calibration and low energy runs
15  // For 300(310/320) um Si, the MIP is 78.47(81.08/83.7) keV
16 }
17 
19 
20 void ESElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, const CaloSamples& cs, ESDataFrame& df) const {
21  std::vector<ESSample> essamples = encode(cs, engine);
22 
23  df.setSize(cs.size());
24  for (int i = 0; i < df.size(); i++) {
25  df.setSample(i, essamples[i]);
26  }
27 }
28 
30  for (int i = 0; i < df.size(); i++) {
31  cs[i] = decode(df[i], df.id());
32  }
33 }
34 
35 std::vector<ESSample> ESElectronicsSim::encode(const CaloSamples& timeframe, CLHEP::HepRandomEngine* engine) const {
37  if (!rng.isAvailable()) {
38  throw cms::Exception("Configuration")
39  << "ESElectroncSim requires the RandomNumberGeneratorService\n"
40  "which is not present in the configuration file. You must add the service\n"
41  "in the configuration file or remove the modules that require it.";
42  }
43 
44  std::vector<ESSample> results;
45  results.reserve(timeframe.size());
46 
47  ESPedestals::const_iterator it_ped = peds_->find(timeframe.id());
49  int baseline_ = (int)it_ped->getMean();
50  double sigma_ = (double)it_ped->getRms();
51  double MIPADC_ = (double)(*it_mip);
52 
53  int adc = 0;
54  double ADCGeV = MIPADC_ / MIPToGeV_;
55 
56  for (int i = 0; i < timeframe.size(); i++) {
57  double noi = 0;
58  double signal = 0;
59 
60  if (addNoise_) {
61  noi = CLHEP::RandGaussQ::shoot(engine, 0., sigma_);
62  }
63 
64  signal = timeframe[i] * ADCGeV + noi + baseline_;
65 
66  if (signal > 0)
67  signal += 0.5;
68  else if (signal < 0)
69  signal -= 0.5;
70 
71  adc = int(signal);
72 
73  if (adc > MAXADC)
74  adc = MAXADC;
75  if (adc < MINADC)
76  adc = MINADC;
77 
78  results.emplace_back(adc);
79  }
80 
81  return results;
82 }
83 
84 double ESElectronicsSim::decode(const ESSample& sample, const DetId& id) const { return 0.; }
const ESIntercalibConstants * mips_
virtual void digitalToAnalog(const ESDataFrame &df, CaloSamples &cs) const
const ESDetId & id() const
Definition: ESDataFrame.h:19
unique_ptr< ClusterSequence > cs
const self & getMap() const
dictionary results
int size() const
Definition: ESDataFrame.h:21
std::vector< ESSample > encode(const CaloSamples &timeframe, CLHEP::HepRandomEngine *) const
virtual void analogToDigital(CLHEP::HepRandomEngine *, const CaloSamples &cs, ESDataFrame &df) const
void setSize(int size)
Definition: ESDataFrame.cc:17
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:40
void setSample(int i, const ESSample &sam)
Definition: ESDataFrame.h:28
Definition: DetId.h:17
int size() const
get the size
Definition: CaloSamples.h:24
std::vector< Item >::const_iterator const_iterator
virtual ~ESElectronicsSim()
const bool addNoise
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
const ESPedestals * peds_
uint16_t *__restrict__ uint16_t const *__restrict__ adc