1 #ifndef __JTESTKOLMOGOROV_T__
2 #define __JTESTKOLMOGOROV_T__
42 int n1 = h1 -> GetNbinsX();
43 int n2 = h2 -> GetNbinsX();
46 ERROR(
"Histograms with different bining. The objects: " << h1 -> GetName() <<
" can not be compared." << endl);
48 TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
54 double s1 = 1./h1->Integral();
55 double s2 = 1./h2->Integral();
57 double ew1, ew2, w1 = 0, w2 = 0;
59 for (
int bin = 1; bin <= n1; ++bin){
60 ew1 = h1->GetBinError(bin);
61 ew2 = h2->GetBinError(bin);
66 double esum1 = 0, esum2 = 0;
75 if (afunc2 && afunc1) {
76 ERROR(
"Errors are zero for both histograms\n");
79 double c1 = 0, c2 = 0;
82 for (
int bin=1 ; bin<=n1 ; ++bin){
83 c1 += s1*h1->GetBinContent(bin);
84 c2 += s2*h2->GetBinContent(bin);
85 double d = TMath::Abs(
c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
86 double p = TMath::KolmogorovProb(d);
87 h3->SetBinContent(bin,p);
88 dmax = TMath::Max(dmax,TMath::Abs(
c1-c2));
94 z = dmax*TMath::Sqrt(esum2);
96 z = dmax*TMath::Sqrt(esum1);
98 z = dmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
100 double pValue = TMath::KolmogorovProb(z);
104 (pValue < threshold ? passed =
false : passed =
true);
106 JResultTitle title(testName, parameterName, passed , pValue);
108 h3->SetTitle(title.
getTitle().c_str());
111 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
112 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
113 h1->GetDirectory()->GetFile()->GetName(),
114 h2->GetDirectory()->GetFile()->GetName(),
115 parameterName, pValue, threshold, h3, passed);
148 if(slice ==
'x' || slice ==
'X'){
150 int nSlices1 = h1->GetNbinsX();
151 int nSlices2 = h2->GetNbinsX();
153 TH1* h3 = h1->ProjectionX(h1->GetName()==h2->GetName() ?
157 if(nSlices1 != nSlices2)
158 ERROR(
"Histograms with different binning. The objects: " << h1->GetName() <<
" and " << h2->GetName() <<
" can not be compared." << endl);
160 for (
int i=1 ; i<=nSlices1 ; ++i){
164 TH1D* s1 = h1->ProjectionY (sliceName.c_str(),i,i);
165 TH1D* s2 = h2->ProjectionY (sliceName.c_str(),i,i);
167 double p = s1 -> KolmogorovTest (s2);
171 (p < threshold ? passed =
false : passed =
true);
173 if (!passed) nFailures++;
175 h3->SetBinContent(i,p);
181 (nFailures/nSlices1 > failuresThreshold ? passed =
false : passed =
true);
183 JResultTitle title(testName, parameterName, passed , nFailures);
185 h3->SetTitle(title.
getTitle().c_str());
188 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
189 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
190 h1->GetDirectory()->GetFile()->GetName(),
191 h2->GetDirectory()->GetFile()->GetName(),
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(h1->GetName()==h2->GetName() ?
203 if(nSlices1 != nSlices2)
204 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 double p = s1 -> KolmogorovTest (s2);
217 (p < threshold ? passed =
false : passed =
true);
219 if (!passed) nFailures++;
221 h3->SetBinContent(i,p);
226 (nFailures/nSlices1 > failuresThreshold ? passed =
false : passed =
true);
228 JResultTitle title(testName, parameterName, passed , nFailures);
230 h3->SetTitle(title.
getTitle().c_str());
233 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
234 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
235 h1->GetDirectory()->GetFile()->GetName(),
236 h2->GetDirectory()->GetFile()->GetName(),
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());
363 string (h1->GetDirectory()->GetPath()).append(h1->GetName()),
364 string (h2->GetDirectory()->GetPath()).append(h2->GetName()),
365 h1->GetDirectory()->GetFile()->GetName(),
366 h2->GetDirectory()->GetFile()->GetName(),
367 parameterName, pValue, threshold, h3, passed);
Implementation of the different Kolmogorov-related tests.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
#define MAKE_CSTRING(A)
Make C-string.
then for HISTOGRAM in h0 h1
JTestResult JKolmogorovTestSlice(TH2 *h1, TH2 *h2, double threshold, double failuresThreshold, std::string testName, std::string parameterName, char slice)
Kolmogorov test for sliced 2D histograms.
Structure containing the result of the test.
#define MAKE_STRING(A)
Make string.
JTestResult JKolmogorovTest(TH1 *h1, TH1 *h2, double threshold, std::string testName, std::string parameterName)
Kolmogorov test for 1D histograms.
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
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.
JTestResult JKolmogorovTest2D(TH2 *h1, TH2 *h2, double threshold, std::string testName, std::string parameterName)
Kolmogorov test for 2D histograms.
JTestKolmogorov_t()
Default constructor.