44def rs_numberCountingCombination(flag=1):
47 rs_numberCountingCombination_expected()
49 rs_numberCountingCombination_observed()
51 rs_numberCountingCombination_observedWithTau()
55def rs_numberCountingCombination_expected():
71 s = array.array(
"d", [20.0, 10.0])
72 b = array.array(
"d", [100.0, 100.0])
73 db = array.array(
"d", [0.0100, 0.0100])
81 f = ROOT.RooStats.NumberCountingPdfFactory()
82 wspace = ROOT.RooWorkspace()
91 f.AddModel(s, 2, wspace,
"TopLevelPdf",
"masterSignal")
96 f.AddExpData(s, b, db, 2, wspace,
"ExpectedNumberCountingData")
106 mu = wspace.var(
"masterSignal")
107 poi = ROOT.RooArgSet(mu)
108 nullParams = ROOT.RooArgSet(
"nullParams")
109 nullParams.addClone(mu)
111 nullParams.setRealValue(
"masterSignal", 0)
115 plc = ROOT.RooStats.ProfileLikelihoodCalculator(
116 wspace[
"ExpectedNumberCountingData"], wspace[
"TopLevelPdf"], poi, 0.05, nullParams
120 htr = plc.GetHypoTest()
122 print(
"-------------------------------------------------")
123 print(
"The p-value for the null is ", htr.NullPValue())
124 print(
"Corresponding to a significance of ", htr.Significance())
125 print(
"-------------------------------------------------\n\n")
138 paramsOfInterest = nullParams
139 plc.SetParameters(paramsOfInterest)
140 lrint = plc.GetInterval()
141 lrint.SetConfidenceLevel(0.95)
146 lower = lrint.LowerLimit(mu)
147 upper = lrint.UpperLimit(mu)
149 c1 = ROOT.TCanvas(
"myc1",
"myc1")
150 lrPlot = ROOT.RooStats.LikelihoodIntervalPlot(lrint)
151 lrPlot.SetMaximum(3.0)
155 c1.SaveAs(
"rs_numberCountingCombination.png")
158 print(
"signal = ", lower)
159 print(
"signal = ", upper)
166 paramsOfInterest.setRealValue(
"masterSignal", 0.0)
167 print(
"-------------------------------------------------")
168 print(
"Consider this parameter point:")
169 paramsOfInterest.first().Print()
170 if lrint.IsInInterval(paramsOfInterest):
171 print(
"It IS in the interval.")
173 print(
"It is NOT in the interval.")
174 print(
"-------------------------------------------------\n\n")
177 paramsOfInterest.setRealValue(
"masterSignal", 2.0)
178 print(
"-------------------------------------------------")
179 print(
"Consider this parameter point:")
180 paramsOfInterest.first().Print()
181 if lrint.IsInInterval(paramsOfInterest):
182 print(
"It IS in the interval.")
184 print(
"It is NOT in the interval.")
185 print(
"-------------------------------------------------\n\n")
195 # Here's an example of what is in the workspace
197 RooWorkspace(NumberCountingWS) Number Counting WS contents
201 (x_0,masterSignal,expected_s_0,b_0,y_0,tau_0,x_1,expected_s_1,b_1,y_1,tau_1)
205 RooProdPdf.joint[ pdfs=(sigRegion_0,sideband_0,sigRegion_1,sideband_1) ] = 2.20148e-08
206 RooPoisson.sigRegion_0[ x=x_0 mean=splusb_0 ] = 0.036393
207 RooPoisson.sideband_0[ x=y_0 mean=bTau_0 ] = 0.00398939
208 RooPoisson.sigRegion_1[ x=x_1 mean=splusb_1 ] = 0.0380088
209 RooPoisson.sideband_1[ x=y_1 mean=bTau_1 ] = 0.00398939
213 RooAddition.splusb_0[ set1=(s_0,b_0) set2=() ] = 120
214 RooProduct.s_0[ compRSet=(masterSignal,expected_s_0) compCSet=() ] = 20
215 RooProduct.bTau_0[ compRSet=(b_0,tau_0) compCSet=() ] = 10000
216 RooAddition.splusb_1[ set1=(s_1,b_1) set2=() ] = 110
217 RooProduct.s_1[ compRSet=(masterSignal,expected_s_1) compCSet=() ] = 10
218 RooProduct.bTau_1[ compRSet=(b_1,tau_1) compCSet=() ] = 10000
222 RooDataSet.ExpectedNumberCountingData(x_0,y_0,x_1,y_1)
224 embedded pre-calculated expensive components
225 -------------------------------------------
229def rs_numberCountingCombination_observed():
245 s_c = (ctypes.c_double * len(s))(*s)
253 f = ROOT.RooStats.NumberCountingPdfFactory()
254 wspace = ROOT.RooWorkspace()
255 f.AddModel(s_c, 2, wspace,
"TopLevelPdf",
"masterSignal")
259 mainMeas = [123.0, 117.0]
260 mainMeas_c = (ctypes.c_double * len(mainMeas))(*mainMeas)
261 bkgMeas = [111.23, 98.76]
262 bkgMeas_c = (ctypes.c_double * len(bkgMeas))(*bkgMeas)
263 dbMeas = [0.011, 0.0095]
264 dbMeas_c = (ctypes.c_double * len(bkgMeas))(*dbMeas)
265 f.AddData(mainMeas_c, bkgMeas_c, dbMeas_c, 2, wspace,
"ObservedNumberCountingData")
275 mu = wspace.var(
"masterSignal")
276 poi = ROOT.RooArgSet(mu)
277 nullParams = ROOT.RooArgSet(
"nullParams")
278 nullParams.addClone(mu)
280 nullParams.setRealValue(
"masterSignal", 0)
284 plc = ROOT.RooStats.ProfileLikelihoodCalculator(
285 wspace.data(
"ObservedNumberCountingData"), wspace.pdf(
"TopLevelPdf"), poi, 0.05, nullParams
288 wspace.var(
"tau_0").Print()
289 wspace.var(
"tau_1").Print()
292 htr = plc.GetHypoTest()
293 print(
"-------------------------------------------------")
294 print(
"The p-value for the null is ", htr.NullPValue())
295 print(
"Corresponding to a significance of ", htr.Significance())
296 print(
"-------------------------------------------------\n\n")
299 # observed case should return:
300 -------------------------------------------------
301 The p-value for the null is 0.0351669
302 Corresponding to a significance of 1.80975
303 -------------------------------------------------
311 paramsOfInterest = nullParams
312 plc.SetParameters(paramsOfInterest)
313 lrint = plc.GetInterval()
314 lrint.SetConfidenceLevel(0.95)
317 print(
"signal = ", lrint.LowerLimit(mu))
318 print(
"signal = ", lrint.UpperLimit(mu))
327def rs_numberCountingCombination_observedWithTau():
343 s_c = (ctypes.c_double * 2)(*s)
351 f = ROOT.RooStats.NumberCountingPdfFactory()
352 wspace = ROOT.RooWorkspace()
353 f.AddModel(s_c, 2, wspace,
"TopLevelPdf",
"masterSignal")
357 mainMeas = [123.0, 117.0]
358 sideband = [11123.0, 9876.0]
360 mainMeas_c = (ctypes.c_double * 2)(*mainMeas)
361 sideband_c = (ctypes.c_double * 2)(*sideband)
362 tau_c = (ctypes.c_double * 2)(*tau)
363 f.AddDataWithSideband(mainMeas_c, sideband_c, tau_c, 2, wspace,
"ObservedNumberCountingDataWithSideband")
373 mu = wspace.var(
"masterSignal")
374 poi = ROOT.RooArgSet(mu)
375 nullParams = ROOT.RooArgSet(
"nullParams")
376 nullParams.addClone(mu)
378 nullParams.setRealValue(
"masterSignal", 0)
382 plc = ROOT.RooStats.ProfileLikelihoodCalculator(
383 wspace.data(
"ObservedNumberCountingDataWithSideband"), wspace.pdf(
"TopLevelPdf"), poi, 0.05, nullParams
387 htr = plc.GetHypoTest()
388 print(
"-------------------------------------------------")
389 print(
"The p-value for the null is ", htr.NullPValue())
390 print(
"Corresponding to a significance of ", htr.Significance())
391 print(
"-------------------------------------------------\n\n")
394 # observed case should return:
395 -------------------------------------------------
396 The p-value for the null is 0.0352035
397 Corresponding to a significance of 1.80928
398 -------------------------------------------------
406 paramsOfInterest = nullParams
407 plc.SetParameters(paramsOfInterest)
408 lrint = plc.GetInterval()
409 lrint.SetConfidenceLevel(0.95)
412 print(
"signal = ", lrint.LowerLimit(mu))
413 print(
"signal = ", lrint.UpperLimit(mu))
422rs_numberCountingCombination(flag=1)