Logo ROOT  
Reference Guide
RooSegmentedIntegrator1D.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 RooSegmentedIntegrator1D.cxx
19\class RooSegmentedIntegrator1D
20\ingroup Roofitcore
21
22RooSegmentedIntegrator1D implements an adaptive one-dimensional
23numerical integration algorithm.
24**/
25
26#include "Riostream.h"
27
28#include "TClass.h"
30#include "RooArgSet.h"
31#include "RooRealVar.h"
32#include "RooNumber.h"
33#include "RooMsgService.h"
34#include "RooNumIntFactory.h"
35
36#include <assert.h>
37
38
39
40using namespace std;
41
43;
44
45// Register this class with RooNumIntConfig
46
47////////////////////////////////////////////////////////////////////////////////
48/// Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactory
49
51{
52 RooRealVar numSeg("numSeg","Number of segments",3) ;
54}
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Constructor
60///
61/// coverity[UNINIT_CTOR]
62
64{
65}
66
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// Constructor of integral on given function binding and with given configuration. The
71/// integration limits are taken from the definition in the function binding
72
74 RooAbsIntegrator(function), _config(config)
75{
76 _nseg = (Int_t) config.getConfigSection(ClassName()).getRealValue("numSeg",3) ;
78
80}
81
82
83
84////////////////////////////////////////////////////////////////////////////////
85/// Constructor integral on given function binding, with given configuration and
86/// explicit definition of integration range
87
89 const RooNumIntConfig& config) :
90 RooAbsIntegrator(function), _config(config)
91{
92 _nseg = (Int_t) config.getConfigSection(ClassName()).getRealValue("numSeg",3) ;
94 _xmin= xmin;
95 _xmax= xmax;
96
98}
99
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
104
106{
107 return new RooSegmentedIntegrator1D(function,config) ;
108}
109
110
111
113
114////////////////////////////////////////////////////////////////////////////////
115/// One-time integrator initialization
116
118{
119 _array = 0 ;
120
121 bool limitsOK = checkLimits();
122 if (!limitsOK) return false ;
123
124 // Make array of integrators for each segment
126
127 Int_t i ;
128
129 double segSize = (_xmax - _xmin) / _nseg ;
130
131 // Adjust integrator configurations for reduced intervals
134
135 for (i=0 ; i<_nseg ; i++) {
136 _array[i] = new RooIntegrator1D(*_function,_xmin+i*segSize,_xmin+(i+1)*segSize,_config) ;
137 }
138
139 return true ;
140}
141
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Destructor
146
148{
149 if (_array) {
150 for (Int_t i=0 ; i<_nseg ; i++) {
151 delete _array[i] ;
152 }
153 delete [] _array ;
154 }
155}
156
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Change our integration limits. Return true if the new limits are
161/// ok, or otherwise false. Always returns false and does nothing
162/// if this object was constructed to always use our integrand's limits.
163
165{
167 oocoutE(nullptr,InputArguments) << "RooSegmentedIntegrator1D::setLimits: cannot override integrand's limits" << endl;
168 return false;
169 }
170 _xmin= *xmin;
171 _xmax= *xmax;
172 return checkLimits();
173}
174
175
176
177////////////////////////////////////////////////////////////////////////////////
178/// Check that our integration range is finite and otherwise return false.
179/// Update the limits from the integrand if requested.
180
182{
184 assert(0 != integrand() && integrand()->isValid());
187 }
188 _range= _xmax - _xmin;
189 if(_range <= 0) {
190 oocoutE(nullptr,InputArguments) << "RooIntegrator1D::checkLimits: bad range with min >= max" << endl;
191 return false;
192 }
193 bool ret = (RooNumber::isInfinite(_xmin) || RooNumber::isInfinite(_xmax)) ? false : true;
194
195 // Adjust component integrators, if already created
196 if (_array && ret) {
197 double segSize = (_xmax - _xmin) / _nseg ;
198 Int_t i ;
199 for (i=0 ; i<_nseg ; i++) {
200 _array[i]->setLimits(_xmin+i*segSize,_xmin+(i+1)*segSize) ;
201 }
202 }
203
204 return ret ;
205}
206
207
208
209
210////////////////////////////////////////////////////////////////////////////////
211/// Evaluate integral at given function binding parameter values
212
213double RooSegmentedIntegrator1D::integral(const double *yvec)
214{
215 assert(isValid());
216
217 Int_t i ;
218 double result(0) ;
219 for (i=0 ; i<_nseg ; i++) {
220 result += _array[i]->integral(yvec) ;
221 }
222
223 return result;
224}
225
#define oocoutE(o, a)
Definition: RooMsgService.h:52
RooIntegrator1D * pRooIntegrator1D
int Int_t
Definition: RtypesCore.h:45
#define ClassImp(name)
Definition: Rtypes.h:375
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
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition: RooAbsFunc.h:27
virtual double getMaxLimit(UInt_t dimension) const =0
virtual double getMinLimit(UInt_t dimension) const =0
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
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.
RooIntegrator1D implements an adaptive one-dimensional numerical integration algorithm.
static TClass * Class()
double integral(const double *yvec=nullptr) override
Calculate numeric integral at given set of function binding parameters.
bool setLimits(double *xmin, double *xmax) override
Change our integration limits.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
void setEpsRel(double newEpsRel)
Set relative convergence criteria (convergence if std::abs(Err)/abs(Int)<newEpsRel)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
double epsRel() const
double epsAbs() const
void setEpsAbs(double newEpsAbs)
Set absolute convergence criteria (convergence if std::abs(Err)<newEpsAbs)
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
bool storeProtoIntegrator(RooAbsIntegrator *proto, const RooArgSet &defConfig, const char *depName="")
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Definition: RooNumber.h:26
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
RooSegmentedIntegrator1D implements an adaptive one-dimensional numerical integration algorithm.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactor...
double integral(const double *yvec=nullptr) override
Evaluate integral at given function binding parameter values.
bool checkLimits() const override
Check that our integration range is finite and otherwise return false.
~RooSegmentedIntegrator1D() override
Destructor.
RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const override
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
bool setLimits(double *xmin, double *xmax) override
Change our integration limits.
RooIntegrator1D ** _array
Array of segment integrators.
bool initialize()
One-time integrator initialization.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:439
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:207
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167
@ InputArguments
Definition: RooGlobalFunc.h:63