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

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

- Public Types inherited from QCriterion
typedef dqm::legacy::MonitorElement MonitorElement
 (class should be created by DQMStore class) 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 623 of file QTest.h.

Constructor & Destructor Documentation

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

Definition at line 626 of file QTest.h.

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

626  : SimpleTest(name, true) {
627  this->_min = 0.2;
628  this->_max = 3.0;
629  this->_emptyBins = 0;
630  this->_maxMed = 10;
631  this->_minMed = 0;
632  this->nBins = 0;
633  this->_statCut = 0;
634  reset();
636  };
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:95
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:158
float _statCut
Definition: QTest.h:662
int _emptyBins
Definition: QTest.h:660
static std::string getAlgoName()
Definition: QTest.h:641
float _minMed
Definition: QTest.h:661
float _maxMed
Definition: QTest.h:661
void reset()
Definition: QTest.h:671
float _max
Definition: QTest.h:659
float _min
Definition: QTest.h:659
CompareToMedian::~CompareToMedian ( )
overridedefault

Member Function Documentation

static std::string CompareToMedian::getAlgoName ( )
inlinestatic
void CompareToMedian::reset ( void  )
inlineprivate

Definition at line 671 of file QTest.h.

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

Reimplemented from QCriterion.

Definition at line 1181 of file QTest.cc.

References newFWLiteAna::bin, officialStyle::chan, Skims_PA_cff::content, gather_cfg::cout, runEdmFileComparison::failed, dqmMemoryStats::float, dqm::impl::MonitorElement::getFullname(), dqm::legacy::MonitorElement::getRootObject(), dqm::legacy::MonitorElement::getTProfile2D(), h, createfilelist::int, dqm::impl::MonitorElement::kind(), pfDeepBoostedJetPreprocessParams_cfi::median, LaserClient_cfi::nbins, reset(), and MonitorElementData::TPROFILE2D.

1181  {
1182  int32_t nbins = 0, failed = 0;
1183  badChannels_.clear();
1184 
1185  if (!me)
1186  return -1;
1187  if (!me->getRootObject())
1188  return -1;
1189  TH1* h = nullptr;
1190 
1191  if (verbose_ > 1) {
1192  std::cout << "QTest:" << getAlgoName() << "::runTest called on " << me->getFullname() << "\n";
1193  std::cout << "\tMin = " << _min << "; Max = " << _max << "\n";
1194  std::cout << "\tMinMedian = " << _minMed << "; MaxMedian = " << _maxMed << "\n";
1195  std::cout << "\tUseEmptyBins = " << (_emptyBins ? "Yes" : "No") << "\n";
1196  }
1197 
1198  if (me->kind() == MonitorElement::Kind::TPROFILE2D) {
1199  h = me->getTProfile2D(); // access Test histo
1200  } else {
1201  if (verbose_ > 0)
1202  std::cout << "QTest:ContentsWithinExpected"
1203  << " ME does not contain TPROFILE2D, exiting\n";
1204  return -1;
1205  }
1206 
1207  nBinsX = h->GetNbinsX();
1208  nBinsY = h->GetNbinsY();
1209  int entries = 0;
1210  float median = 0.0;
1211 
1212  //Median calculated with partially sorted vector
1213  for (int binX = 1; binX <= nBinsX; binX++) {
1214  reset();
1215  // Fill vector
1216  for (int binY = 1; binY <= nBinsY; binY++) {
1217  int bin = h->GetBin(binX, binY);
1218  auto content = (double)h->GetBinContent(bin);
1219  if (content == 0 && !_emptyBins)
1220  continue;
1221  binValues.push_back(content);
1222  entries = me->getTProfile2D()->GetBinEntries(bin);
1223  }
1224  if (binValues.empty())
1225  continue;
1226  nbins += binValues.size();
1227 
1228  //calculate median
1229  if (!binValues.empty()) {
1230  int medPos = (int)binValues.size() / 2;
1231  nth_element(binValues.begin(), binValues.begin() + medPos, binValues.end());
1232  median = *(binValues.begin() + medPos);
1233  }
1234 
1235  // if median == 0, use the absolute cut
1236  if (median == 0) {
1237  if (verbose_ > 0) {
1238  std::cout << "QTest: Median is 0; the fixed cuts: [" << _minMed << "; " << _maxMed << "] are used\n";
1239  }
1240  for (int binY = 1; binY <= nBinsY; binY++) {
1241  int bin = h->GetBin(binX, binY);
1242  auto content = (double)h->GetBinContent(bin);
1243  entries = me->getTProfile2D()->GetBinEntries(bin);
1244  if (entries == 0)
1245  continue;
1246  if (content > _maxMed || content < _minMed) {
1247  DQMChannel chan(binX, binY, 0, content, h->GetBinError(bin));
1248  badChannels_.push_back(chan);
1249  failed++;
1250  }
1251  }
1252  continue;
1253  }
1254 
1255  //Cut on stat: will mask rings with no enought of statistics
1256  if (median * entries < _statCut)
1257  continue;
1258 
1259  // If median is off the absolute cuts, declare everything bad (if bin has non zero entries)
1260  if (median > _maxMed || median < _minMed) {
1261  for (int binY = 1; binY <= nBinsY; binY++) {
1262  int bin = h->GetBin(binX, binY);
1263  auto content = (double)h->GetBinContent(bin);
1264  entries = me->getTProfile2D()->GetBinEntries(bin);
1265  if (entries == 0)
1266  continue;
1267  DQMChannel chan(binX, binY, 0, content / median, h->GetBinError(bin));
1268  badChannels_.push_back(chan);
1269  failed++;
1270  }
1271  continue;
1272  }
1273 
1274  // Test itself
1275  float minCut = median * _min;
1276  float maxCut = median * _max;
1277  for (int binY = 1; binY <= nBinsY; binY++) {
1278  int bin = h->GetBin(binX, binY);
1279  auto content = (double)h->GetBinContent(bin);
1280  entries = me->getTProfile2D()->GetBinEntries(bin);
1281  if (entries == 0)
1282  continue;
1283  if (content > maxCut || content < minCut) {
1284  DQMChannel chan(binX, binY, 0, content / median, h->GetBinError(bin));
1285  badChannels_.push_back(chan);
1286  failed++;
1287  }
1288  }
1289  }
1290 
1291  if (nbins == 0) {
1292  if (verbose_ > 0)
1293  std::cout << "QTest:CompareToMedian: Histogram is empty" << std::endl;
1294  return 1.;
1295  }
1296  return 1 - (float)failed / nbins;
1297 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
int verbose_
Definition: QTest.h:138
float _statCut
Definition: QTest.h:662
Kind kind() const
Get the type of the monitor element.
int _emptyBins
Definition: QTest.h:660
const std::string getFullname() const
get full name of ME including Pathname
static std::string getAlgoName()
Definition: QTest.h:641
float _minMed
Definition: QTest.h:661
float _maxMed
Definition: QTest.h:661
virtual TProfile2D * getTProfile2D() const
void reset()
Definition: QTest.h:671
std::vector< float > binValues
Definition: QTest.h:669
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 _max
Definition: QTest.h:659
TObject * getRootObject() const override
float _min
Definition: QTest.h:659
void CompareToMedian::setEmptyBins ( int  eB)
inline

Definition at line 646 of file QTest.h.

Referenced by QTestConfigure::EnableCompareToMedianTest().

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

Definition at line 645 of file QTest.h.

References SiStripPI::max.

Referenced by QTestConfigure::EnableCompareToMedianTest().

void CompareToMedian::setMaxMedian ( float  max)
inline

Definition at line 647 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 652 of file QTest.h.

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

652  {
653  std::ostringstream message;
654  message << "Test " << qtname_ << " (" << algoName_ << "): Entry fraction within range = " << prob_;
655  message_ = message.str();
656  }
std::string algoName_
name of quality test
Definition: QTest.h:132
std::string qtname_
Definition: QTest.h:131
float prob_
name of algorithm
Definition: QTest.h:133
std::string message_
quality test status
Definition: QTest.h:135
void CompareToMedian::setMin ( float  min)
inline

Definition at line 644 of file QTest.h.

References min().

Referenced by QTestConfigure::EnableCompareToMedianTest().

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

Definition at line 648 of file QTest.h.

References min().

Referenced by QTestConfigure::EnableCompareToMedianTest().

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

Definition at line 649 of file QTest.h.

Referenced by QTestConfigure::EnableCompareToMedianTest().

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

Member Data Documentation

int CompareToMedian::_emptyBins
private

Definition at line 660 of file QTest.h.

float CompareToMedian::_max
private

Definition at line 659 of file QTest.h.

Referenced by generateEDF.LumiInfoCont::max().

float CompareToMedian::_maxMed
private

Definition at line 661 of file QTest.h.

float CompareToMedian::_min
private

Definition at line 659 of file QTest.h.

Referenced by generateEDF.LumiInfoCont::min().

float CompareToMedian::_minMed
private

Definition at line 661 of file QTest.h.

float CompareToMedian::_statCut
private

Definition at line 662 of file QTest.h.

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

Definition at line 669 of file QTest.h.

int CompareToMedian::nBins
private

Definition at line 666 of file QTest.h.

int CompareToMedian::nBinsX
private

Definition at line 664 of file QTest.h.

int CompareToMedian::nBinsY
private

Definition at line 664 of file QTest.h.