Changing leaf in TTree ROOT

Hi all, i am trying to use ROOT for GEANT4 analysis. I am saving a root file with counts as a leaf, and Energy deposit, x and y as a branches. It is easy to use analysis in this way, to cut off specific x’s and y’s when i need it. However, how can i replace counts to Energy deposit as a leaf, without writing a new root file, since it might be time consuming? What i want to is instead counts (leaf), x(branch), y(branch), Edep(branch) to have Edep(leaf), counts(branch), x(branch), y (branch).
Since i am very new in ROOT, you are wellcome to treat me as a very stupid and provide some kind of not a very complex answer.
Thank you in advance!
Cheers

Hello,

Perhaps this answer will help you:

Pinging @pcanal in case he wants to add something.

However, how can i replace counts to Energy deposit as a leaf,

In coding term, what do you mean? What do you hope to achieve by this change?

So for example i can do next thing:
tree->Draw (“fX>>htemp(5000,-20,-20)”, “(fY>8 && fY<<24)”)
Which will give me hist of counts vs x for y>8<24.
In my TFile, there is also an energy deposit number fo each count. So i simply want to build hist/plot for Edep vs x for y>8<24.
Is there any simple way to do it? I can kind of create a loop, and rewrite every Edep to a separate variable + add an if in this loop for y>8<24, but since i have 10^9 entries, everything just start to be very slow.

Search for “TEventList”, “TEntryList” and “TEntryListArray” in the TTree::Draw method description.

Another solution would be to create a new tree (in a new file) with a subset of events and / or branches of the original tree. Try:
rooteventselector --help
rootslimtree --help

I am confused. Isn’t:

tree->Draw("fX:fEdep", "(fY>8 && fY<<24)");

what you are looking for? And if it isn’t, how is it different from what you need?