How to find range for TF1

let say my fried do the fitting on a data on some selected range (unknown to me) by something like this:

fit_func.SetRange(30., 40.) ; hist.Fit(fit_func, "REM")
hist.Fit(fit_func, "EM", "", 30., 40.)
he/she then save the function or the original data in the file.

when i open and retrive the function, how do i get back the range for the function ? (i suppose using TF1::GetRange(), but it seems does not work.)

ROOT Version: 6.26
Platform: Not Provided
Compiler: Not Provided

Dear @NgJunKai ,

What do you mean exactly? What is the error/unexpected behaviour you see?


i am expecting the same data was fitted with the copies of the functions (at different ranges). But what i see is that, the range of those functions are the same. Maybe my friend has made some mistakes …

If you don’t see any errors, maybe there is indeed something wrong in how the functions were created/fitted/saved. As a side note, always take a look at the docs: TF1::GetRange should be used as follows:

TF1 f1;
f1.SetRange(11, 22);
double xmin;
double xmax;
f1.GetRange(xmin, xmax);
std::cout << xmin << " " << xmax << std::endl;

Try to understand better the situation of your application and double check that the ranges are correct even before storing the functions to disk. Let me know if you still see problems afterwards.


TF1 *func = hist->GetFunction("fit_func_name"); func->Print("V");
Double_t xmin, xmax;
xmin = func->GetXmin(); xmax = func->GetXmax(); // either this ...
func->GetRange(xmin, xmax); // ... or that

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