File indexing completed on 2024-04-06 12:25:40
0001
0002
0003
0004
0005
0006
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
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
0041 mask |= (0x1 << f);
0042 }
0043
0044 flagMask_[snum] = mask;
0045 }
0046
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
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
0077 EcalRecHitCollection::const_iterator rh = rhs.find(id);
0078 if (rh != rhs.end())
0079 return severityLevel(*rh);
0080
0081
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
0093 if (0 == dbStatus)
0094 return kGood;
0095
0096
0097
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
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
0113 if (rh.checkFlag(kGood))
0114 return kGood;
0115
0116
0117
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
0126 LogDebug("EcalSeverityLevelAlgo") << "Unmatched Flag , returning kGood";
0127 return kGood;
0128 }
0129
0130
0131
0132
0133
0134