THStack and GetBinContent()

Hello,
Is there a straightforward way of getting a bin content of a THStack, similar to TH1::GetBinContent()?
Viesturs

The very last histogram in the list returned by the THStack::GetStack method will be the “sum of all”, and then you can simply use TH1::GetBinContent on it.

So, I should call Last() on the TObjArray* returned by THStack::GetStack?

Calling a GetBinContent() on THStack would be a very useful function. In HEP one often needs to draw ratio graphs between MonteCarlo THStack and data TH1. Making a sum histogram in parallel seems very redundant that becomes even more confusing when dealing with a huge number of histograms,

I suggest that the Root class reference
root.cern.ch/root/html532/THSta … k:GetStack
elaborate on what is returned by THStack::GetStack.

Thank you,
Viesturs

Hi,

I think returning an histogram pointer with the last histogram from the array would be enough. One should avoid to re-implement all the TH1 functions in the THStack.

Lorenzo

Get a pointer to the last histogram in the stack (containing the sum)

TH1 *last = (TH1*)mystack->GetStack()->Last(); last->GetBinContent(binnumber);
Rene