Hi Hongquan,
You have to specify the parameters to the object, otherwise
if you draw the same function several times, you will only see
the last parameters.
The TF1::Paint function is called when the pad/canvas needs to be
updated. Paint will call your function to get the values.
Root does not behave like a pen plotter !
It is very bad practice to have global variables in your program
to specify the function parameters. This introduces fundamental
limitations to object-oriented programming.
Two examples:
- the one you hit. In case of several pads representing the
same function algorithm with different parameters.
- if you want to save your function and read it into another
program, the original values are lost or not available.
Storing the current parameters together with the function object
has only advantages. See example below.
Rene Brun
Double_t myfunc(Double_t *x, Double_t *par)
{
return par[0] + par[1]*x[0];
}
void func2()
{
TCanvas *c1 = new TCanvas("c1","c1",600,800);
c1->Divide(1,2);
c1->cd(1);
TF1 *func = new TF1("func",myfunc,0,10,2);
func->SetParameters(1,1);
func->DrawCopy();
c1->cd(2);
func->SetParameters(1,0.5);
func->Draw();
}