Logo ROOT   6.12/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 
16 
17 
19 
20 class RooRealVar;
21 class TGraphErrors;
22 
23 #include <memory>
24 
25 
26 namespace RooStats {
27 
28  //class HypoTestCalculator;
29  class HybridCalculator;
30  class FrequentistCalculator;
31  class AsymptoticCalculator;
32  class HypoTestCalculatorGeneric;
33  class TestStatistic;
34 
35 
37 
38 public:
39 
41 
42  // default constructor (used only for I/O)
44 
45  // constructor from generic hypotest calculator
47  RooRealVar* scannedVariable =0,
48  double size = 0.05) ;
49 
50 
51  // constructor from hybrid calculator
53  RooRealVar* scannedVariable = 0,
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 = 0, ECalculatorType type = kFrequentist,
70  double size = 0.05) ;
71 
72 
73  virtual HypoTestInverterResult* GetInterval() const;
74 
75  void Clear();
76 
77  // set for a fixed scan in nbins
78  void SetFixedScan(int nBins, double xMin = 1, double xMax = -1, bool scanLog = false ) {
79  fNBins = nBins;
80  fXmin = xMin; fXmax = xMax;
81  fScanLog = scanLog;
82  }
83 
84  // set auto scan (default)
85  void SetAutoScan() { SetFixedScan(0); }
86 
87  bool RunFixedScan( int nBins, double xMin, double xMax, bool scanLog = false ) const;
88 
89  bool RunOnePoint( double thisX, bool adaptive = false, double clTarget = -1 ) const;
90 
91  //bool RunAutoScan( double xMin, double xMax, double target, double epsilon=0.005, unsigned int numAlgorithm=0 );
92 
93  bool RunLimit(double &limit, double &limitErr, double absTol = 0, double relTol = 0, const double *hint=0) const;
94 
95  void UseCLs( bool on = true) { fUseCLs = on; if (fResults) fResults->UseCLs(on); }
96 
97  virtual void SetData(RooAbsData &);
98 
99  virtual void SetModel(const ModelConfig &) { } // not needed
100 
101  // set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
102  virtual void SetTestSize(Double_t size) {fSize = size; if (fResults) fResults->SetTestSize(size); }
103  // set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
104  virtual void SetConfidenceLevel(Double_t cl) {fSize = 1.-cl; if (fResults) fResults->SetConfidenceLevel(cl); }
105  // Get the size of the test (eg. rate of Type I error)
106  virtual Double_t Size() const {return fSize;}
107  // Get the Confidence level for the test
108  virtual Double_t ConfidenceLevel() const {return 1.-fSize;}
109 
110  // destructor
111  virtual ~HypoTestInverter() ;
112 
113  // retrieved a reference to the internally used HypoTestCalculator
114  // it might be invalid when the class is deleted
116 
117  // get the upper/lower limit distribution
118  SamplingDistribution * GetLowerLimitDistribution(bool rebuild=false, int nToys = 100);
119  SamplingDistribution * GetUpperLimitDistribution(bool rebuild=false, int nToys = 100);
120 
121  // function to rebuild the distributions
122  SamplingDistribution * RebuildDistributions(bool isUpper=true, int nToys = 100,
123  TList * clsDist = 0, TList *clsbDist= 0, TList * clbDist = 0, const char * outputfile = "HypoTestInverterRebuiltDist.root");
124 
125  // get the test statistic
127 
128  // set the test statistic
129  bool SetTestStatistic(TestStatistic& stat);
130 
131  // set verbose level (0,1,2)
132  void SetVerbose(int level=1) { fVerbose = level; }
133 
134  // set maximum number of toys
135  void SetMaximumToys(int ntoys) { fMaxToys = ntoys;}
136 
137  // set numerical error in test statistic evaluation (default is zero)
138  void SetNumErr(double err) { fNumErr = err; }
139 
140  // set flag to close proof for every new run
141  static void SetCloseProof(Bool_t flag);
142 
143 
144 protected:
145 
146  // copy c-tor
147  HypoTestInverter(const HypoTestInverter & rhs);
148 
149  // assignment
151 
152  void CreateResults() const;
153 
154  // run the hybrid at a single point
155  HypoTestResult * Eval( HypoTestCalculatorGeneric &hc, bool adaptive , double clsTarget) const;
156 
157  // helper functions
159  static void CheckInputModels(const HypoTestCalculatorGeneric &hc, const RooRealVar & scanVar);
160 
161 private:
162 
163 
164  static unsigned int fgNToys;
165  static double fgCLAccuracy;
166  static double fgAbsAccuracy;
167  static double fgRelAccuracy;
168  static bool fgCloseProof;
169  static std::string fgAlgo;
170 
171  // graph, used to compute the limit, not just for plotting!
172  mutable std::unique_ptr<TGraphErrors> fLimitPlot; //! plot of limits
173 
174 
175  // performance counter: remember how many toys have been thrown
176  mutable int fTotalToysRun;
177  int fMaxToys; // maximum number of toys to run
178 
179  HypoTestCalculatorGeneric* fCalculator0; // pointer to the calculator passed in the constructor
180  std::unique_ptr<HypoTestCalculatorGeneric> fHC; //! pointer to the generic hypotest calculator used
181  RooRealVar* fScannedVariable; // pointer to the constrained variable
182  mutable HypoTestInverterResult* fResults; // pointer to the result
183 
184  bool fUseCLs;
185  bool fScanLog;
186  double fSize;
187  int fVerbose;
189  int fNBins;
190  double fXmin;
191  double fXmax;
192  double fNumErr;
193 
194 protected:
195 
196  ClassDef(HypoTestInverter,4) // HypoTestInverter class
197 
198 };
199 
200 }
201 
202 #endif
virtual ~HypoTestInverter()
destructor (delete the HypoTestInverterResult)
void CreateResults() const
create a new HypoTestInverterResult to hold all computed results
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
run only one point at the given POI value
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
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
Run the Hypothesis test at a previous configured point (internal function called by RunOnePoint) ...
bool RunFixedScan(int nBins, double xMin, double xMax, bool scanLog=false) const
Run a Fixed scan in npoints between min and max.
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)
get the distribution of lower limit if rebuild = false (default) it will re-use the results of the sc...
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)
check the model given the given hypotestcalculator
static unsigned int fgNToys
bool Bool_t
Definition: RtypesCore.h:59
HypoTestInverterResult * fResults
HypoTestInverter & operator=(const HypoTestInverter &rhs)
assignment operator NOTE: this class does not copy the contained result and the HypoTestCalculator, but only the pointers It requires the original HTI to be alive
Common base class for the Hypothesis Test Calculators.
#define ClassDef(name, id)
Definition: Rtypes.h:320
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)
set flag to close proof for every new run
HypoTestInverter()
default constructor (doesn&#39;t do anything)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
A doubly linked list.
Definition: TList.h:44
TestStatistic * GetTestStatistic() const
return the test statistic which is or will be used by the class
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.
Same purpose as HybridCalculatorOriginal, but different implementation.
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 inte...
double Double_t
Definition: RtypesCore.h:55
virtual HypoTestInverterResult * GetInterval() const
Run a fixed scan or the automatic scan depending on the configuration Return if needed a copy of the ...
int type
Definition: TGX11.cxx:120
virtual void SetModel(const ModelConfig &)
Set the Model.
bool SetTestStatistic(TestStatistic &stat)
set the test statistic to use
void SetFixedScan(int nBins, double xMin=1, double xMax=-1, bool scanLog=false)
void SetVerbose(int level=1)
std::unique_ptr< HypoTestCalculatorGeneric > fHC
Does a frequentist hypothesis test.
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:26
void Clear()
delete contained result and graph
static RooRealVar * GetVariableToScan(const HypoTestCalculatorGeneric &hc)
get the variable to scan try first with null model if not go to alternate model
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
run an automatic scan until the desired accuracy is reached Start by default from the full interval (...
SamplingDistribution * RebuildDistributions(bool isUpper=true, int nToys=100, TList *clsDist=0, TList *clsbDist=0, TList *clbDist=0, const char *outputfile="HypoTestInverterRebuiltDist.root")
rebuild the sampling distributions by generating some toys and find for each of them a new upper limi...
void UseCLs(bool on=true)
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:31
SamplingDistribution * GetLowerLimitDistribution(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...
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) ...