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", "[2]*TMath::Gaus(x,[0],[1])");
    f1->SetParameters(1,1,1);
    h1->FillRandom("f1");
    h1->Draw()
    

The histogram created should look similar to the one in the next picture

Histogram created for the example.

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:

      Layout of the FitPanel
    

Now the the fitpanel is open, we need to take the following steps to make a proper fitting of the data:

  1. 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
  2. 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.

  3. 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.

    The parameters dialog to set the function parameters

  4. 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.
  5. 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.
  6. Click the "Fit" button. The results should look like this:

    Results of the fit

AttachmentSize
fitresult.gif10.58 KB
histogram.gif9.52 KB
fitpanel.gif13.35 KB
ParametersDialog.gif10.79 KB