CMS 3D CMS Logo

HcalElectronicsSim.cc
Go to the documentation of this file.
8 #include "CLHEP/Random/RandFlat.h"
9 #include <math.h>
10 
11 HcalElectronicsSim::HcalElectronicsSim(HcalAmplifier * amplifier, const HcalCoderFactory * coderFactory, bool PreMixing)
12  : theAmplifier(amplifier),
13  theCoderFactory(coderFactory),
14  theStartingCapId(0),
15  theStartingCapIdIsRandom(true),
16  PreMixDigis(PreMixing)
17 {
18 }
19 
20 
22 }
23 
25  // theAmplifier->setDbService(service);
26  theTDC.setDbService(service);
27 }
28 
29 template<class Digi>
30 void HcalElectronicsSim::convert(CaloSamples & frame, Digi & result, CLHEP::HepRandomEngine* engine) {
31  result.setSize(frame.size());
32  theAmplifier->amplify(frame, engine);
33  theCoderFactory->coder(frame.id())->fC2adc(frame, result, theStartingCapId);
34 }
35 
36 template<>
37 void HcalElectronicsSim::convert<QIE10DataFrame>(CaloSamples & frame, QIE10DataFrame & result, CLHEP::HepRandomEngine* engine) {
38  theAmplifier->amplify(frame, engine);
39  theCoderFactory->coder(frame.id())->fC2adc(frame, result, theStartingCapId);
40 }
41 
42 template<>
43 void HcalElectronicsSim::convert<QIE11DataFrame>(CaloSamples & frame, QIE11DataFrame & result, CLHEP::HepRandomEngine* engine) {
44  theAmplifier->amplify(frame, engine);
45  theCoderFactory->coder(frame.id())->fC2adc(frame, result, theStartingCapId);
46 }
47 
48 template<class Digi>
49 void HcalElectronicsSim::premix(CaloSamples & frame, Digi & result, double preMixFactor, unsigned preMixBits){
50  for(int isample = 0; isample !=frame.size(); ++isample) {
51  uint16_t theADC = round(preMixFactor*frame[isample]);
52  unsigned capId = result[isample].capid();
53 
54  if(theADC > preMixBits) {
55  uint16_t keepADC = result[isample].adc();
56  result.setSample(isample, HcalQIESample(keepADC, capId, 0, 0, true, true) ); // set error bit as a flag
57  }
58  else {
59  result.setSample(isample, HcalQIESample(theADC, capId, 0, 0) ); // preserve fC, no noise
60  }
61  }
62 }
63 
64 template<>
65 void HcalElectronicsSim::premix<QIE10DataFrame>(CaloSamples & frame, QIE10DataFrame & result, double preMixFactor, unsigned preMixBits){
66  for(int isample = 0; isample !=frame.size(); ++isample) {
67  uint16_t theADC = round(preMixFactor*frame[isample]);
68  unsigned capId = result[isample].capid();
69  bool ok = true;
70 
71  if(theADC > preMixBits) {
72  theADC = result[isample].adc();
73  ok = false; // set error bit as a flag
74  }
75 
76  result.setSample(isample, theADC, result[isample].le_tdc(), result[isample].te_tdc(), capId, result[isample].soi(), ok);
77  }
78 }
79 
80 template<>
81 void HcalElectronicsSim::premix<QIE11DataFrame>(CaloSamples & frame, QIE11DataFrame & result, double preMixFactor, unsigned preMixBits){
82  uint16_t flag = 0;
83  for(int isample = 0; isample !=frame.size(); ++isample) {
84  uint16_t theADC = round(preMixFactor*frame[isample]);
85 
86  if(theADC > preMixBits) {
87  theADC = result[isample].adc();
88  flag |= 1<<isample; // set error bit as a flag
89  }
90 
91  result.setSample(isample, theADC, result[isample].tdc(), result[isample].soi());
92  }
93  result.setFlags(flag);
94 }
95 
96 template<class Digi>
97 void HcalElectronicsSim::analogToDigitalImpl(CLHEP::HepRandomEngine* engine, CaloSamples & lf, Digi & result, double preMixFactor, unsigned preMixBits) {
98  convert<Digi>(lf, result, engine);
99  if(PreMixDigis) premix(lf,result,preMixFactor,preMixBits);
100 }
101 
102 //TODO:
103 //HcalTDC extension for QIE10? and QIE11?
104 
105 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, HBHEDataFrame & result, double preMixFactor, unsigned preMixBits) {
106  analogToDigitalImpl(engine,lf,result,preMixFactor,preMixBits);
107 }
108 
109 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, HODataFrame & result, double preMixFactor, unsigned preMixBits) {
110  analogToDigitalImpl(engine,lf,result,preMixFactor,preMixBits);
111 }
112 
113 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, HFDataFrame & result, double preMixFactor, unsigned preMixBits) {
114  analogToDigitalImpl(engine,lf,result,preMixFactor,preMixBits);
115 }
116 
117 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, ZDCDataFrame & result, double preMixFactor, unsigned preMixBits) {
118  analogToDigitalImpl(engine,lf,result,preMixFactor,preMixBits);
119 }
120 
121 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, QIE10DataFrame & result, double preMixFactor, unsigned preMixBits) {
122  analogToDigitalImpl(engine,lf,result,preMixFactor,preMixBits);
123 }
124 
125 void HcalElectronicsSim::analogToDigital(CLHEP::HepRandomEngine* engine, CaloSamples & lf, QIE11DataFrame & result, double preMixFactor, unsigned preMixBits) {
126  analogToDigitalImpl(engine,lf,result,preMixFactor,preMixBits);
127 }
128 
129 void HcalElectronicsSim::newEvent(CLHEP::HepRandomEngine* engine) {
130  // pick a new starting Capacitor ID
132  {
133  theStartingCapId = CLHEP::RandFlat::shootInt(engine, 4);
135  }
136 }
137 
139 {
140  theStartingCapId = startingCapId;
142  // turns off random capIDs forever for this instance
143  theStartingCapIdIsRandom = false;
144 }
HcalAmplifier * theAmplifier
void setStartingCapId(int startingCapId)
void setStartingCapId(int capId)
Definition: HcalAmplifier.h:40
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
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 analogToDigitalImpl(CLHEP::HepRandomEngine *, CaloSamples &linearFrame, Digi &result, double preMixFactor, unsigned preMixBits)
void analogToDigital(CLHEP::HepRandomEngine *, CaloSamples &linearFrame, HBHEDataFrame &result, double preMixFactor=10.0, unsigned preMixBits=126)
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
std::unique_ptr< HcalCoder > coder(const DetId &detId) const
user gets control of the pointer
void premix(CaloSamples &frame, Digi &result, double preMixFactor, unsigned preMixBits)
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
Definition: HcalTDC.cc:133