This simple script plots the sampling distribution of the profile likelihood ratio test statistic based on the input Model File. To do this one needs to specify the value of the parameter of interest that will be used for evaluating the test statistic and the value of the parameters used for generating the toy data. In this case, it uses the upper-limit estimated from the ProfileLikleihoodCalculator, which assumes the asymptotic chi-square distribution for -2 log profile likelihood ratio. Thus, the script is handy for checking to see if the asymptotic approximations are valid. To aid, that comparison, the script overlays a chi-square distribution as well. The most common parameter of interest is a parameter proportional to the signal rate, and often that has a lower-limit of 0, which breaks the standard chi-square distribution. Thus the script allows the parameter to be negative so that the overlay chi-square is the correct asymptotic distribution.
=== Using the following for ModelConfig ===
Observables: RooArgSet:: = (obs_x_channel1,channelCat)
Parameters of Interest: RooArgSet:: = (SigXsecOverSM)
Nuisance Parameters: RooArgSet:: = (alpha_syst2,alpha_syst3,gamma_stat_channel1_bin_0,gamma_stat_channel1_bin_1)
Global Observables: RooArgSet:: = (nominalLumi,nom_alpha_syst1,nom_alpha_syst2,nom_alpha_syst3,nom_gamma_stat_channel1_bin_0,nom_gamma_stat_channel1_bin_1)
PDF: RooSimultaneous::simPdf[ indexCat=channelCat channel1=model_channel1 ] = 0.190787
[#1] INFO:InputArguments -- The deprecated RooFit::CloneData(1) option passed to createNLL() is ignored.
[#1] INFO:Minimization -- p.d.f. provides expected number of events, including extended term in likelihood.
[#1] INFO:Minimization -- Including the following constraint terms in minimization: (alpha_syst2Constraint,alpha_syst3Constraint,gamma_stat_channel1_bin_0_constraint,gamma_stat_channel1_bin_1_constraint)
[#1] INFO:Minimization -- The following global observables have been defined and their values are taken from the model: (nominalLumi,nom_alpha_syst1,nom_alpha_syst2,nom_alpha_syst3,nom_gamma_stat_channel1_bin_0,nom_gamma_stat_channel1_bin_1)
[#0] PROGRESS:Minimization -- ProfileLikelihoodCalcultor::DoGLobalFit - find MLE
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_simPdf_obsData_with_constr) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
RooAbsTestStatistic::initSimMode: creating slave calculator #0 for state channel1 (2 dataset entries)
[#1] INFO:Fitting -- RooAbsTestStatistic::initSimMode: created 1 slave calculators.
[#1] INFO:Minimization -- The following expressions have been identified as constant and will be precalculated and cached: (signal_channel1_shapes,background1_channel1_Hist_alphanominal,channel1_model_binWidth,background2_channel1_Hist_alphanominal)
[#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (mc_stat_channel1)
[#0] PROGRESS:Minimization -- ProfileLikelihoodCalcultor::DoMinimizeNLL - using Minuit / with strategy 1
[#1] INFO:Minimization --
RooFitResult: minimized FCN value: 15.5775, estimated distance to minimum: 1.99576e-08
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0
Floating Parameter FinalValue +/- Error
-------------------- --------------------------
SigXsecOverSM 1.1153e+00 +/- 5.87e-01
alpha_syst2 -8.9073e-03 +/- 9.83e-01
alpha_syst3 1.7876e-02 +/- 9.48e-01
gamma_stat_channel1_bin_0 9.9955e-01 +/- 4.93e-02
gamma_stat_channel1_bin_1 1.0036e+00 +/- 8.01e-02
Warning: lower value for SigXsecOverSM is at limit 0
--------------------------------------
Will generate sampling distribution at SigXsecOverSM = 2.32744
1) 0x55619acce540 RooRealVar:: SigXsecOverSM = 2.32744 +/- 0.586576 L(-3 - 3) "SigXsecOverSM"
2) 0x556199fa63a0 RooRealVar:: alpha_syst2 = 0.710783 +/- 0.982506 L(-5 - 5) "alpha_syst2"
3) 0x55619ab5b840 RooRealVar:: alpha_syst3 = 0.260224 +/- 0.947653 L(-5 - 5) "alpha_syst3"
4) 0x55619aa9e060 RooRealVar:: gamma_stat_channel1_bin_0 = 1.03668 +/- 0.0493362 L(0 - 1.25) "gamma_stat_channel1_bin_0"
5) 0x55619aab94a0 RooRealVar:: gamma_stat_channel1_bin_1 = 1.05296 +/- 0.0800896 L(0 - 1.5) "gamma_stat_channel1_bin_1"
[#0] PROGRESS:Generation -- generated toys: 500 / 1000
bool useProof = false;
int nworkers = 0;
void StandardTestStatDistributionDemo(const char *infile = "", const char *workspaceName = "combined",
const char *modelConfigName = "ModelConfig", const char *dataName = "obsData")
{
int nToyMC = 1000;
bool allowNegativeMu = true;
if (!strcmp(infile, "")) {
filename =
"results/example_combined_GaussExample_model.root";
if (!fileExist) {
#ifdef _WIN32
cout << "HistFactory file cannot be generated on Windows - exit" << endl;
return;
#endif
cout << "will run standard hist2workspace example" << endl;
gROOT->ProcessLine(
".! prepareHistFactory .");
gROOT->ProcessLine(
".! hist2workspace config/example.xml");
cout << "\n\n---------------------" << endl;
cout << "Done creating example input" << endl;
cout << "---------------------\n\n" << endl;
}
} else
cout <<
"StandardRooStatsDemoMacro: Input file " <<
filename <<
" is not found" << endl;
return;
}
cout << "workspace not found" << endl;
return;
}
cout << "data or ModelConfig was not found" << endl;
return;
}
double plcUpperLimit = interval->
UpperLimit(*firstPOI);
delete interval;
cout << "\n\n--------------------------------------" << endl;
cout <<
"Will generate sampling distribution at " << firstPOI->
GetName() <<
" = " << plcUpperLimit << endl;
if (nPOI > 1) {
cout << "not sure what to do with other parameters of interest, but here are their values" << endl;
}
if (allowNegativeMu)
sampler.SetPdf(*mc->
GetPdf());
cout << "tell it to use 1 event" << endl;
sampler.SetNEventsPerToy(1);
}
firstPOI->
setVal(plcUpperLimit);
if (useProof) {
sampler.SetProofConfig(&pc);
}
firstPOI->
setVal(plcUpperLimit);
allParameters.
Print(
"v");
plot.AddSamplingDistribution(sampDist);
plot.GetTH1F(sampDist)->GetYaxis()->SetTitle(
Form(
"f(-log #lambda(#mu=%.2f) | #mu=%.2f)", plcUpperLimit, plcUpperLimit));
plot.SetAxisTitle(
Form(
"-log #lambda(#mu=%.2f)", plcUpperLimit));
double min =
plot.GetTH1F(sampDist)->GetXaxis()->GetXmin();
double max =
plot.GetTH1F(sampDist)->GetXaxis()->GetXmax();
TF1 *
f =
new TF1(
"f",
Form(
"2*ROOT::Math::chisquared_pdf(2*x,%d,0)", nPOI), min, max);
c1->SaveAs(
"standard_test_stat_distribution.pdf");
}
winID h TVirtualViewer3D TVirtualGLPainter char TVirtualGLPainter plot
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TSystem * gSystem
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * first() const
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
RooAbsData is the common abstract base class for binned and unbinned datasets.
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void setMin(const char *name, double value)
Set minimum of name range to given value.
LikelihoodInterval is a concrete implementation of the RooStats::ConfInterval interface.
double UpperLimit(const RooRealVar ¶m)
return the upper bound of the interval on a given parameter
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return nullptr if not existing)
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return nullptr if not existing)
void Print(Option_t *option="") const override
overload the print method
const RooArgSet * GetObservables() const
get RooArgSet for observables (return nullptr if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
The ProfileLikelihoodCalculator is a concrete implementation of CombinedCalculator (the interface cla...
ProfileLikelihoodTestStat is an implementation of the TestStatistic interface that calculates the pro...
Holds configuration options for proof and proof-lite.
This class provides simple and straightforward utilities to plot SamplingDistribution objects.
This class simply holds a sampling distribution of some test statistic.
const std::vector< double > & GetSamplingDistribution() const
Get test statistics values.
ToyMCSampler is an implementation of the TestStatSampler interface.
The RooWorkspace is a persistable container for RooFit projects.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
const char * GetName() const override
Returns name of object.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.