KolmogorovTest and Chi2Test in Root 4.00/08

I’ve been having some trouble getting the KolmogorovTest and Chi2Test functions to work properly. When I use them to compare two 1-D histograms, each normalized to unit area, as follows:

Double_t EtAKSTest = atop4z_met_0->KolmogorovTest(zewk0d_met_0,“ND”);
Double_t EtAChiTest = atop4z_met_0->Chi2Test(zewk0d_met_0,“UOP”,1);

which should as I understand it give the probability that the two histograms could come from the same distribution, the result is always exactly one. However, working out the value of the maximum Kolmogorov distance and the Chi2 gives sensible results. What might I be doing wrong?

Also, I can make EtAKSTest return the maximum Kolmogorov distance instead by adding the option “M”, but there is apparently no similar option to put the chi-squared value from Chi2Test into a variable (though it can be sent to stdout). Is there a way to get the chi-squared into a variable?

Thanks,
Dan

I need a concrete example.
Could you try with a newer version. We made changes in 4.02

Rene

I’m afraid 4.00/08 is the newest version currently available on my system.

Without emailing you the root files and scripts, I’m not sure how to make the example more concrete, but I’ll try to put the lines I included in context:

[i]{
TFile f1(“zewk0d-2j.root”);
TFile f2(“atop4z.root”);

f1.cd();
f1.cd(“Ana”);
f1.cd(“zewk0dAna”);
f1.cd(“Hist”);
TH1F zewk0d_met_0 = (TH1F) met_0->Clone();
zewk0d_met_0->Sumw2();
zewk0d_met_0->Scale(1.0/zewk0d_met_0->Integral());
zewk0d_met_0->SetXTitle(“Missing Et”);
zewk0d_met_0->SetTitle("");
zewk0d_met_0->SetStats(0);

f2.cd();
f2.cd(“Ana”);
f2.cd(“atop4zAna”);
f2.cd(“Hist”);
TH1F atop4z_met_0 = (TH1F) met_0->Clone();
atop4z_met_0->Sumw2();
atop4z_met_0->Scale(1.0/atop4z_met_0->Integral());
atop4z_met_0->SetXTitle(“Missing Et”);
atop4z_met_0->SetTitle("");
atop4z_met_0->SetStats(0);

cMEt = new TCanvas(“MEt”,“MEt”);
cMEt->Divide(1,1);
cMEt->cd(1);
zewk0d_met_0->SetLineColor(2);
zewk0d_met_0->Draw(“P”);
atop4z_met_0->SetLineColor(4);
atop4z_met_0->Draw(“SAMEHIST”);
Double_t EtAKSTest = atop4z_met_0->KolmogorovTest(zewk0d_met_0,“ND”);
Double_t EtAChiTest = atop4z_met_0->Chi2Test(zewk0d_met_0,“UOP”,1);
// The “1” is because since the two distributions are normalized to the
// same unit area, there’s a constraint on the fit

char fit[100];
sprintf(fit,“KS TEST = %lf Chi2 TEST=%lf”,EtAKSTest,EtAChiTest);
std::cout << fit << endl;
}[/i]

gives the result

[i]Kolmo Prob h1 = met_0, sum1=1
Kolmo Prob h2 = met_0, sum2=1
Kolmo Probabil = 1, Max Dist = 0.163579
Kolmo Probabil = 1.000000 for shape alone, =1.000000 for normalisation alone
the value of chi2 = 4.249898

the number of degrees of freedom = 25

KS TEST = 1.000000 Chi2 TEST=0.999189[/i]

…OK, so the Chi-squared probability isn’t always coming out as exactly one, but when comparing other pairs of histograms, it’s always 0.999xxx or 1.000000. The KS probability is always 1.000000.

The two histograms I’m comparing look like this:

Thanks,
Dan

You forgot to send the two files

Rene

OK, here are the root files.
atop4z.root (28.5 KB)
zewk0d-2j.root (40 KB)

Running with root version 4.03/02 and adding the option “x”, ie
Double_t EtAKSTest = atop4z_met_0->KolmogorovTest(zewk0d_met_0,“NDX”);
I get the following result:
Kolmo Prob h1 = met_0, sum1=1
Kolmo Prob h2 = met_0, sum2=1
Kolmo Probabil = 0, Max Dist = 0.163579
Kolmo Probabil = 0.290542 for shape alone, =0.000000 for normalisation alone
Kolmo Probabil = 0.108000 with 1000 pseudo-experiments
the value of chi2 = 4.249898

the number of degrees of freedom = 25

KS TEST = 0.108000 Chi2 TEST=0.999189

Rene

Adding the option “x” does seem to be helpful – here’s my 4.00/02 output:

Kolmo Prob h1 = met_0, sum1=1
Kolmo Prob h2 = met_0, sum2=1
Kolmo Probabil = 1, Max Dist = 0.163579
Kolmo Probabil = 1.000000 for shape alone, =1.000000 for normalisation alone
Kolmo Probabil = 0.103000 with 1000 pseudo-experiments
the value of chi2 = 4.249898

the number of degrees of freedom = 25

KS TEST = 0.103000 Chi2 TEST=0.999189

Will try and use a newer version, and keep using the “X” option. Thanks again!