CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
50 
51  // These are multi-bit counters; we may have to revisit how to set them in the SLComputer in the future
52  else if (mybit=="HBHETimingTrustBits") setBit(HcalCaloFlagLabels::HBHETimingTrustBits, mydef.HBHEFlagMask );
53  else if (mybit=="HBHETimingShapedCutsBits") setBit(HcalCaloFlagLabels::HBHETimingShapedCutsBits, mydef.HBHEFlagMask);
54  else if (mybit=="HBHEIsolatedNoise") setBit(HcalCaloFlagLabels::HBHEIsolatedNoise, mydef.HBHEFlagMask );
55 
56  // HO ++++++++++++++++++++
57  else if (mybit == "HOBit") setBit(HcalCaloFlagLabels::HOBit, mydef.HOFlagMask);
58 
59  // HF ++++++++++++++++++++
60  else if (mybit == "HFLongShort") setBit(HcalCaloFlagLabels::HFLongShort, mydef.HFFlagMask);
61  else if (mybit == "HFDigiTime") setBit(HcalCaloFlagLabels::HFDigiTime, mydef.HFFlagMask);
62  else if (mybit == "HFInTimeWindow") setBit(HcalCaloFlagLabels::HFInTimeWindow, mydef.HFFlagMask);
63  else if (mybit == "HFS8S1Ratio") setBit(HcalCaloFlagLabels::HFS8S1Ratio, mydef.HFFlagMask);
64  else if (mybit == "HFPET") setBit(HcalCaloFlagLabels::HFPET, mydef.HFFlagMask);
65  else if (mybit == "HFTimingTrustBits") setBit(HcalCaloFlagLabels::HFTimingTrustBits, mydef.HFFlagMask); // multi-bit counter
66 
67  // ZDC ++++++++++++++++++++
68  else if (mybit == "ZDCBit") setBit(HcalCaloFlagLabels::ZDCBit, mydef.ZDCFlagMask);
69 
70  // Calib ++++++++++++++++++++
71  else if (mybit == "CalibrationBit") setBit(HcalCaloFlagLabels::CalibrationBit, mydef.CalibFlagMask);
72 
73  // Common subdetector bits ++++++++++++++++++++++
74  else if (mybit == "TimingSubtractedBit") setAllRHMasks(HcalCaloFlagLabels::TimingSubtractedBit, mydef);
75  else if (mybit == "TimingAddedBit") setAllRHMasks(HcalCaloFlagLabels::TimingAddedBit, mydef);
76  else if (mybit == "TimingErrorBit") setAllRHMasks(HcalCaloFlagLabels::TimingErrorBit, mydef);
77  else if (mybit == "ADCSaturationBit") setAllRHMasks(HcalCaloFlagLabels::ADCSaturationBit, mydef);
78  else if (mybit== "AddedSimHcalNoise") setAllRHMasks(HcalCaloFlagLabels::AddedSimHcalNoise, mydef);
79 
80  else if (mybit == "UserDefinedBit0") setAllRHMasks(HcalCaloFlagLabels::UserDefinedBit0, mydef);
81  else if (mybit == "UserDefinedBit1") setAllRHMasks(HcalCaloFlagLabels::UserDefinedBit1, mydef);
82  else if (mybit == "UserDefinedBit2") setAllRHMasks(HcalCaloFlagLabels::UserDefinedBit2, 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 
234 int HcalSeverityLevelComputer::getSeverityLevel(const DetId& myid, const uint32_t& myflag,
235  const uint32_t& mystatus) const
236 {
237  uint32_t myRecHitMask;
238  HcalGenericDetId myId(myid);
240 
241  // for (unsigned i=(SevDef.size()-1); i >= 0; i--) // Wrong
242  // Since i is unsigned, i >= 0 is always true,
243  // and the loop termination condition is never reached.
244  // We offset the loop index by one to fix this.
245  for (size_t j=(SevDef.size()); j > 0; j--)
246  {
247  size_t i = j - 1;
248  switch (mysubdet)
249  {
251  myRecHitMask = SevDef[i].HBHEFlagMask; break;
252  case HcalGenericDetId::HcalGenOuter : myRecHitMask = SevDef[i].HOFlagMask; break;
253  case HcalGenericDetId::HcalGenForward : myRecHitMask = SevDef[i].HFFlagMask; break;
254  case HcalGenericDetId::HcalGenZDC : myRecHitMask = SevDef[i].ZDCFlagMask; break;
255  case HcalGenericDetId::HcalGenCalibration : myRecHitMask = SevDef[i].CalibFlagMask; break;
256  default: myRecHitMask = 0;
257  }
258 
259  // for debugging:
260 // std::cout << std::hex << " SLD: RHMask 0x" << myRecHitMask
261 // << " chstmask 0x" << SevDef[i].chStatusMask
262 // << " RHmask & myflag 0x" << (myRecHitMask&myflag)
263 // << " chstmask & mystatus 0x" << (SevDef[i].chStatusMask&mystatus)
264 // << std::dec << " level = " << SevDef[i].sevLevel << std::endl;
265 
266  // true if:
267  // rechitmask empty and chstatusmask empty
268  // rechitmask empty and chstatusmask&mychstat true
269  // chstatusmask empty and rechitmask&myflag true
270  // rechitmask&myflag true OR chstatusmask&mychstat true
271 
272 
273  // if ( ( ( (!myRecHitMask) || (myRecHitMask & myflag) ) &&
274  if ( ( ( ( !SevDef[i].HBHEFlagMask
275  && !SevDef[i].HOFlagMask
276  && !SevDef[i].HFFlagMask
277  && !SevDef[i].ZDCFlagMask
278  && !SevDef[i].CalibFlagMask )
279  || (myRecHitMask & myflag) )
280  && ( (!SevDef[i].chStatusMask) || (SevDef[i].chStatusMask & mystatus) ) )
281  || ( (myRecHitMask & myflag) || (SevDef[i].chStatusMask & mystatus) ) )
282  return SevDef[i].sevLevel;
283 
284  }
285 
286  return -100; // default value, if no definition applies
287 }
288 
289 bool HcalSeverityLevelComputer::recoveredRecHit(const DetId& myid, const uint32_t& myflag) const
290 {
291  uint32_t myRecHitMask;
292  HcalGenericDetId myId(myid);
294 
295  switch (mysubdet)
296  {
298  myRecHitMask = RecoveredRecHit_->HBHEFlagMask; break;
299  case HcalGenericDetId::HcalGenOuter : myRecHitMask = RecoveredRecHit_->HOFlagMask; break;
300  case HcalGenericDetId::HcalGenForward : myRecHitMask = RecoveredRecHit_->HFFlagMask; break;
301  case HcalGenericDetId::HcalGenZDC : myRecHitMask = RecoveredRecHit_->ZDCFlagMask; break;
303  default: myRecHitMask = 0;
304  }
305 
306  if (myRecHitMask & myflag)
307  return true;
308 
309  return false;
310 }
311 
312 bool HcalSeverityLevelComputer::dropChannel(const uint32_t& mystatus) const
313 {
314  if (DropChannel_->chStatusMask & mystatus)
315  return true;
316 
317  return false;
318 }
319 
320 void HcalSeverityLevelComputer::setBit(const unsigned bitnumber, uint32_t& where)
321 {
322  uint32_t statadd = 0x1<<(bitnumber);
323  where = where|statadd;
324 }
325 
327 {
328  setBit(bitnumber, mydef.HBHEFlagMask);
329  setBit(bitnumber, mydef.HOFlagMask);
330  setBit(bitnumber, mydef.HFFlagMask);
331  setBit(bitnumber, mydef.ZDCFlagMask);
332  setBit(bitnumber, mydef.CalibFlagMask);
333 }
334 
336 {
337  s << "Hcal Severity Level Definition, Level = " << def.sevLevel << std::endl;
338  s << std::hex << std::showbase;
339  s << " channel status mask = " << def.chStatusMask << std::endl;
340  s << " HBHEFlagMask = " << def.HBHEFlagMask << std::endl;
341  s << " HOFlagMask = " << def.HOFlagMask << std::endl;
342  s << " HFFlagMask = " << def.HFFlagMask << std::endl;
343  s << " ZDCFlagMask = " << def.ZDCFlagMask << std::endl;
344  s << " CalibFlagMask = " << def.CalibFlagMask << std::dec << std::noshowbase << std::endl;
345  return s;
346 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
HcalSeverityLevelComputer(const edm::ParameterSet &)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
std::vector< HcalSeverityDefinition > SevDef
bool recoveredRecHit(const DetId &myid, const uint32_t &myflag) const
int j
Definition: DBlmapReader.cc:9
bool dropChannel(const uint32_t &mystatus) const
HcalSeverityDefinition * RecoveredRecHit_
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)