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