Save variable in different branches into one branch

hello experts
I have a root file with different trees showed in picture:
Screen Shot 2022-11-04 at 13.07.29
i want to read from tree Events to get variable genWeight and read from tree Runs to get variable genEventSumw, then save genWeight/genEventSumw as another variable, i did this:
import ROOT
fileName = "6F3B4758-2BFA-5441-8D5A-E2BB3FA2C876.root"
treeName = "Events"
treeName2 = "Runs"
d = ROOT.RDataFrame(treeName, fileName)
df=d.Redefine("genWeight", "genWeight*0.045096*16.9")

d2 = ROOT.RDataFrame(treeName2, fileName)
df2=d2.Define("sum", "genEventSumw")

df3=df/df2
df3.Snapshot("Events", "pt-binned-nanoaod/650toInf_nanoaod.root")

but i guess it doesnt work. is there any way to read variable from different tree? thanks a lot

The “Events” and “Runs” are not branches. They are both TTree objects.

yes sorry i used the wrong word, they should be tree, not branches, how to save the two variables from two different trees into one use RDataFrame? thank you

Hi @yiruole ,

conceptually you need to “join” the two datasets (Runs and Events) before processing the joined dataset with RDataFrame. You typically use friend trees (or indexed friend trees) for that, see also ROOT: ROOT::RDataFrame Class Reference .

Do Runs and Events have the same number of entries? If not, what’s the correspondence between entries in one tree and entries in the other?

Cheers,
Enrico

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.