Filing weighted Histo1D with vectoor of floats in RDataFrame


When I try to create a Histo1D using event weights, I get a segfault.
However, if I don’t use event weight there’s no crash. Is there a way to get around the problem? The tree with floats is provided by the experiment, so I can’t remake the trees with doubles.

Histo1D({“hjetpt”, “Passing jet pt” , 50, 0.0, 2000.0}, “Sel2_jetpt”, “evWeight”)

relevant error message might be:
/home/suyong/work/Tools/root-6.15/etc/…/include/ROOT/RDF/ActionHelpers.hxx:259:9: note: candidate function not viable: no known conversion from ‘ROOT::VecOps::RVec’ to ‘double’ for 2nd argument
void Exec(unsigned int slot, double x0, double x1) // 1D weighted and 2D histos

_ROOT Version: 6.15.01
_Platform: Linux
_Compiler: gcc 6.4.1


Hi Suyong,
could it be that the problem is that "Sel2_jetpt" is a single double and "evWeight" is an array?


if yes, the issue is that RDF can’t deal with this case. If what you intended was to weight the single "Sel2_jetpt" value with each of the weights in "evWeight", you can do it with df.Define("weighted_jetpt", "Sel2_jetpt*evWeight").Histo1D(...) (because in the Define evWeight is read as an RVec which allows element-by-element multiplication by a scalar

Hi Enrico,

Actually, “Sel2_jetpt” is a vector of floats (not doubles) and “evWeight” is a single number per event. What I wanted is what I would do in C++ as
for (auto i=0; i<Sel2_jetpt.size(); i++)
hjetpt->Fill(Sel2_jetpt[i], evWeight);

I was thinking the error occurred because Sel2_jetpt is vector of floats rather than doubles.


So the workaround I describe above should apply.

Histo1D only supports values and weights with the same length (either both scalars or both arrays of the same length).

The error message does hint to that fact but it should be much clearer, I’ll see what I can do about that.


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

Dear Suyong,

the workaround should not be needed any more when using the master and 6.16 patches branch since the support of filling with iterable column values with scalar weights has been implemented ( This feature will be part of ROOT 6.18 and 6.16/02.