Hi John,
The TF1 doc has this remark:
//
// WHY TF1 CANNOT ACCEPT A CLASS MEMBER FUNCTION ?
// ===============================================
// This is a frequently asked question.
// C++ is a strongly typed language. There is no way for TF1 (without
// recompiling this class) to know about all possible user defined data types.
// This also apply to the case of a static class function.
In the C-style function referenced by TF1 and called from TH1::Fit,
you can call your class member function.
You can either use a global to access an object of your class
or use TVirtualFitter::SetUserFunc to register the address of a TObject*
to the fitter. In the C-style function, you can retrieve this pointer
with something like:
TObject *myobject = TVirtualfitter::GetFitter()->GetUserFunc();
Rene Brun
"Dr. John Krane" wrote:
>
> Hi,
>
> I'm trying to use weighted histograms to fit a distribution. Because I
> want to be able to change the histos that I'm using as components, I
> made a little class that holds an array of TH1F. A member function
> provides the weighted sum of these histograms, with the weights being
> the fit parameters and the interface being as required by TF1. So I
> tried to make a TF1 for use with the ->Fit method, like this:
>
> cerr<< "Assign the histos that contribute to fit"<<endl;
> func_fit fclass;
> fclass.add_param(d1or); //first histo
> fclass.add_param(d1crl); //second histo...etc.
>
> TF1 *fitFcn = new
> TF1("fitFcn",fclass.func_val,-600.,-1.,fclass.get_nparam());
>
> Well the compiler within ROOT doesn't like that, so I tried making a
> pointer-to-member-function and giving that to root, but I didn't get
> anywhere. Does anybody know how to provide a member-function to TF1? I
> think my class solution is quite clean for what I'd like to do, but I
> need to get around this barrier...
>
> - John
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET