Bug: SetRange and SetRangeUser affects TF1

TAxis::SetRange(…) and TAxis::SetRangeUser(…) are supposed to just set the viewing range, as according to the documentation in ROOT: TAxis Class Reference
.

However, for h1 as a TH1F,

h1->GetXaxis()->SetRangeUser(1000,10000);
TF1 * fit = new TF1("fit","[0]*x",500,15000);
h1->Fit(fit,"","",500,15000);

Will not fit between the range 500,15000, but instead will fit between the range 1000,10000 (with no errors or warnings), even though from the documentation it is quite clear this should not happen.

It looks like the fitting range is taken from SetRange and not from the Fit command ? I guess @moneta can tell you more about this behaviour.

Hi @couet ,

The fitting range is taken from the fit command if the range given to the fit command is smaller than SetRange, but otherwise the maximum range of the fit allowed is restricted to the range given by SetRange/SetRangeUser, rather than the full range of the histogram

Ah ok, that makes sense in that case, because when you do SetRange on a histogram, it is just like this histogram is a new one restricted to the new range. I am not surprised that the fit command is not able to extend its fitting range outside the range applied on the histogram. @moneta can confirm.

A warning should probably be shown if one tries to fit outside this range then (or ideally just fixed so that the viewing range does not affect the fitting range), or at a minimum the documentation should mention it (since as is the documentation says it only affects the viewing range).

I let @moneta decide what’s the best to do.

I agree that we need to explain this behaviour better in the documentation. I will update it

Cheers

Lorenzo

2 Likes

Thanks very much

PR updating the doc: [skip-ci] complete fitting range doc by couet · Pull Request #10355 · root-project/root · GitHub
Thanks for you imput.

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