#include "RooStats/HybridCalculator.h"
#include "RooStats/ToyMCSampler.h"
ClassImp(RooStats::HybridCalculator)
using namespace RooStats;
using namespace std;
int HybridCalculator::CheckHook(void) const {
if( fPriorNuisanceNull && (!fNullModel->GetNuisanceParameters() || fNullModel->GetNuisanceParameters()->getSize() == 0) ) {
oocoutE((TObject*)0,InputArguments) << "HybridCalculator - Nuisance PDF has been specified, but is unaware of which parameters are the nuisance parameters. Must set nuisance parameters in the Null ModelConfig." << endl;
return -1;
}
if( fPriorNuisanceAlt && (!fAltModel->GetNuisanceParameters() || fAltModel->GetNuisanceParameters()->getSize() == 0) ) {
oocoutE((TObject*)0,InputArguments) << "HybridCalculator - Nuisance PDF has been specified, but is unaware of which parameters are the nuisance parameters. Must set nuisance parameters in the Alt ModelConfig" << endl;
return -1;
}
return 0;
}
int HybridCalculator::PreNullHook(RooArgSet* , double obsTestStat) const {
if(fPriorNuisanceNull) {
fTestStatSampler->SetPriorNuisance(fPriorNuisanceNull);
} else if(
fNullModel->GetNuisanceParameters() == NULL ||
fNullModel->GetNuisanceParameters()->getSize() == 0
) {
oocoutI((TObject*)0,InputArguments)
<< "HybridCalculator - No nuisance parameters specified for Null model and no prior forced. "
<< "Case is reduced to simple hypothesis testing with no uncertainty." << endl;
} else {
oocoutI((TObject*)0,InputArguments) << "HybridCalculator - Using uniform prior on nuisance parameters (Null model)." << endl;
}
ToyMCSampler *toymcs = dynamic_cast<ToyMCSampler*>(GetTestStatSampler());
if(toymcs) {
oocoutI((TObject*)0,InputArguments) << "Using a ToyMCSampler. Now configuring for Null." << endl;
if(fNToysNull >= 0) toymcs->SetNToys(fNToysNull);
if(fNToysNullTail) {
oocoutI((TObject*)0,InputArguments) << "Adaptive Sampling" << endl;
if(GetTestStatSampler()->GetTestStatistic()->PValueIsRightTail()) {
toymcs->SetToysRightTail(fNToysNullTail, obsTestStat);
}else{
toymcs->SetToysLeftTail(fNToysNullTail, obsTestStat);
}
}else{
toymcs->SetToysBothTails(0, 0, obsTestStat);
}
GetNullModel()->LoadSnapshot();
}
return 0;
}
int HybridCalculator::PreAltHook(RooArgSet* , double obsTestStat) const {
if(fPriorNuisanceAlt){
fTestStatSampler->SetPriorNuisance(fPriorNuisanceAlt);
} else if (
fAltModel->GetNuisanceParameters()==NULL ||
fAltModel->GetNuisanceParameters()->getSize()==0
) {
oocoutI((TObject*)0,InputArguments)
<< "HybridCalculator - No nuisance parameters specified for Alt model and no prior forced. "
<< "Case is reduced to simple hypothesis testing with no uncertainty." << endl;
} else {
oocoutI((TObject*)0,InputArguments) << "HybridCalculator - Using uniform prior on nuisance parameters (Alt model)." << endl;
}
ToyMCSampler *toymcs = dynamic_cast<ToyMCSampler*>(GetTestStatSampler());
if(toymcs) {
oocoutI((TObject*)0,InputArguments) << "Using a ToyMCSampler. Now configuring for Alt." << endl;
if(fNToysAlt >= 0) toymcs->SetNToys(fNToysAlt);
if(fNToysAltTail) {
oocoutI((TObject*)0,InputArguments) << "Adaptive Sampling" << endl;
if(GetTestStatSampler()->GetTestStatistic()->PValueIsRightTail()) {
toymcs->SetToysLeftTail(fNToysAltTail, obsTestStat);
}else{
toymcs->SetToysRightTail(fNToysAltTail, obsTestStat);
}
}else{
toymcs->SetToysBothTails(0, 0, obsTestStat);
}
}
return 0;
}