17from array 
import array
 
   20def makeTH1(name, mean, sigma):
 
   21    """Create ROOT TH1 filled with a Gaussian distribution.""" 
   23    hh = ROOT.TH1D(name, name, 100, -10, 10)
 
   25        hh.Fill(ROOT.gRandom.Gaus(mean, sigma))
 
   31    """Create ROOT ROOT.TTree filled with a Gaussian distribution in x and a uniform distribution in y.""" 
   33    tree = ROOT.TTree(
"tree", 
"tree")
 
   38    tree.Branch(
"x", px, 
"x/D")
 
   39    tree.Branch(
"y", py, 
"y/D")
 
   40    tree.Branch(
"z", pz, 
"z/D")
 
   41    tree.Branch(
"i", pi, 
"i/I")
 
   43        px[0] = ROOT.gRandom.Gaus(0, 3)
 
   44        py[0] = ROOT.gRandom.Uniform() * 30 - 15
 
   45        pz[0] = ROOT.gRandom.Gaus(0, 5)
 
   56hh_1 = makeTH1(
"hh1", 0, 3)
 
   57hh_2 = makeTH1(
"hh2", -3, 1)
 
   58hh_3 = makeTH1(
"hh3", +3, 4)
 
   61x = ROOT.RooRealVar(
"x", 
"x", -10, 10)
 
   64c = ROOT.RooCategory(
"c", 
"c")
 
   65c.defineType(
"SampleA")
 
   66c.defineType(
"SampleB")
 
   67c.defineType(
"SampleC")
 
   71dh = ROOT.RooDataHist(
"dh", 
"dh", [x], Index=c, Import={
"SampleA": hh_1, 
"SampleB": hh_2, 
"SampleC": hh_3})
 
   74dh2 = ROOT.RooDataHist(
"dh", 
"dh", [x], Index=c, Import={
"SampleA": hh_1, 
"SampleB": hh_2, 
"SampleC": hh_3})
 
   83y = ROOT.RooRealVar(
"y", 
"y", -10, 10)
 
   84z = ROOT.RooRealVar(
"z", 
"z", -10, 10)
 
   87ds = ROOT.RooDataSet(
"ds", 
"ds", {x, y}, Import=tree)
 
   92ds2 = ROOT.RooDataSet(
"ds2", 
"ds2", {x, y, z}, Import=tree, Cut=
"y+z<0")
 
   99i = ROOT.RooRealVar(
"i", 
"i", 0, 5)
 
  100ds3 = ROOT.RooDataSet(
"ds3", 
"ds3", {i, x}, Import=tree)
 
  104icat = ROOT.RooCategory(
"i", 
"i", {
"State0": 0, 
"State1": 1})
 
  108ds4 = ROOT.RooDataSet(
"ds4", 
"ds4", {icat, x}, Import=tree)
 
  115dsA = ds2.reduce({x, y}, 
"z<-5")
 
  116dsB = ds2.reduce({x, y}, 
"abs(z)<5")
 
  117dsC = ds2.reduce({x, y}, 
"z>5")
 
  121dsABC = ROOT.RooDataSet(
"dsABC", 
"dsABC", {x, y}, Index=c, Import={
"SampleA": dsA, 
"SampleB": dsB, 
"SampleC": dsC})