CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalElectronicsSim.cc
Go to the documentation of this file.
10 #include "CLHEP/Random/RandFlat.h"
11 #include <math.h>
12 
13 HcalElectronicsSim::HcalElectronicsSim(HcalAmplifier * amplifier, const HcalCoderFactory * coderFactory, bool PreMixing)
14  : theAmplifier(amplifier),
15  theCoderFactory(coderFactory),
16  theStartingCapId(0),
17  theStartingCapIdIsRandom(true),
18  PreMixDigis(PreMixing)
19 {
20 }
21 
22 
24 }
25 
26 
28  // theAmplifier->setDbService(service);
29  theTDC.setDbService(service);
30 }
31 
32 template<class Digi>
33 void HcalElectronicsSim::convert(CaloSamples & frame, Digi & result, CLHEP::HepRandomEngine* engine) {
34  result.setSize(frame.size());
35  theAmplifier->amplify(frame, engine);
36  theCoderFactory->coder(frame.id())->fC2adc(frame, result, theStartingCapId);
37 }
38 
39 template<>
40 void HcalElectronicsSim::convert<QIE10DataFrame>(CaloSamples & frame, QIE10DataFrame & result, CLHEP::HepRandomEngine* engine) {
41  theAmplifier->amplify(frame, engine);
42  theCoderFactory->coder(frame.id())->fC2adc(frame, result, theStartingCapId);
43 }
44 
45 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, HBHEDataFrame & result) {
46  convert<HBHEDataFrame>(lf, result, engine);
47  if(PreMixDigis) {
48  for(int isample = 0; isample !=lf.size(); ++isample) {
49  uint16_t theADC = round(10.0*lf[isample]);
50  unsigned capId = result[isample].capid();
51 
52  if(theADC > 126) {
53  uint16_t keepADC = result[isample].adc();
54  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true); // set error bit as a flag
55  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
56  }
57  else {
58  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
59  HcalQIESample mysamp(theADC, capId, 0, 0);
60  }
61  }
62  }
63 }
64 
65 
66 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, HODataFrame & result) {
67  convert<HODataFrame>(lf, result, engine);
68  if(PreMixDigis) {
69  for(int isample = 0; isample !=lf.size(); ++isample) {
70  uint16_t theADC = round(10.0*lf[isample]);
71  unsigned capId = result[isample].capid();
72 
73  if(theADC > 126) {
74  uint16_t keepADC = result[isample].adc();
75  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true);// set error bit as a flag
76  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
77  }
78  else {
79  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
80  HcalQIESample mysamp(theADC, capId, 0, 0);
81  }
82  }
83  }
84 }
85 
86 
87 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, HFDataFrame & result) {
88  convert<HFDataFrame>(lf, result, engine);
89  if(PreMixDigis) {
90  for(int isample = 0; isample !=lf.size(); ++isample) {
91  uint16_t theADC = round(10.0*lf[isample]);
92  unsigned capId = result[isample].capid();
93 
94  if(theADC > 126) {
95  uint16_t keepADC = result[isample].adc();
96  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true);// set error bit as a flag
97  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
98  }
99  else {
100  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
101  HcalQIESample mysamp(theADC, capId, 0, 0);
102  }
103  }
104  }
105 }
106 
107 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, ZDCDataFrame & result) {
108  convert<ZDCDataFrame>(lf, result, engine);
109  if(PreMixDigis) {
110  for(int isample = 0; isample !=lf.size(); ++isample) {
111  uint16_t theADC = round(10.0*lf[isample]);
112  unsigned capId = result[isample].capid();
113 
114  if(theADC > 126) {
115  uint16_t keepADC = result[isample].adc();
116  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true);//set error bit as a flag
117  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
118  }
119  else {
120  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
121  HcalQIESample mysamp(theADC, capId, 0, 0);
122  }
123  }
124  }
125 }
126 
127 
128 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf,
130  convert<HcalUpgradeDataFrame>(lf, result, engine);
131 // std::cout << HcalDetId(lf.id()) << ' ' << lf;
132  theTDC.timing(lf, result, engine);
133 }
134 
135 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf,
137  convert<QIE10DataFrame>(lf, result, engine);
138  //TODO:
139  //HcalTDC extension for QIE10?
140  //PreMixDigis for QIE10?
141 }
142 
143 void HcalElectronicsSim::newEvent(CLHEP::HepRandomEngine* engine) {
144  // pick a new starting Capacitor ID
146  {
147  theStartingCapId = CLHEP::RandFlat::shootInt(engine, 4);
149  }
150 }
151 
152 
154 {
155  theStartingCapId = startingCapId;
157  // turns off random capIDs forever for this instance
158  theStartingCapIdIsRandom = false;
159 }
160 
HcalAmplifier * theAmplifier
void setStartingCapId(int startingCapId)
void analogToDigital(CLHEP::HepRandomEngine *, CaloSamples &linearFrame, HBHEDataFrame &result)
void setStartingCapId(int capId)
Definition: HcalAmplifier.h:44
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
tuple result
Definition: mps_fire.py:84
void setDbService(const HcalDbService *service)
void newEvent(CLHEP::HepRandomEngine *)
HcalElectronicsSim(HcalAmplifier *amplifier, const HcalCoderFactory *coderFactory, bool PreMix)
void convert(CaloSamples &frame, Digi &result, CLHEP::HepRandomEngine *)
const HcalCoderFactory * theCoderFactory
virtual void amplify(CaloSamples &linearFrame, CLHEP::HepRandomEngine *) const
int size() const
get the size
Definition: CaloSamples.h:24
void timing(const CaloSamples &lf, HcalUpgradeDataFrame &digi, CLHEP::HepRandomEngine *) const
adds timing information to the digi
Definition: HcalTDC.cc:16
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
Definition: HcalTDC.cc:132
std::auto_ptr< HcalCoder > coder(const DetId &detId) const
user gets control of the pointer