RDataFrame Book questions


ROOT Version: 6.26/00
Platform: CentOS
Compiler: gcc 8.5


Hi,

I have a number of questions regarding the Book function of RDataFrame. I finally managed to do what I wanted to do (read custom classes from a tree and fill multiple histograms using those classes) by creating a helper-class that creates and fills those histograms (loosely based on the tutorial df018, but returning a TList with TH1* and TH2*). There are however a few issues I came across:

  • Unlike the tutorial (which uses THn histograms) I use TH1 and TH2 histograms and get warnings about potential memory leaks because the histograms all have the same name for each slot. The results however look correct, so there doesn’t seem to be any real issue with this. My questions is whether there is a way to turn these warnings off, or is this an actual issue that I should solve (e.g. by appending the slot number to each histogram name)?
  • I tried printing out a status bar as shown in one of the tutorials, but the code fails with a logic error because “This action does not support callbacks!”. Is there a way to show the progress of the Book action? Also is there a way to display the percent of entries processed instead of a progress bar?
  • Is this the correct way of using the Book action? Meaning is there a huge difference between creating and filling histograms in the Book action instead of using Histo1D or Histo2D combined with defining custom columns calculated from the branches of the input tree?

Thank you for any tips!

I’m sure @eguiraud will be happy to help you!

Hi @vaubee ,

  • the warnings are due to histograms with the same name being added to ROOT’s global lists of objects, and they are harmless if you manage the lifetime of your TH1s and TH2s (as in, you allocate them and deallocate them yourself or through smart pointers or RAII and you don’t need ROOT to do that for you). If you don’t need ROOT to manage the lifetime of your histograms and you don’t need to register these histograms with ROOT’s global lists of things, you can avoid the warnings by adding the line TH1::AddDirectory(false); before the creation of the histograms (and possibly returning the program to the default state with TH1::AddDirectory(true) afterwards
  • you can attach a callback that prints a progress bar to a dummy Count action that you create just for this purpose. You can display anything you want as part of the callback function (you can execute arbitrary logic in there after all), but to display a percentage you will have to retrieve the total number of entries beforehand, separately. However you might be happy to know that this summer we are working on adding a progress bar feature to RDF itself
  • yes, this is a valid use for Book and it should not be much slower than Histo1D or Histo2D (except for the fact that you are filling more than one histogram). If that’s not the case we can take a better look at the implementation of your custom action. I also want to point out the Fill action as a potentially simpler alternative to Book (Fill only requires an object that implements a Fill and a Merge method, while Book’s required API is larger as you know).

Cheers,
Enrico

Thank you for the clarifications @eguiraud. I will definitely put the line in to turn those warnings off and use the Count action to create a progress bar (maybe with percentages).
I will have a look at the Fill action as an alternative to Book.

Cheers,

Vinzenz

One more question about the progress bar, how do I access the current event that is being processed to display a percentage of events processed? I searched the tutorials and this forum but came up empty, all the examples use a simple progress bar.

You cannot access the current event number from the callback, but the callback can count how many times it’s being called and that gives you the amount of events that have been processed so far (after you multiply it to the every_n_events parameter you pass to OnPartialResult).

I see, makes sense. Thanks for the quick and helpful response!

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