31 ClassImp(RooStats::FrequentistCalculator);
33 using namespace RooStats;
38 void FrequentistCalculator::PreHook()
const {
39 if (fFitInfo != NULL) {
44 fFitInfo =
new RooArgSet();
50 void FrequentistCalculator::PostHook()
const {
55 int FrequentistCalculator::PreNullHook(RooArgSet *parameterPoint,
double obsTestStat)
const {
60 RooArgSet * allParams = fNullModel->GetPdf()->getParameters(*fData);
61 RemoveConstantParameters(allParams);
69 bool doProfile =
true;
70 RooArgSet allButNuisance(*allParams);
71 if( fNullModel->GetNuisanceParameters() ) {
72 allButNuisance.remove(*fNullModel->GetNuisanceParameters());
73 if( fConditionalMLEsNull ) {
74 oocoutI((TObject*)0,InputArguments) <<
"Using given conditional MLEs for Null." << endl;
75 *allParams = *fConditionalMLEsNull;
77 allButNuisance.add( *fConditionalMLEsNull );
78 if (fNullModel->GetNuisanceParameters()) {
79 RooArgSet remain(*fNullModel->GetNuisanceParameters());
80 remain.remove(*fConditionalMLEsNull,
true,
true);
81 if( remain.getSize() == 0 ) doProfile =
false;
88 oocoutI((TObject*)0,InputArguments) <<
"Profiling conditional MLEs for Null." << endl;
89 RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow();
90 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
92 RooArgSet conditionalObs;
93 if (fNullModel->GetConditionalObservables()) conditionalObs.add(*fNullModel->GetConditionalObservables());
95 if (fNullModel->GetGlobalObservables()) globalObs.add(*fNullModel->GetGlobalObservables());
97 auto& config = GetGlobalRooStatsConfig();
98 RooAbsReal* nll = fNullModel->GetPdf()->createNLL(*const_cast<RooAbsData*>(fData), RooFit::CloneData(kFALSE), RooFit::Constrain(*allParams),
99 RooFit::GlobalObservables(globalObs),
100 RooFit::ConditionalObservables(conditionalObs),
101 RooFit::Offset(config.useLikelihoodOffset));
102 RooProfileLL* profile =
dynamic_cast<RooProfileLL*
>(nll->createProfile(allButNuisance));
107 RooFitResult *result = profile->minimizer()->save();
108 RooArgSet * detOutput = DetailedOutputAggregator::GetAsArgSet(result,
"fitNull_");
109 fFitInfo->addOwned(*detOutput);
116 RooMsgService::instance().setGlobalKillBelow(msglevel);
120 TestStatistic * testStatistic =
nullptr;
121 auto testStatSampler = GetTestStatSampler();
122 if (testStatSampler) testStatistic = testStatSampler->GetTestStatistic();
124 testStatistic->SetConditionalObservables(conditionalObs);
125 testStatistic->SetGlobalObservables(globalObs);
131 if(fNullModel->GetNuisanceParameters())
132 parameterPoint->add(*fNullModel->GetNuisanceParameters());
140 ToyMCSampler *toymcs =
dynamic_cast<ToyMCSampler*
>(GetTestStatSampler());
142 oocoutI((TObject*)0,InputArguments) <<
"Using a ToyMCSampler. Now configuring for Null." << endl;
145 if(fNToysNull >= 0) toymcs->SetNToys(fNToysNull);
148 toymcs->SetGlobalObservables(*fNullModel->GetGlobalObservables());
152 oocoutI((TObject*)0,InputArguments) <<
"Adaptive Sampling" << endl;
153 if(GetTestStatSampler()->GetTestStatistic()->PValueIsRightTail()) {
154 toymcs->SetToysRightTail(fNToysNullTail, obsTestStat);
156 toymcs->SetToysLeftTail(fNToysNullTail, obsTestStat);
159 toymcs->SetToysBothTails(0, 0, obsTestStat);
162 GetNullModel()->LoadSnapshot();
170 int FrequentistCalculator::PreAltHook(RooArgSet *parameterPoint,
double obsTestStat)
const {
175 RooArgSet * allParams = fAltModel->GetPdf()->getParameters(*fData);
176 RemoveConstantParameters(allParams);
178 bool doProfile =
true;
179 RooArgSet allButNuisance(*allParams);
180 if( fAltModel->GetNuisanceParameters() ) {
181 allButNuisance.remove(*fAltModel->GetNuisanceParameters());
182 if( fConditionalMLEsAlt ) {
183 oocoutI((TObject*)0,InputArguments) <<
"Using given conditional MLEs for Alt." << endl;
184 *allParams = *fConditionalMLEsAlt;
186 allButNuisance.add( *fConditionalMLEsAlt );
187 if (fAltModel->GetNuisanceParameters()) {
188 RooArgSet remain(*fAltModel->GetNuisanceParameters());
189 remain.remove(*fConditionalMLEsAlt,
true,
true);
190 if( remain.getSize() == 0 ) doProfile =
false;
197 oocoutI((TObject*)0,InputArguments) <<
"Profiling conditional MLEs for Alt." << endl;
198 RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow();
199 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
201 RooArgSet conditionalObs;
202 if (fAltModel->GetConditionalObservables()) conditionalObs.add(*fAltModel->GetConditionalObservables());
204 if (fAltModel->GetGlobalObservables()) globalObs.add(*fAltModel->GetGlobalObservables());
206 const auto& config = GetGlobalRooStatsConfig();
207 RooAbsReal* nll = fAltModel->GetPdf()->createNLL(*const_cast<RooAbsData*>(fData), RooFit::CloneData(kFALSE), RooFit::Constrain(*allParams),
208 RooFit::GlobalObservables(globalObs),
209 RooFit::ConditionalObservables(conditionalObs),
210 RooFit::Offset(config.useLikelihoodOffset));
212 RooProfileLL* profile =
dynamic_cast<RooProfileLL*
>(nll->createProfile(allButNuisance));
217 RooFitResult *result = profile->minimizer()->save();
218 RooArgSet * detOutput = DetailedOutputAggregator::GetAsArgSet(result,
"fitAlt_");
219 fFitInfo->addOwned(*detOutput);
226 RooMsgService::instance().setGlobalKillBelow(msglevel);
230 TestStatistic * testStatistic =
nullptr;
231 auto testStatSampler = GetTestStatSampler();
232 if (testStatSampler) testStatistic = testStatSampler->GetTestStatistic();
234 testStatistic->SetConditionalObservables(conditionalObs);
235 testStatistic->SetGlobalObservables(globalObs);
241 if(fAltModel->GetNuisanceParameters())
242 parameterPoint->add(*fAltModel->GetNuisanceParameters());
249 ToyMCSampler *toymcs =
dynamic_cast<ToyMCSampler*
>(GetTestStatSampler());
251 oocoutI((TObject*)0,InputArguments) <<
"Using a ToyMCSampler. Now configuring for Alt." << endl;
254 if(fNToysAlt >= 0) toymcs->SetNToys(fNToysAlt);
257 toymcs->SetGlobalObservables(*fAltModel->GetGlobalObservables());
261 oocoutI((TObject*)0,InputArguments) <<
"Adaptive Sampling" << endl;
262 if(GetTestStatSampler()->GetTestStatistic()->PValueIsRightTail()) {
263 toymcs->SetToysLeftTail(fNToysAltTail, obsTestStat);
265 toymcs->SetToysRightTail(fNToysAltTail, obsTestStat);
268 toymcs->SetToysBothTails(0, 0, obsTestStat);