I have a question about rdataframe histogram handling.
I know that Histos1D() method is lazy, but what happens if I do h1D.SetName() or something similar ? Will this action trigger the Histos1D() method or not ?
Hi @imanol097 ,
yes, that will trigger the event loop. You can however pass to Histo1D a TH1 model that already has the correct name so you don’t have to call methods on the result later.
The order w.r.t. Draw does not matter for what concerns RDF’s event loop.
You just have to make sure to tell RDataFrame about all the results you want to produce before you access any of them (calling a method on a result counts as accessing it, because then the result must be generated in order to call the method on it).
So do this:
x = df.Histo1D("x")
y = df.Histo1D("y")
x.SomeMethod(...) # event loop runs here
y.SomeMethod(...)
and don’t do this:
x = df.Histo1D("x")
x.SomeMethod(...) # event loop must run here
y = df.Histo1D("y")
y.SomeMethod(...) # event loop must run again here
You can use df.GetNRuns() to check how many event loops your df object ran.
I see that after drawing histograms doing Snapshot to these variables adds one extra event loop. Is there a way to print histograms and snapshot these variables in one single loop ?
The reason is that drawing the histograms triggers the event loop, and then when you call Snapshot another event loop must be started to perform that operation.
The workaround is simple, it’s enough to call the Snapshot before drawing the histograms but after booking them.
Unrelated, but note that Snapshot is a bit special in that by default it’s not lazy: it triggers the event loop on the spot. You can make it lazy with the appropriate option parameter.