ROOT
v6-36
Reference Guide
Loading...
Searching...
No Matches
gr011_graph2d_errorsfit.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_graphs
3
## \notebook
4
## \preview Create, draw and fit a TGraph2DErrors. See the [TGraph2DErrors documentation](https://root.cern/doc/master/classTGraph2DErrors.html)
5
##
6
## \macro_image
7
## \macro_code
8
## \author Olivier Couet, Jamie Gooding
9
10
from
ctypes
import
c_double
11
12
import
ROOT
13
14
c1 =
ROOT.TCanvas
(
"c1"
)
15
16
e = 0.3
17
nd = 500
18
19
# To generate some random data to put into the graph
20
r =
ROOT.TRandom
()
21
f2 =
ROOT.TF2
(
"f2"
,
"1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200"
, -6, 6, -6, 6)
22
f2.SetParameters
(1, 1)
23
24
dte =
ROOT.TGraph2DErrors
(nd)
25
26
# Fill the 2D graph. It was created only specifying the number of points, so all
27
# elements are empty. We now "fill" the values and errors with SetPoint and SetPointError.
28
# Note that the first point has index zero
29
x =
c_double
()
30
y =
c_double
()
31
zmax = 0
32
for
i
in
range
(nd):
33
f2.GetRandom2
(x, y)
34
rnd =
r.Uniform
(-e, e)
# Generate a random number in [-e,e]
35
z =
f2.Eval
(x, y) * (1 + rnd)
36
if
z > zmax:
37
zmax = z
38
dte.SetPoint
(i, x, y, z)
39
ex = 0.05 *
r.Rndm
()
40
ey = 0.05 *
r.Rndm
()
41
ez = abs(z * rnd)
42
dte.SetPointError
(i, ex, ey, ez)
43
44
# If the fit is not needed, just draw dte here and skip the lines below
45
# dte.Draw("A p0")
46
47
# To do the fit we use a function, in this example the same f2 from above
48
f2.SetParameters
(0.5, 1.5)
49
dte.Fit
(f2)
50
fit2 =
dte.FindObject
(
"f2"
)
51
fit2.SetTitle
(
"Minuit fit result on the Graph2DErrors points"
)
52
fit2.SetMaximum
(zmax)
53
ROOT.gStyle.SetHistTopMargin
(0)
54
fit2.SetLineColor
(1)
55
fit2.SetLineWidth
(1)
56
fit2.Draw
(
"surf1"
)
57
dte.Draw
(
"same p0"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
tutorials
visualisation
graphs
gr011_graph2d_errorsfit.py
ROOT v6-36 - Reference Guide Generated on Thu Aug 21 2025 04:30:48 (GVA Time) using Doxygen 1.10.0