33 def __init__(self, **kargs):
34 self.__dict__.
update(kargs)
37BayesianNumericalOptions = Struct(
53optBayes = BayesianNumericalOptions
57 infile="", workspaceName="combined", modelConfigName="ModelConfig", dataName="obsData"
64 confLevel = optBayes.confLevel
65 integrationType = ROOT.TString(optBayes.integrationType)
66 nToys = optBayes.nToys
67 scanPosterior = optBayes.scanPosterior
68 plotPosterior = optBayes.plotPosterior
69 nScanPoints = optBayes.nScanPoints
70 intervalType = optBayes.intervalType
71 maxPOI = optBayes.maxPOI
72 nSigmaNuisance = optBayes.nSigmaNuisance
80 filename =
"results/example_combined_GaussExample_model.root"
81 fileExist =
not ROOT.gSystem.AccessPathName(filename)
86 ROOT.gROOT.ProcessLine(
".! prepareHistFactory .")
87 ROOT.gROOT.ProcessLine(
".! hist2workspace config/example.xml")
88 print(f
"\n\n---------------------")
89 print(f
"Done creating example input")
90 print(f
"---------------------\n\n")
96 file = ROOT.TFile.Open(filename)
100 print(f
"StandardRooStatsDemoMacro: Input file {filename} is not found")
108 w = file.Get(workspaceName)
110 print(f
"workspace not found")
114 mc = w.obj(modelConfigName)
117 data = w.data(dataName)
120 if not data
or not mc:
122 print(f
"data or ModelConfig was not found")
134 prior = ROOT.RooUniform(
"prior",
"", mc.GetParametersOfInterest())
136 mc.SetPriorPdf(w.pdf(
"prior"))
140 if nSigmaNuisance > 0:
147 Minimizer=MinimizerOptions.DefaultMinimizerType(),
149 PrintLevel=MinimizerOptions.DefaultPrintLevel() - 1,
154 nuisPar =
RooArgList(mc.GetNuisanceParameters())
155 for i
in range(nuisPar.getSize()):
158 v.setMin(
TMath.Max(v.getMin(), v.getVal() - nSigmaNuisance * v.getError()))
159 v.setMax(
TMath.Min(v.getMax(), v.getVal() + nSigmaNuisance * v.getError()))
160 print(f
"setting interval for nuisance {v.GetName()} : [ {v.getMin()} , {v.getMax()} ] \n")
162 bayesianCalc = ROOT.RooStats.BayesianCalculator(data, mc)
163 bayesianCalc.SetConfidenceLevel(confLevel)
167 if intervalType == 0:
168 bayesianCalc.SetShortestInterval()
169 if intervalType == 1:
170 bayesianCalc.SetLeftSideTailFraction(0.5)
171 if intervalType == 2:
172 bayesianCalc.SetLeftSideTailFraction(0.0)
174 if not integrationType.IsNull():
175 bayesianCalc.SetIntegrationType(integrationType)
176 bayesianCalc.SetNumIters(nToys)
179 if integrationType.Contains(
"TOYMC"):
181 print(f
"using TOYMC integration: make nuisance pdf from the model ")
183 bayesianCalc.ForceNuisancePdf(nuisPdf)
188 bayesianCalc.SetScanOfPosterior(nScanPoints)
190 poi = mc.GetParametersOfInterest().first()
191 if maxPOI != -999
and maxPOI > poi.getMin():
194 interval = bayesianCalc.GetInterval()
198 f
"\n>>>> RESULT : {confLevel*100}% interval on {poi.GetName()} is : ["
199 + f
"{interval.LowerLimit():f}, {interval.UpperLimit():f} ] "
203 if not plotPosterior:
212 ROOT.RooAbsReal.setEvalErrorLoggingMode(
"Ignore")
216 print(
"Standard Bayesian Numerical Algorithm was performed in :")
217 print(
"{:2f} seconds. ".
format(t1 - t0))
218 print(f
"\nDrawing plot of posterior function.....")
221 bayesianCalc.SetScanOfPosterior(nScanPoints)
223 plot = bayesianCalc.GetPosteriorPlot()
227 c1.SaveAs(
"StandardBayesianNumericalDemo.png")
228 global gbayesianCalc, gplot
229 gbayesianCalc = bayesianCalc
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
extract constraint terms from pdf
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.