Logo ROOT   6.08/07
Reference Guide
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 
15 
16 #ifndef ROOSTATS_IntervalCalculator
18 #endif
19 
20 
21 #ifndef ROOSTATS_HypoTestInverterResult
23 #endif
24 
25 class RooRealVar;
26 class TGraphErrors;
27 
28 #include <memory>
29 
30 
31 
32 
33 namespace RooStats {
34 
35  //class HypoTestCalculator;
36  class HybridCalculator;
37  class FrequentistCalculator;
38  class AsymptoticCalculator;
39  class HypoTestCalculatorGeneric;
40  class TestStatistic;
41 
42  /**
43 
44  \ingroup Roostats
45 
46  HypoTestInverter class for performing an hypothesis test inversion by scanning the hypothesis test results of an
47  HypoTestCalculator for various values of the parameter of interest. By looking at the confidence level curve of
48  the result an upper limit, where it intersects the desired confidence level, can be derived.
49  The class implements the RooStats::IntervalCalculator interface and returns an RooStats::HypoTestInverterResult class.
50  The result is a SimpleInterval, which via the method UpperLimit returns to the user the upper limit value.
51 
52 The HypoTestInverter implements various option for performing the scan. HypoTestInverter::RunFixedScan will scan using a fixed grid the parameter of interest. HypoTestInverter::RunAutoScan will perform an automatic scan to find optimally the curve and it will stop until the desired precision is obtained.
53 The confidence level value at a given point can be done via HypoTestInverter::RunOnePoint.
54 The class can scan the CLs+b values or alternativly CLs (if the method HypoTestInverter::UseCLs has been called).
55 
56 
57  Contributions to this class have been written by Giovanni Petrucciani and Annapaola Decosa
58 **/
59 
60 
62 
63 public:
64 
66 
67  // default constructor (used only for I/O)
69 
70  // constructor from generic hypotest calculator
72  RooRealVar* scannedVariable =0,
73  double size = 0.05) ;
74 
75 
76  // constructor from hybrid calculator
78  RooRealVar* scannedVariable = 0,
79  double size = 0.05) ;
80 
81  // constructor from frequentist calculator
83  RooRealVar* scannedVariable,
84  double size = 0.05) ;
85 
86  // constructor from asymptotic calculator
88  RooRealVar* scannedVariable,
89  double size = 0.05) ;
90 
91  // constructor from two ModelConfigs (first sb (the null model) then b (the alt model)
92  // creating a calculator inside
94  RooRealVar * scannedVariable = 0, ECalculatorType type = kFrequentist,
95  double size = 0.05) ;
96 
97 
98  virtual HypoTestInverterResult* GetInterval() const;
99 
100  void Clear();
101 
102  // set for a fixed scan in nbins
103  void SetFixedScan(int nBins, double xMin = 1, double xMax = -1, bool scanLog = false ) {
104  fNBins = nBins;
105  fXmin = xMin; fXmax = xMax;
106  fScanLog = scanLog;
107  }
108 
109  // set auto scan (default)
110  void SetAutoScan() { SetFixedScan(0); }
111 
112  bool RunFixedScan( int nBins, double xMin, double xMax, bool scanLog = false ) const;
113 
114  bool RunOnePoint( double thisX, bool adaptive = false, double clTarget = -1 ) const;
115 
116  //bool RunAutoScan( double xMin, double xMax, double target, double epsilon=0.005, unsigned int numAlgorithm=0 );
117 
118  bool RunLimit(double &limit, double &limitErr, double absTol = 0, double relTol = 0, const double *hint=0) const;
119 
120  void UseCLs( bool on = true) { fUseCLs = on; if (fResults) fResults->UseCLs(on); }
121 
122  virtual void SetData(RooAbsData &);
123 
124  virtual void SetModel(const ModelConfig &) { } // not needed
125 
126  // set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
127  virtual void SetTestSize(Double_t size) {fSize = size; if (fResults) fResults->SetTestSize(size); }
128  // set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
129  virtual void SetConfidenceLevel(Double_t cl) {fSize = 1.-cl; if (fResults) fResults->SetConfidenceLevel(cl); }
130  // Get the size of the test (eg. rate of Type I error)
131  virtual Double_t Size() const {return fSize;}
132  // Get the Confidence level for the test
133  virtual Double_t ConfidenceLevel() const {return 1.-fSize;}
134 
135  // destructor
136  virtual ~HypoTestInverter() ;
137 
138  // retrieved a reference to the internally used HypoTestCalculator
139  // it might be invalid when the class is deleted
141 
142  // get the upper/lower limit distribution
143  SamplingDistribution * GetLowerLimitDistribution(bool rebuild=false, int nToys = 100);
144  SamplingDistribution * GetUpperLimitDistribution(bool rebuild=false, int nToys = 100);
145 
146  // function to rebuild the distributions
147  SamplingDistribution * RebuildDistributions(bool isUpper=true, int nToys = 100,
148  TList * clsDist = 0, TList *clsbDist= 0, TList * clbDist = 0, const char * outputfile = "HypoTestInverterRebuiltDist.root");
149 
150  // get the test statistic
152 
153  // set the test statistic
154  bool SetTestStatistic(TestStatistic& stat);
155 
156  // set verbose level (0,1,2)
157  void SetVerbose(int level=1) { fVerbose = level; }
158 
159  // set maximum number of toys
160  void SetMaximumToys(int ntoys) { fMaxToys = ntoys;}
161 
162  // set numerical error in test statistic evaluation (default is zero)
163  void SetNumErr(double err) { fNumErr = err; }
164 
165  // set flag to close proof for every new run
166  static void SetCloseProof(Bool_t flag);
167 
168 
169 protected:
170 
171  // copy c-tor
172  HypoTestInverter(const HypoTestInverter & rhs);
173 
174  // assignment
176 
177  void CreateResults() const;
178 
179  // run the hybrid at a single point
180  HypoTestResult * Eval( HypoTestCalculatorGeneric &hc, bool adaptive , double clsTarget) const;
181 
182  // helper functions
184  static void CheckInputModels(const HypoTestCalculatorGeneric &hc, const RooRealVar & scanVar);
185 
186 private:
187 
188 
189  static unsigned int fgNToys;
190  static double fgCLAccuracy;
191  static double fgAbsAccuracy;
192  static double fgRelAccuracy;
193  static bool fgCloseProof;
194  static std::string fgAlgo;
195 
196  // graph, used to compute the limit, not just for plotting!
197  mutable std::unique_ptr<TGraphErrors> fLimitPlot; //! plot of limits
198 
199 
200  // performance counter: remember how many toys have been thrown
201  mutable int fTotalToysRun;
202  int fMaxToys; // maximum number of toys to run
203 
204  HypoTestCalculatorGeneric* fCalculator0; // pointer to the calculator passed in the constructor
205  std::unique_ptr<HypoTestCalculatorGeneric> fHC; //! pointer to the generic hypotest calculator used
206  RooRealVar* fScannedVariable; // pointer to the constrained variable
207  mutable HypoTestInverterResult* fResults; // pointer to the result
208 
209  bool fUseCLs;
210  bool fScanLog;
211  double fSize;
212  int fVerbose;
214  int fNBins;
215  double fXmin;
216  double fXmax;
217  double fNumErr;
218 
219 protected:
220 
221  ClassDef(HypoTestInverter,4) // HypoTestInverter class
222 
223 };
224 
225 }
226 
227 #endif
virtual void SetConfidenceLevel(Double_t cl)
set the confidence level for the interval (e.g. 0.95 for a 95% Confidence Interval) ...
bool RunOnePoint(double thisX, bool adaptive=false, double clTarget=-1) const
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:52
const double absTol
HypoTestInverter class for performing an hypothesis test inversion by scanning the hypothesis test re...
IntervalCalculator is an interface class for a tools which produce RooStats ConfIntervals.
HypoTestResult * Eval(HypoTestCalculatorGeneric &hc, bool adaptive, double clsTarget) const
bool RunFixedScan(int nBins, double xMin, double xMax, bool scanLog=false) const
std::unique_ptr< TGraphErrors > fLimitPlot
virtual void SetTestSize(Double_t size)
set the size of the test (rate of Type I error) (eg. 0.05 for a 95% Confidence Interval) ...
HypoTestResult is a base class for results from hypothesis tests.
SamplingDistribution * GetUpperLimitDistribution(bool rebuild=false, int nToys=100)
virtual void SetTestSize(Double_t size)
set the size of the test (rate of Type I error) ( e.g. 0.05 for a 95% Confidence Interval) ...
static void CheckInputModels(const HypoTestCalculatorGeneric &hc, const RooRealVar &scanVar)
static unsigned int fgNToys
bool Bool_t
Definition: RtypesCore.h:59
HypoTestInverterResult * fResults
HypoTestInverter & operator=(const HypoTestInverter &rhs)
Common base class for the Hypothesis Test Calculators.
#define ClassDef(name, id)
Definition: Rtypes.h:254
HypoTestCalculatorGeneric * GetHypoTestCalculator() const
void UseCLs(bool on=true)
flag to switch between using CLsb (default) or CLs as confidence level
static void SetCloseProof(Bool_t flag)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
A doubly linked list.
Definition: TList.h:47
TestStatistic * GetTestStatistic() const
int fTotalToysRun
plot of limits
RooRealVar * fScannedVariable
pointer to the generic hypotest calculator used
HypoTestCalculatorGeneric * fCalculator0
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
This class simply holds a sampling distribution of some test statistic.
This class implements the Hypothesis test calculation using an hybrid (frequentist/bayesian) procedur...
virtual Double_t ConfidenceLevel() const
Get the Confidence level for the test.
Namespace for the RooStats classes.
Definition: Asimov.h:20
HypoTestInverterResult class: holds the array of hypothesis test results and compute a confidence int...
double Double_t
Definition: RtypesCore.h:55
virtual HypoTestInverterResult * GetInterval() const
Main interface to get a ConfInterval, pure virtual.
int type
Definition: TGX11.cxx:120
virtual void SetModel(const ModelConfig &)
Set the Model.
bool SetTestStatistic(TestStatistic &stat)
void SetFixedScan(int nBins, double xMin=1, double xMax=-1, bool scanLog=false)
void SetVerbose(int level=1)
std::unique_ptr< HypoTestCalculatorGeneric > fHC
Hypothesis Test Calculator using a full frequentist procedure for sampling the test statistic distrib...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
A TGraphErrors is a TGraph with error bars.
Definition: TGraphErrors.h:28
static RooRealVar * GetVariableToScan(const HypoTestCalculatorGeneric &hc)
virtual Double_t Size() const
Get the size of the test (eg. rate of Type I error)
bool RunLimit(double &limit, double &limitErr, double absTol=0, double relTol=0, const double *hint=0) const
SamplingDistribution * RebuildDistributions(bool isUpper=true, int nToys=100, TList *clsDist=0, TList *clsbDist=0, TList *clbDist=0, const char *outputfile="HypoTestInverterRebuiltDist.root")
virtual void SetData(RooAbsData &)
Set the DataSet ( add to the the workspace if not already there ?)
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
Definition: TestStatistic.h:33
SamplingDistribution * GetLowerLimitDistribution(bool rebuild=false, int nToys=100)
Hypothesis Test Calculator based on the asymptotic formulae for the profile likelihood ratio...
virtual void SetConfidenceLevel(Double_t cl)
set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval) ...