CMS 3D CMS Logo

HcalTDC.cc
Go to the documentation of this file.
5 
6 #include "CLHEP/Random/RandGaussQ.h"
7 
8 HcalTDC::HcalTDC(unsigned int thresholdDAC) : theTDCParameters(),
9  theDbService(nullptr),
10  theDAC(thresholdDAC),
11  lsb(3.74) {}
12 
14 }
15 
16 template <class Digi>
17 void HcalTDC::timing(const CaloSamples& lf, Digi& digi, CLHEP::HepRandomEngine* engine) const {
18 
19  float const TDC_Threshold(getThreshold(digi.id(), engine));
20  float const TDC_Threshold_hyst(TDC_Threshold);
21  bool risingReady(true), fallingReady(false);
22  int tdcBins = theTDCParameters.nbins();
23  // start with a loop over 10 samples
24  bool hasTDCValues=true;
25  if (lf.preciseSize()==0 ) hasTDCValues=false;
26 
27  // "AC" hysteresis from Tom: There cannot be a second transition
28  // within the QIE within 3ns
29  int const rising_ac_hysteresis(5);
30  int lastRisingEdge(0);
31 
32  // if (hasTDCValues)
33  // std::cout << digi.id()
34  // << " threshold: " << TDC_Threshold
35  // << '\n';
36  for (int ibin = 0; ibin < lf.size(); ++ibin) {
37  /*
38  If in a given 25ns bunch/time sample, the pulse is above
39  TDC_Thresh already, then TDC_RisingEdge=0 if it was low in the
40  last precision bin on the previous bunch crossing, otherwise,
41  TDC_RisingEdge=63 if the pulse never crosses the threshold
42  having started off, then the special code is 62 and then
43  one can still have a TDC_FallingEdge that is valid. If the pulse
44  never falls below threshold having started above threshold (or
45  goes above threshold in the bunch crossing and doesn't come down),
46  then TDC_FallingEdge=. If the pulse never went above
47  threshold, then TDC_RisingEdge=63 and
48  TDC_FallingEdge=62.
49  */
50  // special codes
51  int TDC_RisingEdge = (risingReady) ?
54  int TDC_FallingEdge = (fallingReady) ?
57  int preciseBegin = ibin * tdcBins;
58  int preciseEnd = preciseBegin + tdcBins;
59  if ( hasTDCValues) {
60  // std::cout << " alreadyOn: " << alreadyOn << '\n';
61  for(int i = preciseBegin; i < preciseEnd; ++i) {
62  // std::cout << " preciseBin: " << i
63  // << " preciseAt(i): " << lf.preciseAt(i);
64  if( (fallingReady) && (i%3 == 0) && (lf.preciseAt(i) < TDC_Threshold)) {
65  fallingReady = false;
66  TDC_FallingEdge = i-preciseBegin;
67  // std::cout << " falling ";
68  }
69  if ((risingReady) && (lf.preciseAt(i) > TDC_Threshold)) {
70  risingReady = false;
71  TDC_RisingEdge = i-preciseBegin;
72  lastRisingEdge = 0;
73  // std::cout << " rising ";
74  }
75  // std::cout << '\n';
76 
77  //This is the place for hysteresis code. Need to to arm the
78  //tdc by setting the risingReady or fallingReady to true.
79 
80  if ((!fallingReady) && (lf.preciseAt(i) > TDC_Threshold)) {
81  fallingReady = true;
82  if (TDC_FallingEdge == theTDCParameters.alreadyTransitionCode())
83  TDC_FallingEdge = theTDCParameters.noTransitionCode();
84  }
85  if ((!risingReady) && (lastRisingEdge > rising_ac_hysteresis) &&
86  (lf.preciseAt(i) < TDC_Threshold_hyst)) {
87  risingReady = true;
88  if (TDC_RisingEdge == theTDCParameters.alreadyTransitionCode())
89  TDC_RisingEdge = theTDCParameters.noTransitionCode();
90  }
91  ++lastRisingEdge;
92  }
93  }
94  // change packing to allow for special codes
95  int packedTDC = TDC_RisingEdge + (tdcBins*2) * TDC_FallingEdge;
96  digi.setSample(ibin, digi.adc(ibin), packedTDC, true);
97  // if ( hasTDCValues) {
98  // std::cout << " sample: " << ibin
99  // << " adc: " << digi.adc(ibin)
100  // << " fC: " << digi[ibin].nominal_fC()
101  // << " risingEdge: " << TDC_RisingEdge
102  // << " fallingEdge: " << TDC_FallingEdge
103  // << " packedTDC: " << packedTDC
104  // << std::endl;
105  // }
106  } // loop over bunch crossing bins
107 }
108 
109 double HcalTDC::getThreshold(const HcalGenericDetId & detId, CLHEP::HepRandomEngine* engine) const {
110  // subtract off pedestal and noise once
112  double pedestalWidth = theDbService->getHcalCalibrationWidths(detId).pedestal(0);
113  // here the TDCthreshold_ is a multiple of the least significant bit
114  // for the TDC portion of the QIE. The nominal reference is 40 uA which is
115  // divided by an 8 bit DAC. This means the least significant bit is 0.135 uA
116  // in the TDC circuit or 3.74 uA at the input current.
117 
118  // the pedestal is assumed to be evenly distributed in time with some
119  // random variation.
120 
121  return lsb*theDAC - CLHEP::RandGaussQ::shoot(engine, pedestal, pedestalWidth)/theTDCParameters.deltaT()/theTDCParameters.nbins();
122 }
123 
124 double HcalTDC::getHysteresisThreshold(double nominal) const {
125  // the TDC will "re-arm" when it crosses the threshold minus 2.5 mV.
126  // the lsb is 44kOhm * (3.74 uA / 24) = 6.86 mV. 2.5 mV is 0.36 lsb.
127  // with the this means that the hysteresis it isn't far from the nominal
128  // threshold
129 
130  return nominal - 0.365*lsb;
131 }
132 
134  theDbService = service;
135 }
void timing(const CaloSamples &lf, Digi &digi, CLHEP::HepRandomEngine *) const
adds timing information to the digi
Definition: HcalTDC.cc:17
float deltaT() const
unsigned int theDAC
Definition: HcalTDC.h:38
const HcalDbService * theDbService
Definition: HcalTDC.h:36
double pedestal(int fCapId) const
get pedestal for capid=0..3
#define nullptr
int preciseSize() const
get the size
Definition: CaloSamples.h:64
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
float preciseAt(int i) const
const function to access precise samples
Definition: CaloSamples.h:33
double getHysteresisThreshold(double nominal) const
Definition: HcalTDC.cc:124
double pedestal(int fCapId) const
get pedestal width for capid=0..3
int noTransitionCode() const
int alreadyTransitionCode() const
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
int size() const
get the size
Definition: CaloSamples.h:24
double const lsb
Definition: HcalTDC.h:40
~HcalTDC()
Definition: HcalTDC.cc:13
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
HcalTDC(unsigned int thresholdDAC=12)
Definition: HcalTDC.cc:8
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
Definition: HcalTDC.cc:133
double getThreshold(const HcalGenericDetId &detId, CLHEP::HepRandomEngine *) const
Definition: HcalTDC.cc:109
HcalTDCParameters theTDCParameters
Definition: HcalTDC.h:35