Histograms - Fitting
How to fit histograms with predefined functions?
h1->Fit("gaus");
h1->Fit("landau", "R", "", 3., 15.); //where "R" indicates to fit only in a range, given in the last two arguments
h1->Fit("landau", "R", "P", 3., 15.); // where "P" is a goption indicating to plots markers instead of histograms
How to fit with a user-defined function
In a file myfunc.C define
double
myfunc(double *x, double *par) {
double arg = 0;
if (par[2])
arg = (x[0] - par[1])/par[2];
return
par[0]*TMath::Exp(-0.5*arg*arg);
}
Load this macro and fit with this function
.L
myfunc.C
TF1 *f1 = new TF1("f1",
myfunc, -1., 1., 3); // where 3 is the number of parameters
for the function
f1->SetParameters(10.,
h1->GetMean(), h1->GetRMS());
h1->Fit("f1");
How to use the Fit Panel
Move the pointer over the histogram line (the cursor should change from cross to arrow) and click on the right mouse button. A context menu on TH1 should appear, from which you can choose FitPanel.

To restrict the fit range, carefully move the pointer onto the slider and adjust the range (watch the lines appearing on the canvas)