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
 (class should be created by DQMStore class) 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...
 

Detailed Description

Check if any channels are noisy compared to neighboring ones.

Definition at line 334 of file QTest.h.

Constructor & Destructor Documentation

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

Definition at line 337 of file QTest.h.

References QCriterion::setAlgoName().

337  : SimpleTest(name,true)
338  {
339  rangeInitialized_ = false;
340  numNeighbors_ = 1;
342  }
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:80
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:140
bool rangeInitialized_
Definition: QTest.h:377
static std::string getAlgoName()
Definition: QTest.h:343
unsigned numNeighbors_
Definition: QTest.h:375

Member Function Documentation

static std::string NoisyChannel::getAlgoName ( )
inlinestatic

Definition at line 343 of file QTest.h.

References QCriterion::runTest().

Referenced by QTestConfigure::EnableNoisyChannelTest(), QTestConfigure::enableTests(), and QTestParameterNames::QTestParameterNames().

343 { return "NoisyChannel"; }
double NoisyChannel::getAverage ( int  bin,
const TH1 *  h 
) const
protected

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

Definition at line 987 of file QTest.cc.

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

988 {
989  int first = 1; // Do NOT use underflow bin
990  int ncx = h->GetXaxis()->GetNbins(); // Do NOT use overflow bin
991  double sum = 0;
992  int bin_start, bin_end;
993  int add_right = 0;
994  int add_left = 0;
995 
996  bin_start = bin - numNeighbors_; // First bin in integral
997  bin_end = bin + numNeighbors_; // Last bin in integral
998 
999  if (bin_start < first) { // If neighbors take you outside of histogram range shift integral right
1000  add_right = first - bin_start; // How much to shift remembering we are not using underflow
1001  bin_start = first; // Remember to reset the starting bin
1002  bin_end += add_right;
1003  if (bin_end > ncx) bin_end = ncx; // If the test would be larger than histogram just sum histogram without overflow
1004  }
1005 
1006  if (bin_end > ncx) { // Now we make sure doesn't run off right edge of histogram
1007  add_left = bin_end - ncx;
1008  bin_end = ncx;
1009  bin_start -= add_left;
1010  if (bin_start < first) bin_start = first; // If the test would be larger than histogram just sum histogram without underflow
1011  }
1012 
1013  sum += h->Integral(bin_start, bin_end);
1014  sum -= h->GetBinContent(bin);
1015 
1016  int dimension = 2 * numNeighbors_ + 1;
1017  if ( dimension > h->GetNbinsX() ) dimension = h->GetNbinsX();
1018 
1019  return sum / (dimension - 1);
1020 }
bin
set the eta bin as selection string.
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
unsigned numNeighbors_
Definition: QTest.h:375
double NoisyChannel::getAverage2D ( int  binX,
int  binY,
const TH2 *  h 
) const
protected

Do NOT use underflow or overflow bins

Definition at line 1022 of file QTest.cc.

1023 {
1025  int firstX = 1;
1026  int firstY = 1;
1027  double sum = 0;
1028  int ncx = h2->GetXaxis()->GetNbins();
1029  int ncy = h2->GetYaxis()->GetNbins();
1030 
1031  int neighborsX, neighborsY; // Convert unsigned input to int so we can use comparators
1032  neighborsX = numNeighbors_;
1033  neighborsY = numNeighbors_;
1034  int bin_startX, bin_endX;
1035  int add_rightX = 0; // Start shifts at 0
1036  int add_leftX = 0;
1037  int bin_startY, bin_endY;
1038  int add_topY = 0;
1039  int add_downY = 0;
1040 
1041  bin_startX = binX - neighborsX; // First bin in X
1042  bin_endX = binX + neighborsX; // Last bin in X
1043 
1044  if (bin_startX < firstX) { // If neighbors take you outside of histogram range shift integral right
1045  add_rightX = firstX - bin_startX; // How much to shift remembering we are no using underflow
1046  bin_startX = firstX; // Remember to reset the starting bin
1047  bin_endX += add_rightX;
1048  if (bin_endX > ncx) bin_endX = ncx;
1049  }
1050 
1051  if (bin_endX > ncx) { // Now we make sure doesn't run off right edge of histogram
1052  add_leftX = bin_endX - ncx;
1053  bin_endX = ncx;
1054  bin_startX -= add_leftX;
1055  if (bin_startX < firstX) bin_startX = firstX; // If the test would be larger than histogram just sum histogram without underflow
1056  }
1057 
1058  bin_startY = binY - neighborsY; // First bin in Y
1059  bin_endY = binY + neighborsY; // Last bin in Y
1060 
1061  if (bin_startY < firstY) { // If neighbors take you outside of histogram range shift integral up
1062  add_topY = firstY - bin_startY; // How much to shift remembering we are no using underflow
1063  bin_startY = firstY; // Remember to reset the starting bin
1064  bin_endY += add_topY;
1065  if (bin_endY > ncy) bin_endY = ncy;
1066  }
1067 
1068  if (bin_endY > ncy){ // Now we make sure doesn't run off top edge of histogram
1069  add_downY = bin_endY - ncy;
1070  bin_endY = ncy;
1071  bin_startY -= add_downY;
1072  if (bin_startY < firstY) bin_startY = firstY; // If the test would be larger than histogram just sum histogram without underflow
1073  }
1074 
1075  sum += h2->Integral(bin_startX, bin_endX, bin_startY, bin_endY);
1076  sum -= h2->GetBinContent(binX, binY);
1077 
1078  int dimensionX = 2 * neighborsX + 1;
1079  int dimensionY = 2 * neighborsY + 1;
1080 
1081  if ( dimensionX > h2->GetNbinsX() ) dimensionX = h2->GetNbinsX();
1082  if ( dimensionY > h2->GetNbinsY() ) dimensionY = h2->GetNbinsY();
1083 
1084  return sum / (dimensionX * dimensionY - 1); // Average is sum over the # of bins used
1085 
1086 } // End getAverage2D
unsigned numNeighbors_
Definition: QTest.h:375
float NoisyChannel::runTest ( const MonitorElement me)
overridevirtual

Reimplemented from QCriterion.

Definition at line 859 of file QTest.cc.

References funct::abs(), stringResolutionProvider_cfi::bin, officialStyle::chan, relmon_rootfiles_spy::contents, gather_cfg::cout, MonitorElement::DQM_KIND_TH1D, MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH1S, MonitorElement::DQM_KIND_TH2D, MonitorElement::DQM_KIND_TH2F, MonitorElement::DQM_KIND_TH2S, cmsPerfPublish::fail(), plotBeamSpotDB::first, MonitorElement::getFullname(), MonitorElement::getRootObject(), MonitorElement::getTH1D(), MonitorElement::getTH1F(), MonitorElement::getTH1S(), MonitorElement::getTH2D(), MonitorElement::getTH2F(), MonitorElement::getTH2S(), MonitorElement::kind(), plotBeamSpotDB::last, and pileupCalc::nbins.

860 {
861  badChannels_.clear();
862  if (!me)
863  return -1;
864  if (!me->getRootObject())
865  return -1;
866  TH1* h=nullptr;//initialize histogram pointer
867  TH2* h2=nullptr;//initialize histogram pointer
868 
869  if (verbose_>1)
870  std::cout << "QTest:" << getAlgoName() << "::runTest called on "
871  << me-> getFullname() << "\n";
872 
873  int nbins=0;
874  int nbinsX=0, nbinsY=0;
875  //-- TH1F
877  {
878  nbins = me->getTH1F()->GetXaxis()->GetNbins();
879  h = me->getTH1F(); // access Test histo
880  }
881  //-- TH1S
882  else if (me->kind()==MonitorElement::DQM_KIND_TH1S)
883  {
884  nbins = me->getTH1S()->GetXaxis()->GetNbins();
885  h = me->getTH1S(); // access Test histo
886  }
887  //-- TH1D
888  else if (me->kind()==MonitorElement::DQM_KIND_TH1D)
889  {
890  nbins = me->getTH1D()->GetXaxis()->GetNbins();
891  h = me->getTH1D(); // access Test histo
892  }
893  //-- TH2
894  else if (me->kind()==MonitorElement::DQM_KIND_TH2F)
895  {
896  nbinsX = me->getTH2F()->GetXaxis()->GetNbins();
897  nbinsY = me->getTH2F()->GetYaxis()->GetNbins();
898  h2 = me->getTH2F(); // access Test histo
899  }
900  //-- TH2
901  else if (me->kind()==MonitorElement::DQM_KIND_TH2S)
902  {
903  nbinsX = me->getTH2S()->GetXaxis()->GetNbins();
904  nbinsY = me->getTH2S()->GetYaxis()->GetNbins();
905  h2 = me->getTH2S(); // access Test histo
906  }
907  //-- TH2
908  else if (me->kind()==MonitorElement::DQM_KIND_TH2D)
909  {
910  nbinsX = me->getTH2F()->GetXaxis()->GetNbins();
911  nbinsY = me->getTH2F()->GetYaxis()->GetNbins();
912  h2 = me->getTH2D(); // access Test histo
913  }
914  else
915  {
916  if (verbose_>0)
917  std::cout << "QTest:NoisyChannel"
918  << " ME " << me->getFullname()
919  << " does not contain TH1F/TH1S/TH1D or TH2F/TH2S/TH2D, exiting\n";
920  return -1;
921  }
922 
923  //-- QUALITY TEST itself
924 
925  // do NOT use underflow bin
926  int first = 1;
927  // do NOT use overflow bin
928  int last = nbins;
929  int lastX = nbinsX, lastY = nbinsY;
930  // bins outside Y-range
931  int fail = 0;
932  int bin;
933  int binX, binY;
934  if (h != nullptr) {
935  if ( !rangeInitialized_ || !h->GetXaxis() ){
936  return 1; // all channels are accepted if tolerance has not been set
937  }
938  for (bin = first; bin <= last; ++bin)
939  {
940  double contents = h->GetBinContent(bin);
941  double average = getAverage(bin, h);
942  bool failure = false;
943  if (average != 0)
944  failure = (((contents-average)/std::abs(average)) > tolerance_);
945 
946  if (failure)
947  {
948  ++fail;
949  DQMChannel chan(bin, 0, 0, contents, h->GetBinError(bin));
950  badChannels_.push_back(chan);
951  }
952  }
953 
954  // return fraction of bins that passed test
955  return 1.*(nbins - fail)/nbins;
956  }
957  else if (h2 !=nullptr ) {
958  for (binY = first; binY <= lastY; ++binY) {
959  for (binX = first; binX <= lastX; ++binX) {
960  double contents = h2->GetBinContent(binX, binY);
961  double average = getAverage2D(binX, binY, h2);
962  bool failure = false;
963  if (average != 0)
964  failure = (((contents-average)/std::abs(average)) > tolerance_);
965  if (failure)
966  {
967  ++fail;
968  DQMChannel chan(binX, 0, 0, contents, h2->GetBinError(binX));
969  badChannels_.push_back(chan);
970  }
971  }//end x loop
972  }//end y loop
973  // return fraction of bins that passed test
974  return 1.*((nbinsX * nbinsY) - fail)/(nbinsX * nbinsY);
975  }//end nullptr conditional
976  else
977  {
978  if (verbose_>0)
979  std::cout << "QTest:NoisyChannel"
980  << " TH1/TH2F are NULL, exiting\n";
981  return -1;
982  }
983 }
double getAverage(int bin, const TH1 *h) const
Definition: QTest.cc:987
double getAverage2D(int binX, int binY, const TH2 *h) const
Definition: QTest.cc:1022
TH1F * getTH1F() const
TH2S * getTH2S() const
int verbose_
Definition: QTest.h:120
TObject * getRootObject() const
TH2D * getTH2D() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TH2F * getTH2F() const
bin
set the eta bin as selection string.
const std::string getFullname() const
get full name of ME including Pathname
std::vector< DQMChannel > badChannels_
Definition: QTest.h:162
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:374
TH1D * getTH1D() const
TH1S * getTH1S() const
def fail(errstr="")
bool rangeInitialized_
Definition: QTest.h:377
Kind kind() const
Get the type of the monitor element.
static std::string getAlgoName()
Definition: QTest.h:343
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 353 of file QTest.h.

References gen::n.

Referenced by QTestConfigure::EnableNoisyChannelTest().

353 { if (n > 0) numNeighbors_ = n; }
unsigned numNeighbors_
Definition: QTest.h:375
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 359 of file QTest.h.

References stringResolutionProvider_cfi::bin.

Referenced by QTestConfigure::EnableNoisyChannelTest().

360  {
361  if (percentage >=0)
362  {
363  tolerance_ = percentage;
364  rangeInitialized_ = true;
365  }
366  }
float tolerance_
Definition: QTest.h:374
bool rangeInitialized_
Definition: QTest.h:377

Member Data Documentation

unsigned NoisyChannel::numNeighbors_
protected

Definition at line 375 of file QTest.h.

bool NoisyChannel::rangeInitialized_
protected

Definition at line 377 of file QTest.h.

float NoisyChannel::tolerance_
protected

Definition at line 374 of file QTest.h.