import ROOT
ROOT.RooMsgService.instance().setGlobalKillBelow(5)
%jsroot on
from matplotlib import pyplot
%matplotlib inline
In our last exercise we will compute an upper limit using the frequentist hypothesis test inversion method. We need to perform the hypothesis test for different parameter of interest points and compute the corresponding p-values. Since we are interesting in computing a limit, the test null hypothesis, that we want to disprove, is the in this case the S+B model, while the alternate hypothesis is the B only model. It is important to remember this, when we construct the hypothesis test calculator.
For doing the inversion RooStats provides an helper class, HypoTestInverter, which is constructed using one of the HypoTest calculator (Frequentist, Hybrid or Asymptotic). To compute the limit we need to do:
infile = ROOT.TFile.Open("output/mH_BinModel.root")
w = infile.Get("w")
mc = w.obj("ModelConfig")
data = w.data("data")
sbModel = w.obj("ModelConfig")
poi = sbModel.GetParametersOfInterest().first()
bModel = sbModel.Clone()
bModel.SetName(sbModel.GetName()+"_with_poi_0")
poi.setVal(0)
bModel.SetSnapshot(ROOT.RooArgSet(poi))
fc = ROOT.RooStats.FrequentistCalculator(data, bModel, sbModel)
fc.SetToys(1000,500)
ac = ROOT.RooStats.AsymptoticCalculator(data, bModel, sbModel)
ac.SetOneSided(True)
ac.SetPrintLevel(-1)
calc = ROOT.RooStats.HypoTestInverter(ac)
calc.SetConfidenceLevel(0.95)
for CLS
calc.UseCLs(True)
calc.SetVerbose(False)
toymcs = calc.GetHypoTestCalculator().GetTestStatSampler()
Profile likelihood test statistics are used one sided for CLs since it's a bounded interval.
profll = ROOT.RooStats.ProfileLikelihoodTestStat(sbModel.GetPdf())
profll.SetOneSided(True)
toymcs.SetTestStatistic(profll)
if not sbModel.GetPdf().canBeExtended():
toymcs.SetNEventsPerToy(1)
print 'can not be extended'
define the number of points and some minmaxes
npoints = 10
poimin = poi.getMin()
poimax = poi.getMax()
calc.SetFixedScan(npoints,poimin,poimax)
r = calc.GetInterval()
upperLimit = r.UpperLimit()
plot = ROOT.RooStats.HypoTestInverterPlot("HTI_Result_Plot","HypoTest Scan Result",r)
c = ROOT.TCanvas("HypoTestInverter Scan")
c.SetLogy(False)
plot.Draw("CLb 2CL")
c.Draw()