# Roofit: fit a polynomial

Hi

I am having a hard time to fit just a polynomial with roofit. Well… the fit runs, but the fir results are very poor (see the attachment).

I am fitting the region from 6 to 9, so it must be easily described with a polynomial (actually it works quite well when I fo histo->Fit(“pol2”) in that range.

But in roofit the result with a second order polynomial is what you can see. I tried many things, polynomial, Chebyshev, Likelihood and RooChi2Var… no way to get something reasonable.

This is my code:

RooRealVar coef_x1(“coef_x1”, “coef_x0”, 1.); coef_x1.setConstant(kFALSE);
RooRealVar coef_x2(“coef_x2”, “coef_x2”, 1.); coef_x2.setConstant(kFALSE);
RooRealVar coef_x3(“coef_x3”, “coef_x3”, 1.); coef_x3.setConstant(kFALSE);
//RooPolynomial bkgdpoly(“bkgdpoly”,“1 + c1 x + c2 x2 + c3 x3”, x ,RooArgList(coef_x,coef_x2, coef_x3));
RooChebychev bkgdpoly(“bkgdpoly”,“1+c1 x + c2 (x2-1)”, x ,RooArgList(coef_x1, coef_x2));

bkgdpoly.fitTo(inv_mass_data, RooFit::Range(“BackgroundLowMass”));

Is there a trick?

Hi,

I think you are not setting correct initial values for the polynomial coefficient. Unfortunately in RooFit the coefficient are not trivial to guess, since the polynomial are self normalised.
In ROOT since a linear fit is done when fitting with a polynomial, there is no need to set initial coefficient values.

Cheers

Lorenzo

Dear Lorenzo

thanks for the feedback. A couple of things:

1. I’ll try to figure out reasonable initial values… but I thought to avoid bias in the final results, previous knowledge of the parameters was to be avoided. Anyway, I understand that have something reasonable may not bias the results and will help the convergence.

2. If I understood correctly the documentation I read, the roofit polynomials are as follows:
RooPolynomial: y = 1 + c1 x + c2 x^2 + c3 x^3 +… (ci means coefficient for i-ith order)
RooChebychev: y = 1 + c1 x + c2 (x^2-1) + c3 (4x^3 - 3x) + …
so there is no equivalent to the root’s “pol0”. So if the coefficient of the independent term has to be different from 1, that will affect the others. Is that right?

I mean: y = c0/c0 + c1/c0 x + c2/c0 x^2 +…

Cheers
Salva

Hi,

1. There is no bias when setting initial values, if this is helpful in reading the global minimum of your negative log-likelihood or least square function.

2. I can;t remember the exact definition, in particular the Chebyshev polynomials are defined internally in the [-1,1] range, so there is a variable transformation which is then reflected in the coefficient definition.
The best way to see the exact definition is to look at the code in the RooChebyshev::evaluate function

root.cern.ch/doc/v606/RooChebyc … tml#l00117

and for RooPolynomial

root.cern.ch/doc/v606/RooPolyno … tml#l00117

Cheers

Lorenzo

Hi

ok, I understand now, and I have a better idea of what’s going on.

A last thing: I am trying to extract the upper and lower values of a range… but I found very hard to read the new pages as for example root.cern.ch/doc/master/classRooAbsBinning.html. There is an overwhelming info and I see how to set a min and a max, but what is the function to retrievem lowBound and highBound?

Cheers
Salva

Hi,

For getting the lower/upper bound of a range you can call the function RooAbsReal::getMin/Max(rangeName)
on the variable object

Best

Lorenzo