CMS 3D CMS Logo

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