%%cpp -d #include "RooRealVar.h" #include "RooDataHist.h" #include "RooGaussian.h" #include "RooProdPdf.h" #include "RooPolyVar.h" #include "TH1.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" #include "RooNumIntConfig.h" using namespace RooFit; RooAbsPdf::defaultIntegratorConfig()->setEpsRel(1e-8); RooAbsPdf::defaultIntegratorConfig()->setEpsAbs(1e-8); RooRealVar x("x", "x", -5, 5); RooRealVar y("y", "y", -2, 2); RooRealVar a0("a0", "a0", 0); RooRealVar a1("a1", "a1", -1.5, -3, 1); RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1)); RooRealVar sigmax("sigmax", "width of gaussian", 0.5); RooGaussian gaussx("gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax); RooGaussian gaussy("gaussy", "Gaussian in y", y, 0.0, 2.0); RooProdPdf model("model", "gaussx(x|y)*gaussy(y)", gaussy, Conditional(gaussx, x)); RooAbsPdf *modelx = model.createProjection(y); std::unique_ptr data{modelx->generateBinned(x, 1000)}; modelx->fitTo(*data, Verbose(), PrintLevel(-1)); RooPlot *frame = x.frame(40); data->plotOn(frame); modelx->plotOn(frame); TH1 *hh = model.createHistogram("x,y"); hh->SetLineColor(kBlue); TCanvas *c = new TCanvas("rf315_projectpdf", "rf315_projectpdf", 800, 400); c->Divide(2); c->cd(1); gPad->SetLeftMargin(0.15); frame->GetYaxis()->SetTitleOffset(1.4); frame->Draw(); c->cd(2); gPad->SetLeftMargin(0.20); hh->GetZaxis()->SetTitleOffset(2.5); hh->Draw("surf"); gROOT->GetListOfCanvases()->Draw()