Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:08

0001 // @(#)root/mathcore:$Id$
0002 // Author: L. Moneta    10/2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 ROOT Foundation,  CERN/PH-SFT                   *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_Fit_FcnAdapter_H_
0011 #define ROOT_Fit_FcnAdapter_H_
0012 
0013 #include "Math/IFunction.h"
0014 
0015 
0016 //___________________________________________________________
0017 //
0018 // Adapt the interface used in TMinuit (and the TVirtualFitter) for
0019 // passing the objective function in a IFunction  interface
0020 // (ROOT::Math::IMultiGenFunction)
0021 //
0022 
0023 namespace ROOT {
0024 
0025    namespace Fit {
0026 
0027 class FcnAdapter : public ROOT::Math::IMultiGenFunction {
0028 
0029 public:
0030 
0031    FcnAdapter(void (*fcn)(int&, double*, double&, double*, int ), int dim = 0) :
0032       fDim(dim),
0033       fFCN(fcn)
0034    {}
0035 
0036    ~FcnAdapter() override {}
0037 
0038     unsigned int NDim() const override { return fDim; }
0039 
0040    ROOT::Math::IMultiGenFunction * Clone() const override {
0041       return new FcnAdapter(fFCN,fDim);
0042    }
0043 
0044    void SetDimension(int dim) { fDim = dim; }
0045 
0046 private:
0047 
0048    double DoEval(const double * x) const override {
0049       double fval = 0;
0050       int dim = fDim;
0051       // call with flag 4
0052       fFCN(dim, nullptr, fval, const_cast<double *>(x), 4);
0053       return fval;
0054    }
0055 
0056 private:
0057 
0058    unsigned int fDim;
0059    void (*fFCN)(int&, double*, double&, double*, int);
0060 
0061 };
0062 
0063    } // end namespace Fit
0064 
0065 } // end namespace ROOT
0066 
0067 #endif //ROOT_Fit_FcnAdapter