Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002    \file
0003    Implementation of class EcalSeverityLevelAlgo
0004 
0005    \author Stefano Argiro
0006    \date 10 Jan 2011
0007 */
0008 
0009 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0012 
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0016 
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 #include "CommonTools/Utils/interface/StringToEnumValue.h"
0020 
0021 EcalSeverityLevelAlgo::EcalSeverityLevelAlgo(const edm::ParameterSet& p) {
0022   timeThresh_ = p.getParameter<double>("timeThresh");
0023   chStatus_ = nullptr;
0024 
0025   const edm::ParameterSet& ps = p.getParameter<edm::ParameterSet>("flagMask");
0026   std::vector<std::string> severities = ps.getParameterNames();
0027   std::vector<std::string> flags;
0028 
0029   flagMask_.resize(severities.size());
0030 
0031   // read configuration of severities
0032 
0033   for (unsigned int is = 0; is != severities.size(); ++is) {
0034     EcalSeverityLevel::SeverityLevel snum =
0035         (EcalSeverityLevel::SeverityLevel)StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severities[is]);
0036     flags = ps.getParameter<std::vector<std::string> >(severities[is]);
0037     uint32_t mask = 0;
0038     for (unsigned int ifi = 0; ifi != flags.size(); ++ifi) {
0039       EcalRecHit::Flags f = (EcalRecHit::Flags)StringToEnumValue<EcalRecHit::Flags>(flags[ifi]);
0040       //manipulate the mask
0041       mask |= (0x1 << f);
0042     }
0043 
0044     flagMask_[snum] = mask;
0045   }
0046   // read configuration of dbstatus
0047 
0048   const edm::ParameterSet& dbps = p.getParameter<edm::ParameterSet>("dbstatusMask");
0049   std::vector<std::string> dbseverities = dbps.getParameterNames();
0050   std::vector<std::string> dbflags;
0051 
0052   dbstatusMask_.resize(dbseverities.size());
0053 
0054   for (unsigned int is = 0; is != dbseverities.size(); ++is) {
0055     EcalSeverityLevel::SeverityLevel snum =
0056         (EcalSeverityLevel::SeverityLevel)StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severities[is]);
0057 
0058     dbflags = dbps.getParameter<std::vector<std::string> >(severities[is]);
0059     uint32_t mask = 0;
0060     for (unsigned int ifi = 0; ifi != dbflags.size(); ++ifi) {
0061       EcalChannelStatusCode::Code f =
0062           (EcalChannelStatusCode::Code)StringToEnumValue<EcalChannelStatusCode::Code>(dbflags[ifi]);
0063 
0064       //manipulate the mask
0065       mask |= (0x1 << f);
0066     }
0067 
0068     dbstatusMask_[snum] = mask;
0069   }
0070 }
0071 
0072 EcalSeverityLevel::SeverityLevel EcalSeverityLevelAlgo::severityLevel(const DetId& id,
0073                                                                       const EcalRecHitCollection& rhs) const {
0074   using namespace EcalSeverityLevel;
0075 
0076   // if the detid is within our rechits, evaluate from flag
0077   EcalRecHitCollection::const_iterator rh = rhs.find(id);
0078   if (rh != rhs.end())
0079     return severityLevel(*rh);
0080 
0081   // else evaluate from dbstatus
0082   return severityLevel(id);
0083 }
0084 
0085 EcalSeverityLevel::SeverityLevel EcalSeverityLevelAlgo::severityLevel(const DetId& id) const {
0086   using namespace EcalSeverityLevel;
0087 
0088   EcalChannelStatus::const_iterator chIt = chStatus_->find(id);
0089 
0090   uint16_t dbStatus = chIt->getStatusCode();
0091 
0092   // kGood==0 we know!
0093   if (0 == dbStatus)
0094     return kGood;
0095 
0096   // check if the bit corresponding to that dbStatus is set in the mask
0097   // This implementation implies that the statuses have a priority
0098   for (size_t i = 0; i < dbstatusMask_.size(); ++i) {
0099     uint32_t tmp = 0x1 << dbStatus;
0100     if (dbstatusMask_[i] & tmp)
0101       return SeverityLevel(i);
0102   }
0103 
0104   // no matching
0105   LogDebug("EcalSeverityLevelAlgo") << "Unmatched DB status, returning kGood";
0106   return kGood;
0107 }
0108 
0109 EcalSeverityLevel::SeverityLevel EcalSeverityLevelAlgo::severityLevel(const EcalRecHit& rh) const {
0110   using namespace EcalSeverityLevel;
0111 
0112   //if marked good, do not do any further test
0113   if (rh.checkFlag(kGood))
0114     return kGood;
0115 
0116   // check if the bit corresponding to that flag is set in the mask
0117   // This implementation implies that  severities have a priority...
0118   for (int sev = kBad; sev >= 0; --sev) {
0119     if (sev == kTime && rh.energy() < timeThresh_)
0120       continue;
0121     if (rh.checkFlagMask(flagMask_[sev]))
0122       return SeverityLevel(sev);
0123   }
0124 
0125   // no matching
0126   LogDebug("EcalSeverityLevelAlgo") << "Unmatched Flag , returning kGood";
0127   return kGood;
0128 }
0129 
0130 // Configure (x)emacs for this file ...
0131 // Local Variables:
0132 // mode:c++
0133 // compile-command: "scram b -k"
0134 // End: