Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
HypoTestInverter.h
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOSTATS_HypoTestInverter
12#define ROOSTATS_HypoTestInverter
13
14
16
17
19
20class RooRealVar;
21class TGraphErrors;
22
23#include <memory>
24#include <string>
25
26namespace RooStats {
27
28 //class HypoTestCalculator;
29 class HybridCalculator;
30 class FrequentistCalculator;
31 class AsymptoticCalculator;
32 class HypoTestCalculatorGeneric;
33 class TestStatistic;
34
35
37
38public:
39
41
42 /// default constructor (used only for I/O)
44
45 /// constructor from generic hypotest calculator
47 RooRealVar* scannedVariable =nullptr,
48 double size = 0.05) ;
49
50
51 /// constructor from hybrid calculator
53 RooRealVar* scannedVariable = nullptr,
54 double size = 0.05) ;
55
56 /// constructor from frequentist calculator
58 RooRealVar* scannedVariable,
59 double size = 0.05) ;
60
61 /// constructor from asymptotic calculator
63 RooRealVar* scannedVariable,
64 double size = 0.05) ;
65
66 /// constructor from two ModelConfigs (first sb (the null model) then b (the alt model)
67 /// creating a calculator inside
69 RooRealVar * scannedVariable = nullptr, ECalculatorType type = kFrequentist,
70 double size = 0.05) ;
71
72
73 HypoTestInverterResult* GetInterval() const override;
74
75 void Clear();
76
77 /// Set up to perform a fixed scan.
78 /// \param[in] nBins Number of points to scan.
79 /// \param[in] xMin Lower limit of range to be scanned.
80 /// \param[in] xMax Upper limit of range to be scanned.
81 /// \param[in] scanLog Run in logarithmic steps along x.
82 void SetFixedScan(int nBins, double xMin = 1, double xMax = -1, bool scanLog = false ) {
83 fNBins = nBins;
84 fXmin = xMin; fXmax = xMax;
85 fScanLog = scanLog;
86 }
87
88 /// Use automatic scanning, i.e. adaptive
90
91 /// Run a fixed scan.
92 /// \param[in] nBins Number of points to scan.
93 /// \param[in] xMin Lower limit of range to be scanned.
94 /// \param[in] xMax Upper limit of range to be scanned.
95 /// \param[in] scanLog Run in logarithmic steps along x.
96 bool RunFixedScan( int nBins, double xMin, double xMax, bool scanLog = false ) const;
97
98 bool RunOnePoint( double thisX, bool adaptive = false, double clTarget = -1 ) const;
99
100 //bool RunAutoScan( double xMin, double xMax, double target, double epsilon=nullptr.005, unsigned int numAlgorithm=nullptr );
101
102 bool RunLimit(double &limit, double &limitErr, double absTol = 0, double relTol = 0, const double *hint=nullptr) const;
103
104 void UseCLs( bool on = true) { fUseCLs = on; if (fResults) fResults->UseCLs(on); }
105
106 void SetData(RooAbsData &) override;
107
108 void SetModel(const ModelConfig &) override { } // not needed
109
110 /// set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
111 void SetTestSize(double size) override {fSize = size; if (fResults) fResults->SetTestSize(size); }
112 /// set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
113 void SetConfidenceLevel(double cl) override {fSize = 1.-cl; if (fResults) fResults->SetConfidenceLevel(cl); }
114 /// Get the size of the test (eg. rate of Type I error)
115 double Size() const override {return fSize;}
116 /// Get the Confidence level for the test
117 double ConfidenceLevel() const override {return 1.-fSize;}
118
119 /// destructor
120 ~HypoTestInverter() override ;
121
122 /// retrieved a reference to the internally used HypoTestCalculator
123 /// it might be invalid when the class is deleted
125
126 /// get the upper/lower limit distribution
127 SamplingDistribution * GetLowerLimitDistribution(bool rebuild=false, int nToys = 100);
128 SamplingDistribution * GetUpperLimitDistribution(bool rebuild=false, int nToys = 100);
129
130 /// function to rebuild the distributions
131 SamplingDistribution * RebuildDistributions(bool isUpper=true, int nToys = 100,
132 TList *clsDist = nullptr, TList *clsbDist = nullptr, TList *clbDist = nullptr, const char *outputfile = "HypoTestInverterRebuiltDist.root");
133
134 /// get the test statistic
136
137 /// set the test statistic
139
140 /// set verbose level (0,1,2)
141 void SetVerbose(int level=1) { fVerbose = level; }
142
143 /// set maximum number of toys
144 void SetMaximumToys(int ntoys) { fMaxToys = ntoys;}
145
146 /// set numerical error in test statistic evaluation (default is zero)
147 void SetNumErr(double err) { fNumErr = err; }
148
149 /// set flag to close proof for every new run
150 static void SetCloseProof(bool flag);
151
152
153protected:
154
155 /// copy c-tor
157
158 /// assignment
160
161 void CreateResults() const;
162
163 /// run the hybrid at a single point
164 HypoTestResult * Eval( HypoTestCalculatorGeneric &hc, bool adaptive , double clsTarget) const;
165
166 /// helper functions
168 static void CheckInputModels(const HypoTestCalculatorGeneric &hc, const RooRealVar & scanVar);
169
170private:
171
172
173 static unsigned int fgNToys;
174 static double fgCLAccuracy;
175 static double fgAbsAccuracy;
176 static double fgRelAccuracy;
177 static bool fgCloseProof;
178 static std::string fgAlgo;
179
180 // graph, used to compute the limit, not just for plotting!
181 mutable std::unique_ptr<TGraphErrors> fLimitPlot; ///<! plot of limits
182
183
184 // performance counter: remember how many toys have been thrown
185 mutable int fTotalToysRun;
186 int fMaxToys; ///< maximum number of toys to run
187
188 HypoTestCalculatorGeneric* fCalculator0; ///< pointer to the calculator passed in the constructor
189 std::unique_ptr<HypoTestCalculatorGeneric> fHC; ///<! pointer to the generic hypotest calculator used
190 RooRealVar* fScannedVariable; ///< pointer to the constrained variable
191 mutable HypoTestInverterResult* fResults; ///< pointer to the result
192
195 double fSize;
199 double fXmin;
200 double fXmax;
201 double fNumErr;
202
203protected:
204
205 ClassDefOverride(HypoTestInverter,4) // HypoTestInverter class
206
207};
208
209}
210
211#endif
#define b(i)
Definition RSha256.hxx:100
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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 on
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
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
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.
HypoTestInverterResult class holds the array of hypothesis test results and compute a confidence inte...
virtual void SetTestSize(double size)
set the size of the test (rate of Type I error) (eg. 0.05 for a 95% Confidence Interval)
void UseCLs(bool on=true)
flag to switch between using CLsb (default) or CLs as confidence level
void SetConfidenceLevel(double cl) override
set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
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
void SetTestSize(double size) override
set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
void SetVerbose(int level=1)
set verbose level (0,1,2)
RooRealVar * fScannedVariable
pointer to the constrained variable
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 Size() const override
Get the size of the test (eg. rate of Type I error)
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
void SetConfidenceLevel(double cl) override
set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
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...
void SetMaximumToys(int ntoys)
set maximum number of toys
static unsigned int fgNToys
HypoTestCalculatorGeneric * GetHypoTestCalculator() const
retrieved a reference to the internally used HypoTestCalculator it might be invalid when the class is...
void Clear()
delete contained result and graph
void SetModel(const ModelConfig &) override
Set the Model.
void SetNumErr(double err)
set numerical error in test statistic evaluation (default is zero)
void SetAutoScan()
Use automatic scanning, i.e. adaptive.
TestStatistic * GetTestStatistic() const
get the test statistic
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
SamplingDistribution * GetLowerLimitDistribution(bool rebuild=false, int nToys=100)
get the upper/lower limit distribution
HypoTestInverter & operator=(const HypoTestInverter &rhs)
assignment
void SetFixedScan(int nBins, double xMin=1, double xMax=-1, bool scanLog=false)
Set up to perform a fixed scan.
HypoTestCalculatorGeneric * fCalculator0
pointer to the calculator passed in the constructor
void CreateResults() const
create a new HypoTestInverterResult to hold all computed results
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...
Definition ModelConfig.h:35
This class simply holds a sampling distribution of some test statistic.
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
A TGraphErrors is a TGraph with error bars.
A doubly linked list.
Definition TList.h:38
Namespace for the RooStats classes.
Definition Asimov.h:19