import ROOT
dt = ROOT.RooRealVar("dt", "dt", -20, 20)
dm = ROOT.RooRealVar("dm", "dm", 0.472)
tau = ROOT.RooRealVar("tau", "tau", 1.547)
w = ROOT.RooRealVar("w", "mistag rate", 0.1)
dw = ROOT.RooRealVar("dw", "delta mistag rate", 0.0)
mixState = ROOT.RooCategory("mixState", "B0/B0bar mixing state", {"mixed": -1, "unmixed": 1})
tagFlav = ROOT.RooCategory("tagFlav", "Flavour of the tagged B0", {"B0": 1, "B0bar": -1})
dterr = ROOT.RooRealVar("dterr", "dterr", 0.1, 1.0)
bias1 = ROOT.RooRealVar("bias1", "bias1", 0)
sigma1 = ROOT.RooRealVar("sigma1", "sigma1", 0.1)
gm1 = ROOT.RooGaussModel("gm1", "gauss model 1", dt, bias1, sigma1)
bmix = ROOT.RooBMixDecay("bmix", "decay", dt, mixState, tagFlav, tau, dm, w, dw, gm1, type="DoubleSided")
data = bmix.generate({dt, mixState, tagFlav}, 2000)
tbins = ROOT.RooBinning(-15, 15)
tbins.addUniform(60, -15, 0)
tbins.addUniform(15, 0, 15)
dtframe = dt.frame(Range=(-15, 15), Title="dt distribution with custom binning")
data.plotOn(dtframe, Binning=tbins)
bmix.plotOn(dtframe)
abins = ROOT.RooBinning(-10, 10)
abins.addBoundary(0)
abins.addBoundaryPair(1)
abins.addBoundaryPair(2)
abins.addBoundaryPair(3)
abins.addBoundaryPair(4)
abins.addBoundaryPair(6)
aframe = dt.frame(Range=(-10, 10), Title="mixState asymmetry distribution with custom binning")
data.plotOn(aframe, Asymmetry=mixState, Binning=abins)
bmix.plotOn(aframe, Asymmetry=mixState)
aframe.SetMinimum(-1.1)
aframe.SetMaximum(1.1)
c = ROOT.TCanvas("rf108_plotbinning", "rf108_plotbinning", 800, 400)
c.Divide(2)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
dtframe.GetYaxis().SetTitleOffset(1.6)
dtframe.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.15)
aframe.GetYaxis().SetTitleOffset(1.6)
aframe.Draw()
c.SaveAs("rf108_plotbinning.png")