Home | News | Documentation | Download

TH1F LabelsOption(">","X"); NOT working sometimes


I am trying to draw a tree containing string entries in descending order of the bin contents. This sometimes works using the LabelsOption(">",“X”), and sometimes it does not. I am attaching a script and a root file showing how this work only sometimes (for one of the trees in this case).

@couet I would be very grateful for any suggestion on how to draw both trees (not just one) in descending order of the bin content. Without the LabelsOption(">",“X”), both trees are drawn randomly, with random (not ordered) been contents.

Thank you,


Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.10/08
_Platform: macosx64
Compiler: Not Provided

two_trees_descending.root (64.7 KB) sort_root_descending.C (830 Bytes)

@couet The “minimal reproducer”:

  TFile *f1 = TFile::Open("two_trees_descending.root");
  TTree *tree_vertex; f1->GetObject("tree_vertex", tree_vertex);
  TH1 *htemp2 = (TH1*)(gPad->GetPrimitive("htemp")->Clone("htemp2"));
  htemp2->Print("all"); // original "unsorted" fSumw contents
  htemp2->LabelsOption(">", "X");
  htemp2->Print("all"); // "sorted" fSumw contents
  htemp2->Print("all"); // still "sorted" fSumw contents
  gPad->Update(); // abracadabra (definitely black magic)
  // original "unsorted" fSumw contents RESTORED but labels are "sorted"

This bug exists in ROOT 6 and 5.

Actually, in ROOT 5, additionally, the fSumw contents entries printed by the first 3 “Print” statements above (1 x “unsorted” and 2 x “sorted”) have doubled values (“Total sum” = 2 * “Entries”) so maybe the problem originates in TTree Draw (the very last “Print” statement shows values for which “Total sum” = “Entries”).

If I add “htemp2->BufferEmpty(1);” right after the “Clone” and before the first “Print” then the histogram bins remain “sorted” also after “gPad->Update();”, but in ROOT 5 the fSumw contents entries remain doubled.

The “tree_vertex” tree has 612 entries so a very brutal fix, which works in ROOT 6 and 5, is to add right in the beginning e.g.: TH1::SetDefaultBufferSize(500); // must be < 612

Thanks. I will look.

This PR fixes this issue: https://github.com/root-project/root/pull/5442


Thank you for looking into this and fixing the issue.

Best regards,