27 double landau(
double x) {
28 return ROOT::Math::landau_pdf(x);
37 UInt_t nEvents1 = 1000;
40 TF1 * f1 =
new TF1(
"logNormal",
"ROOT::Math::lognormal_pdf(x,[0],[1])",0,500);
42 f1->SetParameters(4.0,1.0);
46 Double_t* sample1 =
new Double_t[nEvents1];
48 TH1D* h1smp =
new TH1D(
"h1smp",
"LogNormal distribution histogram", 100, 0, 500);
49 h1smp->SetStats(kFALSE);
51 for (UInt_t i = 0; i < nEvents1; ++i) {
53 Double_t data = gRandom->Gaus(4,1);
54 data = TMath::Exp(data);
59 h1smp->Scale( ROOT::Math::lognormal_cdf(500.,4.,1) / nEvents1,
"width");
61 TCanvas* c =
new TCanvas(
"c",
"1-Sample and 2-Samples GoF Tests");
63 TPad * pad = (TPad *)c->cd(1);
65 h1smp->SetLineColor(kBlue);
68 f1->SetLineColor(kRed);
75 ROOT::Math::GoFTest* goftest_1 =
new ROOT::Math::GoFTest(nEvents1, sample1, ROOT::Math::GoFTest::kLogNormal);
79 Double_t A2_1 = goftest_1-> AndersonDarlingTest(
"t");
80 Double_t A2_2 = (*goftest_1)(ROOT::Math::GoFTest::kAD,
"t");
84 Double_t pvalueAD_1 = goftest_1-> AndersonDarlingTest();
85 Double_t pvalueAD_2 = (*goftest_1)();
86 assert(pvalueAD_1 == pvalueAD_2);
90 goftest_1 =
new ROOT::Math::GoFTest(nEvents1, sample1 );
91 goftest_1->SetDistribution(ROOT::Math::GoFTest::kLogNormal);
96 Double_t Dn_1 = goftest_1-> KolmogorovSmirnovTest(
"t");
97 Double_t Dn_2 = (*goftest_1)(ROOT::Math::GoFTest::kKS,
"t");
101 Double_t pvalueKS_1 = goftest_1-> KolmogorovSmirnovTest();
102 Double_t pvalueKS_2 = (*goftest_1)(ROOT::Math::GoFTest::kKS);
103 assert(pvalueKS_1 == pvalueKS_2);
106 #ifdef TEST_ERROR_MESSAGE
107 Double_t A2 = (*goftest_1)(ROOT::Math::GoFTest::kAD2s,
"t");
108 Double_t pvalueKS = (*goftest_1)(ROOT::Math::GoFTest::kKS2s);
109 assert(A2 == pvalueKS);
112 TPaveText* pt1 =
new TPaveText(0.58, 0.6, 0.88, 0.80,
"brNDC");
114 sprintf(str1,
"p-value for A-D 1-smp test: %f", pvalueAD_1);
116 pt1->SetFillColor(18);
117 pt1->SetTextFont(20);
118 pt1->SetTextColor(4);
120 sprintf(str2,
"p-value for K-S 1-smp test: %f", pvalueKS_1);
127 UInt_t nEvents2 = 2000;
129 Double_t* sample2 =
new Double_t[nEvents2];
131 TH1D* h2smps_1 =
new TH1D(
"h2smps_1",
"Gaussian distribution histograms", 100, 0, 500);
132 h2smps_1->SetStats(kFALSE);
134 TH1D* h2smps_2 =
new TH1D(
"h2smps_2",
"Gaussian distribution histograms", 100, 0, 500);
135 h2smps_2->SetStats(kFALSE);
138 for (UInt_t i = 0; i < nEvents1; ++i) {
139 Double_t data = r.Gaus(300, 50);
141 h2smps_1->Fill(data);
143 h2smps_1->Scale(1. / nEvents1,
"width");
146 h2smps_1->SetLineColor(kBlue);
148 for (UInt_t i = 0; i < nEvents2; ++i) {
149 Double_t data = r.Gaus(300, 50);
151 h2smps_2->Fill(data);
153 h2smps_2->Scale(1. / nEvents2,
"width");
154 h2smps_2->Draw(
"SAME");
155 h2smps_2->SetLineColor(kRed);
160 ROOT::Math::GoFTest* goftest_2 =
new ROOT::Math::GoFTest(nEvents1, sample1, nEvents2, sample2);
165 A2_1 = goftest_2->AndersonDarling2SamplesTest(
"t");
166 A2_2 = (*goftest_2)(ROOT::Math::GoFTest::kAD2s,
"t");
167 assert(A2_1 == A2_2);
170 pvalueAD_1 = goftest_2-> AndersonDarling2SamplesTest();
171 pvalueAD_2 = (*goftest_2)(ROOT::Math::GoFTest::kAD2s);
172 assert(pvalueAD_1 == pvalueAD_2);
177 Dn_1 = goftest_2-> KolmogorovSmirnov2SamplesTest(
"t");
178 Dn_2 = (*goftest_2)(ROOT::Math::GoFTest::kKS2s,
"t");
179 assert(Dn_1 == Dn_2);
182 pvalueKS_1 = goftest_2-> KolmogorovSmirnov2SamplesTest();
183 pvalueKS_2 = (*goftest_2)(ROOT::Math::GoFTest::kKS2s);
184 assert(pvalueKS_1 == pvalueKS_2);
186 #ifdef TEST_ERROR_MESSAGE
188 A2 = (*goftest_2)(ROOT::Math::GoFTest::kAD,
"t");
189 pvalueKS = (*goftest_2)(ROOT::Math::GoFTest::kKS);
190 assert(A2 == pvalueKS);
193 TPaveText* pt2 =
new TPaveText(0.13, 0.6, 0.43, 0.8,
"brNDC");
194 sprintf(str1,
"p-value for A-D 2-smps test: %f", pvalueAD_1);
196 pt2->SetFillColor(18);
197 pt2->SetTextFont(20);
198 pt2->SetTextColor(4);
199 sprintf(str2,
"p-value for K-S 2-smps test: %f", pvalueKS_1);
206 UInt_t nEvents3 = 1000;
208 Double_t* sample3 =
new Double_t[nEvents3];
209 for (UInt_t i = 0; i < nEvents3; ++i) {
210 Double_t data = r.Landau();
220 ROOT::Math::Functor1D f(&landau);
221 double minimum = 3*TMath::MinElement(nEvents3, sample3);
222 double maximum = 3*TMath::MaxElement(nEvents3, sample3);
223 ROOT::Math::GoFTest* goftest_3a =
new ROOT::Math::GoFTest(nEvents3, sample3, f, ROOT::Math::GoFTest::kPDF, minimum,maximum);
225 ROOT::Math::Functor1D fI(&TMath::LandauI);
226 ROOT::Math::GoFTest* goftest_3b =
new ROOT::Math::GoFTest(nEvents3, sample3, fI, ROOT::Math::GoFTest::kCDF,minimum,maximum);
230 pvalueAD_1 = goftest_3a-> AndersonDarlingTest();
232 pvalueAD_2 = (*goftest_3b)();
235 std::cout <<
" \n\nTEST with LANDAU distribution:\t";
236 if (TMath::Abs(pvalueAD_1 - pvalueAD_2) > 1.E-1 * pvalueAD_2) {
237 std::cout <<
"FAILED " << std::endl;
238 Error(
"goftest",
"Error in comparing testing using Landau and Landau CDF");
239 std::cerr <<
" pvalues are " << pvalueAD_1 <<
" " << pvalueAD_2 << std::endl;
242 std::cout <<
"OK ( pvalues = " << pvalueAD_2 <<
" )" << std::endl;