I’m trying to read a TTree through the new TDataFrame interface (using the ROOT prompt).
The basic functionality are working but I’ve not been able to plot only a specific entry from an array stored inside a Branch.
I’m assuming the syntax is the same as in TTree::Draw (i.e. “myarray[0]” to access the first entry, etc…) but it’s not working neither with TDataFrame::Histo1D nor TDataFrame::Fill.
The error I get in both case is:
ROOT::Experimental::TDataFrame df(“eb”, “history_EB_Run2016_v2.root”)
auto h = df.Histo1D(“lc[0]”)
Error in TRint::HandleTermInput(): std::runtime_error caught: Column “lc[0]” is not in a file and has not been defined.
Of course TTree::Draw(“lc[0]”) works properly on the same tree.
I also tried to Define a new column as:
df.Define(“lc_0”,(float lc[2]){return lc[0];},{“lc”})
but plotting “lc_0” resulted in a crash.
What should I do to read the array entry?
Thank you,
Simone
PS: I’m running ROOT 6.10/02 compiled with gcc 7.1.1
the argument of the Histo1D method you are invoking is the name of the column: no accessors are accepted there.
The way in which you can obtain the first element of the array is “functional”: a new, different column needs to be created and then plotted.
For example:
auto h = tdf.Define("lc_0", [](std::array_view<int> lc){return lc[0]}, {"lc"}).Histo1D("lc_0");
h->Draw();
We are aware of the burden the definition the full blown lambda imposes to users . This is the reason why starting from ROOT 6.12 (expected in November) the line above could be squeezed into this one:
auto h = tdf.Define("lc_0", "lc[0]").Histo1D("lc_0");
h->Draw();
The technical reason behind this is that one needs to be able to detect that lc is an array and not a simple pointer. By the way, if you like bleeding edge stuff, the functionality is available in the ROOT master already.
I am not sure I get the problem correctly, but it’s not true that you cannot draw multiple hisos hanging from the same Define: it’s an objective by design!
The TDataFrame is not a chain but rather a graph of nodes.
So the computation setup would be like this:
[...]
auto dft_d = dft.Define("newvar", "expr");
auto h1 = dft_d.Histo1D("newvar");
// inventing an hypothetical weight column
auto h1 = dft_d.Histo1D("newvar","newvarweight");
// new we hang an hypothetical filter to the Define node and a histo to it
auto dft_df = dft_d.Filter("newvar > 2");
auto h3 = dft_df.Histo1D("newvar");
Cheers,
D
PS
TDF is rather sturdy and not work in progress. The Experimental namespace signal that (minimal) interface changes might occour. It’s a bit like std::experimental