Sum using cuts instead of looping

Hello,

I have a very big dataset…

I have a branch with several leafs among which I find “energy” and “eventID”

I can display the energy for a certain eventID like this

which shows me all the energies for the eventID X

I can also draw that

Now I’m trying to do something like

meaning that it would be like a vectorized sum of the energies of eventID X which will be stored in a variable “totalenergy”

I have tried looking in the documentation and the forum but still haven’t been successful with this…

anyone can give me some advice on how to do it?

Thank you very much

You can Draw or Scan the special function Sum$ of the branch. So something like:

t.Draw("Sum$(energy)","eventID==X");

A list of the special “" functions can be found here: [url]http://root.cern.ch/root/html/TTree.html#TTree:Draw@1[/url]. There is no direct link to the actual section that talks about them, so use your browser's search function to look for "Entry” (with the dollar-sign) to find the list.

Other ref:

Jean-François

Thank you for your reply Jean-François.
So yes I was able to draw and display the sum however, I want to know if I can store that sum in a variable

and then be able to use that sum for some other analysis…for example

if(totalenergy < X){ fill histogram }

Is it possible?

thanks again