ROOT logo
// @(#)root/minuit2:$Id: TFcnAdapter.h 20880 2007-11-19 11:23:41Z rdm $
// Author: L. Moneta    10/2005  

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2005 ROOT Foundation,  CERN/PH-SFT                   *
 *                                                                    *
 **********************************************************************/

#ifndef ROOT_TFcnAdapter_H_
#define ROOT_TFcnAdapter_H_

#ifndef ROOT_Minuit2_FCNGradientBase
#include "Minuit2/FCNGradientBase.h"
#endif

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif

//___________________________________________________________
//
// Adapt the interface used in TMinuit (and the TVirtualFitter) for 
// passing the objective function in a Minuit2 interface 
// (ROOT::Minuit2::FCNGradientBase or ROOT::Minuit2::FCNBase)
//

class TFcnAdapter : public ROOT::Minuit2::FCNGradientBase {

public:

   TFcnAdapter(void (*fcn)(int&, double*, double&, double*, int)) : fFCN(fcn), fUp(1) {}

   virtual ~TFcnAdapter() {}

   const ROOT::Minuit2::FCNBase& Base() const {return *this;}
  
   double operator()(const std::vector<double>&) const;
   double Up() const {return fUp; }
  
   void SetErrorDef(double up) { fUp = up; }

   std::vector<double> Gradient(const std::vector<double>&) const;

   // forward interface
   double operator()(int npar, double* params,int iflag = 4) const;

private:

   void (*fFCN)(int&, double*, double&, double*, int);
   double fUp; 
   mutable std::vector<double> fGradCache; 

   ClassDef(TFcnAdapter,0)  // wrapper class implementing the Minuit2 interface for TMinuit2-like objective functions
};
#endif //ROOT_GFcnAdapter_H_
 TFcnAdapter.h:1
 TFcnAdapter.h:2
 TFcnAdapter.h:3
 TFcnAdapter.h:4
 TFcnAdapter.h:5
 TFcnAdapter.h:6
 TFcnAdapter.h:7
 TFcnAdapter.h:8
 TFcnAdapter.h:9
 TFcnAdapter.h:10
 TFcnAdapter.h:11
 TFcnAdapter.h:12
 TFcnAdapter.h:13
 TFcnAdapter.h:14
 TFcnAdapter.h:15
 TFcnAdapter.h:16
 TFcnAdapter.h:17
 TFcnAdapter.h:18
 TFcnAdapter.h:19
 TFcnAdapter.h:20
 TFcnAdapter.h:21
 TFcnAdapter.h:22
 TFcnAdapter.h:23
 TFcnAdapter.h:24
 TFcnAdapter.h:25
 TFcnAdapter.h:26
 TFcnAdapter.h:27
 TFcnAdapter.h:28
 TFcnAdapter.h:29
 TFcnAdapter.h:30
 TFcnAdapter.h:31
 TFcnAdapter.h:32
 TFcnAdapter.h:33
 TFcnAdapter.h:34
 TFcnAdapter.h:35
 TFcnAdapter.h:36
 TFcnAdapter.h:37
 TFcnAdapter.h:38
 TFcnAdapter.h:39
 TFcnAdapter.h:40
 TFcnAdapter.h:41
 TFcnAdapter.h:42
 TFcnAdapter.h:43
 TFcnAdapter.h:44
 TFcnAdapter.h:45
 TFcnAdapter.h:46
 TFcnAdapter.h:47
 TFcnAdapter.h:48
 TFcnAdapter.h:49
 TFcnAdapter.h:50
 TFcnAdapter.h:51
 TFcnAdapter.h:52
 TFcnAdapter.h:53
 TFcnAdapter.h:54
 TFcnAdapter.h:55
 TFcnAdapter.h:56