{ using namespace RooFit; RooRealVar x("x","x",-5.,5.); RooRealVar w("w","w", 0.,1.); RooDataSet data("data","nomial data",RooArgSet(x)); RooDataSet data_wgt("data_wgt","weighted data",RooArgSet(x,w),"w"); TRandom3 rnd; for (int i=0;i<1000;i++) { x.setVal(rnd.Gaus(0.,1.)); data.add(x); x.setVal(rnd.Uniform(-5.,5.)); data_wgt.add(x,TMath::Gaus(x.getVal(),0.,1.)); } RooRealVar mu("mu","mu",0.,-0.5,+0.5); RooRealVar sigma("sigma","sigma",1.,0.8,1.2); RooGaussian gaus("gaus","gaus",x,mu,sigma); TCanvas *c1 = new TCanvas("c1","c1",400,800); c1->Divide(1,2); c1->cd(1); gaus.fitTo(data,Minos(true)); RooPlot* frame1 = x.frame(); data.plotOn(frame1); gaus.plotOn(frame1); frame1->Draw(); c1->cd(2); gaus.fitTo(data_wgt,Minos(true)); RooPlot* frame2 = x.frame(); data_wgt.plotOn(frame2); gaus.plotOn(frame2); frame2->Draw(); }