Copy tree from one file to another (no changes in between)


I am using ROOT files as input and output of a simulation.

I need to copy a tree from my input file (“a0.root”) to my output file (“a.root”), just 1 to 1, without making any change on it.

I thought that something like this would work:

  TTree *tinput = (TTree*)a0->Get("tinput");
  a -> cd();

But it does not. The file “a.root” contains a “tinput”, but it is empty.

I know that defining all branches and their addresses it would probably work, but I would prefer to avoid this because the structure of my tinput is not always the same (depends on which kind of input is coming to the simulation).

Can somebody tell me how to copy one tree from one file to another without the need of defining all the branches?

Thanks in advance,

1 Like

This should work. Could you post the shortest possible RUNNING script reproducing the problem and tell where to pick your inut file ?


My apologies.

Indeed it does work. I’ve just found out that the problem was related with the compilation of the simulation, due to what my last modification, the introduction of “CloneTree()”, was ignored.

Sorry, I was about to remove my message but your reply was faster.

Nice day,