Weighting RooDataset - Distribuition is not expected after the weighting

Hello. I am using root_v6.20.00

I have a branch “PUWeight” that has different values for each event.
So i tried the fallowing implementation:

RooDataSet* data = new RooDataSet("data","data",t1_data,arg_list);
RooRealVar PUWeight = *(ws.var("PUWeight"));
RooRealVar* w = (RooRealVar*) data->addColumn(PUWeight);

where “ws” is a worksapce.

In this point the RooDataSet seems to be weighted (I used the command “Print()” to confirm that).
But when compare a distribution (invariant mass e.g) before and after the weighting, the distribution seems only multiplied by a constant c=5. I expected a slightly different distribution, because each event has a different weight value.

Is my implementation wrong for this case?
Thank you for your attention.

Hi @Raphael_Souza,

you need to tell the dataset that you want a weight variable. Your variable PUWeight looks like a fit variable to RooFit.
Weights are used in e.g. the tutorial rf611:
https://root.cern.ch/doc/master/group__tutorial__roofit.html

What’s important is to tell using WeightVar(<variable | name>) what should be used for weighting. You can verify by doing something like

data->get(0)->Print("V"); // For printing fit variables
std::cout << data->weight() << std::endl;
data->get(1)-> [...]

Also note that

RooRealVar PUWeight = *(ws.var("PUWeight"));

creates a copy of the variable object. Maybe you wanted to get a reference to it?

RooRealVar& PUWeight = *(ws.var("PUWeight"));

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.