Addfriend doesn't work

tree = TTree(...)
friend = TTree(...)

tree.AddFriend(friend,"friend")

tree.GetEntry(1)
tree.__getattr__('Branch of original tree') # ok
tree.__getattr__('Branch of friend') # AttributeError: 'TTree' object has no attribute 'Branch of friend'

in c++ it’s work.

I think there is a serious bug, the problem is not AddFriend, the problem is this:

from ROOT import *
friend_file_name = "decaytree011208_v19r13_v31_friend.root"
friend_file = TFile(friend_file_name)
friend_data = friend_file.Get("friend_tree")
friend_data.GetEntry(1)
friend_data.__getattr__('Associato') #OK
friend_data.__getattr__('MIPS') #OK
friend_data.__getattr__('PhiDsP_MM') # AttributeError: 'TTree' object has no attribute 'PhiDsP_MM'

Why? ‘Associato’, ‘MIPS’, ‘PhiDsP_MM’ are all Branches! There is no difference. I attach the root file.
decaytree011208_v19r13_v31_friend.root (276 KB)

Hi,

the problem is that the friend branch added does not yield a classname (and does not show up as a leaf, like the other examples do). Try:print friend_data.GetBranch( 'PhiDsP_MM' ).GetClassName()
Which turns up empty. Note sure how that came about or where it can be solved.

Cheers,
Wim

[code]root [3] friend_tree->Print()


*Tree :friend_tree: friend_tree *
*Entries : 19527 : Total = 434755 bytes File Size = 277902 *

  •    :          : Tree compression factor =   1.56                       *
    

*Br 0 :PhiDsP_MM : PhiDsP/F *
*Entries : 19527 : Total Size= 78838 bytes File Size = 51277 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.53 *

*Br 1 :PhiDsM_MM : PhiDsM/F *
*Entries : 19527 : Total Size= 78838 bytes File Size = 52081 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.50 *

*Br 2 :KStarDsP_MM : KStarDsP/F *
*Entries : 19527 : Total Size= 78852 bytes File Size = 52475 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.49 *

*Br 3 :KstarDsM_MM : KStarDsM/F *
*Entries : 19527 : Total Size= 78852 bytes File Size = 52959 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.48 *

*Br 4 :MIPS : MIPS/F *
*Entries : 19527 : Total Size= 78812 bytes File Size = 61073 *
*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.28 *

*Br 5 :B2Ds_DIRECT : B2Ds_DIRECT/B *
*Entries : 19527 : Total Size= 20104 bytes File Size = 2813 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 6.97 *

*Br 6 :Associato : Associato/B *
*Entries : 19527 : Total Size= 20094 bytes File Size = 4256 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 4.61 *

[/code]

Note that for Associate and MIPPS the name of the branch and the name of its unique leaf is the same while for PhiDsP_MM the leaf is named differently. I think that in the python interface you will need to use the leaf name instead (i.e: PhiDsP)

Cheers,
Philippe.

Yes, using the leaf name appears to give a reasonable result.

How could I have detected the connection from the branch name to the leaf name programmatically?

Cheers,
Wim

Hi,

The Branch object has a list of leaves (GetListOfLeaves).

Cheers,
Philippe.