CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions
Comp2RefKolmogorov Class Reference

Comparison to reference using the Kolmogorov algorithm. More...

#include <QTest.h>

Inheritance diagram for Comp2RefKolmogorov:
SimpleTest QCriterion

Public Member Functions

 Comp2RefKolmogorov (const std::string &name)
 
float runTest (const MonitorElement *me)
 
- Public Member Functions inherited from SimpleTest
virtual std::vector< DQMChannelgetBadChannels (void) const
 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 (void) const
 get algorithm name More...
 
std::string getMessage (void) const
 get message attached to test More...
 
std::string getName (void) const
 get name of quality test More...
 
int getStatus (void) const
 (class should be created by DQMStore class) 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 (void)
 

Additional Inherited Members

- Protected Member Functions inherited from SimpleTest
virtual void setMessage (void)
 set status & message after test has run More...
 
- Protected Member Functions inherited from QCriterion
void init (void)
 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 (void)
 
- 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

Comparison to reference using the Kolmogorov algorithm.

Definition at line 240 of file QTest.h.

Constructor & Destructor Documentation

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

Definition at line 243 of file QTest.h.

References QCriterion::setAlgoName().

243  : SimpleTest(name)
244  {
246  }
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:78
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:138
static std::string getAlgoName(void)
Definition: QTest.h:247

Member Function Documentation

static std::string Comp2RefKolmogorov::getAlgoName ( void  )
inlinestatic

Definition at line 247 of file QTest.h.

References QCriterion::runTest().

Referenced by QTestConfigure::EnableComp2RefKolmogorovTest(), QTestConfigure::enableTests(), and QTestParameterNames::QTestParameterNames().

247 { return "Comp2RefKolmogorov"; }
float Comp2RefKolmogorov::runTest ( const MonitorElement me)
virtual

Reimplemented from QCriterion.

Definition at line 394 of file QTest.cc.

References Abs(), stringResolutionProvider_cfi::bin, gather_cfg::cout, MonitorElement::DQM_KIND_TH1D, MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH1S, MonitorElement::DQM_KIND_TPROFILE, MillePedeFileConverter_cfg::e, plotBeamSpotDB::first, MonitorElement::getRefRootObject(), MonitorElement::getRefTH1D(), MonitorElement::getRefTH1F(), MonitorElement::getRefTH1S(), MonitorElement::getRefTProfile(), MonitorElement::getRootObject(), MonitorElement::getTH1D(), MonitorElement::getTH1F(), MonitorElement::getTH1S(), MonitorElement::getTProfile(), MonitorElement::kind(), plotBeamSpotDB::last, Max(), indexGen::s2, combinedConstraintHelpers::sum2(), and w2.

395 {
396  const double difprec = 1e-5;
397 
398  if (!me)
399  return -1;
400  if (!me->getRootObject() || !me->getRefRootObject())
401  return -1;
402  TH1* h=0;
403  TH1* ref_=0;
404 
405  if (verbose_>1)
406  std::cout << "QTest:" << getAlgoName() << "::runTest called on "
407  << me-> getFullname() << "\n";
408  //-- TH1F
410  {
411  h = me->getTH1F(); // access Test histo
412  ref_ = me->getRefTH1F(); //access Ref histo
413  }
414  //-- TH1S
415  else if (me->kind()==MonitorElement::DQM_KIND_TH1S)
416  {
417  h = me->getTH1S(); // access Test histo
418  ref_ = me->getRefTH1S(); //access Ref histo
419  }
420  //-- TH1D
421  else if (me->kind()==MonitorElement::DQM_KIND_TH1D)
422  {
423  h = me->getTH1D(); // access Test histo
424  ref_ = me->getRefTH1D(); //access Ref histo
425  }
426  //-- TProfile
427  else if (me->kind()==MonitorElement::DQM_KIND_TPROFILE)
428  {
429  h = me->getTProfile(); // access Test histo
430  ref_ = me->getRefTProfile(); //access Ref histo
431  }
432  else
433  {
434  if (verbose_>0)
435  std::cout << "QTest:Comp2RefKolmogorov"
436  << " ME does not contain TH1F/TH1S/TH1D/TProfile, exiting\n";
437  return -1;
438  }
439 
440  //-- isInvalid ? - Check consistency in number of channels
441  int ncx1 = h->GetXaxis()->GetNbins();
442  int ncx2 = ref_->GetXaxis()->GetNbins();
443  if ( ncx1 != ncx2)
444  {
445  if (verbose_>0)
446  std::cout << "QTest:Comp2RefKolmogorov"
447  << " different number of channels! ("
448  << ncx1 << ", " << ncx2 << "), exiting\n";
449  return -1;
450  }
451  //-- isInvalid ? - Check consistency in channel edges
452  double diff1 = TMath::Abs(h->GetXaxis()->GetXmin() - ref_->GetXaxis()->GetXmin());
453  double diff2 = TMath::Abs(h->GetXaxis()->GetXmax() - ref_->GetXaxis()->GetXmax());
454  if (diff1 > difprec || diff2 > difprec)
455  {
456  if (verbose_>0)
457  std::cout << "QTest:Comp2RefKolmogorov"
458  << " histograms with different binning, exiting\n";
459  return -1;
460  }
461 
462  //-- QUALITY TEST itself
463  Bool_t afunc1 = kFALSE; Bool_t afunc2 = kFALSE;
464  double sum1 = 0, sum2 = 0;
465  double ew1, ew2, w1 = 0, w2 = 0;
466  int bin;
467  for (bin=1;bin<=ncx1;bin++)
468  {
469  sum1 += h->GetBinContent(bin);
470  sum2 += ref_->GetBinContent(bin);
471  ew1 = h->GetBinError(bin);
472  ew2 = ref_->GetBinError(bin);
473  w1 += ew1*ew1;
474  w2 += ew2*ew2;
475  }
476 
477  if (sum1 == 0)
478  {
479  if (verbose_>0)
480  std::cout << "QTest:Comp2RefKolmogorov"
481  << " Test Histogram: " << h->GetName()
482  << ": integral is zero, exiting\n";
483  return -1;
484  }
485  if (sum2 == 0)
486  {
487  if (verbose_>0)
488  std::cout << "QTest:Comp2RefKolmogorov"
489  << " Ref Histogram: " << ref_->GetName()
490  << ": integral is zero, exiting\n";
491  return -1;
492  }
493 
494  double tsum1 = sum1; double tsum2 = sum2;
495  tsum1 += h->GetBinContent(0);
496  tsum2 += ref_->GetBinContent(0);
497  tsum1 += h->GetBinContent(ncx1+1);
498  tsum2 += ref_->GetBinContent(ncx1+1);
499 
500  // Check if histograms are weighted.
501  // If number of entries = number of channels, probably histograms were
502  // not filled via Fill(), but via SetBinContent()
503  double ne1 = h->GetEntries();
504  double ne2 = ref_->GetEntries();
505  // look at first histogram
506  double difsum1 = (ne1-tsum1)/tsum1;
507  double esum1 = sum1;
508  if (difsum1 > difprec && int(ne1) != ncx1)
509  {
510  if (h->GetSumw2N() == 0)
511  {
512  if (verbose_>0)
513  std::cout << "QTest:Comp2RefKolmogorov"
514  << " Weighted events and no Sumw2 for "
515  << h->GetName() << "\n";
516  }
517  else
518  {
519  esum1 = sum1*sum1/w1; //number of equivalent entries
520  }
521  }
522  // look at second histogram
523  double difsum2 = (ne2-tsum2)/tsum2;
524  double esum2 = sum2;
525  if (difsum2 > difprec && int(ne2) != ncx1)
526  {
527  if (ref_->GetSumw2N() == 0)
528  {
529  if (verbose_>0)
530  std::cout << "QTest:Comp2RefKolmogorov"
531  << " Weighted events and no Sumw2 for "
532  << ref_->GetName() << "\n";
533  }
534  else
535  {
536  esum2 = sum2*sum2/w2; //number of equivalent entries
537  }
538  }
539 
540  double s1 = 1/tsum1; double s2 = 1/tsum2;
541  // Find largest difference for Kolmogorov Test
542  double dfmax =0, rsum1 = 0, rsum2 = 0;
543  // use underflow bin
544  int first = 0; // 1
545  // use overflow bin
546  int last = ncx1+1; // ncx1
547  for ( bin=first; bin<=last; bin++)
548  {
549  rsum1 += s1*h->GetBinContent(bin);
550  rsum2 += s2*ref_->GetBinContent(bin);
551  dfmax = TMath::Max(dfmax,TMath::Abs(rsum1-rsum2));
552  }
553 
554  // Get Kolmogorov probability
555  double z = 0;
556  if (afunc1) z = dfmax*TMath::Sqrt(esum2);
557  else if (afunc2) z = dfmax*TMath::Sqrt(esum1);
558  else z = dfmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
559 
560  // This numerical error condition should never occur:
561  if (TMath::Abs(rsum1-1) > 0.002)
562  if (verbose_>0)
563  std::cout << "QTest:Comp2RefKolmogorov"
564  << " Numerical problems with histogram "
565  << h->GetName() << "\n";
566  if (TMath::Abs(rsum2-1) > 0.002)
567  if (verbose_>0)
568  std::cout << "QTest:Comp2RefKolmogorov"
569  << " Numerical problems with histogram "
570  << ref_->GetName() << "\n";
571 
572  return TMath::KolmogorovProb(z);
573 }
TH1F * getRefTH1F(void) const
TH1S * getTH1S(void) const
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
int verbose_
Definition: QTest.h:118
TH1D * getTH1D(void) const
T Abs(T a)
Definition: MathUtil.h:49
static std::string getAlgoName(void)
Definition: QTest.h:247
Kind kind(void) const
Get the type of the monitor element.
bin
set the eta bin as selection string.
T Max(T a, T b)
Definition: MathUtil.h:44
TObject * getRootObject(void) const
TH1F * getTH1F(void) const
TProfile * getRefTProfile(void) const
TProfile * getTProfile(void) const
TObject * getRefRootObject(void) const
TH1S * getRefTH1S(void) const
TH1D * getRefTH1D(void) const