Deprecation of setWeightVar()

I was using setWeightVar but it has been removed from version 5.25/05
Why was it not deprecated, so we’d have time to bring our programs up to date?
It seems I am always struggling with backwards compatibility in ROOT.

Here is a snippet of my code:

  RooArgSet dataVarSet;
  RooDataSet* data_temp;
   //This way used to work, but the function has been removed from roofit
   //data_temp = new RooDataSet("input tree", "input tree", tree1, dataVarSet);

   //The new way doesn't work--- all weights = 1
   data_temp = new RooDataSet("input tree", "input tree", tree1, dataVarSet, 0, "weight");


Many thanks,

For new packages in ROOT (like Roofit) the authors have still to realize that they are not any more the only users of their systems ::).

You said:

[quote]It seems I am always struggling with backwards compatibility in ROOT
Could you give examples where you had to suffer from back incompatibilities?


Thank you for your quick reply.

I will be sure to post them on the root talk forum from now on, when I encounter them. I have since solved the ones I found in the past, so no longer have examples.

Now I am struggling with setting the proper weight in a RooDataSet.
To be more specific:

     TH1F *h = new TH1F("h", "histo of weights", 300, 0, 299);
     int sumX = (int) h->Integral();
     cout<<"sumX = "<<sumX<<endl<<endl;

     int sumXW = (int) h->Integral();
     cout<<"sumXW = "<<sumXW<<endl<<endl;
     delete h;

with output:
TCanvas::MakeDefCanvas: created default TCanvas with name c1
sumX = 100197
sumXW = 6507395

Then with this code:

     cout<<"Retrieving Data from the tree...\n";
     data_temp = new RooDataSet("input tree", "input tree", tree1, dataVarSet, 0, "weight");
     cout<<"Is weighted:"<<data_temp->isWeighted()<<endl;
     cout<<"Print after setting weight\n";

I get this output:

Retrieving Data from the tree…
[#1] INFO:Eval – RooAbsReal::attachToTree(weight) TTree Float_t branch weight will be converted to double precision
[#1] INFO:Eval – RooAbsReal::attachToTree(x) TTree Float_t branch x will be converted to double precision
[#1] INFO:Eval – RooTreeData::loadValues(input tree) Ignored 95145 out of range events
Is weighted:1
Print after setting weight
RooDataSet::input tree[x,weight:weight] = 97343 entries (97343 weighted)
Entries = 97343

As you can see, the RooDataSet thinks it is weighted, with weight “weight” but I get " 97343 entries (97343 weighted)" and the output above proves that “weight” is not always equal to 1.

I appreciate any help,


I’m generally extremely reluctant to make non-backward compatible
changes to RooFit code (the number of instances in the past 10 years
can be counted on one hand).

In this particular case it is necessary as part of the general reorganization of RooFit dataset structures that will bring many good things (optimized performance, more features and flexibility). The completely new internal storage design makes it extremely difficult to support dynamic weight changes (i.e. after object construction), hence that feature is dropped.

Almost all use cases of setWeightVar() that I know usually intent to set once what the weight variable is (rathing than intending to make a change half way the life span of a dataset), which can also be accomplished by the WeightVar() modifier in the RooDataSet constructor, e.g.

RooDataSet d(“d”,“d”,RooArgSet(x,w),WeightVar(w)) ;

will be a functional replacement of your existing code and will continue to work indefinitely (this constructor form also exists since quite a while)

At the suggestion of Rene, I have restored setWeightVar() as a dummy function to retain binary compatibility. Calling it will print an error message (and the above replacement suggestion) as well as throw an exception to make sure that the deprecation will not go unnoticed.

My apologies for the inconvenience that this migration causes.



I’ve tried the to use the new form to set the weight for a RooDataSet, and it worked with ROOT 5.24 (RooFit 3.00). However, after I updated to ROOT 5.26 (RooFit 3.12), weights are no longer applied when I draw a histogram.

The following macro demonstrates it. I create a TTree with some data and weights and draw it to two pads. The first pad has the tree without weights, and the second with weights. Then I import it into a RooDataSet, set a weight variable and draw it to both pads. The idea is that if weights were applied to the RooDataSet, then the plots in the second pad should match up. In ROOT 5.24, this works as expected. But in ROOT 5.26, the graphs in the first (unweighted) match up instead.

#include "TTree.h"
#include "TCanvas.h"

#include "RooRealVar.h"
#include "RooArgSet.h"
#include "RooDataSet.h"
#include "RooPlot.h"
using namespace RooFit;

void rooweighttest()
  /* Create some data */
  double weight;
  double var;
  TTree *tree=new TTree();
  for(int i=0;i<10;i++)

  /* Import TTree into RooFit */
  RooRealVar roovar("var","Variable",0,100);
  RooRealVar rooweight("weight","Weight",0,100);
  RooArgSet variables;
  RooDataSet data("roodata","roodata",variables,WeightVar(rooweight),Import(*tree));
  RooPlot *frame=roovar.frame();

  /* Draw some stuff to test if weighting worked */
  TCanvas *c=new TCanvas("c","c",600,800);


Hi Karol,

Oops! Please use WeightVar(“w”) instead of WeightVar(w).

Both forms exists, but the latter seems to be affected by a silly bug as I just discovered. Thanks for reporting this, I’ll fix this a.s.a.p and please use the other form for now.



Using WeightVar(“weight”) instead of WeightVar(rooweight) does not seem to work either.

On 5.24.00b, it works as expected.
On 5.26.00, the Roo plots are not being draw at all.

Hi Karol,

Hmm, the 5.26 regression tests on weighted datasets ran fine…
I’ll investigate this this tomorrow and get back to you.


Hi Karol,

The combination of WeightVar() with Import(TTree&) specifically seems broken.
The combination with Import(RooAbsData&), which is tested in my automated regression test, works OK.

I’ll fix the probem a.s.a.p (now filed in Savannah as ticket #60771), thanks again for reporting this, and my apologies for the inconvenience.

As Import(RooAbsData&) works OK, you can work around this bug for now as follows

RooDataSet tmp(“tmp”,“tmp”,variables,Import(*tree));
RooDataSet data(“roodata”,“roodata”,variables,WeightVar(“weight”),Import(tmp));


Hi Wouter,

as far as I can see there was some recent fix related to the bug. The Savannah ticket is still open. So what is the status? CMS started using RooFit out of 5.26.00, which most likely has the bug and it’s important to understand how significant the issue is and is it limited only to the mentioned case?


Hi Dmitry,

The fix is certainly in the latest ROOT 5.27 cycle. To get it to 5.26 I will need to port it to the patch branch so that it can go in the next 5.26 patch release. Given that bug was isolated, this should not be difficult. Alternatively you should be able to use the latest RooFit with ROOT 5.26 (I believe CMS has a mechanism to support this)