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(
MAKE_CSTRING(h1->GetName() << 
"_VS_" <<
 
  158                                                h2->GetName() << 
"_KolmogorovTestSliceX"));
 
  160         if(nSlices1 != nSlices2) {
 
  161           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           if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) { 
continue; }    
 
  173           double p = s1 -> KolmogorovTest (s2);
 
  175           bool passed = (p < threshold ? 
false : 
true);
 
  177           if (!passed) nFailures++;
 
  179           h3->SetBinContent(
i,p);
 
  183         bool passed = (nFailures/nSlices1 > failuresThreshold ? 
false : 
true);
 
  185         JResultTitle title(testName, parameterName, passed, nFailures);
 
  187         h3->SetTitle(title.
getTitle().c_str());
 
  192                           parameterName, nFailures, failuresThreshold, h3, passed);
 
  194       } 
else if (slice == 
'y' || slice == 
'Y') {
 
  196         int nSlices1 = h1->GetNbinsY();
 
  197         int nSlices2 = h2->GetNbinsY();
 
  199         TH1* h3 = h1->ProjectionY(
MAKE_CSTRING(h1->GetName() << 
"_VS_" <<
 
  200                                                h2->GetName() << 
"_KolmogorovTestSliceY"));
 
  202         if(nSlices1 != nSlices2) {
 
  203           ERROR(
"Histograms with different binning. The objects: " << h1->GetName() << 
" can not be compared." << endl);
 
  206         for (
int i=1 ; 
i<=nSlices1 ; ++
i){
 
  210           TH1D* s1 = h1->ProjectionX (sliceName.c_str(),
i,
i);
 
  211           TH1D* s2 = h2->ProjectionX (sliceName.c_str(),
i,
i);
 
  213           if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) { 
continue; }
 
  215           double p = s1 -> KolmogorovTest (s2);
 
  217           bool passed = (p < threshold ? 
false : 
true);
 
  219           if (!passed) nFailures++;
 
  221           h3->SetBinContent(
i,p);
 
  224         bool passed = (nFailures/nSlices1 > failuresThreshold ? 
false : 
true);
 
  226         JResultTitle title(testName, parameterName, passed, nFailures);
 
  228         h3->SetTitle(title.
getTitle().c_str());
 
  233                          parameterName, nFailures, failuresThreshold, h3, passed);
 
  261       int n1x = h1 -> GetNbinsX();
 
  262       int n2x = h2 -> GetNbinsX();
 
  263       int n1y = h1 -> GetNbinsY();
 
  264       int n2y = h2 -> GetNbinsY();
 
  266       if(n1x != n2x || n1y != n2y)
 
  267         ERROR(
"Histograms with different bining. The objects: " << h1 -> GetName() << 
" can not be compared." << endl);
 
  269       if(h1->Integral()==0 || h2->Integral()==0)
 
  270         ERROR(
"Empty histogram: " << h1 -> GetName() << 
" can not be compared." << endl);
 
  272       double s1 = 1./h1->Integral();
 
  273       double s2 = 1./h2->Integral();
 
  275       TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
 
  282       double ew1, ew2, w1 = 0, w2 = 0;
 
  284       for (
int i = 1; 
i <= n1x; ++
i){
 
  285         for (
int j = 1; 
j <= n1y; ++
j){
 
  286           ew1 = h1->GetBinError(
i,
j);
 
  287           ew2 = h2->GetBinError(
i,
j);
 
  293       double esum1 = 0, esum2 = 0;
 
  302       if (afunc2 && afunc1) {
 
  303         ERROR(
"Errors are zero for both histograms\n");
 
  306       double c1 = 0, c2 = 0;
 
  309       for (
int i=1 ; 
i<=n1x ; ++
i){
 
  310         for (
int j=1 ; 
j<=n1y ; ++
j){
 
  311           c1 += s1*h1->GetBinContent(
i,
j);
 
  312           c2 += s2*h2->GetBinContent(
i,
j);
 
  313           double d = TMath::Abs(
c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
  315           dmax1 = TMath::Max(dmax1,TMath::Abs(
c1-c2));
 
  322       for (
int j=1 ; 
j<=n1y ; ++
j){
 
  323         for (
int i=1 ; 
i<=n1x ; ++
i){
 
  324           c1 += s1*h1->GetBinContent(
i,
j);
 
  325           c2 += s2*h2->GetBinContent(
i,
j);
 
  326           double d = TMath::Abs(
c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
  328           dmax1 = TMath::Max(dmax2,TMath::Abs(
c1-c2));
 
  332       double dmax = 0.5*(dmax1+dmax2);
 
  336         z = dmax*TMath::Sqrt(esum2);
 
  338         z = dmax*TMath::Sqrt(esum1);
 
  340         z = dmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
 
  342       double pValue = TMath::KolmogorovProb(z);
 
  344       for (
int i=1 ; 
i<=n1x ; ++
i){
 
  345         for (
int j=1 ; 
j<=n1y ; ++
j){
 
  346           h3->SetBinContent(
i,
j,TMath::KolmogorovProb(0.5 * h3->GetBinContent(
i,
j)));
 
  352       (pValue < threshold ? passed = 
false : passed = 
true);
 
  354       JResultTitle title(testName, parameterName, passed , pValue);
 
  356       h3->SetTitle(title.
getTitle().c_str());
 
  361                      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. 
 
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.