CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/RecoLocalCalo/EcalRecAlgos/src/EcalSeverityLevelAlgo.cc

Go to the documentation of this file.
00001 
00012 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00015 
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00019 
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 #include "CommonTools/Utils/interface/StringToEnumValue.h"
00023 
00024 EcalSeverityLevelAlgo::EcalSeverityLevelAlgo(const edm::ParameterSet& p){
00025   
00026   
00027   timeThresh_    = p.getParameter< double> ("timeThresh");
00028   chStatus_ =0;     
00029 
00030   const edm::ParameterSet & ps=p.getParameter< edm::ParameterSet >("flagMask");
00031   std::vector<std::string> severities = ps.getParameterNames();
00032   std::vector<std::string> flags;
00033  
00034   flagMask_.resize(severities.size());
00035 
00036   // read configuration of severities
00037 
00038   for (unsigned int is=0;is!=severities.size();++is){
00039 
00040     EcalSeverityLevel::SeverityLevel snum=
00041       (EcalSeverityLevel::SeverityLevel) StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severities[is]);
00042     flags=ps.getParameter<std::vector<std::string> >(severities[is]);
00043     uint32_t mask=0;
00044     for (unsigned int ifi=0;ifi!=flags.size();++ifi){
00045       EcalRecHit::Flags f=
00046         (EcalRecHit::Flags)StringToEnumValue<EcalRecHit::Flags>(flags[ifi]);
00047       //manipulate the mask
00048       mask|=(0x1<<f);
00049     }
00050     flagMask_[snum]=mask;
00051   }
00052   // read configuration of dbstatus
00053 
00054   const edm::ParameterSet & dbps=
00055     p.getParameter< edm::ParameterSet >("dbstatusMask");
00056   std::vector<std::string> dbseverities = dbps.getParameterNames();
00057   std::vector<uint32_t>    dbflags;
00058  
00059   dbstatusMask_.resize(dbseverities.size());
00060 
00061   for (unsigned int is=0;is!=dbseverities.size();++is){
00062 
00063     EcalSeverityLevel::SeverityLevel snum=
00064       (EcalSeverityLevel::SeverityLevel) StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severities[is]);
00065     
00066     dbflags=dbps.getParameter<std::vector<uint32_t> >(severities[is]);
00067     uint32_t mask=0;
00068     for (unsigned int ifi=0;ifi!=dbflags.size();++ifi){
00069       int f= dbflags[ifi];
00070       
00071       //manipulate the mask
00072       mask|=(0x1<<f);
00073     }
00074     dbstatusMask_[snum]=mask;
00075   }
00076 
00077   
00078 
00079 }
00080 
00081 
00082 EcalSeverityLevel::SeverityLevel 
00083 EcalSeverityLevelAlgo::severityLevel(const DetId& id,      
00084                                      const EcalRecHitCollection& rhs) const{
00085   
00086   using namespace EcalSeverityLevel;
00087 
00088   // if the detid is within our rechits, evaluate from flag
00089  EcalRecHitCollection::const_iterator rh= rhs.find(id);
00090   if ( rh != rhs.end()  )
00091     return severityLevel(*rh);
00092 
00093 
00094   // else evaluate from dbstatus
00095  
00096   if (!chStatus_)     
00097     edm::LogError("ObjectNotFound") << "Channel Status not set for EcalSeverityLevelAlgo"; 
00098         
00099 
00100   EcalChannelStatus::const_iterator chIt = chStatus_->find( id );
00101   uint16_t dbStatus = 0;
00102   if ( chIt != chStatus_->end() ) {
00103     dbStatus = chIt->getStatusCode() & 0x1F;
00104   } else {
00105     edm::LogError("ObjectNotFound") << "No channel status found for xtal " 
00106          << id.rawId() 
00107          << "! something wrong with EcalChannelStatus in your DB? ";
00108   }
00109  
00110   // kGood==0 we know!
00111   if (0==dbStatus)  return kGood;
00112  
00113   // check if the bit corresponding to that dbStatus is set in the mask
00114   // This implementation implies that the statuses have a priority
00115   for (size_t i=0; i< dbstatusMask_.size();++i){
00116     uint32_t tmp = 0x1<<dbStatus;
00117     if (dbstatusMask_[i] & tmp) return SeverityLevel(i);
00118   }
00119 
00120   // no matching
00121   LogDebug("EcalSeverityLevelAlgo")<< 
00122     "Unmatched DB status, returning kGood";
00123   return kGood;
00124 }
00125 
00126 
00127 EcalSeverityLevel::SeverityLevel 
00128 EcalSeverityLevelAlgo::severityLevel(const EcalRecHit& rh) const{
00129 
00130   using namespace EcalSeverityLevel;
00131 
00132   //if marked good, do not do any further test
00133   if (rh.checkFlag(kGood)) return kGood;
00134 
00135   // check if the bit corresponding to that flag is set in the mask
00136   // This implementation implies that  severities have a priority... 
00137   for (int sev=kBad;sev>=0;--sev){
00138     if(sev==kTime && rh.energy() < timeThresh_ ) continue;
00139     if (rh.checkFlagMask(flagMask_[sev])) return SeverityLevel(sev);
00140   }
00141 
00142   // no matching
00143   LogDebug("EcalSeverityLevelAlgo")<< "Unmatched Flag , returning kGood";
00144   return kGood;
00145 
00146 }
00147 
00148 
00149 
00150 
00151 // Configure (x)emacs for this file ...
00152 // Local Variables:
00153 // mode:c++
00154 // compile-command: "scram b -k"
00155 // End: