Re: TMinuit.SetFCN() casting in a class

Rene Brun (Rene.Brun@cern.ch)
Mon, 14 Dec 1998 08:25:44 +0100


Stephen Bailey wrote:
>
> Hi.
>
> I'm trying to use TMinuit and am having problems with the
> casting of my minimization function for SetFCN(). A snippet
> of my code is:
>
> void (*pf)(Int_t&, Double_t*, Double_t&, Double_t*, Int_t);
> pf = MinusLogLikelihood;
> gMinuit->SetFCN(pf);
>
> MinusLogLikelihood is a member function of the class DataSet
> which contains the fitting routine from which this code comes.
> My compiler (KAI KCC 3.3e) complains
>
> KCC -g +K0 -O0 --no_exceptions -fPIC
> -I/usr/products/root/v2_00_13b/include -c DataSet.cc -o DataSet.o
> "DataSet.cc", line 67: error: a value of type "void (DataSet::*)(Int_t &,
> Double_t *, Double_t &, Double_t *, Int_t)" cannot be assigned
> to an
> entity of type
> "void (*)(Int_t &, Double_t *, Double_t &, Double_t *, Int_t)"
> pf = MinusLogLikelihood;
> ^
>
> If I make MinusLogLikelihood a regular function not belonging to
> any class, these statements compile fine, but then MinusLogLikelihood
> no longer has any access to the data in my DataSet object. Even if
> I provided public access functions, it still wouldn't know which DataSet
> object to use. The example in the tutorial relies upon the data to be
> fit being global. Can this be avoided? Does anyone have experience using
> TMinuit from within the context of a class structure with data belonging
> to objects? I also tried using SetFCN(void *) and the compiler was
> similarly unhappy about my casting.
>
> Thanks.
>
> Stephen

Hi Stephen,
You have the choice of:
- using a global variable (not recommended)
- using TMinuit::SetObjFit(TObject *object)

Suppose you have a class you want to use in your minimisation function
do:
gMinuit->SetObjFit(myClass);
then in the static function (the one given to TMinuit::SetFCN)
you can use your class via gMinuit->GetObjFit().

Rene Brun