= Fit()
f f
Fit Fit: fit with 0 parameters
This class define generic methods
Fit (name='fit', h=None, fit_range=None, npx:int=1000, invert:bool=False, par_names=None)
general class for fitting histograms
Type | Default | Details | |
---|---|---|---|
name | str | fit | Name of the fitting function |
h | NoneType | None | histogram to fit |
fit_range | NoneType | None | list or tuple of fit range borders |
npx | int | 1000 | Number of points used to draw the fit function |
invert | bool | False | |
par_names | NoneType | None | List of parameter names of the fitting function |
Fit.init_fit ()
returns root TF1 fit function
Place holder functions, will be overwritten in the child classes
Fit.find_fit_range ()
placeholder to be overwritten in child classes, here is simply returns [0, 1000]
Fit.get_par_names ()
placeholder to be overwritten in child classes, here is simply returns []
functions that set parameter name, limits, start values, as well as clears previous fit functions
Fit.set_par_names ()
Sets fit function parameter names by passing a list of parameter names to the TF1.SetParNames() method
Fit.set_par_limits ()
placeholder to be overwritten in child classes
Fit.set_start_values ()
placeholder to be overwritten in child classes
Fit.set_parameters (*pars)
Sets fit function parameters by passing a parameter list to the TF1.SetParameters() method
Fit.clear_old ()
deletes the previous fit function
functions that access internal state of the fit class such as parameters and the results of the fit
Fit.get_parameter (i:int)
returns the value and the error of a parameter
Type | Details | |
---|---|---|
i | int | index of the parameter to get |
Fit.get_parameters ()
returns a list of parameter values
Fit.from_hist (h)
When Fit (TH1:Fit) is invoked, the fitted function is added to the list of function associated with this histogram. Given an histogram h, one can retrieve an associated function
Details | |
---|---|
h | histogram |
Fit.get_chi2 ()
returns chi2 of the fit divided by the number of degrees of freedom
Fit.formula ()
return the formula of the fit function
Fit.print_parameters ()
prints parameters names and values
Fit.fit (n:int=1, draw=True, minuit=True, fl=0, fh=0)
The method performs the fit and optionally draws fit function overlayed on the histogram
Type | Default | Details | |
---|---|---|---|
n | int | 1 | number of iterations |
draw | bool | True | Overlay the fitting function on histogram |
minuit | bool | True | Use Minuit2 and Migrad for minimization |
fl | int | 0 | lower fitting range |
fh | int | 0 | upper fitting range |
Fit.draw (*args, **kwargs)
plots the fit functions
make_fit (h, f, xmin=0, xmax=1, start_values=None, par_names=None, name=None, npx=1000)
factory method for making NewFit classes that are inherit from the Fit
class
Type | Default | Details | |
---|---|---|---|
h | histogram to fit | ||
f | fitting function | ||
xmin | int | 0 | lower fitting range |
xmax | int | 1 | upper fitting range |
start_values | NoneType | None | list initial values |
par_names | NoneType | None | list of parameter names |
name | NoneType | None | name of the fitting function |
npx | int | 1000 | number of points used to draw the fitting function |
PoissonI (h=None, fit_range=None, npx:int=1000, p0:float=None, p1:float=None)
general class for fitting histograms
Type | Default | Details | |
---|---|---|---|
h | NoneType | None | histogram to fit |
fit_range | NoneType | None | list with the low and high values of the fitting range |
npx | int | 1000 | number of points to use when drawing the fitting function |
p0 | float | None | initial value for constant parameter |
p1 | float | None | initial value for lambda parameter |
Expo (h=None, xmin=None, xmax=None, npx=100)
general class for fitting histograms
gauss (x, scale, mean_, sigma, off=0)
Gauss (h=None, fit_range=None, npx=100, fl=3, fh=3, thresh=0.01, **fkw)
general class for fitting histograms
Landau (h=None, fit_range=None, npx=100)
general class for fitting histograms
Type | Default | Details | |
---|---|---|---|
h | NoneType | None | histogram to fit |
fit_range | NoneType | None | |
npx | int | 100 |
Erf (h=None, fit_range=None, pars=None, npx=100)
general class for fitting histograms
crystalball (x, pars, inv=False)
Crystalball (h=None, fit_range=None, inv=False, npx=1000)
general class for fitting histograms
erfland (x, pars)
retruns error function merged with Landau
# from ROOT import TCanvas, TFormula, TF1
# from ROOT import gROOT, gObjectTable
# %jsroot on
# c = TCanvas( 'c', 'Example with Formula', 200, 10, 700, 500 )
# fun1 = TF1( 'fun1', erfland, 0, 10, 8)
# c0, mpv, sigma, c1, xoff, w, yoff = 1, 7, 2, 1, 3, 2, 0
# fun1.SetParameters(c0, mpv, sigma, c1, xoff, w, yoff)
# fun1 = TF1( 'fun1', 'abs(sin(x)/x)', 0, 10 )
# c.SetGridx()
# c.SetGridy()
# fun1.Draw()
# c.Update()
ErfLand (h=None, fit_range=None, npx=1000)
general class for fitting histograms
Langau (h=None, nconv:int=100, fit_range=None, npx:int=1000)
general class for fitting histograms
Type | Default | Details | |
---|---|---|---|
h | NoneType | None | histogram to fit |
nconv | int | 100 | number of convolutions within the range |
fit_range | NoneType | None | fitting range |
npx | int | 1000 | number of points to draw the function |
NLandau (h=None, fit_range=None, npx:int=100, n:int=3)
general class for fitting histograms
Type | Default | Details | |
---|---|---|---|
h | NoneType | None | histogram to fit |
fit_range | NoneType | None | fitting range |
npx | int | 100 | number of points to draw the fitting function |
n | int | 3 | number of Landaus |
langau (x:float, pars, nconv:int, nsigma:int=5)
Convoluted Landau and Gaussian Fitting Function (using ROOT’s Landau and Gauss functions)
Fit parameters: par[0]=Width (scale) parameter of Landau density par[1]=Most Probable (MP, location) parameter of Landau density par[2]=Total area (integral -inf to inf, normalization constant) par[3]=Width (sigma) of convoluted Gaussian function
In the Landau distribution (represented by the CERNLIB approximation), the maximum is located at x=-0.22278298 with the location parameter=0. This shift is corrected within this function, so that the actual maximum is identical to the MP parameter.
The code is literally converted to python from the original C at https://root.cern.ch/root/html404/examples/langaus.C.html
Type | Default | Details | |
---|---|---|---|
x | float | independent variable | |
pars | list of langau fit parameters | ||
nconv | int | number of convolutions | |
nsigma | int | 5 | number of sigmas, extent of the convolution intergral |
langaupro (params, maxx, FWHM)
Seaches for the location (x value) at the maximum of the Landau-Gaussian convolute and its full width at half-maximum.
The search is probably not very efficient, but it’s a first try.
The code is literally converted to python from the original C at https://root.cern.ch/root/html404/examples/langaus.C.html
main ()