Got crash messages when use RDataFrame to redefine weight in NanoAOD file

hello experts
i’m trying to use RDataFrame to redefine weight in NanoAOD file, here is the script:
import ROOT
fileName = "/eos/user/r/ryi/TagandProbe/TnP2016post/6F3B4758-2BFA-5441-8D5A-E2BB3FA2C876.root"
treeName = "Events"
d = ROOT.RDataFrame(treeName, fileName)
df=d.Redefine("genWeight", "genWeight*0.045096*16.9")
df.Snapshot("Events", "/eos/user/r/ryi/TagandProbe/TnP2016post/650toInf_nanoaod.root")

however, i got a very long crash message and i dont know where’s the problem comes from?
crash message in txt file
crash.txt (37.3 KB)

input NanoAOD root file is here /afs/cern.ch/user/r/ryi/public/6F3B4758-2BFA-5441-8D5A-E2BB3FA2C876.root

Hi @yiruole ,

the important error message is at the beginning:

Error in TBranch::TBranch: Illegal leaf: CorrT1METJet_area/CorrT1METJet_area[nCorrT1METJet]/F. If this is a variable size C array it’s possible that the branch holding the size is
not available.

You are likely hitting this issue (more details there), which should be fixed in v6.26.06. Can you please try with that ROOT version?

Otherwise the workaround is to manually specify which columns you want to write out as an argument to Snapshot taking care of putting nCorrT1METJet before CorrT1METJet_area in that list (in v6.26.06 RDataFrame takes care of that automatically).

Cheers,
Enrico

thanks a lot, can i know how to use v6.26.06? i tried command source /cvmfs/sft.cern.ch/lcg/views/LCG_102/x86_64-centos7-gcc11-opt/setup.sh but it goes to v6.26/04

The ROOT team does not maintain the LCG releases, but from what I see at https://lcginfo.cern.ch/pkgver/ROOT/6.26.08 I think you can use source /cvmfs/sft.cern.ch/lcg/views/LCG_102b/x86_64-centos7-gcc11-opt/setup.sh.

thanks a lot, this works. i have another question about this problem. I have a root file with different branches 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

This is followed up at Save variable in different branches into one branch .

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