CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitWorkerSimple.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitWorkerSimple.h"
00002 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00006 #include "CondFormats/DataRecord/interface/EcalTimeCalibConstantsRcd.h"
00007 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
00008 #include "CondFormats/DataRecord/interface/EcalTimeOffsetConstantRcd.h"
00009 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00010 #include "CondFormats/EcalObjects/interface/EcalTimeCalibConstants.h"
00011 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "CommonTools/Utils/interface/StringToEnumValue.h"
00014 
00015 EcalRecHitWorkerSimple::EcalRecHitWorkerSimple(const edm::ParameterSet&ps) :
00016         EcalRecHitWorkerBaseClass(ps)
00017 {
00018         rechitMaker_ = new EcalRecHitSimpleAlgo();
00019         v_chstatus_ = ps.getParameter<std::vector<int> >("ChannelStatusToBeExcluded");
00020         v_DB_reco_flags_ = ps.getParameter<std::vector<int> >("flagsMapDBReco");
00021         killDeadChannels_ = ps.getParameter<bool>("killDeadChannels");
00022         laserCorrection_ = ps.getParameter<bool>("laserCorrection");
00023         EBLaserMIN_ = ps.getParameter<double>("EBLaserMIN");
00024         EELaserMIN_ = ps.getParameter<double>("EELaserMIN");
00025         EBLaserMAX_ = ps.getParameter<double>("EBLaserMAX");
00026         EELaserMAX_ = ps.getParameter<double>("EELaserMAX");
00027 
00028 }
00029 
00030 
00031 
00032 void EcalRecHitWorkerSimple::set(const edm::EventSetup& es)
00033 {
00034         es.get<EcalIntercalibConstantsRcd>().get(ical);
00035         es.get<EcalTimeCalibConstantsRcd>().get(itime);
00036         es.get<EcalTimeOffsetConstantRcd>().get(offtime);
00037         es.get<EcalADCToGeVConstantRcd>().get(agc);
00038         es.get<EcalChannelStatusRcd>().get(chStatus);
00039         if ( laserCorrection_ ) es.get<EcalLaserDbRecord>().get(laser);
00040 }
00041 
00042 
00043 bool
00044 EcalRecHitWorkerSimple::run( const edm::Event & evt,
00045                 const EcalUncalibratedRecHit& uncalibRH,
00046                 EcalRecHitCollection & result )
00047 {
00048         DetId detid=uncalibRH.id();
00049 
00050         EcalChannelStatusMap::const_iterator chit = chStatus->find(detid);
00051         EcalChannelStatusCode chStatusCode = 1;
00052         if ( chit != chStatus->end() ) {
00053                 chStatusCode = *chit;
00054         } else {
00055                 edm::LogError("EcalRecHitError") << "No channel status found for xtal " 
00056                         << detid.rawId() 
00057                         << "! something wrong with EcalChannelStatus in your DB? ";
00058         }
00059         if ( v_chstatus_.size() > 0) {
00060                 uint16_t code = chStatusCode.getStatusCode() & 0x001F;
00061                 std::vector<int>::const_iterator res = std::find( v_chstatus_.begin(), v_chstatus_.end(), code );
00062                 if ( res != v_chstatus_.end() ) {
00063                         return false;
00064                 }
00065         }
00066 
00067         // find the proper flag for the recHit
00068         // from a configurable vector
00069         // (see cfg file for the association)
00070         uint32_t recoFlag = 0;
00071         uint16_t statusCode = chStatusCode.getStatusCode() & 0x001F;
00072         if ( statusCode < v_DB_reco_flags_.size() ) {
00073                 // not very nice...
00074                 recoFlag = v_DB_reco_flags_[ statusCode ];  
00075         } else {
00076                 edm::LogError("EcalRecHitError") << "Flag " << statusCode 
00077                         << " in DB exceed the allowed range of " << v_DB_reco_flags_.size();
00078         }
00079 
00080         float offsetTime = 0; // the global time phase
00081         const EcalIntercalibConstantMap& icalMap = ical->getMap();  
00082         if ( detid.subdetId() == EcalEndcap ) {
00083                 rechitMaker_->setADCToGeVConstant( float(agc->getEEValue()) );
00084                 offsetTime = offtime->getEEValue();
00085         } else {
00086                 rechitMaker_->setADCToGeVConstant( float(agc->getEBValue()) );
00087                 offsetTime = offtime->getEBValue();
00088         }
00089 
00090         // first intercalibration constants
00091         EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(detid);
00092         EcalIntercalibConstant icalconst = 1;
00093         if( icalit!=icalMap.end() ) {
00094                 icalconst = (*icalit);
00095         } else {
00096                 edm::LogError("EcalRecHitError") << "No intercalib const found for xtal "
00097                         << detid.rawId()
00098                         << "! something wrong with EcalIntercalibConstants in your DB? ";
00099         }
00100 
00101         // get laser coefficient
00102         float lasercalib = 1.;
00103         if ( laserCorrection_ ) lasercalib = laser->getLaserCorrection( detid, evt.time());
00104         
00105 
00106         // get time calibration coefficient
00107         const EcalTimeCalibConstantMap & itimeMap = itime->getMap();  
00108         EcalTimeCalibConstantMap::const_iterator itime = itimeMap.find(detid);
00109         EcalTimeCalibConstant itimeconst = 0;
00110         if( itime!=itimeMap.end() ) {
00111                 itimeconst = (*itime);
00112                   } else {
00113                 edm::LogError("EcalRecHitError") << "No time calib const found for xtal "
00114                         << detid.rawId()
00115                         << "! something wrong with EcalTimeCalibConstants in your DB? ";
00116         }
00117           
00118          
00119         // make the rechit and put in the output collection
00120         if (recoFlag<=EcalRecHit::kLeadingEdgeRecovered || !killDeadChannels_) {
00121           EcalRecHit myrechit( rechitMaker_->makeRecHit(uncalibRH, icalconst * lasercalib, (itimeconst + offsetTime), /*recoflags_*/ 0) );      
00122           if (detid.subdetId() == EcalBarrel && (lasercalib < EBLaserMIN_ || lasercalib > EBLaserMAX_)) myrechit.setFlag(EcalRecHit::kPoorCalib);
00123           if (detid.subdetId() == EcalEndcap && (lasercalib < EELaserMIN_ || lasercalib > EELaserMAX_)) myrechit.setFlag(EcalRecHit::kPoorCalib);
00124           result.push_back(myrechit);
00125         }
00126 
00127         return true;
00128 }
00129 
00130 EcalRecHitWorkerSimple::~EcalRecHitWorkerSimple(){
00131 
00132   delete rechitMaker_;
00133 }
00134 
00135 
00136 #include "FWCore/Framework/interface/MakerMacros.h"
00137 #include "RecoLocalCalo/EcalRecProducers/interface/EcalRecHitWorkerFactory.h"
00138 DEFINE_EDM_PLUGIN( EcalRecHitWorkerFactory, EcalRecHitWorkerSimple, "EcalRecHitWorkerSimple" );