CMS 3D CMS Logo

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

List of all members.

Public Member Functions

 CompareToMedian (const std::string &name)
float runTest (const MonitorElement *me)
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 ()

Static Public Member Functions

static std::string getAlgoName (void)

Protected Member Functions

void setMessage (void)
 set status & message after test has run

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

Detailed Description

Definition at line 593 of file QTest.h.


Constructor & Destructor Documentation

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

Definition at line 597 of file QTest.h.

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

                                         : SimpleTest(name,true){
    this->_min = 0.2;
    this->_max = 3.0;
    this->_emptyBins = 0;
    this->_maxMed = 10;
    this->_minMed = 0;
    this->nBins = 0;
    this->_statCut = 0;
    reset();
    setAlgoName( getAlgoName() );
  };
CompareToMedian::~CompareToMedian ( ) [inline]

Definition at line 609 of file QTest.h.

{};

Member Function Documentation

static std::string CompareToMedian::getAlgoName ( void  ) [inline, static]
void CompareToMedian::reset ( void  ) [inline, private]

Definition at line 642 of file QTest.h.

References binValues.

Referenced by CompareToMedian().

{binValues.clear();};
float CompareToMedian::runTest ( const MonitorElement me) [virtual]

Reimplemented from QCriterion.

Definition at line 1264 of file QTest.cc.

References newFWLiteAna::bin, ws_sso_content_reader::content, gather_cfg::cout, MonitorElement::DQM_KIND_TPROFILE2D, python::tagInventory::entries, MonitorElement::getRootObject(), MonitorElement::getTProfile2D(), h, MonitorElement::kind(), pileupCalc::nbins, and reset().

                                                      {
  int32_t nbins=0, failed=0;
  badChannels_.clear();

  if (!me)
    return -1;
  if (!me->getRootObject())
    return -1;
  TH1* h=0;

  if (verbose_>1){
    std::cout << "QTest:" << getAlgoName() << "::runTest called on "
              << me-> getFullname() << "\n";
    std::cout << "\tMin = " << _min << "; Max = " << _max << "\n";
    std::cout << "\tMinMedian = " << _minMed << "; MaxMedian = " << _maxMed << "\n";
    std::cout << "\tUseEmptyBins = " << (_emptyBins?"Yes":"No" )<< "\n";
  }

  if (me->kind()==MonitorElement::DQM_KIND_TPROFILE2D)
    {
      h  = me->getTProfile2D(); // access Test histo
    }
  else
    {
      if (verbose_>0) 
        std::cout << "QTest:ContentsWithinExpected" 
         << " ME does not contain TPROFILE2D, exiting\n"; 
      return -1;
    }
  
  nBinsX = h->GetNbinsX();
  nBinsY = h->GetNbinsY();
  int entries = 0;
  float median = 0.0;

  //Median calculated with partially sorted vector
  for (int binX = 1; binX <= nBinsX; binX++ ){
    reset();
    // Fill vector
    for (int binY = 1; binY <= nBinsY; binY++){
      int bin = h->GetBin(binX, binY);
      double content = (double)h->GetBinContent(bin);
      if ( content == 0 && !_emptyBins)
        continue;
      binValues.push_back(content);
      entries = me->getTProfile2D()->GetBinEntries(bin);
    }
    if (binValues.empty())
      continue;
    nbins+=binValues.size();

    //calculate median
    if(binValues.size()>0){
      int medPos = (int)binValues.size()/2;
      nth_element(binValues.begin(),binValues.begin()+medPos,binValues.end());
      median = *(binValues.begin()+medPos);
    }

    // if median == 0, use the absolute cut
    if(median == 0){
      if (verbose_ > 0){
        std::cout << "QTest: Median is 0; the fixed cuts: [" << _minMed << "; " << _maxMed << "]  are used\n";
      }
      for(int  binY = 1; binY <= nBinsY; binY++){
        int bin = h->GetBin(binX, binY);
        double content = (double)h->GetBinContent(bin);
        entries = me->getTProfile2D()->GetBinEntries(bin);
        if ( entries == 0 )
          continue;
        if (content > _maxMed || content < _minMed){ 
            DQMChannel chan(binX,binY, 0, content, h->GetBinError(bin));
            badChannels_.push_back(chan);
            failed++;
        }
      }
      continue;
    }

    //Cut on stat: will mask rings with no enought of statistics
    if (median*entries < _statCut )
      continue;
     
    // If median is off the absolute cuts, declare everything bad (if bin has non zero entries)
    if(median > _maxMed || median < _minMed){
      for(int  binY = 1; binY <= nBinsY; binY++){
        int bin = h->GetBin(binX, binY);
        double content = (double)h->GetBinContent(bin);
        entries = me->getTProfile2D()->GetBinEntries(bin);
         if ( entries == 0 )
          continue;
         DQMChannel chan(binX,binY, 0, content/median, h->GetBinError(bin));
         badChannels_.push_back(chan);
         failed++;
      }
      continue;
    }

    // Test itself  
    float minCut = median*_min;
    float maxCut = median*_max;
    for(int  binY = 1; binY <= nBinsY; binY++){
        int bin = h->GetBin(binX, binY);
        double content = (double)h->GetBinContent(bin);
        entries = me->getTProfile2D()->GetBinEntries(bin);
        if ( entries == 0 )
          continue;
        if (content > maxCut || content < minCut){
          DQMChannel chan(binX,binY, 0, content/median, h->GetBinError(bin));
          badChannels_.push_back(chan);
          failed++;
        }
    }
  }

  if (nbins==0){
    if (verbose_ > 0)
      std::cout << "QTest:CompareToMedian: Histogram is empty" << std::endl;
    return 1.;
    }
  return 1 - (float)failed/nbins;
}
void CompareToMedian::setEmptyBins ( int  eB) [inline]

Definition at line 616 of file QTest.h.

References _emptyBins.

Referenced by QTestConfigure::EnableCompareToMedianTest().

{eB > 0 ? _emptyBins = 1 : _emptyBins = 0;};
void CompareToMedian::setMax ( float  max) [inline]

Definition at line 615 of file QTest.h.

References _max, and max().

Referenced by QTestConfigure::EnableCompareToMedianTest().

{_max = max;};
void CompareToMedian::setMaxMedian ( float  max) [inline]

Definition at line 617 of file QTest.h.

References _maxMed, and max().

Referenced by QTestConfigure::EnableCompareToMedianTest().

{_maxMed = max;};
void CompareToMedian::setMessage ( void  ) [inline, protected, virtual]

set status & message after test has run

Reimplemented from SimpleTest.

Definition at line 622 of file QTest.h.

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

                       {
    std::ostringstream message;
    message << "Test " << qtname_ << " (" << algoName_
            << "): Entry fraction within range = " << prob_;
    message_ = message.str();
  }
void CompareToMedian::setMin ( float  min) [inline]

Definition at line 614 of file QTest.h.

References _min, and min.

Referenced by QTestConfigure::EnableCompareToMedianTest().

{_min = min;};
void CompareToMedian::setMinMedian ( float  min) [inline]

Definition at line 618 of file QTest.h.

References _minMed, and min.

Referenced by QTestConfigure::EnableCompareToMedianTest().

{_minMed = min;};
void CompareToMedian::setStatCut ( float  cut) [inline]

Definition at line 619 of file QTest.h.

References _statCut.

Referenced by QTestConfigure::EnableCompareToMedianTest().

{_statCut = (cut > 0) ? cut : 0;};

Member Data Documentation

Definition at line 631 of file QTest.h.

Referenced by CompareToMedian(), and setEmptyBins().

float CompareToMedian::_max [private]

Definition at line 630 of file QTest.h.

Referenced by CompareToMedian(), and setMax().

float CompareToMedian::_maxMed [private]

Definition at line 632 of file QTest.h.

Referenced by CompareToMedian(), and setMaxMedian().

float CompareToMedian::_min [private]

Definition at line 630 of file QTest.h.

Referenced by CompareToMedian(), and setMin().

float CompareToMedian::_minMed [private]

Definition at line 632 of file QTest.h.

Referenced by CompareToMedian(), and setMinMedian().

float CompareToMedian::_statCut [private]

Definition at line 633 of file QTest.h.

Referenced by CompareToMedian(), and setStatCut().

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

Definition at line 640 of file QTest.h.

Referenced by reset().

int CompareToMedian::nBins [private]

Definition at line 637 of file QTest.h.

Referenced by CompareToMedian().

int CompareToMedian::nBinsX [private]

Definition at line 635 of file QTest.h.

int CompareToMedian::nBinsY [private]

Definition at line 635 of file QTest.h.