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
8 changes: 7 additions & 1 deletion roofit/roofitcore/inc/RooAICRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class RooAICRegistry {

public:
RooAICRegistry(UInt_t size = 10) ;
RooAICRegistry(const RooAICRegistry& other) ;
RooAICRegistry(const RooAICRegistry &other);
RooAICRegistry &operator=(const RooAICRegistry &other);
RooAICRegistry(RooAICRegistry &&other) = default;
RooAICRegistry &operator=(RooAICRegistry &&other) = default;
virtual ~RooAICRegistry() ;

Int_t store(const std::vector<Int_t>& codeList, RooArgSet* set1 = nullptr, RooArgSet* set2 = nullptr,
Expand All @@ -39,6 +42,9 @@ class RooAICRegistry {
pRooArgSet& set2, pRooArgSet& set3, pRooArgSet& set4) const ;
size_t size() const;

private:
void copyImpl(const RooAICRegistry &other);

protected:

std::vector<std::vector<Int_t> > _clArr; ///<! Array of array of code lists
Expand Down
2 changes: 0 additions & 2 deletions roofit/roofitcore/inc/RooAddPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ class RooAddPdf : public RooAbsPdf {

void finalizeConstruction();
void materializeRefCoefNormFromAttribute() const;
inline void setRecursiveFraction(bool recursiveFraction) { _recursive = recursiveFraction; }
inline void setAllExtendable(bool allExtendable) { _allExtendable = allExtendable; }

ClassDefOverride(RooAddPdf,5) // PDF representing a sum of PDFs
};
Expand Down
69 changes: 52 additions & 17 deletions roofit/roofitcore/src/RooAICRegistry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,37 @@ RooAICRegistry::RooAICRegistry(UInt_t size)
////////////////////////////////////////////////////////////////////////////////
/// Copy constructor

RooAICRegistry::RooAICRegistry(const RooAICRegistry& other)
: _clArr(other._clArr), _asArr1(other._clArr.size(), nullptr), _asArr2(other._clArr.size(), nullptr),
_asArr3(other._clArr.size(), nullptr), _asArr4(other._clArr.size(), nullptr)
RooAICRegistry::RooAICRegistry(const RooAICRegistry &other)
{
// Copy code-list array if other PDF has one
UInt_t size = other._clArr.size();
if (size) {
_asArr1.resize(size, nullptr);
_asArr2.resize(size, nullptr);
_asArr3.resize(size, nullptr);
_asArr4.resize(size, nullptr);
for(UInt_t i = 0; i < size; ++i) {
_asArr1[i] = makeSnapshot(other._asArr1[i]);
_asArr2[i] = makeSnapshot(other._asArr2[i]);
_asArr3[i] = makeSnapshot(other._asArr3[i]);
_asArr4[i] = makeSnapshot(other._asArr4[i]);
}
}
copyImpl(other);
}

////////////////////////////////////////////////////////////////////////////////
/// Copy assignment

RooAICRegistry &RooAICRegistry::operator=(const RooAICRegistry &other)
{
// Delete code list array, if allocated
for (unsigned int i = 0; i < _clArr.size(); ++i) {
if (_asArr1[i]) {
delete _asArr1[i];
_asArr1[i] = nullptr;
}
if (_asArr2[i]) {
delete _asArr2[i];
_asArr2[i] = nullptr;
}
if (_asArr3[i]) {
delete _asArr3[i];
_asArr3[i] = nullptr;
}
if (_asArr4[i]) {
delete _asArr4[i];
_asArr4[i] = nullptr;
}
}
copyImpl(other);
return *this;
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -93,6 +106,28 @@ RooAICRegistry::~RooAICRegistry()
}
}


void RooAICRegistry::copyImpl(const RooAICRegistry &other)
{
_clArr = other._clArr;

// Copy code-list array if other PDF has one
UInt_t size = other._clArr.size();
if (size) {
_asArr1.resize(size, nullptr);
_asArr2.resize(size, nullptr);
_asArr3.resize(size, nullptr);
_asArr4.resize(size, nullptr);
for (UInt_t i = 0; i < size; ++i) {
_asArr1[i] = makeSnapshot(other._asArr1[i]);
_asArr2[i] = makeSnapshot(other._asArr2[i]);
_asArr3[i] = makeSnapshot(other._asArr3[i]);
_asArr4[i] = makeSnapshot(other._asArr4[i]);
}
}
}


////////////////////////////////////////////////////////////////////////////////
/// Get size of _clArr vector

Expand Down
36 changes: 29 additions & 7 deletions roofit/roofitcore/src/RooAddPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ RooAddPdf::RooAddPdf(const char *name, const char *title, const RooArgList &inPd
bool recursiveFractions)
: RooAddPdf(name, title)
{
setRecursiveFraction(recursiveFractions);
_recursive = recursiveFractions;

if (inPdfList.size()>inCoefList.size()+1 || inPdfList.size()<inCoefList.size()) {
std::stringstream errorMsg;
Expand Down Expand Up @@ -257,7 +257,7 @@ RooAddPdf::RooAddPdf(const char *name, const char *title, const RooArgList &inPd
RooAddPdf::RooAddPdf(const char *name, const char *title, const RooArgList &inPdfList)
: RooAddPdf(name, title)
{
setAllExtendable(true);
_allExtendable = true;

// Constructor with N PDFs
for (const auto pdfArg : inPdfList) {
Expand Down Expand Up @@ -580,9 +580,8 @@ void RooAddPdf::doEval(RooFit::EvalContext & ctx) const
std::vector<std::span<const double>> pdfs;
std::vector<double> coefs;
AddCacheElem* cache = getProjCache(nullptr);
// We don't sync the coefficient values from the _coefList to the _coefCache
// because we have already done it using the ctx.
updateCoefficients(*cache, nullptr, /*syncCoefValues=*/false);
RooAddHelpers::updateCoefficients(*this, _pdfList.size(), _coefCache, _haveLastCoef || _allExtendable, *cache,
_coefErrCount);

for (unsigned int pdfNo = 0; pdfNo < _pdfList.size(); ++pdfNo)
{
Expand Down Expand Up @@ -705,7 +704,7 @@ double RooAddPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, con
}

// Retrieve analytical integration subCodes and set of observabels integrated over
RooArgSet* intSet ;
RooArgSet* intSet = nullptr;
const std::vector<Int_t>& subCode = _codeReg.retrieve(code-1,intSet) ;
if (subCode.empty()) {
std::stringstream errorMsg;
Expand Down Expand Up @@ -973,7 +972,30 @@ RooAddPdf::compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileCo
// Make sure _refCoefNorm is defined
materializeRefCoefNormFromAttribute();

auto newArg = std::unique_ptr<RooAbsReal>{static_cast<RooAbsReal *>(Clone())};
// Instead of cloning this RooAddPdf directly, we have to massage it a bit.
// In the case of extended pdfs, the coefficients should be set to functions
// representing the expected number of events, so we don't have to fall back
// to legacy code paths that don't support evaluation with the
// RooFit::EvalContext, like RooAbsPdf::expectedEvents().
RooArgList coefListNew;
if (_allExtendable) {
for (auto *pdf : static_range_cast<RooAbsPdf *>(_pdfList)) {
coefListNew.addOwned(pdf->createExpectedEventsFunc(!_refCoefNorm.empty() ? &_refCoefNorm : &normSet));
}
} else {
coefListNew.add(coefList());
}
auto newArg = std::make_unique<RooAddPdf>(GetName(), GetTitle(), pdfList(), coefListNew, _recursive);
// Copy some other info that the RooAddPdf copy constructor would otherwise take care of.
newArg->setNormRange(normRange());
newArg->_codeReg = _codeReg;
if (!_refCoefNorm.empty()) {
newArg->fixCoefNormalization(_refCoefNorm);
}
if (_refCoefRangeName) {
newArg->fixCoefRange(getCoefRange());
}

ctx.markAsCompiled(*newArg);

// If we set the normalization ranges of the component pdfs to the
Expand Down
13 changes: 8 additions & 5 deletions roofit/roofitcore/src/RooExtendPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ the nominal integration range \f$ \mathrm{normRegion}[x] \f$.

#include "Riostream.h"

#include "RooExtendPdf.h"
#include "RooArgList.h"
#include "RooRealVar.h"
#include "RooConstVar.h"
#include "RooExtendPdf.h"
#include "RooFormulaVar.h"
#include "RooMsgService.h"
#include "RooNameReg.h"
#include "RooConstVar.h"
#include "RooProduct.h"
#include "RooRatio.h"
#include "RooMsgService.h"

#include "RooRealVar.h"

#include "RooFitImplHelpers.h"

using std::endl;

Expand Down Expand Up @@ -162,6 +162,9 @@ std::unique_ptr<RooAbsReal> RooExtendPdf::createExpectedEventsFunc(const RooArgS
}

auto name = std::string(GetName()) + "_expectedEvents";
if (nset) {
name += "[" + RooHelpers::getColonSeparatedNameString(*nset, ',') + "]";
}
auto out = std::make_unique<RooProduct>(name.c_str(), name.c_str(), prodList);
if(rangeFactor) {
out->addOwnedComponents(std::move(rangeFactor));
Expand Down
Loading