22 using namespace RooFit;
24 void rf609_xychi2fit()
36 RooRealVar x(
"x",
"x", -11, 11);
37 RooRealVar y(
"y",
"y", -10, 200);
38 RooDataSet dxy(
"dxy",
"dxy", RooArgSet(x, y), StoreError(RooArgSet(x, y)));
41 for (
int i = 0; i <= 10; i++) {
45 x.setError(i < 5 ? 0.5 / 1. : 1.0 / 1.);
48 y = x.getVal() * x.getVal() + 4 * fabs(gRandom->Gaus());
49 y.setError(sqrt(y.getVal()));
51 dxy.add(RooArgSet(x, y));
58 RooRealVar a(
"a",
"a", 0.0, -10, 10);
59 RooRealVar b(
"b",
"b", 0.0, -100, 100);
60 RooPolyVar f(
"f",
"f", x, RooArgList(b, a, RooConst(1)));
63 RooPlot *frame = x.frame(Title(
"Chi^2 fit of function set of (X#pmdX,Y#pmdY) values"));
64 dxy.plotOnXY(frame, YVar(y));
67 f.chi2FitTo(dxy, YVar(y));
74 f.chi2FitTo(dxy, YVar(y), Integrate(kTRUE));
77 f.plotOn(frame, LineStyle(kDashed), LineColor(kRed));
80 new TCanvas(
"rf609_xychi2fit",
"rf609_xychi2fit", 600, 600);
81 gPad->SetLeftMargin(0.15);
82 frame->GetYaxis()->SetTitleOffset(1.4);