88template<
class HypoTestType>
111 const RooArgSet * poi =
mc->GetParametersOfInterest();
115 mc =
hc.GetAlternateModel();
117 const RooArgSet * poi =
mc->GetParametersOfInterest();
131 oocoutF(
nullptr,InputArguments) <<
"HypoTestInverter - model are not existing" << std::endl;
134 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter ---- Input models: \n"
135 <<
"\t\t using as S+B (null) model : "
137 <<
"\t\t using as B (alternate) model : "
138 <<
modelB->GetName() <<
"\n" << std::endl;
144 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - B model has no pdf or observables defined" << std::endl;
149 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - pdf of B model has no parameters" << std::endl;
156 oocoutW(
nullptr, InputArguments)
157 <<
"HypoTestInverter - using a B model with POI " <<
scanVariable.GetName() <<
" not equal to zero "
158 <<
" user must check input model configurations " << endl;
170 fCalculator0(nullptr),
171 fScannedVariable(nullptr),
177 fCalcType(kUndefined),
178 fNBins(0), fXmin(1), fXmax(1),
196 fCalculator0(nullptr),
203 fCalcType(kUndefined),
204 fNBins(0), fXmin(1), fXmax(1),
212 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
235 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Type of hypotest calculator is not supported " <<std::endl;
258 fNBins(0), fXmin(1), fXmax(1),
266 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
290 fCalcType(kFrequentist),
291 fNBins(0), fXmin(1), fXmax(1),
299 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
323 fCalcType(kAsymptotic),
324 fNBins(0), fXmin(1), fXmax(1),
332 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
349 fCalculator0(nullptr),
357 fNBins(0), fXmin(1), fXmax(1),
369 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - Cannot guess the variable to scan " << std::endl;
384 fCalculator0(nullptr), fScannedVariable(nullptr),
397 if (
this == &
rhs)
return *
this;
465 TString title =
"HypoTestInverter Result For ";
496 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - return an already existing interval " << std::endl;
501 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - run a fixed scan" << std::endl;
504 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - error running a fixed scan " << std::endl;
507 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - run an automatic scan" << std::endl;
512 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::GetInterval - error running an auto scan " << std::endl;
538 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::Eval - HypoTest failed" << std::endl;
551 if (
hcResult->GetPValueIsRightTail()) {
569 std::unique_ptr<HypoTestResult>
more(
hc.GetHypoTest());
586 "\tCLsplusb = " <<
hcResult->CLsplusb() <<
" +/- " <<
hcResult->CLsplusbError() <<
"\n" <<
619 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - Please provide nBins>0\n";
623 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - nBins==1 -> I will run for xMin (" <<
xMin <<
")\n";
626 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMin==xMax -> I will enforce nBins==1\n";
630 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - Please provide xMin ("
631 <<
xMin <<
") smaller than xMax (" <<
xMax <<
")\n";
637 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMin < lower bound, using xmin = "
638 <<
xMin << std::endl;
642 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RunFixedScan - xMax > upper bound, using xmax = "
643 <<
xMax << std::endl;
647 oocoutE(
nullptr, InputArguments) <<
"HypoTestInverter::RunFixedScan - cannot go in log steps if xMin <= 0" << std::endl;
652 for (
int i=0; i<nBins; i++) {
665 if ( status==
false ) {
666 oocoutW(
nullptr,
Eval) <<
"HypoTestInverter::RunFixedScan - The hypo test for point " <<
thisX <<
" failed. Skipping." << std::endl;
683 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RunOnePoint - Out of range: using the lower bound "
685 <<
" on the scanned variable rather than " <<
rVal<<
"\n";
691 oocoutE(
nullptr, InputArguments) <<
"HypoTestInverter::RunOnePoint - Out of range: using the upper bound "
737 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunOnePoint - Merge with previous result for "
745 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunOnePoint - replace previous empty result\n";
784 if ((
hint !=
nullptr) && (*
hint >
r->getMin())) {
785 r->setMax(std::min<double>(3.0 * (*
hint),
r->getMax()));
786 r->setMin(std::max<double>(0.3 * (*
hint),
r->getMin()));
787 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter::RunLimit - Use hint value " << *
hint
788 <<
" search in interval " <<
r->getMin() <<
" , " <<
r->getMax() << std::endl;
795 typedef std::pair<double,double>
CLs_t;
800 double rMin =
r->getMin();
801 double rMax =
r->getMax();
808 fLimitPlot = std::make_unique<TGraphErrors>();
810 if (
fVerbose > 0) std::cout <<
"Search for upper limit to the limit" << std::endl;
813 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at upper limit of scan range: " <<
rMax << std::endl;
821 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Cannot determine upper limit of scan range. At " <<
r->GetName()
822 <<
" = " <<
rMax <<
" still getting "
823 << (
fUseCLs ?
"CLs" :
"CLsplusb") <<
" = " <<
clsMax.first << std::endl;
828 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Search for lower limit to the limit" << std::endl;
836 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at lower limit of scan range: " <<
rMin << std::endl;
849 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypotest failed at lower limit of scan range: " <<
rMin << std::endl;
857 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Cannot determine lower limit of scan range. At " <<
r->GetName()
858 <<
" = " <<
rMin <<
" still get " << (
fUseCLs ?
"CLs" :
"CLsplusb")
859 <<
" = " <<
clsMin.first << std::endl;
867 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Now doing proper bracketing & bisection" << std::endl;
872 oocoutW(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - maximum number of toys reached " << std::endl;
894 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - reached accuracy " <<
limitErr <<
" below "
902 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" << limit <<
" when trying to find limit." << std::endl;
907 if (
clsMid.second == -1) {
908 std::cerr <<
"Hypotest failed" << std::endl;
920 if (
fVerbose > 0) std::cout <<
"Trying to move the interval edges closer" << std::endl;
927 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" <<
rMin <<
" when trying to find limit from below." << std::endl;
937 oocoutE(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Hypo test failed at x=" <<
rMin <<
" when trying to find limit from above." << std::endl;
951 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Before fit --- \n";
952 std::cout <<
"Limit: " <<
r->GetName() <<
" < " << limit <<
" +/- " <<
limitErr <<
" [" <<
rMin <<
", " <<
rMax <<
"]\n";
979 limit =
expoFit.GetParameter(2);
998 double xmin =
r->getMin();
999 double xmax =
r->getMax();
1018 oocoutI(
nullptr,
Eval) <<
"HypoTestInverter::RunLimit - Result: \n"
1019 <<
"\tLimit: " <<
r->GetName() <<
" < " << limit <<
" +/- " <<
limitErr <<
" @ " << (1-
fSize) * 100 <<
"% CL\n";
1044 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::GetLowerLimitDistribution(false) - result not existing\n";
1071 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::GetUpperLimitDistribution(false) - result not existing\n";
1108 if (!
sbModel->GetParametersOfInterest())
return nullptr;
1113 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - background snapshot not existing"
1114 <<
" assume is for POI = 0" << std::endl;
1124 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - no toy MC sampler existing" << std::endl;
1135 if (!
sbModel->GetPdf()->canBeExtended())
1144 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter::RebuildDistribution - cannot return p values distribution with the auto scan" << std::endl;
1152 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - result is not existing and number of point to scan is not set"
1165 for (
int i = 0; i <
nPoints; ++i) {
1174 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter - rebuilding the p value distributions by generating ntoys = "
1175 <<
nToys << std::endl;
1178 oocoutI(
nullptr,InputArguments) <<
"Rebuilding using parameter of interest point: ";
1180 if (
sbModel->GetNuisanceParameters() ) {
1181 oocoutI(
nullptr,InputArguments) <<
"And using nuisance parameters: ";
1193 oocoutE(
nullptr,InputArguments) <<
"HypoTestInverter - RebuildDistributions - Error opening file " <<
outputfile
1194 <<
" - the resulting limits will not be stored" << std::endl;
1197 TH1D *
hL =
new TH1D(
"lowerLimitDist",
"Rebuilt lower limit distribution",100,1.,0.);
1198 TH1D *
hU =
new TH1D(
"upperLimitDist",
"Rebuilt upper limit distribution",100,1.,0.);
1199 TH1D *
hN =
new TH1D(
"nObs",
"Observed events",100,1.,0.);
1202 std::vector<TH1*>
hCLb;
1203 std::vector<TH1*>
hCLsb;
1204 std::vector<TH1*>
hCLs;
1206 for (
int i = 0; i <
nPoints; ++i) {
1217 oocoutP(
nullptr,
Eval) <<
"\nHypoTestInverter - RebuildDistributions - running toy # " <<
itoy <<
" / "
1218 <<
nToys << std::endl;
1221 printf(
"\n\nshnapshot of s+b model \n");
1222 sbModel->GetSnapshot()->Print(
"v");
1236 double nObs =
bkgdata->sumEntries();
1238 if (
bkgdata->numEntries() ==1 && !
bModel->GetPdf()->canBeExtended()) {
1239 oocoutP(
nullptr,Generation) <<
"Generate observables are : ";
1243 for (std::size_t i = 0; i <
genObs.size(); ++i) {
1245 if (
x) nObs +=
x->getVal();
1255 auto gobs =
bModel->GetPdf()->getVariables()->selectCommon(*
sbModel->GetGlobalObservables() );
1260 if (
r ==
nullptr)
continue;
1264 hU->Fill(
r->UpperLimit() );
1265 hL->Fill(
r->LowerLimit() );
1268 std::cout <<
"The computed upper limit for toy #" <<
itoy <<
" is " <<
value << std::endl;
1280 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: skip extra points" << std::endl;
1282 else if (
nPoints >
r->ArraySize()) {
1283 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: missing some points" << std::endl;
1298 oocoutW(
nullptr,InputArguments) <<
"HypoTestInverter: missing result for point: x = "
1322 oocoutI(
nullptr,InputArguments) <<
"HypoTestInverter: storing rebuilt p values " << std::endl;
1351 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.
static void SetCloseProof(bool flag)
set flag to close proof for every new run
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...
static void CloseProof(Option_t *option="s")
close all proof connections
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)