Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
minuit2GausFit.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_fit
3/// \notebook -js
4/// Perform fits with different configurations using Minuit2
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \author Lorenzo Moneta
11
12#include "TH1.h"
13#include "TF1.h"
14#include "TCanvas.h"
15#include "TRandom3.h"
16#include "TVirtualFitter.h"
17#include "TPaveLabel.h"
18#include "TStyle.h"
19
20#include <iostream>
21#include <string>
22
23
24void testGausFit( std::string type = "Minuit2", int n = 1000) {
25
26 gRandom = new TRandom3();
27
29
30 std::string name;
31 name = "h1_" + type;
32 TH1D * h1 = new TH1D(name.c_str(),"Chi2 Fit",100, -5, 5. );
33 name = "h2_" + type;
34 TH1D * h2 = new TH1D(name.c_str(),"Chi2 Fit with Minos Error",100, -5, 5. );
35 name = "h3_" + type;
36 TH1D * h3 = new TH1D(name.c_str(),"Chi2 Fit with Integral and Minos",100, -5, 5. );
37 name = "h4_" + type;
38 TH1D * h4 = new TH1D(name.c_str(),"Likelihood Fit with Minos Error",100, -5, 5. );
39
40 gStyle->SetOptStat(1111111);
41 gStyle->SetOptFit(1111111);
42
43 for (int i = 0; i < n; ++i) {
44 double x = gRandom->Gaus(0,1);
45 h1->Fill( x );
46 h2->Fill( x );
47 h3->Fill( x );
48 h4->Fill( x );
49 }
50
51 std::string cname = type + "Canvas" ;
52 std::string ctitle = type + " Gaussian Fit" ;
53 TCanvas *c1 = new TCanvas(cname.c_str(),cname.c_str(),10,10,900,900);
54 c1->Divide(2,2);
55
56 c1->cd(1);
57 cout << "\nDo Fit 1\n";
58 h1->Fit("gaus","Q");
59 h1->Draw();
60 c1->cd(2);
61 cout << "\nDo Fit 2\n";
62 h2->Fit("gaus","VE");
63 h2->Draw();
64 c1->cd(3);
65 cout << "\nDo Fit 3\n";
66 h3->Fit("gaus","IE");
67 h3->Draw();
68 c1->cd(4);
69 cout << "\nDo Fit 4\n";
70 h4->Fit("gaus","VLE");
71 h4->Draw();
72
73}
74
75void minuit2GausFit() {
76
77 int n = 1000;
78 testGausFit("Minuit2",n);
79 testGausFit("Fumili2",n);
80
81}
82
83
84
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
R__EXTERN TStyle * gStyle
Definition TStyle.h:413
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a double per channel (see TH1 documentation)}
Definition TH1.h:618
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:3893
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3351
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3074
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:274
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:1589
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:1541
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