Loop counter and log10 of a variable

Hi everyone,

I started working with TDataFrame but I have two questions:

  1. Is there a way to print on the terminal some kind of iterator that show me the status of the event loop ? I’m running in multithreading
  2. If I have a branch of my TTree called “Energy” and i want to plot the log10(Energy) in a TH1D how I can do it ?
    Because if I try something like:
    auto myHisto = d.Histo1D(“log10(Energy)”);
    The error is that “log10(Energy)” is not a branch of the TTree

(this is the first time that I write something in this forum so maybe I’m doing something not in the proper way)

Hi Federico,
you did everything the proper way, your question is very clear and already tagged as #tdataframe.

Printing status of the event loop
There are a few different ways to do this.
In C++, the easiest and most robust is via TResultProxy::OnPartialResult.
A TResultProxy is the pointer-like object that all of TDF actions return: for example, d.Histo1D returns a TResultProxy<TH1D>. OnPartialResult is a method that registers a function that is to be called on the contents of the TResultProxy every N processed entries.

Things should be clear with an example:

// print "hello" every 100 processed entries
auto h = tdf.Histo1D("x");
auto printHello = [](TH1D&) { std::cout << "hello" << std::endl; };
h.OnPartialResult(100, printHello);
h->GetNEntries(); // event loop is run here, when we use the result for the first time

As per the docs, in a multi-thread execution OnPartialResult is only called by one of the threads, so it will just give you a rough idea of how far the event loop went. You can also check $ROOTSYS/tutorials/dataframe/tdf013_InspectAnalysis.C for a nicer example usage of OnPartialResult, also in a multi-thread application – there we plot the result histogram and update it every 50 entries dynamically.

Histogram of the log10 of a variable
This is very easy, you need to define a new column with the logarithm of your energy variable:

auto hlog10 = tdf.Define("log10E", "log10(Energy)").Histo1D("log10E");

If you are using python instead answer number 1 is to be revised a bit.
Hope this helps!


Thank you very much !!
This is exactly what I needed !

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