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