Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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, 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 ]
28ROOT.RooAbsPdf.defaultGeneratorConfig().method1D(
29 ROOT.kFALSE, ROOT.kFALSE).setLabel("RooAcceptReject")
30
31# Generate 10Kevt using ROOT.RooAcceptReject
32data_ar = model.generate(ROOT.RooArgSet(
33 x), 10000, ROOT.RooFit.Verbose(ROOT.kTRUE))
34data_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
42model.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
50ROOT.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)
56model.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)
61data_foam = model.generate(ROOT.RooArgSet(x), 10000, ROOT.RooFit.Verbose())
62data_foam.Print()