Reduced chi square test for 2 histogram compared to graph result

I want to perform a reduced chi-square test for 4 degrees of freedom system for two histograms compared to graph result. I have no idea regarding this even tried to look roofit and other posted questions. The minimal code would work for me.

Thanks

My histogram (histogram->h16) and graph root(z.root) files are:
Histo16_1.root (47.4 KB) Histo16_2.root (47.5 KB) Z.root (8.1 KB)

ROOT Version: 6.14/06
Platform: Ubuntu
_Compiler:


Perhaps @moneta can give a suggestion?

Hi,

I have not understood exactly which test would you like to do? Test the compatibility of two histograms ? Please explain with more details

Lorenzo

As much i studied from a research article an author named it reduced chi square test in which the author compared multiple simulated results with the experimental results using root. Iā€™m trying the same, deviations of two simulated results(histogram h16) compared to the experimental (z.root) results. I guess it would help you to understand.
Thanks

Can you help if you know how to do that for a particular histogram from root file ?
Thanks

1 Like

Hi,
You can do a chi2 test between two histograms, using the TH1::Chi2Test function, see
https://root.cern.ch/doc/master/classTH1.html#a6c281eebc0c0a848e7a0d620425090a5

The function can return p-value, chi2 value and ndf. Reduced chi2 is just chi2/ndf.
Am example is the tutorial tutorials/math/chi2test.C, see
https://root.cern.ch/doc/master/chi2test_8C.html

Lorenzo

Thanks, but as I mentioned my both root files contain 20 histograms out of which I want to compare the 16th histogram. So, how should I mention the 16th histogram?
For example for drawing 16th histogram from the root files on the same canvas I used

TFile *f1 = TFile::Open("1st.root");
   TH1D* h1 = (TH1D*)f1->Get("h16");
   h1->Draw("hist same");

You do the same, get the histograms from the file and then compare:

TFile *f1 = TFile::Open("1st.root");
   TH1D* h1 = (TH1D*)f1->Get("h16");
TFile *f2 = TFile::Open("2nd.root");
    TH1D* h2 = (TH1D*)f2->Get("h16");

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

It works, thanks. I got the message but no graphical outcome or results.

Info in TH1D::Chi2TestX: There is a bin in h1 with less than 10 effective events.ph

Info in TH1D::Chi2TestX: There is a bin in h2 with less than 10 effective events.

Chi2 = 0.000000, Prob = 1, NDF = 9, igood = 3
root [1]

Hi,
The routine to compute the Chi2 test does not due any graphics. See the tutorial example on how to show some information (e.g. residuals).

I see, however, that you compare histograms that are identical (chi2 value = 0.0)

Lorenzo

Thank you. :slight_smile: