tree.CloneTree(0) not working

The problem:
I clone my tree so that I don’t mess up the previous root file:

cloned_tree = tree.CloneTree(0)

When I type tree.GetEntries() I see that it prints a large number. But when I do

output_file = ROOT.TFile("with_weights.root", "RECREATE")

cloned_tree.GetEntries() 

that returns 0. So how does the cloned tree is empty?

My ultimate goal: I have a tree where I want to add a new branch (weights) to it . The values (weights) I want to add are already stored in a different .root file. I started by cloning the tree, then I loop over the weights and save them as a list. Then I try to create a new branch and fill the branch with this new list.

Hi @greentree, thanks for the question. I’m not an expert. But from what I see, you tried to

CloneTree(0) // which means 0 entries will be copied

So it makes sense that there are 0 entries in the cloned_tree. You can have a look at the documentation and tutorials mentioned here: ROOT: TTree Class Reference

Maybe @couet can confirm.

1 Like

Thanks this resolved the issue

1 Like