71using std::cout, std::endl;
81 bool generateBinned =
false;
105 std::string minimizerType =
133 void SetParameter(
const char *
name,
const char *
value);
134 void SetParameter(
const char *
name,
bool value);
135 void SetParameter(
const char *
name,
int value);
136 void SetParameter(
const char *
name,
double value);
163RooStats::HypoTestInvTool::HypoTestInvTool()
171void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
bool value)
179 if (
s_name.find(
"PlotHypoTestResult") != std::string::npos)
181 if (
s_name.find(
"WriteResult") != std::string::npos)
183 if (
s_name.find(
"Optimize") != std::string::npos)
185 if (
s_name.find(
"UseVectorStore") != std::string::npos)
187 if (
s_name.find(
"GenerateBinned") != std::string::npos)
189 if (
s_name.find(
"EnableDetailedOutput") != std::string::npos)
191 if (
s_name.find(
"Rebuild") != std::string::npos)
193 if (
s_name.find(
"ReuseAltToys") != std::string::npos)
199void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
int value)
207 if (
s_name.find(
"NToyToRebuild") != std::string::npos)
209 if (
s_name.find(
"RebuildParamValues") != std::string::npos)
211 if (
s_name.find(
"PrintLevel") != std::string::npos)
213 if (
s_name.find(
"InitialFit") != std::string::npos)
215 if (
s_name.find(
"RandomSeed") != std::string::npos)
217 if (
s_name.find(
"AsimovBins") != std::string::npos)
223void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
double value)
231 if (
s_name.find(
"NToysRatio") != std::string::npos)
233 if (
s_name.find(
"MaxPOI") != std::string::npos)
239void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
const char *
value)
247 if (
s_name.find(
"MassValue") != std::string::npos)
249 if (
s_name.find(
"MinimizerType") != std::string::npos)
251 if (
s_name.find(
"ResultFileName") != std::string::npos)
257void wsName =
"combined",
310 filename =
"results/example_combined_GaussExample_model.root";
315 cout <<
"will run standard hist2workspace example" << endl;
316 gROOT->ProcessLine(
".! prepareHistFactory .");
317 gROOT->ProcessLine(
".! hist2workspace config/example.xml");
318 cout <<
"\n\n---------------------" << endl;
319 cout <<
"Done creating example input" << endl;
320 cout <<
"---------------------\n\n" << endl;
331 cout <<
"StandardRooStatsDemoMacro: Input file " <<
filename <<
" is not found" << endl;
338 calc.SetParameter(
"PlotHypoTestResult",
optHTInv.plotHypoTestResult);
341 calc.SetParameter(
"UseVectorStore",
optHTInv.useVectorStore);
342 calc.SetParameter(
"GenerateBinned",
optHTInv.generateBinned);
345 calc.SetParameter(
"EnableDetailedOutput",
optHTInv.enableDetailedOutput);
347 calc.SetParameter(
"ReuseAltToys",
optHTInv.reuseAltToys);
348 calc.SetParameter(
"NToyToRebuild",
optHTInv.nToyToRebuild);
349 calc.SetParameter(
"RebuildParamValues",
optHTInv.rebuildParamValues);
350 calc.SetParameter(
"MassValue",
optHTInv.massValue.c_str());
351 calc.SetParameter(
"MinimizerType",
optHTInv.minimizerType.c_str());
354 calc.SetParameter(
"ResultFileName",
optHTInv.resultFileName);
364 std::cout <<
w <<
"\t" <<
filename << std::endl;
369 std::cerr <<
"Error running the HypoTestInverter - Exit " << std::endl;
374 std::cout <<
"Reading an HypoTestInverterResult with name " <<
wsName <<
" from file " <<
filename << std::endl;
377 std::cerr <<
"File " <<
filename <<
" does not contain a workspace or an HypoTestInverterResult - Exit "
397#if defined ROOT_SVN_VERSION && ROOT_SVN_VERSION >= 44126
398 if (
r->IsTwoSided()) {
400 llError =
r->LowerLimitEstimatedError();
404 llError =
r->LowerLimitEstimatedError();
408 double ulError =
r->UpperLimitEstimatedError();
413 std::cout <<
"The computed lower limit is: " <<
lowerLimit <<
" +/- " <<
llError << std::endl;
414 std::cout <<
"The computed upper limit is: " <<
upperLimit <<
" +/- " <<
ulError << std::endl;
417 std::cout <<
"Expected upper limits, using the B (alternate) model : " << std::endl;
418 std::cout <<
" expected limit (median) " <<
r->GetExpectedUpperLimit(0) << std::endl;
419 std::cout <<
" expected limit (-1 sig) " <<
r->GetExpectedUpperLimit(-1) << std::endl;
420 std::cout <<
" expected limit (+1 sig) " <<
r->GetExpectedUpperLimit(1) << std::endl;
421 std::cout <<
" expected limit (-2 sig) " <<
r->GetExpectedUpperLimit(-2) << std::endl;
422 std::cout <<
" expected limit (+2 sig) " <<
r->GetExpectedUpperLimit(2) << std::endl;
427 Info(
"StandardHypoTestInvDemo",
"detailed output will be written in output result file");
446 name.Replace(0,
name.Last(
'/') + 1,
"");
460 mResultFileName,
"RECREATE");
464 Info(
"StandardHypoTestInvDemo",
"HypoTestInverterResult has been written in the file %s",
mResultFileName.Data());
470 std::string typeName =
"";
472 typeName =
"Frequentist";
476 typeName =
"Asymptotic";
489 plot->Draw(
"CLb 2CL");
506 for (
int i = 0; i <
nEntries; i++) {
510 pl->SetLogYaxis(
true);
525 std::cout <<
"Running HypoTestInverter on the workspace " <<
w->GetName() << std::endl;
531 Error(
"StandardHypoTestDemo",
"Not existing data %s",
dataName);
534 std::cout <<
"Using data set " <<
dataName << std::endl;
538 data->convertToVectorStore();
555 if (!
sbModel->GetParametersOfInterest()) {
559 if (!
sbModel->GetObservables()) {
560 Error(
"StandardHypoTestInvDemo",
"Model %s has no observables ",
modelSBName);
564 Info(
"StandardHypoTestInvDemo",
"Model %s has no snapshot - make one using model poi",
modelSBName);
573 std::cout <<
"StandardHypoTestInvDemo"
574 <<
" - Switch off all systematics by setting them constant to their initial values" << std::endl;
585 Info(
"StandardHypoTestInvDemo",
"The background model %s does not exist",
modelBName);
586 Info(
"StandardHypoTestInvDemo",
"Copy it from ModelConfig %s and set POI to zero",
modelSBName);
597 if (!
bModel->GetSnapshot()) {
598 Info(
"StandardHypoTestInvDemo",
"Model %s has no snapshot - make one using model poi and 0 values ",
607 Error(
"StandardHypoTestInvDemo",
"Model %s has no valid poi",
modelBName);
622 Warning(
"StandardHypoTestInvDemo",
"Model %s has nuisance parameters but no global observables associated",
624 Warning(
"StandardHypoTestInvDemo",
625 "\tThe effect of the nuisance parameters will not be treated correctly ");
640 std::cout <<
"StandardHypoTestInvDemo : POI initial value: " << poi->
GetName() <<
" = " << poi->
getVal()
658 Info(
"StandardHypoTestInvDemo",
"Using %s as minimizer for computing the test statistic",
667 Info(
"StandardHypoTestInvDemo",
" Doing a first fit to the observed data ");
669 if (
sbModel->GetNuisanceParameters())
673 std::unique_ptr<RooFitResult>
fitres{
sbModel->GetPdf()->fitTo(
676 if (
fitres->status() != 0) {
677 Warning(
"StandardHypoTestInvDemo",
678 "Fit to the model failed - try with strategy 1 and perform first an Hesse computation");
679 fitres = std::unique_ptr<RooFitResult>{
sbModel->GetPdf()->fitTo(
683 if (
fitres->status() != 0)
684 Warning(
"StandardHypoTestInvDemo",
" Fit still failed - continue anyway.....");
687 std::cout <<
"StandardHypoTestInvDemo - Best Fit value : " << poi->
GetName() <<
" = " <<
poihat <<
" +/- "
689 std::cout <<
"Time for fitting : ";
694 std::cout <<
"StandardHypoTestInvo: snapshot of S+B Model " <<
sbModel->GetName()
695 <<
" is set to the best fit value" << std::endl;
701 Info(
"StandardHypoTestInvDemo",
"Using LEP test statistic - an initial fit is not done and the TS will use "
702 "the nuisances at the model value");
704 Info(
"StandardHypoTestInvDemo",
"Using LEP test statistic - an initial fit has been done and the TS will use "
705 "the nuisances at the best fit value");
714 if (
sbModel->GetNuisanceParameters())
719 if (
bModel->GetNuisanceParameters())
721 if (
bModel->GetSnapshot())
724 slrts.EnableDetailedOutput();
728 ropl.SetSubtractMLE(
false);
730 ropl.SetSubtractMLE(
true);
734 ropl.EnableDetailedOutput();
744 profll.EnableDetailedOutput();
779 Error(
"StandardHypoTestInvDemo",
"Invalid - calculator type = %d supported values are only :\n\t\t\t 0 "
780 "(Frequentist) , 1 (Hybrid) , 2 (Asymptotic) ",
799 Error(
"StandardHypoTestInvDemo",
"Invalid - test statistic type = %d supported values are only :\n\t\t\t 0 (SLR) "
800 ", 1 (Tevatron) , 2 (PLR), 3 (PLR1), 4(MLE)",
808 if (
sbModel->GetPdf()->canBeExtended()) {
810 Warning(
"StandardHypoTestInvDemo",
"Pdf is extended: but number counting flag is set: ignore it ");
814 int nEvents =
data->numEntries();
815 Info(
"StandardHypoTestInvDemo",
816 "Pdf is not extended: number of events to generate taken from observed data set is %d", nEvents);
817 toymcs->SetNEventsPerToy(nEvents);
819 Info(
"StandardHypoTestInvDemo",
"using a number counting pdf");
820 toymcs->SetNEventsPerToy(1);
827 Info(
"StandardHypoTestInvDemo",
"Data set is weighted, nentries = %d and sum of weights = %8.1f but toy "
828 "generation is unbinned - it would be faster to set mGenerateBinned to true\n",
829 data->numEntries(),
data->sumEntries());
836 Warning(
"StandardHypoTestInvDemo",
"generate binned is activated but the number of observable is %d. Too much "
837 "memory could be needed for allocating all the bins",
838 sbModel->GetObservables()->getSize());
848 hc->UseSameAltToys();
862 if (
bModel->GetNuisanceParameters() ||
sbModel->GetNuisanceParameters()) {
865 toymcs->SetUseMultiGen(
false);
866 ToyMCSampler::SetAlwaysUseMultiGen(
false);
873 Info(
"StandardHypoTestInvDemo",
874 "No nuisance pdf given for the HybridCalculator - try to deduce pdf from the model");
881 if (
bModel->GetPriorPdf()) {
883 Info(
"StandardHypoTestInvDemo",
884 "No nuisance pdf given - try to use %s that is defined as a prior pdf in the B model",
887 Error(
"StandardHypoTestInvDemo",
"Cannot run Hybrid calculator because no prior on the nuisance "
888 "parameter is specified or can be derived");
893 Info(
"StandardHypoTestInvDemo",
"Using as nuisance Pdf ... ");
897 (
bModel->GetNuisanceParameters()) ?
bModel->GetNuisanceParameters() :
sbModel->GetNuisanceParameters();
899 if (
np->getSize() == 0) {
900 Warning(
"StandardHypoTestInvDemo",
901 "Prior nuisance does not depend on nuisance parameters. They will be smeared in their full range");
907 }
else if (
type == 2 ||
type == 3) {
911 Warning(
"StandardHypoTestInvDemo",
912 "Only the PL test statistic can be used with AsymptoticCalculator - use by default a two-sided PL");
913 }
else if (
type == 0) {
918 }
else if (
type == 1) {
931 calc.SetVerbose(
true);
939 std::cout <<
"Doing a fixed scan in interval : " <<
poimin <<
" , " <<
poimax << std::endl;
943 std::cout <<
"Doing an automatic scan in interval : " << poi->
getMin() <<
" , " << poi->
getMax() << std::endl;
948 std::cout <<
"Time to perform limit scan \n";
953 std::cout <<
"\n***************************************************************\n";
954 std::cout <<
"Rebuild the upper limit distribution by re-generating new set of pseudo-experiment and re-compute "
955 "for each of them a new upper limit\n\n";
968 if (
sbModel->GetNuisanceParameters())
984 std::cout <<
"rebuild using fitted parameter value for B-model snapshot" << std::endl;
990 std::cout <<
"StandardHypoTestInvDemo: Initial parameters used for rebuilding: ";
995 std::cout <<
"Time to rebuild distributions " << std::endl;
999 std::cout <<
"Expected limits after rebuild distribution " << std::endl;
1000 std::cout <<
"expected upper limit (median of limit distribution) " <<
limDist->InverseCDF(0.5) << std::endl;
1001 std::cout <<
"expected -1 sig limit (0.16% quantile of limit dist) "
1003 std::cout <<
"expected +1 sig limit (0.84% quantile of limit dist) "
1005 std::cout <<
"expected -2 sig limit (.025% quantile of limit dist) "
1007 std::cout <<
"expected +2 sig limit (.975% quantile of limit dist) "
1013 limPlot.GetTH1F()->SetStats(
true);
1015 new TCanvas(
"limPlot",
"Upper Limit Distribution");
1020 TFile(
"RULDist.root",
"RECREATE");
1028 r =
calc.GetInterval();
1031 std::cout <<
"ERROR : failed to re-build distributions " << std::endl;
1047 StandardHypoTestInvDemo();
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
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
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 np
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 r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
R__EXTERN TSystem * gSystem
static void SetDefaultMinimizer(const char *type, const char *algo=nullptr)
Set the default Minimizer type and corresponding algorithms.
static void SetDefaultStrategy(int strat)
Set the default strategy.
static const std::string & DefaultMinimizerType()
Abstract base class for binned and unbinned datasets.
static void setDefaultStorageType(StorageType s)
Abstract interface for all probability density functions.
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
static RooMsgService & instance()
Return reference to singleton instance.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void setMax(const char *name, double value)
Set maximum of name range to given value.
Hypothesis Test Calculator based on the asymptotic formulae for the profile likelihood ratio.
Does a frequentist hypothesis test.
Same purpose as HybridCalculatorOriginal, but different implementation.
Common base class for the Hypothesis Test Calculators.
Class to plot a HypoTestInverterResult, the output of the HypoTestInverter calculator.
HypoTestInverterResult class holds the array of hypothesis test results and compute a confidence inte...
A class for performing a hypothesis test inversion by scanning the hypothesis test results of a HypoT...
MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood estimate of a specified ...
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
NumEventsTestStat is a simple implementation of the TestStatistic interface used for simple number co...
ProfileLikelihoodTestStat is an implementation of the TestStatistic interface that calculates the pro...
TestStatistic that returns the ratio of profiled likelihoods.
This class provides simple and straightforward utilities to plot SamplingDistribution objects.
This class simply holds a sampling distribution of some test statistic.
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.
Persistable container for RooFit projects.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
void ls(Option_t *option="") const override
List file contents.
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.
Mother of all ROOT objects.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
RooCmdArg InitialHesse(bool flag=true)
RooCmdArg Offset(std::string const &mode)
RooCmdArg Constrain(const RooArgSet ¶ms)
RooCmdArg Minimizer(const char *type, const char *alg=nullptr)
RooCmdArg Hesse(bool flag=true)
RooCmdArg Strategy(Int_t code)
RooCmdArg Save(bool flag=true)
RooCmdArg PrintLevel(Int_t code)
double normal_cdf(double x, double sigma=1, double x0=0)
Cumulative distribution function of the normal (Gaussian) distribution (lower tail).
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
utility function to set all variable constant in a collection (from G.
void RemoveConstantParameters(RooArgSet *set)
std::string const & NLLOffsetMode()
Test what offsetting mode RooStats should use by default.
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
extract constraint terms from pdf
void SetNLLOffsetMode(std::string const &mode)
Function to set a global flag in RooStats to use NLL offset when performing nll computations.
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
useful function to print in one line the content of a set with their values
Double_t Sqrt(Double_t x)
Returns the square root of x.
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).