Re:

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue May 05 1998 - 14:57:49 MEST


Recently, I posted an answer to this problem.
Here is a copy of my mail to roottalk on 30 April.

Rene Brun




Because this mail is of general interest, I post my answer to roottalk.
The latest versions of CINT, apparently, are confused in case
of a TF1 constructor with an interpreted function.
If TF1 is called only once with a reference to an interpreted function
(in the example below, the function func), the second call to TF1
invokes the wrong constructor.
I have already forwarded this problem to Masa.
There is a very simple solution to circumvent this problem.
You must force the fonction to a "void *". This helps CINT.
So, in your macro below, change the statements:

  TF1* myfunc1 = new TF1("myfunc1", func, -90., 90., 2);
  TF1* myfunc2 = new TF1("myfunc2", func, -90., 90., 2);
to
  TF1* myfunc1 = new TF1("myfunc1", (void*)func, -90., 90., 2);
  TF1* myfunc2 = new TF1("myfunc2", (void*)func, -90., 90., 2);

and your macro will work nicely.

Rene Brun



Daniel Barna wrote:
> 
> Hi,
> I would like to plot a function with two different parameters on the same
> canvas. I tried the following:
> 
> I wrote the C function in a separate file (func.C)
> for simplicity it is now:
> 
> Double_t func(Double_t *arg,Double_t *par)
> {
>   return arg[0]*par[0];
> }
> 
> And now:
> 
> gROOT->LoadMacro("func.C");
> 
> TF1 f1("f1",func,-1,1,1);
> f1.SetParameter(0,1);
> f1.Draw();  // ok, it works
> 
> TF1 f2("f2",func,-1,1,1);
> f2.SetParameter(0,2);
> f2.Draw("same");
> 
>  *** Break *** segmentation violation
> 
> What did I do wrong?
> 
> --------------------------------
> something else:
> 
> If I want to write multiple statements between { }s, only the first line
> seems to be executed:
> 
> int a=0;
> int b=0;
> for(int i=0; i<10; i++) {a++;
> b++; }
> 
> now a=10, but b=1 !
> but if I try
> 
> int a=0;
> int b=0;
> for(int i=0; i<10; i++) {a++; b++; }
> 
> now a=10,b=10.
> 
> Thanks
> Daniel



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