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(IsA()->GetName()).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(IsA()->GetName()).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_t limitsOK = checkLimits();
122 if (!limitsOK) return kFALSE ;
123
124 // Make array of integrators for each segment
126
127 Int_t i ;
128
129 Double_t 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 kTRUE ;
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 kTRUE if the new limits are
161/// ok, or otherwise kFALSE. Always returns kFALSE and does nothing
162/// if this object was constructed to always use our integrand's limits.
163
165{
167 oocoutE((TObject*)0,InputArguments) << "RooSegmentedIntegrator1D::setLimits: cannot override integrand's limits" << endl;
168 return kFALSE;
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 kFALSE.
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((TObject*)0,InputArguments) << "RooIntegrator1D::checkLimits: bad range with min >= max" << endl;
191 return kFALSE;
192 }
194
195 // Adjust component integrators, if already created
196 if (_array && ret) {
197 Double_t 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
214{
215 assert(isValid());
216
217 Int_t i ;
218 Double_t 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:48
RooIntegrator1D * pRooIntegrator1D
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#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_t getMinLimit(UInt_t dimension) const =0
virtual Double_t getMaxLimit(UInt_t dimension) const =0
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
const RooAbsFunc * _function
Pointer to function binding of integrand.
const RooAbsFunc * integrand() const
Return integrand function binding.
Bool_t isValid() const
Is integrator in valid state.
RooIntegrator1D implements an adaptive one-dimensional numerical integration algorithm.
static TClass * Class()
Bool_t setLimits(Double_t *xmin, Double_t *xmax) override
Change our integration limits.
Double_t integral(const Double_t *yvec=0) override
Calculate numeric integral at given set of function binding parameters.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Double_t epsAbs() const
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
Double_t epsRel() const
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
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...
static Int_t isInfinite(Double_t x)
Return true if x is infinite by RooNumBer internal specification.
Definition: RooNumber.cxx:57
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...
Bool_t setLimits(Double_t *xmin, Double_t *xmax) override
Change our integration limits.
TClass * IsA() const override
Double_t integral(const Double_t *yvec=0) override
Evaluate integral at given function binding parameter values.
Bool_t initialize()
One-time integrator initialization.
~RooSegmentedIntegrator1D() override
Destructor.
RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const override
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
Bool_t checkLimits() const override
Check that our integration range is finite and otherwise return kFALSE.
RooIntegrator1D ** _array
Array of segment integrators.
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
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:64