Hi ROOTers,
I am trying to merge two trees, with different branches, into a single tree containing all of them. I tried to do it using TChain and the AddFriend function.
I currently tried to do it directly from terminal.
What I do is to add the main tree to a first chain, then add the other tree to another chain, and add it as a friend to the main one.
I manage to access all the variables contained in the "variables" tree using Draw() or Scan() functions on originalChain.
What I don’t manage to do, is to save everything as a single TTree that contains all the branches.
I tried to do
originalChain.Merge("newFile.root")
but the output contained only the branches from the "merged" tree.
Is there a way to do this?
_ROOT Version: 6.18/00
_Platform: Linux 3.10.0-1127.13.1.el7.x86_64
Merging friend trees (horizontal merge) is not yet implement in CloneTree
To do such a merge you would need:
CloneTree(0) [just the structure] the main tree.
Add/Create the branch corresponding to the friend tree in the cloned structure
Connect the branch addresses from the friend to the new branches in the cloned structure
[probably] Connect a notify object (SetNotify on the friend chain) so that you can update the branches address of the friend tree and the cloned structure.
loop over the entry and call GetEntry/Fill as appropriate.
Does any RdataFrame operation be used in this case?
In the past to merge a tree and a friend one to a single tuple i did the AddFriend on a given TTree passing a nickname to each friend, then i apply a Recursive Define so that nickname.XX gets Define as XX, then snapshot with dropped columns.
I don’t know if anything like dataframe from TChain with an AddedFriend would work as well. Might be good a try maybe.
Your final tuple will contains in principle “all-columns” from originalTree, and all added friends branches with
friendAliasX_COLUMNY
The aliasing is useful if you have 4-5 different friends all done with the same name on branches, so to not confuse the RDataFrame the aliasing push the branches to have friend1.XX , friend2.XX in the ColumnNames() list, the Define with . replaced with _ is arbitrary, is just to flatten everything