A hypothesis testing example based on number counting with background uncertainty.
NOTE: This example is like HybridInstructional, but the model is more clearly generalizable to an analysis with shapes. There is a lot of flexibility for how one models a problem in RooFit/RooStats. Models come in a few common forms:
Here we convert the number counting form into the standard form by introducing a dummy discriminating variable m with a uniform distribution.
The basic setup here is that a main measurement has observed x events with an expectation of s+b. One can choose an ad hoc prior for the uncertainty on b, or try to base it on an auxiliary measurement. In this case, the auxiliary measurement (aka control measurement, sideband) is another counting experiment with measurement y and expectation tau*b. With an 'original prior' on b, called \( \eta(b) \) then one can obtain a posterior from the auxiliary measurement \( \pi(b) = \eta(b) * Pois(y|tau*b) \). This is a principled choice for a prior on b in the main measurement of x, which can then be treated in a hybrid Bayesian/Frequentist way. Additionally, one can try to treat the two measurements simultaneously, which is detailed in Part 6 of the tutorial.
This tutorial is related to the FourBin.C tutorial in the modeling, but focuses on hypothesis testing instead of interval estimation.
More background on this 'prototype problem' can be found in the following papers:
-----------------------------------------
Part 3
Z_Bi p-value (analytic): 0.00094165
Z_Bi significance (analytic): 3.10804
Real time 0:00:00, CP time 0.050
[#0] WARNING:Eval -- RooStatsUtils::MakeNuisancePdf - no constraints found on nuisance parameters in the input model
[#0] WARNING:Eval -- RooStatsUtils::MakeNuisancePdf - no constraints found on nuisance parameters in the input model
-----------------------------------------
Part 4
Results HypoTestCalculator_result:
- Null p-value = 0.001 +/- 0.000408044
- Significance = 3.09023 +/- 0.121186 sigma
- Number of Alt toys: 300
- Number of Null toys: 6000
- Test statistic evaluated on data: 150
- CL_b: 0.001 +/- 0.000408044
- CL_s+b: 0.573333 +/- 0.0285553
- CL_s: 573.333 +/- 235.682
Real time 0:00:11, CP time 11.690
public:
BinCountTestStat(void) : fColumnName("tmp") {}
BinCountTestStat(string columnName) : fColumnName(columnName) {}
virtual Double_t Evaluate(RooAbsData &data, RooArgSet & )
{
for (int i = 0; i < data.numEntries(); i++) {
value += data.get(i)->getRealValue(fColumnName.c_str());
}
return value;
}
virtual const TString GetVarName() const { return fColumnName; }
private:
string fColumnName;
protected:
};
void HybridStandardForm(int ntoys = 6000)
{
double nToysRatio = 20;
w->factory("Uniform::f(m[0,1])");
w->factory("ExtendPdf::px(f,sum::splusb(s[0,0,100],b[100,0.1,300]))");
w->factory("Poisson::py(y[100,0.1,500],prod::taub(tau[1.],b))");
w->factory("PROD::model(px,py)");
w->factory("Uniform::prior_b(b)");
cout << "-----------------------------------------" << endl;
cout << "Part 3" << endl;
std::cout << "Z_Bi p-value (analytic): " << p_Bi << std::endl;
std::cout << "Z_Bi significance (analytic): " << Z_Bi << std::endl;
w->defineSet("obs", "m");
w->defineSet("poi", "s");
b_model.SetPdf(*w->pdf("px"));
b_model.SetObservables(*w->set("obs"));
b_model.SetParametersOfInterest(*w->set("poi"));
w->var("s")->setVal(0.0);
b_model.SetSnapshot(*w->set("poi"));
sb_model.SetPdf(*w->pdf("px"));
sb_model.SetObservables(*w->set("obs"));
sb_model.SetParametersOfInterest(*w->set("poi"));
w->var("s")->setVal(50.0);
sb_model.SetSnapshot(*w->set("poi"));
w->factory("Gaussian::gauss_prior(b,y, expr::sqrty('sqrt(y)',y))");
w->factory("Lognormal::lognorm_prior(b,y, expr::kappa('1+1./sqrt(y)',y))");
hc1.SetToys(ntoys, ntoys / nToysRatio);
hc1.ForcePriorNuisanceAlt(*w->pdf("py"));
hc1.ForcePriorNuisanceNull(*w->pdf("py"));
cout << "-----------------------------------------" << endl;
cout << "Part 4" << endl;
return;
slrts.SetNullParameters(*b_model.GetSnapshot());
slrts.SetAltParameters(*sb_model.GetSnapshot());
hc2.SetToys(ntoys, ntoys / nToysRatio);
hc2.ForcePriorNuisanceAlt(*w->pdf("py"));
hc2.ForcePriorNuisanceNull(*w->pdf("py"));
cout << "-----------------------------------------" << endl;
cout << "Part 5" << endl;
return;
}
double Double_t
Double 8 bytes.
#define ClassDef(name, id)
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Same purpose as HybridCalculatorOriginal, but different implementation.
This class provides the plots for the result of a study performed with any of the HypoTestCalculatorG...
HypoTestResult is a base class for results from hypothesis tests.
void Print(const Option_t *="") const override
Print out some information about the results Note: use Alt/Null labels for the hypotheses here as the...
NumEventsTestStat is a simple implementation of the TestStatistic interface used for simple number co...
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
TestStatistic class that returns -log(L[null] / L[alt]) where L is the likelihood.
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
ToyMCSampler is an implementation of the TestStatSampler interface.
virtual void SetTestStatistic(TestStatistic *testStatistic, unsigned int i)
Set the TestStatistic (want the argument to be a function of the data & parameter points.
Persistable container for RooFit projects.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void Print(Option_t *option="") const override
Print the real and cpu time passed between the start and stop events.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
RooStats::ModelConfig ModelConfig
double BinomialWithTauObsZ(double nObs, double bExp, double tau)
See BinomialWithTauObsP.
double BinomialWithTauObsP(double nObs, double bExp, double tau)
P-value for s=nullptr in a ratio of Poisson means.
Namespace for the RooStats classes.