Save new root file with Snapshot in RDataFrame

hello experts
i’m trying to use rdataframe to add new column to dataset, the input root file structure is like this:
Screen Shot 2022-09-13 at 14.41.30

i defined a new branch weight_new and trying to save in tree tnpEleTrig/fitter_tree by doing this:
fileName = "DYJetsToLL_LHEFilterPtZ-650ToInf_MatchEWPDG20_TuneCP5_13TeV-amcatnloFXFX-pythia8.root"
treeName = "tnpEleTrig/fitter_tree"
d = ROOT.RDataFrame(treeName, fileName)
df=d.Define("weight_new", "2")
df.Snapshot("tnpEleTrig/fitter_tree", "newfile.root")

but i got error like this:

i dont know what the ‘third argument’ should be? thank you

Hi @yiruole ,

Your Snapshot call looks ok, the relevant part of the error is "Unknown columns: ...".

I don’t know what might cause that. Which ROOT version is this with? Can you try with v6.26.06, and if you still get this error, can you share the input file with us (or also just with me privately)?

Cheers,
Enrico

hi Enrico
idk how to check root version? i downloaded newest root 1.5 years ago
i copied the root file i use to my lxplus public space since it is too large and failed uploaded here:
/afs/cern.ch/user/r/ryi/public/DYJetsToLL_LHEFilterPtZ-650ToInf_MatchEWPDG20_TuneCP5_13TeV-amcatnloFXFX-pythia8.root
thank you

root --version or, with older versions, root-config --version

Hi,

I tried running this code against the file you shared:

import ROOT
fileName = "DYJetsToLL_LHEFilterPtZ-650ToInf_MatchEWPDG20_TuneCP5_13TeV-amcatnloFXFX-pythia8.root"
treeName = "tnpEleTrig/fitter_tree"
d = ROOT.RDataFrame(treeName, fileName)
df=d.Define("weight_new", "2")
df.Snapshot("tnpEleTrig/fitter_tree", "newfile.root")

I cannot reproduce the problem with ROOT v6.26.06 or a recent build of ROOT’s master branch. Please try this, e.g. on LXPLUS. Let us know in case you get the error with a recent LCG view on LXPLUS.

Cheers,
Enrico

Hi Enrico
i tried on lxplus, still got the same error, then i checked the root version on lxplus, it’s 6.14/09 :disappointed_relieved:
then i tried to download the ROOT v6.26.06 Release 62606 - ROOT


after the installation success, i checked the root version is still same as what I had: 6.22/06, idk why…

Hi @yiruole ,

you can get recent ROOT versions on LXPLUS via the LCG releases, e.g. source /cvmfs/sft.cern.ch/lcg/views/LCG_102/x86_64-centos7-gcc11-opt/setup.sh gets you ROOT v6.26.04.

I will be off next week, I’d kindly ask @vpadulan to follow up if a recent ROOT version still has the problem.

Cheers,
Enrico

1 Like

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