- What's New
- Download ROOT
- Building ROOT
- v6-04 Release
- v6-02 Release
- v5-34 Release
- Older Versions
- Download Statistics
How to fit using the FitPanel
Preparing the data to be fitted
As an excersice, we will present here a simple histogram following a gaussian distribution. The code that will generate such a histogram is shown next:
TH1F *h1 = new TH1F("h1", "h1", 200, -5,5); TF1 *f1 = new TF1("f1", "*TMath::Gaus(x,,)"); f1->SetParameters(1,1,1); h1->FillRandom("f1"); h1->Draw()
The histogram created should look similar to the one in the next picture
Opening the FitPanel
There are two separate ways of showing the FitPanel in ROOT. One is right-clicking on the object to be fitted and select the FitPanel option in the popup menu. Nevertheless, sometimes the object is not directly accesible in the canvas and a second options existe. Click on the menu "Tools" and then on "Fit Panel". It will look as this:
Now the the fitpanel is open, we need to take the following steps to make a proper fitting of the data:
- Select the data set to be fitted: In the TGComboBox named "Data Set", we need to select the data to be fitted. Normally, the FitPanel will know which data we want to use, but it is important to be sure we have made the right selection. In our example, we will select TH1::h1
- Select the function that will be used for the fitting. The
FitPanel will aid the user with some set of functions already
prepared to work:
- Predefined Functions that will depend on the dimensionality of the data.
- Functions present in gDirectory. Which means that functions previosly created by the user through a macro will be present into this subset.
- Previously used functions, i.e. functions that fitted the current data previously, if the data is able to store such functions.
Apart from these set of functions, the user can always create their own functions through the TGTextEntry, either as a standalone function or as a combination of others. Here we will select "gaus" inside the subset "Predef-1D" subset.
- Set the parameters of the fit function. If the function to
be used needs some parameters to be defined, then this is the
way to go, clickin on the "Parameters..." button will show a
dialog windown that will help us to do this. In our example, we
will leave them as they are.
- Select the general options of the fitting in the tab "General". This includes the method that will be used, as well as what fit options will be used with it and the draw options. The range of the function used for the fitting can also be constrained.
- Select the minimization algorithm from the tab "Minimization". As well as the print options, i.e. how much information will the method give while running.
- Click the "Fit" button. The results should look like this: