00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __CINT__
00013 #include "RooGlobalFunc.h"
00014 #endif
00015 #include "RooRealVar.h"
00016 #include "RooDataSet.h"
00017 #include "RooGaussian.h"
00018 #include "RooPolynomial.h"
00019 #include "RooAddPdf.h"
00020 #include "RooProdPdf.h"
00021 #include "RooFitResult.h"
00022 #include "RooPlot.h"
00023 #include "TCanvas.h"
00024 #include "TH1.h"
00025 using namespace RooFit ;
00026
00027
00028 class TestBasic604 : public RooFitTestUnit
00029 {
00030 public:
00031 TestBasic604(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Auxiliary observable constraints",refFile,writeRef,verbose) {} ;
00032 Bool_t testCode() {
00033
00034
00035
00036
00037
00038 RooRealVar x("x","x",-10,10) ;
00039
00040 RooRealVar m("m","m",0,-10,10) ;
00041 RooRealVar s("s","s",2,0.1,10) ;
00042 RooGaussian gauss("gauss","gauss(x,m,s)",x,m,s) ;
00043
00044
00045 RooPolynomial poly("poly","poly(x)",x) ;
00046
00047
00048 RooRealVar f("f","f",0.5,0.,1.) ;
00049 RooAddPdf model("model","model",RooArgSet(gauss,poly),f) ;
00050
00051
00052 RooDataSet* d = model.generate(x,50) ;
00053
00054
00055
00056
00057
00058
00059
00060 RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.8),RooConst(0.1)) ;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 RooProdPdf modelc("modelc","model with constraint",RooArgSet(model,fconstraint)) ;
00072
00073
00074 RooFitResult* r1 = modelc.fitTo(*d,Save()) ;
00075
00076
00077 RooFitResult* r2 = modelc.fitTo(*d,Constrain(f),Save()) ;
00078
00079
00080
00081
00082
00083
00084
00085 RooGaussian fconstext("fconstext","fconstext",f,RooConst(0.2),RooConst(0.1)) ;
00086
00087
00088 RooFitResult* r3 = model.fitTo(*d,ExternalConstraints(fconstext),Save()) ;
00089
00090
00091 regResult(r1,"rf604_r1") ;
00092 regResult(r2,"rf604_r2") ;
00093 regResult(r3,"rf604_r3") ;
00094
00095 delete d ;
00096
00097 return kTRUE ;
00098 }
00099 } ;