15from array
import array
22 hh = ROOT.TH1D(
"hh",
"hh", 25, -10, 10)
24 hh.Fill(ROOT.gRandom.Gaus(0, 3))
32 tree = ROOT.TTree(
"tree",
"tree")
35 tree.Branch(
"x", px,
"x/D")
36 tree.Branch(
"y", py,
"y/D")
38 px[0] = ROOT.gRandom.Gaus(0, 3)
39 py[0] = ROOT.gRandom.Uniform() * 30 - 15
53x = ROOT.RooRealVar(
"x",
"x", -10, 10)
57dh = ROOT.RooDataHist(
"dh",
"dh", [x], Import=hh)
62frame = x.frame(Title=
"Imported ROOT.TH1 with Poisson error bars")
66mean = ROOT.RooRealVar(
"mean",
"mean", 0, -10, 10)
67sigma = ROOT.RooRealVar(
"sigma",
"sigma", 3, 0.1, 10)
68gauss = ROOT.RooGaussian(
"gauss",
"gauss", x, mean, sigma)
69gauss.fitTo(dh, PrintLevel=-1)
78frame2 = x.frame(Title=
"Imported ROOT.TH1 with internal errors")
79dh.plotOn(frame2, DataError=
"SumW2")
96y = ROOT.RooRealVar(
"y",
"y", -10, 10)
106ds = ROOT.RooDataSet(
"ds",
"ds", {x, y}, Import=tree)
112def write_dataset(ds, filename):
114 outstream = ROOT.std.ofstream(filename)
120write_dataset(ds,
"rf102_testData.txt")
124print(
"\n-----------------------\nReading data from ASCII")
125dataReadBack = ROOT.RooDataSet.read(
126 "rf102_testData.txt",
131dataReadBack.Print(
"V")
133print(
"\nOriginal data, line 20:")
136print(
"\nRead-back data, line 20:")
137dataReadBack.get(20).Print(
"V")
146frame3 = y.frame(Title=
"Unbinned data shown in default frame binning")
150frame4 = y.frame(Title=
"Unbinned data shown with custom binning")
151ds.plotOn(frame4, Binning=20)
153frame5 = y.frame(Title=
"Unbinned data read back from ASCII file")
154ds.plotOn(frame5, Binning=20)
155dataReadBack.plotOn(frame5, Binning=20, MarkerColor=
"r", MarkerStyle=5)
158c = ROOT.TCanvas(
"rf102_dataimport",
"rf102_dataimport", 800, 800)
161ROOT.gPad.SetLeftMargin(0.15)
162frame.GetYaxis().SetTitleOffset(1.4)
165ROOT.gPad.SetLeftMargin(0.15)
166frame2.GetYaxis().SetTitleOffset(1.4)
169ROOT.gPad.SetLeftMargin(0.15)
170frame3.GetYaxis().SetTitleOffset(1.4)
173ROOT.gPad.SetLeftMargin(0.15)
174frame4.GetYaxis().SetTitleOffset(1.4)
177ROOT.gPad.SetLeftMargin(0.15)
178frame4.GetYaxis().SetTitleOffset(1.4)
181c.SaveAs(
"rf102_dataimport.png")