I am seeing an odd behavior using setRange and then passing it as argument to fitTo. A minimal working code reproducing the issue is attached here (testfitrange.cpp (2.1 KB) ). The code generates 100 events from a Gaussian PDF and creates a histogram. This histogram is then fit with the same Gaussian PDF used to create the histogram. I attach here as well the result of fitting with setRange (right) and without any range, just for reference (left) (test.pdf (19.4 KB) ). Needless to say, the fit results for the case using setRange is way off.
Am I misunderstanding something about fitting within a range? Any advice is greatly appreciated!
The RooDataHist has 25 bins from -10 to 10. The ranges you are giving don’t align with bin edges, so there could be problems deciding which bins go into the fit.
There could simply be a bug, but I don’t have the time to run your example during the conference. Could you check in the mean time that the bin edges don’t cause the problem?
The best way probably is to use an unbinned fit. In this way, it doesn’t matter if bins are populated.
Note also that sigma in your model can go negative. I advise to limits its range to something like [0.1, 10.]
A short explanation:
If a bin has zero entries, but the Gaussian distribution in this bin suggests that 0.4 events should be in that bin, it’s best to either set n to zero or shift the mean value to the left, to get the gaussian that’s touching the empty bin as close to zero as possible. If the left part of the data is ignored, there’s no bins to counter that decision.
In unbinned fits, this “this bin is empty, let’s pull the Gaussian down” doesn’t happen.