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.
9 #include "CLHEP/Random/RandFlat.h"
10 #include <math.h>
11 
12 HcalElectronicsSim::HcalElectronicsSim(HcalAmplifier * amplifier, const HcalCoderFactory * coderFactory, bool PreMixing)
13  : theAmplifier(amplifier),
14  theCoderFactory(coderFactory),
15  theRandFlat(0),
16  theStartingCapId(0),
17  theStartingCapIdIsRandom(false),
18  PreMixDigis(PreMixing)
19 {
20 }
21 
22 
24  if (theRandFlat) delete theRandFlat;
25 }
26 
27 
28 void HcalElectronicsSim::setRandomEngine(CLHEP::HepRandomEngine & engine) {
29  theRandFlat = new CLHEP::RandFlat(engine);
31  theTDC.setRandomEngine(engine);
32 }
33 
34 
36  // theAmplifier->setDbService(service);
37  theTDC.setDbService(service);
38 }
39 
40 template<class Digi>
42  result.setSize(frame.size());
43  theAmplifier->amplify(frame);
44 
45  theCoderFactory->coder(frame.id())->fC2adc(frame, result, theStartingCapId);
46 }
47 
48 
50  convert<HBHEDataFrame>(lf, result);
51  if(PreMixDigis) {
52  for(int isample = 0; isample !=lf.size(); ++isample) {
53  uint16_t theADC = round(10.0*lf[isample]);
54  unsigned capId = result[isample].capid();
55 
56  if(theADC > 126) {
57  uint16_t keepADC = result[isample].adc();
58  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true); // set error bit as a flag
59  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
60  }
61  else {
62  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
63  HcalQIESample mysamp(theADC, capId, 0, 0);
64  }
65  }
66  }
67 }
68 
69 
71  convert<HODataFrame>(lf, result);
72  if(PreMixDigis) {
73  for(int isample = 0; isample !=lf.size(); ++isample) {
74  uint16_t theADC = round(10.0*lf[isample]);
75  unsigned capId = result[isample].capid();
76 
77  if(theADC > 126) {
78  uint16_t keepADC = result[isample].adc();
79  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true);// set error bit as a flag
80  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
81  }
82  else {
83  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
84  HcalQIESample mysamp(theADC, capId, 0, 0);
85  }
86  }
87  }
88 }
89 
90 
92  convert<HFDataFrame>(lf, result); //not enough dynamic range with simple multiplication
93  if(PreMixDigis) {
94  for(int isample = 0; isample !=lf.size(); ++isample) {
95  uint16_t theADC = round(10.0*lf[isample]);
96  unsigned capId = result[isample].capid();
97 
98  if(theADC > 126) {
99  uint16_t keepADC = result[isample].adc();
100  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true);// set error bit as a flag
101  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
102  }
103  else {
104  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
105  HcalQIESample mysamp(theADC, capId, 0, 0);
106  }
107  }
108  }
109 }
110 
112  convert<ZDCDataFrame>(lf, result);
113  if(PreMixDigis) {
114  for(int isample = 0; isample !=lf.size(); ++isample) {
115  uint16_t theADC = round(10.0*lf[isample]);
116  unsigned capId = result[isample].capid();
117 
118  if(theADC > 126) {
119  uint16_t keepADC = result[isample].adc();
120  HcalQIESample mysamp(keepADC, capId, 0, 0, true, true);//set error bit as a flag
121  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) );
122  }
123  else {
124  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
125  HcalQIESample mysamp(theADC, capId, 0, 0);
126  }
127  }
128  }
129 }
130 
131 
134  convert<HcalUpgradeDataFrame>(lf, result);
135 // std::cout << HcalDetId(lf.id()) << ' ' << lf;
136  theTDC.timing(lf, result);
137 }
138 
140  // pick a new starting Capacitor ID
142  {
143  theStartingCapId = theRandFlat->fireInt(4);
145  }
146 }
147 
148 
150 {
151  theStartingCapId = startingCapId;
153  // turns off random capIDs forever for this instance
154  theStartingCapIdIsRandom = false;
155 }
156 
HcalAmplifier * theAmplifier
void setRandomEngine(CLHEP::HepRandomEngine &engine)
Definition: HcalTDC.cc:132
void setStartingCapId(int startingCapId)
void convert(CaloSamples &frame, Digi &result)
void setStartingCapId(int capId)
Definition: HcalAmplifier.h:42
void setDbService(const HcalDbService *service)
HcalElectronicsSim(HcalAmplifier *amplifier, const HcalCoderFactory *coderFactory, bool PreMix)
void analogToDigital(CaloSamples &linearFrame, HBHEDataFrame &result)
void setSample(int i, const HcalQIESample &sam)
Definition: HBHEDataFrame.h:50
void setSample(int i, const HcalQIESample &sam)
Definition: HODataFrame.h:51
void setRandomEngine(CLHEP::HepRandomEngine &engine)
tuple result
Definition: query.py:137
const HcalCoderFactory * theCoderFactory
void setSample(int i, const HcalQIESample &sam)
Definition: HFDataFrame.h:50
void timing(const CaloSamples &lf, HcalUpgradeDataFrame &digi) const
adds timing information to the digi
Definition: HcalTDC.cc:16
int size() const
get the size
Definition: CaloSamples.h:24
virtual void amplify(CaloSamples &linearFrame) const
CLHEP::RandFlat * theRandFlat
void setSample(int i, const HcalQIESample &sam)
Definition: ZDCDataFrame.h:50
volatile std::atomic< bool > shutdown_flag false
void setRandomEngine(CLHEP::HepRandomEngine &engine)
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:136
std::auto_ptr< HcalCoder > coder(const DetId &detId) const
user gets control of the pointer