Hi John, > Are you saying it is possible or that it *should* be possible to use > pointer-to-static-member-function? For sure it is possible, I did it a lot of times. There is no any difference between C-function and static function of a class. For instance such approach I used it TThread class. > Either it is not possible or the syntax is tricky indeed! sintax no more tricky than all busyness with the pointers to C++ functions Victor Victor M. Perevoztchikov perev@bnl.gov Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000 tel office : 631-344-7894; fax 631-344-4206; ----- Original Message ----- From: "Dr. John Krane" <jkrane@netzero.com> To: "Victor Perevoztchikov" <perev@bnl.gov> Cc: "Rene Brun" <Rene.Brun@cern.ch>; <roottalk@pcroot.cern.ch> Sent: Tuesday, July 22, 2003 1:24 PM Subject: Re: [ROOT] fitting with a member function > Hi Victor, > > Are you saying it is possible or that it *should* be possible to use > pointer-to-static-member-function? I played around with pointers to > static member functions for quite some time before writing to Roottalk. > Either it is not possible or the syntax is tricky indeed! > > If it is not currently possible to just use a pointer I will continue > with Philippe's proposed solution. My Root v3.05/06 is building right > now... > > - John > > Victor Perevoztchikov wrote: > > Hi Rene, > > just remark, > > > >>// This also apply to the case of a static class function. > > > > You can use static function of class. There is no difference in > > C-function and static function of a class. The pointer to function is the > > same. > > It is used for example in TThread > > > > > > Also, I think , it would be good to allow do the fit with the special class. > > Let say > > class THFun { public: virtual Fcn(...)=0;} > > Then user can create his own class inherited from THFun and overload Fcn. > > and provide the pointer of the object to TH1 class > > > > It is more flexible than just user function, because user can have some non > > global > > variables, to communicate, some additional methods etc.... > > The same for TMinuit. > > > > Victor > > > > > > Victor M. Perevoztchikov perev@bnl.gov > > Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000 > > tel office : 631-344-7894; fax 631-344-4206; > > > > ----- Original Message ----- > > From: "Rene Brun" <Rene.Brun@cern.ch> > > To: "Dr. John Krane" <jkrane@netzero.com> > > Cc: <roottalk@pcroot.cern.ch> > > Sent: Tuesday, July 22, 2003 12:31 PM > > Subject: Re: [ROOT] fitting with a member function > > > > > > > >>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); file://first histo > >>> fclass.add_param(d1crl); file://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