%%cpp -d #include "RooRealVar.h" #include "RooDataSet.h" #include "RooPolyVar.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" #include "TRandom.h" using namespace RooFit; RooRealVar x("x", "x", -11, 11); RooRealVar y("y", "y", -10, 200); RooDataSet dxy("dxy", "dxy", {x, y}, StoreError({x, y})); for (int i = 0; i <= 10; i++) { // Set X value and error x = -10 + 2 * i; x.setError(i < 5 ? 0.5 / 1. : 1.0 / 1.); // Set Y value and error y = x.getVal() * x.getVal() + 4 * fabs(gRandom->Gaus()); y.setError(sqrt(y.getVal())); dxy.add({x, y}); } RooRealVar a("a", "a", 0.0, -10, 10); RooRealVar b("b", "b", 0.0, -100, 100); RooRealVar c("c", "c", 0.0, -100, 100); RooPolyVar f("f", "f", x, RooArgList(b, a, c)); RooPlot *frame = x.frame(Title("Chi^2 fit of function set of (X#pmdX,Y#pmdY) values")); dxy.plotOnXY(frame, YVar(y)); std::unique_ptr fit1{f.chi2FitTo(dxy, YVar(y), Save(), PrintLevel(-1))}; fit1->Print(); f.plotOn(frame); std::unique_ptr fit2{f.chi2FitTo(dxy, YVar(y), Save(), PrintLevel(-1), Integrate(true))}; fit2->Print(); f.plotOn(frame, LineStyle(kDashed), LineColor(kRed)); new TCanvas("rf609_xychi2fit", "rf609_xychi2fit", 600, 600); gPad->SetLeftMargin(0.15); frame->GetYaxis()->SetTitleOffset(1.4); frame->Draw(); %jsroot on gROOT->GetListOfCanvases()->Draw()