CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
NoisyChannel Class Reference

Check if any channels are noisy compared to neighboring ones. More...

#include <QTest.h>

Inheritance diagram for NoisyChannel:
SimpleTest QCriterion

Public Member Functions

 NoisyChannel (const std::string &name)
 
float runTest (const MonitorElement *me) override
 
void setNumNeighbors (unsigned n)
 
void setTolerance (float percentage)
 
- Public Member Functions inherited from SimpleTest
std::vector< DQMChannelgetBadChannels () const override
 get vector of channels that failed test (not always relevant!) More...
 
void setMinimumEntries (unsigned n)
 set minimum # of entries needed More...
 
 SimpleTest (const std::string &name, bool keepBadChannels=false)
 
- Public Member Functions inherited from QCriterion
std::string algoName () const
 get algorithm name More...
 
std::string getMessage () const
 get message attached to test More...
 
std::string getName () const
 get name of quality test More...
 
int getStatus () const
 get test status (see Core/interface/DQMDefinitions.h) More...
 
void setErrorProb (float prob)
 
void setWarningProb (float prob)
 set probability limit for warning and error (default: 90% and 50%) More...
 

Static Public Member Functions

static std::string getAlgoName ()
 

Protected Member Functions

double getAverage (int bin, const TH1 *h) const
 
double getAverage2D (int binX, int binY, const TH2 *h) const
 
- Protected Member Functions inherited from SimpleTest
void setMessage () override
 set status & message after test has run More...
 
- Protected Member Functions inherited from QCriterion
void init ()
 initialize values More...
 
 QCriterion (std::string qtname)
 
float runTest (const MonitorElement *me, QReport &qr, DQMNet::QValue &qv)
 
void setAlgoName (std::string name)
 set algorithm name More...
 
void setVerbose (int verbose)
 probability limits for warnings, errors More...
 
virtual ~QCriterion ()=default
 

Protected Attributes

unsigned numNeighbors_
 
bool rangeInitialized_
 
float tolerance_
 
- Protected Attributes inherited from SimpleTest
std::vector< DQMChannelbadChannels_
 
bool keepBadChannels_
 
unsigned minEntries_
 
- Protected Attributes inherited from QCriterion
std::string algoName_
 name of quality test More...
 
float errorProb_
 
std::string message_
 quality test status More...
 
float prob_
 name of algorithm More...
 
std::string qtname_
 
int status_
 
int verbose_
 
float warningProb_
 message attached to test More...
 

Additional Inherited Members

- Public Types inherited from QCriterion
typedef dqm::legacy::MonitorElement MonitorElement
 (class should be created by DQMStore class) More...
 

Detailed Description

Check if any channels are noisy compared to neighboring ones.

Definition at line 254 of file QTest.h.

Constructor & Destructor Documentation

NoisyChannel::NoisyChannel ( const std::string &  name)
inline

Definition at line 256 of file QTest.h.

References QCriterion::setAlgoName().

256  : SimpleTest(name, true) {
257  rangeInitialized_ = false;
258  numNeighbors_ = 1;
260  }
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:95
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:158
bool rangeInitialized_
Definition: QTest.h:296
static std::string getAlgoName()
Definition: QTest.h:261
unsigned numNeighbors_
Definition: QTest.h:294

Member Function Documentation

static std::string NoisyChannel::getAlgoName ( )
inlinestatic
double NoisyChannel::getAverage ( int  bin,
const TH1 *  h 
) const
protected

get average for bin under consideration (see description of method setNumNeighbors)

Definition at line 379 of file QTest.cc.

References pat::helper::ParametrizationHelper::dimension(), and dqmdumpme::first.

379  {
380  int first = 1; // Do NOT use underflow bin
381  int ncx = h->GetXaxis()->GetNbins(); // Do NOT use overflow bin
382  double sum = 0;
383  int bin_start, bin_end;
384  int add_right = 0;
385  int add_left = 0;
386 
387  bin_start = bin - numNeighbors_; // First bin in integral
388  bin_end = bin + numNeighbors_; // Last bin in integral
389 
390  if (bin_start < first) { // If neighbors take you outside of histogram range shift integral right
391  add_right = first - bin_start; // How much to shift remembering we are not using underflow
392  bin_start = first; // Remember to reset the starting bin
393  bin_end += add_right;
394  if (bin_end > ncx)
395  bin_end = ncx; // If the test would be larger than histogram just sum histogram without overflow
396  }
397 
398  if (bin_end > ncx) { // Now we make sure doesn't run off right edge of histogram
399  add_left = bin_end - ncx;
400  bin_end = ncx;
401  bin_start -= add_left;
402  if (bin_start < first)
403  bin_start = first; // If the test would be larger than histogram just sum histogram without underflow
404  }
405 
406  sum += h->Integral(bin_start, bin_end);
407  sum -= h->GetBinContent(bin);
408 
409  int dimension = 2 * numNeighbors_ + 1;
410  if (dimension > h->GetNbinsX())
411  dimension = h->GetNbinsX();
412 
413  return sum / (dimension - 1);
414 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
unsigned numNeighbors_
Definition: QTest.h:294
double NoisyChannel::getAverage2D ( int  binX,
int  binY,
const TH2 *  h 
) const
protected

Do NOT use underflow or overflow bins

Definition at line 416 of file QTest.cc.

416  {
418  int firstX = 1;
419  int firstY = 1;
420  double sum = 0;
421  int ncx = h2->GetXaxis()->GetNbins();
422  int ncy = h2->GetYaxis()->GetNbins();
423 
424  int neighborsX, neighborsY; // Convert unsigned input to int so we can use comparators
425  neighborsX = numNeighbors_;
426  neighborsY = numNeighbors_;
427  int bin_startX, bin_endX;
428  int add_rightX = 0; // Start shifts at 0
429  int add_leftX = 0;
430  int bin_startY, bin_endY;
431  int add_topY = 0;
432  int add_downY = 0;
433 
434  bin_startX = binX - neighborsX; // First bin in X
435  bin_endX = binX + neighborsX; // Last bin in X
436 
437  if (bin_startX < firstX) { // If neighbors take you outside of histogram range shift integral right
438  add_rightX = firstX - bin_startX; // How much to shift remembering we are no using underflow
439  bin_startX = firstX; // Remember to reset the starting bin
440  bin_endX += add_rightX;
441  if (bin_endX > ncx)
442  bin_endX = ncx;
443  }
444 
445  if (bin_endX > ncx) { // Now we make sure doesn't run off right edge of histogram
446  add_leftX = bin_endX - ncx;
447  bin_endX = ncx;
448  bin_startX -= add_leftX;
449  if (bin_startX < firstX)
450  bin_startX = firstX; // If the test would be larger than histogram just sum histogram without underflow
451  }
452 
453  bin_startY = binY - neighborsY; // First bin in Y
454  bin_endY = binY + neighborsY; // Last bin in Y
455 
456  if (bin_startY < firstY) { // If neighbors take you outside of histogram range shift integral up
457  add_topY = firstY - bin_startY; // How much to shift remembering we are no using underflow
458  bin_startY = firstY; // Remember to reset the starting bin
459  bin_endY += add_topY;
460  if (bin_endY > ncy)
461  bin_endY = ncy;
462  }
463 
464  if (bin_endY > ncy) { // Now we make sure doesn't run off top edge of histogram
465  add_downY = bin_endY - ncy;
466  bin_endY = ncy;
467  bin_startY -= add_downY;
468  if (bin_startY < firstY)
469  bin_startY = firstY; // If the test would be larger than histogram just sum histogram without underflow
470  }
471 
472  sum += h2->Integral(bin_startX, bin_endX, bin_startY, bin_endY);
473  sum -= h2->GetBinContent(binX, binY);
474 
475  int dimensionX = 2 * neighborsX + 1;
476  int dimensionY = 2 * neighborsY + 1;
477 
478  if (dimensionX > h2->GetNbinsX())
479  dimensionX = h2->GetNbinsX();
480  if (dimensionY > h2->GetNbinsY())
481  dimensionY = h2->GetNbinsY();
482 
483  return sum / (dimensionX * dimensionY - 1); // Average is sum over the # of bins used
484 
485 } // End getAverage2D
unsigned numNeighbors_
Definition: QTest.h:294
float NoisyChannel::runTest ( const MonitorElement me)
overridevirtual

Reimplemented from QCriterion.

Definition at line 267 of file QTest.cc.

References funct::abs(), PDRates::average, newFWLiteAna::bin, officialStyle::chan, relmon_rootfiles_spy::contents, gather_cfg::cout, dqmdumpme::first, dqm::impl::MonitorElement::getFullname(), dqm::legacy::MonitorElement::getRootObject(), dqm::legacy::MonitorElement::getTH1D(), dqm::legacy::MonitorElement::getTH1F(), dqm::legacy::MonitorElement::getTH1S(), dqm::legacy::MonitorElement::getTH2D(), dqm::legacy::MonitorElement::getTH2F(), dqm::legacy::MonitorElement::getTH2S(), h, dqm::impl::MonitorElement::kind(), dqmdumpme::last, LaserClient_cfi::nbins, hlt_dqm_clientPB-live_cfg::nbinsX, hlt_dqm_clientPB-live_cfg::nbinsY, MonitorElementData::TH1D, MonitorElementData::TH1F, MonitorElementData::TH1S, MonitorElementData::TH2D, MonitorElementData::TH2F, and MonitorElementData::TH2S.

267  {
268  badChannels_.clear();
269  if (!me)
270  return -1;
271  if (!me->getRootObject())
272  return -1;
273  TH1* h = nullptr; //initialize histogram pointer
274  TH2* h2 = nullptr; //initialize histogram pointer
275 
276  if (verbose_ > 1)
277  std::cout << "QTest:" << getAlgoName() << "::runTest called on " << me->getFullname() << "\n";
278 
279  int nbins = 0;
280  int nbinsX = 0, nbinsY = 0;
281  //-- TH1F
282  if (me->kind() == MonitorElement::Kind::TH1F) {
283  nbins = me->getTH1F()->GetXaxis()->GetNbins();
284  h = me->getTH1F(); // access Test histo
285  }
286  //-- TH1S
287  else if (me->kind() == MonitorElement::Kind::TH1S) {
288  nbins = me->getTH1S()->GetXaxis()->GetNbins();
289  h = me->getTH1S(); // access Test histo
290  }
291  //-- TH1D
292  else if (me->kind() == MonitorElement::Kind::TH1D) {
293  nbins = me->getTH1D()->GetXaxis()->GetNbins();
294  h = me->getTH1D(); // access Test histo
295  }
296  //-- TH2
297  else if (me->kind() == MonitorElement::Kind::TH2F) {
298  nbinsX = me->getTH2F()->GetXaxis()->GetNbins();
299  nbinsY = me->getTH2F()->GetYaxis()->GetNbins();
300  h2 = me->getTH2F(); // access Test histo
301  }
302  //-- TH2
303  else if (me->kind() == MonitorElement::Kind::TH2S) {
304  nbinsX = me->getTH2S()->GetXaxis()->GetNbins();
305  nbinsY = me->getTH2S()->GetYaxis()->GetNbins();
306  h2 = me->getTH2S(); // access Test histo
307  }
308  //-- TH2
309  else if (me->kind() == MonitorElement::Kind::TH2D) {
310  nbinsX = me->getTH2F()->GetXaxis()->GetNbins();
311  nbinsY = me->getTH2F()->GetYaxis()->GetNbins();
312  h2 = me->getTH2D(); // access Test histo
313  } else {
314  if (verbose_ > 0)
315  std::cout << "QTest:NoisyChannel"
316  << " ME " << me->getFullname() << " does not contain TH1F/TH1S/TH1D or TH2F/TH2S/TH2D, exiting\n";
317  return -1;
318  }
319 
320  //-- QUALITY TEST itself
321 
322  // do NOT use underflow bin
323  int first = 1;
324  // do NOT use overflow bin
325  int last = nbins;
326  int lastX = nbinsX, lastY = nbinsY;
327  // bins outside Y-range
328  int fail = 0;
329  int bin;
330  int binX, binY;
331  if (h != nullptr) {
332  if (!rangeInitialized_ || !h->GetXaxis()) {
333  return 1; // all channels are accepted if tolerance has not been set
334  }
335  for (bin = first; bin <= last; ++bin) {
336  double contents = h->GetBinContent(bin);
337  double average = getAverage(bin, h);
338  bool failure = false;
339  if (average != 0)
340  failure = (((contents - average) / std::abs(average)) > tolerance_);
341 
342  if (failure) {
343  ++fail;
344  DQMChannel chan(bin, 0, 0, contents, h->GetBinError(bin));
345  badChannels_.push_back(chan);
346  }
347  }
348 
349  // return fraction of bins that passed test
350  return 1. * (nbins - fail) / nbins;
351  } else if (h2 != nullptr) {
352  for (binY = first; binY <= lastY; ++binY) {
353  for (binX = first; binX <= lastX; ++binX) {
354  double contents = h2->GetBinContent(binX, binY);
355  double average = getAverage2D(binX, binY, h2);
356  bool failure = false;
357  if (average != 0)
358  failure = (((contents - average) / std::abs(average)) > tolerance_);
359  if (failure) {
360  ++fail;
361  DQMChannel chan(binX, 0, 0, contents, h2->GetBinError(binX));
362  badChannels_.push_back(chan);
363  }
364  } //end x loop
365  } //end y loop
366  // return fraction of bins that passed test
367  return 1. * ((nbinsX * nbinsY) - fail) / (nbinsX * nbinsY);
368  } //end nullptr conditional
369  else {
370  if (verbose_ > 0)
371  std::cout << "QTest:NoisyChannel"
372  << " TH1/TH2F are NULL, exiting\n";
373  return -1;
374  }
375 }
virtual TH2D * getTH2D() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
double getAverage(int bin, const TH1 *h) const
Definition: QTest.cc:379
virtual TH2F * getTH2F() const
double getAverage2D(int binX, int binY, const TH2 *h) const
Definition: QTest.cc:416
int verbose_
Definition: QTest.h:138
virtual TH1F * getTH1F() const
Kind kind() const
Get the type of the monitor element.
virtual TH1S * getTH1S() const
const std::string getFullname() const
get full name of ME including Pathname
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual TH2S * getTH2S() const
virtual TH1D * getTH1D() const
std::vector< DQMChannel > badChannels_
Definition: QTest.h:173
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
float tolerance_
Definition: QTest.h:293
TObject * getRootObject() const override
bool rangeInitialized_
Definition: QTest.h:296
static std::string getAlgoName()
Definition: QTest.h:261
void NoisyChannel::setNumNeighbors ( unsigned  n)
inline

set # of neighboring channels for calculating average to be used for comparison with channel under consideration; use 1 for considering bin+1 and bin-1 (default), use 2 for considering bin+1,bin-1, bin+2,bin-2, etc; Will use rollover when bin+i or bin-i is beyond histogram limits (e.g. for histogram with N bins, bin N+1 corresponds to bin 1, and bin -1 corresponds to bin N)

Definition at line 271 of file QTest.h.

References dqmiodumpmetadata::n.

Referenced by QTestConfigure::EnableNoisyChannelTest().

271  {
272  if (n > 0)
273  numNeighbors_ = n;
274  }
unsigned numNeighbors_
Definition: QTest.h:294
void NoisyChannel::setTolerance ( float  percentage)
inline

set (percentage) tolerance for considering a channel noisy; eg. if tolerance = 20%, a channel will be noisy if (contents-average)/|average| > 20%; average is calculated from neighboring channels (also see method setNumNeighbors)

Definition at line 280 of file QTest.h.

References newFWLiteAna::bin, and h.

Referenced by QTestConfigure::EnableNoisyChannelTest().

280  {
281  if (percentage >= 0) {
282  tolerance_ = percentage;
283  rangeInitialized_ = true;
284  }
285  }
float tolerance_
Definition: QTest.h:293
bool rangeInitialized_
Definition: QTest.h:296

Member Data Documentation

unsigned NoisyChannel::numNeighbors_
protected

Definition at line 294 of file QTest.h.

bool NoisyChannel::rangeInitialized_
protected

Definition at line 296 of file QTest.h.

float NoisyChannel::tolerance_
protected

Definition at line 293 of file QTest.h.