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!


I would use RDataFrame:

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).

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.