CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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     if(totalCharge <= 0.) totalCharge = 1.e-6; // protecion against negaive v.
00048     double delay = HcalTimeSlew::delay(totalCharge, biasSetting);
00049     // now, the smearing
00050     const HcalSimParameters& params=static_cast<const HcalSimParameters&>(theParameterMap->simParameters(detId));
00051     if (params.doTimeSmear() && theRandGaussQ!=0) {
00052       double rms=params.timeSmearRMS(totalCharge);
00053       double smearns=theRandGaussQ->fire()*rms;
00054 
00055       LogDebug("HcalTimeSlewSim") << "TimeSmear charge " << totalCharge << " rms " << rms << " delay " << delay << " smearns " << smearns;
00056       delay+=smearns;
00057     }
00058 
00059     samples.offsetTime(delay);
00060   }
00061 }
00062 
00063 
00064 void HcalTimeSlewSim::setRandomEngine(CLHEP::HepRandomEngine & engine) {
00065   if (theRandGaussQ==0) {
00066     theRandGaussQ=new CLHEP::RandGaussQ(engine);
00067   }
00068 }