# Finding x and y values of points in a histogram

Hi All,

I have a 2D histogram that I filled with 2 variables: mass, event.
I would like to get the x-value and y-value of the points I got (meaning the mass vs event I filled).

Looking at the C file of the histogram, I can see only the global bin number and the number of entries correspond to that bin.

I tried:
For instance, I took one global bin number 61029 and search for the x and y bins:
[]int x,y,z
[]h->GetBinXYZ(61029,x,y,z)
[]h->GetBin(x)
25
[]h->GetBin(y)
3
[]h->GetYaxis()->GetBinLowEdge(3)
3.94666666666666628e+05
[]h->GetXaxis()->GetBinLowEdge(25)
6.42700000000000000e+07

But this gives me a close number, but not the exact number of the point I wanted

Your help would be most appreciated
R

By filling a histogram you lose the information about exactly where the point is, and instead store the number of counts in each bin. This may lead to a great reduction in the space needed to represent such information. Perhaps you would instead like to use a TTree or a TGraph2D, which maintain the point to point information.

Hi,

I have two questions regarding your suggestion, and I apologize in advance if they are stupid:

1. For the TGraph2D - if it is a 2D graph, I saw that it goes like this:
TGraph2D *g = new TGraph2D(n, x, y, z);
g->SetPoint(i, x, y, z);
what do I put in the z if I don’t need it?
and i - I guess it is the point number…

Thanks again

It is a little difficult to suggest which would work better for you as your goal is not completely clear. I suggest you take a look at the User’s Guide http://root.cern.ch/drupal/content/users-guide. It contains lots of useful information and examples that may lead you in the direction your interested. Specifically you should look at the chapters covering Histograms, Graphs, and Trees. I attempt to answer your questions below.

1. In the TGraph2D constructor i is the point number and z is the third dimension of the point. Don’t forget that a 1D histogram contains two dimensions of data, the 1 variable axis and the bin content. While a 2D histogram contains two dimensional data points and the bin content. Perhaps all you need is a TGraph. Again, its not clear what your goal is.

2. A TTree is often compared to a sort of database. It is similar to storing your data in a text file where each row is an entry and you had multiple columns referring to various parameter. That is a gross under description, TTrees are cpapble of then dumping the data into various histograms (1D,2D…) and you may make selections of the data, for example column 1 > 4, using TCut.

Hi,

I have these root files, for different run periods, and I suspect I have somewhere duplication. So basically I am trying to learn about specific events.

One of the tests I was trying to do, is to get these event numbers and check the different properties, like mass, p etc…
The thing is, I couldn’t locate the exact event numbers from the histogram. When I used the EventStatusBar, I saw the x and y values - but not the exact ones, because I couldn’t set the mouse exactly on the relevant point in the histogram.

I tried you suggestion. I used the tree of my files and created a TChain. Then I did the following:
I took the tree and draw what I needed :
int n = tree->Draw(“Event:mass”,"<>, “goff”")
Graph *g = new TGraph(n,tree->GetV1(),tree->GetV2())
g->Draw(“ap”)
and saved the graph as a .C file

BTW - I didn’t know what is goff and ap - i saw it in the forum
But when I opened the .C file, again I didn’t see the x and y value as they appear on the graph with the event status bar… in fact they where in a different scale, and where similar to what I got when I filled a histogram

If you have any further ideas - they will be more than welcome… I am kind of knew in all the root business… sorry.

Thanks again for the help

You should see these values in the .C file generated.
All the SetPoint() calls should contain all your data.
Can you post here the .C file you get ?

Hi again,
I am so embarrassed - you were right.
I accidentally run two root scripts with the same path and same graph name to save, so one ran over the other. This is why I got different numbers than I expected.

Thank you very much for your help.
Apologizes