CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalTDC.cc
Go to the documentation of this file.
5 
6 HcalTDC::HcalTDC(unsigned int thresholdDAC) : theTDCParameters(),
7  theDbService(0),
8  theDAC(thresholdDAC),
9  theRandGaussQ(0) {}
10 
12  if (theRandGaussQ) delete theRandGaussQ;
13 }
14 
15 void HcalTDC::timing(const CaloSamples& lf, HcalUpgradeDataFrame& digi) const {
16 
17  float TDC_Threshold = getThreshold(digi.id());
18  bool alreadyOn = false;
19  int tdcBins = theTDCParameters.nbins();
20  // start with a loop over 10 samples
21  bool hasTDCValues=true;
22  if (lf.preciseSize()==0 ) hasTDCValues=false;
23 
24  // if (hasTDCValues)
25  // std::cout << digi.id()
26  // << " threshold: " << TDC_Threshold
27  // << " hasTDCValues: " << hasTDCValues
28  // << '\n';
29  for (int ibin = 0; ibin < lf.size(); ++ibin) {
30  /*
31  If in a given 25ns bunch/time sample, the pulse is above
32  TDC_Thresh already, then TDC_RisingEdge=0 if it was low in the
33  last precision bin on the previous bunch crossing, otherwise,
34  TDC_RisingEdge=63 if the pulse never crosses the threshold
35  having started off, then the special code is 62 and then
36  one can still have a TDC_FallingEdge that is valid. If the pulse
37  never falls below threshold having started above threshold (or
38  goes above threshold in the bunch crossing and doesn't come down),
39  then TDC_FallingEdge=. If the pulse never went above
40  threshold, then TDC_RisingEdge=63 and
41  TDC_FallingEdge=62.
42  */
43  // special codes
44  int TDC_RisingEdge = (alreadyOn) ? theTDCParameters.alreadyTransitionCode()
46  int TDC_FallingEdge = (alreadyOn) ? theTDCParameters.noTransitionCode() :
48  int preciseBegin = ibin * tdcBins;
49  int preciseEnd = preciseBegin + tdcBins;
50  if ( hasTDCValues) {
51  // std::cout << " alreadyOn: " << alreadyOn << '\n';
52  for(int i = preciseBegin; i < preciseEnd; ++i) {
53  // std::cout << " preciseBin: " << i
54  // << " preciseAt(i): " << lf.preciseAt(i);
55  if (alreadyOn) {
56  if( (i%3 == 0) && (lf.preciseAt(i) < TDC_Threshold) ) {
57  alreadyOn = false;
58  TDC_FallingEdge = i-preciseBegin;
59  // std::cout << " falling ";
60  }
61  } else {
62  if (lf.preciseAt(i) > TDC_Threshold) {
63  alreadyOn = true;
64  TDC_RisingEdge = i-preciseBegin;
65  // the flag for hasn't gone low yet
66  TDC_FallingEdge = theTDCParameters.noTransitionCode();
67  // std::cout << " rising ";
68  }
69  }
70  // std::cout << '\n';
71  }
72  }
73  // change packing to allow for special codes
74  int packedTDC = TDC_RisingEdge + (tdcBins*2) * TDC_FallingEdge;
75  digi.setSample(ibin, digi.adc(ibin), packedTDC, true);
76  // if ( hasTDCValues) {
77  // std::cout << " sample: " << ibin
78  // << " adc: " << digi.adc(ibin)
79  // << " fC: " << digi[ibin].nominal_fC()
80  // << " risingEdge: " << TDC_RisingEdge
81  // << " fallingEdge: " << TDC_FallingEdge
82  // << " packedTDC: " << packedTDC
83  // << std::endl;
84  // }
85  } // loop over bunch crossing bins
86 }
87 
88 double HcalTDC::getThreshold(const HcalGenericDetId & detId) const {
89  // subtract off pedestal and noise once
90  double pedestal = theDbService->getHcalCalibrations(detId).pedestal(0);
91  double pedestalWidth = theDbService->getHcalCalibrationWidths(detId).pedestal(0);
92  // here the TDCthreshold_ is a multiple of the least significant bit
93  // for the TDC portion of the QIE. The nominal reference is 40 uA which is
94  // divided by an 8 bit DAC. This means the least significant bit is 0.135 uA
95  // in the TDC circuit or 3.74 uA at the input current.
96 
97  // the pedestal is assumed to be evenly distributed in time with some
98  // random variation. No hysteresis is implemented here.
99 
100  double const lsb(3.74);
101  return lsb*theDAC - theRandGaussQ->shoot(pedestal, pedestalWidth)/theTDCParameters.deltaT()/theTDCParameters.nbins();
102 }
103 
104 void HcalTDC::setRandomEngine(CLHEP::HepRandomEngine & engine) {
105  theRandGaussQ = new CLHEP::RandGaussQ(engine);
106 }
107 
108 void HcalTDC::setDbService(const HcalDbService * service) {
109  theDbService = service;
110 }
111 
double getThreshold(const HcalGenericDetId &detId) const
Definition: HcalTDC.cc:88
int i
Definition: DBlmapReader.cc:9
float deltaT() const
void setRandomEngine(CLHEP::HepRandomEngine &engine)
Definition: HcalTDC.cc:104
unsigned int theDAC
Definition: HcalTDC.h:32
const HcalDbService * theDbService
Definition: HcalTDC.h:30
double pedestal(int fCapId) const
get pedestal for capid=0..3
int preciseSize() const
get the size
Definition: CaloSamples.h:64
float preciseAt(int i) const
const function to access precise samples
Definition: CaloSamples.h:35
double pedestal(int fCapId) const
get pedestal width for capid=0..3
CLHEP::RandGaussQ * theRandGaussQ
Definition: HcalTDC.h:34
int noTransitionCode() const
int alreadyTransitionCode() const
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
void timing(const CaloSamples &lf, HcalUpgradeDataFrame &digi) const
adds timing information to the digi
Definition: HcalTDC.cc:15
void setSample(int iSample, uint16_t adc, uint16_t tdc, bool dv)
int size() const
get the size
Definition: CaloSamples.h:26
const HcalDetId & id() const
~HcalTDC()
Definition: HcalTDC.cc:11
uint16_t adc(int iSample=0) const
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
HcalTDC(unsigned int thresholdDAC=12)
Definition: HcalTDC.cc:6
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
Definition: HcalTDC.cc:108
HcalTDCParameters theTDCParameters
Definition: HcalTDC.h:29