16from array
import array
20def makeTH1(trnd, name, mean, sigma):
21 """Create ROOT TH1 filled with a Gaussian distribution."""
23 hh = ROOT.TH1D(name, name, 100, -10, 10)
24 hh.Fill(np.array([trnd.Gaus(mean, sigma)
for _
in range(1000)]))
29 """Create ROOT ROOT.TTree filled with a Gaussian distribution in x and a uniform distribution in y."""
31 tree = ROOT.TTree(
"tree",
"tree")
36 tree.Branch(
"x", px,
"x/D")
37 tree.Branch(
"y", py,
"y/D")
38 tree.Branch(
"z", pz,
"z/D")
39 tree.Branch(
"i", pi,
"i/I")
41 px[0] = trnd.Gaus(0, 3)
42 py[0] = trnd.Uniform() * 30 - 15
43 pz[0] = trnd.Gaus(0, 5)
55hh_1 = makeTH1(trnd,
"hh1", 0, 3)
56hh_2 = makeTH1(trnd,
"hh2", -3, 1)
57hh_3 = makeTH1(trnd,
"hh3", +3, 4)
60x = ROOT.RooRealVar(
"x",
"x", -10, 10)
63c = ROOT.RooCategory(
"c",
"c")
64c.defineType(
"SampleA")
65c.defineType(
"SampleB")
66c.defineType(
"SampleC")
70dh = ROOT.RooDataHist(
"dh",
"dh", [x], Index=c, Import={
"SampleA": hh_1,
"SampleB": hh_2,
"SampleC": hh_3})
73dh2 = ROOT.RooDataHist(
"dh",
"dh", [x], Index=c, Import={
"SampleA": hh_1,
"SampleB": hh_2,
"SampleC": hh_3})
82y = ROOT.RooRealVar(
"y",
"y", -10, 10)
83z = ROOT.RooRealVar(
"z",
"z", -10, 10)
86ds = ROOT.RooDataSet(
"ds",
"ds", {x, y}, Import=tree)
91ds2 = ROOT.RooDataSet(
"ds2",
"ds2", {x, y, z}, Import=tree, Cut=
"y+z<0")
98i = ROOT.RooRealVar(
"i",
"i", 0, 5)
99ds3 = ROOT.RooDataSet(
"ds3",
"ds3", {i, x}, Import=tree)
103icat = ROOT.RooCategory(
"i",
"i", {
"State0": 0,
"State1": 1})
107ds4 = ROOT.RooDataSet(
"ds4",
"ds4", {icat, x}, Import=tree)
114dsA = ds2.reduce({x, y},
"z<-5")
115dsB = ds2.reduce({x, y},
"abs(z)<5")
116dsC = ds2.reduce({x, y},
"z>5")
120dsABC = ROOT.RooDataSet(
"dsABC",
"dsABC", {x, y}, Index=c, Import={
"SampleA": dsA,
"SampleB": dsB,
"SampleC": dsC})