Fitting a THStack object


What I want is in principle:
Take two histograms - add them to a THStack object - draw it - and fit it (so, practically the sum of these two histograms).
I noticed there is no THStack::Fit method like for TH1 - is there some other way I am missing (of course I can think of cumbersome work-around, but being able to directly fit would really be convenient!)?


there is presently no a THStack::Fit. We are planning eventually to implement it for the next cycle of development release (5.17.XX) in the next month.

Would you like to fit the two histogram independently (have different functions for them but a global chi2) or fit their sum.
In the latter case you can just add now the two histogram using TH1::Add and then fit the sum.

Best Regards


Hi Lorenzo,

Thanks for your help. I want to fit the sum of the two histograms, but I still want to display them stacked.
It’s great that this functionality is going to be added. For now I will follow your suggestion - have a third temporary histogram which is the sum of the other two, fit it, retrieve the fit parameters, and then draw the function into the canvas of the THStack object, or something similar.


Dear Lorenzo,
is THStack::Fit planned for 5.22?

Many thanks,

Yes, we have already introduced in ROOT 5.21 new classes for fitting histograms and it will be rather easy to to add now a THStack::Fit.