90ROOT.gInterpreter.Declare(
92using namespace RooFit;
93using namespace RooStats;
95class BinCountTestStat : public TestStatistic {
97 BinCountTestStat(void) : fColumnName("tmp") {}
98 BinCountTestStat(string columnName) : fColumnName(columnName) {}
100 virtual Double_t Evaluate(RooAbsData &data, RooArgSet & /*nullPOI*/)
102 // This is the main method in the interface
103 Double_t value = 0.0;
104 for (int i = 0; i < data.numEntries(); i++) {
105 value += data.get(i)->getRealValue(fColumnName.c_str());
109 virtual const TString GetVarName() const { return fColumnName; }
115 ClassDef(BinCountTestStat, 1)
148w = ROOT.RooWorkspace(
"w")
153w.factory(
"Uniform::f(m[0,1])")
154w.factory(
"ExtendPdf::px(f,sum::splusb(s[0,0,100],b[100,0.1,300]))")
155w.factory(
"Poisson::py(y[100,0.1,500],prod::taub(tau[1.],b))")
156w.factory(
"PROD::model(px,py)")
157w.factory(
"Uniform::prior_b(b)")
162msglevel = ROOT.RooMsgService.instance().globalKillBelow()
171p_Bi = ROOT.RooStats.NumberCountingUtils.BinomialWithTauObsP(150, 100, 1)
172Z_Bi = ROOT.RooStats.NumberCountingUtils.BinomialWithTauObsZ(150, 100, 1)
173print(
"-----------------------------------------")
175print(f
"Z_Bi p-value (analytic): {p_Bi}")
176print(f
"Z_Bi significance (analytic) {Z_Bi}")
200w.defineSet(
"obs",
"m")
201w.defineSet(
"poi",
"s")
206data = w.pdf(
"px").generate(w.set(
"obs"), 150)
211b_model = ROOT.RooStats.ModelConfig(
"B_model", w)
212b_model.SetPdf(w.pdf(
"px"))
213b_model.SetObservables(w.set(
"obs"))
214b_model.SetParametersOfInterest(w.set(
"poi"))
215w.var(
"s").setVal(0.0)
216b_model.SetSnapshot(w.set(
"poi"))
219sb_model = ROOT.RooStats.ModelConfig(
"S+B_model", w)
220sb_model.SetPdf(w.pdf(
"px"))
221sb_model.SetObservables(w.set(
"obs"))
222sb_model.SetParametersOfInterest(w.set(
"poi"))
223w.var(
"s").setVal(50.0)
224sb_model.SetSnapshot(w.set(
"poi"))
234eventCount = ROOT.RooStats.NumEventsTestStat(w.pdf(
"px"))
257w.factory(
"Gaussian::gauss_prior(b,y, expr::sqrty('sqrt(y)',y))")
261w.factory(
"Lognormal::lognorm_prior(b,y, expr::kappa('1+1./sqrt(y)',y))")
279hc1 = ROOT.RooStats.HybridCalculator(data, sb_model, b_model)
280toymcs1 = ROOT.RooStats.ToyMCSampler()
281toymcs1 = hc1.GetTestStatSampler()
283toymcs1.SetTestStatistic(eventCount)
285hc1.SetToys(ntoys, ntoys // nToysRatio)
286hc1.ForcePriorNuisanceAlt(w.pdf(
"py"))
287hc1.ForcePriorNuisanceNull(w.pdf(
"py"))
300ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.ERROR)
302r1 = hc1.GetHypoTest()
303ROOT.RooMsgService.instance().setGlobalKillBelow(msglevel)
304print(
"-----------------------------------------")
313p1 = ROOT.RooStats.HypoTestPlot(r1, 30)
325slrts = ROOT.RooStats.SimpleLikelihoodRatioTestStat(b_model.GetPdf(), sb_model.GetPdf())
326slrts.SetNullParameters(b_model.GetSnapshot())
327slrts.SetAltParameters(sb_model.GetSnapshot())
330hc2 = ROOT.RooStats.HybridCalculator(data, sb_model, b_model)
331toymcs2 = ROOT.RooStats.ToyMCSampler()
332toymcs2 = hc2.GetTestStatSampler()
334toymcs2.SetTestStatistic(slrts)
336hc2.SetToys(ntoys, ntoys // nToysRatio)
337hc2.ForcePriorNuisanceAlt(w.pdf(
"py"))
338hc2.ForcePriorNuisanceNull(w.pdf(
"py"))
351ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.ERROR)
353r2 = hc2.GetHypoTest()
354print(
"-----------------------------------------")
361ROOT.RooMsgService.instance().setGlobalKillBelow(msglevel)
364p2 = ROOT.RooStats.HypoTestPlot(r2, 30)