Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions roofit/roofit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ endif()

ROOT_STANDARD_LIBRARY_PACKAGE(RooFit
HEADERS
RooMultiPdf.h
Roo2DKeysPdf.h
RooArgusBG.h
RooBCPEffDecay.h
Expand Down Expand Up @@ -82,7 +81,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFit
RooVoigtian.h
RooJohnson.h
SOURCES
src/RooMultiPdf.cxx
src/Roo2DKeysPdf.cxx
src/RooArgusBG.cxx
src/RooBCPEffDecay.cxx
Expand Down
4 changes: 2 additions & 2 deletions roofit/roofit/inc/LinkDef1.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class Roo2DKeysPdf+ ;
#pragma link C++ class RooMultiPdf + ;
#pragma link C++ class Roo2DKeysPdf + ;
#pragma link C++ class RooArgusBG+ ;
#pragma link C++ class RooBCPEffDecay+ ;
#pragma link C++ class RooBCPGenDecay+ ;
Expand Down Expand Up @@ -59,6 +58,7 @@
#pragma link C++ class RooSpline+ ;
#pragma link C++ class RooStepFunction+ ;
#pragma link C++ class RooMultiBinomial+ ;

/* #pragma link C++ class std::vector< TVector2 >; */
/* #pragma link C++ class std::vector< TVector2 >::iterator ; */
/* #pragma link C++ class RooPolyMorph2D+ ; */
Expand Down
2 changes: 1 addition & 1 deletion roofit/roofit/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ROOT_ADD_GTEST(testRooLandau testRooLandau.cxx LIBRARIES RooFit)
ROOT_ADD_GTEST(testRooParamHistFunc testRooParamHistFunc.cxx LIBRARIES Gpad RooFit)
ROOT_ADD_GTEST(testRooPoisson testRooPoisson.cxx LIBRARIES RooFit)
ROOT_ADD_GTEST(testRooStepFunc testRooStepFunc.cxx LIBRARIES RooFit)
ROOT_ADD_GTEST(testRooMultiPdf testRooMultiPdf.cxx LIBRARIES RooFit)

if(mathmore)
ROOT_EXECUTABLE(testRooFit testRooFit.cxx LIBRARIES RooFit MathMore)
ROOT_ADD_TEST(test-fit-testRooFit COMMAND testRooFit)
Expand Down
2 changes: 2 additions & 0 deletions roofit/roofitcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore
RooMsgService.h
RooMultiCategory.h
RooMultiVarGaussian.h
RooMultiPdf.h
RooNameReg.h
RooNormSetCache.h
RooNumCdf.h
Expand Down Expand Up @@ -366,6 +367,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore
src/RooMsgService.cxx
src/RooMultiCategory.cxx
src/RooMultiVarGaussian.cxx
src/RooMultiPdf.cxx
src/RooNLLVarNew.cxx
src/RooNameReg.cxx
src/RooNormSetCache.cxx
Expand Down
1 change: 1 addition & 0 deletions roofit/roofitcore/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
#pragma read sourceClass="RooMappedCategory::Entry" targetClass="RooMappedCategory::Entry" version="[1]" include="RooFitLegacy/RooCatTypeLegacy.h" \
source="RooCatType _cat" target="_catIdx" code="{ _catIdx = onfile._cat.getVal(); }"
#pragma link C++ class RooMultiCategory+ ;
#pragma link C++ class RooMultiPdf + ;
#pragma link off class RooNameReg+ ;
#pragma link C++ class RooNumConvolution+ ;
#pragma link C++ class RooNumConvPdf+ ;
Expand Down
3 changes: 0 additions & 3 deletions roofit/roofitcore/inc/RooAbsArg.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,6 @@ class RooAbsArg : public TNamed, public RooPrintable {

mutable bool _localNoInhibitDirty = false; //! Prevent 'AlwaysDirty' mode for this node

/* RooArgSet _leafNodeCache ; //! Cached leaf nodes */
/* RooArgSet _branchNodeCache //! Cached branch nodes */

mutable RooWorkspace *_myws = nullptr; //! In which workspace do I live, if any

std::size_t _dataToken = std::numeric_limits<std::size_t>::max(); //! Set by the RooFitDriver for this arg to retrieve its result in the run context
Expand Down
2 changes: 2 additions & 0 deletions roofit/roofitcore/inc/RooAbsCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ class RooAbsCollection : public TObject, public RooPrintable {

void useHashMapForFind(bool flag) const;

void removeConstantParameters();

// For use in the RooArgList/Set(std::vector<RooAbsArgPtrOrDouble> const&) constructor.
// Can be replaced with std::variant when C++17 is the minimum supported standard.
struct RooAbsArgPtrOrDouble {
Expand Down
24 changes: 10 additions & 14 deletions roofit/roofitcore/inc/RooAbsPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@
class RooArgSet ;
class RooAbsGenContext ;
class RooFitResult ;
class RooExtendPdf ;
class RooCategory ;
class TPaveText;
class TH1F;
class TH2F;
class TList ;
class RooMinimizer ;
class RooNumGenConfig ;
class RooRealIntegral ;


class RooAbsPdf : public RooAbsReal {
Expand Down Expand Up @@ -165,18 +157,22 @@ class RooAbsPdf : public RooAbsReal {
return RooFit::makeOwningPtr(createNLLImpl(data, *RooFit::Detail::createCmdList(&cmdArgs...)));
}

// Constraint management
virtual RooArgSet* getConstraints(const RooArgSet& /*observables*/, RooArgSet const& /*constrainedParams*/, RooArgSet& /*pdfParams*/) const
// Constraint management. Interface to retrieve constraint terms on this pdf. Default implementation returns null.
virtual std::unique_ptr<RooArgSet> getConstraints(const RooArgSet & /*observables*/,
RooArgSet const & /*constrainedParams*/,
RooArgSet & /*pdfParams*/) const
{
// Interface to retrieve constraint terms on this pdf. Default implementation returns null
return nullptr ;
return nullptr;
}
RooArgSet* getAllConstraints(const RooArgSet& observables, RooArgSet& constrainedParams,
bool stripDisconnected=true) const ;

std::unique_ptr<RooArgSet>
getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, bool stripDisconnected = true) const;

// Project p.d.f into lower dimensional p.d.f
virtual RooAbsPdf* createProjection(const RooArgSet& iset) ;

virtual double getCorrection() const;

// Create cumulative density function from p.d.f
RooFit::OwningPtr<RooAbsReal> createCdf(const RooArgSet& iset, const RooArgSet& nset=RooArgSet()) ;
RooFit::OwningPtr<RooAbsReal> createCdf(const RooArgSet& iset, const RooCmdArg& arg1, const RooCmdArg& arg2={},
Expand Down
2 changes: 2 additions & 0 deletions roofit/roofitcore/inc/RooFit/Detail/RooNormalizedPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class RooNormalizedPdf : public RooAbsPdf {

bool selfNormalized() const override { return true; }

inline double getCorrection() const override { return _pdf->getCorrection(); }

bool forceAnalyticalInt(const RooAbsArg & /*dep*/) const override { return true; }
/// Forward determination of analytical integration capabilities to input p.d.f
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet * /*normSet*/,
Expand Down
5 changes: 5 additions & 0 deletions roofit/roofitcore/inc/RooHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ void checkRangeOfParameters(const RooAbsReal *callingClass, std::initializer_lis
double max = std::numeric_limits<double>::max(), bool limitsInAllowedRange = false,
std::string const &extraMessage = "");

/// set all RooRealVars to constants. return true if at least one changed status
bool setAllConstant(const RooAbsCollection &coll, bool constant = true);

bool freezeAllDisassociatedRooMultiPdfParameters(const RooArgSet &multiPdfs, const RooArgSet &allRooMultiPdfParams,
bool freeze = true, bool freezeDisassParams_verb = false);

} // namespace RooHelpers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RooMultiPdf : public RooAbsPdf {
TObject *clone(const char *newname) const override { return new RooMultiPdf(*this, newname); }

inline bool checkIndexDirty() const { return _oldIndex != x; }
inline double getCorrection() const { return cFactor * static_cast<RooAbsReal *>(corr.at(x))->getVal(); }
inline double getCorrection() const override { return cFactor * static_cast<RooAbsReal *>(corr.at(x))->getVal(); }
inline RooAbsPdf *getCurrentPdf() const { return getPdf(getCurrentIndex()); }
int getNumPdfs() const { return c.size(); }

Expand Down
3 changes: 2 additions & 1 deletion roofit/roofitcore/inc/RooProdPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class RooProdPdf : public RooAbsPdf {
bool isDirectGenSafe(const RooAbsArg& arg) const override ;

// Constraint management
RooArgSet* getConstraints(const RooArgSet& observables, RooArgSet const& constrainedParams, RooArgSet &pdfParams) const override ;
std::unique_ptr<RooArgSet> getConstraints(const RooArgSet &observables, RooArgSet const &constrainedParams,
RooArgSet &pdfParams) const override;

std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override ;
std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
Expand Down
38 changes: 37 additions & 1 deletion roofit/roofitcore/src/FitHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <RooFuncWrapper.h>
#include <RooLinkedList.h>
#include <RooMinimizer.h>
#include <RooConstVar.h>
#include <RooRealVar.h>
#include <RooSimultaneous.h>
#include <RooFormulaVar.h>
Expand Down Expand Up @@ -763,7 +764,7 @@ std::unique_ptr<RooAbsReal> createNLL(RooAbsPdf &pdf, RooAbsData &data, const Ro
RooFit::Detail::CompileContext ctx{normSet};
ctx.setLikelihoodMode(true);
std::unique_ptr<RooAbsArg> head = pdf.compileForNormSet(normSet, ctx);
std::unique_ptr<RooAbsPdf> pdfClone = std::unique_ptr<RooAbsPdf>{static_cast<RooAbsPdf *>(head.release())};
std::unique_ptr<RooAbsPdf> pdfClone = std::unique_ptr<RooAbsPdf>{&dynamic_cast<RooAbsPdf &>(*head.release())};

// reset attributes
pdf.setAttribute("SplitRange", false);
Expand Down Expand Up @@ -810,8 +811,26 @@ std::unique_ptr<RooAbsReal> createNLL(RooAbsPdf &pdf, RooAbsData &data, const Ro
takeGlobalObservablesFromData);
}

const double correction = pdfClone->getCorrection();
nllWrapper->addOwnedComponents(std::move(nll));
nllWrapper->addOwnedComponents(std::move(pdfClone));

if (correction > 0) {
oocoutI(&pdf, Fitting) << "[FitHelpers] Detected correction term from RooAbsPdf::getCorrection(). "
<< "Adding penalty to NLL." << std::endl;

// Convert the multiplicative correction to an additive term in -log L
auto penaltyTerm = std::make_unique<RooConstVar>((baseName + "_Penalty").c_str(),
"Penalty term from getCorrection()", correction);

auto correctedNLL = std::make_unique<RooAddition>(
// add penalty and NLL
(baseName + "_corrected").c_str(), "NLL + penalty", RooArgSet(*nllWrapper, *penaltyTerm));

// transfer ownership of terms
correctedNLL->addOwnedComponents(std::move(nllWrapper), std::move(penaltyTerm));
nllWrapper = std::move(correctedNLL);
}
return nllWrapper;
}

Expand Down Expand Up @@ -888,6 +907,23 @@ std::unique_ptr<RooAbsReal> createNLL(RooAbsPdf &pdf, RooAbsData &data, const Ro
throw std::runtime_error("RooFit was not built with the legacy evaluation backend");
#endif

if (const double correction = pdf.getCorrection(); correction > 0) {
oocoutI(&pdf, Fitting) << "[FitHelpers] Detected correction term from RooAbsPdf::getCorrection(). "
<< "Adding penalty to NLL." << std::endl;

// Convert the multiplicative correction to an additive term in -log L
auto penaltyTerm = std::make_unique<RooConstVar>((baseName + "_Penalty").c_str(),
"Penalty term from getCorrection()", correction);

auto correctedNLL = std::make_unique<RooAddition>(
// add penalty and NLL
(baseName + "_corrected").c_str(), "NLL + penalty", RooArgSet(*nll, *penaltyTerm));

// transfer ownership of terms
correctedNLL->addOwnedComponents(std::move(nll), std::move(penaltyTerm));
nll = std::move(correctedNLL);
}

return nll;
}

Expand Down
Loading
Loading