CMS 3D CMS Logo

MeanWithinExpected Class Reference

Algorithm for testing if histogram's mean value is near expected value. More...

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

Inheritance diagram for MeanWithinExpected:

SimpleTest QCriterion

List of all members.

Public Member Functions

 MeanWithinExpected (const std::string &name)
float runTest (const MonitorElement *me)
 run the test; (a) if useRange is called: 1 if mean within allowed range, 0 otherwise
void setExpectedMean (float expMean)
 set expected value for mean
void useRange (float xmin, float xmax)
void useRMS (void)
void useSigma (float expectedSigma)

Static Public Member Functions

static std::string getAlgoName (void)

Protected Member Functions

void checkRange (void)
 check that allowed range is logical
void checkSigma (void)
 check that exp_sigma_ is non-zero
float doGaussTest (const TH1 *h, float sigma)
 test assuming mean value is quantity with gaussian errors
float doRangeTest (const TH1 *h)
 test for useRange_ = true case
bool isInvalid (void)
void setMessage (void)
 set status & message after test has run

Protected Attributes

float expMean_
TH1F * h
float sigma_
bool useRange_
bool useRMS_
bool useSigma_
bool validExpMean_
bool validMethod_
float xmax_
float xmin_


Detailed Description

Algorithm for testing if histogram's mean value is near expected value.

Definition at line 542 of file QTest.h.


Constructor & Destructor Documentation

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

Definition at line 545 of file QTest.h.

References getAlgoName(), QCriterion::setAlgoName(), validExpMean_, and validMethod_.

00545                                             : SimpleTest(name)
00546     {
00547       validMethod_ = validExpMean_ = false;
00548       setAlgoName(getAlgoName());
00549     }


Member Function Documentation

void MeanWithinExpected::checkRange ( void   )  [protected]

check that allowed range is logical

Definition at line 981 of file QTest.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), getAlgoName(), validMethod_, xmax_, and xmin_.

Referenced by useRange().

00982 {
00983   if (xmin_ < xmax_)  validMethod_ = true;
00984   else
00985   {
00986     std::cout << " *** Error! Illogical range: (" << xmin_ << ", " << xmax_
00987               << ") in algorithm " << getAlgoName() << std::endl;
00988     validMethod_ = false;
00989   }
00990 }

void MeanWithinExpected::checkSigma ( void   )  [protected]

check that exp_sigma_ is non-zero

Definition at line 970 of file QTest.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), getAlgoName(), sigma_, and validMethod_.

Referenced by useSigma().

00971 {
00972   if (sigma_ != 0) validMethod_ = true;
00973   else
00974   {
00975   std::cout << " *** Error! Expected sigma = " << sigma_ << " in algorithm " << getAlgoName() << std::endl;
00976     validMethod_ = false;
00977   }
00978 }

float MeanWithinExpected::doGaussTest ( const TH1 *  h,
float  sigma 
) [protected]

test assuming mean value is quantity with gaussian errors

Definition at line 954 of file QTest.cc.

References expMean_.

Referenced by runTest().

00955 {
00956   float chi = (h->GetMean() - expMean_)/sigma;
00957   return TMath::Prob(chi*chi, 1);
00958 }

float MeanWithinExpected::doRangeTest ( const TH1 *  h  )  [protected]

test for useRange_ = true case

Definition at line 961 of file QTest.cc.

References mean(), and xmin_.

Referenced by runTest().

00962 {
00963   float mean = h->GetMean();
00964   if (mean <= xmax_ && mean >= xmin_) return 1;
00965   else  return 0;
00966 }

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

Definition at line 551 of file QTest.h.

Referenced by checkRange(), checkSigma(), QTestConfigure::EnableMeanWithinExpectedTest(), QTestConfigure::enableTests(), MeanWithinExpected(), and QTestParameterNames::QTestParameterNames().

00552   { return "MeanWithinExpected"; }

bool MeanWithinExpected::isInvalid ( void   )  [protected]

Definition at line 993 of file QTest.cc.

References useRange_, validExpMean_, and validMethod_.

Referenced by runTest().

00994 {
00995   // if useRange_ = true, test does not need a "expected mean value"
00996   if (useRange_) return !validMethod_; // set by checkRange()
00997 
00998   // otherwise (useSigma_ or useRMS_ case), we also need to check
00999   // if "expected mean value" has been set
01000   return !validMethod_  // set by useRMS() or checkSigma()
01001     || !validExpMean_; // set by setExpectedMean()
01002 
01003 }

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

run the test; (a) if useRange is called: 1 if mean within allowed range, 0 otherwise

(b) is useRMS or useSigma is called: result is the probability Prob(chi^2, ndof=1) that the mean of histogram will be deviated by more than +/- delta from <expected_mean>, where delta = mean - <expected_mean>, and chi^2 = (delta/sigma)^2. sigma is the RMS of the histogram ("useRMS") or <expected_sigma> ("useSigma") e.g. for delta = 1, Prob = 31.7% for delta = 2, Prob = 4.55%

(returns result in [0, 1] or <0 for failure)

Reimplemented from QCriterion.

Definition at line 924 of file QTest.cc.

References GenMuonPlsPt100GeV_cfg::cout, doGaussTest(), doRangeTest(), MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH1S, lat::endl(), MonitorElement::getFullname(), MonitorElement::getRootObject(), MonitorElement::getTH1F(), MonitorElement::getTH1S(), h, isInvalid(), MonitorElement::kind(), sigma_, useRange_, useRMS_, and useSigma_.

00925 {
00926   if (!me) return -1;
00927   if (!me->getRootObject()) return -1;
00928   TH1* h=0;
00929    
00930   if (me->kind()==MonitorElement::DQM_KIND_TH1F) { 
00931     h = me->getTH1F(); //access Test histo
00932   }
00933   else if (me->kind()==MonitorElement::DQM_KIND_TH1S) { 
00934     h = me->getTH1S(); //access Test histo
00935   }
00936   else {
00937     std::cout<< " MeanWithinExpected ERROR: ME " << me->getFullname() << " does not contain TH1F/TH1S" << std::endl; 
00938     return -1;
00939   } 
00940    
00941   if (isInvalid()) return -1;
00942 
00943   if (useRange_) return doRangeTest(h);
00944 
00945   if (useSigma_) return doGaussTest(h, sigma_);
00946 
00947   if (useRMS_) return doGaussTest(h, h->GetRMS());
00948 
00949   // we should never reach this point;
00950   return -99;
00951 }

void MeanWithinExpected::setExpectedMean ( float  expMean  )  [inline]

set expected value for mean

Definition at line 555 of file QTest.h.

References expMean_, and validExpMean_.

Referenced by createMeanValueTest(), and QTestConfigure::EnableMeanWithinExpectedTest().

00556   {
00557    expMean_ = expMean;
00558    validExpMean_ = true;
00559   }

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

set status & message after test has run

Reimplemented from SimpleTest.

Definition at line 603 of file QTest.h.

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

00603                         {
00604       std::ostringstream message;
00605       message << " Test " << qtname_ << " (" << algoName_ << "): ";
00606       if(useRange_)
00607       {
00608         message << "Mean within allowed range? ";
00609         if(prob_)
00610           message << "Yes";
00611         else
00612           message << "No";
00613       }
00614       else
00615         message << "prob = " << prob_;
00616 
00617       message_ = message.str();
00618     }

void MeanWithinExpected::useRange ( float  xmin,
float  xmax 
) [inline]

Definition at line 576 of file QTest.h.

References checkRange(), useRange_, useRMS_, useSigma_, xmax_, and xmin_.

Referenced by QTestConfigure::EnableMeanWithinExpectedTest().

00577   {
00578     useRange_ = true;
00579     useSigma_ = useRMS_ = false;
00580     xmin_ = xmin; xmax_ = xmax;
00581     checkRange();
00582    }

void MeanWithinExpected::useRMS ( void   )  [inline]

Definition at line 561 of file QTest.h.

References useRange_, useRMS_, useSigma_, and validMethod_.

Referenced by createMeanValueTest(), and QTestConfigure::EnableMeanWithinExpectedTest().

00562   {
00563    useRMS_ = true;
00564    useSigma_ = useRange_ = false;
00565    validMethod_ = true;
00566   }

void MeanWithinExpected::useSigma ( float  expectedSigma  )  [inline]

Definition at line 568 of file QTest.h.

References checkSigma(), sigma_, useRange_, useRMS_, and useSigma_.

Referenced by createMeanValueTest(), and QTestConfigure::EnableMeanWithinExpectedTest().

00569   {
00570    useSigma_ = true;
00571    useRMS_ = useRange_ = false;
00572    sigma_ = expectedSigma;
00573    checkSigma();
00574   }


Member Data Documentation

float MeanWithinExpected::expMean_ [protected]

Definition at line 638 of file QTest.h.

Referenced by doGaussTest(), and setExpectedMean().

TH1F* MeanWithinExpected::h [protected]

Definition at line 633 of file QTest.h.

Referenced by runTest().

float MeanWithinExpected::sigma_ [protected]

Definition at line 637 of file QTest.h.

Referenced by checkSigma(), runTest(), and useSigma().

bool MeanWithinExpected::useRange_ [protected]

Definition at line 636 of file QTest.h.

Referenced by isInvalid(), runTest(), setMessage(), useRange(), useRMS(), and useSigma().

bool MeanWithinExpected::useRMS_ [protected]

Definition at line 634 of file QTest.h.

Referenced by runTest(), useRange(), useRMS(), and useSigma().

bool MeanWithinExpected::useSigma_ [protected]

Definition at line 635 of file QTest.h.

Referenced by runTest(), useRange(), useRMS(), and useSigma().

bool MeanWithinExpected::validExpMean_ [protected]

Definition at line 641 of file QTest.h.

Referenced by isInvalid(), MeanWithinExpected(), and setExpectedMean().

bool MeanWithinExpected::validMethod_ [protected]

Definition at line 640 of file QTest.h.

Referenced by checkRange(), checkSigma(), isInvalid(), MeanWithinExpected(), and useRMS().

float MeanWithinExpected::xmax_ [protected]

Definition at line 639 of file QTest.h.

Referenced by checkRange(), and useRange().

float MeanWithinExpected::xmin_ [protected]

Definition at line 639 of file QTest.h.

Referenced by checkRange(), doRangeTest(), and useRange().


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