ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
minuit2GausFit.C
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Author: L. Moneta 10/2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 ROOT Foundation, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 
11 #include "TH1.h"
12 #include "TF1.h"
13 #include "TCanvas.h"
14 #include "TRandom3.h"
15 #include "TVirtualFitter.h"
16 #include "TPaveLabel.h"
17 #include "TStyle.h"
18 
19 #include <iostream>
20 #include <string>
21 
22 
23 void testGausFit( std::string type = "Minuit2", int n = 1000) {
24 
25  gRandom = new TRandom3();
26 
28 
29  std::string name;
30  name = "h1_" + type;
31  TH1D * h1 = new TH1D(name.c_str(),"Chi2 Fit",100, -5, 5. );
32  name = "h2_" + type;
33  TH1D * h2 = new TH1D(name.c_str(),"Chi2 Fit with Minos Error",100, -5, 5. );
34  name = "h3_" + type;
35  TH1D * h3 = new TH1D(name.c_str(),"Chi2 Fit with Integral and Minos",100, -5, 5. );
36  name = "h4_" + type;
37  TH1D * h4 = new TH1D(name.c_str(),"Likelihood Fit with Minos Error",100, -5, 5. );
38 
39  gStyle->SetOptStat(1111111);
40  gStyle->SetOptFit(1111111);
41 
42  for (int i = 0; i < n; ++i) {
43  double x = gRandom->Gaus(0,1);
44  h1->Fill( x );
45  h2->Fill( x );
46  h3->Fill( x );
47  h4->Fill( x );
48  }
49 
50  std::string cname = type + "Canvas" ;
51  std::string ctitle = type + " Gaussian Fit" ;
52  TCanvas *c1 = new TCanvas(cname.c_str(),cname.c_str(),10,10,900,900);
53  c1->Divide(2,2);
54 
55  c1->cd(1);
56  cout << "\nDo Fit 1\n";
57  h1->Fit("gaus","Q");
58  h1->Draw();
59  c1->cd(2);
60  cout << "\nDo Fit 2\n";
61  h2->Fit("gaus","VE");
62  h2->Draw();
63  c1->cd(3);
64  cout << "\nDo Fit 3\n";
65  h3->Fit("gaus","IE");
66  h3->Draw();
67  c1->cd(4);
68  cout << "\nDo Fit 4\n";
69  h4->Fit("gaus","VLE");
70  h4->Draw();
71 
72 }
73 
75 
76  int n = 1000;
77  testGausFit("Minuit2",n);
78  testGausFit("Fumili2",n);
79 
80 }
81 
82 
83 
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
Random number generator class based on M.
Definition: TRandom3.h:29
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:235
TCanvas * c1
Definition: legend1.C:2
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
static void SetDefaultFitter(const char *name="")
static: set name of default fitter
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
Double_t x[n]
Definition: legend1.C:17
TH2D * h2
Definition: fit2dHist.C:45
TH1F * h1
Definition: legend1.C:5
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
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:1204
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
void minuit2GausFit()
void testGausFit(std::string type="Minuit2", int n=1000)
The Canvas class.
Definition: TCanvas.h:48
int type
Definition: TGX11.cxx:120
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
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:1252
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:3607
const Int_t n
Definition: legend1.C:16