Subsections

2.21 Fitting data. The HFit class

2.21.1 Fitting data using FreeHEP libraries

Look at an example in histo_fit.py. This script fills a histogram, creates factories and does a fit with a Gaussian function.

2.21.2 HFit class

One can fit data (H1D histograms or P1D data holders) using the Fit Panel based on the HFit class. One can look at the example histo_fit1.py.

>>># .. define c1 as HPLot object and h1 as a H1D histogram and fill it 
>>>a=HFit(c1,"c1",h,"h1")  # start HFit panel
After execution of HFit(c1,"c1",h,"h1") (the arguments should be adjusted to reflect the variable names for HPlot and H1D objects), a pop-up fit panel will be shown. Note that we pass not only the objects, but also the variable names for the HPlot and H1D class. One can also pass a P1D object instead of a histogram H1D. One should pass the variable names if one needs to generate JAIDA source code automatically in future.

The fit panel allows the user to set up the predefined fit functions, fit method and perform the fit. The user can also set up the initial parameters for the fit function (use the Settings button). Once the fit is acceptable, the used can generate the output fit parameters, which will be inserted directly to the jeHEP editor in form of a Jython code. The user can also automatically generate the JAIDA source code which corresponds to the fit. Once inserted, it can further be corrected using the jeHEP editor. Then HFit() statement can be removed and the user can run the generated JAIDA code manually.

One can also specify a user-defined 1D function and add it to the HFit Panel. This is an example:

>>># .. define c1 as HPLot object and h1 as a H1D histogram and fill it
>>>a=HFit(c1,"c1",h,"h1")  # start HFit panel
>>>a.addFunc("User1", "Tool tip", "a*x[0]+b","a,b") # add "User1" function
After executing this scrip, a new function User1 will be added to the fit panel.