27def StandardFrequentistDiscovery(
29 workspaceName="channel1",
30 modelConfigNameSB="ModelConfig",
33 poiValueForBackground=0.0,
34 poiValueForSignal=1.0,
50 filename =
"results/example_channel1_GammaExample_model.root"
51 fileExist =
not ROOT.gSystem.AccessPathName(filename)
55 print(f
"will run standard hist2workspace example")
56 ROOT.gROOT.ProcessLine(
".! prepareHistFactory .")
57 ROOT.gROOT.ProcessLine(
".! hist2workspace config/example.xml")
58 print(f
"\n\n---------------------")
59 print(f
"Done creating example input")
60 print(f
"---------------------\n\n")
66 file = ROOT.TFile.Open(filename)
70 print(f
"StandardRooStatsDemoMacro: Input file {filename} is not found")
77 mn_t = ROOT.TStopwatch()
81 w = file.Get(workspaceName)
83 print(f
"workspace not found")
87 mc = w[modelConfigNameSB]
93 if not data
or not mc:
95 print(f
"data or ModelConfig was not found")
98 firstPOI = mc.GetParametersOfInterest().first()
99 firstPOI.setVal(poiValueForSignal)
100 mc.SetSnapshot(mc.GetParametersOfInterest())
102 mcNull = mc.Clone(
"ModelConfigNull")
103 firstPOI.setVal(poiValueForBackground)
104 mcNull.SetSnapshot(mcNull.GetParametersOfInterest().snapshot())
109 plts = ROOT.RooStats.ProfileLikelihoodTestStat(mc.GetPdf())
110 plts.SetOneSidedDiscovery(
True)
111 plts.SetVarName(
"q_0/2")
115 toymcs = ROOT.RooStats.ToyMCSampler(plts, 50)
124 if not mc.GetPdf().canBeExtended():
125 if data.numEntries() == 1:
126 toymcs.SetNEventsPerToy(1)
128 print(f
"Not sure what to do about this model")
131 freqCalc = ROOT.RooStats.FrequentistCalculator(data, mc, mcNull, toymcs)
132 freqCalc.SetToys(toys, toys)
135 freqCalcResult = freqCalc.GetHypoTest()
136 freqCalcResult.GetNullDistribution().SetTitle(
"b only")
137 freqCalcResult.GetAltDistribution().SetTitle(
"s+b")
138 freqCalcResult.Print()
139 pvalue = freqCalcResult.NullPValue()
143 print(f
"total CPU time: ", mn_t.CpuTime())
144 print(f
"total real time: ", mn_t.RealTime())
148 plot = ROOT.RooStats.HypoTestPlot(freqCalcResult, 100, -0.49, 9.51)
149 plot.SetLogYaxis(
True)
153 c1.SaveAs(
"StandardFrequentistDiscovery.1.png")
157 c2 = ROOT.TCanvas(
"myc2",
"myc2")
161 ROOT.gInterpreter.Declare(
162 f
"""TF1 *g = new TF1("g", TString::Format("{scale_ctte}*ROOT::Math::chisquared_pdf(2*x,%d,0)", {nPOI}), 0, 9);"""
165 g.SetLineColor(ROOT.kBlack)
167 plot2 = ROOT.RooStats.HypoTestPlot(freqCalcResult, 100, -0.49, 9.51)
168 tmptitle = f
"#chi^{{2}}(2x,{nPOI})"
169 plot2.AddTF1(g, tmptitle,
"SAME")
170 plot2.SetLogYaxis(
True)
175 c2.SaveAs(
"StandardFrequentistDiscovery.2.png")
180StandardFrequentistDiscovery(
182 workspaceName=
"channel1",
183 modelConfigNameSB=
"ModelConfig",
186 poiValueForBackground=0.0,
187 poiValueForSignal=1.0,