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 242 of file QTest.h.

Constructor & Destructor Documentation

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

Definition at line 245 of file QTest.h.

References QCriterion::setAlgoName().

245  : SimpleTest(name)
246  {
248  }
void setAlgoName(std::string name)
set algorithm name
Definition: QTest.h:80
SimpleTest(const std::string &name, bool keepBadChannels=false)
Definition: QTest.h:140
static std::string getAlgoName()
Definition: QTest.h:249

Member Function Documentation

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

Definition at line 249 of file QTest.h.

References QCriterion::runTest().

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

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

Reimplemented from QCriterion.

Definition at line 405 of file QTest.cc.

References funct::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(), h, MonitorElement::kind(), plotBeamSpotDB::last, Max(), indexGen::s2, combinedConstraintHelpers::sum2(), and w2.

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