Divide THStack histogram

Hi,

How can I divide a sum of all hists of THStack by some other histogram?
It seems that neither mystack -> GetStack() nor mystack -> GetHistogram() returns a histogram of sum, so I couldn’t use it for dividing.

THStack is a collection of histogram, not a sum of histograms. You can sum histogram. No need to use a THStack for that

Well, yes, I can. Although I think it would be nice (and natural) to have a Sum function from THStack object.
Thanks anyway.

Yes it should not be difficult to implement.
If you implement it we can consider to put it in the TStack Class.

Some thing like: TH1 *stack_sum = st->Sum();

Hi here is function that seems to work for me:

TH1 *THStack::Sum() { //cout<<"doing sum "<<endl; TList * mylist = (TList*)this->GetHists(); TIter next(mylist); TH1 *hh = (TH1*) mylist -> First() ->Clone(); hh -> SetLineColor(kBlack); hh -> SetFillStyle(0); TObject *obj; while ((obj = next())) { // cout<<obj->GetName()<<endl; //skip first object since it's used by creating the histogram if(obj == mylist->First()) continue; hh -> Add((TH1*)obj); } //cout<<"end of sum"<<endl; return hh; }