48 using namespace RooFit;
49 using namespace RooStats;
51 bool useProof =
false;
57 void StandardTestStatDistributionDemo(
const char *infile =
"",
const char *workspaceName =
"combined",
58 const char *modelConfigName =
"ModelConfig",
const char *dataName =
"obsData")
65 bool allowNegativeMu =
true;
70 const char *filename =
"";
71 if (!strcmp(infile,
"")) {
72 filename =
"results/example_combined_GaussExample_model.root";
73 bool fileExist = !gSystem->AccessPathName(filename);
77 cout <<
"HistFactory file cannot be generated on Windows - exit" << endl;
81 cout <<
"will run standard hist2workspace example" << endl;
82 gROOT->ProcessLine(
".! prepareHistFactory .");
83 gROOT->ProcessLine(
".! hist2workspace config/example.xml");
84 cout <<
"\n\n---------------------" << endl;
85 cout <<
"Done creating example input" << endl;
86 cout <<
"---------------------\n\n" << endl;
93 TFile *file = TFile::Open(filename);
97 cout <<
"StandardRooStatsDemoMacro: Input file " << filename <<
" is not found" << endl;
105 RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
107 cout <<
"workspace not found" << endl;
112 ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
115 RooAbsData *data = w->data(dataName);
120 cout <<
"data or ModelConfig was not found" << endl;
127 RooRealVar *firstPOI = (RooRealVar *)mc->GetParametersOfInterest()->first();
128 ProfileLikelihoodCalculator plc(*data, *mc);
129 LikelihoodInterval *interval = plc.GetInterval();
130 double plcUpperLimit = interval->UpperLimit(*firstPOI);
132 cout <<
"\n\n--------------------------------------" << endl;
133 cout <<
"Will generate sampling distribution at " << firstPOI->GetName() <<
" = " << plcUpperLimit << endl;
134 int nPOI = mc->GetParametersOfInterest()->getSize();
136 cout <<
"not sure what to do with other parameters of interest, but here are their values" << endl;
137 mc->GetParametersOfInterest()->Print(
"v");
142 ProfileLikelihoodTestStat ts(*mc->GetPdf());
146 firstPOI->setMin(-1 * firstPOI->getMax());
150 poi.add(*mc->GetParametersOfInterest());
153 ToyMCSampler sampler(ts, nToyMC);
154 sampler.SetPdf(*mc->GetPdf());
155 sampler.SetObservables(*mc->GetObservables());
156 sampler.SetGlobalObservables(*mc->GetGlobalObservables());
157 if (!mc->GetPdf()->canBeExtended() && (data->numEntries() == 1)) {
158 cout <<
"tell it to use 1 event" << endl;
159 sampler.SetNEventsPerToy(1);
161 firstPOI->setVal(plcUpperLimit);
162 sampler.SetParametersForTestStat(*mc->GetParametersOfInterest());
165 ProofConfig pc(*w, nworkers,
"",
false);
166 sampler.SetProofConfig(&pc);
169 firstPOI->setVal(plcUpperLimit);
170 RooArgSet allParameters;
171 allParameters.add(*mc->GetParametersOfInterest());
172 allParameters.add(*mc->GetNuisanceParameters());
173 allParameters.Print(
"v");
175 SamplingDistribution *sampDist = sampler.GetSamplingDistribution(allParameters);
176 SamplingDistPlot plot;
177 plot.AddSamplingDistribution(sampDist);
178 plot.GetTH1F(sampDist)->GetYaxis()->SetTitle(
179 Form(
"f(-log #lambda(#mu=%.2f) | #mu=%.2f)", plcUpperLimit, plcUpperLimit));
180 plot.SetAxisTitle(Form(
"-log #lambda(#mu=%.2f)", plcUpperLimit));
182 TCanvas *c1 =
new TCanvas(
"c1");
185 double min = plot.GetTH1F(sampDist)->GetXaxis()->GetXmin();
186 double max = plot.GetTH1F(sampDist)->GetXaxis()->GetXmax();
188 TF1 *f =
new TF1(
"f", Form(
"2*ROOT::Math::chisquared_pdf(2*x,%d,0)", nPOI), min, max);
190 c1->SaveAs(
"standard_test_stat_distribution.pdf");