Re: [ROOT] TMinuit with fcn as a member function of a class ?

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Thu Apr 01 2004 - 23:56:42 MEST


Hi,

"Dr. John Krane" <jkrane@netzero.com> wrote concerning
  Re: [ROOT] TMinuit with fcn as a member function of a class ? [Thu, 01 Apr 2004 08:29:31 -0600] 
----------------------------------------------------------------------
> The global function was certainly my solution.  It was just a wrapper to 
> the member function.  Give it a very similar name or put it in a 
> namespace maybe?  Not so bad.
> 
>     - J
> 
> Jan CONRAD wrote:
> 
> >Dear rooters,
> >
> > I try to use TMinuit inside a class and try to have fcn as a member 
> >function of this class, i.e.: gMinuit->SetFCN(pointerToFCN). This seems 
> >not to work, and was a known problem, I found a couple of mails some years 
> >ago. I don't like the workaround (defining a global function). 
> >
> >Is there any other solution to this problem ?

Yes, but it does involve using a global function of sort, but it's
declared static, so it's not accessible from outside it's compilation
unit: 

  // Header file 
  class MyFitfunction 
  { 
    static MyFitFunction* _instance;
    MyFitFunction() {}
    MyFitFunction(const MyFitFunction& o) {}
    MyFitFunction& operator=(const MyFitFunction& o) { return *this; }
  public:
    static MyFitFunction& Instance();
    Double_t Function(Int_t&, Double_t*, Double_t*, Int_t);
    static void Use();
  };

  // Source 
  static myFitFunction(Int_t& a, Double_t* p, Double_t &f, Double_t* d, Int_t f)  
  {
    MyFitFunction& fitFunc = MyFitFunction::Instance();
    f = fitFunction.Function(a, p, d, f);
  }

  MyFitFunction* MyFitFunction::_instance = 0;

  MyFitFunction* MyFitFunction::Instance() 
  { 
    if (!_instance) _instance = new MyFitFunction;
    return _instance;
  }

  MyFitFunction::MyFitFunction() 
  {}

  void MyFitFunction::Use() 
  {
    gMinuit->SetFcn(myFitFunction);
  }

Another way would be to use the Functor stuff from
www.moderncppdesign.com. 

My 2 cents.

Yours,

 ___  |  Christian Holm Christensen 
  |_| |	 -------------------------------------------------------------
    | |	 Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|	          DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|	          Denmark                    Office: (+45) 353  25 404
 ____|	 Email:   cholm@nbi.dk               Web:    www.nbi.dk/~cholm
 | |



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:07 MET