91ROOT.gInterpreter.Declare(
93using namespace RooFit;
94using namespace RooStats;
96class BinCountTestStat : public TestStatistic {
98 BinCountTestStat(void) : fColumnName("tmp") {}
99 BinCountTestStat(string columnName) : fColumnName(columnName) {}
101 virtual Double_t Evaluate(RooAbsData &data, RooArgSet & /*nullPOI*/)
103 // This is the main method in the interface
104 Double_t value = 0.0;
105 for (int i = 0; i < data.numEntries(); i++) {
106 value += data.get(i)->getRealValue(fColumnName.c_str());
110 virtual const TString GetVarName() const { return fColumnName; }
116 ClassDef(BinCountTestStat, 1)
154w = ROOT.RooWorkspace(
"w")
159w.factory(
"Uniform::f(m[0,1])")
160w.factory(
"ExtendPdf::px(f,sum::splusb(s[0,0,100],b[100,0.1,300]))")
161w.factory(
"Poisson::py(y[100,0.1,500],prod::taub(tau[1.],b))")
162w.factory(
"PROD::model(px,py)")
163w.factory(
"Uniform::prior_b(b)")
168msglevel = ROOT.RooMsgService.instance().globalKillBelow()
177p_Bi = ROOT.RooStats.NumberCountingUtils.BinomialWithTauObsP(150, 100, 1)
178Z_Bi = ROOT.RooStats.NumberCountingUtils.BinomialWithTauObsZ(150, 100, 1)
179print(
"-----------------------------------------")
181print(f
"Z_Bi p-value (analytic): {p_Bi}")
182print(f
"Z_Bi significance (analytic) {Z_Bi}")
206w.defineSet(
"obs",
"m")
207w.defineSet(
"poi",
"s")
212data = w.pdf(
"px").generate(w.set(
"obs"), 150)
217b_model = ROOT.RooStats.ModelConfig(
"B_model", w)
218b_model.SetPdf(w.pdf(
"px"))
219b_model.SetObservables(w.set(
"obs"))
220b_model.SetParametersOfInterest(w.set(
"poi"))
221w.var(
"s").setVal(0.0)
222b_model.SetSnapshot(w.set(
"poi"))
225sb_model = ROOT.RooStats.ModelConfig(
"S+B_model", w)
226sb_model.SetPdf(w.pdf(
"px"))
227sb_model.SetObservables(w.set(
"obs"))
228sb_model.SetParametersOfInterest(w.set(
"poi"))
229w.var(
"s").setVal(50.0)
230sb_model.SetSnapshot(w.set(
"poi"))
240eventCount = ROOT.RooStats.NumEventsTestStat(w.pdf(
"px"))
263w.factory(
"Gaussian::gauss_prior(b,y, expr::sqrty('sqrt(y)',y))")
267w.factory(
"Lognormal::lognorm_prior(b,y, expr::kappa('1+1./sqrt(y)',y))")
285hc1 = ROOT.RooStats.HybridCalculator(data, sb_model, b_model)
286toymcs1 = ROOT.RooStats.ToyMCSampler()
287toymcs1 = hc1.GetTestStatSampler()
289toymcs1.SetTestStatistic(eventCount)
291hc1.SetToys(ntoys, ntoys // nToysRatio)
292hc1.ForcePriorNuisanceAlt(w.pdf(
"py"))
293hc1.ForcePriorNuisanceNull(w.pdf(
"py"))
306ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.ERROR)
308r1 = hc1.GetHypoTest()
309ROOT.RooMsgService.instance().setGlobalKillBelow(msglevel)
310print(
"-----------------------------------------")
319p1 = ROOT.RooStats.HypoTestPlot(r1, 30)
331slrts = ROOT.RooStats.SimpleLikelihoodRatioTestStat(b_model.GetPdf(), sb_model.GetPdf())
332slrts.SetNullParameters(b_model.GetSnapshot())
333slrts.SetAltParameters(sb_model.GetSnapshot())
336hc2 = ROOT.RooStats.HybridCalculator(data, sb_model, b_model)
337toymcs2 = ROOT.RooStats.ToyMCSampler()
338toymcs2 = hc2.GetTestStatSampler()
340toymcs2.SetTestStatistic(slrts)
342hc2.SetToys(ntoys, ntoys // nToysRatio)
343hc2.ForcePriorNuisanceAlt(w.pdf(
"py"))
344hc2.ForcePriorNuisanceNull(w.pdf(
"py"))
357ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.ERROR)
359r2 = hc2.GetHypoTest()
360print(
"-----------------------------------------")
367ROOT.RooMsgService.instance().setGlobalKillBelow(msglevel)
370p2 = ROOT.RooStats.HypoTestPlot(r2, 30)