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
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 }
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] , 0. , sam.capid(), sam.soi(), sam.ok());
0028
0029 }
0030 }
0031
0032
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
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
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 }
0087 }
0088
0089
0090 int packedTDC = TDC_RisingEdge;
0091
0092 result.push_back(packedTDC);
0093
0094 }
0095
0096 return result;
0097 }
0098
0099 void HcalTDC::setDbService(const HcalDbService* service) { theDbService = service; }