Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
minuit2GausFit.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Perform fits with different configurations using Minuit2

Do Fit 1
Do Fit 2
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 65.1586
NDf = 56
Edm = 1.93774e-09
NCalls = 69
Constant = 36.3132 +/- 1.52625 -1.51651 +1.53547 (Minos)
Mean = 0.013082 +/- 0.0347499 -0.0347674 +0.0347613 (Minos)
Sigma = 1.03413 +/- 0.0288039 -0.0286274 +0.0290102 (Minos) (limited)
Do Fit 3
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 65.1586
NDf = 56
Edm = 5.63977e-09
NCalls = 50
Constant = 36.3274 +/- 1.52734 -1.51763 +1.53654 (Minos)
Mean = 0.0130805 +/- 0.0347499 -0.0347659 +0.0347628 (Minos)
Sigma = 1.03373 +/- 0.0288151 -0.0286384 +0.0290217 (Minos) (limited)
Do Fit 4
****************************************
Minimizer is Minuit2 / Migrad
MinFCN = 43.3935
Chi2 = 86.7869
NDf = 97
Edm = 9.98059e-08
NCalls = 60
Constant = 38.427 +/- 1.48837 -1.46667 +1.51031 (Minos)
Mean = 0.027601 +/- 0.032831 -0.0328395 +0.0328395 (Minos)
Sigma = 1.03819 +/- 0.0232194 -0.0227841 +0.0236699 (Minos) (limited)
Do Fit 1
Do Fit 2
****************************************
Minimizer is Minuit2 / Fumili
Chi2 = 65.1586
NDf = 56
Edm = 4.17059e-08
NCalls = 32
Constant = 36.313 +/- 1.52625 -1.51631 +1.53567 (Minos)
Mean = 0.0130818 +/- 0.0347499 -0.0347672 +0.0347615 (Minos)
Sigma = 1.03413 +/- 0.0288039 -0.0286324 +0.0290052 (Minos) (limited)
Do Fit 3
****************************************
Minimizer is Minuit2 / Fumili
Chi2 = 65.1586
NDf = 56
Edm = 9.83435e-08
NCalls = 32
Constant = 36.327 +/- 1.52734 -1.51727 +1.5369 (Minos)
Mean = 0.0130818 +/- 0.0347498 -0.0347672 +0.0347615 (Minos)
Sigma = 1.03373 +/- 0.0288152 -0.028647 +0.0290131 (Minos) (limited)
Do Fit 4
****************************************
Minimizer is Minuit2 / Fumili
MinFCN = 43.3935
Chi2 = 86.7869
NDf = 97
Edm = 1.39892e-09
NCalls = 32
Constant = 38.4264 +/- 1.48835 -1.46601 +1.51097 (Minos)
Mean = 0.027601 +/- 0.0328313 -0.0328395 +0.0328395 (Minos)
Sigma = 1.0382 +/- 0.0232198 -0.0227933 +0.0236607 (Minos) (limited)
#include "TH1.h"
#include "TF1.h"
#include "TCanvas.h"
#include "TRandom3.h"
#include "TVirtualFitter.h"
#include "TPaveLabel.h"
#include "TStyle.h"
#include <iostream>
#include <string>
void testGausFit( std::string type = "Minuit2", int n = 1000) {
gRandom = new TRandom3();
std::string name;
name = "h1_" + type;
TH1D * h1 = new TH1D(name.c_str(),"Chi2 Fit",100, -5, 5. );
name = "h2_" + type;
TH1D * h2 = new TH1D(name.c_str(),"Chi2 Fit with Minos Error",100, -5, 5. );
name = "h3_" + type;
TH1D * h3 = new TH1D(name.c_str(),"Chi2 Fit with Integral and Minos",100, -5, 5. );
name = "h4_" + type;
TH1D * h4 = new TH1D(name.c_str(),"Likelihood Fit with Minos Error",100, -5, 5. );
gStyle->SetOptStat(1111111);
gStyle->SetOptFit(1111111);
for (int i = 0; i < n; ++i) {
double x = gRandom->Gaus(0,1);
h1->Fill( x );
h2->Fill( x );
h3->Fill( x );
h4->Fill( x );
}
std::string cname = type + "Canvas" ;
std::string ctitle = type + " Gaussian Fit" ;
TCanvas *c1 = new TCanvas(cname.c_str(),cname.c_str(),10,10,900,900);
c1->Divide(2,2);
c1->cd(1);
std::cout << "\nDo Fit 1\n";
h1->Fit("gaus","Q");
h1->Draw();
c1->cd(2);
std::cout << "\nDo Fit 2\n";
h2->Fit("gaus","E");
h2->Draw();
c1->cd(3);
std::cout << "\nDo Fit 3\n";
h3->Fit("gaus","IGE");
h3->Draw();
c1->cd(4);
std::cout << "\nDo Fit 4\n";
h4->Fit("gaus","LE");
h4->Draw();
}
void minuit2GausFit() {
int n = 1000;
testGausFit("Minuit2",n);
testGausFit("Fumili2",n);
}
char name[80]
Definition TGX11.cxx:148
externTRandom * gRandom
Definition TRandom.h:62
externTStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:926
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
Definition TH1.cxx:3954
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3393
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3097
Random number generator class based on M.
Definition TRandom3.h:27
static void SetDefaultFitter(const char *name="")
static: set name of default fitter
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5
Author
Lorenzo Moneta

Definition in file minuit2GausFit.C.