CMS 3D CMS Logo

ContentsWithinExpected Class Reference

#include <DQMServices/Core/interface/QTest.h>

Inheritance diagram for ContentsWithinExpected:

SimpleTest QCriterion

List of all members.

Public Member Functions

 ContentsWithinExpected (const std::string &name)
float runTest (const MonitorElement *me)
void setMeanRange (float xmin, float xmax)
 set expected value for mean
void setMeanTolerance (float fracTolerance)
 set (fractional) tolerance for mean
void setRMSRange (float xmin, float xmax)
 set expected value for mean
void setUseEmptyBins (unsigned int useEmptyBins)

Static Public Member Functions

static std::string getAlgoName (void)

Protected Member Functions

void checkRange (const float xmin, const float xmax)
 check that allowed range is logical
void setMessage (void)
 set status & message after test has run

Protected Attributes

bool checkMean_
bool checkMeanTolerance_
bool checkRMS_
TH1 * h
float maxMean_
float maxRMS_
float minMean_
float minRMS_
float toleranceMean_
unsigned int useEmptyBins_
bool validMethod_


Detailed Description

Definition at line 463 of file QTest.h.


Constructor & Destructor Documentation

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

Definition at line 466 of file QTest.h.

References checkMean_, checkMeanTolerance_, checkRMS_, getAlgoName(), maxMean_, maxRMS_, minMean_, minRMS_, QCriterion::setAlgoName(), toleranceMean_, and validMethod_.

00466                                                 : SimpleTest(name,true)
00467     {
00468       checkMean_ = checkRMS_ = validMethod_ = false;
00469       minMean_ = maxMean_ = minRMS_ = maxRMS_ = 0.0;
00470       checkMeanTolerance_ = false;
00471       toleranceMean_ = -1.0;
00472       setAlgoName(getAlgoName());
00473     }


Member Function Documentation

void ContentsWithinExpected::checkRange ( const float  xmin,
const float  xmax 
) [protected]

check that allowed range is logical

Definition at line 899 of file QTest.cc.

References TestMuL1L2Filter_cff::cerr, lat::endl(), getAlgoName(), and validMethod_.

Referenced by setMeanRange(), and setRMSRange().

00900 {
00901   if (xmin < xmax)
00902     validMethod_ = true;
00903   else
00904   {
00905     std::cerr << " *** Error! Illogical range: (" << xmin << ", " << xmax
00906               << ") in algorithm " << getAlgoName() << std::endl;
00907     validMethod_ = false;
00908   }
00909 }

static std::string ContentsWithinExpected::getAlgoName ( void   )  [inline, static]

Definition at line 480 of file QTest.h.

Referenced by checkRange(), ContentsWithinExpected(), QTestConfigure::EnableContentsWithinExpectedTest(), QTestConfigure::enableTests(), and QTestParameterNames::QTestParameterNames().

00481   { return "ContentsWithinExpected"; }

float ContentsWithinExpected::runTest ( const MonitorElement me  )  [virtual]

end of normal Test

AS quality test !!!

end of AS quality test

Reimplemented from QCriterion.

Definition at line 706 of file QTest.cc.

References average(), SimpleTest::badChannels_, checkMean_, checkMeanTolerance_, checkRMS_, GenMuonPlsPt100GeV_cfg::cout, MonitorElement::DQM_KIND_TH2F, MonitorElement::DQM_KIND_TH2S, MonitorElement::DQM_KIND_TPROFILE, MonitorElement::DQM_KIND_TPROFILE2D, lat::endl(), cmsPerfPublish::fail(), MonitorElement::getRootObject(), MonitorElement::getTH2F(), MonitorElement::getTH2S(), MonitorElement::getTProfile(), MonitorElement::getTProfile2D(), h, MonitorElement::kind(), maxMean_, maxRMS_, mean(), SimpleTest::minEntries_, nsum, sum(), toleranceMean_, and useEmptyBins_.

00707 {
00708   badChannels_.clear();
00709   if (!me) return -1;
00710   if (!me->getRootObject()) return -1;
00711   h=0;//initialize histogram pointer
00712 
00713   int ncx;
00714   int ncy;
00715 
00716  if(useEmptyBins_)
00717  {
00718    //-- TH2
00719   if (me->kind()==MonitorElement::DQM_KIND_TH2F){
00720     ncx = me->getTH2F()->GetXaxis()->GetNbins();
00721     ncy = me->getTH2F()->GetYaxis()->GetNbins(); 
00722     h  = me->getTH2F(); // access Test histo
00723   }
00724  
00725    //-- TH2S
00726   else if (me->kind()==MonitorElement::DQM_KIND_TH2S){
00727     ncx = me->getTH2S()->GetXaxis()->GetNbins();
00728     ncy = me->getTH2S()->GetYaxis()->GetNbins(); 
00729     h  = me->getTH2S(); // access Test histo
00730   }
00731 
00732   //-- TProfile
00733   else if (me->kind()==MonitorElement::DQM_KIND_TPROFILE){
00734     ncx = me->getTProfile()->GetXaxis()->GetNbins();
00735     ncy = 1;
00736     h  = me->getTProfile(); // access Test histo
00737   }
00738 
00739   //-- TProfile2D
00740   else if (me->kind()==MonitorElement::DQM_KIND_TPROFILE2D){
00741     ncx = me->getTProfile2D()->GetXaxis()->GetNbins();
00742     ncy = me->getTProfile2D()->GetYaxis()->GetNbins();
00743     h  = me->getTProfile2D(); // access Test histo
00744   }
00745 
00746   else{
00747   std::cout<< " ContentsWithinExpected ERROR: ME does not contain TH2F/TH2S/TPROFILE/TPROFILE2D" << std::endl; 
00748   return -1;
00749   } 
00750  
00751    int nsum = 0;
00752    float sum = 0.0;
00753    float average = 0.0;
00754 
00755   if (checkMeanTolerance_){ // calculate average value of all bin contents
00756 
00757     for (int cx = 1; cx <= ncx; ++cx)
00758     {
00759       for (int cy = 1; cy <= ncy; ++cy)
00760       {
00761         if (me->kind() == MonitorElement::DQM_KIND_TH2F)
00762         {
00763           sum += h->GetBinContent(h->GetBin(cx, cy));
00764           ++nsum;
00765         }
00766         else if (me->kind() == MonitorElement::DQM_KIND_TH2S)
00767         {
00768           sum += h->GetBinContent(h->GetBin(cx, cy));
00769           ++nsum;
00770         }
00771         else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE)
00772         {
00773           if (me->getTProfile()->GetBinEntries(h->GetBin(cx)) >= minEntries_/(ncx))
00774           {
00775             sum += h->GetBinContent(h->GetBin(cx));
00776             ++nsum;
00777           }
00778         }
00779         else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D)
00780         {
00781           if (me->getTProfile2D()->GetBinEntries(h->GetBin(cx, cy)) >= minEntries_/(ncx*ncy))
00782           {
00783             sum += h->GetBinContent(h->GetBin(cx, cy));
00784             ++nsum;
00785           }
00786         }
00787       }
00788     }
00789 
00790     if (nsum > 0) average = sum/nsum;
00791 
00792   } // calculate average value of all bin contents
00793 
00794   int fail = 0;
00795 
00796   for (int cx = 1; cx <= ncx; ++cx)
00797   {
00798     for (int cy = 1; cy <= ncy; ++cy)
00799     {
00800       bool failMean = false;
00801       bool failRMS = false;
00802       bool failMeanTolerance = false;
00803 
00804       if (me->kind() == MonitorElement::DQM_KIND_TPROFILE && me->getTProfile()->GetBinEntries(h->GetBin(cx)) < minEntries_/(ncx)) continue;
00805 
00806       if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D && me->getTProfile2D()->GetBinEntries(h->GetBin(cx, cy)) < minEntries_/(ncx*ncy)) continue;
00807 
00808       if (checkMean_)
00809       {
00810         float mean = h->GetBinContent(h->GetBin(cx, cy));
00811         failMean = (mean < minMean_ || mean > maxMean_);
00812       }
00813 
00814       if (checkRMS_)
00815       {
00816         float rms = h->GetBinError(h->GetBin(cx, cy));
00817         failRMS = (rms < minRMS_ || rms > maxRMS_);
00818       }
00819 
00820       if (checkMeanTolerance_)
00821       {
00822         float mean = h->GetBinContent(h->GetBin(cx, cy));
00823         failMeanTolerance = (TMath::Abs(mean - average) > toleranceMean_*TMath::Abs(average));
00824       }
00825 
00826       if (failMean || failRMS || failMeanTolerance)
00827       {
00828 
00829         if (me->kind() == MonitorElement::DQM_KIND_TH2F) {
00830           DQMChannel chan(cx, cy, 0,
00831                           h->GetBinContent(h->GetBin(cx, cy)),
00832                           h->GetBinError(h->GetBin(cx, cy)));
00833           badChannels_.push_back(chan);
00834         }
00835         else if (me->kind() == MonitorElement::DQM_KIND_TH2S) {
00836           DQMChannel chan(cx, cy, 0,
00837                           h->GetBinContent(h->GetBin(cx, cy)),
00838                           h->GetBinError(h->GetBin(cx, cy)));
00839           badChannels_.push_back(chan);
00840         }
00841         else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) {
00842           DQMChannel chan(cx, cy, int(me->getTProfile()->GetBinEntries(h->GetBin(cx))),
00843                           0,
00844                           h->GetBinError(h->GetBin(cx)));
00845           badChannels_.push_back(chan);
00846         }
00847         else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D) {
00848           DQMChannel chan(cx, cy, int(me->getTProfile2D()->GetBinEntries(h->GetBin(cx, cy))),
00849                           h->GetBinContent(h->GetBin(cx, cy)),
00850                           h->GetBinError(h->GetBin(cx, cy)));
00851           badChannels_.push_back(chan);
00852         }
00853         ++fail;
00854       }
00855     }
00856   }
00857 
00858   return 1.*(ncx*ncy - fail)/(ncx*ncy);
00859   } 
00860 
00861 else     
00862 {
00863   if (me->kind()==MonitorElement::DQM_KIND_TH2F){
00864     ncx = me->getTH2F()->GetXaxis()->GetNbins();
00865     ncy = me->getTH2F()->GetYaxis()->GetNbins();
00866     h  = me->getTH2F(); // access Test histo
00867   }
00868   else if (me->kind()==MonitorElement::DQM_KIND_TH2S){
00869     ncx = me->getTH2S()->GetXaxis()->GetNbins();
00870     ncy = me->getTH2S()->GetYaxis()->GetNbins();
00871     h  = me->getTH2S(); // access Test histo
00872   }
00873   else {
00874    std::cout<< " ContentsWithinExpected AS! ERROR: ME does not contain TH2F/TH2S" << std::endl; 
00875    return -1;
00876    } 
00877 
00878   // if (!rangeInitialized_) return 0; // all accepted if no initialization
00879    int fail = 0;
00880    for (int cx = 1; cx <= ncx; ++cx)
00881    {
00882      for (int cy = 1; cy <= ncy; ++cy)
00883      {
00884        bool failure = false;
00885        float Content = h->GetBinContent(h->GetBin(cx, cy));
00886        if(Content) failure = (Content <  minMean_ || Content >  maxMean_);
00887        if (failure) ++fail;
00888       }
00889     }
00890  
00891     return 1.*(ncx*ncy-fail)/(ncx*ncy);
00892  } 
00893 
00894 
00895 }

void ContentsWithinExpected::setMeanRange ( float  xmin,
float  xmax 
) [inline]

set expected value for mean

Definition at line 484 of file QTest.h.

References checkMean_, checkRange(), maxMean_, and minMean_.

Referenced by QTestConfigure::EnableContentsWithinExpectedTest().

00485     {
00486       checkRange(xmin, xmax);
00487       minMean_ = xmin;
00488       maxMean_ = xmax;
00489       checkMean_ = true;
00490     }

void ContentsWithinExpected::setMeanTolerance ( float  fracTolerance  )  [inline]

set (fractional) tolerance for mean

Definition at line 502 of file QTest.h.

References checkMeanTolerance_, and toleranceMean_.

Referenced by QTestConfigure::EnableContentsWithinExpectedTest().

00503     {
00504       if (fracTolerance >= 0.0)
00505       {
00506         toleranceMean_ = fracTolerance;
00507         checkMeanTolerance_ = true;
00508       }
00509     }

void ContentsWithinExpected::setMessage ( void   )  [inline, protected, virtual]

set status & message after test has run

Reimplemented from SimpleTest.

Definition at line 518 of file QTest.h.

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

00518                         {
00519       std::ostringstream message;
00520       message << " Test " << qtname_ << " (" << algoName_
00521               << "): Entry fraction within range = " << prob_;
00522       message_ = message.str();
00523     }

void ContentsWithinExpected::setRMSRange ( float  xmin,
float  xmax 
) [inline]

set expected value for mean

Definition at line 493 of file QTest.h.

References checkRange(), checkRMS_, maxRMS_, and minRMS_.

Referenced by QTestConfigure::EnableContentsWithinExpectedTest().

00494     {
00495       checkRange(xmin, xmax);
00496       minRMS_ = xmin;
00497       maxRMS_ = xmax;
00498       checkRMS_ = true;
00499     }

void ContentsWithinExpected::setUseEmptyBins ( unsigned int  useEmptyBins  )  [inline]

Definition at line 477 of file QTest.h.

References useEmptyBins_.

Referenced by QTestConfigure::EnableContentsWithinExpectedTest().

00477 { useEmptyBins_ = useEmptyBins; }


Member Data Documentation

bool ContentsWithinExpected::checkMean_ [protected]

Definition at line 528 of file QTest.h.

Referenced by ContentsWithinExpected(), runTest(), and setMeanRange().

bool ContentsWithinExpected::checkMeanTolerance_ [protected]

Definition at line 530 of file QTest.h.

Referenced by ContentsWithinExpected(), runTest(), and setMeanTolerance().

bool ContentsWithinExpected::checkRMS_ [protected]

Definition at line 529 of file QTest.h.

Referenced by ContentsWithinExpected(), runTest(), and setRMSRange().

TH1* ContentsWithinExpected::h [protected]

Definition at line 516 of file QTest.h.

Referenced by runTest().

float ContentsWithinExpected::maxMean_ [protected]

Definition at line 532 of file QTest.h.

Referenced by ContentsWithinExpected(), runTest(), and setMeanRange().

float ContentsWithinExpected::maxRMS_ [protected]

Definition at line 533 of file QTest.h.

Referenced by ContentsWithinExpected(), runTest(), and setRMSRange().

float ContentsWithinExpected::minMean_ [protected]

Definition at line 532 of file QTest.h.

Referenced by ContentsWithinExpected(), and setMeanRange().

float ContentsWithinExpected::minRMS_ [protected]

Definition at line 533 of file QTest.h.

Referenced by ContentsWithinExpected(), and setRMSRange().

float ContentsWithinExpected::toleranceMean_ [protected]

Definition at line 531 of file QTest.h.

Referenced by ContentsWithinExpected(), runTest(), and setMeanTolerance().

unsigned int ContentsWithinExpected::useEmptyBins_ [protected]

Definition at line 536 of file QTest.h.

Referenced by runTest(), and setUseEmptyBins().

bool ContentsWithinExpected::validMethod_ [protected]

Definition at line 534 of file QTest.h.

Referenced by checkRange(), and ContentsWithinExpected().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:16:47 2009 for CMSSW by  doxygen 1.5.4