1 #ifndef __JCOMPAREHISTOGRAMS__JTESTKOLMOGOROV_T__ 
    2 #define __JCOMPAREHISTOGRAMS__JTESTKOLMOGOROV_T__ 
   14 namespace JCOMPAREHISTOGRAMS {
 
   48       int n1 = h1 -> GetNbinsX();
 
   49       int n2 = h2 -> GetNbinsX();
 
   52         ERROR(
"Histograms with different bining. The objects: " << h1 -> GetName() << 
" can not be compared." << endl);
 
   54       TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
 
   60       double s1 = 1./h1->Integral();
 
   61       double s2 = 1./h2->Integral();
 
   63       double ew1, ew2, w1 = 0, w2 = 0;
 
   65       for (
int bin = 1; bin <= n1; ++bin){
 
   66         ew1 = h1->GetBinError(bin);
 
   67         ew2 = h2->GetBinError(bin);
 
   72       double esum1 = 0, esum2 = 0;
 
   81       if (afunc2 && afunc1) {
 
   82         ERROR(
"Errors are zero for both histograms\n");
 
   85       double c1 = 0, c2 = 0;
 
   88       for (
int bin=1 ; bin<=n1 ; ++bin){
 
   89         c1 += s1*h1->GetBinContent(bin);
 
   90         c2 += s2*h2->GetBinContent(bin);
 
   91         double d = TMath::Abs(
c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
   92         double p = TMath::KolmogorovProb(d);
 
   93         h3->SetBinContent(bin,p);
 
   94         dmax = TMath::Max(dmax,TMath::Abs(
c1-c2));
 
  100         z = dmax*TMath::Sqrt(esum2);
 
  102         z = dmax*TMath::Sqrt(esum1);
 
  104         z = dmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
  106       double pValue = TMath::KolmogorovProb(z);
 
  110       (pValue < threshold ? passed = 
false : passed = 
true);
 
  112       JResultTitle title(testName, parameterName, passed , pValue);
 
  114       h3->SetTitle(title.
getTitle().c_str());
 
  119                      parameterName, pValue, threshold, h3, passed);
 
  152       if(slice == 
'x' || slice == 
'X'){
 
  154         int nSlices1 = h1->GetNbinsX();
 
  155         int nSlices2 = h2->GetNbinsX();
 
  157         TH1* h3 = h1->ProjectionX(h1->GetName()==h2->GetName() ?
 
  161         if(nSlices1 != nSlices2)
 
  162           ERROR(
"Histograms with different binning. The objects: " << h1->GetName() << 
" and " << h2->GetName() << 
" can not be compared." << endl);
 
  164         for (
int i=1 ; i<=nSlices1 ; ++i){
 
  168           TH1D* s1 = h1->ProjectionY (sliceName.c_str(),i,i);
 
  169           TH1D* s2 = h2->ProjectionY (sliceName.c_str(),i,i);
 
  171           double p = s1 -> KolmogorovTest (s2);
 
  175           (p < threshold ? passed = 
false : passed = 
true);
 
  177           if (!passed) nFailures++;
 
  179           h3->SetBinContent(i,p);
 
  185         (nFailures/nSlices1 > failuresThreshold ? passed = 
false : passed = 
true);
 
  187         JResultTitle title(testName, parameterName, passed , nFailures);
 
  189         h3->SetTitle(title.
getTitle().c_str());
 
  194                           parameterName, nFailures, failuresThreshold, h3, passed);
 
  196       }
else if (slice == 
'y' || slice == 
'Y'){
 
  198         int nSlices1 = h1->GetNbinsY();
 
  199         int nSlices2 = h2->GetNbinsY();
 
  201         TH1* h3 = h1->ProjectionY(h1->GetName()==h2->GetName() ?
 
  205         if(nSlices1 != nSlices2)
 
  206           ERROR(
"Histograms with different binning. The objects: " << h1->GetName() << 
" can not be compared." << endl);
 
  208         for (
int i=1 ; i<=nSlices1 ; ++i){
 
  212           TH1D* s1 = h1->ProjectionX (sliceName.c_str(),i,i);
 
  213           TH1D* s2 = h2->ProjectionX (sliceName.c_str(),i,i);
 
  215           double p = s1 -> KolmogorovTest (s2);
 
  219           (p < threshold ? passed = 
false : passed = 
true);
 
  221           if (!passed) nFailures++;
 
  223           h3->SetBinContent(i,p);
 
  228         (nFailures/nSlices1 > failuresThreshold ? passed = 
false : passed = 
true);
 
  230         JResultTitle title(testName, parameterName, passed , nFailures);
 
  232         h3->SetTitle(title.
getTitle().c_str());
 
  237                          parameterName, nFailures, failuresThreshold, h3, passed);
 
  265       int n1x = h1 -> GetNbinsX();
 
  266       int n2x = h2 -> GetNbinsX();
 
  267       int n1y = h1 -> GetNbinsY();
 
  268       int n2y = h2 -> GetNbinsY();
 
  270       if(n1x != n2x || n1y != n2y)
 
  271         ERROR(
"Histograms with different bining. The objects: " << h1 -> GetName() << 
" can not be compared." << endl);
 
  273       if(h1->Integral()==0 || h2->Integral()==0)
 
  274         ERROR(
"Empty histogram: " << h1 -> GetName() << 
" can not be compared." << endl);
 
  276       double s1 = 1./h1->Integral();
 
  277       double s2 = 1./h2->Integral();
 
  279       TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
 
  286       double ew1, ew2, w1 = 0, w2 = 0;
 
  288       for (
int i = 1; i <= n1x; ++i){
 
  289         for (
int j = 1; 
j <= n1y; ++
j){
 
  290           ew1 = h1->GetBinError(i,
j);
 
  291           ew2 = h2->GetBinError(i,
j);
 
  297       double esum1 = 0, esum2 = 0;
 
  306       if (afunc2 && afunc1) {
 
  307         ERROR(
"Errors are zero for both histograms\n");
 
  310       double c1 = 0, c2 = 0;
 
  313       for (
int i=1 ; i<=n1x ; ++i){
 
  314         for (
int j=1 ; 
j<=n1y ; ++
j){
 
  315           c1 += s1*h1->GetBinContent(i,
j);
 
  316           c2 += s2*h2->GetBinContent(i,
j);
 
  317           double d = TMath::Abs(
c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
  319           dmax1 = TMath::Max(dmax1,TMath::Abs(
c1-c2));
 
  326       for (
int j=1 ; 
j<=n1y ; ++
j){
 
  327         for (
int i=1 ; i<=n1x ; ++i){
 
  328           c1 += s1*h1->GetBinContent(i,
j);
 
  329           c2 += s2*h2->GetBinContent(i,
j);
 
  330           double d = TMath::Abs(
c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
  332           dmax1 = TMath::Max(dmax2,TMath::Abs(
c1-c2));
 
  336       double dmax = 0.5*(dmax1+dmax2);
 
  340         z = dmax*TMath::Sqrt(esum2);
 
  342         z = dmax*TMath::Sqrt(esum1);
 
  344         z = dmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
  346       double pValue = TMath::KolmogorovProb(z);
 
  348       for (
int i=1 ; i<=n1x ; ++i){
 
  349         for (
int j=1 ; 
j<=n1y ; ++
j){
 
  350           h3->SetBinContent(i,
j,TMath::KolmogorovProb(0.5 * h3->GetBinContent(i,
j)));
 
  356       (pValue < threshold ? passed = 
false : passed = 
true);
 
  358       JResultTitle title(testName, parameterName, passed , pValue);
 
  360       h3->SetTitle(title.
getTitle().c_str());
 
  365                      parameterName, pValue, threshold, h3, passed);
 
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Implementation of the different Kolmogorov-related tests. 
#define MAKE_CSTRING(A)
Make C-string. 
then for HISTOGRAM in h0 h1
Auxiliary class to handle file name, ROOT directory and object name. 
JTestResult JKolmogorovTest(TH1 *h1, TH1 *h2, double threshold, std::string testName, std::string parameterName)
Kolmogorov test for 1D histograms. 
#define MAKE_STRING(A)
Make string. 
JTestResult JKolmogorovTestSlice(TH2 *h1, TH2 *h2, double threshold, double failuresThreshold, std::string testName, std::string parameterName, char slice)
Kolmogorov test for sliced 2D histograms. 
JTestKolmogorov_t()
Default constructor. 
TCanvas * c1
Global variables to handle mouse events. 
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
std::string to_string(const T &value)
Convert value to string. 
Structure containing the result of the test. 
JTestResult JKolmogorovTest2D(TH2 *h1, TH2 *h2, double threshold, std::string testName, std::string parameterName)
Kolmogorov test for 2D histograms. 
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.