|
33 | 33 | #include <RooFuncWrapper.h> |
34 | 34 | #include <RooLinkedList.h> |
35 | 35 | #include <RooMinimizer.h> |
| 36 | +#include <RooConstVar.h> |
36 | 37 | #include <RooRealVar.h> |
37 | 38 | #include <RooSimultaneous.h> |
38 | 39 | #include <RooFormulaVar.h> |
@@ -810,8 +811,26 @@ std::unique_ptr<RooAbsReal> createNLL(RooAbsPdf &pdf, RooAbsData &data, const Ro |
810 | 811 | takeGlobalObservablesFromData); |
811 | 812 | } |
812 | 813 |
|
| 814 | + const double correction = pdfClone->getCorrection(); |
813 | 815 | nllWrapper->addOwnedComponents(std::move(nll)); |
814 | 816 | nllWrapper->addOwnedComponents(std::move(pdfClone)); |
| 817 | + |
| 818 | + if (correction > 0) { |
| 819 | + oocoutI(&pdf, Fitting) << "[FitHelpers] Detected correction term from RooAbsPdf::getCorrection(). " |
| 820 | + << "Adding penalty to NLL." << std::endl; |
| 821 | + |
| 822 | + // Convert the multiplicative correction to an additive term in -log L |
| 823 | + auto penaltyTerm = std::make_unique<RooConstVar>((baseName + "_Penalty").c_str(), |
| 824 | + "Penalty term from getCorrection()", correction); |
| 825 | + |
| 826 | + auto correctedNLL = std::make_unique<RooAddition>( |
| 827 | + // add penalty and NLL |
| 828 | + (baseName + "_corrected").c_str(), "NLL + penalty", RooArgSet(*nllWrapper, *penaltyTerm)); |
| 829 | + |
| 830 | + // transfer ownership of terms |
| 831 | + correctedNLL->addOwnedComponents(std::move(nllWrapper), std::move(penaltyTerm)); |
| 832 | + nllWrapper = std::move(correctedNLL); |
| 833 | + } |
815 | 834 | return nllWrapper; |
816 | 835 | } |
817 | 836 |
|
@@ -888,6 +907,23 @@ std::unique_ptr<RooAbsReal> createNLL(RooAbsPdf &pdf, RooAbsData &data, const Ro |
888 | 907 | throw std::runtime_error("RooFit was not built with the legacy evaluation backend"); |
889 | 908 | #endif |
890 | 909 |
|
| 910 | + if (const double correction = pdf.getCorrection(); correction > 0) { |
| 911 | + oocoutI(&pdf, Fitting) << "[FitHelpers] Detected correction term from RooAbsPdf::getCorrection(). " |
| 912 | + << "Adding penalty to NLL." << std::endl; |
| 913 | + |
| 914 | + // Convert the multiplicative correction to an additive term in -log L |
| 915 | + auto penaltyTerm = std::make_unique<RooConstVar>((baseName + "_Penalty").c_str(), |
| 916 | + "Penalty term from getCorrection()", correction); |
| 917 | + |
| 918 | + auto correctedNLL = std::make_unique<RooAddition>( |
| 919 | + // add penalty and NLL |
| 920 | + (baseName + "_corrected").c_str(), "NLL + penalty", RooArgSet(*nll, *penaltyTerm)); |
| 921 | + |
| 922 | + // transfer ownership of terms |
| 923 | + correctedNLL->addOwnedComponents(std::move(nll), std::move(penaltyTerm)); |
| 924 | + nll = std::move(correctedNLL); |
| 925 | + } |
| 926 | + |
891 | 927 | return nll; |
892 | 928 | } |
893 | 929 |
|
|
0 commit comments