def plInterval(w, modelConfig, dataset, cl=0.95, poi="f", plot=False): out = {} calc = r.RooStats.ProfileLikelihoodCalculator(dataset, modelConfig) w.var("f").setVal(0.1) # was 0.1 w.var("f").setConstant(False) calc.SetConfidenceLevel(0.95) interval = calc.GetInterval() out["low"] = interval.LowerLimit(w.var(poi)) out["high"] = interval.UpperLimit(w.var(poi)) if plot: canvas = r.TCanvas("pl") canvas.SetTickx() canvas.SetTicky() plPlot = r.RooStats.LikelihoodIntervalPlot(interval) plPlot.Draw() canvas.Write() utils.rootkill(interval) return out
def pValue(w, nToys, plot_name=None): results = rooFitResults(w.pdf("model"), dataset) w.saveSnapshot("snap", w.allVars()) maxData = -results.minNll() maxs = [] graph = r.TGraph() for i,dset in enumerate(pseudoData(w, nToys)): w.loadSnapshot("snap") results = rooFitResults(w.pdf("model"), dset) maxs.append(-results.minNll()) graph.SetPoint(i, i, indexFraction(maxData, maxs)) utils.rootkill(results) if plot: c = r.TCanvas(plot_name) graph.Draw("a*") c.Write() hist = histToList("%s_hist" % plot_name, "", 50, maxs) hist_actual = histToList("%s_hist_actual" % plot_name, "", 50, [0, maxData]) hist.Write() hist_actual.Write() utils.rootkill(graph) return indexFraction(maxData, maxs)