TVirtualFitter::SetFCN(void *fcn);

Hi all,
I’m trying to include a TVirtualFitter object in a class.
The idea is to create an object of this class and passing it the data to fit.

So I declared some methods (SetFcn(), CallMigrad(),…) which will call the correspondent TVirtualFitter method (SetFCN,…).

In attachment you have the header and source of the class.
I try to compile in this way:

[quote] g++ -c -Itmp -Iroot-config --incdir SbtGrandFit.cc
[/quote]

But I get:

The relevant line in source file is:

      _minuit = TVirtualFitter::Fitter(0, _nparms);
    // ...
    _minuit->SetFCN(calcChi2);

where in the header:

     // the fitter
    TVirtualFitter *_minuit;
   // ...
   // function to be passed to fitter
    void calcChi2(Int_t &, Double_t *, Double_t &f, Double_t *x, Int_t iflag);

A way to avoid that problem is to declare calcChi2 method as static, but then I cannot access the data that I pass to class c’tor.

So, How can I call TVirtualFitter methods in a class?

Many thanks in advance!

Regards,
Marco

PS root-version: 5.20
arch: linux - 32 bit
distro: Ubuntu (7.04)
gcc version 4.1.2
SbtGrandFit.tar (20 KB)

For TVirtualFitter::SetFCN the function must be static or a free function.

The best way is to minimize your chi2 function using the ROOT::Math::Minimizer interface

root.cern.ch/root/htmldoc/ROOT__ … mizer.html

where you can pass a function object in the SetFunction method.
An example of using this interface is

root.cern.ch/viewvc/trunk/math/m … tMinim.cxx

Best Regards

Lorenzo

Dear Lorenzo,
many thanks for the hint.

I’ve tried the example you suggested, but…

it crashes when it tries to use new ROOT::Math::Minimizer.

I was able to find the problematic line:

std::vector<double> xmin(func.NDim() );

If I ask for func.NDim() in this way: std::cout << "func.NDim() = " << func.NDim() << "\n";
I get:[quote]
*** Break *** illegal instruction
func.NDim() = Using host libthread_db library "[/quote]

I’m using version 5.20 on a linux machine.

Do you have an idea of what’s wrong here?
Many thanks in advance!

Regards,
Marco Bomben

These examples are not designed to run in CINT. Use AClic by doing:

root>.L math/mathcore/test/fit/testMinim.cxx+

Lorenzo

Thanks Lorenzo for the explanation.

I tried but…

But If I try to call directly one of the other ‘functions’:

[quote]root [0] .L math/mathcore/test/fit/testMinim.cxx++
Info in TUnixSystem::ACLiC: creating shared library /home/bomben/work/root-520/root/./math/mathcore/test/fit/testMinim_cxx.so
root [1] testChebyQuad()


    CHEBYQUAD function test , n = 8

FUNC 3.03141


    Test new ROOT::Math::Minimizer
    Minimizer is Minuit2  

NCalls: 312 , 67 MinValue: 0.00351687378550893199 Edm: 5.98445366778502958e-11
Time: 0.124415 , 0.11
Minimum X values
0.0431508223686 , 0.266326366553 , 0.193087657126 , 0.499997583509 , 0.499997279803 , 0.733670910913 , 0.806904384851 ,
0.956845750882



    Test new ROOT::Math::Minimizer
    Minimizer is Minuit  

CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT
CHECK OF GRADIENT CALCULATION IN FCN
PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT

NCalls: 264 , 66 MinValue: 0.00351687372951945288 Edm: 4.29288063917702604e-12
Time: 0.022059 , 0.01
Minimum X values
0.0431526261688 , 0.193090610754 , 0.266328443666 , 0.50000063507 , 0.499999398924 , 0.733672001726 , 0.806908773757 ,
0.956847100058



    Test new ROOT::Math::Minimizer
    Minimizer is GSLMultiMin  ConjugateFR

Error in TUnixSystem::DynamicPathName: MathMore[.so | .sl | .dl | .a | .dll] does not exist in .:/home/bomben/work/root-520/root/lib::/home/bomben/work/root-520/root/lib:/home/bomben/work/root-520/root/lib:/home/bomben/work/root-520/root/cint/cint/stl
Error using minimizer GSLMultiMin ConjugateFR


    Test new ROOT::Math::Minimizer
    Minimizer is GSLMultiMin  ConjugatePR

Error in TUnixSystem::DynamicPathName: MathMore[.so | .sl | .dl | .a | .dll] does not exist in .:/home/bomben/work/root-520/root/lib::/home/bomben/work/root-520/root/lib:/home/bomben/work/root-520/root/lib:/home/bomben/work/root-520/root/cint/cint/stl
Error using minimizer GSLMultiMin ConjugatePR


    Test new ROOT::Math::Minimizer
    Minimizer is GSLMultiMin  BFGS

Error in TUnixSystem::DynamicPathName: MathMore[.so | .sl | .dl | .a | .dll] does not exist in .:/home/bomben/work/root-520/root/lib::/home/bomben/work/root-520/root/lib:/home/bomben/work/root-520/root/lib:/home/bomben/work/root-520/root/cint/cint/stl
Error using minimizer GSLMultiMin BFGS
(int)(-1)
[/quote]

something works…

Since your idea was to use SetFunction method via Minimizer (and it looks that this part is working in that macro) I will try to implement that in my class.
But I’m interested in getting that example working too, of course :smiley:

Many thanks in advance!

Regards,
Marco Bomben

Hi,

I cannot reproduce your first problem, but I am using 5.22.

The other error is due to a missing MathMore library. For running all the test you need to have built libMathMore and this is possible only if you have before a version of GSL (>=1.8) installed in your system.
The other tests however seem to work.

Best Regards

Lorenzo[/code]

Dear Lorenzo,
thanks for quick reply.
Yes, MathMore library was missing 'cause gsl was missing too.
Now testChebyQuad() works, though main() still not.

Many thanks for your help!

Regards,
Marco Bomben

[quote]Now testChebyQuad() works, though main() still not.[/quote]Which is the expected behavior. ‘main’ is to be used only if you compile the example as a standalone executable (and hence execute things that ought to be executed once and are already executed by the main in root.exe :slight_smile:).

Cheers,
Philippe.

Dear Lorenzo and Philippe,
thank you very much for the help!
I was able to run the example and then to build my class and test program.

Regards,
Marco Bomben
errfit.tar (30 KB)