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