Re: A ROOT Problem:How to use TF1 to do function integration

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Aug 27 1999 - 08:08:10 MEST


Hi Feng,
The solution is simple.
call your member function from the normal function expected by TF1.
If you only have one object PRCHe3, the member function
PRCHe3::IntegrandERT can be declared static.
If you have more than one object, use a global pointer pointing to the
right object.
There are several raisons why TF1 cannot call directly a member
function.

Rene Brun

Feng Xiong wrote:
> 
> Hi Rooters,
> 
> I am a beginner in C++ and I had a problem when I was trying to use ROOT's
> class TF1 to do integration. I believe it's very simple by nature.
> 
> Basically in my class PRCHe3 there is a member function IntegrandERT() to
> calculate cross section(elastic radiative tail) as a function of some
> parameter t (it's very complicated in form and has to call several Fortran
> subroutines, it also depends on some private members of the class, thus I
> can not make it an ordinary function), and I want to integrate over a
> certain range of t to get my result. A simple idea is to define a TF1
> object for this member function and thus utilize the Integral() member
> function of TF1. However the TF1 constructor only takes a pointer to the
> function, and I can not define a pointer to the member function(though
> it'a all right for ordinary functions, as in the example of stress1 in
> test/stress.cxx), like:
> 
>        Double_t PRCHe3::IntegrandERT(Double_t *x, Double_t *p)
>        {
>           ...
>        }
> 
>        Double_t (*func) (Double_t *, Double_t *);
>        func = IntegrandERT;
>        TF1 *f1 =  new TF1("elastic", func, -10, 10, 5);
> 
> or segmentation violation occurs -- though it compiles and links, with
> a warning like:
> 
> PRCHe3.cxx:178: warning: assuming & on `PRCHe3::IntegrandERT(Double_t *, Double_t *)'
> PRCHe3.cxx:178: warning: converting from `Double_t (PRCHe3::*)(Double_t *,
> Double_t *)' to `Double_t (*)(Double_t *, Double_t *)'
> 
> Then I tried to define the member function something like
> 
>    Double_t PRCHe3::(*IntegrandERT)(Double_t *x, Double_t *p) { ... }
> 
> but it did not work.
> 
> Can anybody show me how to solve this problem? Many thanks!
> 
> Best regards,
> Feng



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