CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimCalorimetry/CastorSim/src/CastorHitCorrection.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/CastorSim/src/CastorHitCorrection.h"
00002 #include "SimCalorimetry/CaloSimAlgos/interface/CaloSimParameters.h"
00003 #include "CalibCalorimetry/CastorCalib/interface/CastorTimeSlew.h"
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00006 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 CastorHitCorrection::CastorHitCorrection(const CaloVSimParameterMap * parameterMap)
00011 : theParameterMap(parameterMap)
00012 {
00013 }
00014 
00015 
00016 void CastorHitCorrection::fillChargeSums(MixCollection<PCaloHit> & hits)
00017 {
00018   //  clear();
00019   for(MixCollection<PCaloHit>::MixItr hitItr = hits.begin();
00020       hitItr != hits.end(); ++hitItr)
00021   {
00022     LogDebug("CastorHitCorrection") << "CastorHitCorrection::Hit 0x" << std::hex << hitItr->id() << std::dec;
00023     int tbin = timeBin(*hitItr);
00024     LogDebug("CastorHitCorrection") << "CastorHitCorrection::Hit tbin" << tbin;
00025     if(tbin >= 0 && tbin < 10) 
00026     {  
00027       theChargeSumsForTimeBin[tbin][DetId(hitItr->id())] += charge(*hitItr);
00028     }
00029   }
00030 }
00031 
00032 
00033 void CastorHitCorrection::clear()
00034 {
00035   for(int i = 0; i < 10; ++i)
00036   {
00037     theChargeSumsForTimeBin[i].clear();
00038   }
00039 }
00040 
00041 double CastorHitCorrection::charge(const PCaloHit & hit) const
00042 {
00043   DetId detId(hit.id());
00044   const CaloSimParameters & parameters = theParameterMap->simParameters(detId);
00045   double simHitToCharge = parameters.simHitToPhotoelectrons()
00046                         * parameters.photoelectronsToAnalog();
00047   return hit.energy() * simHitToCharge;
00048 }
00049 
00050 double CastorHitCorrection::delay(const PCaloHit & hit) const 
00051 {
00052   // HO goes slow, HF shouldn't be used at all
00053   //Castor not used for the moment
00054 
00055   DetId detId(hit.id());
00056   if(detId.det()==DetId::Calo && (detId.subdetId()==HcalCastorDetId::SubdetectorId)) return 0;
00057 
00058   HcalDetId hcalDetId(hit.id());
00059   if(hcalDetId.subdet() == HcalForward) return 0;  
00060   CastorTimeSlew::BiasSetting biasSetting = (hcalDetId.subdet() == HcalOuter) ?
00061                                           CastorTimeSlew::Slow :
00062                                           CastorTimeSlew::Medium;
00063   double delay = 0.;
00064   int tbin = timeBin(hit);
00065   if(tbin >= 0 && tbin < 10)
00066   {
00067     ChargeSumsByChannel::const_iterator totalChargeItr = theChargeSumsForTimeBin[tbin].find(detId);
00068     if(totalChargeItr == theChargeSumsForTimeBin[tbin].end())
00069     {
00070       throw cms::Exception("CastorHitCorrection") << "Cannot find HCAL/CASTOR charge sum for hit " << hit;
00071     }
00072     double totalCharge = totalChargeItr->second;
00073     delay = CastorTimeSlew::delay(totalCharge, biasSetting);
00074     LogDebug("CastorHitCorrection") << "TIMESLEWcharge " << charge(hit) 
00075                                   << "  totalcharge " << totalCharge 
00076                                   << " olddelay "  << CastorTimeSlew::delay(charge(hit), biasSetting) 
00077                                   << " newdelay " << delay;
00078   }
00079 
00080   return delay;
00081 }
00082 
00083 void CastorHitCorrection::correct(PCaloHit & hit) const {
00084   // replace the hit with a new one, with a time delay
00085   hit = PCaloHit(hit.id(), hit.energyEM(), hit.energyHad(), hit.time(), hit.geantTrackId());
00086 }
00087 
00088 
00089 int CastorHitCorrection::timeBin(const PCaloHit & hit) const
00090 {
00091   const CaloSimParameters & parameters = theParameterMap->simParameters(DetId(hit.id()));
00092   double t = hit.time() - timeOfFlight(DetId(hit.id())) + parameters.timePhase();
00093   return static_cast<int> (t / 25) + parameters.binOfMaximum() - 1;
00094 }
00095 
00096 
00097 double CastorHitCorrection::timeOfFlight(const DetId & detId) const
00098 {
00099     if(detId.det()==DetId::Calo && detId.subdetId()==HcalCastorDetId::SubdetectorId)
00100         return 37.666;
00101     else
00102         throw cms::Exception("not HcalCastorDetId"); 
00103 }
00104