In [1]:
import ROOT
Inject into the interpreter the functions.
In [2]:
%%cpp -d
//Define functions for fitting
// Quadratic background function
double background(double *x, double *par) {
return par[0] + par[1]*x[0] + par[2]*x[0]*x[0];
}
// Lorenzian Peak function
double lorentzianPeak(double *x, double *par) {
return (0.5*par[0]*par[1]/TMath::Pi()) /
TMath::Max(1.e-10,(x[0]-par[2])*(x[0]-par[2])
+ .25*par[1]*par[1]);
}
// Sum of background and peak function
double fitFunction(double *x, double *par) {
return background(x, par) + lorentzianPeak(x, &par[3]);
}
Construct the histogram containing the input data
In [3]:
# Your code here
Create the function and try to fit it without setting any parameter. Activate the interactive visualisation with %jsroot on
.
Remember that in order to embed a plot in a notebook, you'll need to create a TCanvas and draw it explicitly.
In [1]:
# Your code here
Less than optimal. Set parameters and fit again, draw histogram with error bars
In [2]:
# Your code here
Much better. Now time to beautify the plot. Construct a TF1 for the background and Lorentzian functions and draw them in the same canvas. We save the fit results and set the parameters of the functions accordingly
In [3]:
# Your code here
We can now add a legend
In [4]:
# Your code here