#include "RooDataHist.h" #include "RooDataSet.h" #include "RooHistPdf.h" #include "RooNDKeysPdf.h" #include "RooRealVar.h" #include "TH2F.h" #include "TRandom.h" #include void hist2dgenerate() { // make a faux dataset TH2F* h2 = new TH2F("h2","h2",40,-5.,5.,40,0.,10.); for(int i = 0; i < 10000; ++i) h2->Fill(gRandom->Gaus(0,2),gRandom->Exp(2)); RooRealVar * x1 = new RooRealVar("x1","x1",-5.,5.); RooRealVar * x2 = new RooRealVar("x2","x2",0.,10.); RooDataHist* dh = new RooDataHist("dh","dh",RooArgList(*x1,*x2),h2); // use keys to smooth as i // don't want zero bins in // my hist pdf RooNDKeysPdf keys("keys","keys",RooArgList(*x1,*x2),*((RooDataSet*)dh)); delete h2; h2 = (TH2F*)keys.createHistogram("h2",*x1,RooFit::YVar(*x2)); delete dh; dh = new RooDataHist("dh","dh",RooArgList(*x1,*x2),h2); // this is my end 2d pdf RooHistPdf* hpdf = new RooHistPdf("hpdf","hpdf",RooArgSet(*x1,*x2),*dh); for(int i = 10; i <= 100; i+=10) { // number of events per toy mc std::cout << "\ni=" << i << " : "; std::cout.flush(); for(int j = 0; j < 10000; j++) { // number of toy mc if (!((j+1)%1000)) { std::cout << j+1 << " "; std::cout.flush(); } RooDataSet* tmp_ds = hpdf->generate(RooArgSet(*x1,*x2),i); RooAbsReal* nll = hpdf->createNLL(*tmp_ds); nll->addServer(*x1); // 5.26.x bug workaround double nll_val = nll->getVal(); delete nll; delete tmp_ds; } } std::cout << std::endl; }