using namespace RooFit; void variable_bin_test(){ TRandom3 rndgen; std::vector edges_bins{ 300, 347, 395, 443, 491, 540, 589, 639, 689, 740, 791, 843, 895, 948,1002, 1056, 1111, 1167, 1224, 1281, 1339, 1398, 1458, 1519, 1581, 1644,1708, 1773, 1839, 1906, 1974, 2043, 2114, 2186, 2259, 2333, 2409, 2486,2564, 2644, 2725, 2808, 2892, 2978, 3065, 3154, 3244, 3336, 3430,3526, 3623, 3722, 3823, 3926, 4031, 4138, 4247, 4358, 4472, 4588,4706, 4826, 4949, 5074}; Double_t* edges = &edges_bins[0]; Int_t NBINS = edges_bins.size()-1; TH1* h = new TH1D("h","Hist with variable bin width",NBINS,edges); for (Int_t i=0; i<82225; i++){ h->Fill(rndgen.Gaus(2500.,400.)); } //h->Scale(1./h->Integral()); RooRealVar mjj("mjj","mjj", 300, 5074); RooBinning mjjbin(NBINS, edges, "mjjbin"); //RooWorkspace w(); mjj.setBinning(mjjbin); RooDataHist hdata("hdata","hdata", mjj, h); mjj.setBins(NBINS); RooHistPdf pdf("pdf","pdf",mjj,hdata); mjj.setBins(NBINS); auto c = new TCanvas("c","c"); gPad->SetLogy(); h->SetLineStyle(2); h->GetYaxis()->SetTitle("Arbitrary units"); h->GetXaxis()->SetTitle("m_{JJ} [GeV]"); h->Draw("Hist"); RooPlot *frameData = mjj.frame(Bins(NBINS)); hdata.plotOn(frameData, Name("hdata"), LineColor(kRed), LineStyle(kDashed), DrawOption("HIST")); pdf.plotOn(frameData, Name("pdf"), LineColor(kBlue), LineStyle(kDashed)); frameData->Draw("hist same"); auto legend = new TLegend(0.65, 0.75, 0.95, 0.9); legend->SetBorderSize(0); legend->AddEntry(h, "Original histogram","l"); legend->AddEntry("hdata", "RooDataHist","l"); legend->AddEntry("pdf", "RooHistPdf","l"); legend->Draw(); }