Using Anderson-Darling and Kolmogorov-Smirnov goodness of fit tests 1 sample test is performed comparing data with a log-normal distribution and a 2 sample test is done comparing two gaussian data sets.
#include <cassert>
double landau(double x) {
}
void goftest() {
TF1 * f1 =
new TF1(
"logNormal",
"ROOT::Math::lognormal_pdf(x,[0],[1])",0,500);
TH1D* h1smp =
new TH1D(
"h1smp",
"LogNormal distribution histogram", 100, 0, 500);
for (
UInt_t i = 0; i < nEvents1; ++i) {
}
Double_t A2_1 = goftest_1-> AndersonDarlingTest(
"t");
assert(A2_1 == A2_2);
Double_t pvalueAD_1 = goftest_1-> AndersonDarlingTest();
assert(pvalueAD_1 == pvalueAD_2);
delete goftest_1;
Double_t Dn_1 = goftest_1-> KolmogorovSmirnovTest(
"t");
assert(Dn_1 == Dn_2);
Double_t pvalueKS_1 = goftest_1-> KolmogorovSmirnovTest();
assert(pvalueKS_1 == pvalueKS_2);
#ifdef TEST_ERROR_MESSAGE
assert(A2 == pvalueKS);
#endif
sprintf(str1, "p-value for A-D 1-smp test: %f", pvalueAD_1);
sprintf(str2, "p-value for K-S 1-smp test: %f", pvalueKS_1);
TH1D* h2smps_1 =
new TH1D(
"h2smps_1",
"Gaussian distribution histograms", 100, 0, 500);
TH1D* h2smps_2 =
new TH1D(
"h2smps_2",
"Gaussian distribution histograms", 100, 0, 500);
for (
UInt_t i = 0; i < nEvents1; ++i) {
}
h2smps_1->
Scale(1. / nEvents1,
"width");
for (
UInt_t i = 0; i < nEvents2; ++i) {
}
h2smps_2->
Scale(1. / nEvents2,
"width");
assert(A2_1 == A2_2);
pvalueAD_1 = goftest_2-> AndersonDarling2SamplesTest();
assert(pvalueAD_1 == pvalueAD_2);
Dn_1 = goftest_2-> KolmogorovSmirnov2SamplesTest("t");
assert(Dn_1 == Dn_2);
pvalueKS_1 = goftest_2-> KolmogorovSmirnov2SamplesTest();
assert(pvalueKS_1 == pvalueKS_2);
#ifdef TEST_ERROR_MESSAGE
assert(A2 == pvalueKS);
#endif
sprintf(str1, "p-value for A-D 2-smps test: %f", pvalueAD_1);
sprintf(str2, "p-value for K-S 2-smps test: %f", pvalueKS_1);
pt2-> AddText(str2);
for (
UInt_t i = 0; i < nEvents3; ++i) {
}
pvalueAD_1 = goftest_3a-> AndersonDarlingTest();
pvalueAD_2 = (*goftest_3b)();
std::cout << " \n\nTEST with LANDAU distribution:\t";
if (
TMath::Abs(pvalueAD_1 - pvalueAD_2) > 1.E-1 * pvalueAD_2) {
std::cout << "FAILED " << std::endl;
Error(
"goftest",
"Error in comparing testing using Landau and Landau CDF");
std::cerr << " pvalues are " << pvalueAD_1 << " " << pvalueAD_2 << std::endl;
}
else
std::cout << "OK ( pvalues = " << pvalueAD_2 << " )" << std::endl;
}