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