14Create a HistFactory measurement from python
17InputFile =
"./data/example.root"
18if ROOT.gSystem.AccessPathName(InputFile):
19 ROOT.Info(
"example.py", InputFile +
" does not exist")
20 ROOT.gROOT.ProcessLine(
".! prepareHistFactory .")
21 if ROOT.gSystem.AccessPathName(InputFile):
22 ROOT.Info(
"example.py", InputFile +
" still does not exist. \n EXIT")
26meas = ROOT.RooStats.HistFactory.Measurement(
"meas",
"meas")
28meas.SetOutputFilePrefix(
"./results/example_UsingPy")
29meas.SetPOI(
"SigXsecOverSM")
30meas.AddConstantParam(
"Lumi")
31meas.AddConstantParam(
"alpha_syst1")
34meas.SetLumiRelErr(0.10)
38chan = ROOT.RooStats.HistFactory.Channel(
"channel1")
39chan.SetData(
"data", InputFile)
40chan.SetStatErrorConfig(0.05,
"Poisson")
45signal = ROOT.RooStats.HistFactory.Sample(
"signal",
"signal", InputFile)
46signal.AddOverallSys(
"syst1", 0.95, 1.05)
47signal.AddNormFactor(
"SigXsecOverSM", 1, 0, 3)
52background1 = ROOT.RooStats.HistFactory.Sample(
"background1",
"background1", InputFile)
53background1.ActivateStatError(
"background1_statUncert", InputFile)
54background1.AddOverallSys(
"syst2", 0.95, 1.05)
55chan.AddSample(background1)
59background2 = ROOT.RooStats.HistFactory.Sample(
"background2",
"background2", InputFile)
60background2.ActivateStatError()
61background2.AddOverallSys(
"syst3", 0.95, 1.05)
62chan.AddSample(background2)
72meas.CollectHistograms()
79ws = ROOT.RooStats.HistFactory.MakeModelAndMeasurementFast(meas)
82modelConfig = ws[
"ModelConfig"]
85pdf = modelConfig.GetPdf()
89 ws[
"obsData"], Save=
True, PrintLevel=-1, GlobalObservables=modelConfig.GetGlobalObservables(), Minos=
True
93poi = modelConfig.GetParametersOfInterest().first()
95nll = pdf.createNLL(ws[
"obsData"])
96profile = nll.createProfile(poi)
102frame.GetYaxis().SetTitle(
"-log likelihood")
103frame.GetXaxis().SetTitle(poi.GetTitle())
105profileLikelihoodCanvas = ROOT.TCanvas(
"combined",
"", 800, 600)
110line = ROOT.TLine(xmin, 0.5, xmax, 0.5)
111line.SetLineColor(ROOT.kGreen)
112line90 = ROOT.TLine(xmin, 2.71 / 2, xmax, 2.71 / 2)
113line90.SetLineColor(ROOT.kGreen)
114line95 = ROOT.TLine(xmin, 3.84 / 2, xmax, 3.84 / 2)
115line95.SetLineColor(ROOT.kGreen)
118frame.addObject(line90)
119frame.addObject(line95)
121nll.plotOn(frame, ShiftToZero=
True, LineColor=
"r", LineStyle=
"--")