Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TGraphFit.C
Go to the documentation of this file.
1void TGraphFit(){
2 //
3 // Draw a graph with error bars and fit a function to it
4 //
5 gStyle->SetOptFit(111) ; //superimpose fit results
6 // make nice Canvas
7 TCanvas *c1 = new TCanvas("c1" ,"Daten" ,200 ,10 ,700 ,500) ;
8 c1->SetGrid( ) ;
9 //define some data points ...
10 const Int_t n = 10;
11 Float_t x[n] = {-0.22, 0.1, 0.25, 0.35, 0.5, 0.61, 0.7, 0.85, 0.89, 1.1};
12 Float_t y[n] = {0.7, 2.9, 5.6, 7.4, 9., 9.6, 8.7, 6.3, 4.5, 1.1};
13 Float_t ey[n] = {.8 ,.7 ,.6 ,.5 ,.4 ,.4 ,.5 ,.6 ,.7 ,.8};
14 Float_t ex[n] = {.05 ,.1 ,.07 ,.07 ,.04 ,.05 ,.06 ,.07 ,.08 ,.05};
15 // and hand over to TGraphErros object
17 gr->SetTitle("TGraphErrors with Fit") ;
18 gr->Draw("AP");
19 // now perform a fit (with errors in x and y!)
20 gr->Fit("gaus");
21 c1->Update();
22}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
void TGraphFit()
Definition TGraphFit.C:1
externTStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
A TGraphErrors is a TGraph with error bars.
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t ey[n]
Definition legend1.C:17
TGraphErrors * gr
Definition legend1.C:25
Double_t ex[n]
Definition legend1.C:17