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?
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().