CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/SimCalorimetry/HcalSimAlgos/src/HcalTimeSlewSim.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/HcalSimAlgos/interface/HcalTimeSlewSim.h"
00002 #include "SimCalorimetry/CaloSimAlgos/interface/CaloSimParameters.h"
00003 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h"
00004 #include "CalibCalorimetry/HcalAlgos/interface/HcalTimeSlew.h"
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00007 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 HcalTimeSlewSim::HcalTimeSlewSim(const CaloVSimParameterMap * parameterMap)
00012   : theParameterMap(parameterMap),theRandGaussQ(0) 
00013 {
00014 }
00015 
00016 
00017 
00018 double HcalTimeSlewSim::charge(const CaloSamples & samples) const
00019 {
00020   double totalCharge = 0.;
00021   for(int i = 0; i < 4; ++i) {
00022     int bin = i + samples.presamples();
00023     if(bin < samples.size()) {
00024       totalCharge += samples[bin];
00025     }
00026   }
00027   return totalCharge;
00028 }
00029 
00030 
00031 void HcalTimeSlewSim::delay(CaloSamples & samples) const 
00032 {
00033   // HO goes slow, HF shouldn't be used at all
00034   //ZDC not used for the moment
00035 
00036   DetId detId(samples.id());
00037   if(detId.det()==DetId::Calo && detId.subdetId()==HcalZDCDetId::SubdetectorId) return;
00038   HcalDetId hcalDetId(detId);
00039 
00040   if(hcalDetId.subdet() == HcalBarrel || hcalDetId.subdet() == HcalEndcap || hcalDetId.subdet() == HcalOuter ) {
00041 
00042     HcalTimeSlew::BiasSetting biasSetting = (hcalDetId.subdet() == HcalOuter) ?
00043       HcalTimeSlew::Slow :
00044       HcalTimeSlew::Medium;
00045 
00046     double totalCharge = charge(samples);
00047     double delay = HcalTimeSlew::delay(totalCharge, biasSetting);
00048     // now, the smearing
00049     const HcalSimParameters& params=static_cast<const HcalSimParameters&>(theParameterMap->simParameters(detId));
00050     if (params.doTimeSmear() && theRandGaussQ!=0) {
00051       double rms=params.timeSmearRMS(totalCharge);
00052       double smearns=theRandGaussQ->fire()*rms;
00053 
00054       LogDebug("HcalTimeSlewSim") << "TimeSmear charge " << totalCharge << " rms " << rms << " delay " << delay << " smearns " << smearns;
00055       delay+=smearns;
00056     }
00057 
00058     samples.offsetTime(delay);
00059   }
00060 }
00061 
00062 
00063 void HcalTimeSlewSim::setRandomEngine(CLHEP::HepRandomEngine & engine) {
00064   if (theRandGaussQ==0) {
00065     theRandGaussQ=new CLHEP::RandGaussQ(engine);
00066   }
00067 }