Logo ROOT  
Reference Guide
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 
42 
43 
44 using namespace std;
45 
47 ;
48 
49 // Register this class with RooNumIntConfig
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory
53 
55 {
56  RooRealVar maxEval2D("maxEval2D","Max number of function evaluations for 2-dim integrals",100000) ;
57  RooRealVar maxEval3D("maxEval3D","Max number of function evaluations for 3-dim integrals",1000000) ;
58  RooRealVar maxEvalND("maxEvalND","Max number of function evaluations for >3-dim integrals",10000000) ;
59  RooRealVar maxWarn("maxWarn","Max number of warnings on precision not reached that is printed",5) ;
60 
61  fact.storeProtoIntegrator(new RooAdaptiveIntegratorND(),RooArgSet(maxEval2D,maxEval3D,maxEvalND,maxWarn)) ;
62 }
63 
64 
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Default ctor
68 
70 {
71  _xmin = 0 ;
72  _xmax = 0 ;
73  _epsRel = 1e-7 ;
74  _epsAbs = 1e-7 ;
75  _nmax = 10000 ;
76  _func = 0 ;
77  _integrator = 0 ;
78  _nError = 0 ;
79  _nWarn = 0 ;
80  _useIntegrandLimits = kTRUE ;
81  _intName = "(none)" ;
82 }
83 
84 
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Constructor of integral on given function binding and with given configuration. The
88 /// integration limits are taken from the definition in the function binding
89 ///_func = function.
90 
93 {
94 
95  _func = new RooMultiGenFunction(function) ;
96  _nWarn = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxWarn")) ;
97  switch (_func->NDim()) {
98  case 1: throw string(Form("RooAdaptiveIntegratorND::ctor ERROR dimension of function must be at least 2")) ;
99  case 2: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval2D")) ; break ;
100  case 3: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEval3D")) ; break ;
101  default: _nmax = static_cast<Int_t>(config.getConfigSection("RooAdaptiveIntegratorND").getRealValue("maxEvalND")) ; break ;
102  }
103  // by default do not use absolute tolerance (see https://root.cern.ch/phpBB3/viewtopic.php?f=15&t=20071 )
104  _epsAbs = 0.0;
105  _epsRel = config.epsRel();
109 
110  _xmin = 0 ;
111  _xmax = 0 ;
112  _nError = 0 ;
113  _nWarn = 0 ;
114  checkLimits() ;
115  _intName = function.getName() ;
116 }
117 
118 
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
122 
124 {
125  RooAbsIntegrator* ret = new RooAdaptiveIntegratorND(function,config) ;
126 
127  return ret ;
128 }
129 
130 
131 
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Destructor
135 
137 {
138  delete[] _xmin ;
139  delete[] _xmax ;
140  delete _integrator ;
141  delete _func ;
142  if (_nError>_nWarn) {
143  coutW(NumIntegration) << "RooAdaptiveIntegratorND::dtor(" << _intName
144  << ") WARNING: Number of suppressed warningings about integral evaluations where target precision was not reached is " << _nError-_nWarn << endl ;
145  }
146 
147 }
148 
149 
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Check that our integration range is finite and otherwise return kFALSE.
153 /// Update the limits from the integrand if requested.
154 
156 {
157  if (!_xmin) {
158  _xmin = new Double_t[_func->NDim()] ;
159  _xmax = new Double_t[_func->NDim()] ;
160  }
161 
162  if (_useIntegrandLimits) {
163  for (UInt_t i=0 ; i<_func->NDim() ; i++) {
164  _xmin[i]= integrand()->getMinLimit(i);
165  _xmax[i]= integrand()->getMaxLimit(i);
166  }
167  }
168 
169  return kTRUE ;
170 }
171 
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// Change our integration limits. Return kTRUE if the new limits are
175 /// ok, or otherwise kFALSE. Always returns kFALSE and does nothing
176 /// if this object was constructed to always use our integrand's limits.
177 
179 {
180  if(_useIntegrandLimits) {
181  oocoutE((TObject*)0,Integration) << "RooAdaptiveIntegratorND::setLimits: cannot override integrand's limits" << endl;
182  return kFALSE;
183  }
184  for (UInt_t i=0 ; i<_func->NDim() ; i++) {
185  _xmin[i]= xmin[i];
186  _xmax[i]= xmax[i];
187  }
188 
189  return checkLimits();
190 }
191 
192 
193 
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Evaluate integral at given function binding parameter values
197 
199 {
201  if (_integrator->Status()==1) {
202  _nError++ ;
203  if (_nError<=_nWarn) {
204  coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName() << ") WARNING: target rel. precision not reached due to nEval limit of "
205  << _nmax << ", estimated rel. precision is " << Form("%3.1e",_integrator->RelError()) << endl ;
206  }
207  if (_nError==_nWarn) {
208  coutW(NumIntegration) << "RooAdaptiveIntegratorND::integral(" << integrand()->getName()
209  << ") Further warnings on target precision are suppressed conform specification in integrator specification" << endl ;
210  }
211  }
212  return ret ;
213 }
214 
RooNumIntConfig::epsRel
Double_t epsRel() const
Definition: RooNumIntConfig.h:51
RooNumIntFactory
Definition: RooNumIntFactory.h:30
RooAbsIntegrator::integrand
const RooAbsFunc * integrand() const
Definition: RooAbsIntegrator.h:54
RooMultiGenFunction
Definition: RooMultiGenFunction.h:27
RooAbsFunc::getMinLimit
virtual Double_t getMinLimit(UInt_t dimension) const =0
RooNumIntConfig::getConfigSection
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Definition: RooNumIntConfig.cxx:222
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
e
#define e(i)
Definition: RSha256.hxx:121
RooMsgService.h
RooFit.h
RooArgSet::getRealValue
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:474
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooAdaptiveIntegratorND::setLimits
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
Definition: RooAdaptiveIntegratorND.cxx:178
RooAbsFunc::getMaxLimit
virtual Double_t getMaxLimit(UInt_t dimension) const =0
xmax
float xmax
Definition: THbookFile.cxx:95
RooAdaptiveIntegratorND::_xmax
Double_t * _xmax
Definition: RooAdaptiveIntegratorND.h:56
coutW
#define coutW(a)
Definition: RooMsgService.h:32
RooAdaptiveIntegratorND::_useIntegrandLimits
Bool_t _useIntegrandLimits
Definition: RooAdaptiveIntegratorND.h:53
TClass.h
RooAdaptiveIntegratorND::checkLimits
virtual Bool_t checkLimits() const
Check that our integration range is finite and otherwise return kFALSE.
Definition: RooAdaptiveIntegratorND.cxx:155
RooAdaptiveIntegratorND::_intName
TString _intName
Definition: RooAdaptiveIntegratorND.h:64
oocoutE
#define oocoutE(o, a)
Definition: RooMsgService.h:48
RooFit::NumIntegration
@ NumIntegration
Definition: RooGlobalFunc.h:69
bool
AdaptiveIntegratorMultiDim.h
RooAbsFunc
Definition: RooAbsFunc.h:23
RooMultiGenFunction::NDim
unsigned int NDim() const
Retrieve the dimension of the function.
Definition: RooMultiGenFunction.h:43
RooAdaptiveIntegratorND::RooAdaptiveIntegratorND
RooAdaptiveIntegratorND()
Default ctor.
Definition: RooAdaptiveIntegratorND.cxx:69
ROOT::Math::AdaptiveIntegratorMultiDim::Status
int Status() const
return status of integration
Definition: AdaptiveIntegratorMultiDim.h:159
RooAdaptiveIntegratorND::integral
virtual Double_t integral(const Double_t *yvec=0)
Evaluate integral at given function binding parameter values.
Definition: RooAdaptiveIntegratorND.cxx:198
xmin
float xmin
Definition: THbookFile.cxx:95
RooAdaptiveIntegratorND::clone
virtual RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
Definition: RooAdaptiveIntegratorND.cxx:123
RooAdaptiveIntegratorND::_epsAbs
Double_t _epsAbs
Definition: RooAdaptiveIntegratorND.h:58
RooAdaptiveIntegratorND::_epsRel
Double_t _epsRel
Definition: RooAdaptiveIntegratorND.h:57
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
ROOT::R::function
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
ROOT::Math::AdaptiveIntegratorMultiDim::Integral
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[]
Definition: AdaptiveIntegratorMultiDim.h:129
RooAdaptiveIntegratorND::_nmax
Int_t _nmax
Definition: RooAdaptiveIntegratorND.h:59
RooNumIntFactory::storeProtoIntegrator
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...
Definition: RooNumIntFactory.cxx:119
RooAdaptiveIntegratorND::_xmin
Double_t * _xmin
Definition: RooAdaptiveIntegratorND.h:55
RooRealVar.h
ROOT::Math::AdaptiveIntegratorMultiDim
Definition: AdaptiveIntegratorMultiDim.h:94
unsigned int
ROOT::Math::AdaptiveIntegratorMultiDim::RelError
double RelError() const
return relative error
Definition: AdaptiveIntegratorMultiDim.h:147
RooNumber.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooAdaptiveIntegratorND::registerIntegrator
static void registerIntegrator(RooNumIntFactory &fact)
Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory...
Definition: RooAdaptiveIntegratorND.cxx:54
TObject
Definition: TObject.h:37
RooAdaptiveIntegratorND::_integrator
ROOT::Math::AdaptiveIntegratorMultiDim * _integrator
ROOT::Math multi-parameter function binding.
Definition: RooAdaptiveIntegratorND.h:63
RooAdaptiveIntegratorND::~RooAdaptiveIntegratorND
virtual ~RooAdaptiveIntegratorND()
Destructor.
Definition: RooAdaptiveIntegratorND.cxx:136
RooAdaptiveIntegratorND::_nWarn
Int_t _nWarn
Definition: RooAdaptiveIntegratorND.h:61
RooNumIntConfig
Definition: RooNumIntConfig.h:25
RooAbsIntegrator
Definition: RooAbsIntegrator.h:22
RooAdaptiveIntegratorND
Definition: RooAdaptiveIntegratorND.h:26
RooFit::Integration
@ Integration
Definition: RooGlobalFunc.h:67
RooRealVar
Definition: RooRealVar.h:36
RooAbsFunc::getName
virtual const char * getName() const
Definition: RooAbsFunc.h:59
Riostream.h
RooAdaptiveIntegratorND::_nError
Int_t _nError
Definition: RooAdaptiveIntegratorND.h:60
RooAdaptiveIntegratorND::_func
RooMultiGenFunction * _func
Definition: RooAdaptiveIntegratorND.h:62
RooAdaptiveIntegratorND.h
RooNumIntFactory.h
RooArgSet
Definition: RooArgSet.h:28
RooMultiGenFunction.h
ROOT::Math::AdaptiveIntegratorMultiDim::SetFunction
void SetFunction(const IMultiGenFunction &f)
set the integration function (must implement multi-dim function interface: IBaseFunctionMultiDim)
Definition: AdaptiveIntegratorMultiDim.cxx:63
int