RooDerivative.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooDerivative.cxx 28259 2009-04-16 16:21:16Z 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 // RooDerivative represents the first, second, or third order derivative
00021 // of any RooAbsReal as calculated (numerically) by the MathCore Richardson
00022 // derivator class.
00023 // END_HTML
00024 //
00025 
00026 
00027 #include "RooFit.h"
00028 
00029 #include "Riostream.h"
00030 #include "Riostream.h"
00031 #include <math.h>
00032 #include <string>
00033 
00034 #include "RooDerivative.h"
00035 #include "RooAbsReal.h"
00036 #include "RooAbsPdf.h"
00037 #include "RooErrorHandler.h"
00038 #include "RooArgSet.h"
00039 #include "RooMsgService.h"
00040 #include "RooRealVar.h"
00041 #include "RooFunctor.h"
00042 
00043 #include "Math/WrappedFunction.h"
00044 #include "Math/RichardsonDerivator.h"
00045 
00046 ClassImp(RooDerivative)
00047 ;
00048 
00049 
00050 //_____________________________________________________________________________
00051 RooDerivative::RooDerivative() : _ftor(0), _rd(0)
00052 {
00053   // Default constructor
00054 }
00055 
00056 
00057 
00058 //_____________________________________________________________________________
00059 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, Int_t orderIn, Double_t epsIn) :
00060   RooAbsReal(name, title),
00061   _order(orderIn),
00062   _eps(epsIn),
00063   _nset("nset","nset",this,kFALSE,kFALSE),
00064   _func("function","function",this,func),
00065   _x("x","x",this,x),
00066   _ftor(0),
00067   _rd(0)
00068 {
00069   if (_order<0 || _order>3 ) {
00070     throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
00071   }
00072 }
00073 
00074 //_____________________________________________________________________________
00075 RooDerivative::RooDerivative(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Int_t orderIn, Double_t epsIn) :
00076   RooAbsReal(name, title),
00077   _order(orderIn),
00078   _eps(epsIn),
00079   _nset("nset","nset",this,kFALSE,kFALSE),
00080   _func("function","function",this,func),
00081   _x("x","x",this,x),
00082   _ftor(0),
00083   _rd(0)
00084 {
00085   if (_order<0 || _order>3) { 
00086     throw std::string(Form("RooDerivative::ctor(%s) ERROR, derivation order must be 1,2 or 3",name)) ;
00087   }
00088   _nset.add(nset) ;
00089 }
00090 
00091 
00092 
00093 //_____________________________________________________________________________
00094 RooDerivative::RooDerivative(const RooDerivative& other, const char* name) :
00095   RooAbsReal(other, name), 
00096   _order(other._order),  
00097   _eps(other._eps),
00098   _nset("nset",this,other._nset),
00099   _func("function",this,other._func),
00100   _x("x",this,other._x),
00101   _ftor(0),
00102   _rd(0)
00103 {
00104 }
00105 
00106 
00107 
00108 //_____________________________________________________________________________
00109 RooDerivative::~RooDerivative() 
00110 {
00111   // Destructor
00112   if (_rd) delete _rd ;
00113   if (_ftor) delete _ftor ;
00114 }
00115 
00116 
00117 
00118 //_____________________________________________________________________________
00119 Double_t RooDerivative::evaluate() const 
00120 {
00121   // Calculate value
00122   if (!_ftor) {
00123     _ftor = _func.arg().functor(_x.arg(),RooArgSet(),_nset)  ;    
00124     ROOT::Math::WrappedFunction<RooFunctor&> wf(*_ftor);
00125     _rd = new ROOT::Math::RichardsonDerivator(wf,_eps*(_x.max()-_x.min()),kTRUE) ;
00126   }
00127   
00128   switch (_order) {    
00129   case 1: return _rd->Derivative1(_x);
00130   case 2: return _rd->Derivative2(_x);
00131   case 3: return _rd->Derivative3(_x);
00132   }
00133   return 0 ;
00134 }
00135 
00136 
00137 
00138 //_____________________________________________________________________________
00139 Bool_t RooDerivative::redirectServersHook(const RooAbsCollection& /*newServerList*/, Bool_t /*mustReplaceAll*/, Bool_t /*nameChange*/, Bool_t /*isRecursive*/) 
00140 {
00141   // Zap functor and derivator ;
00142   delete _ftor ;
00143   delete _rd ; 
00144   _ftor = 0 ;
00145   _rd = 0 ;
00146   return kFALSE ;
00147 }

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