Hi Jeff, One cannot pass a pointer to a member function as argument to TF1. You can solve your problem by using the second argument of your parameters to contain a pointer to your objects or equivalent as you already do with the first parameter. I could add an additional TF1 constructor accepting a TObject* as argument. Rene Brun Jeffrey McDonald wrote: > > Hi, > > I've a question regarding using the root class TF1 to make plots > from a function in a class. The class is a library (or the makings of > one) to describe/plot LaplaceTransforms of a given type. The user > creates a "simple pole in frequency space" and the function can return > the value of the function evaluated in the time domain. I can send > you the class library if you wish. > > The user generates a LaplaceTransform via: > > LaplaceTransformA *Lt1 = new LaplaceTransformA(3,0.15); // > multiplicity 3 and simple pole at -0.15 > LaplaceTransformA *Lt2 = new LaplaceTransformA(4,0.15); > > Lt1->time_domain(double *time); // function returns double > returns the value of the function in the time domain. > I'd like to be able to do something like: > > TF1 *f1 = new TF1("calibration",Lt1->time_domain,0,1 ,1); > > but this doesn't work. So, I have to calculate the value by taking > having another function > which takes a pointer to the LaplaceTransformA and then accesses the > Lt1->time_domain() and > returns the functional value. > > A snipet of code: > > Lt[i] = new LaplaceTransformA(i+3,0.15); > ltplot(& Lt[i]); > > uses the functions below to calculate the functional value of > Lt[i].time_domain(); > > void ltplot(LaplaceTransformA * ltp){ > TF1 *f1 = new TF1("calibration",plot_laplace,0,1 ,1); > f1->SetParameters((double *)ltp); > f1->Draw(); > return; > } > > and > > double plot_laplace(double *t,double *par ){ > > LaplaceTransformA *Lt2 = (LaplaceTransformA *)par; > double rvalue = Lt2->time_domain(t) ; > return (rvalue); > }; > > -----This works, but there is an apparent limitation if I want to Draw > multiple functions on the same > canvas, i.e, it doesn't look like I can use have multiple instances > of TF1s pointing to the same > function (plot_laplace) -- with different "parameters". For example, > > TF1 *f2 = new TF1("calibration",plot_laplace,0,1 ,1); > f2->SetParameters((double *)Lt2); > > will give an exception if I try to draw it -- I can draw the function > again if I re-create f1. > What I'd really like is to be able to have a function draw a routine > from a class. Unfortunately, I'm > not schooled enough in C++/ROOT to be able to know how do to do this, > yet. > > Any suggestions or advice on how to make the object TF1 work with a > function from a class would > be welcome. > The function looks like: > > double LaplaceTransformA::time_domain(double *time, double *par) { > int order; > double TimeConstant; > > order = LT_pole->get_mult(); > TimeConstant = LT_pole->get_pole(); > > if (order != 0 ){ > switch( order ) { > case 1: > return( exp(-*time/TimeConstant)/TimeConstant ); > break; > default: > return > (*time*exp(-*time/TimeConstant)/TimeConstant/(double)fact(order-1)); > break; > } > > } > } > > > When I try to use it in a function, I find: > > root [0] .L laplace.h > root [1] LaplaceTransformA *Lt1 = new LaplaceTransformA(3,0.15); > root [2] TF1 *f1 = new TF1("calibration",Lt1->time_domain,0,1,1); > Error: No symbol Lt1->time_domain in current scope > FILE:/tmp/file9oXnNv_cint LINE:1 > > Please advise. > > Regards, > > Jeff > > _____________________________________________________ > Jeffrey McDonald, University of Pittsburgh jemcdon+@pitt.edu > 100 Allen Hall office: 412-624-9160 > 3941 O'Hara St. lab: 412-624-9160 > Dept. of Physics and Astronomy fax: 412-624-9163 > University of Pittsburgh > Pittsburgh, PA 15260 > >
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:42 MET