Function not printed with the right parameters


ROOT Version: 6.12.04
Platform: Ubuntu 17.04
Compiler: gcc 7.2.0


Hi,
In attachment the macro that is causing me a little trouble. fitmass_root_talk.C (5.9 KB)
I am trying to fit different histograms in a cycle as you can see in the macro and all goes fine. However I have a problem with the graphic output of one of them.
I am quite sure is only a graphic problem beause the fit went well.

The total function that is fitting the distribution is a sum of 3 components. My purpose is to plot on the same pad the histo, the total fit function and the single components (2 gaussians for the picks and one power law for the continuum).

The parameters of the 3 functions are taken, after fitting, from the fit function (as you can see in the macro), so they should be aligned well with the red line (that is the fit function).
I checked with output to video that, after setting the parameters of the 3 functions as I told before, they are exactly the same as the parameters of the fit function.

In this canvas you can see there is the histo on the right that has the 3 functions as they were shifted upwards, while the bottom one is what I mean for “good” output. (the one without fit is ok, I didn’t fit that)

Of 10 histograms in total, only the one I am showing above is “wrong”.
All the other 9 are good as the bottom one.

I can’t explain this behavior, what do you suggest?
It is not a big fault, but I would like to know if I am missing something.

Davide

I guess we need the input file to play with (the one which produces the “wrong” output).

All your histograms are “TH1F”, not “TH1D” (you should fix it in your macro).

Well, I think the problem is that you “reuse” functions (“f1”, “f2” and “f3”) in all pads. In the end, right before the whole canvas is saved, the parameters’ settings from the last drawn pad (i.e. from the last fit) are “propagated” to the previously drawn pads (so, “f1”, “f2” and “f3” in all pads are redrawn with the same parameters). This happens for all canvases, of course, but it is best visible for the “wrong” one.
Try with:

		f1->DrawCopy("same");
		f2->DrawCopy("same");
		f3->DrawCopy("same");

Yes, using DrawCopy works! Thank you very much
have a nice day

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.