I have the variables md0, md0pi, and weight in my ntuple. I want to create a weighted dataset of md0 and md0pi variables using weight. and do a 2d fit of md0 and md0pi.
I am trying like, below:
RooDataSet * dataxy = new RooDataSet(“dataxy”,“dataxy”, tree, RooArgSet(mD0, mD0pi, weight));
and in the fit results:
RooFitResult *fitresult = model.fitTo(*dataxy, Save(true), Strategy(2), Extended(true), RooFit::SumW2Error(true));
When creating a weighted dataset, you need to specify the weight variable in the constructor of RooDataSet. However, it seems like you might not have declared the weight as a RooRealVar and included it in your RooArgSet.
Try something like this:
RooRealVar weight("weight", "weight", 0, 100); // Adjust the range as needed
RooDataSet *dataxy = new RooDataSet("dataxy", "dataxy", RooArgSet(mD0, mD0pi, weight), WeightVar(weight));
However, this constructor doesn’t take the tree directly, but you need to use the Import(tree) command argument as explained in the docs that I linked.