Fitting a TGraph2D
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 4.25425e+06
NDf = 398
Edm = 5.98608e-13
NCalls = 45
p0 = 0.574556 +/- 0.109977
p1 = 1.72367 +/- 0.329932
void graph2dfit()
{
auto c =
new TCanvas(
"c",
"Graph2D example",0,0,600,800);
int nd = 400;
int np = 10000;
double fl = 6;
auto f2 =
new TF2(
"f2",
"1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200",
-fl,fl,-fl,fl);
f2->SetParameters(1,1);
double zmax = 0;
for (
int N=0;
N<nd;
N++) {
z = f2->Eval(
x,
y)*(1+rnd);
if (z>zmax) zmax = z;
}
double hr = 350;
"#splitline{Difference between Original}{#splitline{function and Function}{with noise}}",
100, -hr, hr);
"#splitline{Difference between Original}{#splitline{function and Delaunay triangles}{interpolation}}",
100, -hr, hr);
"#splitline{Difference between Original}{function and Minuit fit}",
500, -hr, hr);
f2->SetParameters(0.5,1.5);
dt->Fit(f2);
auto fit2 = (
TF2*)dt->FindObject(
"f2");
f2->SetParameters(1,1);
for (
int N=0;
N<np;
N++) {
z = f2->Eval(
x,
y)*(1+rnd);
h1->Fill(f2->Eval(
x,
y)-z);
z = dt->Interpolate(
x,
y);
h2->Fill(f2->Eval(
x,
y)-z);
h3->Fill(f2->Eval(
x,
y)-z);
}
f2->SetTitle("Original function with Graph2D points on top");
f2->SetMaximum(zmax);
f2->Draw("surf1");
dt->Draw("same p0");
dt->SetMargin(0.1);
dt->SetFillColor(36);
dt->SetTitle("Histogram produced with Delaunay interpolation");
dt->Draw("surf4");
fit2->SetTitle("Minuit fit result on the Graph2D points");
fit2->Draw("surf1");
h2->SetFillColor(38);
h3->SetFillColor(29);
c->cd(2);
h1->Fit(
"gaus",
"Q") ;
h1->Draw();
c->cd(4); h2->Fit(
"gaus",
"Q") ; h2->Draw();
c->cd(6); h3->Fit(
"gaus",
"Q") ; h3->Draw();
}
1-D histogram with a double per channel (see TH1 documentation)
This is the base class for the ROOT Random number generators.
- Author
- Olivier Couet
Definition in file graph2dfit.C.