CMS 3D CMS Logo

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

#include <QTest.h>

Inheritance diagram for CompareToMedian:
SimpleTest QCriterion

Public Member Functions

 CompareToMedian (const std::string &name)
 
float runTest (const MonitorElement *me) override
 
void setEmptyBins (int eB)
 
void setMax (float max)
 
void setMaxMedian (float max)
 
void setMin (float min)
 
void setMinMedian (float min)
 
void setStatCut (float cut)
 
 ~CompareToMedian () override=default
 
- 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 More...
 
void init ()
 initialize values More...
 
 QCriterion (std::string qtname)
 
float runTest (const MonitorElement *me, QReport &qr, DQMNet::QValue &qv)
 
void setErrorProb (float prob)
 
void setWarningProb (float prob)
 set probability limit for warning and error (default: 90% and 50%) More...
 
virtual ~QCriterion ()=default
 

Static Public Member Functions

static std::string getAlgoName ()
 

Protected Member Functions

void setMessage () override
 set status & message after test has run More...
 
- Protected Member Functions inherited from QCriterion
void setAlgoName (std::string name)
 set algorithm name More...
 
void setVerbose (int verbose)
 probability limits for warnings, errors More...
 

Private Member Functions

void reset ()
 

Private Attributes

int _emptyBins
 
float _max
 
float _maxMed
 
float _min
 
float _minMed
 
float _statCut
 
std::vector< float > binValues
 
int nBins
 
int nBinsX
 
int nBinsY
 

Additional Inherited Members

- Public Types inherited from QCriterion
typedef dqm::legacy::MonitorElement MonitorElement
 (class should be created by DQMStore class) More...
 
- Static Public Attributes inherited from QCriterion
static const float ERROR_PROB_THRESHOLD = 0.50
 
static const float WARNING_PROB_THRESHOLD = 0.90
 default "probability" values for setting warnings & errors when running tests More...
 
- 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

Definition at line 589 of file QTest.h.

Constructor & Destructor Documentation

◆ CompareToMedian()

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

Definition at line 592 of file QTest.h.

References _emptyBins, _max, _maxMed, _min, _minMed, _statCut, getAlgoName(), nBins, reset(), and QCriterion::setAlgoName().

592  : SimpleTest(name, true) {
593  this->_min = 0.2;
594  this->_max = 3.0;
595  this->_emptyBins = 0;
596  this->_maxMed = 10;
597  this->_minMed = 0;
598  this->nBins = 0;
599  this->_statCut = 0;
600  reset();
602  };
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:96
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:124
float _statCut
Definition: QTest.h:628
int _emptyBins
Definition: QTest.h:626
static std::string getAlgoName()
Definition: QTest.h:607
float _minMed
Definition: QTest.h:627
float _maxMed
Definition: QTest.h:627
void reset()
Definition: QTest.h:637
float _max
Definition: QTest.h:625
float _min
Definition: QTest.h:625

◆ ~CompareToMedian()

CompareToMedian::~CompareToMedian ( )
overridedefault

Member Function Documentation

◆ getAlgoName()

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

Definition at line 607 of file QTest.h.

Referenced by CompareToMedian(), and QualityTester::makeQCriterion().

607 { return "CompareToMedian"; }

◆ reset()

void CompareToMedian::reset ( void  )
inlineprivate

Definition at line 637 of file QTest.h.

References binValues.

Referenced by CompareToMedian().

637 { binValues.clear(); };
std::vector< float > binValues
Definition: QTest.h:635

◆ runTest()

float CompareToMedian::runTest ( const MonitorElement me)
overridevirtual

Reimplemented from QCriterion.

Definition at line 1177 of file QTest.cc.

References newFWLiteAna::bin, officialStyle::chan, submitPVResolutionJobs::content, gather_cfg::cout, runEdmFileComparison::failed, ALCARECOEcalPhiSym_cff::float, h, createfilelist::int, hlt_dqm_clientPB-live_cfg::me, median(), LaserClient_cfi::nbins, reset(), and MonitorElementData::TPROFILE2D.

1177  {
1178  int32_t nbins = 0, failed = 0;
1179  badChannels_.clear();
1180 
1181  if (!me)
1182  return -1;
1183  if (!me->getRootObject())
1184  return -1;
1185  TH1* h = nullptr;
1186 
1187  if (verbose_ > 1) {
1188  std::cout << "QTest:" << getAlgoName() << "::runTest called on " << me->getFullname() << "\n";
1189  std::cout << "\tMin = " << _min << "; Max = " << _max << "\n";
1190  std::cout << "\tMinMedian = " << _minMed << "; MaxMedian = " << _maxMed << "\n";
1191  std::cout << "\tUseEmptyBins = " << (_emptyBins ? "Yes" : "No") << "\n";
1192  }
1193 
1194  if (me->kind() == MonitorElement::Kind::TPROFILE2D) {
1195  h = me->getTProfile2D(); // access Test histo
1196  } else {
1197  if (verbose_ > 0)
1198  std::cout << "QTest:ContentsWithinExpected"
1199  << " ME does not contain TPROFILE2D, exiting\n";
1200  return -1;
1201  }
1202 
1203  nBinsX = h->GetNbinsX();
1204  nBinsY = h->GetNbinsY();
1205  int entries = 0;
1206  float median = 0.0;
1207 
1208  //Median calculated with partially sorted vector
1209  for (int binX = 1; binX <= nBinsX; binX++) {
1210  reset();
1211  // Fill vector
1212  for (int binY = 1; binY <= nBinsY; binY++) {
1213  int bin = h->GetBin(binX, binY);
1214  auto content = (double)h->GetBinContent(bin);
1215  if (content == 0 && !_emptyBins)
1216  continue;
1217  binValues.push_back(content);
1218  entries = me->getTProfile2D()->GetBinEntries(bin);
1219  }
1220  if (binValues.empty())
1221  continue;
1222  nbins += binValues.size();
1223 
1224  //calculate median
1225  if (!binValues.empty()) {
1226  int medPos = (int)binValues.size() / 2;
1227  nth_element(binValues.begin(), binValues.begin() + medPos, binValues.end());
1228  median = *(binValues.begin() + medPos);
1229  }
1230 
1231  // if median == 0, use the absolute cut
1232  if (median == 0) {
1233  if (verbose_ > 0) {
1234  std::cout << "QTest: Median is 0; the fixed cuts: [" << _minMed << "; " << _maxMed << "] are used\n";
1235  }
1236  for (int binY = 1; binY <= nBinsY; binY++) {
1237  int bin = h->GetBin(binX, binY);
1238  auto content = (double)h->GetBinContent(bin);
1239  entries = me->getTProfile2D()->GetBinEntries(bin);
1240  if (entries == 0)
1241  continue;
1242  if (content > _maxMed || content < _minMed) {
1243  DQMChannel chan(binX, binY, 0, content, h->GetBinError(bin));
1244  badChannels_.push_back(chan);
1245  failed++;
1246  }
1247  }
1248  continue;
1249  }
1250 
1251  //Cut on stat: will mask rings with no enought of statistics
1252  if (median * entries < _statCut)
1253  continue;
1254 
1255  // If median is off the absolute cuts, declare everything bad (if bin has non zero entries)
1256  if (median > _maxMed || median < _minMed) {
1257  for (int binY = 1; binY <= nBinsY; binY++) {
1258  int bin = h->GetBin(binX, binY);
1259  auto content = (double)h->GetBinContent(bin);
1260  entries = me->getTProfile2D()->GetBinEntries(bin);
1261  if (entries == 0)
1262  continue;
1263  DQMChannel chan(binX, binY, 0, content / median, h->GetBinError(bin));
1264  badChannels_.push_back(chan);
1265  failed++;
1266  }
1267  continue;
1268  }
1269 
1270  // Test itself
1271  float minCut = median * _min;
1272  float maxCut = median * _max;
1273  for (int binY = 1; binY <= nBinsY; binY++) {
1274  int bin = h->GetBin(binX, binY);
1275  auto content = (double)h->GetBinContent(bin);
1276  entries = me->getTProfile2D()->GetBinEntries(bin);
1277  if (entries == 0)
1278  continue;
1279  if (content > maxCut || content < minCut) {
1280  DQMChannel chan(binX, binY, 0, content / median, h->GetBinError(bin));
1281  badChannels_.push_back(chan);
1282  failed++;
1283  }
1284  }
1285  }
1286 
1287  if (nbins == 0) {
1288  if (verbose_ > 0)
1289  std::cout << "QTest:CompareToMedian: Histogram is empty" << std::endl;
1290  return 1.;
1291  }
1292  return 1 - (float)failed / nbins;
1293 }
int verbose_
Definition: QTest.h:110
float _statCut
Definition: QTest.h:628
int _emptyBins
Definition: QTest.h:626
static std::string getAlgoName()
Definition: QTest.h:607
float _minMed
Definition: QTest.h:627
float _maxMed
Definition: QTest.h:627
void reset()
Definition: QTest.h:637
std::vector< float > binValues
Definition: QTest.h:635
std::vector< DQMChannel > badChannels_
Definition: QTest.h:139
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
T median(std::vector< T > values)
Definition: median.h:16
float _max
Definition: QTest.h:625
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
float _min
Definition: QTest.h:625

◆ setEmptyBins()

void CompareToMedian::setEmptyBins ( int  eB)
inline

Definition at line 612 of file QTest.h.

References _emptyBins.

612 { eB > 0 ? _emptyBins = 1 : _emptyBins = 0; };
int _emptyBins
Definition: QTest.h:626

◆ setMax()

void CompareToMedian::setMax ( float  max)
inline

Definition at line 611 of file QTest.h.

References _max, and WZElectronSkims53X_cff::max.

◆ setMaxMedian()

void CompareToMedian::setMaxMedian ( float  max)
inline

Definition at line 613 of file QTest.h.

References _maxMed, and WZElectronSkims53X_cff::max.

◆ setMessage()

void CompareToMedian::setMessage ( )
inlineoverrideprotectedvirtual

set status & message after test has run

Reimplemented from SimpleTest.

Definition at line 618 of file QTest.h.

References QCriterion::algoName_, QCriterion::message_, QCriterion::prob_, and QCriterion::qtname_.

618  {
619  std::ostringstream message;
620  message << "Test " << qtname_ << " (" << algoName_ << "): Entry fraction within range = " << prob_;
621  message_ = message.str();
622  }
std::string algoName_
name of quality test
Definition: QTest.h:104
std::string qtname_
Definition: QTest.h:103
float prob_
name of algorithm
Definition: QTest.h:105
std::string message_
quality test status
Definition: QTest.h:107

◆ setMin()

void CompareToMedian::setMin ( float  min)
inline

Definition at line 610 of file QTest.h.

References _min, and SiStripPI::min.

◆ setMinMedian()

void CompareToMedian::setMinMedian ( float  min)
inline

Definition at line 614 of file QTest.h.

References _minMed, and SiStripPI::min.

◆ setStatCut()

void CompareToMedian::setStatCut ( float  cut)
inline

Definition at line 615 of file QTest.h.

References _statCut, and DMR_cfg::cut.

615 { _statCut = (cut > 0) ? cut : 0; };
float _statCut
Definition: QTest.h:628

Member Data Documentation

◆ _emptyBins

int CompareToMedian::_emptyBins
private

Definition at line 626 of file QTest.h.

Referenced by CompareToMedian(), and setEmptyBins().

◆ _max

float CompareToMedian::_max
private

Definition at line 625 of file QTest.h.

Referenced by CompareToMedian(), generateEDF.LumiInfoCont::max(), and setMax().

◆ _maxMed

float CompareToMedian::_maxMed
private

Definition at line 627 of file QTest.h.

Referenced by CompareToMedian(), and setMaxMedian().

◆ _min

float CompareToMedian::_min
private

Definition at line 625 of file QTest.h.

Referenced by CompareToMedian(), generateEDF.LumiInfoCont::min(), and setMin().

◆ _minMed

float CompareToMedian::_minMed
private

Definition at line 627 of file QTest.h.

Referenced by CompareToMedian(), and setMinMedian().

◆ _statCut

float CompareToMedian::_statCut
private

Definition at line 628 of file QTest.h.

Referenced by CompareToMedian(), and setStatCut().

◆ binValues

std::vector<float> CompareToMedian::binValues
private

Definition at line 635 of file QTest.h.

Referenced by reset().

◆ nBins

int CompareToMedian::nBins
private

Definition at line 632 of file QTest.h.

Referenced by CompareToMedian().

◆ nBinsX

int CompareToMedian::nBinsX
private

Definition at line 630 of file QTest.h.

◆ nBinsY

int CompareToMedian::nBinsY
private

Definition at line 630 of file QTest.h.