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 std::cout << "\nDo Fit 1\n";
58 h1->Fit("gaus","Q");
59 h1->Draw();
60 c1->cd(2);
61 std::cout << "\nDo Fit 2\n";
62 h2->Fit("gaus","E");
63 h2->Draw();
64 c1->cd(3);
65 std::cout << "\nDo Fit 3\n";
66 h3->Fit("gaus","IGE");
67 h3->Draw();
68 c1->cd(4);
69 std::cout << "\nDo Fit 4\n";
70 h4->Fit("gaus","LE");
71 h4->Draw();
72
73}
74
75void minuit2GausFit() {
76
77 int n = 1000;
78 testGausFit("Minuit2",n);
79 testGausFit("Fumili2",n);
80
81}
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:436
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:670
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:1640
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:1593
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