How to fit a straight line plot

Hi Root Experts,

I have an attached root macro in which I am attempting to fit a straight line to five points. As you can see from the attached graph, the fit is bizarrely wrong. I have boiled the macro down to nine lines so that you can reproduce the issue for yourselves.

Any suggestions are warmly appreciated.

EniolaSiPM.C (406 Bytes)

In ROOT, before you try to fit your graph or histogram, you MUST set “reasonable” initial values for ALL parameters of your function (except for some “built-in” formulas, like “gaus”, for which the standard fit procedure can automatically “guess” them), otherwise the fitting procedure may easily misbehave.

If you do not want to set “reasonable” initial values for parameters, try: SiPM_g->Fit("pol1");

BTW. Because the “y” values of your graph are very small (of the order of 1e-5), the chi^2 that you get is extremely small (of the order of 1e-10) and this may additionally fool ROOT (I guess lowering the fitter’s “tolerance” / “precision” could help and maybe @moneta could comment on it).

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