RDataFrame and Fill method with a custom class

I have a question about Fill method, when using custom classes in RDataFrame.
Lets say I have RDataFrame with columns jet_pt, jet_eta and jet_phi columns, and create a column with the following class:

struct Jet{ double pt,eta,phi;};
auto newDF = inputDF
    .Define("new_jet", [](float pt, float eta, float phi){Jet j;j.pt = pt; j.eta = eta; j.phi = phi; return j;}, {"jet_pt", "jet_eta", "jet_phi"})

now, I would like to fill 2D histogram with this class.:
newDF.Fill(Boo(), {"new_jet"});
where Boo() will inherit from TH2D and will have customized Fill method:

void Fill(Jet j) { hh->Fill(j.pt, j.phi); }

I am able to create this custom Fill method where I can pass it like two double values (found a solution here), but when I try to pass it a custom class, I get error about some Exec() function unable to convert Jet to double.

I know I can extract the class variables before the Fill like this:

    .Define("new_jet_pt", [](Jet j({return jet.pt'}), "new_jet")
    .Define("new_jet_phi", [](Jet j({return jet.phi'}), "new_jet");

with custom Fill:

    .Fill(double pt, double phi) { hh->Fill(pt, phi); }

but that would make Jet class obsolete (I want this for a much more complicated class)

Thank you

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Hi @Martin1512 ,
currently the kind of signatures you can use for the Fill method of your custom object are quite limited – I’d like to lift this limit, work in progress.

In the meanwhile the workaround is to use the more generic Book instead, with which you can register an arbitrary action to be executed. A tutorial is here.

Let me know if this helps – this will get easier with the upcoming ROOT v6.26.

Hi @eguiraud ,
thank you, I have managed to make this work somehow :).

I have however one more idea. Is it not possible to reference somehow the class value directly when calling the Fill method? :

newDF.Fill(Boo(), {"new_jet.pt", "new_jet.eta"});

This does not work for me, but maybe there is some other syntax?


unfortunately that’s not possible :grimacing:


I see. Anyway, looking forward to new features in the dataframe section :slight_smile:


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