Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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 <TCanvas.h>
20#include <TGraph.h>
21#include <TH1F.h>
22#include <TVirtualFitter.h>
23
24void fitcont()
25{
26 //be sure default is Minuit since we will use gMinuit
28
29 TCanvas *c1 = new TCanvas("c1");
30 TH1F *h = new TH1F("h","My histogram",100,-3,3);
31 h->FillRandom("gaus",6000);
32 h->Fit("gaus");
33 c1->Update();
34
35 TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800);
36 c2->Divide(1,2);
37 c2->cd(1);
38 /*get first contour for parameter 1 versus parameter 2*/
39 TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2);
40 gr12->Draw("alp");
41 c2->cd(2);
42 /*Get contour for parameter 0 versus parameter 2 for ERRDEF=2*/
43 gMinuit->SetErrorDef(4); //note 4 and not 2!
44 TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2);
45 gr2->SetFillColor(42);
46 gr2->Draw("alf");
47 /*Get contour for parameter 0 versus parameter 2 for ERRDEF=1*/
48 gMinuit->SetErrorDef(1);
49 TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2);
50 gr1->SetFillColor(38);
51 gr1->Draw("lf");
52}
#define h(i)
Definition RSha256.hxx:106
externTMinuit * gMinuit
Definition TMinuit.h:271
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
The Canvas class.
Definition TCanvas.h:23
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
static void SetDefaultFitter(const char *name="")
static: set name of default fitter
return c1
Definition legend1.C:41
return c2
Definition legend2.C:14