Merging a trees and copying subsample of branches into another tree

Hello all,

I am using ROOT 5.34/32.

I would like to do the following:

  • Chain several trees (each one named ntp) from several root files,
  • Select a set of branches of the chained trees and copy them into another three.

I tried to follow the example in the link below, … ree.C.html

but with no success.

The structure of the tree is a set of variable size arrays as follows,

  • Branch N: actual number of entries of the variable size arrays,
  • Branches Var1, Var2, Var3, …: arrays with variable size N => e.g. Var1[N] for each entry in the tree

I tried to do the following,

  • Build a TChain (fChain) and chain the set of root files to it.

    TChain* fChain = new TChain(“ntp”,“A chain”);

  • Then deactivate all the branches and active only the ones I want,

    //Deactivate all the branches

    //Activate only the ones I want

    Then I tried to create a new tree as follows,

    TTree* new_tree = fChain->CloneTree(0);

but I get a segmentation fault.

Any of you guys knows what I am doing wrong?

Many thanks in advance,


Hi Alejandro,

Did you create a new TFile to hold the new TTree?

Cheers, Bertrand.