How to set the order of the histograms of histogram-stack according to the ascending order of the integrals of the individual histograms in the histogram-stack?

how to set the order of the histograms of histogram-stack according to the ascending order of the integrals of the individual histograms in the histogram-stack?

You have to add them in the order you want.

so are you telling that there is no shortcut command to set the order in the ascending order of integrals of the background?i have 4 backgrounds.To keep in ascending order i know that i can use if else condition while adding.I was seeking for some shortcut method.So if you know some command please help me out in this.

In a THStack the histograms are ordered in the order you added them in the stack. Up to you to put them is the correct order.

@couet Do you know any ROOT “collection class” with which users could define their own “compare” function and then use a class built-in “sort” method?

I not aware of a such tool in ROOT. TList has a sort method but it does not allow to define its own “compare” method. May be @pcanal or @axel know.

std::vector<TH1*> hists;
std::sort(hists.begin(), hists.end(), [](TH1* hist1, TH1* hist2) { return hist1->GetEntries() > hist2->GetEntries(); });
for (TH1* hist: hists)
  hStack.Add(hist);

should do!

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