Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
AsymptoticCalculator.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: Sven Kreiss, Kyle Cranmer Nov 2010
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_AsymptoticCalculator
12 #define ROOSTATS_AsymptoticCalculator
13 
15 #include "RooArgSet.h"
16 #include "Rtypes.h"
17 
18 class RooArgList;
19 class RooCategory;
20 class RooRealVar;
21 class RooPoisson;
22 class RooProdPdf;
23 
24 
25 namespace RooStats {
26 
27  class AsymptoticCalculator : public HypoTestCalculatorGeneric {
28 
29  public:
30  AsymptoticCalculator(
31  RooAbsData &data, // need to pass non-const since RooAbsPdf::fitTo takes a non-const data set
32  const ModelConfig &altModel,
33  const ModelConfig &nullModel,
34  bool nominalAsimov = false
35  );
36  // HypoTestCalculatorGeneric(data, altModel, nullModel, 0)
37  // {
38  // }
39 
40  ~AsymptoticCalculator() {
41  }
42 
43  /// initialize the calculator by performing a global fit and make the Asimov data set
44  bool Initialize() const;
45 
46  /// re-implement HypoTest computation using the asymptotic
47  virtual HypoTestResult *GetHypoTest() const;
48 
49  /// Make Asimov data.
50  static RooAbsData * MakeAsimovData( RooAbsData & data, const ModelConfig & model, const RooArgSet & poiValues, RooArgSet & globObs, const RooArgSet * genPoiValues = 0);
51 
52 
53  /// Make a nominal Asimov data set from a model.
54  static RooAbsData * MakeAsimovData( const ModelConfig & model, const RooArgSet & allParamValues, RooArgSet & globObs);
55 
56 
57 
58  static RooAbsData * GenerateAsimovData(const RooAbsPdf & pdf, const RooArgSet & observables );
59 
60  /// function given the null and the alt p value - return the expected one given the N - sigma value
61  static double GetExpectedPValues(double pnull, double palt, double nsigma, bool usecls, bool oneSided = true );
62 
63  /// set test statistic for one sided (upper limits)
64  void SetOneSided(bool on) { fOneSided = on; }
65 
66  /// set the test statistics for two sided (in case of upper limits
67  /// for discovery does not make really sense)
68  void SetTwoSided() { fOneSided = false; fOneSidedDiscovery = false;}
69 
70  /// set the test statistics for one-sided discovery
71  void SetOneSidedDiscovery(bool on) { fOneSidedDiscovery = on; }
72 
73  /// re-implementation of setters since they are needed to re-initialize the calculator
74  virtual void SetNullModel(const ModelConfig &nullModel) {
75  HypoTestCalculatorGeneric::SetNullModel(nullModel);
76  fIsInitialized = false;
77  }
78  virtual void SetAlternateModel(const ModelConfig &altModel) {
79  HypoTestCalculatorGeneric::SetAlternateModel(altModel);
80  fIsInitialized = false;
81  }
82  virtual void SetData(RooAbsData &data) {
83  HypoTestCalculatorGeneric::SetData(data);
84  fIsInitialized = false;
85  }
86 
87 
88  bool IsTwoSided() const { return (!fOneSided && !fOneSidedDiscovery); }
89  bool IsOneSidedDiscovery() const { return fOneSidedDiscovery; }
90 
91 
92  /// set using of qtilde, by default is controlled if RoORealVar is limited or not
93  void SetQTilde(bool on) { fUseQTilde = on; }
94 
95  /// return snapshot of the best fit parameter
96  const RooArgSet & GetBestFitPoi() const { return fBestFitPoi; }
97  /// return best fit parameter (firs of poi)
98  const RooRealVar * GetMuHat() const { return dynamic_cast<RooRealVar*>(fBestFitPoi.first()); }
99  /// return best fit value for all parameters
100  const RooArgSet & GetBestFitParams() const { return fBestFitPoi; }
101 
102  static void SetPrintLevel(int level);
103 
104  protected:
105  // // configure TestStatSampler for the Null run
106  // int PreNullHook(RooArgSet *parameterPoint, double obsTestStat) const;
107 
108  // // configure TestStatSampler for the Alt run
109  // int PreAltHook(RooArgSet *parameterPoint, double obsTestStat) const;
110 
111 
112  static RooAbsData * GenerateAsimovDataSinglePdf(const RooAbsPdf & pdf, const RooArgSet & obs, const RooRealVar & weightVar,
113  RooCategory * channelCat = 0);
114 
115  static RooAbsData * GenerateCountingAsimovData(RooAbsPdf & pdf, const RooArgSet & obs, const RooRealVar & weightVar,
116  RooCategory * channelCat = 0);
117 
118 
119  static void FillBins(const RooAbsPdf & pdf, const RooArgList &obs, RooAbsData & data, int &index, double
120  &binVolume, int &ibin);
121 
122  static double EvaluateNLL(RooAbsPdf & pdf, RooAbsData& data, const RooArgSet * condObs, const RooArgSet * globObs, const RooArgSet *poiSet = 0 );
123 
124  static bool SetObsToExpected(RooAbsPdf &pdf, const RooArgSet &obs);
125  static bool SetObsToExpected(RooProdPdf &prod, const RooArgSet &obs);
126 
127  protected:
128  ClassDef(AsymptoticCalculator,2)
129 
130  private:
131 
132  bool fOneSided; // for one sided PL test statistic (upper limits)
133  mutable bool fOneSidedDiscovery; // for one sided PL test statistic (for discovery)
134  bool fNominalAsimov; // make Asimov at nominal parameter values
135  mutable bool fIsInitialized; //! flag to check if calculator is initialized
136  mutable int fUseQTilde; // flag to indicate if using qtilde or not (-1 (default based on RooRealVar)), 0 false, 1 (true)
137  static int fgPrintLevel; // control print level (0 minimal, 1 normal, 2 debug)
138  mutable double fNLLObs;
139  mutable double fNLLAsimov;
140 
141  mutable RooAbsData * fAsimovData; // asimov data set
142  mutable RooArgSet fAsimovGlobObs; // snapshot of Asimov global observables
143  mutable RooArgSet fBestFitPoi; // snapshot of best fitted POI values
144  mutable RooArgSet fBestFitParams; // snapshot of all best fitted Parameter values
145 
146 
147  };
148 }
149 
150 #endif