27wspace = ROOT.RooWorkspace()
29 "Poisson::countingModel(obs[150,0,300], " "sum(s[50,0,120]*ratioSigEff[1.,0,3.],b[100]*ratioBkgEff[1.,0.,3.]))"
31wspace.factory(
"Gaussian::sigConstraint(gSigEff[1,0,3],ratioSigEff,0.05)")
32wspace.factory(
"Gaussian::bkgConstraint(gSigBkg[1,0,3],ratioBkgEff,0.2)")
33wspace.factory(
"PROD::modelWithConstraints(countingModel,sigConstraint,bkgConstraint)")
36modelWithConstraints = wspace[
"modelWithConstraints"]
42ratioSigEff = wspace[
"ratioSigEff"]
43ratioBkgEff = wspace[
"ratioBkgEff"]
44constrainedParams = {ratioSigEff, ratioBkgEff}
46gSigEff = wspace[
"gSigEff"]
47gSigBkg = wspace[
"gSigBkg"]
53dataOrig = ROOT.RooDataSet(
"exampleData",
"exampleData", {obs})
57modelWithConstraints.fitTo(dataOrig, Constrain=constrainedParams, PrintLevel=-1)
60modelConfig = ROOT.RooStats.ModelConfig(wspace)
61modelConfig.SetPdf(modelWithConstraints)
62modelConfig.SetParametersOfInterest({s})
63modelConfig.SetNuisanceParameters(constrainedParams)
64modelConfig.SetObservables(obs)
65modelConfig.SetGlobalObservables({gSigEff, gSigBkg})
66modelConfig.SetName(
"ModelConfig")
67wspace.Import(modelConfig)
68wspace.Import(dataOrig)
73data = wspace[dataOrig.GetName()]
76plc = ROOT.RooStats.ProfileLikelihoodCalculator(data, modelConfig)
78lrinterval = plc.GetInterval()
81dataCanvas = ROOT.TCanvas(
"dataCanvas")
82dataCanvas.Divide(2, 1)
85plotInt = ROOT.RooStats.LikelihoodIntervalPlot(lrinterval)
86plotInt.SetTitle(
"Profile Likelihood Ratio and Posterior for S")
90fc = ROOT.RooStats.FeldmanCousins(data, modelConfig)
91fc.UseAdaptiveSampling(
True)
92fc.FluctuateNumDataEntries(
False)
96fcint = fc.GetInterval()
98fit = modelWithConstraints.fitTo(data, Save=
True, PrintLevel=-1)
103ph = ROOT.RooStats.ProposalHelper()
104ph.SetVariables(fit.floatParsFinal())
105ph.SetCovMatrix(fit.covarianceMatrix())
106ph.SetUpdateProposalParameters(
True)
108pdfProp = ph.GetProposalFunction()
110mc = ROOT.RooStats.MCMCCalculator(data, modelConfig)
113mc.SetNumBurnInSteps(40)
114mc.SetProposalFunction(pdfProp)
115mc.SetLeftSideTailFraction(0.5)
116mcInt = mc.GetInterval()
119print(
"Profile lower limit on s = ", lrinterval.LowerLimit(s))
120print(
"Profile upper limit on s = ", lrinterval.UpperLimit(s))
124 fcul = fcint.UpperLimit(s)
125 fcll = fcint.LowerLimit(s)
126 print(
"FC lower limit on s = ", fcll)
127 print(
"FC upper limit on s = ", fcul)
128 fcllLine = ROOT.TLine(fcll, 0, fcll, 1)
129 fculLine = ROOT.TLine(fcul, 0, fcul, 1)
130 fcllLine.SetLineColor(ROOT.kRed)
131 fculLine.SetLineColor(ROOT.kRed)
132 fcllLine.Draw(
"same")
133 fculLine.Draw(
"same")
137mcPlot = ROOT.RooStats.MCMCIntervalPlot(mcInt)
138mcPlot.SetLineColor(ROOT.kMagenta)
139mcPlot.SetLineWidth(2)
142mcul = mcInt.UpperLimit(s)
143mcll = mcInt.LowerLimit(s)
144print(
"MCMC lower limit on s = ", mcll)
145print(
"MCMC upper limit on s = ", mcul)
146print(
"MCMC Actual confidence level: ", mcInt.GetActualConfidenceLevel())
152chainData = mcInt.GetChainAsDataSet()
154print(
"plotting the chain data - nentries = ", chainData.numEntries())
155chain = ROOT.RooStats.GetAsTTree(
"chainTreeData",
"chainTreeData", chainData)
156chain.SetMarkerStyle(6)
157chain.SetMarkerColor(ROOT.kRed)
159chain.Draw(
"s:ratioSigEff:ratioBkgEff",
"nll_MarkovChain_local_",
"box")
162parScanData = fc.GetPointsToScan()
163print(
"plotting the scanned points used in the frequentist construction - npoints = ", parScanData.numEntries())
165gr = ROOT.TGraph2D(parScanData.numEntries())
166for ievt
in range(parScanData.numEntries()):
167 evt = parScanData.get(ievt)
168 x = evt.getRealValue(
"ratioBkgEff")
169 y = evt.getRealValue(
"ratioSigEff")
170 z = evt.getRealValue(
"s")
171 gr.SetPoint(ievt, x, y, z)
180dataCanvas.SaveAs(
"rs101_limitexample.png")