Cesar1
November 25, 2021, 1:29pm
1
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,
Cesar.
couet
November 25, 2021, 1:36pm
2
I think @moneta can help you.
1 Like
moneta
November 25, 2021, 3:03pm
3
Hi,
You should be able to do this by calling before histogram->GetXaxis()->SetRange(bin1, bin2)
Lorenzo
1 Like
Cesar1
November 25, 2021, 4:13pm
4
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?
moneta
December 3, 2021, 10:51am
5
Hi,
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)
h1.FillRandom('f1')
h2 = ROOT.TH1D('h2','h2',100,0,10)
f1.SetParameter(1,5.4)
h2.FillRandom('f1')
res = np.zeros(100)
h1.Chi2Test(h2,'P UU',res)
print(res)
h3 = ROOT.TH1D('h3','rediduals',100,0,10)
for i in range(1,101) :
h3.SetBinContent(i,res[i-1])
h3.SetBinError(i,1) # residuals are normalized
h3.DrawClone()
1 Like