Logo ROOT   6.08/07
Reference Guide
minuit2FitBench2D.C File Reference

Detailed Description

View in nbviewer Open in SWAN

pict1_minuit2FitBench2D.C.png
Processing /mnt/build/workspace/root-makedoc-v608/rootspi/rdoc/src/v6-08-00-patches/tutorials/fit/minuit2FitBench2D.C...
FCN=7196.63 FROM MIGRAD STATUS=CONVERGED 169 CALLS 170 TOTAL
EDM=3.06507e-09 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 2.0 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 5.28670e+01 2.67227e-01 1.71567e-03 1.41591e-04
2 p1 2.00562e+00 9.99521e-03 -6.72962e-05 -5.71944e-03
3 p2 -1.02279e+00 1.35440e-02 3.22465e-05 2.77025e-03
4 p3 2.89928e+00 7.94099e-03 -9.38703e-05 -4.55754e-03
5 p4 3.86656e+00 1.13330e-02 1.06568e-05 -2.11128e-03
Minuit, npass=0 : RT= 0.105 s, Cpu= 0.100 s
****************************************
Minimizer is Fumili
Chi2 = 7196.63
NDf = 7366
NCalls = 30
p0 = 52.8672 +/- 0.262932
p1 = 2.00562 +/- 0.00992527
p2 = -1.02279 +/- 0.0135821
p3 = 2.89927 +/- 0.00781808
p4 = 3.86655 +/- 0.011235
Fumili, npass=0 : RT= 0.155 s, Cpu= 0.160 s
FCN=7196.63 FROM MIGRAD STATUS=CONVERGED 175 CALLS 176 TOTAL
EDM=4.80301e-08 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 1.9 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 5.28670e+01 2.64728e-01 1.56358e-03 1.49258e-03
2 p1 2.00562e+00 9.95152e-03 -3.17014e-05 -2.36572e-04
3 p2 -1.02280e+00 1.37398e-02 -1.04616e-05 -2.27679e-02
4 p3 2.89928e+00 7.98634e-03 -2.96448e-05 2.44334e-02
5 p4 3.86656e+00 1.12306e-02 4.64806e-06 1.47587e-02
Minuit2, npass=0 : RT= 0.077 s, Cpu= 0.080 s
FCN=7196.63 FROM MIGRAD STATUS=CONVERGED 175 CALLS 176 TOTAL
EDM=4.80299e-08 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 1.9 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 5.28670e+01 2.64728e-01 1.56358e-03 1.49258e-03
2 p1 2.00562e+00 9.95152e-03 -3.17013e-05 -2.36580e-04
3 p2 -1.02280e+00 1.37398e-02 -1.04616e-05 -2.27677e-02
4 p3 2.89928e+00 7.98634e-03 -2.96447e-05 2.44336e-02
5 p4 3.86656e+00 1.12306e-02 4.64805e-06 1.47586e-02
Fumili2, npass=0 : RT= 0.076 s, Cpu= 0.080 s
#include "TH1.h"
#include "TF1.h"
#include "TH2D.h"
#include "TF2.h"
#include "TCanvas.h"
#include "TStopwatch.h"
#include "TSystem.h"
#include "TRandom3.h"
#include "TVirtualFitter.h"
#include "TPaveLabel.h"
#include "TStyle.h"
TF2 *fitFcn;
TH2D *histo;
// Quadratic background function
double t1 = x[0] - par[1];
double t2 = x[1] - par[2];
return par[0]* exp( - 0.5 * ( t1*t1/( par[3]*par[3]) + t2*t2 /( par[4]*par[4] ) ) ) ;
}
// Sum of background and peak function
return gaus2D(x,par);
}
void fillHisto(int n =10000) {
gRandom = new TRandom3();
for (int i = 0; i < n; ++i) {
double x = gRandom->Gaus(2,3);
double y = gRandom->Gaus(-1,4);
histo->Fill(x,y,1.);
}
}
void DoFit(const char* fitter, TVirtualPad *pad, Int_t npass) {
pad->SetGrid();
fitFcn->SetParameters(100,0,0,2,7);
fitFcn->Update();
timer.Start();
histo->Fit("fitFcn","0");
timer.Stop();
histo->Draw();
Double_t cputime = timer.CpuTime();
printf("%s, npass=%d : RT=%7.3f s, Cpu=%7.3f s\n",fitter,npass,timer.RealTime(),cputime);
TPaveLabel *p = new TPaveLabel(0.5,0.7,0.85,0.8,Form("%s CPU= %g s",fitter,cputime),"brNDC");
p->Draw();
pad->Update();
}
void minuit2FitBench2D(int n = 100000) {
TCanvas *c1 = new TCanvas("c1","Fitting Demo",10,10,900,900);
c1->Divide(2,2);
// create a TF1 with the range from 0 to 3 and 6 parameters
fitFcn = new TF2("fitFcn",fitFunction,-10,10,-10,10,5);
//fitFcn->SetNpx(200);
histo = new TH2D("h2","2D Gauss",100,-10,10,100,-10,10);
fillHisto(n);
int npass=0;
//with Minuit
c1->cd(1);
DoFit("Minuit",gPad,npass);
//with Fumili
c1->cd(2);
DoFit("Fumili",gPad,npass);
//with Minuit2
c1->cd(3);
DoFit("Minuit2",gPad,npass);
//with Fumili2
c1->cd(4);
DoFit("Fumili2",gPad,npass);
}
Author
Lorenzo Moneta

Definition in file minuit2FitBench2D.C.