11from __future__
import print_function
22x = ROOT.RooRealVar(
"x",
"x", -10, 10)
23y = ROOT.RooRealVar(
"y",
"y", 0, 40)
24c = ROOT.RooCategory(
"c",
"c")
25c.defineType(
"Plus", +1)
26c.defineType(
"Minus", -1)
33d = ROOT.RooDataSet(
"d",
"d", {x, y, c})
42 y.setVal(math.sqrt(1.0 * i))
75print(
"\n >> d1 has only columns x,c")
79print(
"\n >> d2 has only column y")
83print(
"\n >> d3 has only the points with y>5.17")
84d3 = d.reduce(
"y>5.17")
87print(
"\n >> d4 has only columns x, for data points with y>5.17")
88d4 = d.reduce({x, c},
"y>5.17")
92print(
"\n >> merge d2(y) with d1(x,c) to form d1(x,c,y)")
97print(
"\n >> append data points of d3 to d1")
107print(
">> construct dh (binned) from d(unbinned) but only take the x and y dimensions, ")
108print(
">> the category 'c' will be projected in the filling process")
116dh = ROOT.RooDataHist(
"dh",
"binned version of d", {x, y}, d)
119yframe = y.frame(Bins=10, Title=
"Operations on binned datasets")
123print(
">> number of bins in dh : ", dh.numEntries())
124print(
">> sum of weights in dh : ", dh.sum(
False))
126print(
">> integral over histogram: ", dh.sum(
True))
131print(
">> retrieving the properties of the bin enclosing coordinate (x,y) = (0.3,20.5) bin center:")
133dh.get({x, y}).Print(
"v")
134print(
" weight = ", dh.weight())
141print(
">> Creating 1-dimensional projection on y of dh for bins with x>0")
142dh2 = dh.reduce({y},
"x>0")
146dh2.plotOn(yframe, LineColor=
"r", MarkerColor=
"r")
152print(
"\n >> Persisting d via ROOT I/O")
153f = ROOT.TFile(
"rf402_datahandling.root",
"RECREATE")
161c = ROOT.TCanvas(
"rf402_datahandling",
"rf402_datahandling", 600, 600)
162ROOT.gPad.SetLeftMargin(0.15)
163yframe.GetYaxis().SetTitleOffset(1.4)
166c.SaveAs(
"rf402_datahandling.png")