diff --git a/roofit/roostats/inc/RooStats/HypoTestCalculatorGeneric.h b/roofit/roostats/inc/RooStats/HypoTestCalculatorGeneric.h index 92006f5a18d1e9f7283ac526ab3d3be9e403da2a..3edc7ba4ff0dfec39a52060063b438e92f254233 100644 --- a/roofit/roostats/inc/RooStats/HypoTestCalculatorGeneric.h +++ b/roofit/roostats/inc/RooStats/HypoTestCalculatorGeneric.h @@ -76,6 +76,12 @@ namespace RooStats { // TestStatSampler, e.g. GetTestStatSampler.SetTestSize(Double_t size); TestStatSampler* GetTestStatSampler(void) const { return fTestStatSampler; } + // set this for re-using always the same toys for alternate hypothesis in + // case of calls at dofferent null parameter points + // This is useful to get more stable bands when running the HypoTest inversion + void UseSameAltToys(); + + protected: // should return zero (to be used later for conditional flow) virtual int CheckHook(void) const { return 0; } @@ -92,6 +98,8 @@ namespace RooStats { TestStatSampler *fDefaultSampler; TestStatistic *fDefaultTestStat; + unsigned int fAltToysSeed; // to have same toys for alternate + private: void SetupSampler(const ModelConfig& model) const; void SetAdaptiveLimits(Double_t obsTestStat, Bool_t forNull) const; @@ -104,7 +112,7 @@ namespace RooStats { protected: - ClassDef(HypoTestCalculatorGeneric,1) + ClassDef(HypoTestCalculatorGeneric,2) }; } diff --git a/roofit/roostats/src/HypoTestCalculatorGeneric.cxx b/roofit/roostats/src/HypoTestCalculatorGeneric.cxx index 5851864beca6849a98b1b524d7c4e820393c000e..0a68e10af39f73660f703d752d0f72be6de6aef1 100644 --- a/roofit/roostats/src/HypoTestCalculatorGeneric.cxx +++ b/roofit/roostats/src/HypoTestCalculatorGeneric.cxx @@ -22,6 +22,8 @@ ToyMCSampler as its TestStatSampler. #include "RooAddPdf.h" +#include "RooRandom.h" + ClassImp(RooStats::HypoTestCalculatorGeneric) @@ -40,7 +42,8 @@ HypoTestCalculatorGeneric::HypoTestCalculatorGeneric( fData(&data), fTestStatSampler(sampler), fDefaultSampler(0), - fDefaultTestStat(0) + fDefaultTestStat(0), + fAltToysSeed(0) { // Constructor. When test stat sampler is not provided // uses ToyMCSampler and RatioOfProfiledLikelihoodsTestStat @@ -184,6 +187,15 @@ HypoTestResult* HypoTestCalculatorGeneric::GetHypoTest() const { SamplingDistribution* samp_alt = NULL; RooDataSet* detOut_alt = NULL; if(toymcs) { + + // case of re-using same toys for every points + // set a given seed + unsigned int prevSeed = 0; + if (fAltToysSeed > 0) { + prevSeed = RooRandom::integer(std::numeric_limits<unsigned int>::max()-1)+1; // want to avoid zero value + RooRandom::randomGenerator()->SetSeed(fAltToysSeed); + } + detOut_alt = toymcs->GetSamplingDistributions(paramPointAlt); if( detOut_alt ) { samp_alt = new SamplingDistribution( detOut_alt->GetName(), detOut_alt->GetTitle(), *detOut_alt ); @@ -192,6 +204,12 @@ HypoTestResult* HypoTestCalculatorGeneric::GetHypoTest() const { detOut_alt= 0; } } + + // restore the seed + if (prevSeed > 0) { + RooRandom::randomGenerator()->SetSeed(prevSeed); + } + }else samp_alt = fTestStatSampler->GetSamplingDistribution(paramPointAlt); @@ -224,6 +242,11 @@ HypoTestResult* HypoTestCalculatorGeneric::GetHypoTest() const { return res; } - +//____________________________________________________ +void HypoTestCalculatorGeneric::UseSameAltToys() { + // to re-use same toys for alternate hypothesis + fAltToysSeed = RooRandom::integer(std::numeric_limits<unsigned int>::max()-1)+1; +} + diff --git a/roofit/roostats/src/ToyMCSampler.cxx b/roofit/roostats/src/ToyMCSampler.cxx index 1b63e5348eb0c12b62581d4a965089dc4ba398b8..abc32c9e36f877d8ebaeb435e7ad81928e833162 100644 --- a/roofit/roostats/src/ToyMCSampler.cxx +++ b/roofit/roostats/src/ToyMCSampler.cxx @@ -387,10 +387,11 @@ RooDataSet* ToyMCSampler::GetSamplingDistributionsSingleWorker(RooArgSet& paramP // set variables to requested parameter point *allVars = *saveAll; // important for example for SimpleLikelihoodRatioTestStat - *allVars = *fParametersForTestStat; RooAbsData* toydata = GenerateToyData(*paramPoint, weight); + *allVars = *fParametersForTestStat; + const RooArgList* allTS = EvaluateAllTestStatistics(*toydata, *fParametersForTestStat, detOutAgg); if (allTS->getSize() > Int_t(fTestStatistics.size())) detOutAgg.AppendArgSet( fGlobalObservables, "globObs_" );