Number of events under a line


I would like to calculate number of events under a line (curve). How can i do it? I tried to fit a line (see attached figure) and integrate it but the answer is wrong.


The simplest way is to use a TCutG (graphical cut) as cut when projecting
your ntuple to the histogram, eg

double x[4] = {1400,1400,1700,1700}; double y[4] = [0,2000,900,0]; TCutG *cut = new TCutG("mycut",4,x,y); int ngood = tree.Draw("Energy","mycut");
You can also create the TCutG with the mouse using the canvas toolbar.

For more details see the doc of TCutG and TTree::Draw … DrawSelect


Hi Rene,

I tried the code that you gave me. And modified it like this.

  double x[4] = {1340,1340,1660,1660};
  double y[4] = {0,1300,500,0};
  TCutG *cut = new TCutG("mycut",4,x,y);

When i do that i’m getting an empty histogram. Could you tell me where is my mistake?

Thanks a lot.[/code]

You must start from a TTree, not a histogram


Hi Rene,

Now, I’m able to apply the cut. But there is one thing that i’m wondering.
When I applied the cut number of events is abour 230.000. But when i look the origina histogram the number of event is about 20000 (number of events under the 1.4 MeV peak, please look first graph). How is that possible?

Thanks a lot for your help.