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

From: Dr. John Krane (jkrane@netzero.com)
Date: Thu Apr 01 2004 - 18:32:05 MEST


Hi Jan,

It is the easiest thing in the world.  Look at the following 
pseudo-code; just change the specifics to match your needs:

Say you have a class like this:
class myclass {
     ...etc...

    void myfittingfunction(double *arg1, double *arg2, ...);
}
void myclass::myfittingfunction(double *arg1, double *arg2, ...){
   blah blah
}

In your main .cpp file, at the top before main(), instantiate your class 
and then put your wrapper function:

myclass theClass;    //use any arguments you might need for the 
constructor of course
void mywrapper(double *arg1, double *arg2, ...){
       myclass::myfittingfunction(arg1, arg2, ...);  //this is it, a one 
line function
}

Then, when TVirutalFitter or TMinuit wants the function pointer, give it 
mywrapper.  Use of a class was essential to me because of all the setup 
I needed for my fits.  I could have many, many member functions to tweak 
the way the class looked at the data, and a function to tell Minuit what 
the chisquare was at any given time.  The I was a little embarrassed at 
how long it took me to think of the wrapper the first time!

Again, if you really want to keep things out of the global namespace, 
you could probably just put the wrapper and class declaration in one.  I 
never bothered, so I don't know what complications, if any, might arise.

    - John

Jan CONRAD wrote:

>Dear John,
>
> could you tell me exactly how you did this ?
>
>cheers,
>Jan
>
>
>
>  
>
>>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 ?
>>>
>>>cheers and thanks,
>>>
>>>Jan
>>>
>>>
>>>
>>>-----------------------------------------------------------------
>>>Jan CONRAD, PH/EP Dept., CERN, CH-1211 Geneva 23, Switzerland
>>>+41 22 767 0182, Office 160-1-0012
>>>-----------------------------------------------------------------
>>>
>>>
>>>
>>> 
>>>
>>>      
>>>
>>    
>>
>
>  
>

-- 

Dr. John Krane
jkrane@netzero.com



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