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