CMS 3D CMS Logo

HcalSeverityLevelComputer.cc
Go to the documentation of this file.
8 
10  if (mybit == "HcalCellOff")
12  else if (mybit == "HcalCellMask")
14  else if (mybit == "HcalCellDead")
16  else if (mybit == "HcalCellHot")
18  else if (mybit == "HcalCellStabErr")
20  else if (mybit == "HcalCellTimErr")
22  else if (mybit == "HcalCellTrigMask")
24  else if (mybit == "HcalCellCaloTowerMask")
26  else if (mybit == "HcalCellCaloTowerProb")
28  else if (mybit == "HcalCellExcludeFromHBHENoiseSummary")
30  else if (mybit == "HcalCellExcludeFromHBHENoiseSummaryR45")
32  else if (mybit == "HcalBadLaserSignal")
34  else { // error: unrecognized channel status name
35  edm::LogWarning("HcalSeverityLevelComputer")
36  << "HcalSeverityLevelComputer: Error: ChannelStatusFlag >>" << mybit << "<< unknown. Ignoring.";
37  return false;
38  }
39  return true;
40 }
41 
43  if (phase == 1) // Phase 1 Rechit flags
44  {
45  // HB, HE ++++++++++++++++++++
46  if (mybit == "HBHEHpdHitMultiplicity")
48  else if (mybit == "HBHEIsolatedNoise")
50  else if (mybit == "HBHEFlatNoise")
52  else if (mybit == "HBHESpikeNoise")
54  else if (mybit == "HBHETS4TS5Noise")
56  else if (mybit == "HBHENegativeNoise")
58  else if (mybit == "HBHEPulseFitBit")
60  else if (mybit == "HBHEOOTPU")
62 
63  // HF ++++++++++++++++++++
64  else if (mybit == "HFLongShort")
66  else if (mybit == "HFS8S1Ratio")
68  else if (mybit == "HFPET")
70  else if (mybit == "HFSignalAsymmetry")
72  else if (mybit == "HFAnomalousHit")
74 
75  // Common subdetector bits ++++++++++++++++++++++
76  else if (mybit == "TimingFromTDC")
78  else if (mybit == "UserDefinedBit0")
80 
81  // unknown -------------------
82  else {
83  // error: unrecognized flag name
84  edm::LogWarning("HcalSeverityLevelComputer")
85  << "HcalSeverityLevelComputer: Error: RecHitFlag >>" << mybit << "<< unknown. Ignoring.";
86  return false;
87  }
88  } else // Phase 0 Rechit flags
89  {
90  // HB, HE ++++++++++++++++++++
91  if (mybit == "HBHEHpdHitMultiplicity")
93  else if (mybit == "HBHEPulseShape")
95  else if (mybit == "HSCP_R1R2")
97  else if (mybit == "HSCP_FracLeader")
99  else if (mybit == "HSCP_OuterEnergy")
101  else if (mybit == "HSCP_ExpFit")
103  else if (mybit == "HBHEFlatNoise")
105  else if (mybit == "HBHESpikeNoise")
107  else if (mybit == "HBHETriangleNoise")
109  else if (mybit == "HBHETS4TS5Noise")
111  else if (mybit == "HBHENegativeNoise")
113  else if (mybit == "HBHEPulseFitBit")
115  else if (mybit == "HBHEOOTPU")
117 
118  // These are multi-bit counters; we may have to revisit how to set them in the SLComputer in the future
119  else if (mybit == "HBHETimingTrustBits")
121  else if (mybit == "HBHETimingShapedCutsBits")
123  else if (mybit == "HBHEIsolatedNoise")
125 
126  // HO ++++++++++++++++++++
127  else if (mybit == "HOBit")
129 
130  // HF ++++++++++++++++++++
131  else if (mybit == "HFLongShort")
133  else if (mybit == "HFDigiTime")
135  else if (mybit == "HFInTimeWindow")
137  else if (mybit == "HFS8S1Ratio")
139  else if (mybit == "HFPET")
141  else if (mybit == "HFTimingTrustBits")
142  setBit(HcalCaloFlagLabels::HFTimingTrustBits, mydef.HFFlagMask); // multi-bit counter
143 
144  // ZDC ++++++++++++++++++++
145  else if (mybit == "ZDCBit")
147 
148  // Calib ++++++++++++++++++++
149  else if (mybit == "CalibrationBit")
151 
152  // Common subdetector bits ++++++++++++++++++++++
153  else if (mybit == "TimingSubtractedBit")
155  else if (mybit == "TimingAddedBit")
157  else if (mybit == "TimingErrorBit")
159  else if (mybit == "ADCSaturationBit")
161  else if (mybit == "AddedSimHcalNoise")
163 
164  else if (mybit == "UserDefinedBit0")
166 
167  // additional defined diagnostic bits; not currently used for rejection
168  else if (mybit == "PresampleADC")
170  else if (mybit == "Fraction2TS")
172  mydef); // should deprecate this at some point; it's been replaced by PresampleADC
173 
174  // unknown -------------------
175  else {
176  // error: unrecognized flag name
177  edm::LogWarning("HcalSeverityLevelComputer")
178  << "HcalSeverityLevelComputer: Error: RecHitFlag >>" << mybit << "<< unknown. Ignoring.";
179  return false;
180  }
181  }
182  return true;
183 }
184 
186  // initialize: get the levels and masks from the cfg:
187  typedef std::vector<edm::ParameterSet> myParameters;
188  myParameters myLevels = iConfig.getParameter<myParameters>((std::string) "SeverityLevels");
189 
190  unsigned int phase_ = iConfig.getParameter<unsigned int>("phase");
191 
192  // now run through the parameter set vector:
193  for (myParameters::iterator itLevels = myLevels.begin(); itLevels != myLevels.end(); ++itLevels) {
194  // create the basic object
196 
197  // get the level:
198  mydef.sevLevel = itLevels->getParameter<int>("Level");
199 
200  // get the RecHitFlags:
201  std::vector<std::string> myRecHitFlags = itLevels->getParameter<std::vector<std::string> >("RecHitFlags");
202 
203  // get channel statuses:
204  std::vector<std::string> myChStatuses = itLevels->getParameter<std::vector<std::string> >("ChannelStatus");
205 
206  // now translate the RecHitFlags and the ChannelStatuses into a mask each:
207  // create counters for invalid flags to be able to catch cases where a definition consists only of invalid bit names:
208  unsigned int bvalid = 0;
209  unsigned int bnonempty = 0;
210  // channel status:
211  for (unsigned k = 0; k < myChStatuses.size(); k++) {
212  if (myChStatuses[k].empty())
213  break; // empty string
214  bnonempty++;
215  bvalid += getChStBit(mydef, myChStatuses[k]);
216  }
217  // RecHitFlag:
218  // HBHEStatusFlag, HOStatusFlag, HFStatusFlag, ZDCStatusFlag, CalibrationFlag
219  for (unsigned k = 0; k < myRecHitFlags.size(); k++) {
220  if (myRecHitFlags[k].empty())
221  break; // empty string
222  bnonempty++;
223  bvalid += getRecHitFlag(mydef, myRecHitFlags[k], phase_);
224  }
225 
226  // std::cout << "Made Severity Level:" << std::endl;
227  // std::cout << mydef << std::endl;
228 
229  // case where definition is made entirely out of invalid flags but not empty strings
230  if ((!bvalid) && (bnonempty)) {
231  edm::LogWarning("HcalSeverityLevelComputer") << "Warning: level " << mydef.sevLevel
232  << " consists of invalid definitions only: "
233  // << myRecHitFlags << "; " << myChStatuses
234  << " Ignoring definition.";
235  continue;
236  }
237 
238  // finally, append the masks to the mask vectors, sorting them according to level
239  std::vector<HcalSeverityDefinition>::iterator it = SevDef.begin();
240 
241  do {
242  if (it == SevDef.end()) {
243  SevDef.push_back(mydef);
244  break;
245  }
246 
247  if (it->sevLevel == mydef.sevLevel) {
248  edm::LogWarning("HcalSeverityLevelComputer") << "HcalSeverityLevelComputer: Warning: level " << mydef.sevLevel
249  << " already defined. Ignoring new definition.";
250  break;
251  }
252 
253  if (it->sevLevel < mydef.sevLevel)
254  if (((it + 1) == SevDef.end()) || ((it + 1)->sevLevel > mydef.sevLevel)) {
255  SevDef.insert(it + 1, mydef);
256  break;
257  }
258 
259  it++;
260  } while (it != SevDef.end());
261 
262  } //for (myParameters::iterator itLevels=myLevels.begin(); itLevels != myLevels.end(); ++itLevels)
263 
264  edm::LogInfo("HcalSeverityLevelComputer") << "HcalSeverityLevelComputer - Summary of Severity Levels:" << std::endl;
265  for (std::vector<HcalSeverityDefinition>::iterator it = SevDef.begin(); it != SevDef.end(); it++) {
266  // debug: write the levels definitions on screen:
267  edm::LogInfo("HcalSeverityLevelComputer") << (*it) << std::endl;
268  }
269 
270  //
271  // Now make the definition for recoveredRecHit
272  //
273  std::vector<std::string> myRecovered = iConfig.getParameter<std::vector<std::string> >("RecoveredRecHitBits");
275  for (unsigned k = 0; k < myRecovered.size(); k++) {
276  if (myRecovered[k].empty())
277  break;
278  getRecHitFlag((*RecoveredRecHit_), myRecovered[k], phase_);
279  }
280 
281  //
282  // Now make the definition for dropChannel
283  //
284  std::vector<std::string> myDrop = iConfig.getParameter<std::vector<std::string> >("DropChannelStatusBits");
286  for (unsigned k = 0; k < myDrop.size(); k++) {
287  if (myDrop[k].empty())
288  break;
289  getChStBit((*DropChannel_), myDrop[k]);
290  }
291 
292  edm::LogInfo("HcalSeverityLevelComputer") << "HcalSeverityLevelComputer - Summary for Recovered RecHit bits: \n"
293  << (*RecoveredRecHit_) << std::endl
294  << "HcalSeverityLevelComputer - Summary for Drop the Channel bits: \n"
295  << (*DropChannel_) << std::endl;
296 
297 } // HcalSeverityLevelComputer::HcalSeverityLevelComputer
298 
300  delete DropChannel_;
301  delete RecoveredRecHit_;
302 }
303 
305  const uint32_t& myflag,
306  const uint32_t& mystatus) const {
307  uint32_t myRecHitMask;
308  HcalGenericDetId myId(myid);
310 
311  // for (unsigned i=(SevDef.size()-1); i >= 0; i--) // Wrong
312  // Since i is unsigned, i >= 0 is always true,
313  // and the loop termination condition is never reached.
314  // We offset the loop index by one to fix this.
315  for (size_t j = (SevDef.size()); j > 0; j--) {
316  size_t i = j - 1;
317  switch (mysubdet) {
320  myRecHitMask = SevDef[i].HBHEFlagMask;
321  break;
323  myRecHitMask = SevDef[i].HOFlagMask;
324  break;
326  myRecHitMask = SevDef[i].HFFlagMask;
327  break;
329  myRecHitMask = SevDef[i].ZDCFlagMask;
330  break;
332  myRecHitMask = SevDef[i].CalibFlagMask;
333  break;
334  default:
335  myRecHitMask = 0;
336  }
337 
338  // for debugging:
339  // std::cout << std::hex << " SLD: RHMask 0x" << myRecHitMask
340  // << " chstmask 0x" << SevDef[i].chStatusMask
341  // << " RHmask & myflag 0x" << (myRecHitMask&myflag)
342  // << " chstmask & mystatus 0x" << (SevDef[i].chStatusMask&mystatus)
343  // << std::dec << " level = " << SevDef[i].sevLevel << std::endl;
344 
345  // true if:
346  // rechitmask empty and chstatusmask empty
347  // rechitmask empty and chstatusmask&mychstat true
348  // chstatusmask empty and rechitmask&myflag true
349  // rechitmask&myflag true OR chstatusmask&mychstat true
350 
351  // if ( ( ( (!myRecHitMask) || (myRecHitMask & myflag) ) &&
352  if ((((!SevDef[i].HBHEFlagMask && !SevDef[i].HOFlagMask && !SevDef[i].HFFlagMask && !SevDef[i].ZDCFlagMask &&
353  !SevDef[i].CalibFlagMask) ||
354  (myRecHitMask & myflag)) &&
355  ((!SevDef[i].chStatusMask) || (SevDef[i].chStatusMask & mystatus))) ||
356  ((myRecHitMask & myflag) || (SevDef[i].chStatusMask & mystatus)))
357  return SevDef[i].sevLevel;
358  }
359 
360  return -100; // default value, if no definition applies
361 }
362 
363 bool HcalSeverityLevelComputer::recoveredRecHit(const DetId& myid, const uint32_t& myflag) const {
364  uint32_t myRecHitMask;
365  HcalGenericDetId myId(myid);
367 
368  switch (mysubdet) {
371  myRecHitMask = RecoveredRecHit_->HBHEFlagMask;
372  break;
374  myRecHitMask = RecoveredRecHit_->HOFlagMask;
375  break;
377  myRecHitMask = RecoveredRecHit_->HFFlagMask;
378  break;
380  myRecHitMask = RecoveredRecHit_->ZDCFlagMask;
381  break;
383  myRecHitMask = RecoveredRecHit_->CalibFlagMask;
384  break;
385  default:
386  myRecHitMask = 0;
387  }
388 
389  if (myRecHitMask & myflag)
390  return true;
391 
392  return false;
393 }
394 
395 bool HcalSeverityLevelComputer::dropChannel(const uint32_t& mystatus) const {
396  if (DropChannel_->chStatusMask & mystatus)
397  return true;
398 
399  return false;
400 }
401 
402 void HcalSeverityLevelComputer::setBit(const unsigned bitnumber, uint32_t& where) {
403  uint32_t statadd = 0x1 << (bitnumber);
404  where = where | statadd;
405 }
406 
407 void HcalSeverityLevelComputer::setAllRHMasks(const unsigned bitnumber, HcalSeverityDefinition& mydef) {
408  setBit(bitnumber, mydef.HBHEFlagMask);
409  setBit(bitnumber, mydef.HOFlagMask);
410  setBit(bitnumber, mydef.HFFlagMask);
411  setBit(bitnumber, mydef.ZDCFlagMask);
412  setBit(bitnumber, mydef.CalibFlagMask);
413 }
414 
416  s << "Hcal Severity Level Definition, Level = " << def.sevLevel << std::endl;
417  s << std::hex << std::showbase;
418  s << " channel status mask = " << def.chStatusMask << std::endl;
419  s << " HBHEFlagMask = " << def.HBHEFlagMask << std::endl;
420  s << " HOFlagMask = " << def.HOFlagMask << std::endl;
421  s << " HFFlagMask = " << def.HFFlagMask << std::endl;
422  s << " ZDCFlagMask = " << def.ZDCFlagMask << std::endl;
423  s << " CalibFlagMask = " << def.CalibFlagMask << std::dec << std::noshowbase << std::endl;
424  return s;
425 }
int def(FILE *, FILE *, int)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
HcalSeverityLevelComputer(const edm::ParameterSet &)
bool recoveredRecHit(const DetId &myid, const uint32_t &myflag) const
bool getRecHitFlag(HcalSeverityDefinition &mydef, const std::string &mybit, int phase_)
std::vector< HcalSeverityDefinition > SevDef
HcalSeverityDefinition * RecoveredRecHit_
HcalGenericSubdetector genericSubdet() const
Log< level::Info, false > LogInfo
Definition: DetId.h:17
int getSeverityLevel(const DetId &myid, const uint32_t &myflag, const uint32_t &mystatus) const
void setBit(const unsigned bitnumber, uint32_t &where)
HcalSeverityDefinition * DropChannel_
std::ostream & operator<<(std::ostream &s, const HcalSeverityLevelComputer::HcalSeverityDefinition &def)
Log< level::Warning, false > LogWarning
void setAllRHMasks(const unsigned bitnumber, HcalSeverityDefinition &mydef)
bool dropChannel(const uint32_t &mystatus) const
bool getChStBit(HcalSeverityDefinition &mydef, const std::string &mybit)