83template<
class HypoTestType>
99 const RooArgSet * poi =
mc->GetParametersOfInterest();
103 mc =
hc.GetAlternateModel();
105 const RooArgSet * poi =
mc->GetParametersOfInterest();
119 oocoutF(
nullptr,InputArguments) <<
"HypoTestInverter - model are not existing" << std::endl;
122 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter ---- Input models: \n"
123 <<
"\t\t using as S+B (null) model : "
125 <<
"\t\t using as B (alternate) model : "
126 <<
modelB->GetName() <<
"\n" << std::endl;
132 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - B model has no pdf or observables defined" << std::endl;
137 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - pdf of B model has no parameters" << std::endl;
144 oocoutW(
nullptr, InputArguments)
145 <<
"HypoTestInverter - using a B model with POI " <<
scanVariable.GetName() <<
" not equal to zero "
146 <<
" user must check input model configurations " << std::endl;
158 fCalculator0(nullptr),
159 fScannedVariable(nullptr),
165 fCalcType(kUndefined),
166 fNBins(0), fXmin(1), fXmax(1),
184 fCalculator0(nullptr),
191 fCalcType(kUndefined),
192 fNBins(0), fXmin(1), fXmax(1),
200 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
223 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Type of hypotest calculator is not supported " <<std::endl;
246 fNBins(0), fXmin(1), fXmax(1),
254 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
278 fCalcType(kFrequentist),
279 fNBins(0), fXmin(1), fXmax(1),
287 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
311 fCalcType(kAsymptotic),
312 fNBins(0), fXmin(1), fXmax(1),
320 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
337 fCalculator0(nullptr),
345 fNBins(0), fXmin(1), fXmax(1),
357 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
372 fCalculator0(nullptr), fScannedVariable(nullptr),
385 if (
this == &
rhs)
return *
this;
453 TString title =
"HypoTestInverter Result For ";
484 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - return an already existing interval " << std::endl;
489 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - run a fixed scan" << std::endl;
492 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - error running a fixed scan " << std::endl;
495 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - run an automatic scan" << std::endl;
500 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - error running an auto scan " << std::endl;
524 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::Eval - HypoTest failed" << std::endl;
537 if (
hcResult->GetPValueIsRightTail()) {
555 std::unique_ptr<HypoTestResult>
more(
hc.GetHypoTest());
572 "\tCLsplusb = " <<
hcResult->CLsplusb() <<
" +/- " <<
hcResult->CLsplusbError() <<
"\n" <<
605 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - Please provide nBins>0\n";
609 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - nBins==1 -> I will run for xMin (" <<
xMin <<
")\n";
612 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMin==xMax -> I will enforce nBins==1\n";
616 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - Please provide xMin ("
617 <<
xMin <<
") smaller than xMax (" <<
xMax <<
")\n";
623 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMin < lower bound, using xmin = "
624 <<
xMin << std::endl;
628 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMax > upper bound, using xmax = "
629 <<
xMax << std::endl;
633 oocoutE(
nullptr, InputArguments) <<
"HypoTestInverter::RunFixedScan - cannot go in log steps if xMin <= 0" << std::endl;
638 for (
int i=0; i<nBins; i++) {
651 if ( status==
false ) {
652 oocoutW(
nullptr,
Eval) <<
"HypoTestInverter::RunFixedScan - The hypo test for point " <<
thisX <<
" failed. Skipping." << std::endl;
669 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunOnePoint - Out of range: using the lower bound "
671 <<
" on the scanned variable rather than " <<
rVal<<
"\n";
677 oocoutE(
nullptr, InputArguments) <<
"HypoTestInverter::RunOnePoint - Out of range: using the upper bound "
723 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunOnePoint - Merge with previous result for "
731 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunOnePoint - replace previous empty result\n";
770 if ((
hint !=
nullptr) && (*
hint >
r->getMin())) {
771 r->setMax(std::min<double>(3.0 * (*
hint),
r->getMax()));
772 r->setMin(std::max<double>(0.3 * (*
hint),
r->getMin()));
773 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter::RunLimit - Use hint value " << *
hint
774 <<
" search in interval " <<
r->getMin() <<
" , " <<
r->getMax() << std::endl;
781 typedef std::pair<double,double>
CLs_t;
786 double rMin =
r->getMin();
787 double rMax =
r->getMax();
794 fLimitPlot = std::make_unique<TGraphErrors>();
796 if (
fVerbose > 0) std::cout <<
"Search for upper limit to the limit" << std::endl;
799 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at upper limit of scan range: " <<
rMax << std::endl;
807 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Cannot determine upper limit of scan range. At " <<
r->GetName()
808 <<
" = " <<
rMax <<
" still getting "
809 << (
fUseCLs ?
"CLs" :
"CLsplusb") <<
" = " <<
clsMax.first << std::endl;
814 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Search for lower limit to the limit" << std::endl;
822 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at lower limit of scan range: " <<
rMin << std::endl;
835 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at lower limit of scan range: " <<
rMin << std::endl;
843 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Cannot determine lower limit of scan range. At " <<
r->GetName()
844 <<
" = " <<
rMin <<
" still get " << (
fUseCLs ?
"CLs" :
"CLsplusb")
845 <<
" = " <<
clsMin.first << std::endl;
853 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Now doing proper bracketing & bisection" << std::endl;
858 oocoutW(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - maximum number of toys reached " << std::endl;
880 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - reached accuracy " <<
limitErr <<
" below "
888 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" << limit <<
" when trying to find limit." << std::endl;
893 if (
clsMid.second == -1) {
894 std::cerr <<
"Hypotest failed" << std::endl;
906 if (
fVerbose > 0) std::cout <<
"Trying to move the interval edges closer" << std::endl;
913 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" <<
rMin <<
" when trying to find limit from below." << std::endl;
923 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" <<
rMin <<
" when trying to find limit from above." << std::endl;
937 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Before fit --- \n";
938 std::cout <<
"Limit: " <<
r->GetName() <<
" < " << limit <<
" +/- " <<
limitErr <<
" [" <<
rMin <<
", " <<
rMax <<
"]\n";
965 limit =
expoFit.GetParameter(2);
984 double xmin =
r->getMin();
985 double xmax =
r->getMax();
1004 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Result: \n"
1005 <<
"\tLimit: " <<
r->GetName() <<
" < " << limit <<
" +/- " <<
limitErr <<
" @ " << (1-
fSize) * 100 <<
"% CL\n";
1030 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::GetLowerLimitDistribution(false) - result not existing\n";
1057 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::GetUpperLimitDistribution(false) - result not existing\n";
1094 if (!
sbModel->GetParametersOfInterest())
return nullptr;
1099 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - background snapshot not existing"
1100 <<
" assume is for POI = 0" << std::endl;
1110 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - no toy MC sampler existing" << std::endl;
1121 if (!
sbModel->GetPdf()->canBeExtended())
1130 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - cannot return p values distribution with the auto scan" << std::endl;
1138 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - result is not existing and number of point to scan is not set"
1151 for (
int i = 0; i <
nPoints; ++i) {
1160 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter - rebuilding the p value distributions by generating ntoys = "
1161 <<
nToys << std::endl;
1164 oocoutI(
nullptr,InputArguments) <<
"Rebuilding using parameter of interest point: ";
1166 if (
sbModel->GetNuisanceParameters() ) {
1167 oocoutI(
nullptr,InputArguments) <<
"And using nuisance parameters: ";
1179 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - RebuildDistributions - Error opening file " <<
outputfile
1180 <<
" - the resulting limits will not be stored" << std::endl;
1183 TH1D *
hL =
new TH1D(
"lowerLimitDist",
"Rebuilt lower limit distribution",100,1.,0.);
1184 TH1D *
hU =
new TH1D(
"upperLimitDist",
"Rebuilt upper limit distribution",100,1.,0.);
1185 TH1D *
hN =
new TH1D(
"nObs",
"Observed events",100,1.,0.);
1188 std::vector<TH1*>
hCLb;
1189 std::vector<TH1*>
hCLsb;
1190 std::vector<TH1*>
hCLs;
1192 for (
int i = 0; i <
nPoints; ++i) {
1203 oocoutP(
nullptr,
Eval) <<
"\nHypoTestInverter - RebuildDistributions - running toy # " <<
itoy <<
" / "
1204 <<
nToys << std::endl;
1207 std::cout <<
"\n\nshnapshot of s+b model \n";
1208 sbModel->GetSnapshot()->Print(
"v");
1222 double nObs =
bkgdata->sumEntries();
1224 if (
bkgdata->numEntries() ==1 && !
bModel->GetPdf()->canBeExtended()) {
1225 oocoutP(
nullptr,Generation) <<
"Generate observables are : ";
1229 for (std::size_t i = 0; i <
genObs.size(); ++i) {
1231 if (
x) nObs +=
x->getVal();
1241 auto gobs =
bModel->GetPdf()->getVariables()->selectCommon(*
sbModel->GetGlobalObservables() );
1246 if (
r ==
nullptr)
continue;
1250 hU->Fill(
r->UpperLimit() );
1251 hL->Fill(
r->LowerLimit() );
1254 std::cout <<
"The computed upper limit for toy #" <<
itoy <<
" is " <<
value << std::endl;
1266 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: skip extra points" << std::endl;
1268 else if (
nPoints >
r->ArraySize()) {
1269 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: missing some points" << std::endl;
1284 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: missing result for point: x = "
1308 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter: storing rebuilt p values " << std::endl;
1337 const char *
disName = (
isUpper) ?
"upperLimit_dist" :
"lowerLimit_dist";
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.
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
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)