Fitting Histograms and plotting the result
Click to retrieve the Python script of the example.
After having setup correctly your environment, you can run the example typing :
python -i fitHisto.py
- The Python module AidaProxy is imported. This module loads
the dictionary for the PI classes, making them available in the Python
environment in the global namespace.
- One histogram is filled with a random distribution composed by
two gaussian, a narrow one representing a signal and a wide one, representing
- The histogram is fitted, using the AIDA fit interface. First a single
gaussian fit is performed. The sequence of fitting is the following:
- A Gaussian function is created, using the keyword "G"
- The function parameters are set to reasonable values
- The fitter is created, using the default Chi2 method
- The fit is performed passing the histogram and the function as
- The FitResult object is returned from the fit, containing the
resulting parameter values, errors and chi2
- A double gaussian fit is performed, after having created a new function
- A Maximum binned likelihood fit is performed using the same double
gaussian function. The fit method is changed using the setFitMethod("PoissonML")
of the Fitter interface.
- The histogram is viewed in a ROOT canvas together with the three fitted functions. In red the Gaussian resulting from the first Chi2 fit, in green the double gaussian resulting from the Chi2 fit and in blue the double Gaussian resulting from the Maximum Likelihood fit.
To plot in ROOT the module rootPlotter2.py is used. There the histograms and functions of AIDA are converted in ROOT objects. The dictionary to the ROOT classes using PyLCGDict (SealRootDict) is used .
- The histogram and the fitted functions are also plotted in HippoDraw.