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) override
 
- Public Member Functions inherited from SimpleTest
std::vector< DQMChannelgetBadChannels () const override
 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 () const
 get algorithm name More...
 
std::string getMessage () const
 get message attached to test More...
 
std::string getName () const
 get name of quality test More...
 
int getStatus () 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 ()
 

Additional Inherited Members

- Protected Member Functions inherited from SimpleTest
void setMessage () override
 set status & message after test has run More...
 
- Protected Member Functions inherited from QCriterion
void init ()
 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 ()=default
 
- 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 241 of file QTest.h.

Constructor & Destructor Documentation

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

Definition at line 244 of file QTest.h.

References QCriterion::setAlgoName().

244  : SimpleTest(name)
245  {
247  }
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:79
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:139
static std::string getAlgoName()
Definition: QTest.h:248

Member Function Documentation

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

Definition at line 248 of file QTest.h.

References QCriterion::runTest().

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

248 { return "Comp2RefKolmogorov"; }
float Comp2RefKolmogorov::runTest ( const MonitorElement me)
overridevirtual

Reimplemented from QCriterion.

Definition at line 404 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.

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