ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RooAdaptiveIntegratorND.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /**
18 \file RooAdaptiveIntegratorND.cxx
19 \class RooAdaptiveIntegratorND
20 \ingroup Roofitcore
21 
22 RooAdaptiveIntegratorND implements an adaptive one-dimensional
23 numerical integration algorithm.
24 **/
25 
26 
27 #include "RooFit.h"
28 #include "Riostream.h"
29 
30 #include "TClass.h"
32 #include "RooArgSet.h"
33 #include "RooRealVar.h"
34 #include "RooNumber.h"
35 #include "RooMsgService.h"
36 #include "RooNumIntFactory.h"
37 #include "RooMultiGenFunction.h"
39 
40 #include <assert.h>
41 #include <iomanip>
42 
43 
44 
45 using namespace std;
46 
48 ;
49 
50 // Register this class with RooNumIntConfig
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory
54 
56 {
57  RooRealVar maxEval2D("maxEval2D","Max number of function evaluations for 2-dim integrals",100000) ;
58  RooRealVar maxEval3D("maxEval3D","Max number of function evaluations for 3-dim integrals",1000000) ;
59  RooRealVar maxEvalND("maxEvalND","Max number of function evaluations for >3-dim integrals",10000000) ;
60  RooRealVar maxWarn("maxWarn","Max number of warnings on precision not reached that is printed",5) ;
61 
62  fact.storeProtoIntegrator(new RooAdaptiveIntegratorND(),RooArgSet(maxEval2D,maxEval3D,maxEvalND,maxWarn)) ;
63 }
64 
65 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Default ctor
69 
71 {
72  _xmin = 0 ;
73  _xmax = 0 ;
74  _epsRel = 1e-7 ;
75  _epsAbs = 1e-7 ;
76  _nmax = 10000 ;
77  _func = 0 ;
78  _integrator = 0 ;
79  _nError = 0 ;
80  _nWarn = 0 ;
81  _useIntegrandLimits = kTRUE ;
82  _intName = "(none)" ;
83 }
84 
85 
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Constructor of integral on given function binding and with given configuration. The
89 /// integration limits are taken from the definition in the function binding
90 ///_func = function.
91 
94 {
95 
96  _func = new RooMultiGenFunction(function) ;
97  _nWarn = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxWarn")) ;
98  switch (_func->NDim()) {
99  case 1: throw string(Form("RooAdaptiveIntegratorND::ctor ERROR dimension of function must be at least 2")) ;
100  case 2: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval2D")) ; break ;
101  case 3: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval3D")) ; break ;
102  default: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEvalND")) ; break ;
103  }
104  // by default do not use absolute tolerance (see https://root.cern.ch/phpBB3/viewtopic.php?f=15&t=20071 )
105  _epsAbs = 0.0;
106  _epsRel = config.epsRel();
110 
111  _xmin = 0 ;
112  _xmax = 0 ;
113  _nError = 0 ;
114  _nWarn = 0 ;
115  checkLimits() ;
116  _intName = function.getName() ;
117 }
118 
119 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
123 
125 {
126  RooAbsIntegrator* ret = new RooAdaptiveIntegratorND(function,config) ;
127 
128  return ret ;
129 }
130 
131 
132 
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Destructor
136 
138 {
139  delete[] _xmin ;
140  delete[] _xmax ;
141  delete _integrator ;
142  delete _func ;
143  if (_nError>_nWarn) {
144  coutW(NumIntegration) << "RooAdaptiveIntegratorND::dtor(" << _intName
145  << ") WARNING: Number of suppressed warningings about integral evaluations where target precision was not reached is " << _nError-_nWarn << endl ;
146  }
147 
148 }
149 
150 
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Check that our integration range is finite and otherwise return kFALSE.
154 /// Update the limits from the integrand if requested.
155 
157 {
158  if (!_xmin) {
159  _xmin = new Double_t[_func->NDim()] ;
160  _xmax = new Double_t[_func->NDim()] ;
161  }
162 
163  if (_useIntegrandLimits) {
164  for (UInt_t i=0 ; i<_func->NDim() ; i++) {
165  _xmin[i]= integrand()->getMinLimit(i);
166  _xmax[i]= integrand()->getMaxLimit(i);
167  }
168  }
169 
170  return kTRUE ;
171 }
172 
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Change our integration limits. Return kTRUE if the new limits are
176 /// ok, or otherwise kFALSE. Always returns kFALSE and does nothing
177 /// if this object was constructed to always use our integrand's limits.
178 
180 {
181  if(_useIntegrandLimits) {
182  oocoutE((TObject*)0,Integration) << "RooAdaptiveIntegratorND::setLimits: cannot override integrand's limits" << endl;
183  return kFALSE;
184  }
185  for (UInt_t i=0 ; i<_func->NDim() ; i++) {
186  _xmin[i]= xmin[i];
187  _xmax[i]= xmax[i];
188  }
189 
190  return checkLimits();
191 }
192 
193 
194 
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Evaluate integral at given function binding parameter values
198 
200 {
202  if (_integrator->Status()==1) {
203  _nError++ ;
204  if (_nError<=_nWarn) {
205  coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName() << ") WARNING: target rel. precision not reached due to nEval limit of "
206  << _nmax << ", estimated rel. precision is " << Form("%3.1e",_integrator->RelError()) << endl ;
207  }
208  if (_nError==_nWarn) {
209  coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName()
210  << ") Further warnings on target precision are suppressed conform specification in integrator specification" << endl ;
211  }
212  }
213  return ret ;
214 }
215 
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
float xmin
Definition: THbookFile.cxx:93
virtual const char * getName() const
Definition: RooAbsFunc.h:59
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
void SetFunction(const IMultiGenFunction &f)
set the integration function (must implement multi-dim function interface: IBaseFunctionMultiDim) ...
int Status() const
return status of integration
RooMultiGenFunction * _func
double RelError() const
return relative error
Lightweight interface adaptor that exports a RooAbsReal as a ROOT::Math::IMultiGenFunction.
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
RooAdaptiveIntegratorND implements an adaptive one-dimensional numerical integration algorithm...
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
#define coutW(a)
Definition: RooMsgService.h:34
virtual Double_t integral(const Double_t *yvec=0)
Evaluate integral at given function binding parameter values.
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
Double_t epsRel() const
#define oocoutE(o, a)
Definition: RooMsgService.h:48
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[] ...
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
void function(const char *name_, T fun, const char *docstring=0)
Definition: RExports.h:159
virtual RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual Double_t getMinLimit(UInt_t dimension) const =0
float xmax
Definition: THbookFile.cxx:93
virtual ~RooAdaptiveIntegratorND()
Destructor.
void Integration()
Definition: Integration.C:27
virtual Double_t getMaxLimit(UInt_t dimension) const =0
double Double_t
Definition: RtypesCore.h:55
static void registerIntegrator(RooNumIntFactory &fact)
Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory...
Mother of all ROOT objects.
Definition: TObject.h:58
ClassImp(RooAdaptiveIntegratorND)
const RooAbsFunc * integrand() const
virtual Bool_t checkLimits() const
Check that our integration range is finite and otherwise return kFALSE.
const Bool_t kTRUE
Definition: Rtypes.h:91
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition: RooAbsFunc.h:23
unsigned int NDim() const
Retrieve the dimension of the function.
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
ROOT::Math::AdaptiveIntegratorMultiDim * _integrator
ROOT::Math multi-parameter function binding.
class for adaptive quadrature integration in multi-dimensions using rectangular regions.
Bool_t storeProtoIntegrator(RooAbsIntegrator *proto, const RooArgSet &defConfig, const char *depName="")
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
Definition: RooArgSet.cxx:527