How can one fit a histogram in a range

_ROOT Version: 6.20/02
_Platform: MAC OS Catalina on MacBook Air
_Compiler: version 10.15.4

I have in my code:

#include “TH1.h”
#include “TF1.h”

TF1 *f1 = new TF1(“f1”,"[0]exp(-0.5((x-[1])/[2])**2)",12., 14.5);

NewInf->Fit(“f1”,r);

and get an error:
error: use of undeclared identifier ‘r’
although in the documentation it is written on https://root.cern.ch/how-use-histograms-classes
By default,TH1::Fit will fit the function on the defined histogram range. You can specify the option " r " in the second parameter to restrict the fit to the range specified in the TF1object.
BTW f1->Draw(""); works fine
BTW in the above documentation the link to A simple fitting example and Fitting histogram sub-ranges doesn’t exist.
Thanks for telling me how can one fit a function on a histogram in a range specified in the function, and if possible, give me a working example.
Elemer

NewInf->Fit("f1", "R");

Many thanks, it works fine! Hopefully the documentation will be updated soon.
Elemer

In the documentation you pointed the option "R" is between quotes.
You missed them. I do not think this documentation should be updated.

I have meant that in the documentation: " For more complete examples, see A simple fitting example and Fitting histogram sub-ranges." A simple fitting example and Fitting histogram sub-ranges are missing, although they would be very useful.
Elemer

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