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.
␛[1mRooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby␛[0m
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
=== Using the following for ModelConfig ===
Observables: RooArgSet:: = (obs_x_channel1,weightVar,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:: = (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.174888
[#1] INFO:Minization -- p.d.f. provides expected number of events, including extended term in likelihood.
[#1] INFO:Minization -- createNLL: caching constraint set under name CONSTR_OF_PDF_simPdf_FOR_OBS_channelCat:obs_x_channel1 with 4 entries
[#1] INFO:Minization -- Including the following contraint terms in minimization: (alpha_syst2Constraint,alpha_syst3Constraint,gamma_stat_channel1_bin_0_constraint,gamma_stat_channel1_bin_1_constraint)
[#1] INFO:Minization -- The following global observables have been defined: (nom_alpha_syst2,nom_alpha_syst3,nom_gamma_stat_channel1_bin_0,nom_gamma_stat_channel1_bin_1)
[#0] PROGRESS:Minization -- ProfileLikelihoodCalcultor::DoGLobalFit - find MLE
[#0] PROGRESS:Minization -- ProfileLikelihoodCalcultor::DoMinimizeNLL - using Minuit / Migrad with strategy 1
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_simPdf_obsData_with_constr) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
RooAbsTestStatistic::initSimMode: creating slave calculator #0 for state channel1 (2 dataset entries)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel1_model_Int[obs_x_channel1]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel1)
[#1] INFO:Fitting -- RooAbsTestStatistic::initSimMode: created 1 slave calculators.
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel1_model_Int[obs_x_channel1]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel1)
[#1] INFO:Minization -- The following expressions have been identified as constant and will be precalculated and cached: (signal_channel1_nominal,background1_channel1_nominal,background2_channel1_nominal)
[#1] INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (mc_stat_channel1)
[#1] INFO:Minization --
RooFitResult: minimized FCN value: -1033.78, estimated distance to minimum: 2.39561e-08
covariance matrix quality: Full, accurate covariance matrix
Status : MINIMIZE=0
Floating Parameter FinalValue +/- Error
-------------------- --------------------------
SigXsecOverSM 1.1153e+00 +/- 5.86e-01
alpha_syst2 -8.9017e-03 +/- 9.82e-01
alpha_syst3 1.7918e-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) 0x556aaf6f8540 RooRealVar:: SigXsecOverSM = 2.32744 +/- 0.586082 L(-3 - 3) "SigXsecOverSM"
2) 0x556aaf6f4cb0 RooRealVar:: alpha_syst2 = 0.710796 +/- 0.982182 L(-5 - 5) "alpha_syst2"
3) 0x556aaf6fbad0 RooRealVar:: alpha_syst3 = 0.260222 +/- 0.947589 L(-5 - 5) "alpha_syst3"
4) 0x556aae5edc80 RooRealVar:: gamma_stat_channel1_bin_0 = 1.03668 +/- 0.0493173 L(0 - 1.25) "gamma_stat_channel1_bin_0"
5) 0x556aaebfa060 RooRealVar:: gamma_stat_channel1_bin_1 = 1.05157 +/- 0.080065 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;
const char *filename = "";
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
filename = infile;
cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
}
if (!w) {
cout << "workspace not found" << endl;
return;
}
ModelConfig *mc = (ModelConfig *)w->
obj(modelConfigName);
if (!data || !mc) {
cout << "data or ModelConfig was not found" << endl;
return;
}
mc->Print();
ProfileLikelihoodCalculator plc(*data, *mc);
LikelihoodInterval *interval = plc.GetInterval();
double plcUpperLimit = interval->UpperLimit(*firstPOI);
delete interval;
cout << "\n\n--------------------------------------" << endl;
cout <<
"Will generate sampling distribution at " << firstPOI->
GetName() <<
" = " << plcUpperLimit << endl;
int nPOI = mc->GetParametersOfInterest()->getSize();
if (nPOI > 1) {
cout << "not sure what to do with other parameters of interest, but here are their values" << endl;
mc->GetParametersOfInterest()->Print("v");
}
ProfileLikelihoodTestStat ts(*mc->GetPdf());
if (allowNegativeMu)
poi.
add(*mc->GetParametersOfInterest());
ToyMCSampler sampler(ts, nToyMC);
sampler.SetPdf(*mc->GetPdf());
sampler.SetObservables(*mc->GetObservables());
sampler.SetGlobalObservables(*mc->GetGlobalObservables());
if (!mc->GetPdf()->canBeExtended() && (data->
numEntries() == 1)) {
cout << "tell it to use 1 event" << endl;
sampler.SetNEventsPerToy(1);
}
firstPOI->
setVal(plcUpperLimit);
sampler.SetParametersForTestStat(*mc->GetParametersOfInterest());
if (useProof) {
ProofConfig
pc(*w, nworkers,
"",
false);
sampler.SetProofConfig(&
pc);
}
firstPOI->
setVal(plcUpperLimit);
allParameters.
add(*mc->GetParametersOfInterest());
allParameters.
add(*mc->GetNuisanceParameters());
allParameters.
Print(
"v");
SamplingDistribution *sampDist = sampler.GetSamplingDistribution(allParameters);
SamplingDistPlot plot;
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));
plot.Draw();
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");
}
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual Int_t numEntries() const
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
RooRealVar represents a fundamental (non-derived) real valued object.
void setMin(const char *name, Double_t value)
Set minimum of name range to given value.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
The RooWorkspace is a persistable container for RooFit projects.
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
void Print(Option_t *opts=0) const
Print contents of the workspace.
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
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::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
virtual const char * GetName() const
Returns name of object.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Template specialisation used in RooAbsArg:
Namespace for the RooStats classes.
static constexpr double pc