83using std::string, std::unique_ptr;
98 std::unique_ptr<RooFitResult> *fitResult =
nullptr);
110 fgPrintLevel() = level;
119 const ModelConfig &nullModel,
bool nominalAsimov) :
121 fOneSided(false), fOneSidedDiscovery(false), fNominalAsimov(nominalAsimov),
123 fNLLObs(0), fNLLAsimov(0),
128 int verbose = fgPrintLevel();
132 assert(nullSnapshot);
138 oocoutI(
nullptr,InputArguments) <<
"AsymptotiCalculator: Minimum of POI is " << muNull->
getMin() <<
" corresponds to null snapshot - default configuration is one-sided discovery formulae " << std::endl;
156 int verbose = fgPrintLevel();
158 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::Initialize...." << std::endl;
163 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - ModelConfig has not a pdf defined" << std::endl;
168 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - data set has not been defined" << std::endl;
176 if (!poi || poi->
empty()) {
177 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - ModelConfig has not POI defined." << std::endl;
180 if (poi->
size() > 1) {
181 oocoutW(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - ModelConfig has more than one POI defined \n\t"
182 <<
"The asymptotic calculator works for only one POI - consider as POI only the first parameter"
189 if(nullSnapshot ==
nullptr || nullSnapshot->empty()) {
190 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - Null model needs a snapshot. Set using modelconfig->SetSnapshot(poi)." << std::endl;
205 allParams->snapshot(nominalParams);
217 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::Initialize - Find best unconditional NLL on observed data" << std::endl;
228 oocoutP(
nullptr,Eval) <<
"Best fitted POI value = " << muBest->
getVal() <<
" +/- " << muBest->
getError() << std::endl;
234 if(altSnapshot ==
nullptr || altSnapshot->empty()) {
235 oocoutE(
nullptr,InputArguments) <<
"Alt (Background) model needs a snapshot. Set using modelconfig->SetSnapshot(poi)." << std::endl;
241 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator: Building Asimov data Set" << std::endl;
254 oocoutW(
nullptr,InputArguments) <<
"AsymptoticCalculator: number of bins in " << xobs->
GetName() <<
" are different than data bins "
255 <<
" set the same data bins " <<
data.numEntries() <<
" in range "
256 <<
" [ " << xobs->
getMin() <<
" , " << xobs->
getMax() <<
" ]" << std::endl;
264 oocoutI(
nullptr,InputArguments) <<
"AsymptoticCalculator: Asimov data will be generated using fitted nuisance parameter values" << std::endl;
272 oocoutI(
nullptr,InputArguments) <<
"AsymptoticCalculator: Asimovdata set will be generated using nominal (current) nuisance parameter values" << std::endl;
273 nominalParams.
assign(poiAlt);
278 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator: Error : Asimov data set could not be generated " << std::endl;
301 <<
"AsymptoticCalculator::Initialize Find best conditional NLL on ASIMOV data set for given alt POI ( "
302 << muAlt->
GetName() <<
" ) = " << muAlt->
getVal() << std::endl;
315 globObs.
assign(globObsSnapshot);
318 if (prevBins > 0 && xobs) xobs->
setBins(prevBins);
327 std::unique_ptr<RooFitResult> *fitResult)
329 int verbose = fgPrintLevel();
348 std::unique_ptr<RooArgSet> attachedSet{
nll->getVariables()};
353 if (poiSet && !poiSet->
empty()) {
359 paramsSetConstant.
add(*poiVar);
361 if (poiSet->
size() > 1)
362 oocoutW(
nullptr,InputArguments) <<
"Model with more than one POI are not supported - ignore extra parameters, consider only first one" << std::endl;
390 bool skipFit = (nllParams.empty());
400 minim.setStrategy( strategy);
401 minim.setEvalErrorWall(config.useEvalErrorWall);
404 tol = std::max(tol,1.0);
407 minim.setPrintLevel(minimPrintLevel-1);
413 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::EvaluateNLL ........ using " << minimizer <<
" / " << algorithm
414 <<
" with strategy " << strategy <<
" and tolerance " << tol << std::endl;
417 for (
int tries = 1, maxtries = 4; tries <= maxtries; ++tries) {
419 status = minim.minimize(minimizer, algorithm);
425 oocoutW(
nullptr,Minimization) <<
" ----> Doing a re-scan first" << std::endl;
426 minim.minimize(minimizer,
"Scan");
430 oocoutW(
nullptr,Minimization) <<
" ----> trying with strategy = 1" << std::endl;
431 minim.setStrategy(1);
437 oocoutW(
nullptr,Minimization) <<
" ----> trying with improve" << std::endl;
438 minimizer =
"Minuit";
439 algorithm =
"migradimproved";
446 std::unique_ptr<RooFitResult>
result{minim.save()};
449 if (status >= 0 &&
result) {
460 oocoutE(
nullptr,Fitting) <<
"FIT FAILED !- return a NaN NLL " << std::endl;
465 *fitResult = std::move(
result);
470 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::EvaluateNLL - value = " << val;
473 ooccoutP(
nullptr,Eval) <<
" for poi fixed at = " << muTest;
477 ooccoutP(
nullptr,Eval) <<
"\tfit time : " << tw.
RealTime() <<
" s (real) " << tw.
CpuTime() <<
" s (cpu)" << std::endl;
479 ooccoutP(
nullptr,Eval) << std::endl;
504 int verbose = fgPrintLevel();
509 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::GetHypoTest - Error initializing Asymptotic calculator - return nullptr result " << std::endl;
515 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::GetHypoTest - Asimov data set has not been generated - return nullptr result " << std::endl;
528 assert(nullSnapshot && !nullSnapshot->empty());
534 if (poiTest.
size() > 1) {
535 oocoutW(
nullptr,InputArguments) <<
"AsymptoticCalculator::GetHypoTest: snapshot has more than one POI - assume as POI first parameter " << std::endl;
544 assert(muHat &&
"no best fit parameter defined");
546 assert(muTest &&
"poi snapshot is not existing");
551 oocoutI(
nullptr,Eval) <<
"\nAsymptoticCalculator::GetHypoTest: - perform an hypothesis test for POI ( " << muTest->
GetName() <<
" ) = " << muTest->
getVal() << std::endl;
552 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::GetHypoTest - Find best conditional NLL on OBSERVED data set ..... " << std::endl;
563 double qmu = 2.*(condNLL -
fNLLObs);
568 oocoutP(
nullptr,Eval) <<
"\t OBSERVED DATA : qmu = " << qmu <<
" condNLL = " << condNLL <<
" uncond " <<
fNLLObs << std::endl;
576 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: Found a negative value of the qmu - retry to do the unconditional fit "
580 <<
"AsymptoticCalculator: unconditional fit failed before - retry to do it now " << std::endl;
583 std::unique_ptr<RooFitResult> refitResult;
587 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: Found a better unconditional minimum "
588 <<
" old NLL = " <<
fNLLObs <<
" old muHat " << muHat->
getVal() << std::endl;
605 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: New minimum found for "
606 <<
" NLL = " <<
fNLLObs <<
" muHat " << muHat->
getVal() << std::endl;
612 oocoutP(
nullptr,Eval) <<
"After unconditional refit, new qmu value is " << qmu << std::endl;
618 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: qmu is still < 0 for mu = "
619 << muTest->
getVal() <<
" return a dummy result "
624 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: failure in fitting for qmu or qmuA "
625 << muTest->
getVal() <<
" return a dummy result "
649 if (verbose > 0)
oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::GetHypoTest -- Find best conditional NLL on ASIMOV data set .... " << std::endl;
661 oocoutP(
nullptr,Eval) <<
"\t ASIMOV data qmu_A = " << qmu_A <<
" condNLL = " << condNLL_A <<
" uncond " <<
fNLLAsimov << std::endl;
667 <<
"AsymptoticCalculator: Found a negative value of the qmu Asimov- retry to do the unconditional fit "
671 <<
"AsymptoticCalculator: Fit failed for unconditional the qmu Asimov- retry unconditional fit "
675 std::unique_ptr<RooFitResult> refitResult;
679 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: Found a better unconditional minimum for Asimov data set"
690 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: New minimum found for "
695 oocoutP(
nullptr,Eval) <<
"After unconditional Asimov refit, new qmu_A value is " << qmu_A << std::endl;
701 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: qmu_A is still < 0 for mu = "
702 << muTest->
getVal() <<
" return a dummy result "
707 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: failure in fitting for qmu or qmuA "
708 << muTest->
getVal() <<
" return a dummy result "
715 globObs.
assign(globObsSnapshot);
727 bool useQTilde =
false;
736 assert(muAlt !=
nullptr );
739 oocoutI(
nullptr,InputArguments) <<
"Minimum of POI is " << muTest->
getMin() <<
" corresponds to alt snapshot - using qtilde asymptotic formulae " << std::endl;
742 oocoutI(
nullptr,InputArguments) <<
"Minimum of POI is " << muTest->
getMin() <<
" is different to alt snapshot " << muAlt->
getVal()
743 <<
" - using standard q asymptotic formulae " << std::endl;
751 bool flipSign =
false;
755 oocoutI(
nullptr, Eval) <<
"Using signed one-sided qmu - flipping the sign of the test statistic muHat = "
756 << muHat->
getVal() <<
" muTest = " << muTest->
getVal() << std::endl;
759 oocoutI(
nullptr, Eval) <<
"Using one-sided qmu - setting qmu to zero muHat = " << muHat->
getVal()
760 <<
" muTest = " << muTest->
getVal() << std::endl;
769 <<
"Using signed one-sided discovery qmu - flipping the sign of the test statistic muHat = "
770 << muHat->
getVal() <<
" muTest = " << muTest->
getVal() << std::endl;
773 oocoutI(
nullptr, Eval) <<
"Using one-sided discovery qmu - setting qmu to zero muHat = " << muHat->
getVal()
774 <<
" muTest = " << muTest->
getVal() << std::endl;
781 if (qmu < 0 && qmu > -tol) qmu = 0;
782 if (qmu_A < 0 && qmu_A > -tol) qmu_A = 0;
798 double sqrtqmu = (qmu > 0) ? std::sqrt(qmu) : 0;
801 double sqrtqmu_A = (qmu_A > 0) ? std::sqrt(qmu_A) : 0;
808 oocoutI(
nullptr,Eval) <<
"Using one-sided limit asymptotic formula (qmu)" << std::endl;
810 oocoutI(
nullptr, Eval) <<
"Using one-sided discovery asymptotic formula (q0)" << std::endl;
818 if (verbose > 2)
oocoutI(
nullptr,Eval) <<
"Using two-sided asymptotic formula (tmu)" << std::endl;
828 if (useQTilde && !flipSign) {
831 if ( qmu > qmu_A && (qmu_A > 0 || qmu > tol) ) {
832 if (verbose > 2)
oocoutI(
nullptr,Eval) <<
"Using qmu_tilde (qmu is greater than qmu_A)" << std::endl;
840 if ( qmu > qmu_A && (qmu_A > 0 || qmu > tol) ) {
841 if (verbose > 2)
oocoutI(
nullptr,Eval) <<
"Using tmu_tilde (qmu is greater than qmu_A)" << std::endl;
851 string resultname =
"HypoTestAsymptotic_result";
855 oocoutP(
nullptr, Eval) <<
"poi = " << muTest->
getVal() <<
" qmu = " << qmu <<
" qmu_A = " << qmu_A
856 <<
" sigma = " << muTest->
getVal() / sqrtqmu_A <<
" CLsplusb = " << pnull
857 <<
" CLb = " << palt <<
" CLs = " << res->
CLs() << std::endl;
866 fOffset(
offset), fPval(pval), fCase(icase) {}
867 double operator() (
double x)
const {
883 if (!useCls)
return clsplusb;
885 return (clb == 0) ? -1 : clsplusb / clb;
900 bool ret = brf.
Solve();
902 oocoutE(
nullptr,Eval) <<
"Error finding expected p-values - return -1" << std::endl;
905 double sqrttmu_A = brf.
Root();
913 oocoutE(
nullptr,Eval) <<
"Error finding expected p-values - return -1" << std::endl;
926 bool debug = (fgPrintLevel() >= 2);
934 if (debug)
oocoutI(
nullptr,Generation) <<
"looping on observable " <<
v->GetName() << std::endl;
935 for (
int i = 0; i <
v->getBins(); ++i) {
939 double prevBinVolume = binVolume;
940 binVolume *=
v->getBinWidth(i);
941 FillBins(pdf, obs,
data,
index, binVolume, ibin);
943 binVolume = prevBinVolume;
948 double totBinVolume = binVolume *
v->getBinWidth(i);
949 double fval = pdf.
getVal(&obstmp)*totBinVolume;
954 if (fval*expectedEvents <= 0)
956 if (fval*expectedEvents < 0) {
957 oocoutW(
nullptr,InputArguments)
958 <<
"AsymptoticCalculator::" << __func__
959 <<
"(): Bin " << i <<
" of " <<
v->GetName() <<
" has negative expected events! Please check your inputs." << std::endl;
962 oocoutW(
nullptr,InputArguments)
963 <<
"AsymptoticCalculator::" << __func__
964 <<
"(): Bin " << i <<
" of " <<
v->GetName() <<
" has zero expected events" << std::endl;
970 data.add(obs, fval*expectedEvents);
974 oocoutI(
nullptr,Generation) <<
"bin " << ibin <<
"\t";
975 for (std::size_t j=0; j < obs.
size(); ++j) {
ooccoutI(
nullptr,Generation) <<
" " << (
static_cast<RooRealVar&
>( obs[j])).getVal(); }
976 ooccoutI(
nullptr,Generation) <<
" w = " << fval*expectedEvents;
977 ooccoutI(
nullptr,Generation) << std::endl;
984 oocoutI(
nullptr,Generation) <<
"ending loop on .. " <<
v->GetName() << std::endl;
999 const bool meanIsObs = obs.
contains(mean);
1000 if (xIsObs && meanIsObs) {
1001 oocoutF(
nullptr, Generation) << errPrefix <<
"Has two observables ?? " << std::endl;
1004 if (!xIsObs && !meanIsObs) {
1005 oocoutF(
nullptr, Generation) << errPrefix <<
"No observable?" << std::endl;
1008 auto *myobs =
dynamic_cast<RooRealVar *
>(xIsObs ? &
x : &mean);
1009 auto *myexp =
dynamic_cast<RooAbsReal *
>(xIsObs ? &mean : &
x);
1010 if (myobs ==
nullptr) {
1011 oocoutF(
nullptr, Generation) << errPrefix <<
"Observable is not a RooRealVar??" << std::endl;
1014 if (myexp ==
nullptr) {
1015 oocoutF(
nullptr, Generation) << errPrefix <<
"Expected is not a RooAbsReal??" << std::endl;
1019 myobs->setVal(myexp->getVal());
1021 if (fgPrintLevel() > 2) {
1022 oocoutI(
nullptr,Generation) <<
"SetObsToExpected : setting " << myobs->GetName() <<
" to expected value " << myexp->getVal() <<
" of " << myexp->GetName() << std::endl;
1036 std::string
const &errPrefix =
"AsymptoticCalculator::SetObsExpected( " + std::string{pdf.
ClassName()} +
" ) : ";
1043 std::string
const &errPrefix =
"AsymptoticCalculator::SetObsExpected( " + std::string{pdf.
ClassName()} +
" ) : ";
1054 std::string
const &errPrefix =
"AsymptoticCalculator::SetObsExpected( " + std::string{mvgauss.
ClassName()} +
" ) : ";
1056 for (std::size_t iDim = 0; iDim < mvgauss.
xVec().
size(); ++iDim) {
1057 ret &= setObsToExpected(mvgauss.
xVec()[iDim], mvgauss.
muVec()[iDim], obs,
1058 errPrefix +
" : dim " + std::to_string(iDim) +
" ");
1070 for (
auto *
a : prod.pdfList()) {
1071 if (!
a->dependsOn(obs))
continue;
1076 if ((pois =
dynamic_cast<RooPoisson *
>(
a)) !=
nullptr) {
1077 ret &= SetObsToExpected(*pois, obs);
1079 }
else if ((gauss =
dynamic_cast<RooGaussian *
>(
a)) !=
nullptr) {
1080 ret &= SetObsToExpected(*gauss, obs);
1082 ret &= setObsToExpectedMultiVarGauss(*mvgauss, obs);
1084 ret &= setObsToExpectedProdPdf(*subprod, obs);
1086 oocoutE(
nullptr, InputArguments)
1087 <<
"Illegal term in counting model: "
1088 <<
"the PDF " <<
a->GetName() <<
" depends on the observables, but is not a Poisson, Gaussian or Product"
1109 if (fgPrintLevel() > 1)
1110 oocoutI(
nullptr,Generation) <<
"generate counting Asimov data for pdf of type " << pdf.
ClassName() << std::endl;
1113 if (prod !=
nullptr) {
1114 r = setObsToExpectedProdPdf(*prod, observables);
1115 }
else if ((pois =
dynamic_cast<RooPoisson *
>(&pdf)) !=
nullptr) {
1116 r = SetObsToExpected(*pois, observables);
1119 }
else if ((gauss =
dynamic_cast<RooGaussian *
>(&pdf)) !=
nullptr) {
1120 r = SetObsToExpected(*gauss, observables);
1122 r = setObsToExpectedMultiVarGauss(*mvgauss, observables);
1124 oocoutE(
nullptr,InputArguments) <<
"A counting model pdf must be either a RooProdPdf or a RooPoisson or a RooGaussian" << std::endl;
1126 if (!
r)
return nullptr;
1133 "CountingAsimovData" + std::to_string(icat), obs);
1146 int printLevel = fgPrintLevel();
1153 if (!pdf.
canBeExtended() )
return GenerateCountingAsimovData(
const_cast<RooAbsPdf&
>(pdf), *obs, weightVar, channelCat);
1156 obsAndWeight.add(weightVar);
1158 std::unique_ptr<RooDataSet> asimovData;
1161 asimovData = std::make_unique<RooDataSet>(
"AsimovData" + std::to_string(icat),
1162 "combAsimovData" + std::to_string(icat),
1179 std::vector<RooRealVar *> obsWithDefaultBinning;
1180 for (
auto *arg : obsList) {
1182 if (rrv && rrv->getBins() == 0) {
1184 obsWithDefaultBinning.push_back(rrv);
1189 if (printLevel >= 2) {
1190 oocoutI(
nullptr,Generation) <<
"Generating Asimov data for pdf " << pdf.
GetName() << std::endl;
1191 oocoutI(
nullptr,Generation) <<
"list of observables " << std::endl;
1196 double binVolume = 1;
1198 FillBins(pdf, obsList, *asimovData, obsIndex, binVolume, nbins);
1201 for (
auto *rrv : obsWithDefaultBinning) {
1204 if (printLevel >= 2)
1205 oocoutI(
nullptr,Generation) <<
"filled from " << pdf.
GetName() <<
" " << nbins <<
" nbins " <<
" volume is " << binVolume << std::endl;
1223 if (printLevel >= 1)
1225 asimovData->Print();
1228 oocoutE(
nullptr,Generation) <<
"sum entries is nan"<< std::endl;
1230 asimovData =
nullptr;
1233 return asimovData.release();
1246 int printLevel = fgPrintLevel();
1248 RooRealVar weightVar{
"binWeightAsimov",
"binWeightAsimov", 1, 0, 1.e30};
1250 if (printLevel > 1)
oocoutI(
nullptr,Generation) <<
" Generate Asimov data for observables"<< std::endl;
1256 for (
auto ele : list) {
1259 strippedPdfSet.
add(*pdfi);
1262 RooProdPdf observableProdPdf(
"observableProdPdf",
"observableProdPdf", strippedPdfSet);
1265 if (strippedPdfSet.
getSize() == 1) {
1266 observablePdf =
dynamic_cast<const RooAbsPdf *
>(strippedPdfSet.
at(0));
1268 observablePdf = &observableProdPdf;
1271 observablePdf = &pdf;
1276 return GenerateAsimovDataSinglePdf(*observablePdf, observables, weightVar,
nullptr);
1279 std::map<std::string, std::unique_ptr<RooDataSet>> asimovDataMap;
1283 int nrIndices = channelCat.
numTypes();
1284 if( nrIndices == 0 ) {
1285 oocoutW(
nullptr,Generation) <<
"Simultaneous pdf does not contain any categories." << std::endl;
1287 for (
int i=0;i<nrIndices;i++){
1292 assert(pdftmp !=
nullptr);
1299 std::unique_ptr<RooDataSet> dataSinglePdf{
static_cast<RooDataSet*
>(GenerateAsimovDataSinglePdf( *pdftmp, observables, weightVar, &channelCat))};
1300 if (!dataSinglePdf) {
1301 oocoutE(
nullptr,Generation) <<
"Error generating an Asimov data set for pdf " << pdftmp->
GetName() << std::endl;
1306 oocoutE(
nullptr,Generation) <<
"AsymptoticCalculator::GenerateAsimovData(): The PDF for " << channelCat.
getCurrentLabel()
1307 <<
" was already defined. It will be overridden. The faulty category definitions follow:" << std::endl;
1308 channelCat.
Print(
"V");
1314 dataSinglePdf->Print();
1315 ooccoutI(
nullptr,Generation) << std::endl;
1318 asimovDataMap[string(channelCat.
getCurrentLabel())] = std::move(dataSinglePdf);
1322 obsAndWeight.
add(weightVar);
1325 return new RooDataSet(
"asimovDataFullModel",
"asimovDataFullModel",
RooArgSet(obsAndWeight,channelCat),
1342 int verbose = fgPrintLevel();
1345 RooArgSet poi(*model.GetParametersOfInterest());
1351 for (
auto *tmpPar : static_range_cast<RooRealVar *>(poi)) {
1352 tmpPar->setConstant();
1354 oocoutI(
nullptr,Generation) <<
"MakeAsimov: Setting poi " << tmpPar->
GetName() <<
" to a constant value = " << tmpPar->getVal() << std::endl;
1355 paramsSetConstant.
add(*tmpPar);
1359 bool hasFloatParams =
false;
1361 if (model.GetNuisanceParameters()) {
1362 constrainParams.
add(*model.GetNuisanceParameters());
1364 if (!constrainParams.
empty()) hasFloatParams =
true;
1368 std::unique_ptr<RooArgSet> params(model.GetPdf()->getParameters(realData));
1369 for (
auto const *rrv : dynamic_range_cast<RooRealVar *>(*params)) {
1370 if ( rrv !=
nullptr && rrv->isConstant() == false ) { hasFloatParams =
true;
break; }
1373 if (hasFloatParams) {
1379 oocoutP(
nullptr,Generation) <<
"MakeAsimov: doing a conditional fit for finding best nuisance values " << std::endl;
1380 minimPrintLevel = verbose;
1382 oocoutI(
nullptr,Generation) <<
"POI values:\n"; poi.
Print(
"v");
1384 oocoutI(
nullptr,Generation) <<
"Nuis param values:\n";
1385 constrainParams.
Print(
"v");
1393 std::vector<RooCmdArg> args{
1404 for (
auto& arg : args) {
1407 model.fitTo(realData, argList);
1410 oocoutP(
nullptr,Generation) <<
"fit time : " << tw2.
RealTime() <<
" s (real) " << tw2.
CpuTime() <<
" s (cpu)" << std::endl;
1414 if (model.GetNuisanceParameters() ) {
1415 oocoutI(
nullptr,Generation) <<
"Nuisance parameters after fit for asimov dataset: " << std::endl;
1416 model.GetNuisanceParameters()->Print(
"V");
1427 std::unique_ptr<RooArgSet> allParams{model.GetPdf()->getParameters(realData)};
1433 allParams->assign(*genPoiValues);
1452 int verbose = fgPrintLevel();
1459 if (!allParamValues.
empty()) {
1460 std::unique_ptr<RooArgSet> allVars{model.GetPdf()->getVariables()};
1461 allVars->assign(allParamValues);
1469 oocoutI(
nullptr,Generation) <<
"Generated Asimov data for observables "; (model.GetObservables() )->Print();
1472 oocoutI(
nullptr,Generation) <<
"--- Asimov data values \n";
1476 oocoutI(
nullptr,Generation) <<
"--- Asimov data numEntries = " << asimov->
numEntries() <<
" sumOfEntries = " << asimov->
sumEntries() << std::endl;
1479 oocoutI(
nullptr,Generation) <<
"\ttime for generating : " << tw.
RealTime() <<
" s (real) " << tw.
CpuTime() <<
" s (cpu)" << std::endl;
1496 if (model.GetGlobalObservables() && !model.GetGlobalObservables()->empty()) {
1499 oocoutI(
nullptr,Generation) <<
"Generating Asimov data for global observables " << std::endl;
1502 RooArgSet gobs(*model.GetGlobalObservables());
1511 if (model.GetNuisanceParameters()) nuis.
add(*model.GetNuisanceParameters());
1513 oocoutW(
nullptr,Generation) <<
"AsymptoticCalculator::MakeAsimovData: model does not have nuisance parameters but has global observables"
1514 <<
" set global observables to model values " << std::endl;
1515 asimovGlobObs.
assign(gobs);
1521 if (nuispdf ==
nullptr) {
1522 oocoutF(
nullptr, Generation) <<
"AsymptoticCalculator::MakeAsimovData: model has nuisance parameters and "
1523 "global obs but no nuisance pdf "
1533 pdfList.
add(*nuispdf);
1536 for (
auto *cterm : static_range_cast<RooAbsPdf *>(pdfList)) {
1538 "AsimovUtils: a factor of the nuisance pdf is not a Pdf!");
1540 if (!cterm->dependsOn(nuis))
continue;
1542 if (
typeid(*cterm) ==
typeid(
RooUniform))
continue;
1544 std::unique_ptr<RooArgSet> cpars(cterm->getParameters(&gobs));
1545 std::unique_ptr<RooArgSet> cgobs(cterm->getObservables(&gobs));
1546 if (cgobs->size() > 1) {
1547 oocoutE(
nullptr,Generation) <<
"AsymptoticCalculator::MakeAsimovData: constraint term " << cterm->GetName()
1548 <<
" has multiple global observables -cannot generate - skip it" << std::endl;
1551 else if (cgobs->empty()) {
1553 <<
"AsymptoticCalculator::MakeAsimovData: constraint term " << cterm->GetName()
1554 <<
" has no global observables - skip it" << std::endl;
1562 if (cpars->size() != 1) {
1564 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1565 << cterm->GetName() <<
" has multiple floating params - cannot generate - skip it " << std::endl;
1569 bool foundServer =
false;
1573 if (verbose > 2)
oocoutI(
nullptr,Generation) <<
"Constraint " << cterm->
GetName() <<
" of type " << cClass->
GetName() << std::endl;
1579 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1580 << cterm->GetName() <<
" of type " << className
1581 <<
" is a non-supported type - result might be not correct " << std::endl;
1599 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1600 << cterm->
GetName() <<
" has no direct dependence on global observable- cannot generate it " << std::endl;
1611 for (
RooAbsArg *a2 : cterm->servers()) {
1617 if (thetaGamma ==
nullptr) {
1619 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1620 << cterm->
GetName() <<
" is a Gamma distribution and no server named theta is found. Assume that the Gamma scale is 1 " << std::endl;
1622 else if (verbose>2) {
1623 oocoutI(
nullptr,Generation) <<
"Gamma constraint has a scale " << thetaGamma->
GetName() <<
" = " << thetaGamma->
getVal() << std::endl;
1626 for (
RooAbsArg *a2 : cterm->servers()) {
1628 if (verbose > 2)
oocoutI(
nullptr,Generation) <<
"Loop on constraint server term " << a2->
GetName() << std::endl;
1634 oocoutE(
nullptr,Generation) <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1635 << cterm->GetName() <<
" constraint term has more server depending on nuisance- cannot generate it " <<
1637 foundServer =
false;
1640 if (thetaGamma && thetaGamma->
getVal() > 0) {
1648 oocoutI(
nullptr,Generation) <<
"setting global observable " << rrv.
GetName() <<
" to value " << rrv.
getVal()
1649 <<
" which comes from " << rrv2->
GetName() << std::endl;
1655 oocoutE(
nullptr,Generation) <<
"AsymptoticCalculator::MakeAsimovData - can't find nuisance for constraint term - global observables will not be set to Asimov value " << cterm->GetName() << std::endl;
1656 oocoutE(
nullptr,Generation) <<
"Parameters: " << std::endl;
1658 oocoutE(
nullptr,Generation) <<
"Observables: " << std::endl;
1671 gobs.
assign(snapGlobalObsData);
1674 oocoutI(
nullptr,Generation) <<
"Generated Asimov data for global observables ";
1675 if (verbose == 1) gobs.
Print();
1679 oocoutI(
nullptr,Generation) <<
"\nGlobal observables for data: " << std::endl;
1681 oocoutI(
nullptr,Generation) <<
"\nGlobal observables for asimov: " << std::endl;
1682 asimovGlobObs.
Print(
"V");
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Class for finding the root of a one dimensional function using the Brent algorithm.
bool SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup) override
Sets the function for the rest of the algorithms.
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10) override
Returns the X value corresponding to the function value fy for (xmin<x<xmax).
double Root() const override
Returns root value.
static int DefaultPrintLevel()
static double DefaultTolerance()
static const std::string & DefaultMinimizerAlgo()
static int DefaultStrategy()
Template class to wrap any C++ callable object which takes one argument i.e.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
bool isConstant() const
Check if the "Constant" attribute is set.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
virtual const char * getCurrentLabel() const
Return label string of current state.
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr)
bool contains(const char *name) const
Check if collection contains an argument with a specific name.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Storage_t const & get() const
Const access to the underlying stl container.
Int_t getSize() const
Return the number of elements in the collection.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
RooAbsArg * first() const
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Abstract base class for binned and unbinned datasets.
virtual double sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
virtual const RooArgSet * get() const
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract interface for all probability density functions.
virtual double expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
virtual Int_t getBins(const char *name=nullptr) const
Get number of bins of currently defined range.
void setConstant(bool value=true)
static constexpr int DefaultNBins
Historical default number of bins, injected by routines that need a concrete bin count when a variabl...
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
static void setHideOffset(bool flag)
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Object to represent discrete states.
bool setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
value_type getCurrentIndex() const final
Return current index.
Container class to hold unbinned data.
void add(const RooArgSet &row, double weight, double weightError)
Add one ore more rows of data.
RooAbsReal const & getX() const
Get the x variable.
RooAbsReal const & getMean() const
Get the mean parameter.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
virtual void Add(TObject *arg)
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Multivariate Gaussian p.d.f.
const RooArgList & xVec() const
const RooArgList & muVec() const
RooAbsReal const & getX() const
Get the x variable.
void setNoRounding(bool flag=true)
Switch off/on rounding of x to the nearest integer.
RooAbsReal const & getMean() const
Get the mean parameter.
Efficient implementation of a product of PDFs of the form.
const RooArgList & pdfList() const
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void setBins(Int_t nBins, const char *name=nullptr, bool shared=true)
Create a uniform binning under name 'name' for this variable.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
const RooAbsCategoryLValue & indexCat() const
std::unique_ptr< RooFitResult > fFitResultCondObs
! result of conditional fit to observed data
std::unique_ptr< RooFitResult > fFitResultUncondAsimov
! result of fit to Asimov data at the alt POI
std::unique_ptr< RooAbsData > fAsimovData
asimov data set
static RooAbsData * MakeAsimovData(RooAbsData &data, const ModelConfig &model, const RooArgSet ¶mValues, RooArgSet &globObs, const RooArgSet *genPoiValues=nullptr)
Make Asimov data.
static double GetExpectedPValues(double pnull, double palt, double nsigma, bool usecls, bool oneSided=true)
function given the null and the alt p value - return the expected one given the N - sigma value
std::unique_ptr< RooFitResult > fFitResultCondAsimov
! result of conditional fit to Asimov data
static void SetPrintLevel(int level)
set print level (static function)
RooArgSet fAsimovGlobObs
snapshot of Asimov global observables
static RooAbsData * GenerateAsimovData(const RooAbsPdf &pdf, const RooArgSet &observables)
generate the asimov data for the observables (not the global ones) need to deal with the case of a si...
int fUseQTilde
flag to indicate if using qtilde or not (-1 (default based on RooRealVar)), 0 false,...
bool fIsInitialized
! flag to check if calculator is initialized
HypoTestResult * GetHypoTest() const override
re-implement HypoTest computation using the asymptotic
bool fOneSided
for one sided PL test statistic (upper limits)
RooArgSet fBestFitParams
snapshot of all best fitted Parameter values
AsymptoticCalculator(RooAbsData &data, const ModelConfig &altModel, const ModelConfig &nullModel, bool nominalAsimov=false)
constructor for asymptotic calculator from Data set and ModelConfig
std::unique_ptr< RooFitResult > fFitResultUncondObs
! result of unconditional fit to observed data
bool fSigned
use signed (uncapped) PL test statistic
bool fOneSidedDiscovery
for one sided PL test statistic (for discovery)
RooArgSet fBestFitPoi
snapshot of best fitted POI values
bool fNominalAsimov
make Asimov at nominal parameter values
bool Initialize() const
initialize the calculator by performing a global fit and make the Asimov data set
Common base class for the Hypothesis Test Calculators.
const ModelConfig * GetNullModel(void) const
const ModelConfig * GetAlternateModel(void) const
const RooAbsData * GetData(void) const
HypoTestResult is a base class for results from hypothesis tests.
virtual double CLs() const
is simply (not a method, but a quantity)
< A class that holds configuration information for a model using a workspace as a store
std::unique_ptr< RooAbsReal > createNLL(RooAbsData &data, CmdArgs_t const &...cmdArgs) const
Wrapper around RooAbsPdf::createNLL(), where the pdf and some configuration options are retrieved fro...
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
const RooArgSet * GetObservables() const
get RooArgSet for observables (return nullptr if not existing)
const RooArgSet * GetSnapshot() const
get RooArgSet for parameters for a particular hypothesis (return nullptr if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
TClass instances represent classes, structs and namespaces in the ROOT type system.
TClass * IsA() const override
const char * GetName() const override
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
RooCmdArg Index(RooCategory &icat)
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg Import(const char *state, TH1 &histo)
RooCmdArg Offset(std::string const &mode)
RooCmdArg Constrain(const RooArgSet ¶ms)
RooCmdArg Minimizer(const char *type, const char *alg=nullptr)
RooCmdArg Hesse(bool flag=true)
RooCmdArg Strategy(Int_t code)
RooCmdArg EvalErrorWall(bool flag)
RooCmdArg PrintLevel(Int_t level)
double normal_cdf_c(double x, double sigma=1, double x0=0)
Complement of the cumulative distribution function of the normal (Gaussian) distribution (upper tail)...
double normal_cdf(double x, double sigma=1, double x0=0)
Cumulative distribution function of the normal (Gaussian) distribution (lower tail).
double normal_quantile(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the lower tail of the normal (Gaussian) distri...
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
double nll(double pdf, double weight, int binnedL, int doBinOffset)
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Namespace for the RooStats classes.
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
utility function to set all variable constant in a collection (from G.
void RemoveConstantParameters(RooArgSet *set)
std::string const & NLLOffsetMode()
Test what offsetting mode RooStats should use by default.
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
extract constraint terms from pdf
RooStatsConfig & GetGlobalRooStatsConfig()
Retrieve the config object which can be used to set flags for things like offsetting the likelihood o...
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
PaltFunction(double offset, double pval, int icase)