Skip to content

Commit

Permalink
[RF] Rename RooMomentMorph::getVal to RooMomentMorph::getValV
Browse files Browse the repository at this point in the history
The RooAbsReal::getVal function should not be overloaded. It is the
getValV function that is a virtual function which might be overloaded in
derived classes. Otherwise, virtual calls don't work.
  • Loading branch information
guitargeek committed Mar 21, 2024
1 parent 2706217 commit 4eb61b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
10 changes: 5 additions & 5 deletions roofit/roofit/inc/RooMomentMorph.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RooMomentMorph : public RooAbsPdf {
return true ;
}

virtual double getVal(const RooArgSet* set=nullptr) const ;
double getValV(const RooArgSet* set=nullptr) const override;
RooAbsPdf* sumPdf(const RooArgSet* nset) ;


Expand All @@ -71,7 +71,7 @@ class RooMomentMorph : public RooAbsPdf {
void calculateFractions(const RooMomentMorph& self, bool verbose=true) const;
} ;
mutable RooObjCacheManager _cacheMgr ; //! The cache manager
mutable RooArgSet* _curNormSet ; //! Current normalization set
mutable RooArgSet* _curNormSet = nullptr; //! Current normalization set

friend class CacheElem ; // Cache needs to be able to clear _norm pointer

Expand All @@ -87,13 +87,13 @@ class RooMomentMorph : public RooAbsPdf {
RooRealProxy m ;
RooSetProxy _varList ;
RooListProxy _pdfList ;
mutable TVectorD* _mref;
mutable TVectorD* _mref = nullptr;

mutable TMatrixD* _M; //
mutable TMatrixD* _M = nullptr;

Setting _setting;

bool _useHorizMorph;
bool _useHorizMorph = true;

ClassDefOverride(RooMomentMorph,3);
};
Expand Down
10 changes: 5 additions & 5 deletions roofit/roofit/inc/RooMomentMorphFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RooMomentMorphFunc : public RooAbsReal {
return true;
}

virtual double getVal(const RooArgSet *set = nullptr) const;
double getValV(const RooArgSet *set = nullptr) const override;
RooAbsReal *sumFunc(const RooArgSet *nset);
const RooAbsReal *sumFunc(const RooArgSet *nset) const;

Expand All @@ -78,7 +78,7 @@ class RooMomentMorphFunc : public RooAbsReal {
void calculateFractions(const RooMomentMorphFunc &self, bool verbose = true) const;
};
mutable RooObjCacheManager _cacheMgr; //! The cache manager
mutable RooArgSet *_curNormSet; //! Current normalization set
mutable RooArgSet *_curNormSet = nullptr; //! Current normalization set

friend class CacheElem; // Cache needs to be able to clear _norm pointer

Expand All @@ -94,13 +94,13 @@ class RooMomentMorphFunc : public RooAbsReal {
RooRealProxy m;
RooSetProxy _varList;
RooListProxy _pdfList;
mutable TVectorD *_mref;
mutable TVectorD *_mref = nullptr;

mutable TMatrixD *_M; //
mutable TMatrixD *_M = nullptr;

Setting _setting;

bool _useHorizMorph;
bool _useHorizMorph = true;

ClassDefOverride(RooMomentMorphFunc, 3);
};
Expand Down
10 changes: 5 additions & 5 deletions roofit/roofit/src/RooMomentMorph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ClassImp(RooMomentMorph);
/// coverity[UNINIT_CTOR]

RooMomentMorph::RooMomentMorph()
: _cacheMgr(this,10,true,true), _curNormSet(nullptr), _mref(nullptr), _M(nullptr), _useHorizMorph(true)
: _cacheMgr(this,10,true,true)
{
}

Expand Down Expand Up @@ -108,7 +108,6 @@ RooMomentMorph::RooMomentMorph(const char *name, const char *title, RooAbsReal &
RooMomentMorph::RooMomentMorph(const RooMomentMorph &other, const char *name)
: RooAbsPdf(other, name),
_cacheMgr(other._cacheMgr, this),
_curNormSet(nullptr),
m("m", this, other.m),
_varList("varList", this, other._varList),
_pdfList("pdfList", this, other._pdfList),
Expand Down Expand Up @@ -170,7 +169,7 @@ RooMomentMorph::CacheElem::CacheElem(std::unique_ptr<RooAbsPdf> && sumPdf,

////////////////////////////////////////////////////////////////////////////////

RooMomentMorph::CacheElem* RooMomentMorph::getCache(const RooArgSet* /*nset*/) const
RooMomentMorph::CacheElem* RooMomentMorph::getCache(const RooArgSet* nset) const
{
if (auto* cache = static_cast<CacheElem*>(_cacheMgr.getObj(nullptr,static_cast<RooArgSet*>(nullptr)))) {
return cache ;
Expand Down Expand Up @@ -287,6 +286,7 @@ RooMomentMorph::CacheElem* RooMomentMorph::getCache(const RooArgSet* /*nset*/) c
else {
theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),_pdfList,coefList);
}
theSumPdf->fixCoefNormalization(*nset);

// *** WVE this is important *** this declares that frac effectively depends on the morphing parameters
// This will prevent the likelihood optimizers from erroneously declaring terms constant
Expand Down Expand Up @@ -319,10 +319,10 @@ RooMomentMorph::CacheElem::~CacheElem() = default;
////////////////////////////////////////////////////////////////////////////////
/// Special version of getVal() overrides RooAbsReal::getVal() to save value of current normalization set

double RooMomentMorph::getVal(const RooArgSet* set) const
double RooMomentMorph::getValV(const RooArgSet* set) const
{
_curNormSet = set ? const_cast<RooArgSet*>(set) : const_cast<RooArgSet*>(static_cast<RooArgSet const*>(&_varList));
return RooAbsPdf::getVal(set) ;
return RooAbsPdf::getValV(set) ;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 6 additions & 9 deletions roofit/roofit/src/RooMomentMorphFunc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ClassImp(RooMomentMorphFunc)

//_____________________________________________________________________________
RooMomentMorphFunc::RooMomentMorphFunc()
: _cacheMgr(this, 10, true, true), _curNormSet(nullptr), _mref(nullptr), _M(nullptr), _useHorizMorph(true)
: _cacheMgr(this, 10, true, true)
{
}

Expand All @@ -49,8 +49,7 @@ RooMomentMorphFunc::RooMomentMorphFunc(const char *name, const char *title, RooA
_varList("varList", "List of variables", this),
_pdfList("pdfList", "List of pdfs", this),
_mref(new TVectorD(mrefpoints)),
_setting(setting),
_useHorizMorph(true)
_setting(setting)
{
// observables
_varList.addTyped<RooAbsReal>(varList);
Expand All @@ -71,8 +70,7 @@ RooMomentMorphFunc::RooMomentMorphFunc(const char *name, const char *title, RooA
_varList("varList", "List of variables", this),
_pdfList("pdfList", "List of pdfs", this),
_mref(new TVectorD(mrefList.size())),
_setting(setting),
_useHorizMorph(true)
_setting(setting)
{
// observables
_varList.addTyped<RooAbsReal>(varList);
Expand Down Expand Up @@ -105,7 +103,6 @@ RooMomentMorphFunc::RooMomentMorphFunc(const char *name, const char *title, RooA
RooMomentMorphFunc::RooMomentMorphFunc(const RooMomentMorphFunc &other, const char *name)
: RooAbsReal(other, name),
_cacheMgr(other._cacheMgr, this),
_curNormSet(nullptr),
m("m", this, other.m),
_varList("varList", this, other._varList),
_pdfList("pdfList", this, other._pdfList),
Expand Down Expand Up @@ -313,11 +310,11 @@ RooMomentMorphFunc::CacheElem::~CacheElem()
}

//_____________________________________________________________________________
double RooMomentMorphFunc::getVal(const RooArgSet *set) const
double RooMomentMorphFunc::getValV(const RooArgSet *set) const
{
// Special version of getVal() overrides RooAbsReal::getVal() to save value of current normalization set
// Special version of getValV() overrides RooAbsReal::getVal() to save value of current normalization set
_curNormSet = set ? const_cast<RooArgSet *>(set) : const_cast<RooArgSet *>(static_cast<RooArgSet const*>(&_varList));
return RooAbsReal::getVal(set);
return RooAbsReal::getValV(set);
}

//_____________________________________________________________________________
Expand Down

0 comments on commit 4eb61b1

Please sign in to comment.