Hi,
I am having a problem when saving a RooDataSet to a RooWorkspace: In the RooDataSet that I retrieve from the RooWorkspace, the weight of all the events are set to the weight of the last event (instead of different weights that i assign per event). I found that it’s not really related to the RooWorkspace, the problem appears already when calling the copy constructor of RooDataSet.
The following code fills a dataset containing a single variable (+a weight) with values from 0 to 100. Events with value less than 80 are given 0 weight. It then produces a plot of the variable. This plot has the correct weights. It then copies the dataset, and plots the variable again, and then all the events have weight 0.9 (like the last event). If I invert the condition, and set the weight of all events with value > 80 to 0.0, then all events in the second dataset have 0 weight.
{
RooRealVar* Variable = new RooRealVar("Variable", "a simple variable, values 0 to 100", 0.0, 100,
"GeV" );
RooRealVar* weight = new RooRealVar("weight", "weight", 0.0, 1.0 );
RooArgSet* ArgSet = new RooArgSet("args");
ArgSet->add(*Variable);
ArgSet->add(*weight);
DataSet = new RooDataSet("dataset", "A dataset", *ArgSet, "weight");
// Fill all integers from 0 to 100
for (int i=0; i < 100; i++) {
Variable->setVal((double)i);
double w = 0.9;
// Set weight of entries with value < 80 to 0.0
if (i < 80) w = 0.0;
DataSet->add(*ArgSet, w, 0);
}
// Show distribution before putting it in to workspace
new TCanvas("c1", "Before import/export cycle");
RooPlot* DPlot = Variable->frame(RooFit::Title("plot (1)"));
DataSet->plotOn(DPlot);
DPlot->Draw();
// Save the RooDataSet in a RooWorkspace, then retrieve it
//RooWorkspace workspace("ws", "a workspace");
//workspace.import(*DataSet);
//workspace.import(*weight);
//workspace.Print();
//RooRealVar* Variable2 = (RooRealVar*)workspace.var("Variable");
//RooDataSet* DataSet2 = (RooDataSet*)workspace.data("dataset");
// Alternatively, just call the copy constructor
RooDataSet* DataSet2 = new RooDataSet(*DataSet);
RooRealVar* Variable2 = (RooRealVar*)DataSet2->get()->find("Variable");
// Plot DataSet2 on a new canvas
new TCanvas("c2", "After import/export cycle");
RooPlot* D2Plot = Variable2->frame(RooFit::Title("plot (2)"));
DataSet2->plotOn(D2Plot);
D2Plot->Draw();
}
Am I doing something wrong (quite possibly) , or is this a bug?
Thanks ,
Marius
PS: This was also posted to the root-talk mailing list, but I hope that someone here could help.