RDataFrame Histo2D filling with RVec's

Dear All,

I have to fill a 2D histogram where one variable is an int and the other a RVec.
For example “Number of tracks” and pT of these tracks. I want the pT vs NTracks 2D HIstogram.

Is there a way to do this in RDataFrame? I guess that I could define a new variable like NTracks but as a RVec to have same datatype in both variables. Is it possible to fill Histo2D with RVec’s ?

Kind regards,

Please read tips for efficient and successful posting and posting code

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

Hi @imanol097 ,
you haven’t provided your ROOT version, but until v6.24 there were some limitations in mixing scalars and RVecs when filling histograms (some combinations would work, other wouldn’t). E.g. this should be possible in v6.24:

  .Define("i", "2")
  .Define("v", "ROOT::RVec<double>{1.,2.,3.}")
  .Histo2D({"", "", 100, 0, 5, 100, 0, 5}, "v", "i")->DrawClone("LEGO")

Since v6.26, all combinations should work, e.g. this (which was not allowed in v6.24, and the workaround would have been to Define an RVec column as "RVec<double>(v.size(), i)"):

ROOT::RDataFrame(10).Define("i", "2").Define("v", "ROOT::RVecD{1.,2.,3.}").Histo2D({"", "", 100, 0, 5, 100, 0, 5}, "i", "v")->DrawClone("LEGO")


I am using 6.24/06 in PyROOT. But it is not working

as mentioned some combinations of scalar/vectors were not allowed in 6.24, you are probably encountering one such case. The constraints are lifted in v6.26.

A workaround for v6.24 is to manually broadcast the scalar to a vector with an expression such as ROOT::RVec<double>(scalar, vector.size).


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