00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __CINT__
00015 #include "RooGlobalFunc.h"
00016 #endif
00017 #include "RooRealVar.h"
00018 #include "RooDataSet.h"
00019 #include "RooPolyVar.h"
00020 #include "RooConstVar.h"
00021 #include "RooChi2Var.h"
00022 #include "RooMinuit.h"
00023 #include "TCanvas.h"
00024 #include "TAxis.h"
00025 #include "RooPlot.h"
00026 #include "TRandom.h"
00027
00028 using namespace RooFit ;
00029
00030
00031 void rf609_xychi2fit()
00032 {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 RooRealVar x("x","x",-11,11) ;
00044 RooRealVar y("y","y",-10,200) ;
00045 RooDataSet dxy("dxy","dxy",RooArgSet(x,y),StoreError(RooArgSet(x,y))) ;
00046
00047
00048 for (int i=0 ; i<=10 ; i++) {
00049
00050
00051 x = -10 + 2*i;
00052 x.setError( i<5 ? 0.5/1. : 1.0/1. ) ;
00053
00054
00055 y = x.getVal() * x.getVal() + 4*fabs(gRandom->Gaus()) ;
00056 y.setError(sqrt(y.getVal())) ;
00057
00058 dxy.add(RooArgSet(x,y)) ;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067 RooRealVar a("a","a",0.0,-10,10) ;
00068 RooRealVar b("b","b",0.0,-100,100) ;
00069 RooPolyVar f("f","f",x,RooArgList(b,a,RooConst(1))) ;
00070
00071
00072 RooPlot* frame = x.frame(Title("Chi^2 fit of function set of (X#pmdX,Y#pmdY) values")) ;
00073 dxy.plotOnXY(frame,YVar(y)) ;
00074
00075
00076 f.chi2FitTo(dxy,YVar(y)) ;
00077
00078
00079 f.plotOn(frame) ;
00080
00081
00082
00083 f.chi2FitTo(dxy,YVar(y),Integrate(kTRUE)) ;
00084
00085
00086 f.plotOn(frame,LineStyle(kDashed),LineColor(kRed)) ;
00087
00088
00089
00090 new TCanvas("rf609_xychi2fit","rf609_xychi2fit",600,600) ;
00091 gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
00092
00093
00094 }