Hist projection with TCutG


I’m having some problems with hist projection using TCutG.
I’m trying to project a slice of a histogram and fit it (so I can compare the results to FitSlices). I’m defining the slice with TCutG.
When projection on X and asking for a slice of 2 bins in Y, I see get a slice of only one (the top) bin.

I’m attaching a sample code to show what I mean. When cutting on
x = {-5.,5.};
y = {0.1, 0.3};
I only get the bin corresponding to y={0.2, 0.3}.
To get both 0.1 and 0.2 bins, I need to define the cut like this:
y = {-0.1,0.3};

Why does this happen?

FitSlicesX.C (1.24 KB)


you are not using correctly TCutg. As stated in the documentation,

Therefore you should define it as follows

double x[4] = {-5.,5., 5.,-5};
double y[4] = {0.1, 0.1, 0.3,0.3};
TCutG cut("cut", 4, x, y);

However, when you apply a simple rectangular cut, you don;t need to go through a TCutg object. You can simply pass the first and last bin as argument to the Projection function or (from 5.24) you can use also TAxis::SetRange

Best Regards



Thanks. I should’ve realized.

I didn’t quite get your second suggestion. Yes, I can pass the y bins range to the projection, but if I want to limit projection with x bins, there’s no way but using TCutG.



for the x axis (the projected one) you can do before projecting

h2->GetXaxis()->SetRange( firstXbin, lastXbin);