How to get a new tree based on cuts on a data tree

Hi, rooters,

I have a tree represents data, say, tree_A, which contains branches of E, x and y.
Ideally, I’d like to make a cut to produce a new tree, tree_B.
The tree_B contains a branch which is the result of : branch E with a cut of “x > 1 && Y > 1”.

I know how to produce a histogram by call “Draw()” command with a cut.
However, for the convenience the next analysis, it’s necessary to get a tree(branch), instead of a histogram.

I’ve looked around here, but can’t find a close example.

Can any expert here tell me how to do it ?

Thanks !



This might not be the most efficient way to do it (I’m not an expert, and I’d be happy to know if there is a better way), but here’s how I’d proceed:

TTree *tree_B( tree_A->CloneTree(0) );
TTreeFormula *myFormula( new TTreeFormula("myFormula", "x > 1 && Y > 1", tree_A) );
for(uint64_t i = 0; i < tree_A->GetEntries(); ++i){

Does this answer your question?