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 "RooDataHist.h"
00018 #include "RooGaussian.h"
00019 #include "RooConstVar.h"
00020 #include "TCanvas.h"
00021 #include "TAxis.h"
00022 #include "RooPlot.h"
00023 #include "RooWorkspace.h"
00024 #include "RooExpensiveObjectCache.h"
00025 #include "TFile.h"
00026 #include "TH1.h"
00027
00028 using namespace RooFit ;
00029
00030 RooWorkspace* getWorkspace(Int_t mode) ;
00031
00032 void rf903_numintcache(Int_t mode=0)
00033 {
00034
00035
00036
00037
00038
00039
00040
00041
00042 RooWorkspace* w = getWorkspace(mode) ;
00043 if (mode==1) {
00044
00045
00046 w->Print() ;
00047
00048
00049 RooDataHist* hhcache = (RooDataHist*) w->expensiveObjectCache().getObj(1) ;
00050
00051 new TCanvas("rf903_numintcache","rf903_numintcache",600,600) ;
00052 hhcache->createHistogram("a")->Draw() ;
00053
00054 return ;
00055 }
00056
00057
00058
00059
00060
00061
00062 RooDataSet* d = w->pdf("model")->generate(RooArgSet(*w->var("x"),*w->var("y"),*w->var("z")),1000) ;
00063
00064
00065 w->pdf("model")->fitTo(*d,Verbose(kTRUE),Timer(kTRUE)) ;
00066
00067
00068 RooPlot* framex = w->var("x")->frame(Title("Projection of 3D model on X")) ;
00069 d->plotOn(framex) ;
00070 w->pdf("model")->plotOn(framex) ;
00071
00072
00073 new TCanvas("rf903_numintcache","rf903_numintcache",600,600) ;
00074 framex->Draw() ;
00075
00076
00077 gDirectory->Add(w) ;
00078
00079 return ;
00080
00081
00082 }
00083
00084
00085
00086 RooWorkspace* getWorkspace(Int_t mode)
00087 {
00088
00089
00090
00091
00092
00093
00094
00095 RooWorkspace* w(0) ;
00096
00097 if (mode!=2) {
00098
00099
00100 w = new RooWorkspace("w",1) ;
00101
00102
00103 w->factory("EXPR::model('1/((x-a)*(x-a)+0.01)+1/((y-a)*(y-a)+0.01)+1/((z-a)*(z-a)+0.01)',x[-1,1],y[-1,1],z[-1,1],a[-5,5])") ;
00104 }
00105
00106 if (mode==1) {
00107
00108
00109
00110
00111
00112 w->pdf("model")->setNormValueCaching(3) ;
00113
00114
00115 RooArgSet normSet(*w->var("x"),*w->var("y"),*w->var("z")) ;
00116 w->pdf("model")->getVal(&normSet) ;
00117 w->writeToFile("rf903_numintcache.root") ;
00118
00119 }
00120
00121 if (mode==2) {
00122
00123 TFile* f = new TFile("rf903_numintcache.root") ;
00124 w = (RooWorkspace*) f->Get("w") ;
00125 }
00126
00127
00128 return w ;
00129 }