Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:32

0001 #include "SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h"
0002 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
0003 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "CLHEP/Random/RandGaussQ.h"
0006 
0007 HcalTDC::HcalTDC(double threshold_currentTDC)
0008     : theTDCParameters(), theDbService(nullptr), threshold_currentTDC_(threshold_currentTDC), lsb(3.74) {}
0009 
0010 HcalTDC::~HcalTDC() {}
0011 
0012 //template <class Digi>
0013 void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame& digi) const {
0014   std::vector<int> packedTDCs = leadingEdgeTDC(lf);
0015 
0016   for (int ibin = 0; ibin < lf.size(); ++ibin) {
0017     digi.setSample(ibin, digi[ibin].adc(), packedTDCs[ibin], digi[ibin].soi());
0018 
0019   }  // loop over bunch crossing bins
0020 }
0021 
0022 void HcalTDC::timing(const CaloSamples& lf, QIE10DataFrame& digi) const {
0023   std::vector<int> packedTDCs = leadingEdgeTDC(lf);
0024 
0025   for (int ibin = 0; ibin < lf.size(); ++ibin) {
0026     QIE10DataFrame::Sample sam = digi[ibin];
0027     digi.setSample(ibin, sam.adc(), packedTDCs[ibin] /*LE TDC*/, 0. /*TE TDC*/, sam.capid(), sam.soi(), sam.ok());
0028 
0029   }  // loop over bunch crossing bins
0030 }
0031 
0032 //leading edge TDC
0033 std::vector<int> HcalTDC::leadingEdgeTDC(const CaloSamples& lf) const {
0034   std::vector<int> result;
0035 
0036   float const TDC_Threshold(getThreshold());
0037   bool risingReady(true);
0038   int tdcBins = theTDCParameters.nbins();
0039   bool hasTDCValues = true;
0040   if (lf.preciseSize() == 0)
0041     hasTDCValues = false;
0042 
0043   for (int ibin = 0; ibin < lf.size(); ++ibin) {
0044     /*
0045     If in a given 25ns bunch/time sample, the pulse is above
0046     TDC_Thresh, then TDC_RisingEdge set to time when threshold
0047     was crossed.
0048     TDC_RisingEdge=0 if it was low in the last precision bin 
0049     on the previous bunch crossing, but above by first precision
0050     bin in current bunch crossing.
0051     TDC_RisingEdge=62 if pulse starts above threshold by end of
0052     previous bunch crossing and stays above threshold in current 
0053     bunch crossing. 
0054     TDC_RisingEdge=63 if the pulse never crosses the threshold.
0055     */
0056     // special codes
0057     int TDC_RisingEdge = (risingReady) ? theTDCParameters.noTransitionCode() : theTDCParameters.alreadyTransitionCode();
0058     int preciseBegin = ibin * tdcBins;
0059     int preciseEnd = preciseBegin + tdcBins;
0060 
0061     if (hasTDCValues) {
0062       for (int i = preciseBegin; i < preciseEnd; ++i) {
0063         if ((!risingReady) && (i == preciseBegin) && (i != 0)) {
0064           if (lf.preciseAt(i) / theTDCParameters.deltaT() > TDC_Threshold) {
0065             TDC_RisingEdge = theTDCParameters.alreadyTransitionCode();
0066           } else {
0067             risingReady = true;
0068           }
0069         }
0070 
0071         if (risingReady) {
0072           if (lf.preciseAt(i) / theTDCParameters.deltaT() > TDC_Threshold) {
0073             TDC_RisingEdge = i - preciseBegin;
0074             risingReady = false;
0075           } else if (i == (preciseEnd - 1)) {
0076             TDC_RisingEdge = theTDCParameters.noTransitionCode();
0077           }
0078         }
0079 
0080         if ((!risingReady) && (i == (preciseEnd - 1))) {
0081           if (lf.preciseAt(i) / theTDCParameters.deltaT() < TDC_Threshold) {
0082             risingReady = true;
0083           }
0084         }
0085 
0086       }  //end of looping precise bins
0087     }
0088 
0089     // change packing to allow for special codes
0090     int packedTDC = TDC_RisingEdge;
0091 
0092     result.push_back(packedTDC);
0093 
0094   }  // loop over bunch crossing bins
0095 
0096   return result;
0097 }
0098 
0099 void HcalTDC::setDbService(const HcalDbService* service) { theDbService = service; }