35 def __init__(self, **entries):
36 self.__dict__.
update(entries)
39BayesianMCMCOptions = Struct(
48optMCMC = BayesianMCMCOptions
59 filename =
"results/example_combined_GaussExample_model.root"
60 fileExist = ROOT.gSystem.AccessPathName(filename)
64 print(f
"will run standard hist2workspace example")
65 ROOT.gROOT.ProcessLine(
".! prepareHistFactory .")
66 ROOT.gROOT.ProcessLine(
".! hist2workspace config/example.xml")
67 print(f
"\n\n---------------------")
68 print(f
"Done creating example input")
69 print(f
"---------------------\n\n")
73 file = ROOT.TFile.Open(filename)
77 print(f
"StandardRooStatsDemoMacro: Input file {filename} is not found")
86 w = file.Get(workspaceName)
88 print(f
"workspace not found")
92 mc = w.obj(modelConfigName)
95 data = w.data(dataName)
98 if not data
or not mc:
100 print(f
"data or ModelConfig was not found")
107 # this one is based on the covariance matrix of fit
108 fit = mc.GetPdf().fitTo(data,Save())
110 ph.SetVariables((RooArgSet&)fit.floatParsFinal())
111 ph.SetCovMatrix(fit.covarianceMatrix())
112 ph.SetUpdateProposalParameters(True) # auto-create mean vars and add mappings
114 pf = ph.GetProposalFunction()
118 sp = ROOT.RooStats.SequentialProposal(0.1)
124 mcmc = ROOT.RooStats.MCMCCalculator(data, mc)
125 mcmc.SetConfidenceLevel(optMCMC.confLevel)
127 mcmc.SetProposalFunction(sp)
128 mcmc.SetNumIters(optMCMC.numIters)
129 mcmc.SetNumBurnInSteps(optMCMC.numBurnInSteps)
132 (optMCMC.intervalType == 0)
133 mcmc.SetIntervalType(ROOT.RooStats.MCMCInterval.kShortest)
134 (optMCMC.intervalType == 1)
135 mcmc.SetLeftSideTailFraction(0.5)
136 (optMCMC.intervalType == 2)
137 mcmc.SetLeftSideTailFraction(0.0)
139 firstPOI = mc.GetParametersOfInterest().first()
140 if optMCMC.minPOI != -999:
141 firstPOI.setMin(optMCMC.minPOI)
142 if optMCMC.maxPOI != -999:
143 firstPOI.setMax(optMCMC.maxPOI)
145 interval = mcmc.GetInterval()
148 c1 = ROOT.TCanvas(
"IntervalPlot")
149 plot = ROOT.RooStats.MCMCIntervalPlot(interval)
152 c2 = ROOT.TCanvas(
"extraPlots")
153 list = mc.GetNuisanceParameters()
154 if list.getSize() > 1:
156 ny = ROOT.TMath.CeilNint(ROOT.sqrt(n))
157 nx = ROOT.TMath.CeilNint(ROOT.double(n) / ny)
164 for nuis
in mc.GetNuisanceParameters():
167 plot.DrawChainScatter(firstPOI, nuis)
170 print(
"\n>>>> RESULT : ", optMCMC.confLevel * 100,
"interval on ", firstPOI.GetName(),
"is : [")
171 print(interval.LowerLimit(firstPOI), interval.UpperLimit(firstPOI))
175 c1.SaveAs(
"StandardBayesianMCMCDemo.1.IntervalPlot.png")
176 c2.SaveAs(
"StandardBayesianMCMCDemo.2.extraPlots.png")
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)