{ using namespace RooFit; gROOT->ProcessLine(".L ../../RooTH1Var.cxx+"); //Construct a TH1 histogram of weights const int nBins = 60; TH1F *histo = new TH1F("histo","histo",nBins,0,3); Double_t dat[nBins] = { 6, 1,10,12, 6,13,23,22,15,21, 23,26,36,25,27,35,40,44,66,81, 75,57,48,45,46,41,35,36,53,32, 40,37,38,31,36,44,42,37,32,32, 43,44,35,33,33,39,29,41,32,44, 26,39,29,35,32,21,21,15,25,15}; for(int i=0; i < nBins; i++) histo->SetBinContent(i+1,dat[i]); // Declare observable RooRealVar p("p","p",0,3) ; p.setBins(40) ; // Construction a uniform pdf RooPolynomial p0("pp","pp",p) ; RooRealVar sig("sig","sig",0,10); RooRealVar mean("mean","mean",0,10); // Sample 1000 events from pdf RooDataSet* data = p0.generate(p,10000) ; TH1 *histo_Cloned=histo.Clone(); //Construct the RooFit variable from histogram of weights along p RooTH1Var weightVar("weightVar","weightVar",histo_Cloned,p); // C a l c u l a t e w e i g h t a n d m a k e d a t a s e t w e i g h t e d // Add column with variable w to previously generated dataset RooRealVar* w = (RooRealVar*) data->addColumn(weightVar) ; // Dataset d is now a dataset with two observable (x,w) with 1000 entries data->Print() ; // Instruct dataset wdata in interpret w as event weight rather than as observable RooDataSet wdata(data->GetName(),data->GetTitle(),data,*data->get(),0,w->GetName()) ; // Dataset d is now a dataset with one observable (x) with 1000 entries and a sum of weights of ~430K wdata.Print(); TCanvas *c1 = new TCanvas("c1","Fitting Demo",10,10,700,500); c1->SetFillColor(33); c1->SetFrameFillColor(41); c1->SetGrid(); //Make plot histo.Scale(200); histo.Draw(); RooPlot *pframe = p.frame(); data.plotOn(pframe); wdata.plotOn(pframe); pframe.Draw("SAME"); }