00001 ////////////////////////////////////////////////////////////////////////// 00002 // 00003 // 'NUMERIC ALGORITHM TUNING' RooFit tutorial macro #902 00004 // 00005 // Configuration and customization of how MC sampling algorithms 00006 // on specific p.d.f.s are executed 00007 // 00008 // 00009 // 00010 // 07/2008 - Wouter Verkerke 00011 // 00012 ///////////////////////////////////////////////////////////////////////// 00013 00014 #ifndef __CINT__ 00015 #include "RooGlobalFunc.h" 00016 #endif 00017 #include "RooRealVar.h" 00018 #include "RooDataSet.h" 00019 #include "RooConstVar.h" 00020 #include "RooChebychev.h" 00021 #include "TCanvas.h" 00022 #include "TAxis.h" 00023 #include "RooPlot.h" 00024 #include "RooNumGenConfig.h" 00025 #include "RooArgSet.h" 00026 #include <iomanip> 00027 using namespace RooFit ; 00028 00029 00030 void rf902_numgenconfig() 00031 { 00032 00033 // A d j u s t g l o b a l MC s a m p l i n g s t r a t e g y 00034 // ------------------------------------------------------------------ 00035 00036 // Example p.d.f. for use below 00037 RooRealVar x("x","x",0,10) ; 00038 RooChebychev model("model","model",x,RooArgList(RooConst(0),RooConst(0.5),RooConst(-0.1))) ; 00039 00040 00041 // Change global strategy for 1D sampling problems without conditional observable 00042 // (1st kFALSE) and without discrete observable (2nd kFALSE) from RooFoamGenerator, 00043 // ( an interface to the TFoam MC generator with adaptive subdivisioning strategy ) to RooAcceptReject, 00044 // a plain accept/reject sampling algorithm [ RooFit default before ROOT 5.23/04 ] 00045 RooAbsPdf::defaultGeneratorConfig()->method1D(kFALSE,kFALSE).setLabel("RooAcceptReject") ; 00046 00047 // Generate 10Kevt using RooAcceptReject 00048 RooDataSet* data_ar = model.generate(x,10000,Verbose(kTRUE)) ; 00049 data_ar->Print() ; 00050 00051 00052 // A d j u s t i n g d e f a u l t c o n f i g f o r a s p e c i f i c p d f 00053 // ------------------------------------------------------------------------------------- 00054 00055 // Another possibility: associate custom MC sampling configuration as default for object 'model' 00056 // The kTRUE argument will install a clone of the default configuration as specialized configuration 00057 // for this model if none existed so far 00058 model.specialGeneratorConfig(kTRUE)->method1D(kFALSE,kFALSE).setLabel("RooFoamGenerator") ; 00059 00060 00061 // A d j u s t i n g p a r a m e t e r s o f a s p e c i f i c t e c h n i q u e 00062 // --------------------------------------------------------------------------------------- 00063 00064 // Adjust maximum number of steps of RooIntegrator1D in the global default configuration 00065 RooAbsPdf::defaultGeneratorConfig()->getConfigSection("RooAcceptReject").setRealValue("nTrial1D",2000) ; 00066 00067 00068 // Example of how to change the parameters of a numeric integrator 00069 // (Each config section is a RooArgSet with RooRealVars holding real-valued parameters 00070 // and RooCategories holding parameters with a finite set of options) 00071 model.specialGeneratorConfig()->getConfigSection("RooFoamGenerator").setRealValue("chatLevel",1) ; 00072 00073 // Generate 10Kevt using RooFoamGenerator (FOAM verbosity increased with above chatLevel adjustment for illustration purposes) 00074 RooDataSet* data_foam = model.generate(x,10000,Verbose()) ; 00075 data_foam->Print() ; 00076 00077 00078 }