00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOSTATS_ToyMCSampler
00014 #define ROOSTATS_ToyMCSampler
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef ROOT_Rtypes
00035 #include "Rtypes.h"
00036 #endif
00037
00038 #include <vector>
00039 #include <sstream>
00040
00041 #include "RooStats/TestStatSampler.h"
00042 #include "RooStats/SamplingDistribution.h"
00043 #include "RooStats/TestStatistic.h"
00044 #include "RooStats/ModelConfig.h"
00045 #include "RooStats/ProofConfig.h"
00046
00047 #include "RooWorkspace.h"
00048 #include "RooMsgService.h"
00049 #include "RooAbsPdf.h"
00050 #include "RooRealVar.h"
00051
00052 #include "RooDataSet.h"
00053
00054 namespace RooStats {
00055
00056 class ToyMCSampler: public TestStatSampler {
00057
00058 public:
00059 ToyMCSampler() :
00060 fTestStat(NULL), fSamplingDistName("temp"), fNToys(1)
00061 {
00062
00063
00064 fPdf = NULL;
00065 fPriorNuisance = NULL;
00066 fNullPOI = NULL;
00067 fNuisancePars = NULL;
00068 fObservables = NULL;
00069 fGlobalObservables = NULL;
00070
00071 fSize = 0.05;
00072 fNEvents = 0;
00073 fGenerateBinned = kFALSE;
00074 fExpectedNuisancePar = kFALSE;
00075
00076 fToysInTails = 0.0;
00077 fMaxToys = RooNumber::infinity();
00078 fAdaptiveLowLimit = -RooNumber::infinity();
00079 fAdaptiveHighLimit = RooNumber::infinity();
00080
00081 fImportanceDensity = NULL;
00082 fImportanceSnapshot = NULL;
00083 fProtoData = NULL;
00084
00085 fProofConfig = NULL;
00086 }
00087 ToyMCSampler(TestStatistic &ts, Int_t ntoys) :
00088 fTestStat(&ts), fSamplingDistName(ts.GetVarName()), fNToys(ntoys)
00089 {
00090 fPdf = NULL;
00091 fPriorNuisance = NULL;
00092 fNullPOI = NULL;
00093 fNuisancePars = NULL;
00094 fObservables = NULL;
00095 fGlobalObservables = NULL;
00096
00097 fSize = 0.05;
00098 fNEvents = 0;
00099 fGenerateBinned = kFALSE;
00100 fExpectedNuisancePar = kFALSE;
00101
00102 fToysInTails = 0.0;
00103 fMaxToys = RooNumber::infinity();
00104 fAdaptiveLowLimit = -RooNumber::infinity();
00105 fAdaptiveHighLimit = RooNumber::infinity();
00106
00107 fImportanceDensity = NULL;
00108 fImportanceSnapshot = NULL;
00109 fProtoData = NULL;
00110
00111 fProofConfig = NULL;
00112 }
00113
00114 virtual ~ToyMCSampler() {
00115 }
00116
00117
00118 virtual SamplingDistribution* GetSamplingDistribution(RooArgSet& paramPoint);
00119
00120 virtual SamplingDistribution* GetSamplingDistributionSingleWorker(RooArgSet& paramPoint);
00121
00122
00123
00124
00125 virtual RooAbsData* GenerateToyData(RooArgSet& ) const;
00126
00127
00128
00129
00130 virtual SamplingDistribution* AppendSamplingDistribution(RooArgSet& allParameters,
00131 SamplingDistribution* last,
00132 Int_t additionalMC) {
00133
00134 Int_t tmp = fNToys;
00135 fNToys = additionalMC;
00136 SamplingDistribution* newSamples = GetSamplingDistribution(allParameters);
00137 fNToys = tmp;
00138
00139 if(last){
00140 last->Add(newSamples);
00141 delete newSamples;
00142 return last;
00143 }
00144
00145 return newSamples;
00146 }
00147
00148
00149
00150 virtual Double_t EvaluateTestStatistic(RooAbsData& data, RooArgSet& nullPOI) {
00151 return fTestStat->Evaluate(data, nullPOI);
00152 }
00153
00154 virtual TestStatistic* GetTestStatistic() const { return fTestStat; }
00155 virtual Double_t ConfidenceLevel() const { return 1. - fSize; }
00156 virtual void Initialize(
00157 RooAbsArg& ,
00158 RooArgSet& ,
00159 RooArgSet&
00160 ) {}
00161
00162 virtual Int_t GetNToys(void) { return fNToys; }
00163 virtual void SetNToys(const Int_t ntoy) { fNToys = ntoy; }
00164 virtual void SetNEventsPerToy(const Int_t nevents) {
00165
00166
00167 fNEvents = nevents;
00168 }
00169
00170
00171
00172 virtual void SetParametersForTestStat(const RooArgSet& nullpoi) { fNullPOI = (RooArgSet*)nullpoi.snapshot(); }
00173
00174 virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; }
00175
00176 virtual void SetPriorNuisance(RooAbsPdf* pdf) { fPriorNuisance = pdf; }
00177
00178 virtual void SetNuisanceParameters(const RooArgSet& np) { fNuisancePars = &np; }
00179
00180 virtual void SetObservables(const RooArgSet& o) { fObservables = &o; }
00181
00182 virtual void SetGlobalObservables(const RooArgSet& o) { fGlobalObservables = &o; }
00183
00184
00185
00186 virtual void SetTestSize(Double_t size) { fSize = size; }
00187
00188 virtual void SetConfidenceLevel(Double_t cl) { fSize = 1. - cl; }
00189
00190
00191 virtual void SetTestStatistic(TestStatistic *testStatistic) { fTestStat = testStatistic; }
00192
00193 virtual void SetExpectedNuisancePar(Bool_t i = kTRUE) { fExpectedNuisancePar = i; }
00194 virtual void SetAsimovNuisancePar(Bool_t i = kTRUE) { fExpectedNuisancePar = i; }
00195
00196
00197 Bool_t CheckConfig(void);
00198
00199
00200 void SetGenerateBinned(bool binned = true) { fGenerateBinned = binned; }
00201
00202
00203 void SetSamplingDistName(const char* name) { if(name) fSamplingDistName = name; }
00204 string GetSamplingDistName(void) { return fSamplingDistName; }
00205
00206
00207 void SetMaxToys(Double_t t) { fMaxToys = t; }
00208
00209 void SetToysLeftTail(Double_t toys, Double_t threshold) {
00210 fToysInTails = toys;
00211 fAdaptiveLowLimit = threshold;
00212 fAdaptiveHighLimit = RooNumber::infinity();
00213 }
00214 void SetToysRightTail(Double_t toys, Double_t threshold) {
00215 fToysInTails = toys;
00216 fAdaptiveHighLimit = threshold;
00217 fAdaptiveLowLimit = -RooNumber::infinity();
00218 }
00219 void SetToysBothTails(Double_t toys, Double_t low_threshold, Double_t high_threshold) {
00220 fToysInTails = toys;
00221 fAdaptiveHighLimit = high_threshold;
00222 fAdaptiveLowLimit = low_threshold;
00223 }
00224
00225
00226 void SetImportanceDensity(RooAbsPdf *p) { fImportanceDensity = p; }
00227
00228 void SetImportanceSnapshot(const RooArgSet &s) { fImportanceSnapshot = &s; }
00229
00230
00231 void SetProofConfig(ProofConfig *pc = NULL) { fProofConfig = pc; }
00232
00233 void SetProtoData(const RooDataSet* d) { fProtoData = d; }
00234
00235 protected:
00236
00237
00238 RooAbsData* Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=NULL, int forceEvents=0) const;
00239
00240
00241
00242 TestStatistic *fTestStat;
00243 RooAbsPdf *fPdf;
00244 string fSamplingDistName;
00245 RooAbsPdf *fPriorNuisance;
00246 RooArgSet *fNullPOI;
00247 const RooArgSet *fNuisancePars;
00248 const RooArgSet *fObservables;
00249 const RooArgSet *fGlobalObservables;
00250 Int_t fNToys;
00251 Int_t fNEvents;
00252 Double_t fSize;
00253 Bool_t fExpectedNuisancePar;
00254 Bool_t fGenerateBinned;
00255
00256
00257
00258
00259 Double_t fToysInTails;
00260
00261
00262 Double_t fMaxToys;
00263
00264 Double_t fAdaptiveLowLimit;
00265 Double_t fAdaptiveHighLimit;
00266
00267 RooAbsPdf *fImportanceDensity;
00268 const RooArgSet *fImportanceSnapshot;
00269
00270 const RooDataSet *fProtoData;
00271
00272 ProofConfig *fProofConfig;
00273
00274 protected:
00275 ClassDef(ToyMCSampler,1)
00276 };
00277 }
00278
00279
00280 #endif