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