# Linear fit

Hi rooters!!
I have a problem, maybe a stupid problem, with a linear fit, in fact if I fit my graph with a predefinite linear fit “pol1” I obtain this result:

instead if I use a user function: f1 = TF1 (“f1”, " [0]+[1]*x" ) I obtain this other result:

Why this?

thanks for the help!!

Before trying to do fit using your own functions, did you set “initial values” for function parameters?
You should have something like this: ```TF1 *f1 = new TF1("f1", "[0]+[1]*x", 2900, 6100); // "xmin" and "xmax" are required f1->SetParameters(0, 0.001);```

Yes is due for this reason!!! thanks a lot!!!
Now I have another problem…
From the fit I take the 1st parameters, and until here is ok:

p0= f2->GetParameter(0)
p1= f2->GetParameter(1)

but then I have to use this parameter to draw a line, so I tried to do:

TF1 f3= new TF1 (“f3”, "p0+(2p1*x)", 0,12000)

but don’t work.
thanks for the help!!

```TF1 *f3 = new TF1("f3", "[0]+2.0*[1]*x", 0, 12000); f3->SetTitle("p0+(2*p1*x);HV_{eff}^{} [kV];Density Current [#muA/cm^{2}_{}]"); f3->SetParameters(p0, p1);``` or: ```TF1 *f3 = new TF1("f3", "pol1", 0, 12000); f3->SetParameters(p0, 2.0*p1);```

Perfect!! now work very well!!!
The last question is about the statistic box:

1. I have to set the statistic box of 2 graph, so I want put the 2 box in different position, so I tried to do this for 1st plot :

gStyle.SetOptFit(1111)
gStyle.SetStatX(0.35)
gStyle.SetStatY(0.7)
gStyle.SetStatH(0.25)
gStyle.SetStatW(0.1)

Then the same command with different values for the 2nd plot, but I obtain the 2 box in the same place. How can I do?

1. I know how the H and W of statistic box, but I didn’t found how set the label of the box. How can I do to set it?

Thanks a lot =) =)

Very good, but now I obtain a double statistic box, 1 created with Tpave, and 1 by gStyle…
so I put 0 the option of gStyle :

gStyle.SetOptFit()
gStyle.SetStatX(0)
gStyle.SetStatY(0)
gStyle.SetStatH(0)
gStyle.SetStatW(0)

And in this way don’t appear.
I know that for the histo there is a command to hide the statistic box, like:
hist->SetStat(0)

for graph there is not a command like this?

You should have: gStyle->SetOptFit(0);
If this doesn’t help, try to delete it (after it is drawn).
In worst case you can always move it to “out of the frame”.