Home | News | Documentation | Download

Slicing a TH2 in Y axis

Dear,

I have a TH2D (X vs. Y), and I want to get X TH1D’s, in specific ranges of Y, so I do the following

hX_i_j = hXY->ProjectionX(“hX_i_j”, hXY->GetYaxis()->FindBin(i), hXY->GetYaxis()->FindBin(j))

but this is giving something else from what I would expect. Is there anything wrong with what I’m doing? is there any cleaner way of doing that? Thanks!!

Hi,

If you want to get a slice, i.e. the 1D histogram of X given the Y value, you should use the same bin:

hX_Y = hXY->ProjectionX(“hX_Yi”, hXY->GetYaxis()->FindBin(yvalue), hXY->GetYaxis()->FindBin(yvalue))

where yvalue is the y value for which you want to get the slice. It is not clear to me what are i and j.
They should be y values and not bin numbers. If you have a range (inlacing more bins in y) you will have a projection, i.e. the sum of all contents of the y bins.

Lorenzo

Hi Moneta! sorry for the bad notation, but i and j are indeed yvalues, but when I compare the entries on the actual TH2 plot, it’s not the same, … any idea why this is?

Hi,

I understand. But what is not the same and how is different ? Please provide an example and better a script reproducing the problem, thank you

Lorenzo

Hi, sorry for the late message, I tried the method on a simple TH2D histogram and it worked fine, I will double-check my original problem, thanks a lot!