Getting the object underneath a RResultPtr

Dear ROOT and RDataFrame Developers,

When I produce a histogram with RDataFrame via the function Histo1D I obtain an object of class RResultPtr. That behaves as a normal pointer to TH1D.

However, some classes of ROOT (TSpectrum to find peaks, TRatioPlot to compute residuals, etc…) work with pointers to TH1 but do not accept RResultPtr. How can I use a histogram made with RDataFrame with such classes? Or more in general, how can I obtain the TH1D underneath the RResultPtr?

Best regards,

Hi @Loris ,
you can use the GetValue or GetPtr methods of RResultPtr, see its docs.


1 Like

Hi @eguiraud , thanks for the quick reply.

I am not sure I am fully understanding how to use it though, most probably I am being a bit naive.
So if I try a simple script starting from one of the RDF examples, I get:

ROOT::RDataFrame rdf(100)
auto rdf_x = rdf.Define("x", [](){ return gRandom->Rndm(); });
auto h = rdf_x.Histo1D("x");
auto hptr = h->GetPtr() // error: no member named 'GetPtr' in 'TH1D'

As if h was a pointer to TH1D. But if I try to use it in the classes above (TSpectrum, etc…) I am told that it is not.

Hi Loris,
h is a RResultPtr<TH1D>. That behaves like a pointer (a “smart pointer”, as they are called). In fact it RResultPtr behaves very similarly to a std::shared_ptr.

The -> is to call methods on the pointee, the TH1D. You want to call a method on the RResultPtr<TH1D>, so you need to use a .: h.GetPtr().


1 Like

Of course! What a silly mistake.
Thanks for your patience!

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