RooSegmentedIntegrator1D.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooSegmentedIntegrator1D.cxx 36209 2010-10-08 21:37:36Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // RooSegmentedIntegrator1D implements an adaptive one-dimensional 
00021 // numerical integration algorithm.
00022 // END_HTML
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 // Register this class with RooNumIntConfig
00045 
00046 //_____________________________________________________________________________
00047 void RooSegmentedIntegrator1D::registerIntegrator(RooNumIntFactory& fact)
00048 {
00049   // Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactory
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   // Constructor
00061   //
00062   // coverity[UNINIT_CTOR]
00063 }
00064 
00065 
00066 
00067 //_____________________________________________________________________________
00068 RooSegmentedIntegrator1D::RooSegmentedIntegrator1D(const RooAbsFunc& function, const RooNumIntConfig& config) :
00069   RooAbsIntegrator(function), _config(config)
00070 {
00071   // Constructor of integral on given function binding and with given configuration. The
00072   // integration limits are taken from the definition in the function binding
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   // Constructor integral on given function binding, with given configuration and
00088   // explicit definition of integration range
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   // Virtual constructor with given function and configuration. Needed by RooNumIntFactory
00104   
00105   return new RooSegmentedIntegrator1D(function,config) ;
00106 }
00107 
00108 
00109 
00110 typedef RooIntegrator1D* pRooIntegrator1D ;
00111 
00112 //_____________________________________________________________________________
00113 Bool_t RooSegmentedIntegrator1D::initialize()
00114 {
00115   // One-time integrator initialization
00116 
00117   _array = 0 ;
00118   
00119   Bool_t limitsOK = checkLimits(); 
00120   if (!limitsOK) return kFALSE ;
00121 
00122   // Make array of integrators for each segment
00123   _array = new pRooIntegrator1D[_nseg] ;
00124 
00125   Int_t i ;
00126 
00127   Double_t segSize = (_xmax - _xmin) / _nseg ;
00128 
00129   // Adjust integrator configurations for reduced intervals
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   // Destructor
00146 }
00147 
00148 
00149 
00150 //_____________________________________________________________________________
00151 Bool_t RooSegmentedIntegrator1D::setLimits(Double_t* xmin, Double_t* xmax) 
00152 {
00153   // Change our integration limits. Return kTRUE if the new limits are
00154   // ok, or otherwise kFALSE. Always returns kFALSE and does nothing
00155   // if this object was constructed to always use our integrand's limits.
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   // Check that our integration range is finite and otherwise return kFALSE.
00172   // Update the limits from the integrand if requested.
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   // Adjust component integrators, if already created
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   // Evaluate integral at given function binding parameter values
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 

Generated on Tue Jul 5 15:07:30 2011 for ROOT_528-00b_version by  doxygen 1.5.1