Rf 9 0 2_Numgenconfig

Numeric algorithm tuning: configuration and customization of how MC sampling algorithms on specific pdfs are executed

Author: Clemens Lange, Wouter Verkerke (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Saturday, November 28, 2020 at 11:12 AM.

In [1]:
import ROOT
Welcome to JupyROOT 6.23/01

Adjust global MC sampling strategy

Example pdf for use below

In [2]:
x = ROOT.RooRealVar("x", "x", 0, 10)
model = ROOT.RooChebychev("model", "model", x, ROOT.RooArgList(
    ROOT.RooFit.RooConst(0), ROOT.RooFit.RooConst(0.5), ROOT.RooFit.RooConst(-0.1)))
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Change global strategy for 1D sampling problems without conditional observable (1st kFALSE) and without discrete observable (2nd kFALSE) from ROOT.RooFoamGenerator, ( an interface to the ROOT.TFoam MC generator with adaptive subdivisioning strategy ) to ROOT.RooAcceptReject, a plain accept/reject sampling algorithm [ ROOT.RooFit default before ROOT 5.23/04 ]

In [3]:
ROOT.RooAbsPdf.defaultGeneratorConfig().method1D(
    ROOT.kFALSE, ROOT.kFALSE).setLabel("RooAcceptReject")
Out[3]:
True
[#0] ERROR:InputArguments -- Trying to set invalid state label 'RooAcceptReject' for category method1D

Generate 10Kevt using ROOT.RooAcceptReject

In [4]:
data_ar = model.generate(ROOT.RooArgSet(
    x), 10000, ROOT.RooFit.Verbose(ROOT.kTRUE))
data_ar.Print()
 --- RooGenContext --- 
Using PDF RooChebychev::model[ x=x coefList=(0,0.5,-0.1) ]
Use PDF generator for ()
Use MC sampling generator RooFoamGenerator for (x)
RooDataSet::modelData[x] = 10000 entries

Adjusting default config for a specific pdf

Another possibility: associate custom MC sampling configuration as default for object 'model' The kTRUE argument will install a clone of the default configuration as specialized configuration for self model if none existed so far

In [5]:
model.specialGeneratorConfig(ROOT.kTRUE).method1D(
    ROOT.kFALSE, ROOT.kFALSE).setLabel("RooFoamGenerator")
Out[5]:
False

Adjusting parameters of a specific technique

Adjust maximum number of steps of ROOT.RooIntegrator1D in the global default configuration

In [6]:
ROOT.RooAbsPdf.defaultGeneratorConfig().getConfigSection(
    "RooAcceptReject").setRealValue("nTrial1D", 2000)
Out[6]:
False

Example of how to change the parameters of a numeric integrator (Each config section is a ROOT.RooArgSet with ROOT.RooRealVars holding real-valued parameters and ROOT.RooCategories holding parameters with a finite set of options)

In [7]:
model.specialGeneratorConfig().getConfigSection(
    "RooFoamGenerator").setRealValue("chatLevel", 1)
Out[7]:
False

Generate 10Kevt using ROOT.RooFoamGenerator (FOAM verbosity increased with above chatLevel adjustment for illustration purposes)

In [8]:
data_foam = model.generate(ROOT.RooArgSet(x), 10000, ROOT.RooFit.Verbose())
data_foam.Print()
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
F                                                                              F
F                   ****************************************                   F
F                    ******      TFoam::Initialize    ******                   F
F                   ****************************************                   F
F                                                      TFOAM                   F
F    Version =           1.02M   =                   Release date:  2005.04.10 F
F       kDim =          1 =  Dimension of the hyper-cubical space              F
F     nCells =         30 =  Requested number of Cells (half of them active)   F
F     nSampl =        200 =  No of MC events in exploration of a cell          F
F       nBin =          8 =  No of bins in histograms, MC exploration of cell  F
F   EvPerBin =         25 =  Maximum No effective_events/bin, MC exploration   F
F   OptDrive =          2 =  Type of Driver   =1,2 for Sigma,WtMax             F
F     OptRej =          1 =  MC rejection on/off for OptRej=0,1                F
F   MaxWtRej =             1.1   =       Maximum wt in rejection for wt=1 evts F
F                                                                              F
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
11
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
F                                                                              F
F                    ***  TFoam::Initialize FINISHED!!!  ***                   F
F     nCalls =       5800 =            Total number of function calls          F
F     XPrime =      0.10992972   =     Primary total integral                  F
F     XDiver =     0.010000374   =     Driver  total integral                  F
F   mcResult =     0.099929343   =     Estimate of the true MC Integral        F
F                                                                              F
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
 --- RooGenContext --- 
Using PDF RooChebychev::model[ x=x coefList=(0,0.5,-0.1) ]
Use PDF generator for ()
Use MC sampling generator RooFoamGenerator for (x)
RooDataSet::modelData[x] = 10000 entries