I make another last attempt to send an email for this problem, since apparently I am not able to send it, could it be due to attachments?
I have a strange problem with RooFit. I have to fit a histogram (data driven) where a Breit-Wigner peak arises over a background, and I wanted to use a fit function made of a BW + a n-th order polynomial (where n goes between 2 and 4). To do this I used the macro in the attached tar-ball.
The figures in the same tar-ball show what I obtain using the “chi2FitTo” and “fitTo” methods. Apparently, the output function has nothing to do with the data, and I don’t understand why, since if I fit the same histogram with the TH1D::Fit function, it seems to work correctly.
Can anyone help me in understanding where the problem is?
The attachment contains all the elements: file with histograms, macro and two examples. files.tar.gz (46.4 KB) files.tar.gz (46.4 KB)
I can see multiple problem in the fit you sent us:
the distribution is background dominated but the fit limits are 0-1000 for background and 0-10000 for signal (you should swaped the 2)
the data distribution have empty bins below x=1 then the poly fit gives negative probability which is a problem for RooFit (in my test I fit only the range for x>1)
the signal bump seems to be better described by a Gaussian (or a Voigt)
For these reasons (must importantly the 1st one) the fit does not converge very well. Taking the 3 points above into account gave me a reasonable fit result.
I can see multiple problem in the fit you sent us:
the distribution is background dominated but the fit limits are 0-1000 for background and 0-10000 for signal (you should swaped the 2)
the data distribution have empty bins below x=1 then the poly fit gives negative probability which is a problem for RooFit (in my test I fit only the range for x>1)
the signal bump seems to be better described by a Gaussian (or a Voigt)
[/quote]
Hello,
about point 1: this raises a general point which is critical. For the “nsig” and “nbkg”, and for all constants in the poly, I would not set any interval. Is there a way to do this?
about point 3: it is a resonance, so I am pretty sure that it must be described by a BW. On the other hand, from a cross-check done on a similar monte-carlo distribution (with “similar” I intend that the shapes of histograms are comparable) I looked at the MC and found that the resolution (which should become the gamma in the Voigt) should be very small.
Point 1 is quite important, since I would be sure that parameters are extremely free, but apparently I am forced to set an interval.
there are various constructors for RooRealVar and you can avoid specifying a sub-range by just omitting these two parameters. see the RooFit manual or the class documentation online. Finally you specify variable.setConstant(false) to fit for it too.