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
 (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

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
 

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

- 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 624 of file QTest.h.

Constructor & Destructor Documentation

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

Definition at line 628 of file QTest.h.

References reset(), and QCriterion::setAlgoName().

628  : SimpleTest(name,true){
629  this->_min = 0.2;
630  this->_max = 3.0;
631  this->_emptyBins = 0;
632  this->_maxMed = 10;
633  this->_minMed = 0;
634  this->nBins = 0;
635  this->_statCut = 0;
636  reset();
638  };
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:79
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:139
float _statCut
Definition: QTest.h:664
int _emptyBins
Definition: QTest.h:662
static std::string getAlgoName()
Definition: QTest.h:642
float _minMed
Definition: QTest.h:663
float _maxMed
Definition: QTest.h:663
void reset()
Definition: QTest.h:673
float _max
Definition: QTest.h:661
float _min
Definition: QTest.h:661
CompareToMedian::~CompareToMedian ( )
overridedefault

Member Function Documentation

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

Definition at line 642 of file QTest.h.

References QCriterion::runTest().

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

642 { return "CompareToMedian"; }
void CompareToMedian::reset ( void  )
inlineprivate

Definition at line 673 of file QTest.h.

673 {binValues.clear();};
std::vector< float > binValues
Definition: QTest.h:671
float CompareToMedian::runTest ( const MonitorElement me)
overridevirtual

Reimplemented from QCriterion.

Definition at line 1375 of file QTest.cc.

References stringResolutionProvider_cfi::bin, officialStyle::chan, ws_sso_content_reader::content, gather_cfg::cout, MonitorElement::DQM_KIND_TPROFILE2D, runEdmFileComparison::failed, objects.autophobj::float, MonitorElement::getRootObject(), MonitorElement::getTProfile2D(), createfilelist::int, MonitorElement::kind(), pileupCalc::nbins, and reset().

1375  {
1376  int32_t nbins=0, failed=0;
1377  badChannels_.clear();
1378 
1379  if (!me)
1380  return -1;
1381  if (!me->getRootObject())
1382  return -1;
1383  TH1* h=nullptr;
1384 
1385  if (verbose_>1){
1386  std::cout << "QTest:" << getAlgoName() << "::runTest called on "
1387  << me-> getFullname() << "\n";
1388  std::cout << "\tMin = " << _min << "; Max = " << _max << "\n";
1389  std::cout << "\tMinMedian = " << _minMed << "; MaxMedian = " << _maxMed << "\n";
1390  std::cout << "\tUseEmptyBins = " << (_emptyBins?"Yes":"No" )<< "\n";
1391  }
1392 
1394  {
1395  h = me->getTProfile2D(); // access Test histo
1396  }
1397  else
1398  {
1399  if (verbose_>0)
1400  std::cout << "QTest:ContentsWithinExpected"
1401  << " ME does not contain TPROFILE2D, exiting\n";
1402  return -1;
1403  }
1404 
1405  nBinsX = h->GetNbinsX();
1406  nBinsY = h->GetNbinsY();
1407  int entries = 0;
1408  float median = 0.0;
1409 
1410  //Median calculated with partially sorted vector
1411  for (int binX = 1; binX <= nBinsX; binX++ ){
1412  reset();
1413  // Fill vector
1414  for (int binY = 1; binY <= nBinsY; binY++){
1415  int bin = h->GetBin(binX, binY);
1416  auto content = (double)h->GetBinContent(bin);
1417  if ( content == 0 && !_emptyBins)
1418  continue;
1419  binValues.push_back(content);
1420  entries = me->getTProfile2D()->GetBinEntries(bin);
1421  }
1422  if (binValues.empty())
1423  continue;
1424  nbins+=binValues.size();
1425 
1426  //calculate median
1427  if(!binValues.empty()){
1428  int medPos = (int)binValues.size()/2;
1429  nth_element(binValues.begin(),binValues.begin()+medPos,binValues.end());
1430  median = *(binValues.begin()+medPos);
1431  }
1432 
1433  // if median == 0, use the absolute cut
1434  if(median == 0){
1435  if (verbose_ > 0){
1436  std::cout << "QTest: Median is 0; the fixed cuts: [" << _minMed << "; " << _maxMed << "] are used\n";
1437  }
1438  for(int binY = 1; binY <= nBinsY; binY++){
1439  int bin = h->GetBin(binX, binY);
1440  auto content = (double)h->GetBinContent(bin);
1441  entries = me->getTProfile2D()->GetBinEntries(bin);
1442  if ( entries == 0 )
1443  continue;
1444  if (content > _maxMed || content < _minMed){
1445  DQMChannel chan(binX,binY, 0, content, h->GetBinError(bin));
1446  badChannels_.push_back(chan);
1447  failed++;
1448  }
1449  }
1450  continue;
1451  }
1452 
1453  //Cut on stat: will mask rings with no enought of statistics
1454  if (median*entries < _statCut )
1455  continue;
1456 
1457  // If median is off the absolute cuts, declare everything bad (if bin has non zero entries)
1458  if(median > _maxMed || median < _minMed){
1459  for(int binY = 1; binY <= nBinsY; binY++){
1460  int bin = h->GetBin(binX, binY);
1461  auto content = (double)h->GetBinContent(bin);
1462  entries = me->getTProfile2D()->GetBinEntries(bin);
1463  if ( entries == 0 )
1464  continue;
1465  DQMChannel chan(binX,binY, 0, content/median, h->GetBinError(bin));
1466  badChannels_.push_back(chan);
1467  failed++;
1468  }
1469  continue;
1470  }
1471 
1472  // Test itself
1473  float minCut = median*_min;
1474  float maxCut = median*_max;
1475  for(int binY = 1; binY <= nBinsY; binY++){
1476  int bin = h->GetBin(binX, binY);
1477  auto content = (double)h->GetBinContent(bin);
1478  entries = me->getTProfile2D()->GetBinEntries(bin);
1479  if ( entries == 0 )
1480  continue;
1481  if (content > maxCut || content < minCut){
1482  DQMChannel chan(binX,binY, 0, content/median, h->GetBinError(bin));
1483  badChannels_.push_back(chan);
1484  failed++;
1485  }
1486  }
1487  }
1488 
1489  if (nbins==0){
1490  if (verbose_ > 0)
1491  std::cout << "QTest:CompareToMedian: Histogram is empty" << std::endl;
1492  return 1.;
1493  }
1494  return 1 - (float)failed/nbins;
1495 }
TProfile2D * getTProfile2D() const
int verbose_
Definition: QTest.h:119
float _statCut
Definition: QTest.h:664
TObject * getRootObject() const
int _emptyBins
Definition: QTest.h:662
static std::string getAlgoName()
Definition: QTest.h:642
float _minMed
Definition: QTest.h:663
float _maxMed
Definition: QTest.h:663
void reset()
Definition: QTest.h:673
bin
set the eta bin as selection string.
std::vector< float > binValues
Definition: QTest.h:671
std::vector< DQMChannel > badChannels_
Definition: QTest.h:161
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
float _max
Definition: QTest.h:661
Kind kind() const
Get the type of the monitor element.
float _min
Definition: QTest.h:661
void CompareToMedian::setEmptyBins ( int  eB)
inline

Definition at line 647 of file QTest.h.

Referenced by QTestConfigure::EnableCompareToMedianTest().

647 {eB > 0 ? _emptyBins = 1 : _emptyBins = 0;};
int _emptyBins
Definition: QTest.h:662
void CompareToMedian::setMax ( float  max)
inline

Definition at line 646 of file QTest.h.

References SiStripPI::max.

Referenced by QTestConfigure::EnableCompareToMedianTest().

void CompareToMedian::setMaxMedian ( float  max)
inline

Definition at line 648 of file QTest.h.

References SiStripPI::max.

Referenced by QTestConfigure::EnableCompareToMedianTest().

void CompareToMedian::setMessage ( )
inlineoverrideprotectedvirtual

set status & message after test has run

Reimplemented from SimpleTest.

Definition at line 653 of file QTest.h.

References QCriterion::algoName_, python.rootplot.argparse::message, QCriterion::message_, QCriterion::prob_, and QCriterion::qtname_.

653  {
654  std::ostringstream message;
655  message << "Test " << qtname_ << " (" << algoName_
656  << "): Entry fraction within range = " << prob_;
657  message_ = message.str();
658  }
std::string algoName_
name of quality test
Definition: QTest.h:113
std::string qtname_
Definition: QTest.h:112
float prob_
name of algorithm
Definition: QTest.h:114
std::string message_
quality test status
Definition: QTest.h:116
void CompareToMedian::setMin ( float  min)
inline

Definition at line 645 of file QTest.h.

References min().

Referenced by QTestConfigure::EnableCompareToMedianTest().

645 {_min = min;};
T min(T a, T b)
Definition: MathUtil.h:58
float _min
Definition: QTest.h:661
void CompareToMedian::setMinMedian ( float  min)
inline

Definition at line 649 of file QTest.h.

References min().

Referenced by QTestConfigure::EnableCompareToMedianTest().

649 {_minMed = min;};
float _minMed
Definition: QTest.h:663
T min(T a, T b)
Definition: MathUtil.h:58
void CompareToMedian::setStatCut ( float  cut)
inline

Definition at line 650 of file QTest.h.

Referenced by QTestConfigure::EnableCompareToMedianTest().

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

Member Data Documentation

int CompareToMedian::_emptyBins
private

Definition at line 662 of file QTest.h.

float CompareToMedian::_max
private

Definition at line 661 of file QTest.h.

Referenced by generateEDF.LumiInfoCont::max().

float CompareToMedian::_maxMed
private

Definition at line 663 of file QTest.h.

float CompareToMedian::_min
private

Definition at line 661 of file QTest.h.

Referenced by generateEDF.LumiInfoCont::min().

float CompareToMedian::_minMed
private

Definition at line 663 of file QTest.h.

float CompareToMedian::_statCut
private

Definition at line 664 of file QTest.h.

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

Definition at line 671 of file QTest.h.

int CompareToMedian::nBins
private

Definition at line 668 of file QTest.h.

int CompareToMedian::nBinsX
private

Definition at line 666 of file QTest.h.

int CompareToMedian::nBinsY
private

Definition at line 666 of file QTest.h.