00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "RooFit.h"
00027 #include "Riostream.h"
00028
00029 #include "TClass.h"
00030 #include "RooSegmentedIntegrator1D.h"
00031 #include "RooArgSet.h"
00032 #include "RooRealVar.h"
00033 #include "RooNumber.h"
00034 #include "RooMsgService.h"
00035 #include "RooNumIntFactory.h"
00036
00037 #include <assert.h>
00038
00039
00040
00041 ClassImp(RooSegmentedIntegrator1D)
00042 ;
00043
00044
00045
00046
00047 void RooSegmentedIntegrator1D::registerIntegrator(RooNumIntFactory& fact)
00048 {
00049
00050
00051 RooRealVar numSeg("numSeg","Number of segments",3) ;
00052 fact.storeProtoIntegrator(new RooSegmentedIntegrator1D(),numSeg,RooIntegrator1D::Class()->GetName()) ;
00053 }
00054
00055
00056
00057
00058 RooSegmentedIntegrator1D::RooSegmentedIntegrator1D()
00059 {
00060
00061
00062
00063 }
00064
00065
00066
00067
00068 RooSegmentedIntegrator1D::RooSegmentedIntegrator1D(const RooAbsFunc& function, const RooNumIntConfig& config) :
00069 RooAbsIntegrator(function), _config(config)
00070 {
00071
00072
00073
00074 _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
00075 _useIntegrandLimits= kTRUE;
00076
00077 _valid= initialize();
00078 }
00079
00080
00081
00082
00083 RooSegmentedIntegrator1D::RooSegmentedIntegrator1D(const RooAbsFunc& function, Double_t xmin, Double_t xmax,
00084 const RooNumIntConfig& config) :
00085 RooAbsIntegrator(function), _config(config)
00086 {
00087
00088
00089
00090 _nseg = (Int_t) config.getConfigSection(IsA()->GetName()).getRealValue("numSeg",3) ;
00091 _useIntegrandLimits= kFALSE;
00092 _xmin= xmin;
00093 _xmax= xmax;
00094
00095 _valid= initialize();
00096 }
00097
00098
00099
00100
00101 RooAbsIntegrator* RooSegmentedIntegrator1D::clone(const RooAbsFunc& function, const RooNumIntConfig& config) const
00102 {
00103
00104
00105 return new RooSegmentedIntegrator1D(function,config) ;
00106 }
00107
00108
00109
00110 typedef RooIntegrator1D* pRooIntegrator1D ;
00111
00112
00113 Bool_t RooSegmentedIntegrator1D::initialize()
00114 {
00115
00116
00117 _array = 0 ;
00118
00119 Bool_t limitsOK = checkLimits();
00120 if (!limitsOK) return kFALSE ;
00121
00122
00123 _array = new pRooIntegrator1D[_nseg] ;
00124
00125 Int_t i ;
00126
00127 Double_t segSize = (_xmax - _xmin) / _nseg ;
00128
00129
00130 _config.setEpsRel(_config.epsRel()/sqrt(1.*_nseg)) ;
00131 _config.setEpsAbs(_config.epsAbs()/sqrt(1.*_nseg)) ;
00132
00133 for (i=0 ; i<_nseg ; i++) {
00134 _array[i] = new RooIntegrator1D(*_function,_xmin+i*segSize,_xmin+(i+1)*segSize,_config) ;
00135 }
00136
00137 return kTRUE ;
00138 }
00139
00140
00141
00142
00143 RooSegmentedIntegrator1D::~RooSegmentedIntegrator1D()
00144 {
00145
00146 }
00147
00148
00149
00150
00151 Bool_t RooSegmentedIntegrator1D::setLimits(Double_t* xmin, Double_t* xmax)
00152 {
00153
00154
00155
00156
00157 if(_useIntegrandLimits) {
00158 oocoutE((TObject*)0,InputArguments) << "RooSegmentedIntegrator1D::setLimits: cannot override integrand's limits" << endl;
00159 return kFALSE;
00160 }
00161 _xmin= *xmin;
00162 _xmax= *xmax;
00163 return checkLimits();
00164 }
00165
00166
00167
00168
00169 Bool_t RooSegmentedIntegrator1D::checkLimits() const
00170 {
00171
00172
00173
00174 if(_useIntegrandLimits) {
00175 assert(0 != integrand() && integrand()->isValid());
00176 _xmin= integrand()->getMinLimit(0);
00177 _xmax= integrand()->getMaxLimit(0);
00178 }
00179 _range= _xmax - _xmin;
00180 if(_range <= 0) {
00181 oocoutE((TObject*)0,InputArguments) << "RooIntegrator1D::checkLimits: bad range with min >= max" << endl;
00182 return kFALSE;
00183 }
00184 Bool_t ret = (RooNumber::isInfinite(_xmin) || RooNumber::isInfinite(_xmax)) ? kFALSE : kTRUE;
00185
00186
00187 if (_array && ret) {
00188 Double_t segSize = (_xmax - _xmin) / _nseg ;
00189 Int_t i ;
00190 for (i=0 ; i<_nseg ; i++) {
00191 _array[i]->setLimits(_xmin+i*segSize,_xmin+(i+1)*segSize) ;
00192 }
00193 }
00194
00195 return ret ;
00196 }
00197
00198
00199
00200
00201
00202 Double_t RooSegmentedIntegrator1D::integral(const Double_t *yvec)
00203 {
00204
00205
00206 assert(isValid());
00207
00208 Int_t i ;
00209 Double_t result(0) ;
00210 for (i=0 ; i<_nseg ; i++) {
00211 result += _array[i]->integral(yvec) ;
00212 }
00213
00214 return result;
00215 }
00216