# What is the difference between unweighted histogram and weighted hist?

Hi, I have a question about unweighted histogram and weighted histogram when I try to do Chi2Test() to 2 histograms. I have 2 histograms h1 h2. Simply create them and then fill fill fill. They both have 100 bins. Then I call

``````h1->Chi2Test(h2,"UU P");
``````

Chi2 = 108.022299, Prob = 0.152939, NDF = 94, igood = 3
But when I change option “UU” to “UW”, result simply change to:
Chi2 = 112.474049, Prob = 0.0941032, NDF = 94, igood = 3
Then option “WW” has result:
Chi2 = 262.364015, Prob = 7.85054e-18, NDF = 94, igood = 3
which is very different. I look up to the Chi2Test() function but don’t get much answer. Also I don’t understand NDF=94 which I thought should be 99. Can anyone give me a hint? Thanks.

HI,

If the histogram represents simple counts, i.e. how many times the variable (e.g. x) is in a corresponding bin, then the histogram is unweighted.
In this case you fill the histogram calling TH1::Fill passing only the variable value (e.g. x) or using a weight value=1.
If you fill the histogram with weights different than one then the histogram is weighted.

In your case if the histogram is unweighted you should use the ‘UU’ option. However using as weighted or unweighted the result should be the same.
If you can send me the two histograms, I can maybe understand better your problem.

Lorenzo

Hi,
Thank you for your reply. You’ve answered most of my problem about unweighted and weighted hists. My histograms’ creation are just what I said in the description only I saved them in a root file and then read them somewhere else due to some reason. Could you answer my other question about NDF?

The number of degrees of freedom (NDF) can be smaller of the number of bins because the empty bins are excluded in the chi2 calculation.

1 Like

Thanks a lot! That explains it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.