5 This file contains example for generating validation plots using python
11 from ROOT
import TFile, TNtuple, TH1F, TF1, TH2F, TF2, TRandom3, gRandom, TNamed, TEfficiency, TGraphErrors
13 basf2.set_random_seed(1337)
15 tfile = TFile(
"examplePython.root",
"RECREATE")
16 tntuple = TNtuple(
"ntuple_test",
"ntuple test",
"x:y:z:k")
18 prefix =
"examplePython"
20 array_of_values = array.array(
'f', [23.4, 4.4, 5.12, -23.0])
21 tntuple.Fill(array_of_values)
23 tntuple.SetAlias(
'Description',
"This is a description test. "
24 "Lorem ipsum sit dolor amet. We also support $\LaTeX$! "
25 "\n <br> \n For example, here is the infamous "
26 "Einstein-Pythagoras-theorem: \n "
27 "$$a^2 + b^2 = \\frac{E}{m}$$ \n Of course, you can also"
28 "do other things, like $\\theta = 90^\circ$ or $D^- "
29 "\\rightarrow D^0 \pi^- \pi^+$. \n Sometimes it is "
30 "necessary to escape commands with a double backslash, "
31 "because e.g. \\theta will be interpreted as [tab]heta.")
32 tntuple.SetAlias(
'Check',
"This is the check text.")
33 tntuple.SetAlias(
'Contact',
"Name of the contact person.")
34 tntuple.SetAlias(
'MetaOptions',
"some_meta_options")
40 gausH = TH1F(
"gaus_histogram", prefix +
" Gaus Histogram", 100, -3, 3)
41 gausH.FillRandom(
"gaus", 5000)
43 gausH.GetListOfFunctions().Add(TNamed(
'Description',
"xlog"))
44 gausH.GetListOfFunctions().Add(TNamed(
'Check',
"Gaus Histogram Check"))
45 gausH.GetListOfFunctions().Add(TNamed(
'Contact',
"Gaus Histogram Contact"))
46 gausH.GetListOfFunctions().Add(TNamed(
'MetaOptions',
"logx, nostats"))
50 gausH = TH1F(
"exp_histogram", prefix +
" Exp Histogram", 100, 0, 10)
52 exp_fn = TF1(
"exp_fn",
"exp(-x)", 0, 10)
53 gausH.FillRandom(
"exp_fn", 5000)
55 gausH.GetListOfFunctions().Add(TNamed(
'Description',
"Expert Validation Plot"))
56 gausH.GetListOfFunctions().Add(TNamed(
'Check',
"Exp Histogram Check"))
57 gausH.GetListOfFunctions().Add(TNamed(
'Contact',
"Exp Histogram Contact"))
58 gausH.GetListOfFunctions().Add(TNamed(
59 'MetaOptions',
"logy, nostats, C"
65 hist2d = TH2F(
"example_2d_histogram",
"example_2d_title",
69 cov = [[1, 0], [0, 1]]
70 for i
in range(10000):
71 x, y = np.random.multivariate_normal(mean, cov)
74 hist2d.GetListOfFunctions().Add(TNamed(
'Description',
"Some 2D Histogram"))
75 hist2d.GetListOfFunctions().Add(TNamed(
'Check',
"Check For Something"))
76 hist2d.GetListOfFunctions().Add(TNamed(
'Contact',
"Contact Someone"))
77 hist2d.GetListOfFunctions().Add(TNamed(
'MetaOptions',
"contz"))
82 gaus_passed = TH1F(
"gaus_passed",
"gaus_passed", 50, -0.5, 49.5)
83 gaus_total = TH1F(
"gaus_total",
"gaus_total", 50, -0.5, 49.5)
87 ratio = float(i) / 5000.0
88 passed = gRandom.Uniform(ratio * 0.45, 1.0)
89 pos = gRandom.Uniform(ratio * 30.0, 49.5)
95 teff = TEfficiency(gaus_passed, gaus_total)
96 teff.SetName(
"TEfficiency")
97 teff.GetListOfFunctions().Add(TNamed(
'Description',
"Efficiency plot of something"))
98 teff.GetListOfFunctions().Add(TNamed(
'Check',
"Check For Something"))
99 teff.GetListOfFunctions().Add(TNamed(
'Contact',
"Contact Someone"))
100 teff.GetListOfFunctions().Add(TNamed(
'MetaOptions',
""))
105 graph_err = TGraphErrors()
110 ratio = float(i) / 50.0
111 passed = gRandom.Uniform(ratio * 0.45, 1.0)
114 graph_err.SetPoint(i, i + 1.0, passed)
116 graph_err.SetName(
"TGraphErrors")
117 graph_err.GetListOfFunctions().Add(TNamed(
'Description',
"TGraphErrors plot of something"))
118 graph_err.GetListOfFunctions().Add(TNamed(
'Check',
"Check For Something"))
119 graph_err.GetListOfFunctions().Add(TNamed(
'Contact',
"Contact Someone"))
120 graph_err.GetListOfFunctions().Add(TNamed(
'MetaOptions',
""))