Fit from fit panel not displayed on canvas

Hello,

in my application, I am plotting histograms into a TRootEmbeddedCanvas in a GUI. After the plotting, I can can open the really groovy Fit Panel, and perform, say, a gauss fit of the histogram. The fit is performed and the parameters look okay, but the fit function is not displayed on the canvas (even with SAME drawing option selected). Unfortunately I am unable to reproduce the problem in a smaller demo application… I apply the same style settings etc. in the demo application but there the fit is always drawn.

Does anyone have an idea what I could be doing wrong, or where the problem might occur? Any diagnostic I could apply to the canvas or the histogram to find out what’s going on? I am at a loss here, but would really like to use this great feature of ROOT!

Thanks very much for any help!

Thomas

We have the same problem in our application. Are you using the latest version of ROOT?
In our case, we notice that the fit functions get plotted using an older version. With the latest ROOT we can use the fancy fitting GUI, get the proper parameters but the function does not get drawn in the canvas. I would think it could be a bug of the Fitting panel?
Cristian

I am using 5.22/00.

My coworker has ROOT 5.22/00 on his computer (the problematic version)

I have ROOT 5.19/04, and FitPanel works like a charm.
Cristian

Hello,

can you please post a script reproducing the problem ? Otherwise there is little we can do.
Are you sure the fit ended fine and the parameters are right ?

Best regards

Lorenzo

Well, as I said, I failed to reproduce it in a simple demo application. Sending my real application would be a bit too much (and it depends on other libraries which I would have to send along…).

The fit result looks perfectly reasonable, but the curve is not displayed. What you might do is suggest some commands (list of functions in gROOT, properties of the canvas that may be involved etc.) that I could run and the output of which would perhaps help us understand the problem (I simply don’t know enough about the inner workings of this fitting tool to debug it further).

Thanks,

Thomas

Hello,

can you please then post a ROOT file with the object you are fitting and the code just defining the fit function ? I would need to know also the options are you using for fitting,

If you have time, could you also try with the latest version, 5.23.04, or the trunk ?

Thank you

Lorenzo

Yeeha, I discovered a way to deliver the problem to you: when I print my plot to a “.cxx” macro from within my GUI, then the resulting macro exhibits the same problem. See attached macro “test.cxx”.

To see the problem, run test.cxx, then right-click on the histogram, select Fit Panel; on that panel choose “Predef-1D” and “gaus” and click on Fit: the fit is clearly done, but the fit function is not displayed anywhere.

The cxx file was generated with ROOT 5.22, but I checked with 5.23.04 that the fit function is not displayed. Thus I strongly suspect the problem is fully present in the latest version.

Thanks for looking into this!

Thomas

PS: while producing this macro I also realized that the macro generator ignores some style options - I filed this as a bug report (http://savannah.cern.ch/bugs/?51139)
test.cxx (6.18 KB)

I think I found the reason for the failure: whenever a histogram is plotted with the “hist” drawing option, the fit function will not be plotted. For instance:

{

  TH1D *h1 = new TH1D("h1","h1",100,-10,10);
  h1->FillRandom("gaus",10000);

  TCanvas *c1 = new TCanvas("c1");
  h1->Draw("hist"); // "hist" option causes failure of fit function plotting

}

…and fitting with the Fit Panel results in not drawing of the fit function. In my application, also the “l” and “c” options have this problem, but that is not reproducible with the simple macro above. I hope fixing the problem for the “hist” case will solve the problem for all cases.

Thanks again for looking into this.

Thomas

Hi Thomas,

Please take a look at the description of the “HIST” drawing option there: http://root.cern.ch/root/html/THistPainter.html#HP01a
And especially this part:

Cheers, Bertrand.

[quote=“bellenot”]…Please take a look at the description of the “HIST” drawing option there: http://root.cern.ch/root/html/THistPainter.html#HP01a
And especially this part:

[quote]The “HIST” option can also be used to plot only the histogram and not the associated function(s). [/quote].[/quote] :blush: Forgive my “French”. It says, “can also be used”. How can one translate it to “can not be used to draw the associated function” ?

When there is a fit function associated to an histogram, by default the function is plotted. If you do not want to plot the function you can use the HIST option. So the HIST option has two usages: plot the histogram with error as a normal histogram and “also” prevent the associated function plotting.

Hello Bertrand,

thank you for pointing this out. It looks like the source of my problem. However, I am not sure I agree with this logic: when I do Draw(“hist”) from within the GUI, then indeed I only want the histogram plotted and not any other stuff along. But when I then, after the histogram has been plotted, decide to pop up the Fit Panel, I clearly have changed my mind and want to see this fit function. I think the “hist” option should only take effect for the one drawing operation (it is called a “drawing option”) and should not spoil the histogram forever… You may want to consider such a change unless there are really good reasons for this logic.

By the way, drawing with “hist” was not my only problem. In my GUI, I systematically have a gPad->RedrawAxis(); after each plotting to avoid histogram fill colors hiding the axes when superimposing histograms (see root.cern.ch/root/roottalk/roottalk02/0424.html). It seems like the RedrawAxis() command triggers a Draw(“sameaxis”), where the “axis” has the same effect as the “hist” option. Again I think it would be good if this had only an effect on the drawing, not on subsequent operations on the histogram.

Is there a solution to this problem? I really need the RedrawAxis() to have the axis visible, but I would also like to see the fit executed from the fit panel… Is there a way to “cure” the histogram again from its “hist”/“axis” condition?

Thanks,

Thomas

That’s what the “HIST” option does… it does not “spoil the histogram forever”…

Yes it does see: root.cern.ch/root/html/src/TPad.cxx.html#E2wo0D

No it does not see the definition of the AXIS option in THistPainter doc.

[quote]
where the “axis” has the same effect as the “hist” option

No it does not see the definition of the AXIS option in THistPainter doc.[/quote]

Well, yes, in the sense that they both prevent the drawing of the fit function. So is there any way to draw the fit function once the histogram has been drawn with either the “hist” or the “axis” option??

Hello,

I have enabled in the fitpanel (trunk revision) the drawing of the fit function always when the option “SAME” is set in the fit panel drawing options.
This works in your example macro, when the histogram was drawn with the
"HIST" and “SAMEAXIS” options.

Best Regards

Lorenzo

AXIS it the option to draw the AXIS only … it does not prevent the function drawing … it is a completely different issue. I think Lorenzo did a change in the fit panel.

{

  TH1D *h1 = new TH1D("h1","h1",100,-10,10);
  h1->FillRandom("gaus",10000);

  TCanvas *c1 = new TCanvas("c1");
  h1->Draw(""); 
  gPad->RedrawAxis();

}

…and the fit function is not drawn. Isn’t that due to the “axis” drawing option?

Thanks to Lorenzo for implementing the change in the Fit Panel!

Thomas

Why do you want to have a function with the macro you sent ? there is no function … so it is normal it is not drawn …

What I mean is that when you run the macro, then right-click on the histogram, select Fit Panel, choose “gaus” among the predef-1d functions, then press the Fit button, the fit is performed but not displayed (see earlier posts in the thread…). I really think it is due to the “sameaxis” drawing triggered by RedrawAxis()…