Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooGaussKronrodIntegrator1D.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 RooGaussKronrodIntegrator1D.cxx
19\class RooGaussKronrodIntegrator1D
20\ingroup Roofitcore
21
22Implements the Gauss-Kronrod integration algorithm.
23
24An Gaussian quadrature method for numerical integration in which
25error is estimation based on evaluation at special points known as
26"Kronrod points." By suitably picking these points, abscissas from
27previous iterations can be reused as part of the new set of points,
28whereas usual Gaussian quadrature would require recomputation of
29all abscissas at each iteration.
30
31This class automatically handles (-inf,+inf) integrals by dividing
32the integration in three regions (-inf,-1), (-1,1), (1,inf) and
33calculating the 1st and 3rd term using a x -> 1/x coordinate
34transformation
35
36This class embeds the Gauss-Kronrod integrator from the GNU
37Scientific Library version 1.5 and applies the 10-, 21-, 43- and
3887-point rule in succession until the required target precision is
39reached
40**/
41
43
44#include <RooArgSet.h>
45#include <RooMsgService.h>
46#include <RooNumIntFactory.h>
47#include <RooNumber.h>
48#include <RooRealVar.h>
49
50#include <TMath.h>
51
52#include <gsl/gsl_integration.h>
53
54#include <cassert>
55#include <cfloat>
56#include <cmath>
57#include <ostream>
58
59using std::endl;
60
61/// \cond ROOFIT_INTERNAL
62
63// register integrator class
64// create a derived class in order to call the protected method of the
65// RoodaptiveGaussKronrodIntegrator1D
66namespace RooFit_internal {
68
69 static void registerIntegrator()
70 {
73 }
74};
75// class used to register integrator at loafing time
76struct Roo_reg_GKInteg1D {
77 Roo_reg_GKInteg1D() { Roo_internal_GKInteg1D::registerIntegrator(); }
78};
79
81} // namespace RooFit_internal
82
83/// \endcond
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Register RooGaussKronrodIntegrator1D, its parameters and capabilities with RooNumIntConfig
88
90{
91 auto creator = [](const RooAbsFunc &function, const RooNumIntConfig &config) {
92 return std::make_unique<RooGaussKronrodIntegrator1D>(function, config);
93 };
94
95 fact.registerPlugin("RooGaussKronrodIntegrator1D", creator, {},
96 /*canIntegrate1D=*/true,
97 /*canIntegrate2D=*/false,
98 /*canIntegrateND=*/false,
99 /*canIntegrateOpenEnded=*/true);
100
101 oocoutI(nullptr, Integration) << "RooGaussKronrodIntegrator1D has been registered" << std::endl;
102}
103
104
105
106////////////////////////////////////////////////////////////////////////////////
107/// Construct integral on 'function' using given configuration object. The integration
108/// range is taken from the definition in the function binding
109
111 : RooAbsIntegrator(function), _useIntegrandLimits(true), _epsAbs(config.epsRel()), _epsRel(config.epsAbs())
112{
113
115}
116
117
118
119////////////////////////////////////////////////////////////////////////////////
120/// Construct integral on 'function' using given configuration object in the given range
121
123 const RooNumIntConfig &config)
124 : RooAbsIntegrator(function),
125 _useIntegrandLimits(false),
126 _epsAbs(config.epsRel()),
127 _epsRel(config.epsAbs()),
128 _xmin(xmin),
129 _xmax(xmax)
130{
132}
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// Perform one-time initialization of integrator
137
139{
140 // Allocate coordinate buffer size after number of function dimensions
141 _x.resize(_function->getDimension());
142
143 return checkLimits();
144}
145
146
147
148////////////////////////////////////////////////////////////////////////////////
149/// Change our integration limits. Return true if the new limits are
150/// ok, or otherwise false. Always returns false and does nothing
151/// if this object was constructed to always use our integrand's limits.
152
154{
156 oocoutE(nullptr,Eval) << "RooGaussKronrodIntegrator1D::setLimits: cannot override integrand's limits" << std::endl;
157 return false;
158 }
159 _xmin= *xmin;
160 _xmax= *xmax;
161 return checkLimits();
162}
163
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// Check that our integration range is finite and otherwise return false.
168/// Update the limits from the integrand if requested.
169
171{
173 assert(nullptr != integrand() && integrand()->isValid());
174 _xmin= integrand()->getMinLimit(0);
175 _xmax= integrand()->getMaxLimit(0);
176 }
177 return true ;
178}
179
180
181
183{
184 auto instance = reinterpret_cast<RooGaussKronrodIntegrator1D*>(data);
185 return instance->integrand(instance->xvec(x)) ;
186}
187
188
189
190////////////////////////////////////////////////////////////////////////////////
191/// Calculate and return integral
192
194{
195 assert(isValid());
196
197 // Copy yvec to xvec if provided
198 if (yvec) {
199 UInt_t i ; for (i=0 ; i<_function->getDimension()-1 ; i++) {
200 _x[i+1] = yvec[i] ;
201 }
202 }
203
204 // Setup glue function
205 gsl_function F;
207 F.params = this ;
208
209 // Return values
210 double result;
211 double error;
212 size_t neval = 0 ;
213
214 // Call GSL implementation of integeator
216
217 return result;
218}
static Roo_reg_AGKInteg1D instance
double RooGaussKronrodIntegrator1D_GSL_GlueFunction(double x, void *data)
#define oocoutE(o, a)
#define oocoutI(o, a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
float xmin
float xmax
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition RooAbsFunc.h:27
Abstract interface for integrators of real-valued functions that implement the RooAbsFunc interface.
bool isValid() const
Is integrator in valid state.
const RooAbsFunc * _function
Pointer to function binding of integrand.
const RooAbsFunc * integrand() const
Return integrand function binding.
bool _valid
Is integrator in valid state?
Implements the Gauss-Kronrod integration algorithm.
double integral(const double *yvec=nullptr) override
Calculate and return integral.
double _xmax
! Upper integration bound
RooGaussKronrodIntegrator1D(const RooAbsFunc &function, const RooNumIntConfig &config)
Construct integral on 'function' using given configuration object.
std::vector< double > _x
! do not persist
friend double RooGaussKronrodIntegrator1D_GSL_GlueFunction(double x, void *data)
bool initialize()
Perform one-time initialization of integrator.
bool checkLimits() const override
Check that our integration range is finite and otherwise return false.
double _xmin
! Lower integration bound
bool setLimits(double *xmin, double *xmax) override
Change our integration limits.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooGaussKronrodIntegrator1D, its parameters and capabilities with RooNumIntConfig.
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
Factory to instantiate numeric integrators from a given function binding and a given configuration.
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
Double_t x[n]
Definition legend1.C:17
double(* function)(double x, void *params)