RooFit: problem in replacing the deprecated SetWeightVar

Hello,

I recently moved from root 5.22 to root 5.26 and I am unable to make some code work because of the deprecation of RooDataSet->SetWeightVar. And I don’t know how to adapt the code with the use of the WeightVar() argument, because I do not use the RooDataSet constructor, but the RooDataSet::read() method.
Here is a short example that was working before:

  RooRealVar *myVar = new RooRealVar("myVar","myVar",-100,100) ;
  RooRealVar *weightVar = new RooRealVar("weight","weight",0.,200.) ;
  RooRealVar *weightVar2 = new RooRealVar("weight2","weight2",0.,200.) ;

  RooDataSet* ds = RooDataSet::read(fileName, RooArgList(*myVar, *weightVar,  *weightVar2),"Q") ;
  RooFormulaVar *weightVar3 = new RooFormulaVar( "weight3", "", "@0*@1", RooArgList(*weightVar, *weightVar2));
  ds->addColumn(*weightVar3) ;

In root 5.22, it was very easy to give the weight weightVar3 to the dataset ds:

  ds->setWeightVar(*weightVar3) ;

But how to perform the same thing in root 5.26 (roofit 3.12)? How to give a weight with a variable which was not originally in the dataset?
I tried to import the dataset in a new one, and putting WeightVar(*weightVar3) in the constructor:

  RooDataSet* ds2 = new RooDataSet("ds2","ds2",RooArgList(*myVar, *weightVar3),Import(*ds),WeightVar(*weightVar3));

But this does not work because weightVar3 is of the type RooFormulaVar and I obtain this error message:
“Data set cannot contain non-fundamental types, ignoring weight3”

I would appreciate any help on this…

Thanks,

Vincent.

Hi Vincent,

You can do this as a two-step operation: First you add your function weight3 to the dataset as a variable

RooRealVar* weight3_var = (RooRealVar*) data->addColumn(weight3) ;

Then you can make a new dataset that interprets the weight3 object (now a variable) as a weight

RooDataSet* ds2 = new RooDataSet(“ds2”,“ds2”,RooArgList(*myVar,*weightVar3_var),Import(*ds),WeightVar(*weightVar3_var));

Wouter