ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fitcont.C
Go to the documentation of this file.
1 #include "TMinuit.h"
2 
3 void fitcont()
4 {
5  // Example illustrating how to draw the n-sigma contour of a Minuit fit.
6  // To get the n-sigma contour the ERRDEF parameter in Minuit has to set
7  // to n^2. The fcn function has to be set before the routine is called.
8  //
9  // WARNING!!! This test works only with TMinuit
10  //
11  // The TGraph object is created via the interpreter. The user must cast it
12  // to a TGraph*
13  // Author: Rene Brun
14 
15  //be sure default is Minuit since we will use gMinuit
17 
18  TCanvas *c1 = new TCanvas("c1");
19  TH1F *h = new TH1F("h","My histogram",100,-3,3);
20  h->FillRandom("gaus",6000);
21  h->Fit("gaus");
22  c1->Update();
23 
24  TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800);
25  c2->Divide(1,2);
26  c2->cd(1);
27  //get first contour for parameter 1 versus parameter 2
28  TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2);
29  gr12->Draw("alp");
30  c2->cd(2);
31  //Get contour for parameter 0 versus parameter 2 for ERRDEF=2
32  gMinuit->SetErrorDef(4); //note 4 and not 2!
33  TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2);
34  gr2->SetFillColor(42);
35  gr2->Draw("alf");
36  //Get contour for parameter 0 versus parameter 2 for ERRDEF=1
37  gMinuit->SetErrorDef(1);
38  TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2);
39  gr1->SetFillColor(38);
40  gr1->Draw("lf");
41 }
TCanvas * c1
Definition: legend1.C:2
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:659
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
R__EXTERN TMinuit * gMinuit
Definition: TMinuit.h:279
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:646
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
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:902
void fitcont()
Definition: fitcont.C:3
The Canvas class.
Definition: TCanvas.h:48
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:1073
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
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