RooFit - weights change histogram content

Hi,

When running the simple macro below I get different
number of entries for the histogram that I extract from
data and the one that I plot from data. That happens
when I set a weight variable different from one.

void test()
{
gSystem->Load(“libRooFit”);
using namespace RooFit;

// Build Gaussian PDF
RooRealVar mass (“mass”,“mass”,0,5);
RooRealVar mean (“mean”,“mean of gaussian”,-1);
RooRealVar sigma(“sigma”,“width of gaussian”,3);
RooGaussian gauss(“gauss”,“gaussian PDF”,mass,mean,sigma);

// Generate a toy MC set
RooDataSet* data = gauss.generate(mass,20000);

// Set weight
RooRealVar weight(“weight”,“weight”,0.11);
data->addColumn (weight);
data->setWeightVar(weight);

// Create histogram
TH1F* massHist = mass.createHistogram(“massHist”);
data->fillHistogram(massHist,RooArgList(mass));

// Draw
TCanvas* c1 = new TCanvas(“c1”,“c1”);

RooPlot* frame = mass.frame();
data->plotOn(frame,DrawOption(“pz”));
frame->Draw();

massHist->SetLineColor ( kRed+2);
massHist->SetLineStyle ( kDotted);
massHist->SetLineWidth ( 3);
massHist->SetMarkerColor( kRed+2);
massHist->SetMarkerStyle(kOpenTriangleUp);

massHist->Draw(“pz,same”);
}

Does anyone know how to fix this difference?

Besides, when plotting data I get

[#0] WARNING:Plotting – gaussData_plot__mass::roundBin: rounding non-integer bin contents: 9.68
[#0] WARNING:Plotting – gaussData_plot__mass::roundBin: rounding non-integer bin contents: 6.82
[#0] WARNING:Plotting – gaussData_plot__mass::roundBin: rounding non-integer bin contents: 5.94

How do I get rid of these warnings?

Thanks,
Jonatan

Hi,

When you have a dataset with weighted entries (i.e not Poisson statistics)
you should draw your histogram with ‘sum-of-weights^2’ errors, which is done as folllows

data->plotOn(frame,DrawOption(“pz”),DataError(RooAbsData::SumW2));

Wouter