(i.e., trouble w/ weight of events in RooFit binned fit)

Hi All,

I encountered something in RooFit that I do not know how to handle. What I would like to do is a bit more complex than the example I am going to report here, but what is blocking me is the same thing (so, I am interested in understanding where I am doing something wrong, rather than in a work around for the example I am posting).

In the example, I want to do a simple linear fit to a set of points which comes from a ratio of two plots (it is not an efficiency, it is spectra_1/spectra_2). The errors in the bins comes from TH1F::SetDefaultSumw2(kTRUE) when dividing the two original plots. The root file that contains the histo is in attach (test_INPUT.root).
Due to the nature of that data, the fit is binned.

In attach there is also a macro (test.C) that in my mind should make the fit. The fit is performed, and as far as I can see from the output, it succeed (status=OK, error matrix is accurate).
However, the result I get for the fit parameter are not correct. Or better, I see that they correspond to a fit in which all points get an equal weight. I checked with “plain” ROOT (not RooFit) and actually it is like that. ROOT makes the proper (at least w.r.t. what I want to do) fit and only if I set weight=1 for all bins then ROOT reproduce what RooFit returns.

I put RooFit::SumW2Error(kTRUE) in the fitTo option and I tried several possibility (chi2FitTo, or chi2Var and then minimize it), but no one gives me the correct result.

I think I need an hand to understand what I am missing…

What you want to do is a simple polynomial fit, and I don’t understand why you want to do in RooFit. If you insist doing this, you should first use the right function to fit in RooFit, you need to build a function not normalized then you need to do a chi2 fit (a Poisson likelihood fit does not make sense).
Then, when comparing with ROOT you need to use the same range.

You can try to do this in RooFit, but you need quite some lines of code, and I am sure you will get at the end the same result. In ROOT you do all this with only one line

what I have posted is a simplified example. What I need to do is indeed a fit using two polinomials (one in denominator, one in the numerator) of the logarithm of x. In addition, I have several of this fit to do, in which I have A/B, C/A, D/C, so I need to do a simultaneous fit of all of them to get the parameters for each of the polinomials. So, I cannot do that with plain ROOT.

I wanted to start wiht something really simple to understand better the machinery of RooFit, hence the example, which compares with a known object such as the fit in ROOT.

I tried already what you suggest (for example, the same range for the fit, does not matter at the end. The Chi2 fit, I tried it and I left commented that lines in the macro, but the answer is still different from what I get from root).

So, can you point me what I should do to exactly reproduce the output from plain ROOT, in RooFit?

You can early do all the simultaneous fit also in ROOT, you just need to build a combined data by using the BinData class or by implementing the chi2 function. Since these are all simple least square fits, you don’t need to worry about normalizing the functions.

If you really want to do in RooFit, you need to use the RooChi2Var, but you need to built it using a not-normalized pdf (I think you can do using a RooAbsReal). Or you can probably use an extended pdf, otherwise you will not be able to fit the constant term of your polynomials.

I tried the extended option too (also with RooChi2Var).
Both using:
RooPolynomial linPdf(“linPdf”, “linear”, x, RooArgList(a));
RooExtendPdf lin(“lin”,“lin”,linPdf,n);

Or fitting using directly the RooGenericPdf. I also tried to import the histogram in RooDataHist using
RooFit::Import(*hRatio,kFALSE), as it is a ratio.

But, I do not get a result which is equivalent to ROOT one.

Sorry to be pedantic, but now, after many trials I am bit lost and it would be really great if someone can give me the instruction on how to make the simple linear fit in RooFit.

The first one should work, but the meaning of the parameters will be different with respect to ROOT or a standard polynomial. RooPolynomial is defined as a f(x) = a * x + 1 and it is normalized by the integral in the range of x.

You can maybe try to make a RooChi2Var using RooPolyVar.