00001 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
00002 #include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
00003 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalCaloFlagLabels.h"
00004 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007
00008
00009 bool HcalSeverityLevelComputer::getChStBit(HcalSeverityDefinition& mydef,
00010 const std::string& mybit)
00011 {
00012 if (mybit == "HcalCellOff") setBit(HcalChannelStatus::HcalCellOff, mydef.chStatusMask);
00013 else if (mybit == "HcalCellMask") setBit(HcalChannelStatus::HcalCellMask, mydef.chStatusMask);
00014 else if (mybit == "HcalCellDead") setBit(HcalChannelStatus::HcalCellDead, mydef.chStatusMask);
00015 else if (mybit == "HcalCellHot") setBit(HcalChannelStatus::HcalCellHot, mydef.chStatusMask);
00016 else if (mybit == "HcalCellStabErr") setBit(HcalChannelStatus::HcalCellStabErr, mydef.chStatusMask);
00017 else if (mybit == "HcalCellTimErr") setBit(HcalChannelStatus::HcalCellTimErr, mydef.chStatusMask);
00018 else if (mybit == "HcalCellTrigMask") setBit(HcalChannelStatus::HcalCellTrigMask, mydef.chStatusMask);
00019 else if (mybit == "HcalCellCaloTowerMask") setBit(HcalChannelStatus::HcalCellCaloTowerMask, mydef.chStatusMask);
00020 else if (mybit == "HcalCellCaloTowerProb") setBit(HcalChannelStatus::HcalCellCaloTowerProb, mydef.chStatusMask);
00021 else if (mybit == "HcalCellExcludeFromHBHENoiseSummary") setBit(HcalChannelStatus::HcalCellExcludeFromHBHENoiseSummary, mydef.chStatusMask);
00022 else if (mybit == "HcalCellExcludeFromHBHENoiseSummaryR45") setBit(HcalChannelStatus::HcalCellExcludeFromHBHENoiseSummaryR45, mydef.chStatusMask);
00023 else if (mybit == "HcalBadLaserSignal") setBit(HcalChannelStatus::HcalBadLaserSignal, mydef.chStatusMask);
00024 else
00025 {
00026 edm::LogWarning ("HcalSeverityLevelComputer")
00027 << "HcalSeverityLevelComputer: Error: ChannelStatusFlag >>" << mybit
00028 << "<< unknown. Ignoring.";
00029 return false;
00030 }
00031 return true;
00032 }
00033
00034 bool HcalSeverityLevelComputer::getRecHitFlag(HcalSeverityDefinition& mydef,
00035 const std::string& mybit)
00036 {
00037
00038 if (mybit == "HBHEHpdHitMultiplicity") setBit(HcalCaloFlagLabels::HBHEHpdHitMultiplicity, mydef.HBHEFlagMask);
00039 else if (mybit == "HBHEPulseShape") setBit(HcalCaloFlagLabels::HBHEPulseShape, mydef.HBHEFlagMask);
00040 else if (mybit == "HSCP_R1R2") setBit(HcalCaloFlagLabels::HSCP_R1R2, mydef.HBHEFlagMask);
00041 else if (mybit == "HSCP_FracLeader") setBit(HcalCaloFlagLabels::HSCP_FracLeader, mydef.HBHEFlagMask);
00042 else if (mybit == "HSCP_OuterEnergy") setBit(HcalCaloFlagLabels::HSCP_OuterEnergy, mydef.HBHEFlagMask);
00043 else if (mybit == "HSCP_ExpFit") setBit(HcalCaloFlagLabels::HSCP_ExpFit, mydef.HBHEFlagMask);
00044 else if (mybit == "HBHEFlatNoise") setBit(HcalCaloFlagLabels::HBHEFlatNoise, mydef.HBHEFlagMask);
00045 else if (mybit == "HBHESpikeNoise") setBit(HcalCaloFlagLabels::HBHESpikeNoise, mydef.HBHEFlagMask);
00046 else if (mybit == "HBHETriangleNoise") setBit(HcalCaloFlagLabels::HBHETriangleNoise, mydef.HBHEFlagMask);
00047 else if (mybit == "HBHETS4TS5Noise") setBit(HcalCaloFlagLabels::HBHETS4TS5Noise, mydef.HBHEFlagMask);
00048
00049
00050 else if (mybit=="HBHETimingTrustBits") setBit(HcalCaloFlagLabels::HBHETimingTrustBits, mydef.HBHEFlagMask );
00051 else if (mybit=="HBHETimingShapedCutsBits") setBit(HcalCaloFlagLabels::HBHETimingShapedCutsBits, mydef.HBHEFlagMask);
00052 else if (mybit=="HBHEIsolatedNoise") setBit(HcalCaloFlagLabels::HBHEIsolatedNoise, mydef.HBHEFlagMask );
00053
00054
00055 else if (mybit == "HOBit") setBit(HcalCaloFlagLabels::HOBit, mydef.HOFlagMask);
00056
00057
00058 else if (mybit == "HFLongShort") setBit(HcalCaloFlagLabels::HFLongShort, mydef.HFFlagMask);
00059 else if (mybit == "HFDigiTime") setBit(HcalCaloFlagLabels::HFDigiTime, mydef.HFFlagMask);
00060 else if (mybit == "HFInTimeWindow") setBit(HcalCaloFlagLabels::HFInTimeWindow, mydef.HFFlagMask);
00061 else if (mybit == "HFS8S1Ratio") setBit(HcalCaloFlagLabels::HFS8S1Ratio, mydef.HFFlagMask);
00062 else if (mybit == "HFPET") setBit(HcalCaloFlagLabels::HFPET, mydef.HFFlagMask);
00063 else if (mybit == "HFTimingTrustBits") setBit(HcalCaloFlagLabels::HFTimingTrustBits, mydef.HFFlagMask);
00064
00065
00066 else if (mybit == "ZDCBit") setBit(HcalCaloFlagLabels::ZDCBit, mydef.ZDCFlagMask);
00067
00068
00069 else if (mybit == "CalibrationBit") setBit(HcalCaloFlagLabels::CalibrationBit, mydef.CalibFlagMask);
00070
00071
00072 else if (mybit == "TimingSubtractedBit") setAllRHMasks(HcalCaloFlagLabels::TimingSubtractedBit, mydef);
00073 else if (mybit == "TimingAddedBit") setAllRHMasks(HcalCaloFlagLabels::TimingAddedBit, mydef);
00074 else if (mybit == "TimingErrorBit") setAllRHMasks(HcalCaloFlagLabels::TimingErrorBit, mydef);
00075 else if (mybit == "ADCSaturationBit") setAllRHMasks(HcalCaloFlagLabels::ADCSaturationBit, mydef);
00076 else if (mybit== "AddedSimHcalNoise") setAllRHMasks(HcalCaloFlagLabels::AddedSimHcalNoise, mydef);
00077
00078 else if (mybit == "UserDefinedBit0") setAllRHMasks(HcalCaloFlagLabels::UserDefinedBit0, mydef);
00079 else if (mybit == "UserDefinedBit1") setAllRHMasks(HcalCaloFlagLabels::UserDefinedBit1, mydef);
00080 else if (mybit == "UserDefinedBit2") setAllRHMasks(HcalCaloFlagLabels::UserDefinedBit2, mydef);
00081
00082
00083
00084 else if (mybit == "PresampleADC") setAllRHMasks(HcalCaloFlagLabels::PresampleADC, mydef);
00085 else if (mybit == "Fraction2TS") setAllRHMasks(HcalCaloFlagLabels::Fraction2TS, mydef);
00086
00087
00088
00089
00090 else
00091 {
00092
00093 edm::LogWarning ("HcalSeverityLevelComputer")
00094 << "HcalSeverityLevelComputer: Error: RecHitFlag >>" << mybit
00095 << "<< unknown. Ignoring.";
00096 return false;
00097 }
00098 return true;
00099 }
00100
00101 HcalSeverityLevelComputer::HcalSeverityLevelComputer( const edm::ParameterSet& iConfig)
00102 {
00103
00104 typedef std::vector< edm::ParameterSet > myParameters;
00105 myParameters myLevels = iConfig.getParameter<myParameters>((std::string)"SeverityLevels");
00106
00107
00108 for ( myParameters::iterator itLevels = myLevels.begin(); itLevels != myLevels.end(); ++itLevels)
00109 {
00110
00111 HcalSeverityDefinition mydef;
00112
00113
00114 mydef.sevLevel = itLevels->getParameter<int>("Level");
00115
00116
00117 std::vector<std::string> myRecHitFlags =
00118 itLevels->getParameter<std::vector <std::string> > ("RecHitFlags");
00119
00120
00121 std::vector<std::string> myChStatuses =
00122 itLevels->getParameter<std::vector <std::string> > ("ChannelStatus");
00123
00124
00125
00126 unsigned int bvalid = 0;
00127 unsigned int bnonempty = 0;
00128
00129 for (unsigned k=0; k < myChStatuses.size(); k++)
00130 {
00131 if (myChStatuses[k].empty()) break;
00132 bnonempty++;
00133 bvalid+=getChStBit(mydef, myChStatuses[k]);
00134 }
00135
00136
00137 for (unsigned k=0; k < myRecHitFlags.size(); k++)
00138 {
00139 if (myRecHitFlags[k].empty()) break;
00140 bnonempty++;
00141 bvalid+=getRecHitFlag(mydef, myRecHitFlags[k]);
00142 }
00143
00144
00145
00146
00147
00148 if ((!bvalid) && (bnonempty))
00149 {
00150 edm::LogWarning ("HcalSeverityLevelComputer")
00151 << "Warning: level " << mydef.sevLevel
00152 << " consists of invalid definitions only: "
00153
00154 << " Ignoring definition.";
00155 continue;
00156 }
00157
00158
00159 std::vector<HcalSeverityDefinition>::iterator it = SevDef.begin();
00160
00161 do
00162 {
00163 if (it == SevDef.end()) { SevDef.push_back(mydef); break; }
00164
00165 if (it->sevLevel == mydef.sevLevel)
00166 {
00167 edm::LogWarning ("HcalSeverityLevelComputer")
00168 << "HcalSeverityLevelComputer: Warning: level " << mydef.sevLevel
00169 << " already defined. Ignoring new definition.";
00170 break;
00171 }
00172
00173 if (it->sevLevel < mydef.sevLevel)
00174 if (( (it+1) == SevDef.end()) || ( (it+1)->sevLevel > mydef.sevLevel ))
00175 {
00176 SevDef.insert(it+1, mydef);
00177 break;
00178 }
00179
00180 it++;
00181 }
00182 while(it != SevDef.end());
00183
00184 }
00185
00186 edm::LogInfo("HcalSeverityLevelComputer")
00187 << "HcalSeverityLevelComputer - Summary of Severity Levels:" << std::endl;
00188 for (std::vector<HcalSeverityDefinition>::iterator it = SevDef.begin(); it !=SevDef.end(); it++)
00189 {
00190
00191 edm::LogInfo("HcalSeverityLevelComputer")
00192 << (*it) << std::endl;
00193 }
00194
00195
00196
00197
00198 std::vector<std::string> myRecovered =
00199 iConfig.getParameter<std::vector <std::string> > ("RecoveredRecHitBits");
00200 RecoveredRecHit_ = new HcalSeverityDefinition();
00201 for (unsigned k=0; k < myRecovered.size(); k++)
00202 {
00203 if (myRecovered[k].empty()) break;
00204 getRecHitFlag( (*RecoveredRecHit_), myRecovered[k]);
00205 }
00206
00207
00208
00209
00210 std::vector<std::string> myDrop =
00211 iConfig.getParameter<std::vector <std::string> > ("DropChannelStatusBits");
00212 DropChannel_ = new HcalSeverityDefinition();
00213 for (unsigned k=0; k < myDrop.size(); k++)
00214 {
00215 if (myDrop[k].empty()) break;
00216 getChStBit( (*DropChannel_), myDrop[k]);
00217 }
00218
00219 edm::LogInfo("HcalSeverityLevelComputer")
00220 << "HcalSeverityLevelComputer - Summary for Recovered RecHit bits: \n"
00221 << (*RecoveredRecHit_) << std::endl
00222 << "HcalSeverityLevelComputer - Summary for Drop the Channel bits: \n"
00223 << (*DropChannel_) << std::endl;
00224
00225
00226 }
00227
00228
00229 HcalSeverityLevelComputer::~HcalSeverityLevelComputer() {}
00230
00231
00232 int HcalSeverityLevelComputer::getSeverityLevel(const DetId& myid, const uint32_t& myflag,
00233 const uint32_t& mystatus) const
00234 {
00235 uint32_t myRecHitMask;
00236 HcalGenericDetId myId(myid);
00237 HcalGenericDetId::HcalGenericSubdetector mysubdet = myId.genericSubdet();
00238
00239
00240
00241
00242
00243 for (size_t j=(SevDef.size()); j > 0; j--)
00244 {
00245 size_t i = j - 1;
00246 switch (mysubdet)
00247 {
00248 case HcalGenericDetId::HcalGenBarrel : case HcalGenericDetId::HcalGenEndcap :
00249 myRecHitMask = SevDef[i].HBHEFlagMask; break;
00250 case HcalGenericDetId::HcalGenOuter : myRecHitMask = SevDef[i].HOFlagMask; break;
00251 case HcalGenericDetId::HcalGenForward : myRecHitMask = SevDef[i].HFFlagMask; break;
00252 case HcalGenericDetId::HcalGenZDC : myRecHitMask = SevDef[i].ZDCFlagMask; break;
00253 case HcalGenericDetId::HcalGenCalibration : myRecHitMask = SevDef[i].CalibFlagMask; break;
00254 default: myRecHitMask = 0;
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 if ( ( ( ( !SevDef[i].HBHEFlagMask
00273 && !SevDef[i].HOFlagMask
00274 && !SevDef[i].HFFlagMask
00275 && !SevDef[i].ZDCFlagMask
00276 && !SevDef[i].CalibFlagMask )
00277 || (myRecHitMask & myflag) )
00278 && ( (!SevDef[i].chStatusMask) || (SevDef[i].chStatusMask & mystatus) ) )
00279 || ( (myRecHitMask & myflag) || (SevDef[i].chStatusMask & mystatus) ) )
00280 return SevDef[i].sevLevel;
00281
00282 }
00283
00284 return -100;
00285 }
00286
00287 bool HcalSeverityLevelComputer::recoveredRecHit(const DetId& myid, const uint32_t& myflag) const
00288 {
00289 uint32_t myRecHitMask;
00290 HcalGenericDetId myId(myid);
00291 HcalGenericDetId::HcalGenericSubdetector mysubdet = myId.genericSubdet();
00292
00293 switch (mysubdet)
00294 {
00295 case HcalGenericDetId::HcalGenBarrel : case HcalGenericDetId::HcalGenEndcap :
00296 myRecHitMask = RecoveredRecHit_->HBHEFlagMask; break;
00297 case HcalGenericDetId::HcalGenOuter : myRecHitMask = RecoveredRecHit_->HOFlagMask; break;
00298 case HcalGenericDetId::HcalGenForward : myRecHitMask = RecoveredRecHit_->HFFlagMask; break;
00299 case HcalGenericDetId::HcalGenZDC : myRecHitMask = RecoveredRecHit_->ZDCFlagMask; break;
00300 case HcalGenericDetId::HcalGenCalibration : myRecHitMask = RecoveredRecHit_->CalibFlagMask; break;
00301 default: myRecHitMask = 0;
00302 }
00303
00304 if (myRecHitMask & myflag)
00305 return true;
00306
00307 return false;
00308 }
00309
00310 bool HcalSeverityLevelComputer::dropChannel(const uint32_t& mystatus) const
00311 {
00312 if (DropChannel_->chStatusMask & mystatus)
00313 return true;
00314
00315 return false;
00316 }
00317
00318 void HcalSeverityLevelComputer::setBit(const unsigned bitnumber, uint32_t& where)
00319 {
00320 uint32_t statadd = 0x1<<(bitnumber);
00321 where = where|statadd;
00322 }
00323
00324 void HcalSeverityLevelComputer::setAllRHMasks(const unsigned bitnumber, HcalSeverityDefinition& mydef)
00325 {
00326 setBit(bitnumber, mydef.HBHEFlagMask);
00327 setBit(bitnumber, mydef.HOFlagMask);
00328 setBit(bitnumber, mydef.HFFlagMask);
00329 setBit(bitnumber, mydef.ZDCFlagMask);
00330 setBit(bitnumber, mydef.CalibFlagMask);
00331 }
00332
00333 std::ostream& operator<<(std::ostream& s, const HcalSeverityLevelComputer::HcalSeverityDefinition& def)
00334 {
00335 s << "Hcal Severity Level Definition, Level = " << def.sevLevel << std::endl;
00336 s << std::hex << std::showbase;
00337 s << " channel status mask = " << def.chStatusMask << std::endl;
00338 s << " HBHEFlagMask = " << def.HBHEFlagMask << std::endl;
00339 s << " HOFlagMask = " << def.HOFlagMask << std::endl;
00340 s << " HFFlagMask = " << def.HFFlagMask << std::endl;
00341 s << " ZDCFlagMask = " << def.ZDCFlagMask << std::endl;
00342 s << " CalibFlagMask = " << def.CalibFlagMask << std::dec << std::noshowbase << std::endl;
00343 return s;
00344 }