Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 p.d.f.s are
5 /// executed
6 ///
7 /// \macro_output
8 /// \macro_code
9 /// \author 07/2008 - Wouter Verkerke
10 
11 #include "RooRealVar.h"
12 #include "RooDataSet.h"
13 #include "RooConstVar.h"
14 #include "RooChebychev.h"
15 #include "TCanvas.h"
16 #include "TAxis.h"
17 #include "RooPlot.h"
18 #include "RooNumGenConfig.h"
19 #include "RooArgSet.h"
20 #include <iomanip>
21 using namespace RooFit;
22 
23 void rf902_numgenconfig()
24 {
25 
26  // 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
27  // ------------------------------------------------------------------
28 
29  // Example p.d.f. for use below
30  RooRealVar x("x", "x", 0, 10);
31  RooChebychev model("model", "model", x, RooArgList(RooConst(0), RooConst(0.5), RooConst(-0.1)));
32 
33  // Change global strategy for 1D sampling problems without conditional observable
34  // (1st kFALSE) and without discrete observable (2nd kFALSE) from RooFoamGenerator,
35  // ( an interface to the TFoam MC generator with adaptive subdivisioning strategy ) to RooAcceptReject,
36  // a plain accept/reject sampling algorithm [ RooFit default before ROOT 5.23/04 ]
37  RooAbsPdf::defaultGeneratorConfig()->method1D(kFALSE, kFALSE).setLabel("RooAcceptReject");
38 
39  // Generate 10Kevt using RooAcceptReject
40  RooDataSet *data_ar = model.generate(x, 10000, Verbose(kTRUE));
41  data_ar->Print();
42 
43  // 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
44  // -------------------------------------------------------------------------------------
45 
46  // Another possibility: associate custom MC sampling configuration as default for object 'model'
47  // The kTRUE argument will install a clone of the default configuration as specialized configuration
48  // for this model if none existed so far
49  model.specialGeneratorConfig(kTRUE)->method1D(kFALSE, kFALSE).setLabel("RooFoamGenerator");
50 
51  // 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
52  // ---------------------------------------------------------------------------------------
53 
54  // Adjust maximum number of steps of RooIntegrator1D in the global default configuration
55  RooAbsPdf::defaultGeneratorConfig()->getConfigSection("RooAcceptReject").setRealValue("nTrial1D", 2000);
56 
57  // Example of how to change the parameters of a numeric integrator
58  // (Each config section is a RooArgSet with RooRealVars holding real-valued parameters
59  // and RooCategories holding parameters with a finite set of options)
60  model.specialGeneratorConfig()->getConfigSection("RooFoamGenerator").setRealValue("chatLevel", 1);
61 
62  // Generate 10Kevt using RooFoamGenerator (FOAM verbosity increased with above chatLevel adjustment for illustration
63  // purposes)
64  RooDataSet *data_foam = model.generate(x, 10000, Verbose());
65  data_foam->Print();
66 }