import ROOT
x = ROOT.RooRealVar("x", "x", 0, 10)
a = ROOT.RooArgusBG("a", "argus(x)", x, ROOT.RooFit.RooConst(10), ROOT.RooFit.RooConst(-1))
data = a.generate({x}, 10000)
xRegion = ROOT.RooThresholdCategory("xRegion", "region of x", x, "Background")
xRegion.addThreshold(4.23, "Background")
xRegion.addThreshold(5.23, "SideBand")
xRegion.addThreshold(8.23, "Signal")
xRegion.addThreshold(9.23, "SideBand")
data.addColumn(xRegion)
xframe = x.frame(Title="Demo of threshold and binning mapping functions")
data.plotOn(xframe)
data.plotOn(xframe, Cut="xRegion==xRegion::SideBand", MarkerColor="r", LineColor="r")
x.setBins(10, "coarse")
xBins = ROOT.RooBinningCategory("xBins", "coarse bins in x", x, "coarse")
xbtable = data.table(xBins)
xbtable.Print("v")
xb = data.addColumn(xBins)
xb.setRange("alt", "x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9")
dataSel = data.reduce(CutRange="alt", EventRange=(0, 5000))
dataSel.plotOn(xframe, MarkerColor="g", LineColor="g")
c = ROOT.TCanvas("rf405_realtocatfuncs", "rf405_realtocatfuncs", 600, 600)
xframe.SetMinimum(0.01)
ROOT.gPad.SetLeftMargin(0.15)
xframe.GetYaxis().SetTitleOffset(1.4)
xframe.Draw()
c.SaveAs("rf405_realtocatfuncs.png")