Access non-selected branches when cloning TTree

Hi all,

I’m currently cloning/copying a TTree selectively (only some branches) as done in the examples copytree*.C of the root tutorials. I’m also calculating new variables from the variables in the input branches and add them to the new Tree on the fly. This all works perfectly, but I would like to exclude some of the variables (respectively their branches) I’m using from the cloning process since they become redundant.

Example: Assume the original Tree has two branches named “b_var1” and “b_var2” holding two ints “var1” and “var2”. Also, I want to calculate var3=var1+var2 and then add a new Branch for it in the output Tree. I of course have to do SetBranchStatus(“b_var1”,1) and SetBranchStatus(“b_var2”,1) in order to be able to access the input branches, but this inevitably will also copy these branches to the new Tree when I do newtree->Clone(0), which is not what I want.

Is there a way to access Branches from the input tree, but not copy them during the cloning process?

Any help would be greatly appreciated.

Cheers,

Fabian

Hi,

Do:oldtree->SetBranchStatus("b_var1",0); oldtree->SetBranchStatus("b_var2",0); newtree = oldtree->CloneTree(0); oldtree->SetBranchStatus("b_var1",1); tree->SetBranchStatus("b_var2",1);

Cheers,
Philippe.

Hi Philippe,

thanks a lot for the quick reply, your suggestion did the trick!

Thanks again, cheers,

Fabian