Dear experts,
Here is a reproducer of the problem. ( basically a tutorial script with the weight var for RDataFrame → RooDataSet making)
import ROOT
import math
# Set up
# ------------------------
# We create an RDataFrame with two columns filled with 2 million random numbers.
d = ROOT.RDataFrame(2000000)
dd = d.Define("x", "gRandom->Uniform(-5., 5.)").Define("y", "gRandom->Gaus(1., 3.)").Define("weight", "gRandom->Uniform(0.1, 1.0)")
# We create RooFit variables that will represent the dataset.
x = ROOT.RooRealVar("x", "x", -5.0, 5.0)
y = ROOT.RooRealVar("y", "y", -50.0, 50.0)
x.setBins(10)
y.setBins(20)
# Booking the creation of RooDataSet / RooDataHist in RDataFrame
# ----------------------------------------------------------------
# Method 1:
# ---------
# We directly book the RooDataSetHelper action.
# We need to pass
# - the RDataFrame column types as template parameters
# - the constructor arguments for RooDataSet (they follow the same syntax as the usual RooDataSet constructors)
# - the column names that RDataFrame should fill into the dataset
#
# NOTE: RDataFrame columns are matched to RooFit variables by position, *not by name*!
rooDataSet = dd.Book(
ROOT.std.move(ROOT.RooDataSetHelper("dataset", "Title of dataset", ROOT.RooArgSet(x, y))), ("x", "y", "weight")
)
def printData(data):
print("")
data.Print()
for i in range(min(data.numEntries(), 20)):
print(
"("
+ ", ".join(["{0:8.3f}".format(var.getVal()) for var in data.get(i)])
+ ", ) weight={0:10.3f}".format(data.weight())
)
print("mean(x) = {0:.3f}".format(data.mean(x)) + "\tsigma(x) = {0:.3f}".format(math.sqrt(data.moment(x, 2.0))))
print("mean(y) = {0:.3f}".format(data.mean(y)) + "\tsigma(y) = {0:.3f}\n".format(math.sqrt(data.moment(y, 2.0))))
printData(rooDataSet)
I added to the tutorial here ROOT: tutorials/roofit/rf408_RDataFrameToRooFit.py File Reference the case for weighted dataset construction and the code segfault.
rooDataSet = dd.Book(
ROOT.std.move(ROOT.RooDataSetHelper("dataset", "Title of dataset", ROOT.RooArgSet(x, y))), ("x", "y", "weight")
)
following what suggested in ROOT: RooAbsDataHelper< DataSet_t > Class Template Reference but apparently the Book call is unhappy when Argset content do not match columns length in python.
Is there a pythonization which is not correctly loaded here?
Thanks in advance renato