ROOT logo

From $ROOTSYS/tutorials/roofit/rf902_numgenconfig.C

//////////////////////////////////////////////////////////////////////////
//
// 'NUMERIC ALGORITHM TUNING' RooFit tutorial macro #902
// 
// Configuration and customization of how MC sampling algorithms
// on specific p.d.f.s are executed
//
//
//
// 07/2008 - Wouter Verkerke 
// 
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooConstVar.h"
#include "RooChebychev.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "RooNumGenConfig.h"
#include "RooArgSet.h"
#include <iomanip>
using namespace RooFit ;


void rf902_numgenconfig()
{

  // 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 
  // ------------------------------------------------------------------

  // Example p.d.f. for use below
  RooRealVar x("x","x",0,10) ;
  RooChebychev model("model","model",x,RooArgList(RooConst(0),RooConst(0.5),RooConst(-0.1))) ;


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

  // Generate 10Kevt using RooAcceptReject
  RooDataSet* data_ar = model.generate(x,10000,Verbose(kTRUE)) ;
  data_ar->Print() ;


  // 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 
  // -------------------------------------------------------------------------------------
  
  // 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 this model if none existed so far
  model.specialGeneratorConfig(kTRUE)->method1D(kFALSE,kFALSE).setLabel("RooFoamGenerator") ;


  // 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 
  // ---------------------------------------------------------------------------------------

  // Adjust maximum number of steps of RooIntegrator1D in the global default configuration
  RooAbsPdf::defaultGeneratorConfig()->getConfigSection("RooAcceptReject").setRealValue("nTrial1D",2000) ;

 
  // Example of how to change the parameters of a numeric integrator
  // (Each config section is a RooArgSet with RooRealVars holding real-valued parameters
  //  and RooCategories holding parameters with a finite set of options)
  model.specialGeneratorConfig()->getConfigSection("RooFoamGenerator").setRealValue("chatLevel",1) ;

  // Generate 10Kevt using RooFoamGenerator (FOAM verbosity increased with above chatLevel adjustment for illustration purposes)
  RooDataSet* data_foam = model.generate(x,10000,Verbose()) ;
  data_foam->Print() ;


}
 rf902_numgenconfig.C:1
 rf902_numgenconfig.C:2
 rf902_numgenconfig.C:3
 rf902_numgenconfig.C:4
 rf902_numgenconfig.C:5
 rf902_numgenconfig.C:6
 rf902_numgenconfig.C:7
 rf902_numgenconfig.C:8
 rf902_numgenconfig.C:9
 rf902_numgenconfig.C:10
 rf902_numgenconfig.C:11
 rf902_numgenconfig.C:12
 rf902_numgenconfig.C:13
 rf902_numgenconfig.C:14
 rf902_numgenconfig.C:15
 rf902_numgenconfig.C:16
 rf902_numgenconfig.C:17
 rf902_numgenconfig.C:18
 rf902_numgenconfig.C:19
 rf902_numgenconfig.C:20
 rf902_numgenconfig.C:21
 rf902_numgenconfig.C:22
 rf902_numgenconfig.C:23
 rf902_numgenconfig.C:24
 rf902_numgenconfig.C:25
 rf902_numgenconfig.C:26
 rf902_numgenconfig.C:27
 rf902_numgenconfig.C:28
 rf902_numgenconfig.C:29
 rf902_numgenconfig.C:30
 rf902_numgenconfig.C:31
 rf902_numgenconfig.C:32
 rf902_numgenconfig.C:33
 rf902_numgenconfig.C:34
 rf902_numgenconfig.C:35
 rf902_numgenconfig.C:36
 rf902_numgenconfig.C:37
 rf902_numgenconfig.C:38
 rf902_numgenconfig.C:39
 rf902_numgenconfig.C:40
 rf902_numgenconfig.C:41
 rf902_numgenconfig.C:42
 rf902_numgenconfig.C:43
 rf902_numgenconfig.C:44
 rf902_numgenconfig.C:45
 rf902_numgenconfig.C:46
 rf902_numgenconfig.C:47
 rf902_numgenconfig.C:48
 rf902_numgenconfig.C:49
 rf902_numgenconfig.C:50
 rf902_numgenconfig.C:51
 rf902_numgenconfig.C:52
 rf902_numgenconfig.C:53
 rf902_numgenconfig.C:54
 rf902_numgenconfig.C:55
 rf902_numgenconfig.C:56
 rf902_numgenconfig.C:57
 rf902_numgenconfig.C:58
 rf902_numgenconfig.C:59
 rf902_numgenconfig.C:60
 rf902_numgenconfig.C:61
 rf902_numgenconfig.C:62
 rf902_numgenconfig.C:63
 rf902_numgenconfig.C:64
 rf902_numgenconfig.C:65
 rf902_numgenconfig.C:66
 rf902_numgenconfig.C:67
 rf902_numgenconfig.C:68
 rf902_numgenconfig.C:69
 rf902_numgenconfig.C:70
 rf902_numgenconfig.C:71
 rf902_numgenconfig.C:72
 rf902_numgenconfig.C:73
 rf902_numgenconfig.C:74
 rf902_numgenconfig.C:75
 rf902_numgenconfig.C:76
 rf902_numgenconfig.C:77
 rf902_numgenconfig.C:78
 rf902_numgenconfig.C:79