import ROOT
ROOT.RooMsgService.instance().setGlobalKillBelow(5)
%jsroot on
from matplotlib import pyplot
%matplotlib inline
First we read in the signal region model from the workspace building notebook.
infile = ROOT.TFile.Open("output/SRselection.root")
w = infile.Get("w")
mc = w.obj("ModelConfig")
data = w.data("data")
mc.LoadSnapshot()
x = w.var("x")
RooStats has several built in Bayesian calculators. We have the choice between using the MCMC calculator or the numerical one. We will start using the MCMC and optionally in the next exercise we will show how to use the numerical Bayesian calculator. We will use the same model used before for the Profile Likelihood calculator and repeat a similar process.
Once the Data etc are extracted from the workspace. We also need the number of signal events.
To optimise we take a range of possible values (Truth was 100 events)
nsig = w.var("n_sig")
nsig.setRange(300,600)
Now we define our MCMC calculator. Again looking at 68.3% confidence level.
mcmc = ROOT.RooStats.MCMCCalculator(data,mc)
mcmc.SetConfidenceLevel(0.683)
Now MCMC methods have various implementations and approaches. Here we must propose a function. The sequential proposal given is usually fairly robust.
sp = ROOT.RooStats.SequentialProposal(0.1)
mcmc.SetProposalFunction(sp)
If you're interested in this I'd recommend looking it up. Here I just define lots of parameters. SetNumIters is related to the number of iterations of the Metropolis-Hastings algorithm SetBurnInSteps concerns how many interations are needed to avoid local minima due to low stats We can construct either a one-sided Bayesian interval (SetLetSideTailFraction=0) or central bayesian interval (SetLetSideTailFraction=0.5)
mcmc.SetNumIters(100000)
mcmc.SetNumBurnInSteps(1000)
mcmc.SetLeftSideTailFraction(0.5)
Now we run the calculator! (may take a while depending on the number of steps)
interval = mcmc.GetInterval()
Now we plot and print!
firstPOI = mc.GetParametersOfInterest().first()
print "68% interval on {0} is : [{1},{2}]".format(firstPOI.GetName(),interval.LowerLimit(firstPOI),interval.UpperLimit(firstPOI))
c = ROOT.TCanvas()
plot = ROOT.RooStats.MCMCIntervalPlot(interval)
plot.Draw()
c.Draw()