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.
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)0x283a490
TauJet_Py = (vector)0x389faa0
TauJet_Pz = (vector)0x3949c00
TauJet_Eta = (vector)0x146ad9d0
TauJet_Phi = (vector)0x146adad0
TauJet_PT = (vector)0x3ff02b0
TauJet_Charge = (vector)0x3ff0570
TauJet_NTracks = (vector)0x3ff05e0
TauJet_EHoverEE = (vector)0x3ca45f0
TauJet_size = 0
Jet = 4
Jet_E = (vector)0x389ec80
Jet_Px = (vector)0x402d190
Jet_Py = (vector)0x39b09a0
Jet_Pz = (vector)0x402d4c0
Jet_Eta = (vector)0x402d860
Jet_Phi = (vector)0x39b45c0
Jet_PT = (vector)0x39b4950
Jet_Btag = (vector)0x39b4cf0
Jet_NTracks = (vector)0x39b5090
Jet_EHoverEE = (vector)0x3948490
Jet_size = 4
Electron = 0
Electron_E = (vector)0x3a61fe0
Electron_Px = (vector)0x3a63dc0
Electron_Py = (vector)0x3a64130
Electron_Pz = (vector)0x3a643b0
Electron_Eta = (vector)0x3a69a40
Electron_Phi = (vector)0x3a69db0
Electron_PT = (vector)0x3aaa380
Electron_Charge = (vector)0x3ab50f0
Electron_IsolFlag = (vector)0x3abfee0
Electron_SumPt = (vector)0x3ac0280
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.