ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // RooSegmentedIntegrator1D implements an adaptive one-dimensional
21 // numerical integration algorithm.
22 // END_HTML
23 //
24 
25 
26 #include "RooFit.h"
27 #include "Riostream.h"
28 
29 #include "TClass.h"
31 #include "RooArgSet.h"
32 #include "RooRealVar.h"
33 #include "RooNumber.h"
34 #include "RooMsgService.h"
35 #include "RooNumIntFactory.h"
36 
37 #include <assert.h>
38 
39 
40 
41 using namespace std;
42 
44 ;
45 
46 // Register this class with RooNumIntConfig
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactory
50 
52 {
53  RooRealVar numSeg("numSeg","Number of segments",3) ;
55 }
56 
57 
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Constructor
61 ///
62 /// coverity[UNINIT_CTOR]
63 
65 {
66 }
67 
68 
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Constructor of integral on given function binding and with given configuration. The
72 /// integration limits are taken from the definition in the function binding
73 
75  RooAbsIntegrator(function), _config(config)
76 {
77  _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
79 
80  _valid= initialize();
81 }
82 
83 
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Constructor integral on given function binding, with given configuration and
87 /// explicit definition of integration range
88 
90  const RooNumIntConfig& config) :
91  RooAbsIntegrator(function), _config(config)
92 {
93  _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
95  _xmin= xmin;
96  _xmax= xmax;
97 
98  _valid= initialize();
99 }
100 
101 
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Virtual constructor with given function and configuration. Needed by RooNumIntFactory
105 
107 {
108  return new RooSegmentedIntegrator1D(function,config) ;
109 }
110 
111 
112 
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// One-time integrator initialization
117 
119 {
120  _array = 0 ;
121 
122  Bool_t limitsOK = checkLimits();
123  if (!limitsOK) return kFALSE ;
124 
125  // Make array of integrators for each segment
126  _array = new pRooIntegrator1D[_nseg] ;
127 
128  Int_t i ;
129 
130  Double_t segSize = (_xmax - _xmin) / _nseg ;
131 
132  // Adjust integrator configurations for reduced intervals
135 
136  for (i=0 ; i<_nseg ; i++) {
137  _array[i] = new RooIntegrator1D(*_function,_xmin+i*segSize,_xmin+(i+1)*segSize,_config) ;
138  }
139 
140  return kTRUE ;
141 }
142 
143 
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Destructor
147 
149 {
150  if (_array) {
151  for (Int_t i=0 ; i<_nseg ; i++) {
152  delete _array[i] ;
153  }
154  delete _array ;
155  }
156 }
157 
158 
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Change our integration limits. Return kTRUE if the new limits are
162 /// ok, or otherwise kFALSE. Always returns kFALSE and does nothing
163 /// if this object was constructed to always use our integrand's limits.
164 
166 {
167  if(_useIntegrandLimits) {
168  oocoutE((TObject*)0,InputArguments) << "RooSegmentedIntegrator1D::setLimits: cannot override integrand's limits" << endl;
169  return kFALSE;
170  }
171  _xmin= *xmin;
172  _xmax= *xmax;
173  return checkLimits();
174 }
175 
176 
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Check that our integration range is finite and otherwise return kFALSE.
180 /// Update the limits from the integrand if requested.
181 
183 {
184  if(_useIntegrandLimits) {
185  assert(0 != integrand() && integrand()->isValid());
186  _xmin= integrand()->getMinLimit(0);
187  _xmax= integrand()->getMaxLimit(0);
188  }
189  _range= _xmax - _xmin;
190  if(_range <= 0) {
191  oocoutE((TObject*)0,InputArguments) << "RooIntegrator1D::checkLimits: bad range with min >= max" << endl;
192  return kFALSE;
193  }
195 
196  // Adjust component integrators, if already created
197  if (_array && ret) {
198  Double_t segSize = (_xmax - _xmin) / _nseg ;
199  Int_t i ;
200  for (i=0 ; i<_nseg ; i++) {
201  _array[i]->setLimits(_xmin+i*segSize,_xmin+(i+1)*segSize) ;
202  }
203  }
204 
205  return ret ;
206 }
207 
208 
209 
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Evaluate integral at given function binding parameter values
213 
215 {
216  assert(isValid());
217 
218  Int_t i ;
219  Double_t result(0) ;
220  for (i=0 ; i<_nseg ; i++) {
221  result += _array[i]->integral(yvec) ;
222  }
223 
224  return result;
225 }
226 
Double_t epsAbs() const
float xmin
Definition: THbookFile.cxx:93
#define assert(cond)
Definition: unittest.h:542
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
static Int_t isInfinite(Double_t x)
Return true if x is infinite by RooNumBer internal specification.
Definition: RooNumber.cxx:57
STL namespace.
Bool_t initialize()
One-time integrator initialization.
double sqrt(double)
void Class()
Definition: Class.C:29
Double_t epsRel() const
#define oocoutE(o, a)
Definition: RooMsgService.h:48
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactor...
virtual RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const
Virtual constructor with given function and configuration. Needed by RooNumIntFactory.
void function(const char *name_, T fun, const char *docstring=0)
Definition: RExports.h:159
virtual Bool_t checkLimits() const
Check that our integration range is finite and otherwise return kFALSE.
virtual Double_t integral(const Double_t *yvec=0)
Calculate numeric integral at given set of function binding parameters.
TClass * IsA() const
const RooAbsFunc * _function
virtual ~RooSegmentedIntegrator1D()
Destructor.
virtual Double_t getMinLimit(UInt_t dimension) const =0
float xmax
Definition: THbookFile.cxx:93
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
RooIntegrator1D * pRooIntegrator1D
virtual Double_t integral(const Double_t *yvec=0)
Evaluate integral at given function binding parameter values.
virtual Double_t getMaxLimit(UInt_t dimension) const =0
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
double Double_t
Definition: RtypesCore.h:55
Mother of all ROOT objects.
Definition: TObject.h:58
const RooAbsFunc * integrand() const
Bool_t setLimits(Double_t *xmin, Double_t *xmax)
Change our integration limits.
double result[121]
Bool_t isValid() const
const Bool_t kTRUE
Definition: Rtypes.h:91
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)
ClassImp(RooSegmentedIntegrator1D)
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