I have a TH2D with x and y, and what I need is to get the values for all the bins to calculate the mean at each bin. So I tried to cycle through the bins and get all the x and y values that are in that bin, but when I print e.g. xval[0], xval[1]…, they are all the same.

thanks for the help!!
After running the macro, I modified some lines:
I had to change GetVal() for xntuple and yntuple, because for some reason in xntuple the values for log(y/x) were stored and in yntuple the values for x. And as yntuple is already log(y/x), yaxis = yntuple[b]. Anyhow, next I’ll try to add the binW parameter to get all the points in a certain bin, not only one.

Am writing again, because I stumbled upon something I don’t understand. Will attach my macro…So now if I print vx[] & vy[], I get ALMOST what I want - in line 59 I say that I want to increment the steps on x axis by the “binW”, which is 4 (I start at 0.1, the next is 0.1+4=4.1 and so on). When I print vx[0], I would like to get the corresponding vy (which is log(y/x)). Or in other words, vx[0] should be an interval between 0.1 and 4.1 (vx should contain all the values in range 0.1-4.1 from the text file), but instead it only contains the first entry from the file, and x[0] is not in the first “bin”. How can I tell ROOT I want all the values from a certain range, not just one?