43def StandardHistFactoryPlotsWithCategories(
44 infile="", workspaceName="combined", modelConfigName="ModelConfig", dataName="obsData"
56 filename =
"results/example_combined_GaussExample_model.root"
57 fileExist =
not ROOT.gSystem.AccessPathName(filename)
61 print(f
"will run standard hist2workspace example")
62 ROOT.gROOT.ProcessLine(
".! prepareHistFactory .")
63 ROOT.gROOT.ProcessLine(
".! hist2workspace config/example.xml")
64 print(f
"\n\n---------------------")
65 print(f
"Done creating example input")
66 print(f
"---------------------\n\n")
72 file = ROOT.TFile.Open(filename)
76 print(f
"StandardRooStatsDemoMacro: Input file {filename} is not found")
84 w = file.Get(workspaceName)
86 print(f
"workspace not found")
90 mc = w.obj(modelConfigName)
93 data = w.data(dataName)
96 if not data
or not mc:
98 print(f
"data or ModelConfig was not found")
104 obs = mc.GetObservables().first()
107 firstPOI = mc.GetParametersOfInterest().first()
109 firstPOI.setVal(muVal)
112 mc.GetPdf().fitTo(data)
116 mc.GetNuisanceParameters().Print(
"v")
118 print(f
" check expectedData by category")
121 if str(mc.GetPdf().ClassName()) ==
"RooSimultaneous":
122 print(f
"Is a simultaneous PDF")
125 print(f
"Is not a simultaneous PDF")
128 channelCat = simPdf.indexCat()
129 catName = channelCat.begin().first
130 pdftmp = (mc.GetPdf()).getPdf(str(catName))
131 obstmppdftmp.getObservables(mc.GetObservables())
134 print(
"{0}=={0}::{1}".format(channelCat.GetName(), catName))
135 print(catName,
" ", channelCat.getLabel())
139 Cut=
"{0}=={0}::{1}".format(channelCat.GetName(), catName),
143 normCount = data.sumEntries(
"{0}=={0}::{1}".format(channelCat.GetName(), catName))
145 pdftmp.plotOn(frame, Normalization(normCount, ROOT.RooAbsReal.NumEvent), LineWidth=2)
147 print(
"expected events = ", mc.GetPdf().expectedEvents(data.get()))
153 for var
in mc.GetNuisanceParameters():
155 frame.SetYTitle(var.GetName())
156 data.plotOn(frame, MarkerSize(1))
158 mc.GetPdf().plotOn(frame, LineWidth(1))
159 var.setVal(value + var.getError());
160 mc.GetPdf().plotOn(frame, LineColor(kRed), LineStyle(kDashed), LineWidth(1))
161 var.setVal(value - var.getError());
162 mc.GetPdf().plotOn(frame, LineColor(kGreen), LineStyle(kDashed), LineWidth(1))
163 frameList.append(frame)
167 channelCat = simPdf.indexCat()
168 for tt
in channelCat:
170 if nPlots == nPlotsMax:
175 print(
"on type ", catName,
" ")
177 pdftmp = simPdf.getPdf(str(catName))
180 obstmp = pdftmp.getObservables(mc.GetObservables())
185 for var
in mc.GetNuisanceParameters():
187 if nPlots >= nPlotsMax:
190 c2 = ROOT.TCanvas(
"c2")
192 frame.SetName(f
"frame{nPlots}")
193 frame.SetYTitle(var.GetName())
195 cut =
"{0}=={0}::{1}".format(channelCat.GetName(), catName)
197 print(catName,
" ", channelCat.getLabel())
205 normCount = data.sumEntries(cut)
229 normCount = pdftmp.expectedEvents(obstmp)
230 pdftmp.plotOn(frame, ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent), LineWidth=2)
232 var.setVal(value + nSigmaToVary * var.getError())
237 normCount = pdftmp.expectedEvents(obstmp)
240 ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent),
246 var.setVal(value - nSigmaToVary * var.getError())
251 normCount = pdftmp.expectedEvents(obstmp)
254 ROOT.RooFit.Normalization(normCount, ROOT.RooAbsReal.NumEvent),
263 frameList.append(frame)
271 c2.SaveAs(f
"StandardHistFactoryPlotsWithCategories.1.{catName}_{obs.GetName()}_{var.GetName()}.png")
277 c1 = ROOT.TCanvas(
"c1",
"ProfileInspectorDemo", 800, 200)
278 nFrames = len(frameList)
280 nx =
int(sqrt(nFrames))
281 ny = ROOT.TMath.CeilNint(nFrames / nx)
282 nx = ROOT.TMath.CeilNint(sqrt(nFrames))
286 for i
in range(nFrames):
291 c1.SaveAs(
"StandardHistFactoryPlotsWithCategories.2.pdf")
296StandardHistFactoryPlotsWithCategories(
297 infile=
"", workspaceName=
"combined", modelConfigName=
"ModelConfig", dataName=
"obsData"