#include "RooStats/HybridCalculator.h"
#include "RooStats/ToyMCSampler.h"
ClassImp(RooStats::HybridCalculator)
using namespace RooStats;
int HybridCalculator::CheckHook(void) const {
if( (fNullModel->GetNuisanceParameters()
&& fNullModel->GetNuisanceParameters()->getSize()>0
&& !fPriorNuisanceNull)
|| (fAltModel->GetNuisanceParameters()
&& fAltModel->GetNuisanceParameters()->getSize()>0
&& !fPriorNuisanceAlt)
){
oocoutE((TObject*)0,InputArguments) << "Must ForceNuisancePdf, inferring posterior from ModelConfig is not yet implemented" << endl;
return -1;
}
if( (!fNullModel->GetNuisanceParameters() && fPriorNuisanceNull)
|| (!fAltModel->GetNuisanceParameters() && fPriorNuisanceAlt)
|| (fNullModel->GetNuisanceParameters() && fNullModel->GetNuisanceParameters()->getSize()==0 && fPriorNuisanceNull)
|| (fAltModel->GetNuisanceParameters() && fAltModel->GetNuisanceParameters()->getSize()>0 && !fPriorNuisanceAlt)
){
oocoutE((TObject*)0,InputArguments) << "Nuisance PDF specified, but the pdf doesn't know which parameters are the nuisance parameters. Must set nuisance parameters in the 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)
<< "No nuisance parameters specified and no prior forced, reduces "
<< "to simple hypothesis testing with no uncertainty" << endl;
} else {
oocoutE((TObject*)0,InputArguments) << "inferring posterior from ModelConfig is not yet implemented" << endl;
}
ToyMCSampler *toymcs = dynamic_cast<ToyMCSampler*>(GetTestStatSampler());
if(toymcs) {
oocoutI((TObject*)0,InputArguments) << "Using a ToyMCSampler. Now configuring for Null." << endl;
if(fNToysNull) 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);
}
if(fNullImportanceDensity) {
oocoutI((TObject*)0,InputArguments) << "Importance Sampling" << endl;
toymcs->SetImportanceDensity(fNullImportanceDensity);
if(fNullImportanceSnapshot) toymcs->SetImportanceSnapshot(*fNullImportanceSnapshot);
}else{
toymcs->SetImportanceDensity(NULL);
}
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)
<< "No nuisance parameters specified and no prior forced, reduces "
<< "to simple hypothesis testing with no uncertainty" << endl;
} else {
oocoutE((TObject*)0,InputArguments) << "inferring posterior from ModelConfig is not yet implemented" << endl;
}
ToyMCSampler *toymcs = dynamic_cast<ToyMCSampler*>(GetTestStatSampler());
if(toymcs) {
oocoutI((TObject*)0,InputArguments) << "Using a ToyMCSampler. Now configuring for Alt." << endl;
if(fNToysAlt) 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);
}
if(fAltImportanceDensity) {
oocoutI((TObject*)0,InputArguments) << "Importance Sampling" << endl;
toymcs->SetImportanceDensity(fAltImportanceDensity);
if(fAltImportanceSnapshot) toymcs->SetImportanceSnapshot(*fAltImportanceSnapshot);
}else{
toymcs->SetImportanceDensity(NULL);
}
}
return 0;
}