Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:43

0001 /** \class EcalRecHitSimpleAlgo
0002   *  Simple algoritm to make rechits from uncalibrated rechits
0003   *
0004   *  \author Shahram Rahatlou, University of Rome & INFN, March 2006
0005   */
0006 
0007 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
0008 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
0009 #include "CommonTools/Utils/interface/StringToEnumValue.h"
0010 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
0011 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0012 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
0013 #include "CondFormats/DataRecord/interface/EcalTimeCalibConstantsRcd.h"
0014 #include "CondFormats/DataRecord/interface/EcalTimeOffsetConstantRcd.h"
0015 #include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
0016 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0017 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
0018 #include "CondFormats/EcalObjects/interface/EcalTimeCalibConstants.h"
0019 #include "CondFormats/EcalObjects/interface/EcalTimeOffsetConstant.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/Utilities/interface/ESGetToken.h"
0025 #include "FWCore/Utilities/interface/ESInputTag.h"
0026 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalRecHitSimpleAlgo.h"
0027 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
0028 #include "RecoLocalCalo/EcalRecProducers/interface/EcalRecHitWorkerBaseClass.h"
0029 
0030 class EcalRecHitWorkerSimple : public EcalRecHitWorkerBaseClass {
0031 public:
0032   EcalRecHitWorkerSimple(const edm::ParameterSet&, edm::ConsumesCollector& c);
0033   ~EcalRecHitWorkerSimple() override;
0034 
0035   void set(const edm::EventSetup& es) override;
0036   bool run(const edm::Event& evt, const EcalUncalibratedRecHit& uncalibRH, EcalRecHitCollection& result) override;
0037 
0038 protected:
0039   double EBLaserMIN_;
0040   double EELaserMIN_;
0041   double EBLaserMAX_;
0042   double EELaserMAX_;
0043 
0044   edm::ESHandle<EcalIntercalibConstants> ical;
0045   edm::ESHandle<EcalTimeCalibConstants> itime;
0046   edm::ESHandle<EcalTimeOffsetConstant> offtime;
0047   edm::ESHandle<EcalADCToGeVConstant> agc;
0048   edm::ESHandle<EcalChannelStatus> chStatus;
0049   std::vector<int> v_chstatus_;
0050   edm::ESHandle<EcalLaserDbService> laser;
0051   edm::ESGetToken<EcalIntercalibConstants, EcalIntercalibConstantsRcd> icalToken_;
0052   edm::ESGetToken<EcalTimeCalibConstants, EcalTimeCalibConstantsRcd> itimeToken_;
0053   edm::ESGetToken<EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd> offtimeToken_;
0054   edm::ESGetToken<EcalADCToGeVConstant, EcalADCToGeVConstantRcd> agcToken_;
0055   edm::ESGetToken<EcalChannelStatus, EcalChannelStatusRcd> chStatusToken_;
0056   edm::ESGetToken<EcalLaserDbService, EcalLaserDbRecord> laserToken_;
0057 
0058   // Associate reco flagbit ( outer vector) to many db status flags (inner vector)
0059   std::vector<std::vector<uint32_t> > v_DB_reco_flags_;
0060 
0061   uint32_t setFlagBits(const std::vector<std::vector<uint32_t> >& map, const uint32_t& status);
0062 
0063   uint32_t flagmask_;  // do not propagate channels with these flags on
0064 
0065   bool killDeadChannels_;
0066   bool laserCorrection_;
0067   bool skipTimeCalib_;
0068 
0069   EcalRecHitSimpleAlgo* rechitMaker_;
0070 };
0071 
0072 EcalRecHitWorkerSimple::EcalRecHitWorkerSimple(const edm::ParameterSet& ps, edm::ConsumesCollector& c)
0073     : EcalRecHitWorkerBaseClass(ps, c) {
0074   rechitMaker_ = new EcalRecHitSimpleAlgo();
0075   v_chstatus_ = StringToEnumValue<EcalChannelStatusCode::Code>(
0076       ps.getParameter<std::vector<std::string> >("ChannelStatusToBeExcluded"));
0077   killDeadChannels_ = ps.getParameter<bool>("killDeadChannels");
0078   laserCorrection_ = ps.getParameter<bool>("laserCorrection");
0079   EBLaserMIN_ = ps.getParameter<double>("EBLaserMIN");
0080   EELaserMIN_ = ps.getParameter<double>("EELaserMIN");
0081   EBLaserMAX_ = ps.getParameter<double>("EBLaserMAX");
0082   EELaserMAX_ = ps.getParameter<double>("EELaserMAX");
0083 
0084   skipTimeCalib_ = ps.getParameter<bool>("skipTimeCalib");
0085 
0086   icalToken_ = c.esConsumes<EcalIntercalibConstants, EcalIntercalibConstantsRcd>();
0087   if (!skipTimeCalib_) {
0088     itimeToken_ = c.esConsumes<EcalTimeCalibConstants, EcalTimeCalibConstantsRcd>(
0089         ps.getParameter<edm::ESInputTag>("timeCalibTag"));
0090     offtimeToken_ = c.esConsumes<EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd>(
0091         ps.getParameter<edm::ESInputTag>("timeOffsetTag"));
0092   }
0093   agcToken_ = c.esConsumes<EcalADCToGeVConstant, EcalADCToGeVConstantRcd>();
0094   chStatusToken_ = c.esConsumes<EcalChannelStatus, EcalChannelStatusRcd>();
0095   if (laserCorrection_)
0096     laserToken_ = c.esConsumes<EcalLaserDbService, EcalLaserDbRecord>();
0097 
0098   // Traslate string representation of flagsMapDBReco into enum values
0099   const edm::ParameterSet& p = ps.getParameter<edm::ParameterSet>("flagsMapDBReco");
0100   std::vector<std::string> recoflagbitsStrings = p.getParameterNames();
0101   v_DB_reco_flags_.resize(32);
0102 
0103   for (unsigned int i = 0; i != recoflagbitsStrings.size(); ++i) {
0104     EcalRecHit::Flags recoflagbit = (EcalRecHit::Flags)StringToEnumValue<EcalRecHit::Flags>(recoflagbitsStrings[i]);
0105     std::vector<std::string> dbstatus_s = p.getParameter<std::vector<std::string> >(recoflagbitsStrings[i]);
0106     std::vector<uint32_t> dbstatuses;
0107     for (unsigned int j = 0; j != dbstatus_s.size(); ++j) {
0108       EcalChannelStatusCode::Code dbstatus =
0109           (EcalChannelStatusCode::Code)StringToEnumValue<EcalChannelStatusCode::Code>(dbstatus_s[j]);
0110       dbstatuses.push_back(dbstatus);
0111     }
0112 
0113     v_DB_reco_flags_[recoflagbit] = dbstatuses;
0114   }
0115 
0116   flagmask_ = 0;
0117   flagmask_ |= 0x1 << EcalRecHit::kNeighboursRecovered;
0118   flagmask_ |= 0x1 << EcalRecHit::kTowerRecovered;
0119   flagmask_ |= 0x1 << EcalRecHit::kDead;
0120   flagmask_ |= 0x1 << EcalRecHit::kKilled;
0121   flagmask_ |= 0x1 << EcalRecHit::kTPSaturated;
0122   flagmask_ |= 0x1 << EcalRecHit::kL1SpikeFlag;
0123 }
0124 
0125 void EcalRecHitWorkerSimple::set(const edm::EventSetup& es) {
0126   ical = es.getHandle(icalToken_);
0127 
0128   if (!skipTimeCalib_) {
0129     itime = es.getHandle(itimeToken_);
0130     offtime = es.getHandle(offtimeToken_);
0131   }
0132 
0133   agc = es.getHandle(agcToken_);
0134   chStatus = es.getHandle(chStatusToken_);
0135   if (laserCorrection_)
0136     laser = es.getHandle(laserToken_);
0137 }
0138 
0139 bool EcalRecHitWorkerSimple::run(const edm::Event& evt,
0140                                  const EcalUncalibratedRecHit& uncalibRH,
0141                                  EcalRecHitCollection& result) {
0142   DetId detid = uncalibRH.id();
0143 
0144   EcalChannelStatusMap::const_iterator chit = chStatus->find(detid);
0145   EcalChannelStatusCode::Code dbstatus = chit->getStatusCode();
0146 
0147   // check for channels to be excluded from reconstruction
0148   if (!v_chstatus_.empty()) {
0149     std::vector<int>::const_iterator res = std::find(v_chstatus_.begin(), v_chstatus_.end(), dbstatus);
0150     if (res != v_chstatus_.end())
0151       return false;
0152   }
0153 
0154   uint32_t flagBits = setFlagBits(v_DB_reco_flags_, dbstatus);
0155 
0156   float offsetTime = 0;  // the global time phase
0157   const EcalIntercalibConstantMap& icalMap = ical->getMap();
0158   if (detid.subdetId() == EcalEndcap) {
0159     rechitMaker_->setADCToGeVConstant(float(agc->getEEValue()));
0160     if (!skipTimeCalib_)
0161       offsetTime = offtime->getEEValue();
0162   } else {
0163     rechitMaker_->setADCToGeVConstant(float(agc->getEBValue()));
0164     if (!skipTimeCalib_)
0165       offsetTime = offtime->getEBValue();
0166   }
0167 
0168   // first intercalibration constants
0169   EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(detid);
0170   EcalIntercalibConstant icalconst = 1;
0171   if (icalit != icalMap.end()) {
0172     icalconst = (*icalit);
0173   } else {
0174     edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << detid.rawId()
0175                                      << "! something wrong with EcalIntercalibConstants in your DB? ";
0176   }
0177 
0178   // get laser coefficient
0179   float lasercalib = 1.;
0180   if (laserCorrection_)
0181     lasercalib = laser->getLaserCorrection(detid, evt.time());
0182 
0183   // get time calibration coefficient
0184   EcalTimeCalibConstant itimeconst = 0;
0185 
0186   if (!skipTimeCalib_) {
0187     const EcalTimeCalibConstantMap& itimeMap = itime->getMap();
0188     EcalTimeCalibConstantMap::const_iterator itime = itimeMap.find(detid);
0189 
0190     if (itime != itimeMap.end()) {
0191       itimeconst = (*itime);
0192     } else {
0193       edm::LogError("EcalRecHitError") << "No time calib const found for xtal " << detid.rawId()
0194                                        << "! something wrong with EcalTimeCalibConstants in your DB? ";
0195     }
0196   }
0197 
0198   // make the rechit and put in the output collection, unless recovery has to take care of it
0199   if (!(flagmask_ & flagBits) || !killDeadChannels_) {
0200     EcalRecHit myrechit(rechitMaker_->makeRecHit(uncalibRH,
0201                                                  icalconst * lasercalib,
0202                                                  (itimeconst + offsetTime),
0203                                                  /*recoflags_ 0*/
0204                                                  flagBits));
0205 
0206     if (detid.subdetId() == EcalBarrel && (lasercalib < EBLaserMIN_ || lasercalib > EBLaserMAX_))
0207       myrechit.setFlag(EcalRecHit::kPoorCalib);
0208     if (detid.subdetId() == EcalEndcap && (lasercalib < EELaserMIN_ || lasercalib > EELaserMAX_))
0209       myrechit.setFlag(EcalRecHit::kPoorCalib);
0210     result.push_back(myrechit);
0211   }
0212 
0213   return true;
0214 }
0215 
0216 // Take our association map of dbstatuses-> recHit flagbits and return the apporpriate flagbit word
0217 uint32_t EcalRecHitWorkerSimple::setFlagBits(const std::vector<std::vector<uint32_t> >& map, const uint32_t& status) {
0218   for (unsigned int i = 0; i != map.size(); ++i) {
0219     if (std::find(map[i].begin(), map[i].end(), status) != map[i].end())
0220       return 0x1 << i;
0221   }
0222 
0223   return 0;
0224 }
0225 
0226 EcalRecHitWorkerSimple::~EcalRecHitWorkerSimple() { delete rechitMaker_; }
0227 
0228 #include "FWCore/Framework/interface/MakerMacros.h"
0229 #include "RecoLocalCalo/EcalRecProducers/interface/EcalRecHitWorkerFactory.h"
0230 DEFINE_EDM_PLUGIN(EcalRecHitWorkerFactory, EcalRecHitWorkerSimple, "EcalRecHitWorkerSimple");