RDataFrame and Friend and python

Hi,
I have a file that contains 2 TTree.
The TTree B_field has a friend called t_hk_obox (both in the file)
root [1] B_field->GetListOfFriends()->At(0)->Print()
OBJ: TFriendElement t_hk_obox
I try to define a cut using a variable that is in t_hk_obox in opening
the B_field TTree:

In python I do:

>>> import ROOT
>>> input_name = "$POLAR_AUX/Allaux_Bfield.root"
>>> TDF = ROOT.RDataFrame
>>> d = TDF("B_field",input_name)
>>> d.Define("high_voltage", "t_hk_obox.fe_hv")
input_line_63:2:28: error: use of undeclared identifier 't_hk_obox'
auto lambda0 = [](){return t_hk_obox.fe_hv
                           ^

How do I achieve to reach the Friend?
If in ROOT I do

B_field->Draw("fe_hv") or B_field->Draw("t_hk_obox.fe_hv")

It works nice


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22
Platform: ubuntu 20.04


I think @etejedor can help you

Hello,

According to the RDataFrame documentation:

(subsection “Friend trees”)

friend trees are supported by RDataFrame, but the user is required to build the trees and its friends and then create an RDataFrame from the tree, instead of using the tree name, file name constructor.

Hi,
I thought reading it from a file will do that for me.
I expect that the constructor of the RDataFrame reestablish the Friends for me.
In ROOT if I open a tree from a file as a tree I get for free the Friend relation.
I suggest this should be added to the constructor of the RDataFrame or the constructor can have a
parameter requesting to do that.
At least to decrease the surprise factor.
In the mean time I will try to do what I think you mean by building the tree in reading it from the file.
Cheers

Hi,
interestingly if I read the TTree from the file and give the
pointer to the TTree to RDataFrame instead of constructing RDataFrame
from the name of the TTree and the name of the file, I don’t have to do anything.
It just work, so it is a clear difference between the two constructors that should not exists.

This code work:

import ROOT
input_name = "$POLAR_AUX/Allaux_Bfield.root"
f=ROOT.TFile(input_name)
t2 = f.Get("B_field");
TDF = ROOT.RDataFrame 
d = TDF(t2)
d.Define("unix_time", "t_hk_obox.tunix.tunix")

I see, thanks for the feedback about the behaviour of the constructor and the docs, I mention @eguiraud as the person responsible for RDataFrame so that he is aware.

Hi,
thank you for bringing this to our attention, the behavior is certainly not desired.
This is now https://github.com/root-project/root/issues/6741 (I’ll get to it as soon as possible).

Cheers,
Enrico

1 Like

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

Hi,
the fix for this issue was just merged in ROOT’s master branch, so it will be available in tomorrow’s nightly builds as well as ROOT’s next release, v6.24.

Cheers,
Enrico

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