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):
if (param2 > cut2):
if(cparm1 > cut3):

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:

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 ). Which was really tedious because there were many branches.
However, your answer looks interesting, I’ll keep it.


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