RooFit: Weights lost when saving a RooDataSet to a RooWorkspace

From: Marius Bjørnstad <paul.bjoernstad_at_hep.manchester.ac.uk>
Date: Mon, 22 Nov 2010 15:05:52 +0100


Hi fellow ROOTers,

I don't know if it's OK to post RooFit questions here, if not, you can ignore this.

I am filling a RooDataSet by inserting each data point manually. I have a weight assigned to each data point. When I save the RooDataSet to a RooWorkspace, and then retrieve it from the workspace, the weight information is lost. The weight of all the data points is set to the weight of the last data point. I have created a minimal code to reproduce this. The code fills a variable called "Dmass" with all the integers from 0 through 100. The weight of data points with Dmass < 80 is set to 0.0, and the weight of the other data points is set to 0.9. The distribution of Dmass is plotted before and after saving it to the RooWorkspace.

{
  RooRealVar* Dmass = new RooRealVar("Dmass", "M-M(#mu#mu)", 0.0, 100, "GeV" );
  RooRealVar* weight = new RooRealVar("weight", "weight", 0.0, 1.0 );   RooArgSet* ArgSet = new RooArgSet("args");   ArgSet->add(*Dmass);
  ArgSet->add(*weight);
  DataSet = new RooDataSet("dataset", "A dataset", *ArgSet, "weight");

// Fill all integers from 0 to 100 as mass
  for (int i=0; i < 101; i++) { Dmass->setVal((double)i);     double w = 0.9;
    // Set weight of entries with mass < 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* DMassPlot = Dmass->frame(RooFit::Title("DMass (1)"));   DataSet->plotOn(DMassPlot);
  DMassPlot->Draw();

// Save the RooDataSet in a RooWorkspace, then retrieve it
  RooWorkspace workspace("ws", "a workspace");   workspace.import(*DataSet);
  workspace.Print();
  RooRealVar* Dmass2 = (RooRealVar*)workspace.var("Dmass");   RooDataSet* DataSet2 = (RooDataSet*)workspace.data("dataset");

// Plot DataSet2 on a new canvas

  new TCanvas("c2", "After import/export cycle");   RooPlot* DMass2Plot = Dmass2->frame(RooFit::Title("DMass (2)"));   DataSet2->plotOn(DMass2Plot);
  DMass2Plot->Draw();
}

I have done some experimentation with how to create/retrieve the RooRealVar for plotting the second dataset, but I always get the same result. If the condition in the if (i < 80) is inverted, all the weights in the second plot are set to 0.0. Is this a bug, or am I doing something wrong?

Thanks,
Marius

Received on Mon Nov 22 2010 - 15:06:08 CET

This archive was generated by hypermail 2.2.0 : Mon Nov 22 2010 - 23:50:01 CET