Copy root file without cut events PyRoot

Dear users,

I have a root file with a TTree and branches. I pass it through a python code where I apply cuts on some parameters (param1, param2,…) of the root file and other parameters computed by the python code ( cpar1, cpar2,…) in the following way
loop events:
if (param1 > cut1):
continue
if (param2 > cut2):
continue
if(cparm1 > cut3):
continue

I’d like to know if there’s a good way to create a new root file similar to the old one with same branches and same names without cut events.

Best Regards.


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18/00
Platform: lxplus
Compiler: Not Provided


Dear @zqsd ,

I would suggest that you use RDataFrame for that. Your use case can be a simplification of what is done in this tutorial:
https://root.cern/doc/master/df007__snapshot_8py.html

You would apply your cuts with Filter and save your new ROOT file that has the same branches but less events by means of Snapshot. We are happy to guide you through that process if necessary.

1 Like

Dear @etejedor,

Thank you for your reply, I finally managed to solve it getting each value “by hand” from tree input in the loop events and Fill a new tree in a new root file after the cuts ( like that https://wiki.physik.uzh.ch/cms/root:example_ttree ). Which was really tedious because there were many branches.
However, your answer looks interesting, I’ll keep it.

Regards,
zqsd

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