12 from __future__
import print_function
23 x = ROOT.RooRealVar(
"x",
"x", -10, 10)
24 y = ROOT.RooRealVar(
"y",
"y", 0, 40)
25 c = ROOT.RooCategory(
"c",
"c")
26 c.defineType(
"Plus", +1)
27 c.defineType(
"Minus", -1)
34 d = ROOT.RooDataSet(
"d",
"d", ROOT.RooArgSet(x, y, c))
43 y.setVal(math.sqrt(1.0 * i))
53 d.add(ROOT.RooArgSet(x, y, c))
75 print(
"\n >> d1 has only columns x,c")
76 d1 = d.reduce(ROOT.RooArgSet(x, c))
79 print(
"\n >> d2 has only column y")
80 d2 = d.reduce(ROOT.RooArgSet(y))
83 print(
"\n >> d3 has only the points with y>5.17")
84 d3 = d.reduce(
"y>5.17")
87 print(
"\n >> d4 has only columns x, for data points with y>5.17")
88 d4 = d.reduce(ROOT.RooArgSet(x, c),
"y>5.17")
92 print(
"\n >> merge d2(y) with d1(x,c) to form d1(x,c,y)")
97 print(
"\n >> append data points of d3 to d1")
107 print(
">> construct dh (binned) from d(unbinned) but only take the x and y dimensions, ")
108 print(
">> the category 'c' will be projected in the filling process")
116 dh = ROOT.RooDataHist(
"dh",
"binned version of d", ROOT.RooArgSet(x, y), d)
119 yframe = y.frame(ROOT.RooFit.Bins(10), ROOT.RooFit.Title(
120 "Operations on binned datasets"))
124 print(
">> number of bins in dh : ", dh.numEntries())
125 print(
">> sum of weights in dh : ", dh.sum(ROOT.kFALSE))
127 print(
">> integral over histogram: ", dh.sum(ROOT.kTRUE))
132 print(
">> retrieving the properties of the bin enclosing coordinate (x,y) = (0.3,20.5) bin center:")
134 dh.get(ROOT.RooArgSet(x, y)).Print(
"v")
135 print(
" weight = ", dh.weight())
142 print(
">> Creating 1-dimensional projection on y of dh for bins with x>0")
143 dh2 = dh.reduce(ROOT.RooArgSet(y),
"x>0")
147 dh2.plotOn(yframe, ROOT.RooFit.LineColor(ROOT.kRed),
148 ROOT.RooFit.MarkerColor(ROOT.kRed))
154 print(
"\n >> Persisting d via ROOT I/O")
155 f = ROOT.TFile(
"rf402_datahandling.root",
"RECREATE")
163 c = ROOT.TCanvas(
"rf402_datahandling",
"rf402_datahandling", 600, 600)
164 ROOT.gPad.SetLeftMargin(0.15)
165 yframe.GetYaxis().SetTitleOffset(1.4)
168 c.SaveAs(
"rf402_datahandling.png")