CMS 3D CMS Logo

Comp2RefKolmogorov Class Reference

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

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

Inheritance diagram for Comp2RefKolmogorov:

SimpleTest QCriterion

List of all members.

Public Member Functions

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

Static Public Member Functions

static std::string getAlgoName (void)

Protected Attributes

TH1 * h
Int_t ncx1
 # of bins for test & reference histograms
Int_t ncx2
TH1 * ref_

Static Protected Attributes

static const Double_t difprec = 1e-5


Detailed Description

Comparison to reference using the Kolmogorov algorithm.

Definition at line 261 of file QTest.h.


Constructor & Destructor Documentation

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

Definition at line 264 of file QTest.h.

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

00264                                             : SimpleTest(name)
00265   { setAlgoName(getAlgoName()); }


Member Function Documentation

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

Definition at line 269 of file QTest.h.

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

00270   { return "Comp2RefKolmogorov"; }

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

Reimplemented from QCriterion.

Definition at line 254 of file QTest.cc.

References GenMuonPlsPt100GeV_cfg::cout, difprec, MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH1S, MonitorElement::DQM_KIND_TPROFILE, lat::endl(), first, MonitorElement::getRefRootObject(), MonitorElement::getRefTH1F(), MonitorElement::getRefTH1S(), MonitorElement::getRefTProfile(), MonitorElement::getRootObject(), MonitorElement::getTH1F(), MonitorElement::getTH1S(), MonitorElement::getTProfile(), h, MonitorElement::kind(), prof2calltree::last, ncx1, ncx2, ref_, s1, s2, w1, w2, and z.

Referenced by FourVectorHLTClient::endRun().

00255 {
00256    if (!me) return -1;
00257    if (!me->getRootObject() || !me->getRefRootObject()) return -1;
00258    h=0;
00259    ref_=0;
00260 
00261    //-- TH1F
00262    if (me->kind()==MonitorElement::DQM_KIND_TH1F){ 
00263     h = me->getTH1F(); // access Test histo
00264     ref_ = me->getRefTH1F(); //access Ref histo
00265    } 
00266    //-- TH1S
00267    else if (me->kind()==MonitorElement::DQM_KIND_TH1S){ 
00268     h = me->getTH1S(); // access Test histo
00269     ref_ = me->getRefTH1S(); //access Ref histo
00270    } 
00271    //-- TProfile
00272    else if (me->kind()==MonitorElement::DQM_KIND_TPROFILE){
00273     h = me->getTProfile(); // access Test histo
00274     ref_ = me->getRefTProfile(); //access Ref histo
00275     }
00276    else{ 
00277     std::cout<< "Comp2RefKolmogorov ERROR: ME does not contain TH1F/TH1S/TProfile" << std::endl; 
00278     return -1;
00279    } 
00280    
00281    //-- isInvalid ? - Check consistency in number of channels
00282   ncx1  = h->GetXaxis()->GetNbins(); 
00283   ncx2   = ref_->GetXaxis()->GetNbins();
00284   if ( ncx1 !=  ncx2){
00285   std::cout<<"Comp2RefKolmogorov ERROR: different number of channels! ("
00286   << ncx1 << ", " << ncx2 << ") " << std::endl;
00287   return -1;
00288   } 
00289   //-- isInvalid ? - Check consistency in channel edges
00290   Double_t diff1 = TMath::Abs(h->GetXaxis()->GetXmin() - ref_->GetXaxis()->GetXmin());
00291   Double_t diff2 = TMath::Abs(h->GetXaxis()->GetXmax() - ref_->GetXaxis()->GetXmax());
00292   if (diff1 > difprec || diff2 > difprec){
00293   std::cout << "Comp2RefKolmogorov ERROR: histograms with different binning" << std::endl;
00294   return -1;
00295   }
00296 
00297    //--  QUALITY TEST itself 
00298   Bool_t afunc1 = kFALSE; Bool_t afunc2 = kFALSE;
00299   Double_t sum1 = 0, sum2 = 0;
00300   Double_t ew1, ew2, w1 = 0, w2 = 0;
00301   Int_t bin;
00302   for (bin=1;bin<=ncx1;bin++){
00303     sum1 += h->GetBinContent(bin);
00304     sum2 += ref_->GetBinContent(bin);
00305     ew1   = h->GetBinError(bin);
00306     ew2   = ref_->GetBinError(bin);
00307     w1   += ew1*ew1;
00308     w2   += ew2*ew2;
00309   }
00310   if (sum1 == 0){
00311     std::cout << "Comp2RefKolmogorov ERROR: Test Histogram " << h->GetName() << " integral is zero" << std::endl;
00312     return -1;
00313   }
00314   if (sum2 == 0){
00315     std::cout << "Comp2RefKolmogorov ERROR: Ref Histogram " << ref_->GetName() << " integral is zero" << std::endl;
00316     return -1;
00317   }
00318 
00319   Double_t tsum1 = sum1; Double_t tsum2 = sum2;
00320   tsum1 += h->GetBinContent(0);
00321   tsum2 += ref_->GetBinContent(0);
00322   tsum1 += h->GetBinContent(ncx1+1);
00323   tsum2 += ref_->GetBinContent(ncx1+1);
00324 
00325   // Check if histograms are weighted.
00326   // If number of entries = number of channels, probably histograms were
00327   // not filled via Fill(), but via SetBinContent()
00328   Double_t ne1 = h->GetEntries();
00329   Double_t ne2 = ref_->GetEntries();
00330   // look at first histogram
00331   Double_t difsum1 = (ne1-tsum1)/tsum1;
00332   Double_t esum1 = sum1;
00333   if (difsum1 > difprec && Int_t(ne1) != ncx1)
00334   {
00335     if (h->GetSumw2N() == 0)
00336       std::cout << " Comp2RefKolmogorov WARNING: Weighted events and no Sumw2 for "
00337                 << h->GetName() << std::endl;
00338     else
00339       esum1 = sum1*sum1/w1;  //number of equivalent entries
00340   }
00341   // look at second histogram
00342   Double_t difsum2 = (ne2-tsum2)/tsum2;
00343   Double_t esum2   = sum2;
00344   if (difsum2 > difprec && Int_t(ne2) != ncx1)
00345   {
00346     if (ref_->GetSumw2N() == 0)
00347       std::cout << " Comp2RefKolmogorov WARNING: Weighted events and no Sumw2 for "
00348                 << ref_->GetName() << std::endl;
00349     else
00350       esum2 = sum2*sum2/w2;  //number of equivalent entries
00351   }
00352 
00353   Double_t s1 = 1/tsum1; Double_t s2 = 1/tsum2;
00354 
00355   // Find largest difference for Kolmogorov Test
00356   Double_t dfmax =0, rsum1 = 0, rsum2 = 0;
00357 
00358   // use underflow bin
00359   Int_t first = 0; // 1
00360   // use overflow bin
00361   Int_t last  = ncx1+1; // ncx1
00362   for (bin=first;bin<=last;bin++)
00363   {
00364     rsum1 += s1*h->GetBinContent(bin);
00365     rsum2 += s2*ref_->GetBinContent(bin);
00366     dfmax = TMath::Max(dfmax,TMath::Abs(rsum1-rsum2));
00367   }
00368 
00369   // Get Kolmogorov probability
00370   Double_t z = 0;
00371   if (afunc1)      z = dfmax*TMath::Sqrt(esum2);
00372   else if (afunc2) z = dfmax*TMath::Sqrt(esum1);
00373   else             z = dfmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
00374 
00375   // This numerical error condition should never occur:
00376   if (TMath::Abs(rsum1-1) > 0.002)
00377     std::cout << " Comp2RefKolmogorov WARNING: Numerical problems with histogram "
00378               << h->GetName() << std::endl;
00379   if (TMath::Abs(rsum2-1) > 0.002)
00380     std::cout << " Comp2RefKolmogorov WARNING: Numerical problems with histogram "
00381               << ref_->GetName() << std::endl;
00382 
00383   return TMath::KolmogorovProb(z);
00384 }


Member Data Documentation

const Double_t Comp2RefKolmogorov::difprec = 1e-5 [static, protected]

Definition at line 279 of file QTest.h.

Referenced by runTest().

TH1* Comp2RefKolmogorov::h [protected]

Definition at line 274 of file QTest.h.

Referenced by runTest().

Int_t Comp2RefKolmogorov::ncx1 [protected]

# of bins for test & reference histograms

Definition at line 278 of file QTest.h.

Referenced by runTest().

Int_t Comp2RefKolmogorov::ncx2 [protected]

Definition at line 278 of file QTest.h.

Referenced by runTest().

TH1* Comp2RefKolmogorov::ref_ [protected]

Definition at line 275 of file QTest.h.

Referenced by runTest().


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