What I do not understand is why all the points related to the same value of position do not appear in the bin center (somwhow they are scattered randomly within the bin in the x axis).
When you force an histogram in the TTree Draw command the resulting histogram is plotted. By default the SCAT option is used to plot this histogram, which is exactly what you said: random points in each cell. The number of points being proportional to the bin contain.
The effect you encounter can be clearly seen with the file hsimple.root generated by $ROOTSYS/tutorials/hsimple.C
So then, if I use the second method, how can I make the first bin to be from 0, instead of 0.5 (so the value do not end up being on top of the y axis)? And how can I make the labels on the xaxis to be centered?
I think the best would be that you first Draw your 2D histogram empty to define the frame and then you draw the TTree using SAME:
hframe->Draw();
tree->Draw("x,y","","SAME") ;
anther alternative would be to use method #1 a with option GOFF and then Draw the 2D histogram with option COL or BOX. You will not get the market but the plot will look nice.
if now I write and close the root file, later when I open the root file and visualize the histogram the only histogram that appears is the first one plotted using
but not the
Do you know how can I do it that I get to save both histograms together?
your plot consists of 2 objects: an histogram for the axis and then the tree plot for the dots. If you want to keep all in a single entity your need to save the canvas.
But what I meant is that now in my root file I will have a “wrong” histogram and a complete canvas with all the information I need. I was wondering if there is a way not to save the histogram (since i do not need it).