Logo ROOT   6.10/09
Reference Guide
fitcont.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_fit
3 /// \notebook
4 /// Example illustrating how to draw the n-sigma contour of a Minuit fit.
5 /// To get the n-sigma contour the ERRDEF parameter in Minuit has to set
6 /// to n^2. The fcn function has to be set before the routine is called.
7 ///
8 /// WARNING!!! This test works only with TMinuit
9 ///
10 /// The TGraph object is created via the interpreter. The user must cast it
11 /// to a TGraph*
12 ///
13 /// \macro_image
14 /// \macro_output
15 /// \macro_code
16 ///
17 /// \author Rene Brun
18 
19 #include "TMinuit.h"
20 
21 void fitcont()
22 {
23  //be sure default is Minuit since we will use gMinuit
25 
26  TCanvas *c1 = new TCanvas("c1");
27  TH1F *h = new TH1F("h","My histogram",100,-3,3);
28  h->FillRandom("gaus",6000);
29  h->Fit("gaus");
30  c1->Update();
31 
32  TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800);
33  c2->Divide(1,2);
34  c2->cd(1);
35  /*get first contour for parameter 1 versus parameter 2*/
36  TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2);
37  gr12->Draw("alp");
38  c2->cd(2);
39  /*Get contour for parameter 0 versus parameter 2 for ERRDEF=2*/
40  gMinuit->SetErrorDef(4); //note 4 and not 2!
41  TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2);
42  gr2->SetFillColor(42);
43  gr2->Draw("alf");
44  /*Get contour for parameter 0 versus parameter 2 for ERRDEF=1*/
45  gMinuit->SetErrorDef(1);
46  TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2);
47  gr1->SetFillColor(38);
48  gr1->Draw("lf");
49 }
return c1
Definition: legend1.C:41
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:311
TH1 * h
Definition: legend2.C:5
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:679
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:745
R__EXTERN TMinuit * gMinuit
Definition: TMinuit.h:271
virtual TObject * Contour(Int_t npoints=10, Int_t pa1=0, Int_t pa2=1)
Creates a TGraph object describing the n-sigma contour of a TMinuit fit.
Definition: TMinuit.cxx:662
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3294
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual Int_t SetErrorDef(Double_t up)
To get the n-sigma contour the error def parameter "up" has to set to n^2.
Definition: TMinuit.cxx:917
The Canvas class.
Definition: TCanvas.h:31
return c2
Definition: legend2.C:14
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:1135
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2208
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:3564