How to Snapshot all but some branches

Dear Experts,

I’m trying to Snapshot a RDataFrame using pyroot. I’d like to write all but some branches and ideally leave out only those matching a certain pattern (for example leaving out all the branches containing the word “ProbNN”). Something of the kind:

expressions = ["*ProbNN*",  ...]

temp.Snapshot(treeName, fileName, expressions, opts)

Where expressions is a list of patterns of variables to be left out from the snapshotted ntuple. More generally, what’s the accepted syntax for columnList in ROOT: ROOT::RDF::RInterface< Proxied, DataSource > Class Template Reference ?

An apparently similar question was asked here How to remove or exclude one branch in RDataFrame in python when reading from tuple file? but the answer provided is not really doing what was asked I believe.

Thanks for your help,
Davide


_ROOT Version: ‘6.30/04’
Platform: Not Provided
_Compiler: conda


Dear @Davide_Lancierini,

Snapshot takes a list of branch names/columns. I guess the easiest way to achieve your goal would be first to compute the list of column names matching your criteria and then to pass this list to the Snapshot function.

Cheers,
Monica

Dear Monica,

Thanks for your reply, it solved my request. I have another (unrelated to the previous) doubt about the Redefine method. Can I use it to change the name of a branch to a new name that is not already present within the tree branches?

for example (old_branch_name is a branch of the df):

df.Redefine(old_branch_name, new_branch_name)

Throws the error:

input_line_239:2:21: error: use of undeclared identifier 'new_branch_name'
auto func6(){return new_branch_name

However, if I do

df.Define(new_branch_name, "(1.)")
df.Redefine(old_branch_name, new_branch_name)

doesn’t throw error, but the new branch only has values of 1., and hasn’t been redefined.
Thanks for your help!

Hi @Davide_Lancierini,

if your goal is just to change the name of a given column, you can use Alias instead of Redefine.

Cheers,
Marta

Brilliant thanks a lot @mczurylo !

Cheers