Drawing tree in same canvas: Y axis rebinning issue


I have a question about plotting 2D TTrees. I have the following inconvenience:

void sample(){

char str[16];
float value=0;
float value1=0;

TTree *tr = new TTree("test", "test");
tr->Branch("value", &value, "value/F");
tr->Branch("value1", &value1, "value1/F");




It happens that when I draw two plot request in the same histogram, the first histogram
seems to setup the binning of the y axis. When I draw the second histogram using the drawing option=“same”, if the y values are outside the Y range of the first histogram, then those Y values of the second histogram are not drawn (i.e because they are out of range).
How do people go around this problem?

In the example, I cannot see the values (entry1, 5) and (entry3, 10)

I tried setting the TAxis::SetRangeuser(ymin,ymax) but that did not work. Any ideas?

Thank you,


tree.Draw("myvar1>>hname1","","goff"); tree.Draw("myvar1>>hname2","some condition","goff"); THStach hs("hs"); hs.Add(hname1); hs.Add(hname2); hs.Draw("nostack"); for more details, see doc of TTree::Draw and class THStack as well as the THStack examples in teh tutorials.


I implemented your solution and it does what I want. However I am having another issue which I have not been able to figure out. I have attached both the source code and the data.
In my code, it happens that when one runs the script, it loads the data in both canvases. However, whenever I click on the canvas (a signal update of some sort) my canvas gets repopulated with more data. You can see that clearly on the second canvas where I have plotted only one set of points.
Could you reproduced this problem?
Any ideas what is causing it?
It has to be the THStack since I was plotting the trees in the same canvas with the “same” drawing option and it was working fine.
Thank you,
treeConcentrations.root (7.93 KB)
TCutsSetConcTree.C (2.09 KB)

I have the following question, based on the issues I reported in my last post.
Looking at the TTree documentation, it says:

[quote] By default the temporary histogram created is called “htemp”, but only in
the one dimensional Draw(“e1”) it contains the TTree’s data points. For
a two dimensional Draw, the data is filled into a TGraph which is named
"Graph". They can be retrieved by calling
TH1F htemp = (TH1F)gPad->GetPrimitive(“htemp”); // 1D
TGraph graph = (TGraph)gPad->GetPrimitive(“Graph”); // 2D

Then what this is telling me is that I am getting a TGraph object instead of a TH1 object and then I should be using TMultiGraph containers instead of the THStack one?
Sorry, I am not familiar manipulating the graphics objects from the TTree class. I am having issues because I notice that if I do something like

tree.Draw("myvar1:plotname>>hname1","","goff"); tree.Draw("myvar1:plotname>>hname2","some condition","goff");

and when I do

THStach hs("hs"); hs.Add(hname1); hs.Add(hname2); hs.Draw("nostack");

The data in the first leaf is also being automatically loaded in the second histogram/ graph object when I draw the second plot. Ideas?

I cannot reproduce this problem.
Post a short script and data file reproducing the problem.


I posted a short script about this problem in a previous reply of this post:

treeConcentrations.root and TCutsSetConcTree.C.


see comments inside your code

TCutsSetConcTree.C (2.85 KB)

Thank you. So the problem was that I was using 2D drawing options? I don’t understand why points are being generated randomly if I am providing a set of x,y values.


because you ask for a TH2 to be drawn by default as a scatter plot.
In your case you do not need a TH2, a TH1 will do the same job with 100 less memory use.