Add cuts for tree in pyroot


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi all,
I want to add some cut when cloning a tree in pyroot:

         tree = rfile.Get(treeName)
         newtree = tree.CloneTree()

Here you can see that, I got a tree. Then I want to add some cuts to slim it, like “Pt > 50”, then clone a slimmed tree.
Is there a simple way to do this?
Thank you very much for your time!

Hello,

I would use RDataFrame:

https://root.cern/doc/master/classROOT_1_1RDataFrame.html

Basically you would need to do

df = ROOT.RDataFrame("tree_name", "file_name.root")
df.Filter("Pt > 50").Snapshot("tree_name", "new_file.root")

After that you can open the new file and get the tree (and clone it if you want).

Hi,
Thanks a lot! Yes, it is a good idea!

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