15from array
import array
23 hh = ROOT.TH1D(
"hh",
"hh", 25, -10, 10)
24 hh.Fill(np.array([trnd.Gaus(0, 3)
for _
in range(100)]))
32 tree = ROOT.TTree(
"tree",
"tree")
35 tree.Branch(
"x", px,
"x/D")
36 tree.Branch(
"y", py,
"y/D")
38 px[0] = trnd.Gaus(0, 3)
39 py[0] = trnd.Uniform() * 30 - 15
54x = ROOT.RooRealVar(
"x",
"x", -10, 10)
58dh = ROOT.RooDataHist(
"dh",
"dh", [x], Import=hh)
63frame = x.frame(Title=
"Imported ROOT.TH1 with Poisson error bars")
67mean = ROOT.RooRealVar(
"mean",
"mean", 0, -10, 10)
68sigma = ROOT.RooRealVar(
"sigma",
"sigma", 3, 0.1, 10)
69gauss = ROOT.RooGaussian(
"gauss",
"gauss", x, mean, sigma)
70gauss.fitTo(dh, PrintLevel=-1)
79frame2 = x.frame(Title=
"Imported ROOT.TH1 with internal errors")
80dh.plotOn(frame2, DataError=
"SumW2")
97y = ROOT.RooRealVar(
"y",
"y", -10, 10)
107ds = ROOT.RooDataSet(
"ds",
"ds", {x, y}, Import=tree)
113def write_dataset(ds, filename):
115 outstream = ROOT.std.ofstream(filename)
121write_dataset(ds,
"rf102_testData.txt")
125print(
"\n-----------------------\nReading data from ASCII")
126dataReadBack = ROOT.RooDataSet.read(
127 "rf102_testData.txt",
132dataReadBack.Print(
"V")
134print(
"\nOriginal data, line 20:")
137print(
"\nRead-back data, line 20:")
138dataReadBack.get(20).
Print(
"V")
147frame3 = y.frame(Title=
"Unbinned data shown in default frame binning")
151frame4 = y.frame(Title=
"Unbinned data shown with custom binning")
152ds.plotOn(frame4, Binning=20)
154frame5 = y.frame(Title=
"Unbinned data read back from ASCII file")
155ds.plotOn(frame5, Binning=20)
156dataReadBack.plotOn(frame5, Binning=20, MarkerColor=
"r", MarkerStyle=5)
159c = ROOT.TCanvas(
"rf102_dataimport",
"rf102_dataimport", 800, 800)
162ROOT.gPad.SetLeftMargin(0.15)
163frame.GetYaxis().SetTitleOffset(1.4)
166ROOT.gPad.SetLeftMargin(0.15)
167frame2.GetYaxis().SetTitleOffset(1.4)
170ROOT.gPad.SetLeftMargin(0.15)
171frame3.GetYaxis().SetTitleOffset(1.4)
174ROOT.gPad.SetLeftMargin(0.15)
175frame4.GetYaxis().SetTitleOffset(1.4)
178ROOT.gPad.SetLeftMargin(0.15)
179frame4.GetYaxis().SetTitleOffset(1.4)
182c.SaveAs(
"rf102_dataimport.png")
void Print(GNN_Data &d, std::string txt="")