I am trying to fit an histogram which is supposed to follow a Binomial distribution.
I know the number of trials (i.e. the n parameter of the Binomial distribution) and I have a very good initial value for the probability (parameter p of the Binomial distribution).
In particular I have: n = 1000, p = 0.994 (Notice that gaussian approximation is not good in this case).
I am using pyROOT
I have tried with the following code:
import ROOT
c2 = ROOT.TCanvas("c2","c2",600,400)
values = [995.0, 998.0, 997.0, 987.0, 997.0, 993.0, 994.0, 992.0, 993.0, 992.0, 994.0, 986.0, 993.0, 991.0, 995.0, 995.0, 999.0, 990.0, 995.0, 993.0, 993.0, 998.0, 995.0, 992.0, 998.0, 992.0, 994.0, 988.0, 994.0, 993.0, 994.0, 993.0, 990.0, 988.0, 998.0, 991.0, 994.0]
histo = ROOT.TH1F("Binomial","Binomial",1001-986,986-0.5,1000+0.5)
for val in values:
histo.Fill(val)
histo.Scale(1./histo.GetEntries())
c2.cd()
histo.Draw()
f1 = ROOT.TF1("Bin","TMath::Binomial(1000, x)*TMath::Power([0], x)*TMath::Power(1-[0], 1000-x)",0,1000)
f1.SetParameter(0,0.994)
histo.Fit("Bin")
but, even if the fit converges and the f1.GetProb() is good, the output plotted function looks not ok: it has a series of peaks over each histogram bin.
I can’t figure out how to solve it.
Thank you in advance.
_ROOT Version: 6.18/00
_Platform: Ubuntu 20.10
python, pyROOT