CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc

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   // start with a loop over 10 samples
00017   bool hasTDCValues=true;
00018   if (lf.preciseSize()==0 ) hasTDCValues=false;
00019   for (int ibin = 0; ibin < lf.size(); ++ibin) {
00020     /*
00021     If in a given 25ns bunch/time sample, the pulse is above TDC_Thresh  
00022     already, then TDC_RisingEdge=0
00023     if it was low in the last precision bin on the previous bunch crossing,
00024     otherwise, TDC_RisingEdge=tdcBins
00025     if the pulse never crosses the threshold having started off, then the special code is tdcBins+1
00026     and then one can still have a TDC_FallingEdge that is valid.  If  
00027     the pulse never falls below threshold having
00028     started above threshold (or goes above threshold in the bunch crossing and doesn't come down), 
00029     then TDC_FallingEdge=tdcBins+1.  If the pulse never  
00030     went above threshold, then
00031     TDC_RisingEdge=tdcBins+1 and TDC_FallingEdge=tdcBins.
00032     */
00033     // special codes
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             // the flag for hasn't gone low yet
00050             TDC_FallingEdge = tdcBins+1;
00051           }
00052         }
00053       }
00054     }
00055     // change packing to allow for special codes
00056     int packedTDC = TDC_RisingEdge + (tdcBins*2) * TDC_FallingEdge;
00057     digi.setSample(ibin, digi.adc(ibin), packedTDC, true);
00058   } // loop over bunch crossing bins
00059 }
00060 
00061 double HcalTDC::getThreshold(const HcalGenericDetId & detId) const {
00062   // subtract off pedestal and noise once
00063   double pedestal = theDbService->getHcalCalibrations(detId).pedestal(0);
00064   double pedestalWidth = theDbService->getHcalCalibrationWidths(detId).pedestal(0);
00065   // here the TDCthreshold_ is a fixed parameter = 100 fC on the absolute QIE10 scale before pedestal subtraction
00066   // the pedestal width is injecting noise - no hysterysis is being simulated here
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