[RooFit] RooDataSet loses weight info when Clone'd

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.

Hi Marius,

What version of ROOT are you using? I just tried your script within ROOT v5.27/06 and it ran fine for me (produced two identical plots at least).

I believe there is a bug in v5.26 with the weight handling in RooDataSet:

[url][RooFit]: random weights when doing RooDataSet->append?

It could well be that this is the cause of the problem you are seeing.

Regards,
Andrew

Hi Andrew,

Thanks a lot for the info, which actually solves the problem! I am using v5.26/00c, with the LHCb software, but I have to find some way to use a newer ROOT.

Cheers,
Marius

Hi Marius,

Glad that solved the problem.

Sorry, I didn’t know I was talking to a fellow LHCb collaborator. I, too, have the issue that v5.27 is not installed in the LHCb LCG stack. If you’re running at CERN, or have access to AFS, then you can at least setup v5.27 through these instructions:

http://root.cern.ch/drupal/content/development-version-52706

If you’re writing code, like I am, within CMT then this sadly doesn’t solve the problem that v5.27 is not within the LHCb framework.

Regards,
Andrew

Thanks again Andrew,

I’m just writing a stand-alone ROOT file to analyse an NTuple, so I can use that link. I used to do SetupProject DaVinci, but that’s not really necessary.

Cheers,
Marius