FCNGradAdapter.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id$
00002 // Author: L. Moneta    10/2006  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2006 ROOT Foundation,  CERN/PH-SFT                   *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #ifndef ROOT_Minuit2_FCNGradAdapter
00011 #define ROOT_Minuit2_FCNGradAdapter
00012 
00013 #ifndef ROOT_Minuit2_FCNGradientBase
00014 #include "Minuit2/FCNGradientBase.h"
00015 #endif
00016 
00017 //#define DEBUG
00018 #ifdef DEBUG
00019 #include <iostream> 
00020 #endif
00021 
00022 namespace ROOT {
00023 
00024    namespace Minuit2 {
00025 
00026 /** 
00027 
00028 
00029 template wrapped class for adapting to FCNBase signature a IGradFunction
00030 
00031 @author Lorenzo Moneta
00032 
00033 @ingroup Minuit
00034 
00035 */
00036 
00037 template< class Function> 
00038 class FCNGradAdapter : public FCNGradientBase {
00039 
00040 public:
00041 
00042    FCNGradAdapter(const Function & f, double up = 1.) : 
00043       fFunc(f) , 
00044       fUp (up) , 
00045       fGrad(std::vector<double>(fFunc.NDim() ) ) 
00046 
00047    {}
00048 
00049    ~FCNGradAdapter() {}
00050 
00051   
00052    double operator()(const std::vector<double>& v) const { 
00053       return fFunc.operator()(&v[0]); 
00054    }
00055    double operator()(const double *  v) const { 
00056       return fFunc.operator()(v); 
00057    }
00058 
00059    double Up() const {return fUp;}
00060   
00061    std::vector<double> Gradient(const std::vector<double>& v) const { 
00062       fFunc.Gradient(&v[0], &fGrad[0]);
00063 
00064 #ifdef DEBUG
00065       std::cout << " gradient in FCNAdapter = { " ;
00066       for (unsigned int i = 0; i < fGrad.size(); ++i) 
00067          std::cout << fGrad[i] << "\t";
00068       std::cout << "}" << std::endl;
00069 #endif
00070       return fGrad; 
00071    }
00072    // forward interface
00073    //virtual double operator()(int npar, double* params,int iflag = 4) const;
00074    bool CheckGradient() const { return false; } 
00075 
00076 private:
00077    const Function & fFunc; 
00078    double fUp; 
00079    mutable std::vector<double> fGrad; 
00080 };
00081 
00082    } // end namespace Minuit2
00083 
00084 } // end namespace ROOT
00085 
00086 
00087 
00088 #endif //ROOT_Minuit2_FCNGradAdapter

Generated on Tue Jul 5 14:25:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1