root icon indicating copy to clipboard operation
root copied to clipboard

[Fit Panel] Fitting to Gaus + Pol0 in two steps is unnecessarily hard

Open ferdymercury opened this issue 1 year ago • 0 comments

Explain what you would like to see improved

My students and myself often encounter the following situation. We are trying to make a fit of a histogram to a Gaussian. This works well and ROOT finds perfectly all parameters without having to set them initially by hand.

image

 FCN=220.83 FROM MIGRAD    STATUS=CONVERGED      70 CALLS          71 TOTAL
                     EDM=6.98482e-10    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  Constant     3.92175e+02   4.99591e+00   2.81307e-02   6.15584e-06
   2  Mean         9.95290e-03   1.03175e-02   7.50080e-05   1.55399e-03
   3  Sigma        1.04566e+00   8.42889e-03   1.42471e-05   1.69822e-02

Now, we decide it would be best to fine-tune the fit by also adding a pol0 constant. Thus we click on Add radio-button, pol0. (Results in gaus(0)+pol0(3)). Then, you click on Fit, and the fit completely fails.

image

 FCN=9324.48 FROM HESSE     STATUS=FAILED         11 CALLS         179 TOTAL
                     EDM=3.13749e-15    STRATEGY= 1  ERROR MATRIX UNCERTAINTY 100.0 per cent
  EXT PARAMETER                APPROXIMATE        STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0          -2.89841e+05   4.24264e-01  -0.00000e+00   0.00000e+00
   2  p1           0.00000e+00   1.41421e+00  -0.00000e+00   0.00000e+00
   3  p2           0.00000e+00   1.41421e+00  -0.00000e+00   0.00000e+00
   4  p3           1.17552e+01   3.42858e-01   1.17552e+01   1.63372e-07

So the manual workaround is to set by hand all the initial parameters of the first fit, so that it finally converges.

Optional: share how it could be improved

After 'adding' a pol0, it would be nice that the initial values of the Gaussian parameters are not reset to zero, but are rescued from the previous fit where only the Gaussian was used.

This is the parameter window just before adding pol0:

image

And this is just after adding it, completely 'reset':

image

To Reproduce

    TCanvas *c1 = new TCanvas("c1","c1",600,600);
    TH1F *h = new TH1F("gaus","gaus", 100, -5, 5);
    h->FillRandom("gaus", 10000);
    for(int i=1;i<=100;++i) h->AddBinContent(i,5);
    h->Draw();

Open Fit Panel, Fit "gaus". Then click "Add", "pol0", click on "Fit" again.

Setup

   ------------------------------------------------------------------
  | Welcome to ROOT 6.27/01                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Apr 25 2022, 22:21:18                 |
  | From heads/master@v6-25-01-3897-gf39eb0e984                      |
  | With c++ (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0                     |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

Additional context

ferdymercury avatar Jul 21 '22 21:07 ferdymercury