Hello!
I was trying to do a linear fit but it isn’t working very well. When I try to fit it with errors my function’s parameters assumes values that don’t make sense!

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.

So, try something like: f->SetParameters(-3000., 300.);

See also the “initial pre-fit” + “final fit” trick in: