CMS 3D CMS Logo

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