FcnAdapter.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: FcnAdapter.h 25529 2008-09-25 09:53:11Z moneta $
00002 // Author: L. Moneta    10/2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 ROOT Foundation,  CERN/PH-SFT                   *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #ifndef ROOT_Fit_FcnAdapter_H_
00011 #define ROOT_Fit_FcnAdapter_H_
00012 
00013 #ifndef ROOT_Math_IFunction
00014 #include "Math/IFunction.h"
00015 #endif
00016 
00017 
00018 //___________________________________________________________
00019 //
00020 // Adapt the interface used in TMinuit (and the TVirtualFitter) for 
00021 // passing the objective function in a IFunction  interface 
00022 // (ROOT::Math::IMultiGenFunction)
00023 //
00024 
00025 namespace ROOT { 
00026 
00027    namespace Fit { 
00028 
00029 class FcnAdapter : public ROOT::Math::IMultiGenFunction {
00030 
00031 public:
00032 
00033    FcnAdapter(void (*fcn)(int&, double*, double&, double*, int ), int dim = 0) : 
00034       fDim(dim),
00035       fFCN(fcn)
00036    {}
00037 
00038    virtual ~FcnAdapter() {}
00039 
00040    virtual  unsigned int NDim() const { return fDim; }
00041 
00042    ROOT::Math::IMultiGenFunction * Clone() const { 
00043       return new FcnAdapter(fFCN,fDim);
00044    }
00045 
00046    void SetDimension(int dim) { fDim = dim; }
00047 
00048 private: 
00049 
00050    virtual double DoEval(const double * x) const { 
00051       double fval = 0; 
00052       int dim = fDim; 
00053       // call with flag 4
00054       fFCN(dim, 0, fval, const_cast<double *>(x), 4); 
00055       return fval; 
00056    }
00057 
00058 private:
00059 
00060    unsigned int fDim;  
00061    void (*fFCN)(int&, double*, double&, double*, int);
00062    
00063 
00064 };
00065 
00066    } // end namespace Fit
00067 
00068 } // end namespace ROOT
00069 
00070 #endif //ROOT_Fit_FcnAdapter

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