Home | News | Documentation | Download

Can i apply the chi2test over a specific region of my histogram?

Dear experts,

I am just want to know if there is a way to apply the chi2test in a specific region of my histogram. I am comparing mc-mc histograms, and there is a region that I want to keep outside of my chi2test. There is a way to do it or do I need to fill the histograms just in the area of interest?

Best Regards,

I think @moneta can help you.

1 Like

You should be able to do this by calling before histogram->GetXaxis()->SetRange(bin1, bin2)


1 Like

That worked, thanks! Just another question, i wanted to get the res array, but I created an array here in pyroot and did this:

h1.Chi2Test(h2, “CHI2/NDF WW”, res)

But I got an error saying it could not convert argument 3. How than can I obtaing this array?

You need to provide an array (e.g. a numpy array) to the Chi2Test function.
Here is an example code:

import ROOT
import numpy as np

f1 = ROOT.TF1('f1','gaus')
f1.SetParameters(1, 5, 2.5)

h1 = ROOT.TH1D('h1','h1',100,0,10)

h2 = ROOT.TH1D('h2','h2',100,0,10)

res = np.zeros(100)

h1.Chi2Test(h2,'P UU',res)


h3 = ROOT.TH1D('h3','rediduals',100,0,10)
for i in range(1,101) :
    h3.SetBinError(i,1)  # residuals are normalized 

1 Like