{ gSystem->Load("libRooFit"); using namespace RooFit; // data as TH1 and then RooDataHist TH1F *h1 = new TH1F("h1","h1",100,0,10); for(int i = 0; i < 10000; i++) h1->Fill(gRandom->Gaus(5,1)); RooRealVar x("x","x",0,10); RooDataHist dhist("dhist","dhist",x,h1); // build RooHistPdf and RooGaussian // from RooDataHist RooHistPdf hpdf("hpdf","hpdf",x,dhist); RooRealVar m("m","m",0,10); RooRealVar s("s","s",0,10); RooGaussian gaus("gaus","gaus",x,m,s); gaus.fitTo(dhist); // generate toy MC RooDataSet *d1000 = gaus.generate(x,1000); // draw things so that I feel happy // with what I've done RooPlot *frame = x.frame(); d1000->plotOn(frame); hpdf.plotOn(frame); gaus.plotOn(frame,LineColor(kRed)); frame->Draw(); // ask pdfs for NLL given the toy MC cout << "hpdf.createNLL(*d1000).getVal(): " << hpdf.createNLL(*d1000).getVal() << endl; cout << "gaus.createNLL(*d1000).getVal(): " << gaus.createNLL(*d1000).getVal() << endl; }