Go to the documentation of this file.00001 #include "SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h"
00002 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00003 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00004
00005 HcalTDC::HcalTDC() : theTDCParameters(), theDbService(0), theRandGaussQ(0) {}
00006
00007 HcalTDC::~HcalTDC() {
00008 if (theRandGaussQ) delete theRandGaussQ;
00009 }
00010
00011 void HcalTDC::timing(const CaloSamples& lf, HcalUpgradeDataFrame& digi) const {
00012
00013 float TDC_Threshold = getThreshold(digi.id());
00014 bool alreadyOn = false;
00015 int tdcBins = theTDCParameters.nbins();
00016
00017 bool hasTDCValues=true;
00018 if (lf.preciseSize()==0 ) hasTDCValues=false;
00019 for (int ibin = 0; ibin < lf.size(); ++ibin) {
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 int TDC_RisingEdge = alreadyOn ? tdcBins : tdcBins+1;
00035 int TDC_FallingEdge = alreadyOn ? tdcBins+1 : tdcBins;
00036 int preciseBegin = ibin * tdcBins;
00037 int preciseEnd = preciseBegin + tdcBins;
00038 if ( hasTDCValues) {
00039 for(int i = preciseBegin; i < preciseEnd; ++i) {
00040 if (alreadyOn) {
00041 if(lf.preciseAt(i) < TDC_Threshold) {
00042 alreadyOn = false;
00043 TDC_FallingEdge = i-preciseBegin;
00044 }
00045 } else {
00046 if (lf.preciseAt(i) > TDC_Threshold) {
00047 alreadyOn = true;
00048 TDC_RisingEdge = i-preciseBegin;
00049
00050 TDC_FallingEdge = tdcBins+1;
00051 }
00052 }
00053 }
00054 }
00055
00056 int packedTDC = TDC_RisingEdge + (tdcBins*2) * TDC_FallingEdge;
00057 digi.setSample(ibin, digi.adc(ibin), packedTDC, true);
00058 }
00059 }
00060
00061 double HcalTDC::getThreshold(const HcalGenericDetId & detId) const {
00062
00063 double pedestal = theDbService->getHcalCalibrations(detId).pedestal(0);
00064 double pedestalWidth = theDbService->getHcalCalibrationWidths(detId).pedestal(0);
00065
00066
00067 return 100. - theRandGaussQ->shoot(pedestal, pedestalWidth);
00068 }
00069
00070 void HcalTDC::setRandomEngine(CLHEP::HepRandomEngine & engine) {
00071 theRandGaussQ = new CLHEP::RandGaussQ(engine);
00072 }
00073
00074 void HcalTDC::setDbService(const HcalDbService * service) {
00075 theDbService = service;
00076 }
00077