71using std::cout, std::endl;
81 bool generateBinned =
false;
108 std::string minimizerType =
136 void SetParameter(
const char *
name,
const char *
value);
137 void SetParameter(
const char *
name,
bool value);
138 void SetParameter(
const char *
name,
int value);
139 void SetParameter(
const char *
name,
double value);
168RooStats::HypoTestInvTool::HypoTestInvTool()
176void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
bool value)
184 if (
s_name.find(
"PlotHypoTestResult") != std::string::npos)
186 if (
s_name.find(
"WriteResult") != std::string::npos)
188 if (
s_name.find(
"Optimize") != std::string::npos)
190 if (
s_name.find(
"UseVectorStore") != std::string::npos)
192 if (
s_name.find(
"GenerateBinned") != std::string::npos)
194 if (
s_name.find(
"UseProof") != std::string::npos)
196 if (
s_name.find(
"EnableDetailedOutput") != std::string::npos)
198 if (
s_name.find(
"Rebuild") != std::string::npos)
200 if (
s_name.find(
"ReuseAltToys") != std::string::npos)
206void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
int value)
214 if (
s_name.find(
"NWorkers") != std::string::npos)
216 if (
s_name.find(
"NToyToRebuild") != std::string::npos)
218 if (
s_name.find(
"RebuildParamValues") != std::string::npos)
220 if (
s_name.find(
"PrintLevel") != std::string::npos)
222 if (
s_name.find(
"InitialFit") != std::string::npos)
224 if (
s_name.find(
"RandomSeed") != std::string::npos)
226 if (
s_name.find(
"AsimovBins") != std::string::npos)
232void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
double value)
240 if (
s_name.find(
"NToysRatio") != std::string::npos)
242 if (
s_name.find(
"MaxPOI") != std::string::npos)
248void RooStats::HypoTestInvTool::SetParameter(
const char *
name,
const char *
value)
256 if (
s_name.find(
"MassValue") != std::string::npos)
258 if (
s_name.find(
"MinimizerType") != std::string::npos)
260 if (
s_name.find(
"ResultFileName") != std::string::npos)
320 filename =
"results/example_combined_GaussExample_model.root";
325 cout <<
"will run standard hist2workspace example" << endl;
326 gROOT->ProcessLine(
".! prepareHistFactory .");
327 gROOT->ProcessLine(
".! hist2workspace config/example.xml");
328 cout <<
"\n\n---------------------" << endl;
329 cout <<
"Done creating example input" << endl;
330 cout <<
"---------------------\n\n" << endl;
341 cout <<
"StandardRooStatsDemoMacro: Input file " <<
filename <<
" is not found" << endl;
348 calc.SetParameter(
"PlotHypoTestResult",
optHTInv.plotHypoTestResult);
351 calc.SetParameter(
"UseVectorStore",
optHTInv.useVectorStore);
352 calc.SetParameter(
"GenerateBinned",
optHTInv.generateBinned);
356 calc.SetParameter(
"EnableDetailedOutput",
optHTInv.enableDetailedOutput);
359 calc.SetParameter(
"ReuseAltToys",
optHTInv.reuseAltToys);
360 calc.SetParameter(
"NToyToRebuild",
optHTInv.nToyToRebuild);
361 calc.SetParameter(
"RebuildParamValues",
optHTInv.rebuildParamValues);
362 calc.SetParameter(
"MassValue",
optHTInv.massValue.c_str());
363 calc.SetParameter(
"MinimizerType",
optHTInv.minimizerType.c_str());
366 calc.SetParameter(
"ResultFileName",
optHTInv.resultFileName);
376 std::cout <<
w <<
"\t" <<
filename << std::endl;
381 std::cerr <<
"Error running the HypoTestInverter - Exit " << std::endl;
386 std::cout <<
"Reading an HypoTestInverterResult with name " <<
wsName <<
" from file " <<
filename << std::endl;
389 std::cerr <<
"File " <<
filename <<
" does not contain a workspace or an HypoTestInverterResult - Exit "
409#if defined ROOT_SVN_VERSION && ROOT_SVN_VERSION >= 44126
410 if (
r->IsTwoSided()) {
412 llError =
r->LowerLimitEstimatedError();
416 llError =
r->LowerLimitEstimatedError();
420 double ulError =
r->UpperLimitEstimatedError();
425 std::cout <<
"The computed lower limit is: " <<
lowerLimit <<
" +/- " <<
llError << std::endl;
426 std::cout <<
"The computed upper limit is: " <<
upperLimit <<
" +/- " <<
ulError << std::endl;
429 std::cout <<
"Expected upper limits, using the B (alternate) model : " << std::endl;
430 std::cout <<
" expected limit (median) " <<
r->GetExpectedUpperLimit(0) << std::endl;
431 std::cout <<
" expected limit (-1 sig) " <<
r->GetExpectedUpperLimit(-1) << std::endl;
432 std::cout <<
" expected limit (+1 sig) " <<
r->GetExpectedUpperLimit(1) << std::endl;
433 std::cout <<
" expected limit (-2 sig) " <<
r->GetExpectedUpperLimit(-2) << std::endl;
434 std::cout <<
" expected limit (+2 sig) " <<
r->GetExpectedUpperLimit(2) << std::endl;
439 Info(
"StandardHypoTestInvDemo",
"detailed output will be written in output result file");
458 name.Replace(0,
name.Last(
'/') + 1,
"");
476 Info(
"StandardHypoTestInvDemo",
"HypoTestInverterResult has been written in the file %s",
mResultFileName.Data());
482 std::string typeName =
"";
484 typeName =
"Frequentist";
488 typeName =
"Asymptotic";
501 plot->Draw(
"CLb 2CL");
518 for (
int i = 0; i <
nEntries; i++) {
522 pl->SetLogYaxis(
true);
537 std::cout <<
"Running HypoTestInverter on the workspace " <<
w->GetName() << std::endl;
543 Error(
"StandardHypoTestDemo",
"Not existing data %s",
dataName);
546 std::cout <<
"Using data set " <<
dataName << std::endl;
550 data->convertToVectorStore();
567 if (!
sbModel->GetParametersOfInterest()) {
571 if (!
sbModel->GetObservables()) {
572 Error(
"StandardHypoTestInvDemo",
"Model %s has no observables ",
modelSBName);
576 Info(
"StandardHypoTestInvDemo",
"Model %s has no snapshot - make one using model poi",
modelSBName);
585 std::cout <<
"StandardHypoTestInvDemo"
586 <<
" - Switch off all systematics by setting them constant to their initial values" << std::endl;
597 Info(
"StandardHypoTestInvDemo",
"The background model %s does not exist",
modelBName);
598 Info(
"StandardHypoTestInvDemo",
"Copy it from ModelConfig %s and set POI to zero",
modelSBName);
609 if (!
bModel->GetSnapshot()) {
610 Info(
"StandardHypoTestInvDemo",
"Model %s has no snapshot - make one using model poi and 0 values ",
619 Error(
"StandardHypoTestInvDemo",
"Model %s has no valid poi",
modelBName);
634 Warning(
"StandardHypoTestInvDemo",
"Model %s has nuisance parameters but no global observables associated",
636 Warning(
"StandardHypoTestInvDemo",
637 "\tThe effect of the nuisance parameters will not be treated correctly ");
644 std::unique_ptr<RooArgSet> allParams{
sbModel->GetPdf()->getParameters(*
data)};
652 std::cout <<
"StandardHypoTestInvDemo : POI initial value: " << poi->
GetName() <<
" = " << poi->
getVal()
670 Info(
"StandardHypoTestInvDemo",
"Using %s as minimizer for computing the test statistic",
679 Info(
"StandardHypoTestInvDemo",
" Doing a first fit to the observed data ");
681 if (
sbModel->GetNuisanceParameters())
685 std::unique_ptr<RooFitResult>
fitres{
sbModel->GetPdf()->fitTo(
688 if (
fitres->status() != 0) {
689 Warning(
"StandardHypoTestInvDemo",
690 "Fit to the model failed - try with strategy 1 and perform first an Hesse computation");
691 fitres = std::unique_ptr<RooFitResult>{
sbModel->GetPdf()->fitTo(
695 if (
fitres->status() != 0)
696 Warning(
"StandardHypoTestInvDemo",
" Fit still failed - continue anyway.....");
699 std::cout <<
"StandardHypoTestInvDemo - Best Fit value : " << poi->
GetName() <<
" = " <<
poihat <<
" +/- "
701 std::cout <<
"Time for fitting : ";
706 std::cout <<
"StandardHypoTestInvo: snapshot of S+B Model " <<
sbModel->GetName()
707 <<
" is set to the best fit value" << std::endl;
713 Info(
"StandardHypoTestInvDemo",
"Using LEP test statistic - an initial fit is not done and the TS will use "
714 "the nuisances at the model value");
716 Info(
"StandardHypoTestInvDemo",
"Using LEP test statistic - an initial fit has been done and the TS will use "
717 "the nuisances at the best fit value");
726 if (
sbModel->GetNuisanceParameters())
731 if (
bModel->GetNuisanceParameters())
733 if (
bModel->GetSnapshot())
736 slrts.EnableDetailedOutput();
740 ropl.SetSubtractMLE(
false);
742 ropl.SetSubtractMLE(
true);
746 ropl.EnableDetailedOutput();
756 profll.EnableDetailedOutput();
791 Error(
"StandardHypoTestInvDemo",
"Invalid - calculator type = %d supported values are only :\n\t\t\t 0 "
792 "(Frequentist) , 1 (Hybrid) , 2 (Asymptotic) ",
811 Error(
"StandardHypoTestInvDemo",
"Invalid - test statistic type = %d supported values are only :\n\t\t\t 0 (SLR) "
812 ", 1 (Tevatron) , 2 (PLR), 3 (PLR1), 4(MLE)",
820 if (
sbModel->GetPdf()->canBeExtended()) {
822 Warning(
"StandardHypoTestInvDemo",
"Pdf is extended: but number counting flag is set: ignore it ");
826 int nEvents =
data->numEntries();
827 Info(
"StandardHypoTestInvDemo",
828 "Pdf is not extended: number of events to generate taken from observed data set is %d", nEvents);
829 toymcs->SetNEventsPerToy(nEvents);
831 Info(
"StandardHypoTestInvDemo",
"using a number counting pdf");
832 toymcs->SetNEventsPerToy(1);
839 Info(
"StandardHypoTestInvDemo",
"Data set is weighted, nentries = %d and sum of weights = %8.1f but toy "
840 "generation is unbinned - it would be faster to set mGenerateBinned to true\n",
841 data->numEntries(),
data->sumEntries());
848 Warning(
"StandardHypoTestInvDemo",
"generate binned is activated but the number of observable is %d. Too much "
849 "memory could be needed for allocating all the bins",
850 sbModel->GetObservables()->getSize());
860 hc->UseSameAltToys();
874 if (
bModel->GetNuisanceParameters() ||
sbModel->GetNuisanceParameters()) {
877 toymcs->SetUseMultiGen(
false);
878 ToyMCSampler::SetAlwaysUseMultiGen(
false);
885 Info(
"StandardHypoTestInvDemo",
886 "No nuisance pdf given for the HybridCalculator - try to deduce pdf from the model");
893 if (
bModel->GetPriorPdf()) {
895 Info(
"StandardHypoTestInvDemo",
896 "No nuisance pdf given - try to use %s that is defined as a prior pdf in the B model",
899 Error(
"StandardHypoTestInvDemo",
"Cannot run Hybrid calculator because no prior on the nuisance "
900 "parameter is specified or can be derived");
905 Info(
"StandardHypoTestInvDemo",
"Using as nuisance Pdf ... ");
909 (
bModel->GetNuisanceParameters()) ?
bModel->GetNuisanceParameters() :
sbModel->GetNuisanceParameters();
911 if (
np->getSize() == 0) {
912 Warning(
"StandardHypoTestInvDemo",
913 "Prior nuisance does not depend on nuisance parameters. They will be smeared in their full range");
919 }
else if (
type == 2 ||
type == 3) {
923 Warning(
"StandardHypoTestInvDemo",
924 "Only the PL test statistic can be used with AsymptoticCalculator - use by default a two-sided PL");
925 }
else if (
type == 0) {
930 }
else if (
type == 1) {
943 calc.SetVerbose(
true);
948 toymcs->SetProofConfig(&pc);
957 std::cout <<
"Doing a fixed scan in interval : " <<
poimin <<
" , " <<
poimax << std::endl;
961 std::cout <<
"Doing an automatic scan in interval : " << poi->
getMin() <<
" , " << poi->
getMax() << std::endl;
966 std::cout <<
"Time to perform limit scan \n";
971 std::cout <<
"\n***************************************************************\n";
972 std::cout <<
"Rebuild the upper limit distribution by re-generating new set of pseudo-experiment and re-compute "
973 "for each of them a new upper limit\n\n";
975 allParams = std::unique_ptr<RooArgSet>{
sbModel->GetPdf()->getParameters(*
data)};
986 if (
sbModel->GetNuisanceParameters())
1002 std::cout <<
"rebuild using fitted parameter value for B-model snapshot" << std::endl;
1008 std::cout <<
"StandardHypoTestInvDemo: Initial parameters used for rebuilding: ";
1011 calc.SetCloseProof(
true);
1014 std::cout <<
"Time to rebuild distributions " << std::endl;
1018 std::cout <<
"Expected limits after rebuild distribution " << std::endl;
1019 std::cout <<
"expected upper limit (median of limit distribution) " <<
limDist->InverseCDF(0.5) << std::endl;
1020 std::cout <<
"expected -1 sig limit (0.16% quantile of limit dist) "
1022 std::cout <<
"expected +1 sig limit (0.84% quantile of limit dist) "
1024 std::cout <<
"expected -2 sig limit (.025% quantile of limit dist) "
1026 std::cout <<
"expected +2 sig limit (.975% quantile of limit dist) "
1032 limPlot.GetTH1F()->SetStats(
true);
1034 new TCanvas(
"limPlot",
"Upper Limit Distribution");
1047 r =
calc.GetInterval();
1050 std::cout <<
"ERROR : failed to re-build distributions " << std::endl;
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
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...
Holds configuration options for proof and proof-lite.
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)
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
extract constraint terms from pdf
void UseNLLOffset(bool on)
function to set a global flag in RooStats to use NLL offset when performing nll computations Note tha...
bool IsNLLOffset()
function returning if the flag to check if the flag to use NLLOffset is set
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).