Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:21

0001 #include "CalibCalorimetry/CastorCalib/interface/CastorTimeSlew.h"
0002 #include "DataFormats/DetId/interface/DetId.h"
0003 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
0004 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 #include "SimCalorimetry/CaloSimAlgos/interface/CaloSimParameters.h"
0008 #include "SimCalorimetry/CastorSim/interface/CastorHitCorrection.h"
0009 
0010 CastorHitCorrection::CastorHitCorrection(const CaloVSimParameterMap *parameterMap) : theParameterMap(parameterMap) {}
0011 
0012 void CastorHitCorrection::fillChargeSums(MixCollection<PCaloHit> &hits) {
0013   //  clear();
0014   for (MixCollection<PCaloHit>::MixItr hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
0015     LogDebug("CastorHitCorrection") << "CastorHitCorrection::Hit 0x" << std::hex << hitItr->id() << std::dec;
0016     int tbin = timeBin(*hitItr);
0017     LogDebug("CastorHitCorrection") << "CastorHitCorrection::Hit tbin" << tbin;
0018     if (tbin >= 0 && tbin < 10) {
0019       theChargeSumsForTimeBin[tbin][DetId(hitItr->id())] += charge(*hitItr);
0020     }
0021   }
0022 }
0023 
0024 void CastorHitCorrection::fillChargeSums(const std::vector<PCaloHit> &hits) {
0025   //  clear();
0026   for (std::vector<PCaloHit>::const_iterator hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
0027     LogDebug("CastorHitCorrection") << "CastorHitCorrection::Hit 0x" << std::hex << hitItr->id() << std::dec;
0028     int tbin = timeBin(*hitItr);
0029     LogDebug("CastorHitCorrection") << "CastorHitCorrection::Hit tbin" << tbin;
0030     if (tbin >= 0 && tbin < 10) {
0031       theChargeSumsForTimeBin[tbin][DetId(hitItr->id())] += charge(*hitItr);
0032     }
0033   }
0034 }
0035 
0036 void CastorHitCorrection::clear() {
0037   for (int i = 0; i < 10; ++i) {
0038     theChargeSumsForTimeBin[i].clear();
0039   }
0040 }
0041 
0042 double CastorHitCorrection::charge(const PCaloHit &hit) const {
0043   DetId detId(hit.id());
0044   const CaloSimParameters &parameters = theParameterMap->simParameters(detId);
0045   double simHitToCharge = parameters.simHitToPhotoelectrons() * parameters.photoelectronsToAnalog();
0046   return hit.energy() * simHitToCharge;
0047 }
0048 
0049 double CastorHitCorrection::delay(const PCaloHit &hit, CLHEP::HepRandomEngine *) const {
0050   // HO goes slow, HF shouldn't be used at all
0051   // Castor not used for the moment
0052 
0053   DetId detId(hit.id());
0054   if (detId.det() == DetId::Calo && (detId.subdetId() == HcalCastorDetId::SubdetectorId))
0055     return 0;
0056 
0057   HcalDetId hcalDetId(hit.id());
0058   if (hcalDetId.subdet() == HcalForward)
0059     return 0;
0060   CastorTimeSlew::BiasSetting biasSetting =
0061       (hcalDetId.subdet() == HcalOuter) ? CastorTimeSlew::Slow : CastorTimeSlew::Medium;
0062   double delay = 0.;
0063   int tbin = timeBin(hit);
0064   if (tbin >= 0 && tbin < 10) {
0065     ChargeSumsByChannel::const_iterator totalChargeItr = theChargeSumsForTimeBin[tbin].find(detId);
0066     if (totalChargeItr == theChargeSumsForTimeBin[tbin].end()) {
0067       throw cms::Exception("CastorHitCorrection") << "Cannot find HCAL/CASTOR charge sum for hit " << hit;
0068     }
0069     double totalCharge = totalChargeItr->second;
0070     delay = CastorTimeSlew::delay(totalCharge, biasSetting);
0071     LogDebug("CastorHitCorrection") << "TIMESLEWcharge " << charge(hit) << "  totalcharge " << totalCharge
0072                                     << " olddelay " << CastorTimeSlew::delay(charge(hit), biasSetting) << " newdelay "
0073                                     << delay;
0074   }
0075 
0076   return delay;
0077 }
0078 
0079 int CastorHitCorrection::timeBin(const PCaloHit &hit) const {
0080   const CaloSimParameters &parameters = theParameterMap->simParameters(DetId(hit.id()));
0081   double t = hit.time() - timeOfFlight(DetId(hit.id())) + parameters.timePhase();
0082   return static_cast<int>(t / 25) + parameters.binOfMaximum() - 1;
0083 }
0084 
0085 double CastorHitCorrection::timeOfFlight(const DetId &detId) const {
0086   if (detId.det() == DetId::Calo && detId.subdetId() == HcalCastorDetId::SubdetectorId)
0087     return 37.666;
0088   else
0089     throw cms::Exception("not HcalCastorDetId");
0090 }