Home | News | Documentation | Download

Snapshot friend trees after filtering

I have a root file with multiple trees inside.
I want to Snapshot it after I filter some events out.
But I get only filtered main tree in the output, losing filtering of Friend trees.

Codewise what I want looks:

import ROOT

ch1 = ROOT.TChain("tree1")
ch1.Add("files*.root")
ch1.AddFriend("tr2 = tree2", "files*.root")
ch1.AddFriend("tr3 = tree3", "files*.root")

ROOT.RDataFrame(ch1).Filter("a >-42 && tr2.b < 42").Snapshot("new_tree", "new_file.root")

And I want to get also skimmed friend trees variables.

Is there a clean way to do it?

Or swaping places the chains and running the same code Nfriend_tree times and merging them in the end is the only solution?

cheers

ROOT Version: 6.22/00

Hi @FoxWise ,
ah indeed, Snapshot should do this by itself, sorry about that! I think this is a missing feature. Feel free to request better support for Snapshots of branches coming from friends at Issues · root-project/root · GitHub.

As an alternative workaround (what you described would work, of course), passing the names of all branches that you want printed out explicitly to Snapshot should get you also the branches of friend trees in the output (the problem is “just” that Snapshot does not pick them up automatically).

Cheers,
Enrico

1 Like

Does an iterative define of (Column, friend.Column) would fix the issue (granted that friend tuples has different column names?) i think i got this working in the past

Yes it will work as a workaround

But still, conservation of TFile structure after the snapshot would be very helpful, if this is implementable

Yes that is also a workaround but it has a performance cost w.r.t. to the other two methods proposed (namely the cost of evaluating the Defines, even if it’s just a simple copy).

Cheers,
Enrico

1 Like

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