#include #include #include "TCanvas.h" #include "TString.h" #include "RooAddPdf.h" #include "RooArgSet.h" #include "RooDataSet.h" #include "RooExponential.h" #include "RooGaussian.h" #include "RooPlot.h" #include "RooRealVar.h" using namespace RooFit; void test_fit2() { RooRealVar x("x", "x", 0., 200., "MeV"); RooRealVar mean("mean", "mean", 100., 50., 150., "MeV"); RooRealVar width("width", "width", 15., 1., 50., "MeV"); RooGaussian sig_gauss("sig_gauss", "sig_gauss", x, mean, width); RooRealVar b("b", "b", -0.01, -1., 0., ""); RooExponential bkg("bkg_pwrlaw_passed", "bkg_pwrlaw_passed", x, b); RooRealVar f("f", "f", 0.4, 0., 1., ""); RooAddPdf model("model", "model", sig_gauss, bkg, f); std::unique_ptr dataset(model.generate(x, 1000000)); mean.setVal(110.); width.setVal(20.); b.setVal(-0.001); f.setVal(0.5); model.fitTo(*dataset, Strategy(2), Minimizer("Minuit", "minimize"), Offset(true)); TCanvas c("c", "c", 960, 720); std::unique_ptr frame_passed(x.frame()); dataset->plotOn(frame_passed.get()); model.plotOn(frame_passed.get()); frame_passed->Draw(); c.SaveAs("./test2.pdf"); return; }