H1D modifications are lazy in rdataframe?

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 ?

Thanks


Please read tips for efficient and successful posting and posting code

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


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.

Cheers,
Enrico

I see, thanks.
Yes but things like LikeColor cannot be implemented in the model right ?

Correct! You have to defer those calls to until after you have booked all the results in RDF to produce all results in a single event loop.

Which are the best practices in order to do this operation in one single event loop? Do histogram aesthetic modifications after Draw it ?

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.

Cheers,
Enrico

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.

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