Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf902_numgenconfig.C
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 on specific pdfs are
5/// executed
6///
7/// \macro_code
8/// \macro_output
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooChebychev.h"
16#include "TCanvas.h"
17#include "TAxis.h"
18#include "RooPlot.h"
19#include "RooNumGenConfig.h"
20#include "RooArgSet.h"
21#include <iomanip>
22using namespace RooFit;
23
25{
26
27 // A d j u s t g l o b a l MC s a m p l i n g s t r a t e g y
28 // ------------------------------------------------------------------
29
30 // Example pdf for use below
31 RooRealVar x("x", "x", 0, 10);
32 RooChebychev model("model", "model", x, RooArgList(0, 0.5, -0.1));
33
34 // Change global strategy for 1D sampling problems without conditional observable
35 // (1st false) and without discrete observable (2nd false) from RooFoamGenerator,
36 // ( an interface to the TFoam MC generator with adaptive subdivisioning strategy ) to RooAcceptReject,
37 // a plain accept/reject sampling algorithm [ RooFit default before ROOT 5.23/04 ]
38 RooAbsPdf::defaultGeneratorConfig()->method1D(false, false).setLabel("RooAcceptReject");
39
40 // Generate 10Kevt using RooAcceptReject
41 std::unique_ptr<RooDataSet> data_ar{model.generate(x, 10000, Verbose(true))};
42 data_ar->Print();
43
44 // A d j u s t i n g d e f a u l t c o n f i g f o r a s p e c i f i c p d f
45 // -------------------------------------------------------------------------------------
46
47 // Another possibility: associate custom MC sampling configuration as default for object 'model'
48 // The true argument will install a clone of the default configuration as specialized configuration
49 // for this model if none existed so far
50 model.specialGeneratorConfig(true)->method1D(false, false).setLabel("RooFoamGenerator");
51
52 // A d j u s t i n g p a r a m e t e r s o f a s p e c i f i c t e c h n i q u e
53 // ---------------------------------------------------------------------------------------
54
55 // Adjust maximum number of steps of RooIntegrator1D in the global default configuration
56 RooAbsPdf::defaultGeneratorConfig()->getConfigSection("RooAcceptReject").setRealValue("nTrial1D", 2000);
57
58 // Example of how to change the parameters of a numeric integrator
59 // (Each config section is a RooArgSet with RooRealVars holding real-valued parameters
60 // and RooCategories holding parameters with a finite set of options)
61 model.specialGeneratorConfig()->getConfigSection("RooFoamGenerator").setRealValue("chatLevel", 1);
62
63 // Generate 10Kevt using RooFoamGenerator (FOAM verbosity increased with above chatLevel adjustment for illustration
64 // purposes)
65 std::unique_ptr<RooDataSet> data_foam{model.generate(x, 10000, Verbose())};
66 data_foam->Print();
67}
bool setRealValue(const char *name, double newVal=0.0, bool verbose=false)
Set value of a RooAbsRealLValue stored in set with given name to newVal No error messages are printed...
static RooNumGenConfig * defaultGeneratorConfig()
Returns the default numeric MC generator configuration for all RooAbsReals.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Chebychev polynomial p.d.f.
RooCategory & method1D(bool cond, bool cat)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
RooCmdArg Verbose(bool flag=true)
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26