#ifndef ROOSTATS_ToyMCSampler
#define ROOSTATS_ToyMCSampler
#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif
#include <vector>
#include <sstream>
#include "RooStats/TestStatSampler.h"
#include "RooStats/SamplingDistribution.h"
#include "RooStats/TestStatistic.h"
#include "RooStats/ModelConfig.h"
#include "RooStats/ProofConfig.h"
#include "RooWorkspace.h"
#include "RooMsgService.h"
#include "RooAbsPdf.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
namespace RooStats {
class ToyMCSampler: public TestStatSampler {
public:
ToyMCSampler() :
fTestStat(NULL), fSamplingDistName("temp"), fNToys(1)
{
fPdf = NULL;
fPriorNuisance = NULL;
fNullPOI = NULL;
fNuisancePars = NULL;
fObservables = NULL;
fGlobalObservables = NULL;
fSize = 0.05;
fNEvents = 0;
fGenerateBinned = kFALSE;
fExpectedNuisancePar = kFALSE;
fToysInTails = 0.0;
fMaxToys = RooNumber::infinity();
fAdaptiveLowLimit = -RooNumber::infinity();
fAdaptiveHighLimit = RooNumber::infinity();
fImportanceDensity = NULL;
fImportanceSnapshot = NULL;
fProtoData = NULL;
fProofConfig = NULL;
}
ToyMCSampler(TestStatistic &ts, Int_t ntoys) :
fTestStat(&ts), fSamplingDistName(ts.GetVarName()), fNToys(ntoys)
{
fPdf = NULL;
fPriorNuisance = NULL;
fNullPOI = NULL;
fNuisancePars = NULL;
fObservables = NULL;
fGlobalObservables = NULL;
fSize = 0.05;
fNEvents = 0;
fGenerateBinned = kFALSE;
fExpectedNuisancePar = kFALSE;
fToysInTails = 0.0;
fMaxToys = RooNumber::infinity();
fAdaptiveLowLimit = -RooNumber::infinity();
fAdaptiveHighLimit = RooNumber::infinity();
fImportanceDensity = NULL;
fImportanceSnapshot = NULL;
fProtoData = NULL;
fProofConfig = NULL;
}
virtual ~ToyMCSampler() {
}
virtual SamplingDistribution* GetSamplingDistribution(RooArgSet& paramPoint);
virtual SamplingDistribution* GetSamplingDistributionSingleWorker(RooArgSet& paramPoint);
virtual RooAbsData* GenerateToyData(RooArgSet& ) const;
virtual SamplingDistribution* AppendSamplingDistribution(RooArgSet& allParameters,
SamplingDistribution* last,
Int_t additionalMC) {
Int_t tmp = fNToys;
fNToys = additionalMC;
SamplingDistribution* newSamples = GetSamplingDistribution(allParameters);
fNToys = tmp;
if(last){
last->Add(newSamples);
delete newSamples;
return last;
}
return newSamples;
}
virtual Double_t EvaluateTestStatistic(RooAbsData& data, RooArgSet& nullPOI) {
return fTestStat->Evaluate(data, nullPOI);
}
virtual TestStatistic* GetTestStatistic() const { return fTestStat; }
virtual Double_t ConfidenceLevel() const { return 1. - fSize; }
virtual void Initialize(
RooAbsArg& ,
RooArgSet& ,
RooArgSet&
) {}
virtual Int_t GetNToys(void) { return fNToys; }
virtual void SetNToys(const Int_t ntoy) { fNToys = ntoy; }
virtual void SetNEventsPerToy(const Int_t nevents) {
fNEvents = nevents;
}
virtual void SetParametersForTestStat(const RooArgSet& nullpoi) { fNullPOI = (RooArgSet*)nullpoi.snapshot(); }
virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; }
virtual void SetPriorNuisance(RooAbsPdf* pdf) { fPriorNuisance = pdf; }
virtual void SetNuisanceParameters(const RooArgSet& np) { fNuisancePars = &np; }
virtual void SetObservables(const RooArgSet& o) { fObservables = &o; }
virtual void SetGlobalObservables(const RooArgSet& o) { fGlobalObservables = &o; }
virtual void SetTestSize(Double_t size) { fSize = size; }
virtual void SetConfidenceLevel(Double_t cl) { fSize = 1. - cl; }
virtual void SetTestStatistic(TestStatistic *testStatistic) { fTestStat = testStatistic; }
virtual void SetExpectedNuisancePar(Bool_t i = kTRUE) { fExpectedNuisancePar = i; }
virtual void SetAsimovNuisancePar(Bool_t i = kTRUE) { fExpectedNuisancePar = i; }
Bool_t CheckConfig(void);
void SetGenerateBinned(bool binned = true) { fGenerateBinned = binned; }
void SetSamplingDistName(const char* name) { if(name) fSamplingDistName = name; }
string GetSamplingDistName(void) { return fSamplingDistName; }
void SetMaxToys(Double_t t) { fMaxToys = t; }
void SetToysLeftTail(Double_t toys, Double_t threshold) {
fToysInTails = toys;
fAdaptiveLowLimit = threshold;
fAdaptiveHighLimit = RooNumber::infinity();
}
void SetToysRightTail(Double_t toys, Double_t threshold) {
fToysInTails = toys;
fAdaptiveHighLimit = threshold;
fAdaptiveLowLimit = -RooNumber::infinity();
}
void SetToysBothTails(Double_t toys, Double_t low_threshold, Double_t high_threshold) {
fToysInTails = toys;
fAdaptiveHighLimit = high_threshold;
fAdaptiveLowLimit = low_threshold;
}
void SetImportanceDensity(RooAbsPdf *p) { fImportanceDensity = p; }
void SetImportanceSnapshot(const RooArgSet &s) { fImportanceSnapshot = &s; }
void SetProofConfig(ProofConfig *pc = NULL) { fProofConfig = pc; }
void SetProtoData(const RooDataSet* d) { fProtoData = d; }
protected:
RooAbsData* Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=NULL, int forceEvents=0) const;
TestStatistic *fTestStat;
RooAbsPdf *fPdf;
string fSamplingDistName;
RooAbsPdf *fPriorNuisance;
RooArgSet *fNullPOI;
const RooArgSet *fNuisancePars;
const RooArgSet *fObservables;
const RooArgSet *fGlobalObservables;
Int_t fNToys;
Int_t fNEvents;
Double_t fSize;
Bool_t fExpectedNuisancePar;
Bool_t fGenerateBinned;
Double_t fToysInTails;
Double_t fMaxToys;
Double_t fAdaptiveLowLimit;
Double_t fAdaptiveHighLimit;
RooAbsPdf *fImportanceDensity;
const RooArgSet *fImportanceSnapshot;
const RooDataSet *fProtoData;
ProofConfig *fProofConfig;
protected:
ClassDef(ToyMCSampler,1)
};
}
#endif