75using std::string, std::unique_ptr;
101 fgPrintLevel() = level;
110 const ModelConfig &nullModel,
bool nominalAsimov) :
119 int verbose = fgPrintLevel();
123 assert(nullSnapshot);
129 oocoutI(
nullptr,InputArguments) <<
"AsymptotiCalculator: Minimum of POI is " << muNull->
getMin() <<
" corresponds to null snapshot - default configuration is one-sided discovery formulae " << std::endl;
147 int verbose = fgPrintLevel();
149 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::Initialize...." << std::endl;
154 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - ModelConfig has not a pdf defined" << std::endl;
159 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - data set has not been defined" << std::endl;
167 if (!poi || poi->
empty()) {
168 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - ModelConfig has not POI defined." << std::endl;
171 if (poi->
size() > 1) {
172 oocoutW(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - ModelConfig has more than one POI defined \n\t"
173 <<
"The asymptotic calculator works for only one POI - consider as POI only the first parameter"
180 if(nullSnapshot ==
nullptr || nullSnapshot->
empty()) {
181 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::Initialize - Null model needs a snapshot. Set using modelconfig->SetSnapshot(poi)." << std::endl;
193 std::unique_ptr<RooArgSet> allParams{nullPdf->
getParameters(data)};
196 allParams->snapshot(nominalParams);
204 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::Initialize - Find best unconditional NLL on observed data" << std::endl;
211 oocoutP(
nullptr,Eval) <<
"Best fitted POI value = " << muBest->
getVal() <<
" +/- " << muBest->
getError() << std::endl;
217 if(altSnapshot ==
nullptr || altSnapshot->
empty()) {
218 oocoutE(
nullptr,InputArguments) <<
"Alt (Background) model needs a snapshot. Set using modelconfig->SetSnapshot(poi)." << std::endl;
224 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator: Building Asimov data Set" << std::endl;
235 if (data.numEntries() != xobs->
getBins() ) {
237 oocoutW(
nullptr,InputArguments) <<
"AsymptoticCalculator: number of bins in " << xobs->
GetName() <<
" are different than data bins "
238 <<
" set the same data bins " << data.numEntries() <<
" in range "
239 <<
" [ " << xobs->
getMin() <<
" , " << xobs->
getMax() <<
" ]" << std::endl;
240 xobs->
setBins(data.numEntries());
247 oocoutI(
nullptr,InputArguments) <<
"AsymptoticCalculator: Asimov data will be generated using fitted nuisance parameter values" << std::endl;
255 oocoutI(
nullptr,InputArguments) <<
"AsymptoticCalculator: Asimovdata set will be generated using nominal (current) nuisance parameter values" << std::endl;
256 nominalParams.
assign(poiAlt);
261 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator: Error : Asimov data set could not be generated " << std::endl;
284 <<
"AsymptoticCalculator::Initialize Find best conditional NLL on ASIMOV data set for given alt POI ( "
285 << muAlt->
GetName() <<
" ) = " << muAlt->
getVal() << std::endl;
294 globObs.
assign(globObsSnapshot);
297 if (prevBins > 0 && xobs) xobs->
setBins(prevBins);
307 int verbose = fgPrintLevel();
315 std::unique_ptr<RooArgSet> allParams{pdf.
getParameters(data)};
323 std::unique_ptr<RooArgSet> attachedSet{
nll->getVariables()};
326 RooArgSet paramsSetConstant;
328 if (poiSet && !poiSet->
empty()) {
329 RooRealVar * muTest =
static_cast<RooRealVar*
> (poiSet->
first());
330 RooRealVar * poiVar =
dynamic_cast<RooRealVar*
>(attachedSet->find( muTest->
GetName() ) );
334 paramsSetConstant.
add(*poiVar);
336 if (poiSet->
size() > 1)
337 oocoutW(
nullptr,InputArguments) <<
"Model with more than one POI are not supported - ignore extra parameters, consider only first one" << std::endl;
363 RooArgSet nllParams(*attachedSet);
365 bool skipFit = (nllParams.empty());
373 RooMinimizer minim(*nll);
375 minim.setStrategy( strategy);
376 minim.setEvalErrorWall(config.useEvalErrorWall);
379 tol = std::max(tol,1.0);
382 minim.setPrintLevel(minimPrintLevel-1);
384 minim.optimizeConst(2);
385 TString minimizer =
"";
389 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::EvaluateNLL ........ using " << minimizer <<
" / " << algorithm
390 <<
" with strategy " << strategy <<
" and tolerance " << tol << std::endl;
393 for (
int tries = 1, maxtries = 4; tries <= maxtries; ++tries) {
395 status = minim.minimize(minimizer, algorithm);
401 oocoutW(
nullptr,Minimization) <<
" ----> Doing a re-scan first" << std::endl;
402 minim.minimize(minimizer,
"Scan");
406 oocoutW(
nullptr,Minimization) <<
" ----> trying with strategy = 1" << std::endl;
407 minim.setStrategy(1);
413 oocoutW(
nullptr,Minimization) <<
" ----> trying with improve" << std::endl;
414 minimizer =
"Minuit";
415 algorithm =
"migradimproved";
420 std::unique_ptr<RooFitResult> result;
424 result = std::unique_ptr<RooFitResult>{minim.save()};
428 val = result->minNll();
438 oocoutE(
nullptr,Fitting) <<
"FIT FAILED !- return a NaN NLL " << std::endl;
442 minim.optimizeConst(
false);
447 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::EvaluateNLL - value = " << val;
449 muTest = (
static_cast<RooRealVar*
>(poiSet->
first()) )->getVal();
450 ooccoutP(
nullptr,Eval) <<
" for poi fixed at = " << muTest;
454 ooccoutP(
nullptr,Eval) <<
"\tfit time : " << tw.
RealTime() <<
" s (real) " << tw.
CpuTime() <<
" s (cpu)" << std::endl;
456 ooccoutP(
nullptr,Eval) << std::endl;
481 int verbose = fgPrintLevel();
486 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::GetHypoTest - Error initializing Asymptotic calculator - return nullptr result " << std::endl;
492 oocoutE(
nullptr,InputArguments) <<
"AsymptoticCalculator::GetHypoTest - Asimov data set has not been generated - return nullptr result " << std::endl;
505 assert(nullSnapshot && !nullSnapshot->
empty());
511 if (poiTest.
size() > 1) {
512 oocoutW(
nullptr,InputArguments) <<
"AsymptoticCalculator::GetHypoTest: snapshot has more than one POI - assume as POI first parameter " << std::endl;
521 assert(muHat &&
"no best fit parameter defined");
523 assert(muTest &&
"poi snapshot is not existing");
528 oocoutI(
nullptr,Eval) <<
"\nAsymptoticCalculator::GetHypoTest: - perform an hypothesis test for POI ( " << muTest->
GetName() <<
" ) = " << muTest->
getVal() << std::endl;
529 oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::GetHypoTest - Find best conditional NLL on OBSERVED data set ..... " << std::endl;
535 double qmu = 2.*(condNLL -
fNLLObs);
540 oocoutP(
nullptr,Eval) <<
"\t OBSERVED DATA : qmu = " << qmu <<
" condNLL = " << condNLL <<
" uncond " <<
fNLLObs << std::endl;
548 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: Found a negative value of the qmu - retry to do the unconditional fit "
552 <<
"AsymptoticCalculator: unconditional fit failed before - retry to do it now " << std::endl;
558 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: Found a better unconditional minimum "
559 <<
" old NLL = " <<
fNLLObs <<
" old muHat " << muHat->
getVal() << std::endl;
571 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: New minimum found for "
572 <<
" NLL = " <<
fNLLObs <<
" muHat " << muHat->
getVal() << std::endl;
578 oocoutP(
nullptr,Eval) <<
"After unconditional refit, new qmu value is " << qmu << std::endl;
584 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: qmu is still < 0 for mu = "
585 << muTest->
getVal() <<
" return a dummy result "
590 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: failure in fitting for qmu or qmuA "
591 << muTest->
getVal() <<
" return a dummy result "
615 if (verbose > 0)
oocoutP(
nullptr,Eval) <<
"AsymptoticCalculator::GetHypoTest -- Find best conditional NLL on ASIMOV data set .... " << std::endl;
623 oocoutP(
nullptr,Eval) <<
"\t ASIMOV data qmu_A = " << qmu_A <<
" condNLL = " << condNLL_A <<
" uncond " <<
fNLLAsimov << std::endl;
629 <<
"AsymptoticCalculator: Found a negative value of the qmu Asimov- retry to do the unconditional fit "
633 <<
"AsymptoticCalculator: Fit failed for unconditional the qmu Asimov- retry unconditional fit "
640 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: Found a better unconditional minimum for Asimov data set"
646 oocoutW(
nullptr,Minimization) <<
"AsymptoticCalculator: New minimum found for "
651 oocoutP(
nullptr,Eval) <<
"After unconditional Asimov refit, new qmu_A value is " << qmu_A << std::endl;
657 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: qmu_A is still < 0 for mu = "
658 << muTest->
getVal() <<
" return a dummy result "
663 oocoutE(
nullptr,Minimization) <<
"AsymptoticCalculator: failure in fitting for qmu or qmuA "
664 << muTest->
getVal() <<
" return a dummy result "
671 globObs.
assign(globObsSnapshot);
683 bool useQTilde =
false;
691 assert(muAlt !=
nullptr );
694 oocoutI(
nullptr,InputArguments) <<
"Minimum of POI is " << muTest->
getMin() <<
" corresponds to alt snapshot - using qtilde asymptotic formulae " << std::endl;
697 oocoutI(
nullptr,InputArguments) <<
"Minimum of POI is " << muTest->
getMin() <<
" is different to alt snapshot " << muAlt->
getVal()
698 <<
" - using standard q asymptotic formulae " << std::endl;
708 oocoutI(
nullptr,Eval) <<
"Using one-sided qmu - setting qmu to zero muHat = " << muHat->
getVal()
709 <<
" muTest = " << muTest->
getVal() << std::endl;
715 oocoutI(
nullptr,Eval) <<
"Using one-sided discovery qmu - setting qmu to zero muHat = " << muHat->
getVal()
716 <<
" muTest = " << muTest->
getVal() << std::endl;
722 if (qmu < 0 && qmu > -tol) qmu = 0;
723 if (qmu_A < 0 && qmu_A > -tol) qmu_A = 0;
736 double sqrtqmu = (qmu > 0) ? std::sqrt(qmu) : 0;
737 double sqrtqmu_A = (qmu_A > 0) ? std::sqrt(qmu_A) : 0;
744 oocoutI(
nullptr,Eval) <<
"Using one-sided limit asymptotic formula (qmu)" << std::endl;
746 oocoutI(
nullptr, Eval) <<
"Using one-sided discovery asymptotic formula (q0)" << std::endl;
754 if (verbose > 2)
oocoutI(
nullptr,Eval) <<
"Using two-sided asymptotic formula (tmu)" << std::endl;
764 if ( qmu > qmu_A && (qmu_A > 0 || qmu > tol) ) {
765 if (verbose > 2)
oocoutI(
nullptr,Eval) <<
"Using qmu_tilde (qmu is greater than qmu_A)" << std::endl;
773 if ( qmu > qmu_A && (qmu_A > 0 || qmu > tol) ) {
774 if (verbose > 2)
oocoutI(
nullptr,Eval) <<
"Using tmu_tilde (qmu is greater than qmu_A)" << std::endl;
786 string resultname =
"HypoTestAsymptotic_result";
790 oocoutP(
nullptr, Eval) <<
"poi = " << muTest->
getVal() <<
" qmu = " << qmu <<
" qmu_A = " << qmu_A
791 <<
" sigma = " << muTest->
getVal() / sqrtqmu_A <<
" CLsplusb = " << pnull
792 <<
" CLb = " << palt <<
" CLs = " << res->
CLs() << std::endl;
818 if (!useCls)
return clsplusb;
820 return (clb == 0) ? -1 : clsplusb / clb;
837 oocoutE(
nullptr,Eval) <<
"Error finding expected p-values - return -1" << std::endl;
840 double sqrttmu_A = brf.
Root();
848 oocoutE(
nullptr,Eval) <<
"Error finding expected p-values - return -1" << std::endl;
861 bool debug = (fgPrintLevel() >= 2);
869 if (debug)
oocoutI(
nullptr,Generation) <<
"looping on observable " <<
v->GetName() << std::endl;
870 for (
int i = 0; i <
v->getBins(); ++i) {
872 if (index <
int(obs.
size()) -1) {
874 double prevBinVolume = binVolume;
875 binVolume *=
v->getBinWidth(i);
876 FillBins(pdf, obs, data, index, binVolume, ibin);
878 binVolume = prevBinVolume;
883 double totBinVolume = binVolume *
v->getBinWidth(i);
884 double fval = pdf.
getVal(&obstmp)*totBinVolume;
886 if (fval*expectedEvents <= 0)
888 if (fval*expectedEvents < 0) {
889 oocoutW(
nullptr,InputArguments)
890 <<
"AsymptoticCalculator::" << __func__
891 <<
"(): Bin " << i <<
" of " <<
v->GetName() <<
" has negative expected events! Please check your inputs." << std::endl;
894 oocoutW(
nullptr,InputArguments)
895 <<
"AsymptoticCalculator::" << __func__
896 <<
"(): Bin " << i <<
" of " <<
v->GetName() <<
" has zero expected events - skip it" << std::endl;
901 data.add(obs, fval*expectedEvents);
905 oocoutI(
nullptr,Generation) <<
"bin " << ibin <<
"\t";
906 for (std::size_t j=0; j < obs.
size(); ++j) {
ooccoutI(
nullptr,Generation) <<
" " << (
static_cast<RooRealVar&
>( obs[j])).getVal(); }
907 ooccoutI(
nullptr,Generation) <<
" w = " << fval*expectedEvents;
908 ooccoutI(
nullptr,Generation) << std::endl;
915 oocoutI(
nullptr,Generation) <<
"ending loop on .. " <<
v->GetName() << std::endl;
922bool setObsToExpected(std::span<RooAbsArg *> servers,
const RooArgSet &obs, std::string
const &errPrefix)
924 RooRealVar *myobs =
nullptr;
925 RooAbsReal *myexp =
nullptr;
926 for (RooAbsArg *
a : servers) {
928 if (myobs !=
nullptr) {
929 oocoutF(
nullptr,Generation) << errPrefix <<
"Has two observables ?? " << std::endl;
932 myobs =
dynamic_cast<RooRealVar *
>(
a);
933 if (myobs ==
nullptr) {
934 oocoutF(
nullptr,Generation) << errPrefix <<
"Observable is not a RooRealVar??" << std::endl;
938 if (!
a->isConstant() ) {
939 if (myexp !=
nullptr) {
940 oocoutE(
nullptr,Generation) << errPrefix <<
"Has two non-const arguments " << std::endl;
943 myexp =
dynamic_cast<RooAbsReal *
>(
a);
944 if (myexp ==
nullptr) {
945 oocoutF(
nullptr,Generation) << errPrefix <<
"Expected is not a RooAbsReal??" << std::endl;
951 if (myobs ==
nullptr) {
952 oocoutF(
nullptr,Generation) << errPrefix <<
"No observable?" << std::endl;
955 if (myexp ==
nullptr) {
956 oocoutF(
nullptr,Generation) << errPrefix <<
"No observable?" << std::endl;
962 if (fgPrintLevel() > 2) {
963 oocoutI(
nullptr,Generation) <<
"SetObsToExpected : setting " << myobs->
GetName() <<
" to expected value " << myexp->
getVal() <<
" of " << myexp->
GetName() << std::endl;
977bool SetObsToExpected(RooAbsPdf &pdf,
const RooArgSet &obs)
979 std::string
const &errPrefix =
"AsymptoticCalculator::SetObsExpected( " + std::string{pdf.
ClassName()} +
" ) : ";
980 std::vector<RooAbsArg *> servers;
981 for (RooAbsArg *
a : pdf.
servers()) {
982 servers.emplace_back(
a);
984 return setObsToExpected(servers, obs, errPrefix);
987bool setObsToExpectedMultiVarGauss(RooMultiVarGaussian &mvgauss,
const RooArgSet &obs)
992 std::string
const &errPrefix =
"AsymptoticCalculator::SetObsExpected( " + std::string{mvgauss.
ClassName()} +
" ) : ";
993 std::vector<RooAbsArg *> servers{
nullptr,
nullptr};
995 for (std::size_t iDim = 0; iDim < mvgauss.
xVec().
size(); ++iDim) {
996 servers[0] = &mvgauss.
xVec()[iDim];
997 servers[1] = &mvgauss.
muVec()[iDim];
998 ret &= setObsToExpected(servers, obs, errPrefix +
" : dim " + std::to_string(iDim) +
" ");
1007bool setObsToExpectedProdPdf(RooProdPdf &prod,
const RooArgSet &obs)
1011 if (!
a->dependsOn(obs))
continue;
1012 RooPoisson *pois =
nullptr;
1013 RooGaussian *gauss =
nullptr;
1014 RooMultiVarGaussian *mvgauss =
nullptr;
1016 if ((pois =
dynamic_cast<RooPoisson *
>(
a)) !=
nullptr) {
1017 ret &= SetObsToExpected(*pois, obs);
1019 }
else if ((gauss =
dynamic_cast<RooGaussian *
>(
a)) !=
nullptr) {
1020 ret &= SetObsToExpected(*gauss, obs);
1021 }
else if ((mvgauss =
dynamic_cast<RooMultiVarGaussian *
>(
a)) !=
nullptr) {
1022 ret &= setObsToExpectedMultiVarGauss(*mvgauss, obs);
1023 }
else if (RooProdPdf *subprod =
dynamic_cast<RooProdPdf *
>(
a)) {
1024 ret &= setObsToExpectedProdPdf(*subprod, obs);
1026 oocoutE(
nullptr, InputArguments)
1027 <<
"Illegal term in counting model: "
1028 <<
"the PDF " <<
a->GetName() <<
" depends on the observables, but is not a Poisson, Gaussian or Product"
1042RooAbsData *GenerateCountingAsimovData(RooAbsPdf & pdf,
const RooArgSet & observables,
const RooRealVar & , RooCategory * channelCat) {
1043 RooArgSet obs(observables);
1044 RooProdPdf *prod =
dynamic_cast<RooProdPdf *
>(&pdf);
1045 RooPoisson *pois =
nullptr;
1046 RooGaussian *gauss =
nullptr;
1047 RooMultiVarGaussian *mvgauss =
nullptr;
1049 if (fgPrintLevel() > 1)
1050 oocoutI(
nullptr,Generation) <<
"generate counting Asimov data for pdf of type " << pdf.
ClassName() << std::endl;
1053 if (prod !=
nullptr) {
1054 r = setObsToExpectedProdPdf(*prod, observables);
1055 }
else if ((pois =
dynamic_cast<RooPoisson *
>(&pdf)) !=
nullptr) {
1056 r = SetObsToExpected(*pois, observables);
1059 }
else if ((gauss =
dynamic_cast<RooGaussian *
>(&pdf)) !=
nullptr) {
1060 r = SetObsToExpected(*gauss, observables);
1061 }
else if ((mvgauss =
dynamic_cast<RooMultiVarGaussian *
>(&pdf)) !=
nullptr) {
1062 r = setObsToExpectedMultiVarGauss(*mvgauss, observables);
1064 oocoutE(
nullptr,InputArguments) <<
"A counting model pdf must be either a RooProdPdf or a RooPoisson or a RooGaussian" << std::endl;
1066 if (!
r)
return nullptr;
1072 RooDataSet *
ret =
new RooDataSet(
"CountingAsimovData" + std::to_string(icat),
1073 "CountingAsimovData" + std::to_string(icat), obs);
1084RooAbsData * GenerateAsimovDataSinglePdf(
const RooAbsPdf & pdf,
const RooArgSet & allobs,
const RooRealVar & weightVar, RooCategory * channelCat) {
1086 int printLevel = fgPrintLevel();
1093 if (!pdf.
canBeExtended() )
return GenerateCountingAsimovData(
const_cast<RooAbsPdf&
>(pdf), *obs, weightVar, channelCat);
1095 RooArgSet obsAndWeight(*obs);
1096 obsAndWeight.add(weightVar);
1098 std::unique_ptr<RooDataSet> asimovData;
1101 asimovData = std::make_unique<RooDataSet>(
"AsimovData" + std::to_string(icat),
1102 "combAsimovData" + std::to_string(icat),
1106 asimovData = std::make_unique<RooDataSet>(
"AsimovData",
"AsimovData",RooArgSet(obsAndWeight),
RooFit::WeightVar(weightVar));
1112 RooArgList obsList(*obs);
1115 if (printLevel >= 2) {
1116 oocoutI(
nullptr,Generation) <<
"Generating Asimov data for pdf " << pdf.
GetName() << std::endl;
1117 oocoutI(
nullptr,Generation) <<
"list of observables " << std::endl;
1122 double binVolume = 1;
1124 FillBins(pdf, obsList, *asimovData, obsIndex, binVolume, nbins);
1125 if (printLevel >= 2)
1126 oocoutI(
nullptr,Generation) <<
"filled from " << pdf.
GetName() <<
" " << nbins <<
" nbins " <<
" volume is " << binVolume << std::endl;
1144 if (printLevel >= 1)
1146 asimovData->Print();
1149 oocoutE(
nullptr,Generation) <<
"sum entries is nan"<< std::endl;
1151 asimovData =
nullptr;
1154 return asimovData.release();
1167 int printLevel = fgPrintLevel();
1169 RooRealVar weightVar{
"binWeightAsimov",
"binWeightAsimov", 1, 0, 1.e30};
1171 if (printLevel > 1)
oocoutI(
nullptr,Generation) <<
" Generate Asimov data for observables"<< std::endl;
1177 for (
auto ele :
list) {
1180 strippedPdfSet.
add(*pdfi);
1183 RooProdPdf observableProdPdf(
"observableProdPdf",
"observableProdPdf", strippedPdfSet);
1186 if (strippedPdfSet.
getSize() == 1)
1187 observablePdf =
dynamic_cast<const RooAbsPdf *
>(strippedPdfSet.
at(0));
1189 observablePdf = &observableProdPdf;
1191 observablePdf = &pdf;
1196 return GenerateAsimovDataSinglePdf(*observablePdf, observables, weightVar,
nullptr);
1199 std::map<std::string, std::unique_ptr<RooDataSet>> asimovDataMap;
1203 int nrIndices = channelCat.
numTypes();
1204 if( nrIndices == 0 ) {
1205 oocoutW(
nullptr,Generation) <<
"Simultaneous pdf does not contain any categories." << std::endl;
1207 for (
int i=0;i<nrIndices;i++){
1212 assert(pdftmp !=
nullptr);
1219 std::unique_ptr<RooDataSet> dataSinglePdf{
static_cast<RooDataSet*
>(GenerateAsimovDataSinglePdf( *pdftmp, observables, weightVar, &channelCat))};
1220 if (!dataSinglePdf) {
1221 oocoutE(
nullptr,Generation) <<
"Error generating an Asimov data set for pdf " << pdftmp->
GetName() << std::endl;
1226 oocoutE(
nullptr,Generation) <<
"AsymptoticCalculator::GenerateAsimovData(): The PDF for " << channelCat.
getCurrentLabel()
1227 <<
" was already defined. It will be overridden. The faulty category definitions follow:" << std::endl;
1228 channelCat.
Print(
"V");
1234 dataSinglePdf->Print();
1235 ooccoutI(
nullptr,Generation) << std::endl;
1238 asimovDataMap[string(channelCat.
getCurrentLabel())] = std::move(dataSinglePdf);
1242 obsAndWeight.
add(weightVar);
1245 return new RooDataSet(
"asimovDataFullModel",
"asimovDataFullModel",
RooArgSet(obsAndWeight,channelCat),
1262 int verbose = fgPrintLevel();
1265 RooArgSet poi(*model.GetParametersOfInterest());
1272 tmpPar->setConstant();
1274 oocoutI(
nullptr,Generation) <<
"MakeAsimov: Setting poi " << tmpPar->GetName() <<
" to a constant value = " << tmpPar->getVal() << std::endl;
1275 paramsSetConstant.
add(*tmpPar);
1279 bool hasFloatParams =
false;
1281 if (model.GetNuisanceParameters()) {
1282 constrainParams.
add(*model.GetNuisanceParameters());
1284 if (!constrainParams.
empty()) hasFloatParams =
true;
1288 std::unique_ptr<RooArgSet> params(model.GetPdf()->getParameters(realData));
1290 if ( rrv !=
nullptr && rrv->isConstant() ==
false ) { hasFloatParams =
true;
break; }
1293 if (hasFloatParams) {
1299 oocoutP(
nullptr,Generation) <<
"MakeAsimov: doing a conditional fit for finding best nuisance values " << std::endl;
1300 minimPrintLevel = verbose;
1302 oocoutI(
nullptr,Generation) <<
"POI values:\n"; poi.
Print(
"v");
1304 oocoutI(
nullptr,Generation) <<
"Nuis param values:\n";
1305 constrainParams.
Print(
"v");
1313 std::vector<RooCmdArg> args{
1324 for (
auto& arg : args) {
1327 model.fitTo(realData, argList);
1330 oocoutP(
nullptr,Generation) <<
"fit time : " << tw2.
RealTime() <<
" s (real) " << tw2.
CpuTime() <<
" s (cpu)" << std::endl;
1334 if (model.GetNuisanceParameters() ) {
1335 oocoutI(
nullptr,Generation) <<
"Nuisance parameters after fit for asimov dataset: " << std::endl;
1336 model.GetNuisanceParameters()->Print(
"V");
1347 std::unique_ptr<RooArgSet> allParams{model.GetPdf()->getParameters(realData)};
1353 allParams->assign(*genPoiValues);
1372 int verbose = fgPrintLevel();
1379 if (!allParamValues.
empty()) {
1380 std::unique_ptr<RooArgSet> allVars{model.GetPdf()->getVariables()};
1381 allVars->assign(allParamValues);
1389 oocoutI(
nullptr,Generation) <<
"Generated Asimov data for observables "; (model.GetObservables() )->Print();
1392 oocoutI(
nullptr,Generation) <<
"--- Asimov data values \n";
1396 oocoutI(
nullptr,Generation) <<
"--- Asimov data numEntries = " << asimov->
numEntries() <<
" sumOfEntries = " << asimov->
sumEntries() << std::endl;
1399 oocoutI(
nullptr,Generation) <<
"\ttime for generating : " << tw.
RealTime() <<
" s (real) " << tw.
CpuTime() <<
" s (cpu)" << std::endl;
1416 if (model.GetGlobalObservables() && !model.GetGlobalObservables()->empty()) {
1419 oocoutI(
nullptr,Generation) <<
"Generating Asimov data for global observables " << std::endl;
1422 RooArgSet gobs(*model.GetGlobalObservables());
1431 if (model.GetNuisanceParameters()) nuis.
add(*model.GetNuisanceParameters());
1433 oocoutW(
nullptr,Generation) <<
"AsymptoticCalculator::MakeAsimovData: model does not have nuisance parameters but has global observables"
1434 <<
" set global observables to model values " << std::endl;
1435 asimovGlobObs.
assign(gobs);
1441 if (nuispdf ==
nullptr) {
1442 oocoutF(
nullptr, Generation) <<
"AsymptoticCalculator::MakeAsimovData: model has nuisance parameters and "
1443 "global obs but no nuisance pdf "
1453 pdfList.
add(*nuispdf);
1458 "AsimovUtils: a factor of the nuisance pdf is not a Pdf!");
1460 if (!cterm->dependsOn(nuis))
continue;
1462 if (
typeid(*cterm) ==
typeid(
RooUniform))
continue;
1464 std::unique_ptr<RooArgSet> cpars(cterm->getParameters(&gobs));
1465 std::unique_ptr<RooArgSet> cgobs(cterm->getObservables(&gobs));
1466 if (cgobs->size() > 1) {
1467 oocoutE(
nullptr,Generation) <<
"AsymptoticCalculator::MakeAsimovData: constraint term " << cterm->GetName()
1468 <<
" has multiple global observables -cannot generate - skip it" << std::endl;
1471 else if (cgobs->empty()) {
1473 <<
"AsymptoticCalculator::MakeAsimovData: constraint term " << cterm->GetName()
1474 <<
" has no global observables - skip it" << std::endl;
1482 if (cpars->size() != 1) {
1484 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1485 << cterm->GetName() <<
" has multiple floating params - cannot generate - skip it " << std::endl;
1489 bool foundServer =
false;
1493 if (verbose > 2)
oocoutI(
nullptr,Generation) <<
"Constraint " << cterm->
GetName() <<
" of type " << cClass->
GetName() << std::endl;
1499 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1500 << cterm->GetName() <<
" of type " << className
1501 <<
" is a non-supported type - result might be not correct " << std::endl;
1519 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1520 << cterm->GetName() <<
" has no direct dependence on global observable- cannot generate it " << std::endl;
1537 if (thetaGamma ==
nullptr) {
1539 <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1540 << cterm->GetName() <<
" is a Gamma distribution and no server named theta is found. Assume that the Gamma scale is 1 " << std::endl;
1542 else if (verbose>2) {
1543 oocoutI(
nullptr,Generation) <<
"Gamma constraint has a scale " << thetaGamma->
GetName() <<
" = " << thetaGamma->
getVal() << std::endl;
1548 if (verbose > 2)
oocoutI(
nullptr,Generation) <<
"Loop on constraint server term " << a2->
GetName() << std::endl;
1554 oocoutE(
nullptr,Generation) <<
"AsymptoticCalculator::MakeAsimovData:constraint term "
1555 << cterm->GetName() <<
" constraint term has more server depending on nuisance- cannot generate it " <<
1557 foundServer =
false;
1560 if (thetaGamma && thetaGamma->
getVal() > 0) {
1568 oocoutI(
nullptr,Generation) <<
"setting global observable " << rrv.
GetName() <<
" to value " << rrv.
getVal()
1569 <<
" which comes from " << rrv2->
GetName() << std::endl;
1575 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;
1576 oocoutE(
nullptr,Generation) <<
"Parameters: " << std::endl;
1578 oocoutE(
nullptr,Generation) <<
"Observables: " << std::endl;
1591 gobs.
assign(snapGlobalObsData);
1594 oocoutI(
nullptr,Generation) <<
"Generated Asimov data for global observables ";
1595 if (verbose == 1) gobs.
Print();
1599 oocoutI(
nullptr,Generation) <<
"\nGlobal observables for data: " << std::endl;
1601 oocoutI(
nullptr,Generation) <<
"\nGlobal observables for asimov: " << std::endl;
1602 asimovGlobObs.
Print(
"V");
ROOT::RRangeCast< T, true, Range_t > dynamic_range_cast(Range_t &&coll)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
TRObject operator()(const T1 &t1) const
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.
const RefCountList_t & servers() const
List of all servers of this object.
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.
Int_t getSize() const
Return the number of elements in the collection.
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
RooAbsArg * find(const char *name) const
Find object with given name in list.
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)
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.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
virtual void Add(TObject *arg)
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
const RooArgList & xVec() const
const RooArgList & muVec() const
void setNoRounding(bool flag=true)
Switch off/on rounding of x to the nearest integer.
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
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
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
bool fOneSidedDiscovery
for one sided PL test statistic (for discovery)
RooAbsData * fAsimovData
asimov data set
RooArgSet fBestFitPoi
snapshot of best fitted POI values
static RooAbsData * MakeAsimovData(RooAbsData &data, const ModelConfig &model, const RooArgSet &poiValues, RooArgSet &globObs, const RooArgSet *genPoiValues=nullptr)
Make Asimov data.
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
const ModelConfig * GetNullModel(void) const
const ModelConfig * GetAlternateModel(void) const
const RooAbsData * GetData(void) const
HypoTestCalculatorGeneric(const RooAbsData &data, const ModelConfig &altModel, const ModelConfig &nullModel, TestStatSampler *sampler=nullptr)
Constructor.
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
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
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 * 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.
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 code)
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)