Problem with KolmogorovTest

Hello everyone,

i have discovered a strange behavior of Kolmogorov test probability, maybe someone can explain it…

So, what i am doing:
i generate 2 samples with uniform distribution and fill the values into array (so i get 2 arrays of unbinned data).
Then i sort them and perform Kolmogorov test for unbinned data on these sorted arrays (TMath::KolmogorovTest (n, arr1,n,arr2,"") )
I repeat this procedure 4000 times, get 4000 values of Kolmogorov probability, and fill these values to histogram.
Since the compared samples have same (uniform) distribution, the distribution of kolmogorov probability should be flat (uniform). However, what i get you can see on attached screenshot, and this is not uniform. There are some empty bins in the histgram, and the mean value is shifted to the right.
Same picture one would see for the binned Kolmogorov test.
Could anyone explain it?

I also attach my code.
KStest.C (946 Bytes)


I think what you are seeing is expected since you are using a sample of events n which is finite. If you increase the number of data points, n, you will see that the distribution of the KS probability becomes more and more like a flat distribution between 0 and 1, as it is expected

Best Regards