82template<
class HypoTestType>
98 const RooArgSet * poi =
mc->GetParametersOfInterest();
102 mc =
hc.GetAlternateModel();
104 const RooArgSet * poi =
mc->GetParametersOfInterest();
118 oocoutF(
nullptr,InputArguments) <<
"HypoTestInverter - model are not existing" << std::endl;
121 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter ---- Input models: \n"
122 <<
"\t\t using as S+B (null) model : "
124 <<
"\t\t using as B (alternate) model : "
125 <<
modelB->GetName() <<
"\n" << std::endl;
131 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - B model has no pdf or observables defined" << std::endl;
136 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - pdf of B model has no parameters" << std::endl;
143 oocoutW(
nullptr, InputArguments)
144 <<
"HypoTestInverter - using a B model with POI " <<
scanVariable.GetName() <<
" not equal to zero "
145 <<
" user must check input model configurations " << std::endl;
157 fCalculator0(nullptr),
158 fScannedVariable(nullptr),
164 fCalcType(kUndefined),
165 fNBins(0), fXmin(1), fXmax(1),
183 fCalculator0(nullptr),
190 fCalcType(kUndefined),
191 fNBins(0), fXmin(1), fXmax(1),
199 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
222 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Type of hypotest calculator is not supported " <<std::endl;
245 fNBins(0), fXmin(1), fXmax(1),
253 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
277 fCalcType(kFrequentist),
278 fNBins(0), fXmin(1), fXmax(1),
286 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
310 fCalcType(kAsymptotic),
311 fNBins(0), fXmin(1), fXmax(1),
319 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
336 fCalculator0(nullptr),
344 fNBins(0), fXmin(1), fXmax(1),
356 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
371 fCalculator0(nullptr), fScannedVariable(nullptr),
384 if (
this == &
rhs)
return *
this;
452 TString title =
"HypoTestInverter Result For ";
483 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - return an already existing interval " << std::endl;
488 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - run a fixed scan" << std::endl;
491 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - error running a fixed scan " << std::endl;
494 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - run an automatic scan" << std::endl;
499 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - error running an auto scan " << std::endl;
523 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::Eval - HypoTest failed" << std::endl;
536 if (
hcResult->GetPValueIsRightTail()) {
554 std::unique_ptr<HypoTestResult>
more(
hc.GetHypoTest());
571 "\tCLsplusb = " <<
hcResult->CLsplusb() <<
" +/- " <<
hcResult->CLsplusbError() <<
"\n" <<
604 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - Please provide nBins>0\n";
608 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - nBins==1 -> I will run for xMin (" <<
xMin <<
")\n";
611 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMin==xMax -> I will enforce nBins==1\n";
615 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - Please provide xMin ("
616 <<
xMin <<
") smaller than xMax (" <<
xMax <<
")\n";
622 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMin < lower bound, using xmin = "
623 <<
xMin << std::endl;
627 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMax > upper bound, using xmax = "
628 <<
xMax << std::endl;
632 oocoutE(
nullptr, InputArguments) <<
"HypoTestInverter::RunFixedScan - cannot go in log steps if xMin <= 0" << std::endl;
637 for (
int i=0; i<nBins; i++) {
650 if ( status==
false ) {
651 oocoutW(
nullptr,
Eval) <<
"HypoTestInverter::RunFixedScan - The hypo test for point " <<
thisX <<
" failed. Skipping." << std::endl;
668 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunOnePoint - Out of range: using the lower bound "
670 <<
" on the scanned variable rather than " <<
rVal<<
"\n";
676 oocoutE(
nullptr, InputArguments) <<
"HypoTestInverter::RunOnePoint - Out of range: using the upper bound "
722 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunOnePoint - Merge with previous result for "
730 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunOnePoint - replace previous empty result\n";
769 if ((
hint !=
nullptr) && (*
hint >
r->getMin())) {
770 r->setMax(std::min<double>(3.0 * (*
hint),
r->getMax()));
771 r->setMin(std::max<double>(0.3 * (*
hint),
r->getMin()));
772 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter::RunLimit - Use hint value " << *
hint
773 <<
" search in interval " <<
r->getMin() <<
" , " <<
r->getMax() << std::endl;
780 typedef std::pair<double,double>
CLs_t;
785 double rMin =
r->getMin();
786 double rMax =
r->getMax();
793 fLimitPlot = std::make_unique<TGraphErrors>();
795 if (
fVerbose > 0) std::cout <<
"Search for upper limit to the limit" << std::endl;
798 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at upper limit of scan range: " <<
rMax << std::endl;
806 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Cannot determine upper limit of scan range. At " <<
r->GetName()
807 <<
" = " <<
rMax <<
" still getting "
808 << (
fUseCLs ?
"CLs" :
"CLsplusb") <<
" = " <<
clsMax.first << std::endl;
813 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Search for lower limit to the limit" << std::endl;
821 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at lower limit of scan range: " <<
rMin << std::endl;
834 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at lower limit of scan range: " <<
rMin << std::endl;
842 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Cannot determine lower limit of scan range. At " <<
r->GetName()
843 <<
" = " <<
rMin <<
" still get " << (
fUseCLs ?
"CLs" :
"CLsplusb")
844 <<
" = " <<
clsMin.first << std::endl;
852 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Now doing proper bracketing & bisection" << std::endl;
857 oocoutW(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - maximum number of toys reached " << std::endl;
879 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - reached accuracy " <<
limitErr <<
" below "
887 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" << limit <<
" when trying to find limit." << std::endl;
892 if (
clsMid.second == -1) {
893 std::cerr <<
"Hypotest failed" << std::endl;
905 if (
fVerbose > 0) std::cout <<
"Trying to move the interval edges closer" << std::endl;
912 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" <<
rMin <<
" when trying to find limit from below." << std::endl;
922 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" <<
rMin <<
" when trying to find limit from above." << std::endl;
936 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Before fit --- \n";
937 std::cout <<
"Limit: " <<
r->GetName() <<
" < " << limit <<
" +/- " <<
limitErr <<
" [" <<
rMin <<
", " <<
rMax <<
"]\n";
964 limit =
expoFit.GetParameter(2);
983 double xmin =
r->getMin();
984 double xmax =
r->getMax();
1003 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Result: \n"
1004 <<
"\tLimit: " <<
r->GetName() <<
" < " << limit <<
" +/- " <<
limitErr <<
" @ " << (1-
fSize) * 100 <<
"% CL\n";
1029 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::GetLowerLimitDistribution(false) - result not existing\n";
1056 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::GetUpperLimitDistribution(false) - result not existing\n";
1093 if (!
sbModel->GetParametersOfInterest())
return nullptr;
1098 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - background snapshot not existing"
1099 <<
" assume is for POI = 0" << std::endl;
1109 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - no toy MC sampler existing" << std::endl;
1120 if (!
sbModel->GetPdf()->canBeExtended())
1129 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - cannot return p values distribution with the auto scan" << std::endl;
1137 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - result is not existing and number of point to scan is not set"
1150 for (
int i = 0; i <
nPoints; ++i) {
1159 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter - rebuilding the p value distributions by generating ntoys = "
1160 <<
nToys << std::endl;
1163 oocoutI(
nullptr,InputArguments) <<
"Rebuilding using parameter of interest point: ";
1165 if (
sbModel->GetNuisanceParameters() ) {
1166 oocoutI(
nullptr,InputArguments) <<
"And using nuisance parameters: ";
1178 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - RebuildDistributions - Error opening file " <<
outputfile
1179 <<
" - the resulting limits will not be stored" << std::endl;
1182 TH1D *
hL =
new TH1D(
"lowerLimitDist",
"Rebuilt lower limit distribution",100,1.,0.);
1183 TH1D *
hU =
new TH1D(
"upperLimitDist",
"Rebuilt upper limit distribution",100,1.,0.);
1184 TH1D *
hN =
new TH1D(
"nObs",
"Observed events",100,1.,0.);
1187 std::vector<TH1*>
hCLb;
1188 std::vector<TH1*>
hCLsb;
1189 std::vector<TH1*>
hCLs;
1191 for (
int i = 0; i <
nPoints; ++i) {
1202 oocoutP(
nullptr,
Eval) <<
"\nHypoTestInverter - RebuildDistributions - running toy # " <<
itoy <<
" / "
1203 <<
nToys << std::endl;
1206 std::cout <<
"\n\nshnapshot of s+b model \n";
1207 sbModel->GetSnapshot()->Print(
"v");
1221 double nObs =
bkgdata->sumEntries();
1223 if (
bkgdata->numEntries() ==1 && !
bModel->GetPdf()->canBeExtended()) {
1224 oocoutP(
nullptr,Generation) <<
"Generate observables are : ";
1228 for (std::size_t i = 0; i <
genObs.size(); ++i) {
1230 if (
x) nObs +=
x->getVal();
1240 auto gobs =
bModel->GetPdf()->getVariables()->selectCommon(*
sbModel->GetGlobalObservables() );
1245 if (
r ==
nullptr)
continue;
1249 hU->Fill(
r->UpperLimit() );
1250 hL->Fill(
r->LowerLimit() );
1253 std::cout <<
"The computed upper limit for toy #" <<
itoy <<
" is " <<
value << std::endl;
1265 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: skip extra points" << std::endl;
1267 else if (
nPoints >
r->ArraySize()) {
1268 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: missing some points" << std::endl;
1283 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: missing result for point: x = "
1307 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter: storing rebuilt p values " << std::endl;
1336 const char *
disName = (
isUpper) ?
"upperLimit_dist" :
"lowerLimit_dist";
bool fVerbose
verbosity flag
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 r
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 result
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
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
RooAbsArg * first() const
Abstract base class for binned and unbinned datasets.
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.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
static double uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to '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.
const ModelConfig * GetNullModel(void) const
void SetData(RooAbsData &data) override
Set the DataSet.
const ModelConfig * GetAlternateModel(void) const
TestStatSampler * GetTestStatSampler(void) const
Returns instance of TestStatSampler.
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...
SamplingDistribution * GetLowerLimitDistribution() const
get expected lower limit distributions implemented using interpolation The size for the sampling dist...
HypoTestResult * GetResult(int index) const
return a pointer to the i^th result object
int ArraySize() const
number of entries in the results array
std::vector< double > fXValues
void UseCLs(bool on=true)
flag to switch between using CLsb (default) or CLs as confidence level
double GetXValue(int index) const
function to return the value of the parameter of interest for the i^th entry in the results
double GetLastYError() const
TList fExpPValues
list of expected sampling distribution for each point
bool fIsTwoSided
two sided scan (look for lower/upper limit)
double GetLastYValue() const
TList fYObjects
list of HypoTestResult for each point
void SetConfidenceLevel(double cl) override
set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
SamplingDistribution * GetUpperLimitDistribution() const
get expected upper limit distributions implemented using interpolation
A class for performing a hypothesis test inversion by scanning the hypothesis test results of a HypoT...
static void CheckInputModels(const HypoTestCalculatorGeneric &hc, const RooRealVar &scanVar)
check the model given the given hypotestcalculator
RooRealVar * fScannedVariable
pointer to the constrained variable
static double fgCLAccuracy
std::unique_ptr< HypoTestCalculatorGeneric > fHC
! pointer to the generic hypotest calculator used
bool RunLimit(double &limit, double &limitErr, double absTol=0, double relTol=0, const double *hint=nullptr) const
Run an automatic scan until the desired accuracy is reached.
void SetData(RooAbsData &) override
Set the DataSet ( add to the workspace if not already there ?)
HypoTestInverterResult * fResults
pointer to the result
SamplingDistribution * RebuildDistributions(bool isUpper=true, int nToys=100, TList *clsDist=nullptr, TList *clsbDist=nullptr, TList *clbDist=nullptr, const char *outputfile="HypoTestInverterRebuiltDist.root")
function to rebuild the distributions
int fMaxToys
maximum number of toys to run
HypoTestInverter()
default constructor (used only for I/O)
~HypoTestInverter() override
destructor
double ConfidenceLevel() const override
Get the Confidence level for the test.
bool SetTestStatistic(TestStatistic &stat)
set the test statistic
HypoTestInverterResult * GetInterval() const override
Run a fixed scan or the automatic scan depending on the configuration.
SamplingDistribution * GetUpperLimitDistribution(bool rebuild=false, int nToys=100)
get the distribution of lower limit if rebuild = false (default) it will re-use the results of the sc...
static unsigned int fgNToys
void Clear()
delete contained result and graph
TestStatistic * GetTestStatistic() const
get the test statistic
static std::string fgAlgo
std::unique_ptr< TGraphErrors > fLimitPlot
! plot of limits
bool RunFixedScan(int nBins, double xMin, double xMax, bool scanLog=false) const
Run a fixed scan.
bool RunOnePoint(double thisX, bool adaptive=false, double clTarget=-1) const
run only one point at the given POI value
ECalculatorType fCalcType
SamplingDistribution * GetLowerLimitDistribution(bool rebuild=false, int nToys=100)
get the upper/lower limit distribution
HypoTestInverter & operator=(const HypoTestInverter &rhs)
assignment
HypoTestCalculatorGeneric * fCalculator0
pointer to the calculator passed in the constructor
static double fgRelAccuracy
void CreateResults() const
create a new HypoTestInverterResult to hold all computed results
static double fgAbsAccuracy
static RooRealVar * GetVariableToScan(const HypoTestCalculatorGeneric &hc)
helper functions
HypoTestResult * Eval(HypoTestCalculatorGeneric &hc, bool adaptive, double clsTarget) const
run the hybrid at a single point
HypoTestResult is a base class for results from hypothesis tests.
IntervalCalculator is an interface class for a tools which produce RooStats ConfIntervals.
< A class that holds configuration information for a model using a workspace as a store
ProfileLikelihoodTestStat is an implementation of the TestStatistic interface that calculates the pro...
This class simply holds a sampling distribution of some test statistic.
double fUpperLimit
upper interval limit
double fLowerLimit
lower interval limit
TestStatSampler is an interface class for a tools which produce RooStats SamplingDistributions.
virtual TestStatistic * GetTestStatistic() const =0
Get the TestStatistic.
virtual void SetTestStatistic(TestStatistic *testStatistic)=0
Set the TestStatistic (want the argument to be a function of the data & parameter points.
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
ToyMCSampler is an implementation of the TestStatSampler interface.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
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.
1-D histogram with a double per channel (see TH1 documentation)
Use the TLine constructor to create a simple line.
virtual TLine * DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
void Add(TObject *obj) override
TObject * Remove(TObject *obj) override
Remove object from the list.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
@ kOverwrite
overwrite existing object with same name
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Namespace for the RooStats classes.
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
Bool_t AreEqualRel(Double_t af, Double_t bf, Double_t relPrec)
Comparing floating points.
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Comparing floating points.
static void SetToys(HypoTestType *h, int toyNull, int toyAlt)