Re: plotting member functions

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jan 20 1998 - 19:12:51 MET


Wouter Hulsbergen wrote:

> Dear Root,
> Is it possible to plot member functions? The following does not work:
>
>   class RtRelation
>   {
>   public:
>     double rmin,rmax;
>     double* Rt(double * x, double* par);
>   }
>
>   RtRelation* rtrelation = new RtRelation;
>   TF1* rt = new TF1("rt",rtrelation->Rt,
>                     rtrelation->rmin,rtrelation->rmax,0);
>
> If it is possible, how should I do it ?
> Regards, thanks, Wouter

  No, an input parameter for TF1 cannot be a class member function.
See list of possibilities in  http://root.cern.ch/root/html/TF1.html
You can only define a normal function like in the example below.
Inside this function, you can use a global pointer to access
one of your objects and invoke its member function.

Rene Brun

Double_t Rt(Double_t *x, Double_t *par)
{
   Double_t arg = 0;
   if (par[2]) arg = (x[0] - par[1])/par[2];

   Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg);
   return fitval;
}
void myfunc()
{
// Creates a Root function based on function Rt above
   TF1 *func = new TF1("Rt",Rt,-2,2,3);

// Sets initial values and parameter names
   func->SetParameters(100,0,1);
   func->SetParNames("Constant","Mean_value","Sigma");
   func->Draw();
}



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:29 MET