ROOT
master
Reference Guide
Loading...
Searching...
No Matches
fit1.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_fit
3
/// \notebook
4
/// Simple fitting example (1-d histogram with an interpreted function)
5
///
6
/// \macro_image
7
/// \macro_output
8
/// \macro_code
9
///
10
/// \author Rene Brun
11
12
#include "
TCanvas.h
"
13
#include "
TFrame.h
"
14
#include "
TBenchmark.h
"
15
#include "
TString.h
"
16
#include "
TF1.h
"
17
#include "
TH1.h
"
18
#include "
TFile.h
"
19
#include "
TROOT.h
"
20
#include "
TError.h
"
21
#include "
TInterpreter.h
"
22
#include "
TSystem.h
"
23
#include "
TPaveText.h
"
24
25
void
fit1() {
26
TCanvas
*
c1
=
new
TCanvas
(
"c1_fit1"
,
"The Fit Canvas"
,200,10,700,500);
27
c1
->SetGridx();
28
c1
->SetGridy();
29
c1
->GetFrame()->SetFillColor(21);
30
c1
->GetFrame()->SetBorderMode(-1);
31
c1
->GetFrame()->SetBorderSize(5);
32
33
// (for more details, see
34
// <a href="hist001_TH1_fillrandom_userfunc.C.nbconvert.ipynb">filling histograms with random numbers from a function</a>)
35
TFormula
*
form1
=
new
TFormula
(
"form1"
,
"abs(sin(x)/x)"
);
36
TF1
*
sqroot
=
new
TF1
(
"sqroot"
,
"x*gaus(0) + [3]*form1"
, 0.0, 10.0);
37
sqroot
->SetLineColor(4);
38
sqroot
->SetLineWidth(6);
39
// Set parameters to the functions "gaus" and "form1".
40
sqroot
->SetParameters(10.0, 4.0, 1.0, 20.0);
41
sqroot
->Print();
42
43
TH1D
*
h1d
=
new
TH1D
(
"h1d"
,
"Test random numbers"
, 200, 0.0, 10.0);
44
h1d
->FillRandom(
"sqroot"
, 10000);
45
46
//
47
// Now fit histogram h1d with the function sqroot
48
//
49
h1d
->SetFillColor(45);
50
h1d
->Fit(
"sqroot"
);
51
52
// We now annotate the picture by creating a PaveText object
53
// and displaying the list of commands in this macro
54
//
55
TString
dir =
gROOT
->GetTutorialDir();
56
dir.
Append
(
"/math/fit/"
);
57
TPaveText(0.6,0.4,0.9,0.75,
"NDC"
);
58
fitlabel->SetTextAlign(12);
59
fitlabel->SetFillColor(42);
60
Data()));
61
fitlabel->Draw();
62
c1
->Update();
63
}
TBenchmark.h
TCanvas.h
TError.h
TF1.h
TFile.h
TFrame.h
TH1.h
TInterpreter.h
TPaveText.h
TROOT.h
gROOT
#define gROOT
Definition
TROOT.h:406
TString.h
Form
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition
TString.cxx:2489
TSystem.h
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TF1
1-Dim function class
Definition
TF1.h:233
TFormula
The Formula class.
Definition
TFormula.h:89
TH1D
1-D histogram with a double per channel (see TH1 documentation)
Definition
TH1.h:695
TPaveText
A Pave (see TPave) with text, lines or/and boxes inside.
Definition
TPaveText.h:21
TString
Basic string class.
Definition
TString.h:139
TString::Data
const char * Data() const
Definition
TString.h:376
TString::Append
TString & Append(const char *cs)
Definition
TString.h:572
c1
return c1
Definition
legend1.C:41
fit1_py.fitlabel
fitlabel
Definition
fit1_py.py:12
fit1
Definition
fit1.py:1
tutorials
math
fit
fit1.C
ROOT master - Reference Guide Generated on Mon Mar 10 2025 15:21:31 (GVA Time) using Doxygen 1.10.0