20x = ROOT.RooRealVar(
"x", 
"x", 0, 20)
 
   21p = ROOT.RooPolynomial(
"p", 
"p", x, [0.01, -0.01, 0.0004])
 
   24data1 = p.generate({x}, 200)
 
   32kest1 = ROOT.RooKeysPdf(
"kest1", 
"kest1", x, data1, ROOT.RooKeysPdf.MirrorBoth)
 
   36kest2 = ROOT.RooKeysPdf(
"kest2", 
"kest2", x, data1, ROOT.RooKeysPdf.NoMirror)
 
   40kest3 = ROOT.RooKeysPdf(
"kest1", 
"kest1", x, data1, ROOT.RooKeysPdf.MirrorBoth, 2)
 
   43frame = x.frame(Title=
"Adaptive kernel estimation pdf with and w/o mirroring", Bins=20)
 
   46kest2.plotOn(frame, LineStyle=
"--", LineColor=
"r")
 
   49frame2 = x.frame(Title=
"Adaptive kernel estimation pdf with regular, bandwidth")
 
   51kest3.plotOn(frame2, LineColor=
"m")
 
   57y = ROOT.RooRealVar(
"y", 
"y", 0, 20)
 
   58py = ROOT.RooPolynomial(
 
   62    [0.01, 0.01, -0.0004],
 
   64pxy = ROOT.RooProdPdf(
"pxy", 
"pxy", [p, py])
 
   65data2 = pxy.generate({x, y}, 1000)
 
   71kest4 = ROOT.RooNDKeysPdf(
"kest4", 
"kest4", [x, y], data2, 
"am")
 
   75kest5 = ROOT.RooNDKeysPdf(
"kest5", 
"kest5", [x, y], data2, 
"am", 2)
 
   78hh_data = data2.createHistogram(
"hh_data", x, Binning=10, YVar=dict(var=y, Binning=10))
 
   81hh_pdf = kest4.createHistogram(
"hh_pdf", x, Binning=25, YVar=dict(var=y, Binning=25))
 
   82hh_pdf2 = kest5.createHistogram(
"hh_pdf2", x, Binning=25, YVar=dict(var=y, Binning=25))
 
   83hh_pdf.SetLineColor(ROOT.kBlue)
 
   84hh_pdf2.SetLineColor(ROOT.kMagenta)
 
   86c = ROOT.TCanvas(
"rf707_kernelestimation", 
"rf707_kernelestimation", 800, 800)
 
   89ROOT.gPad.SetLeftMargin(0.15)
 
   90frame.GetYaxis().SetTitleOffset(1.4)
 
   93ROOT.gPad.SetLeftMargin(0.15)
 
   94frame2.GetYaxis().SetTitleOffset(1.8)
 
   97ROOT.gPad.SetLeftMargin(0.15)
 
   98hh_data.GetZaxis().SetTitleOffset(1.4)
 
  101ROOT.gPad.SetLeftMargin(0.20)
 
  102hh_pdf.GetZaxis().SetTitleOffset(2.4)
 
  104hh_pdf2.Draw(
"surfsame")
 
  106c.SaveAs(
"rf707_kernelestimation.png")