CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

Comp2RefChi2 Class Reference

#include <QTest.h>

Inheritance diagram for Comp2RefChi2:
SimpleTest QCriterion

List of all members.

Public Member Functions

 Comp2RefChi2 (const std::string &name)
float runTest (const MonitorElement *me)

Static Public Member Functions

static std::string getAlgoName (void)

Protected Member Functions

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

Protected Attributes

double chi2_
int Ndof_

Detailed Description

Definition at line 182 of file QTest.h.


Constructor & Destructor Documentation

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

Definition at line 185 of file QTest.h.

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


Member Function Documentation

static std::string Comp2RefChi2::getAlgoName ( void  ) [inline, static]
float Comp2RefChi2::runTest ( const MonitorElement me) [virtual]

Reimplemented from QCriterion.

Definition at line 163 of file QTest.cc.

References gather_cfg::cout, MonitorElement::DQM_KIND_TH1D, MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH1S, MonitorElement::DQM_KIND_TPROFILE, MonitorElement::getRefRootObject(), MonitorElement::getRefTH1D(), MonitorElement::getRefTH1F(), MonitorElement::getRefTH1S(), MonitorElement::getRefTProfile(), MonitorElement::getRootObject(), MonitorElement::getTH1D(), MonitorElement::getTH1F(), MonitorElement::getTH1S(), MonitorElement::getTProfile(), h, i, MonitorElement::kind(), and groupFilesInBlocks::temp.

{
  if (!me) 
    return -1;
  if (!me->getRootObject() || !me->getRefRootObject()) 
    return -1;
  TH1* h=0;
  TH1* ref_=0;
 
  if (verbose_>1) 
    std::cout << "QTest:" << getAlgoName() << "::runTest called on " 
              << me-> getFullname() << "\n";
  //-- TH1F
  if (me->kind()==MonitorElement::DQM_KIND_TH1F)
  { 
    h = me->getTH1F(); // access Test histo
    ref_ = me->getRefTH1F(); //access Ref histo
  } 
  //-- TH1S
  else if (me->kind()==MonitorElement::DQM_KIND_TH1S)
  { 
    h = me->getTH1S(); // access Test histo
    ref_ = me->getRefTH1S(); //access Ref histo
  } 
  //-- TH1D
  else if (me->kind()==MonitorElement::DQM_KIND_TH1D)
  { 
    h = me->getTH1D(); // access Test histo
    ref_ = me->getRefTH1D(); //access Ref histo
  } 
  //-- TProfile
  else if (me->kind()==MonitorElement::DQM_KIND_TPROFILE)
  {
    h = me->getTProfile(); // access Test histo
    ref_ = me->getRefTProfile(); //access Ref histo
  } 
  else
  { 
    if (verbose_>0) 
      std::cout << "QTest::Comp2RefChi2"
                << " ME does not contain TH1F/TH1S/TH1D/TProfile, exiting\n"; 
    return -1;
  } 

   //-- isInvalid ? - Check consistency in number of channels
  int ncx1  = h->GetXaxis()->GetNbins(); 
  int ncx2  = ref_->GetXaxis()->GetNbins();
  if ( ncx1 !=  ncx2)
  {
    if (verbose_>0) 
      std::cout << "QTest:Comp2RefChi2"
                << " different number of channels! ("
                << ncx1 << ", " << ncx2 << "), exiting\n";
    return -1;
  } 

  //--  QUALITY TEST itself 
  //reset Results
  Ndof_ = 0; chi2_ = -1.; ncx1 = ncx2 = -1;

  int i, i_start, i_end;
  double chi2 = 0.;  int ndof = 0; int constraint = 0;

  i_start = 1;  
  i_end = ncx1;
  //  if (fXaxis.TestBit(TAxis::kAxisRange)) {
  i_start = h->GetXaxis()->GetFirst();
  i_end   = h->GetXaxis()->GetLast();
  //  }
  ndof = i_end-i_start+1-constraint;

  //Compute the normalisation factor
  double sum1=0, sum2=0;
  for (i=i_start; i<=i_end; i++)
  {
    sum1 += h->GetBinContent(i);
    sum2 += ref_->GetBinContent(i);
  }

  //check that the histograms are not empty
  if (sum1 == 0)
  {
    if (verbose_>0) 
      std::cout << "QTest:Comp2RefChi2"
                << " Test Histogram " << h->GetName() 
                << " is empty, exiting\n";
    return -1;
  }
  if (sum2 == 0)
  {
    if (verbose_>0) 
      std::cout << "QTest:Comp2RefChi2"
                << " Ref Histogram " << ref_->GetName() 
                << " is empty, exiting\n";
    return -1;
  }

  double bin1, bin2, err1, err2, temp;
  for (i=i_start; i<=i_end; i++)
  {
    bin1 = h->GetBinContent(i)/sum1;
    bin2 = ref_->GetBinContent(i)/sum2;
    if (bin1 ==0 && bin2==0)
    {
      --ndof; //no data means one less degree of freedom
    } 
    else 
    {
      temp  = bin1-bin2;
      err1=h->GetBinError(i); err2=ref_->GetBinError(i);
      if (err1 == 0 && err2 == 0)
      {
        if (verbose_>0) 
          std::cout << "QTest:Comp2RefChi2"
                    << " bins with non-zero content and zero error, exiting\n";
        return -1;
      }
      err1*=err1      ; err2*=err2;
      err1/=sum1*sum1 ; err2/=sum2*sum2;
      chi2 +=temp*temp/(err1+err2);
    }
  }
  chi2_ = chi2;  Ndof_ = ndof;
  return TMath::Prob(0.5*chi2, int(0.5*ndof));
}
void Comp2RefChi2::setMessage ( void  ) [inline, protected, virtual]

set status & message after test has run

Reimplemented from SimpleTest.

Definition at line 194 of file QTest.h.

References chi2_, QCriterion::errorProb_, python::rootplot::argparse::message, QCriterion::message_, SimpleTest::minEntries_, Ndof_, and QCriterion::warningProb_.

  {
    std::ostringstream message;
    message << "chi2/Ndof = " << chi2_ << "/" << Ndof_
            << ", minimum needed statistics = " << minEntries_
            << " warning threshold = " << this->warningProb_
            << " error threshold = " << this->errorProb_;
    message_ = message.str();
  }

Member Data Documentation

double Comp2RefChi2::chi2_ [protected]

Definition at line 205 of file QTest.h.

Referenced by setMessage().

int Comp2RefChi2::Ndof_ [protected]

Definition at line 205 of file QTest.h.

Referenced by setMessage().