# Fitting more than cause the normalisation to be screwed up

I started to learn RooFit and I am now blocked by the following strange behaviour. Fitting a simple gauss function to a data set once works fine. But when I repeat this exercise, because want to change the fit range for example, things break down. The normalization seems to get screwed up, the fitted curve is much large than data. Trying again, increases further. How can I stop this behaviour? Fit parameters look ok.

``````mean  = ROOT.RooRealVar("mean","Mean of Gaussian",-10,10)
sigma = ROOT.RooRealVar("sigma","Width of Gaussian",3,-10,10)
gauss = ROOT.RooGaussian("gauss","gauss(x,mean,sigma)",x,mean,sigma)
fitResult = gauss.fitTo(data,ROOT.RooFit.Range(1.,5.),ROOT.RooFit.PrintLevel(1))
xframe = x.frame()
data.plotOn(xframe)
gauss.plotOn(xframe)
xframe.Draw()
fitResult = gauss.fitTo(data,ROOT.RooFit.Range(3.,7.),ROOT.RooFit.PrintLevel(1))
gauss.plotOn(xframe)
xframe.Draw()
``````

there is also an error about:
[#0] ERROR:InputArguments – RooArgSet::checkForDup: ERROR argument with name gauss_Int[mcor|fit_nll_gauss_data]_Norm[mcor] is already in this set

Hi @Tom_Ruf,

let me first scold you a little bit for posting code that doesn’t work. I had to add x and data, and now it works. That’s the code:

``````  1 import ROOT
2
3 x     = ROOT.RooRealVar("x", "x", 0, -20, 20)
4 mean  = ROOT.RooRealVar("mean","Mean of Gaussian",-10,10)
5 sigma = ROOT.RooRealVar("sigma","Width of Gaussian",3,-10,10)
6 gauss = ROOT.RooGaussian("gauss","gauss(x,mean,sigma)",x,mean,sigma)
7 data  = gauss.generate(x, 1000)
8 fitResult = gauss.fitTo(data,ROOT.RooFit.Range(1.,5.),ROOT.RooFit.PrintLevel(1))
9 xframe = x.frame()
10 data.plotOn(xframe)
11 gauss.plotOn(xframe)
12 fitResult = gauss.fitTo(data,ROOT.RooFit.Range(3.,7.),ROOT.RooFit.PrintLevel(1))
13 gauss.plotOn(xframe, ROOT.RooFit.LineColor(ROOT.kRed))
14 canv = ROOT.TCanvas()
15 xframe.Draw()
16 canv.Draw()
17 canv.SaveAs("/tmp/canv.png")
``````

What I see now is that it seems to work for me. That indicates that you see something that I fixed recently, see here:

I assume that this is the problem you are seeing:
https://sft.its.cern.ch/jira/browse/ROOT-10550

In ROOT 6.20, you might see warnings, but the normalisation should be correct. In ROOT 6.22, it should just work.
Are you using 6.20?

We are using 6.14/00. Changing to a newer version is a major enterprise, re-compilation of all experiment software depending on ROOT, with any unforeseen hickup. Maybe it is now the time to do it. I will also study the jira report. Thanks for the fast feedback.

If I remember correctly, the problem is in implicitly setting the either normalisation range or the plotting range if don’t ask for it explicitly.
You could therefore get around the bug by something like this:

``````x.setRange("rangeA", 3, 7)
[...]
gauss.plotOn(frame, ROOT.RooFit.Range("rangeA"))
``````

It could also be the normalisation range, `ROOT.RooFit.NormRange(" ...")`.

Moving to a newer version of ROOT fixed the problem. Thanks for the help. Thomas

1 Like

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