ROOT logo

From $ROOTSYS/tutorials/roofit/rf901_numintconfig.C

//////////////////////////////////////////////////////////////////////////
//
// 'NUMERIC ALGORITHM TUNING' RooFit tutorial macro #901 
// 
// Configuration and customization of how numeric (partial) integrals
// are executed
//
//
//
// 07/2008 - Wouter Verkerke 
// 
/////////////////////////////////////////////////////////////////////////

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


void rf901_numintconfig()
{

  // A d j u s t   g l o b a l   1 D   i n t e g r a t i o n   p r e c i s i o n 
  // ----------------------------------------------------------------------------

  // Print current global default configuration for numeric integration strategies
  RooAbsReal::defaultIntegratorConfig()->Print("v") ;

  // Example: Change global precision for 1D integrals from 1e-7 to 1e-6
  //
  // The relative epsilon (change as fraction of current best integral estimate) and
  // absolute epsilon (absolute change w.r.t last best integral estimate) can be specified
  // separately. For most p.d.f integrals the relative change criterium is the most important,
  // however for certain non-p.d.f functions that integrate out to zero a separate absolute
  // change criterium is necessary to declare convergence of the integral
  //
  // NB: This change is for illustration only. In general the precision should be at least 1e-7 
  // for normalization integrals for MINUIT to succeed.
  //
  RooAbsReal::defaultIntegratorConfig()->setEpsAbs(1e-6) ;
  RooAbsReal::defaultIntegratorConfig()->setEpsRel(1e-6) ;


  // N u m e r i c   i n t e g r a t i o n   o f   l a n d a u   p d f 
  // ------------------------------------------------------------------
  
  // Construct p.d.f without support for analytical integrator for demonstration purposes
  RooRealVar x("x","x",-10,10) ;
  RooLandau landau("landau","landau",x,RooConst(0),RooConst(0.1)) ;
  

  // Activate debug-level messages for topic integration to be able to follow actions below
  RooMsgService::instance().addStream(DEBUG,Topic(Integration)) ;


  // Calculate integral over landau with default choice of numeric integrator
  RooAbsReal* intLandau = landau.createIntegral(x) ;
  Double_t val = intLandau->getVal() ;
  cout << " [1] int_dx landau(x) = " << setprecision(15) << val << endl ;



  // S a m e   w i t h   c u s t o m   c o n f i g u r a t i o n
  // -----------------------------------------------------------
  

  // Construct a custom configuration which uses the adaptive Gauss-Kronrod technique
  // for closed 1D integrals
  RooNumIntConfig customConfig(*RooAbsReal::defaultIntegratorConfig()) ;
  customConfig.method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D") ;


  // Calculate integral over landau with custom integral specification
  RooAbsReal* intLandau2 = landau.createIntegral(x,NumIntConfig(customConfig)) ;
  Double_t val2 = intLandau2->getVal() ;
  cout << " [2] int_dx landau(x) = " << val2 << endl ;



  // 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 numeric integration configuration as default for object 'landau'
  landau.setIntegratorConfig(customConfig) ;


  // Calculate integral over landau custom numeric integrator specified as object default
  RooAbsReal* intLandau3 = landau.createIntegral(x) ;
  Double_t val3 = intLandau3->getVal() ;
  cout << " [3] int_dx landau(x) = " << val3 << endl ;
 

  // Another possibility: Change global default for 1D numeric integration strategy on finite domains
  RooAbsReal::defaultIntegratorConfig()->method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D") ;  



  // 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
  RooAbsReal::defaultIntegratorConfig()->getConfigSection("RooIntegrator1D").setRealValue("maxSteps",30) ;

 
  // 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)
  customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").setRealValue("maxSeg",50) ;
  customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").setCatLabel("method","15Points") ;


  // Example of how to print set of possible values for "method" category
  customConfig.getConfigSection("RooAdaptiveGaussKronrodIntegrator1D").find("method")->Print("v") ;

}
 rf901_numintconfig.C:1
 rf901_numintconfig.C:2
 rf901_numintconfig.C:3
 rf901_numintconfig.C:4
 rf901_numintconfig.C:5
 rf901_numintconfig.C:6
 rf901_numintconfig.C:7
 rf901_numintconfig.C:8
 rf901_numintconfig.C:9
 rf901_numintconfig.C:10
 rf901_numintconfig.C:11
 rf901_numintconfig.C:12
 rf901_numintconfig.C:13
 rf901_numintconfig.C:14
 rf901_numintconfig.C:15
 rf901_numintconfig.C:16
 rf901_numintconfig.C:17
 rf901_numintconfig.C:18
 rf901_numintconfig.C:19
 rf901_numintconfig.C:20
 rf901_numintconfig.C:21
 rf901_numintconfig.C:22
 rf901_numintconfig.C:23
 rf901_numintconfig.C:24
 rf901_numintconfig.C:25
 rf901_numintconfig.C:26
 rf901_numintconfig.C:27
 rf901_numintconfig.C:28
 rf901_numintconfig.C:29
 rf901_numintconfig.C:30
 rf901_numintconfig.C:31
 rf901_numintconfig.C:32
 rf901_numintconfig.C:33
 rf901_numintconfig.C:34
 rf901_numintconfig.C:35
 rf901_numintconfig.C:36
 rf901_numintconfig.C:37
 rf901_numintconfig.C:38
 rf901_numintconfig.C:39
 rf901_numintconfig.C:40
 rf901_numintconfig.C:41
 rf901_numintconfig.C:42
 rf901_numintconfig.C:43
 rf901_numintconfig.C:44
 rf901_numintconfig.C:45
 rf901_numintconfig.C:46
 rf901_numintconfig.C:47
 rf901_numintconfig.C:48
 rf901_numintconfig.C:49
 rf901_numintconfig.C:50
 rf901_numintconfig.C:51
 rf901_numintconfig.C:52
 rf901_numintconfig.C:53
 rf901_numintconfig.C:54
 rf901_numintconfig.C:55
 rf901_numintconfig.C:56
 rf901_numintconfig.C:57
 rf901_numintconfig.C:58
 rf901_numintconfig.C:59
 rf901_numintconfig.C:60
 rf901_numintconfig.C:61
 rf901_numintconfig.C:62
 rf901_numintconfig.C:63
 rf901_numintconfig.C:64
 rf901_numintconfig.C:65
 rf901_numintconfig.C:66
 rf901_numintconfig.C:67
 rf901_numintconfig.C:68
 rf901_numintconfig.C:69
 rf901_numintconfig.C:70
 rf901_numintconfig.C:71
 rf901_numintconfig.C:72
 rf901_numintconfig.C:73
 rf901_numintconfig.C:74
 rf901_numintconfig.C:75
 rf901_numintconfig.C:76
 rf901_numintconfig.C:77
 rf901_numintconfig.C:78
 rf901_numintconfig.C:79
 rf901_numintconfig.C:80
 rf901_numintconfig.C:81
 rf901_numintconfig.C:82
 rf901_numintconfig.C:83
 rf901_numintconfig.C:84
 rf901_numintconfig.C:85
 rf901_numintconfig.C:86
 rf901_numintconfig.C:87
 rf901_numintconfig.C:88
 rf901_numintconfig.C:89
 rf901_numintconfig.C:90
 rf901_numintconfig.C:91
 rf901_numintconfig.C:92
 rf901_numintconfig.C:93
 rf901_numintconfig.C:94
 rf901_numintconfig.C:95
 rf901_numintconfig.C:96
 rf901_numintconfig.C:97
 rf901_numintconfig.C:98
 rf901_numintconfig.C:99
 rf901_numintconfig.C:100
 rf901_numintconfig.C:101
 rf901_numintconfig.C:102
 rf901_numintconfig.C:103
 rf901_numintconfig.C:104
 rf901_numintconfig.C:105
 rf901_numintconfig.C:106
 rf901_numintconfig.C:107
 rf901_numintconfig.C:108
 rf901_numintconfig.C:109
 rf901_numintconfig.C:110
 rf901_numintconfig.C:111
 rf901_numintconfig.C:112
 rf901_numintconfig.C:113
 rf901_numintconfig.C:114
 rf901_numintconfig.C:115
 rf901_numintconfig.C:116
 rf901_numintconfig.C:117
 rf901_numintconfig.C:118
 rf901_numintconfig.C:119
 rf901_numintconfig.C:120
 rf901_numintconfig.C:121
 rf901_numintconfig.C:122
 rf901_numintconfig.C:123
 rf901_numintconfig.C:124
 rf901_numintconfig.C:125
 rf901_numintconfig.C:126
 rf901_numintconfig.C:127
 rf901_numintconfig.C:128