Home | News | Documentation | Download

Combining multiple individually weighted RooDataSets?

Hi all:

I am currently trying to convert two TTrees into RooDataSets, weight each of the datasets individually with a constant factor, then combine the datasets. My code resembles:

RooDataSet ds_global_MC("ds_global_MC", "ds_global_MC", varset);
int test = 0;

for (int i = 0; i < {list of 2 TTrees}; i++) {

RooDataSet* ds_local_MC = new RooDataSet("k", "k", varset, Import(*Fit_Tree_MC));

        if (test==0) {
        if (test==1) {
        RooRealVar* w = (RooRealVar*) ds_local_MC->addColumn(scale);
        RooDataSet wdata(ds_local_MC->GetName(),ds_local_MC >GetTitle(),ds_local_MC,*ds_local_MC->get(),0,w->GetName()) ;

        test = test + 1;
RooDataSet ds_final("f","f",varset,Import(ds_global_MC),WeightVar("scale"));

where scale is defined earlier as RooRealVar scale1("scale","scale",1.,0.,100.).

However, when I plot ds_final, the resulting histogram is as if the weight / scaling factor was set to 1.0 for both datasets, despite the fact that printing out scale.getValV() confirms that I am able to change the value of the scale variable.

Thank you!

I think @StephanH can most probably help you with this

Hi @rrm,

you can use RooDataSet::Print("V") to check whether the scale variable has been picked up by the relevant datasets.

  • Is scale in varset that’s used to create ds_global_MC?
    If it’s not, it will not be considered during append.
  • I hope it’s scale and not scale1? If not, that could be the problem.

  • Also try


to dump the values of the variables. Until you create ds_final, scale should just be a variable that’s mentioned in the printouts. For ds_final, it should be mentioned that it’s a weight variable.

Hi @StephanH,

Yes, scale is in the varset used to create ds_global_MC – sorry for not making that clear before! Additionally, the scale1 was a typo, so the variable is defined as RooRealVar scale("scale","scale",1.,0.,100.).

If I run the following in the for loop:


the printout includes

12) RooRealVar::             scale = 1

However, when I run the code


after creating the ds_final dataset, the lines corresponding to the scale variable are missing! This is quite interesting as when I create ds_final, I include the argument WeightVar("scale") – that should set the weight variable, correct?

Thank you!

Some additional information:

  1. When I run the line ds_global_MC.get(0)->Print("V");, the returned value for the scale is always the value that was used to initialized RooRealVar scale1("scale","scale",1.,0.,100.) (i.e. the value in the 3rd argument).

  2. If I run the line std::cout << scale.getValV() << std::endl; immediately before the line RooRealVar* w = (RooRealVar*) ds_local_MC->addColumn(scale); in my original codeblock, I get 0 or 1, depending on the value of test.

  3. If I plot ds_global_MC, the histogram shows no scaling regardless of my initial value for scale. If I plot ds_final, the histogram is scaled using the value that I chose to initialize the variable scale. This seems to contradict what I said in my last post, as I mentioned that the output ds_final.get(0)->Print("V"); contains no information about scale.

Ok, I think I need to run it myself to spot the problem. Could you condense it into a little script that e.g. adds only one variable and the weight?

Hi @StephanH:

This script reproduces all the issues that I mentioned above.

Thank you!

tester.C (3.3 KB)

Ok, it wasn’t easy, but here’s what needs to be done:

  • All datasets (the final one and the ones you use for merging) need to have a WeightVar(scale) set.
  • You need to change the value of scale before you create the intermediate datasets. Since the original data that you Import() from don’t have values for scale, it just retains the value that it had before the dataset was created.
  • Then append to the global dataset.

Side note:
The usual syntax for getting a value is getVal(). getValV() is only if you really want that the object recomputes its value. It does that automatically, though, if necessary.

And here’s a working example:
tester.C (2.9 KB)

Works exactly as I wanted it to, thank you very much for your help!