Member functions in trees

Hi All,

Could someone suggest me, how to access the member functions in a tree.

track

I want to write the information in a histogram.

e.g. MyHist->Fill(Value_from_the_member_function);

Thanks!

Hi,

you can programmatically read in the objects in that column and then invoke the method. Maybe one of the many RDataFrame tutorials can help you?
https://root.cern/doc/master/group__tutorial__dataframe.html

Cheers,
P

Hi,
Thanks for reply! but, I am using older version of ROOT, where RDataframes cannot be used.

I have found another idea of using TTreeReader, which can be used to read for member functions as well.
Reference can be found here :
https://root.cern.ch/how/how-read-tree

It is very good with the branches but terribly slow with the member functions.
Can we do something in this?

Hi,

I think moving to a recent version of ROOT and using RDF would solve your problem.
About TTreeReader: I am not sure of what you mean. You should be able to read objects with TTreeReader and invoke methods on them and this is not slow, as a matter of fact I think RDataFrame relies internally on TTreeReader + many optimisations…

P

Hi
Thanks for suggestion once again! but I have to run this in a remote cluster and I have no privillages to update the software there.
Regarding the TTreeReader, I am implementing like this-

TH1D * h1 = new TH1D(“h1”,“h1”,160,0,160);
// Tree reader
TTreeReaderValue <_double> ptr_to_tree_memberfunction(reader, “treeBranch.memberfunction()”);
while (reader.Next())
{
h1->Fill(*ptr_to_tree_memberfunction);
}

which is extremely slow.

Hi,

I am not sure I understand. The concept where you link a reader to a member function is not defined (even in C++: you invoke a method, you do not “read” it). You can read a a data member, or, alternatively, the entire object and after invoke the function on that object.
As for the runtime performance, not sure either. Try to read the right member or object and then verify whether this is a remote file or if the file is on network fs or similar - if yes, compare with a local copy.
As a side note, it is important to mention the ROOT version you are using.

P

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