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 = 6.86315e-08
NCalls = 57
Constant = 36.327 +/- 2 -1.51685 +1.53726 (Minos)
Mean = 0.0130817 +/- 2
Sigma = 1.03373 +/- 6.72116 (limited)
Do Fit 4
****************************************
Minimizer is Minuit2 / Migrad
MinFCN = 43.3935
Chi2 = 86.7869
NDf = 97
Edm = 9.97216e-08
NCalls = 62
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 = 8.05693e-09
NCalls = 45
Constant = 36.3131 +/- 1.52625 -1.51642 +1.53556 (Minos)
Mean = 0.0130818 +/- 0.0347499 -0.0347671 +0.0347615 (Minos)
Sigma = 1.03413 +/- 0.0288039 -0.0286291 +0.0290085 (Minos) (limited)
Do Fit 3
****************************************
Minimizer is Minuit2 / Fumili
Chi2 = 65.1586
NDf = 56
Edm = 1.52369e-08
NCalls = 45
Constant = 36.3272 +/- 1.52734 -1.51745 +1.53671 (Minos)
Mean = 0.0130818 +/- 0.0347499 -0.0347671 +0.0347615 (Minos)
Sigma = 1.03373 +/- 0.0288151 -0.0286415 +0.0290186 (Minos) (limited)
Do Fit 4
****************************************
Minimizer is Minuit2 / Fumili
MinFCN = 43.3935
Chi2 = 86.7869
NDf = 97
Edm = 3.18744e-08
NCalls = 45
Constant = 38.4264 +/- 1.48835 -1.46601 +1.51097 (Minos)
Mean = 0.0275931 +/- 0.0328313 -0.0328316 +0.0328474 (Minos)
Sigma = 1.0382 +/- 0.0232197 -0.0227928 +0.0236612 (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);
}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:669
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:3898
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3344
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
Random number generator class based on M.
Definition TRandom3.h:27
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:275
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition TStyle.cxx:1636
void SetOptFit(Int_t fit=1)
The type of information about fit parameters printed in the histogram statistics box can be selected ...
Definition TStyle.cxx:1589
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.