14import matplotlib.pyplot
as plt
21form1 = ROOT.TFormula(
"form1",
"abs(sin(x)/x)")
24sqroot = ROOT.TF1(
"sqroot",
"x*gaus(0) + [3]*form1", rangeMin, rangeMax)
25sqroot.SetParameters(10.0, 4.0, 1.0, 20.0)
28h1d = ROOT.TH1D(
"h1d",
"Test random numbers", nBins, rangeMin, rangeMax)
30random_numbers = np.array([sqroot.GetRandom()
for _
in range(10000)])
31h1d[...] = np.histogram(np.array([sqroot.GetRandom()
for _
in range(10000)]), bins=nBins, range=(rangeMin, rangeMax))[0]
34plt.figure(figsize=(7, 9))
37plt.axes([0.05, 0.55, 0.90, 0.40])
38x = np.linspace(rangeMin, rangeMax, 500)
39plt.plot(x, [sqroot.Eval(xi)
for xi
in x],
"b-", lw=5)
41plt.title(
"x*gaus(0) + [3]*form1")
42plt.text(5, 40,
"The sqroot function", fontsize=18, weight=
"bold", bbox=dict(facecolor=
"white", edgecolor=
"black"))
43plt.xlim(rangeMin, rangeMax)
46plt.axes([0.05, 0.05, 0.90, 0.40])
47hep.histplot(h1d, yerr=
False, histtype=
"fill", color=
"brown", alpha=0.7, edgecolor=
"blue", linewidth=1)
49plt.title(
"Test random numbers")
52plt.xlim(rangeMin, rangeMax)
56 f
"Entries = {len(random_numbers)}\nMean = {(np.mean(random_numbers)):.3f}\nStd Dev = {(np.std(random_numbers)):.2f}"
58plt.text(0.90, 0.90, stats_text, transform=plt.gca().transAxes, ha=
"right", va=
"top", bbox=dict(facecolor=
"white"))