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) {
scale.setVal(0.0);
}
if (test==1) {
scale.setVal(1.0);
}
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()) ;
ds_global_MC.append(wdata);
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.
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.
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.).
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?
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).
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.
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, 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 scalebefore 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.