Finding Tbranches

I have a root find which have 5 Tbranch and each Tbranch have soem TBranchElement. So I want to write a code to group each event based on their Tbranches. that means for entry(1):

array=[ [TBranch] ,[TBranch],[TBranch].[TBranch],[TBranch] ]

[TBranch]=[ [TBranchElement],[TBranchElement],[TBranchElement],[TBranchElement],… ]

I can do it if I want use my knowledge about the data,but I want to write a general purpose code not just for one specific tree.

any idea?


perhaps you are looking for TTree::GetListOfBranches() and TBranch::GetListOfLeaves().


both of them give me the same result.

TauJet = 0
TauJet_E = (vector)0x3ff32c0
TauJet_Px = (vector
TauJet_Py = (vector)0x389faa0
TauJet_Pz = (vector
TauJet_Eta = (vector)0x146ad9d0
TauJet_Phi = (vector
TauJet_PT = (vector)0x3ff02b0
TauJet_Charge = (vector
TauJet_NTracks = (vector)0x3ff05e0
TauJet_EHoverEE = (vector
TauJet_size = 0
Jet = 4
Jet_E = (vector)0x389ec80
Jet_Px = (vector
Jet_Py = (vector)0x39b09a0
Jet_Pz = (vector
Jet_Eta = (vector)0x402d860
Jet_Phi = (vector
Jet_PT = (vector)0x39b4950
Jet_Btag = (vector
Jet_NTracks = (vector)0x39b5090
Jet_EHoverEE = (vector
Jet_size = 4
Electron = 0
Electron_E = (vector)0x3a61fe0
Electron_Px = (vector
Electron_Py = (vector)0x3a64130
Electron_Pz = (vector
Electron_Eta = (vector)0x3a69a40
Electron_Phi = (vector
Electron_PT = (vector)0x3aaa380
Electron_Charge = (vector
Electron_IsolFlag = (vector)0x3abfee0
Electron_SumPt = (vector
Electron_EtaCalo = (vector*)0x3ac0360

I want to find just “TauJet,”“Jet” and " Electron " not others like Electron_Px.But both GetListOfBranches() and GetListOfLeaves() give me all of theses.

In “Browser” , when I right click on “TauJet” , I have "TBranch::TauJet"but for “TBranchElement::TauJet_Py”


ah, I misunderstood. How were those created? A split branch does not (AFAICS) show up in this way, as the list of branches will only be the top level created branch.

Of course, you can always filter if that naming convention that I see holds, for example:mybranches = [b for b in mytree.GetListOfBranches() if not '_' in b.GetName()]

Thanks wlav. I aware of that but I just wanted to see if I can do it by ROOT itself. Actually I didn’t created the tree, I am just working on that. As I said I want write a function that deals with any tree with this structure. It is possible that Branches have different name format.


even if you didn’t create the tree, it’d still be helpful to know how it was created. If the split was done automatically by ROOT (but I don’t think so), then I’m sure it can be detected when reading back. If all those branches were explicitly created, then that’s it: there’s no reason for the I/O system to know that they belong together, as that information is then only available in the name, and hence parsing the name is all that can be done.