Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf902_numgenconfig.py
Go to the documentation of this file.
1 ## \ingroup tutorial_roofit
2 ## \notebook -nodraw
3 ##
4 ## Numeric algorithm tuning: configuration and customization of how MC sampling algorithms
5 ## on specific p.d.f.s are executed
6 ##
7 ## \macro_code
8 ##
9 ## \date February 2018
10 ## \author Clemens Lange, Wouter Verkerke (C++ version)
11 
12 import ROOT
13 
14 
15 # Adjust global MC sampling strategy
16 # ------------------------------------------------------------------
17 
18 # Example p.d.f. for use below
19 x = ROOT.RooRealVar("x", "x", 0, 10)
20 model = ROOT.RooChebychev("model", "model", x, ROOT.RooArgList(
21  ROOT.RooFit.RooConst(0), ROOT.RooFit.RooConst(0.5), ROOT.RooFit.RooConst(-0.1)))
22 
23 # Change global strategy for 1D sampling problems without conditional observable
24 # (1st kFALSE) and without discrete observable (2nd kFALSE) from ROOT.RooFoamGenerator,
25 # ( an interface to the ROOT.TFoam MC generator with adaptive subdivisioning strategy ) to ROOT.RooAcceptReject,
26 # a plain accept/reject sampling algorithm [ ROOT.RooFit default before
27 # ROOT 5.23/04 ]
28 ROOT.RooAbsPdf.defaultGeneratorConfig().method1D(
29  ROOT.kFALSE, ROOT.kFALSE).setLabel("RooAcceptReject")
30 
31 # Generate 10Kevt using ROOT.RooAcceptReject
32 data_ar = model.generate(ROOT.RooArgSet(
33  x), 10000, ROOT.RooFit.Verbose(ROOT.kTRUE))
34 data_ar.Print()
35 
36 # Adjusting default config for a specific pdf
37 # -------------------------------------------------------------------------------------
38 
39 # Another possibility: associate custom MC sampling configuration as default for object 'model'
40 # The kTRUE argument will install a clone of the default configuration as specialized configuration
41 # for self model if none existed so far
42 model.specialGeneratorConfig(ROOT.kTRUE).method1D(
43  ROOT.kFALSE, ROOT.kFALSE).setLabel("RooFoamGenerator")
44 
45 # Adjusting parameters of a specific technique
46 # ---------------------------------------------------------------------------------------
47 
48 # Adjust maximum number of steps of ROOT.RooIntegrator1D in the global
49 # default configuration
50 ROOT.RooAbsPdf.defaultGeneratorConfig().getConfigSection(
51  "RooAcceptReject").setRealValue("nTrial1D", 2000)
52 
53 # Example of how to change the parameters of a numeric integrator
54 # (Each config section is a ROOT.RooArgSet with ROOT.RooRealVars holding real-valued parameters
55 # and ROOT.RooCategories holding parameters with a finite set of options)
56 model.specialGeneratorConfig().getConfigSection(
57  "RooFoamGenerator").setRealValue("chatLevel", 1)
58 
59 # Generate 10Kevt using ROOT.RooFoamGenerator (FOAM verbosity increased
60 # with above chatLevel adjustment for illustration purposes)
61 data_foam = model.generate(ROOT.RooArgSet(x), 10000, ROOT.RooFit.Verbose())
62 data_foam.Print()