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+(2 p1*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:
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?
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 =) =)
[code]# include “TCanvas.h”
include “TROOT.h”
include “TStyle.h”
include “TMultiGraph.h”
include “TGraphErrors.h”
include “TF1.h”
include “TLegend.h”
include “TPaveStats.h”
include “TArrow.h”
include “TLatex.h”
void gain(){
TCanvas *mycanvas = new TCanvas(“c”,“c”,600, 400);
TMultiGraph * mg = new TMultiGraph(“gain curve”,“GAIN CURVE”);
// The values on the X,Y axes and error on Y axis
const int n_Fe=20;
double x_Fe[n_Fe]={560,565,570,575,580,585,590,595,600,605,610,615,620,625,630,635,640,…
// http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptStat
gStyle->SetOptStat(1111);
// ...
// http://root.cern.ch/root/html/TH1.html#TH1:SetStats
// SomeHisto->SetStats(kTRUE);
// ...
// http://root.cern.ch/root/html/THistPainter.html
SomeHisto->Draw("SAMES"); // you MUST draw "SomeHisto" first (e.g. with "SAMES")
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
// http://root.cern.ch/root/html/TPaveStats.html
#if 1 /* 0 or 1 */
TPaveStats *s = ((TPaveStats*)(SomeHisto->F…
Note “h->SetStats(kFALSE); // mandatory (not sure why)”: [code]{
gStyle->SetOptStat(); // mandatory
TCanvas *c = new TCanvas(“c”, “c”, 600, 400);
TH2F h = new TH2F(“h”, "TH2F example ", 30, -4, 4, 30, -20, 20);
Float_t px, py;
for (Int_t i = 0; i < 25000; i++) {
gRandom->Rannor(px, py);
h->Fill(px-1, 5py);
h->Fill(2+0.5px, 2py-10., 0.1);
}
h->SetStats(kTRUE);
h->Draw(“COLZ”);
gPad->Modified(); gPad->Update(); // mandatory
TPaveStats ps = (TPaveStats)gPad->GetPrimitive(“stats”);
if …
[code] gStyle->SetOptFit(1);
h_ccd_CTE_L->SetOption(“p”);
TF1 *pol1_LCCD = new TF1(“pol1”,“pol1”,lower_x_hist_cte,upper_x_hist_cte);
h_ccd_CTE_L->Fit(pol1_LCCD,“R”);
gPad->Modified(); gPad->Update(); // make sure it’s (re)drawn
// https://root.cern.ch/root/html/TPaveStats.html
TPaveStats st = (TPaveStats)h_ccd_CTE_L->FindObject(“stats”);
st->SetX1NDC(0.7);
st->SetX2NDC(0.99);
st->SetY1NDC(0.2);
st->SetY2NDC(0.5);
st->SetName(“mystats”);
h_ccd_CTE_L->SetStats(0);
TList *list = st->G…
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”.