Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[RF] Remove unnecessary data members from RooLagrangianMorphFunc
This commit removes the `_curNormSet` and `_ownParameters` member
variables from the RooLagrangianMorphFunc. The `_ownParameters` was
simply unused, and the `_curNormSet` was redundant because there is
already `RooAbsReal::_lastNSet` that also points to the current
normalization set.

Now, the `RooLagrangianMorphFunc::getValV()` can also be removed because
the sole purpose was to set `_curNormSet`, and also the private
`RooLagrangianMorphFunc::getCache()` interface can be changed to take no
normSet parameter (as it was unused anyway).

The `RooLagrangianMorphFunc::_cacheMgr` declaration is also moved to the
bottom of the file together with the other member variables.
  • Loading branch information
guitargeek committed Jul 26, 2022
commit c48e7c483e4c87fd1ccd44a7aec6c5b472b06a7d
12 changes: 4 additions & 8 deletions roofit/roofit/inc/RooLagrangianMorphFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class RooLagrangianMorphFunc : public RooAbsReal {
bool isBinnedDistribution(const RooArgSet &obs) const override;
double evaluate() const override;
TObject *clone(const char *newname) const override;
double getValV(const RooArgSet *set = 0) const override;

bool checkObservables(const RooArgSet *nset) const override;
bool forceAnalyticalInt(const RooAbsArg &arg) const override;
Expand Down Expand Up @@ -179,16 +178,13 @@ class RooLagrangianMorphFunc : public RooAbsReal {
class CacheElem;
void init();
void setup(bool ownParams = true);
bool _ownParameters = false;
void disableInterference(const std::vector<const char *> &nonInterfering);
void disableInterferences(const std::vector<std::vector<const char *>> &nonInterfering);

mutable RooObjCacheManager _cacheMgr; //! The cache manager

void addFolders(const RooArgList &folders);

bool hasCache() const;
RooLagrangianMorphFunc::CacheElem *getCache(const RooArgSet *nset) const;
RooLagrangianMorphFunc::CacheElem *getCache() const;
void updateSampleWeights();

RooRealVar *setupObservable(const char *obsname, TClass *mode, TObject *inputExample);
Expand Down Expand Up @@ -251,7 +247,9 @@ class RooLagrangianMorphFunc : public RooAbsReal {
static std::unique_ptr<RooRatio> makeRatio(const char *name, const char *title, RooArgList &nr, RooArgList &dr);

private:
double _scale = 1;

mutable RooObjCacheManager _cacheMgr; //! The cache manager
double _scale = 1.0;
std::map<std::string, int> _sampleMap;
RooListProxy _physics;
RooSetProxy _operators;
Expand All @@ -260,8 +258,6 @@ class RooLagrangianMorphFunc : public RooAbsReal {
RooListProxy _flags;
Config _config;
std::vector<std::vector<RooListProxy *>> _diagrams;
mutable const RooArgSet *_curNormSet = nullptr; //!

std::vector<RooListProxy *> _nonInterfering;

ClassDefOverride(RooLagrangianMorphFunc, 1)
Expand Down
61 changes: 24 additions & 37 deletions roofit/roofit/src/RooLagrangianMorphFunc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ inline void RooLagrangianMorphFunc::updateSampleWeights()
{
//#ifdef USE_MULTIPRECISION_LC
int sampleidx = 0;
auto cache = this->getCache(_curNormSet);
auto cache = this->getCache();
const size_t n(size(cache->_inverse));
for (auto sampleit : this->_config.paramCards) {
const std::string sample(sampleit.first);
Expand Down Expand Up @@ -1824,7 +1824,7 @@ RooLagrangianMorphFunc::RooLagrangianMorphFunc(const char *name, const char *tit
: RooAbsReal(name, title), _cacheMgr(this, 10, kTRUE, kTRUE),
_operators("operators", "set of operators", this, kTRUE, kFALSE),
_observables("observables", "morphing observables", this, kTRUE, kFALSE),
_binWidths("binWidths", "set of binWidth objects", this, kTRUE, kFALSE), _config(config), _curNormSet(0)
_binWidths("binWidths", "set of binWidth objects", this, kTRUE, kFALSE), _config(config)
{
this->init();
this->disableInterferences(_config.nonInterfering);
Expand All @@ -1841,7 +1841,7 @@ RooLagrangianMorphFunc::RooLagrangianMorphFunc(const char *name, const char *tit
: RooAbsReal(name, title), _cacheMgr(this, 10, kTRUE, kTRUE),
_operators("operators", "set of operators", this, kTRUE, kFALSE),
_observables("observables", "morphing observables", this, kTRUE, kFALSE),
_binWidths("binWidths", "set of binWidth objects", this, kTRUE, kFALSE), _curNormSet(0)
_binWidths("binWidths", "set of binWidth objects", this, kTRUE, kFALSE)
{
this->_config.fileName = filename;
this->_config.observableName = observableName;
Expand All @@ -1859,8 +1859,6 @@ RooLagrangianMorphFunc::RooLagrangianMorphFunc(const char *name, const char *tit

void RooLagrangianMorphFunc::setup(bool own)
{
_ownParameters = own;

if (_config.couplings.size() > 0) {
RooArgList operators;
std::vector<RooListProxy *> vertices;
Expand Down Expand Up @@ -1975,7 +1973,7 @@ RooLagrangianMorphFunc::RooLagrangianMorphFunc(const RooLagrangianMorphFunc &oth
_operators(other._operators.GetName(), this, other._operators),
_observables(other._observables.GetName(), this, other._observables),
_binWidths(other._binWidths.GetName(), this, other._binWidths), _flags(other._flags.GetName(), this, other._flags),
_config(other._config), _curNormSet(0)
_config(other._config)
{
for (size_t j = 0; j < other._diagrams.size(); ++j) {
std::vector<RooListProxy *> diagram;
Expand Down Expand Up @@ -2209,7 +2207,7 @@ std::vector<std::string> RooLagrangianMorphFunc::getSamples() const

RooAbsReal *RooLagrangianMorphFunc::getSampleWeight(const char *name)
{
auto cache = this->getCache(_curNormSet);
auto cache = this->getCache();
auto wname = std::string("w_") + name + "_" + this->GetName();
return dynamic_cast<RooAbsReal *>(cache->_weights.find(wname.c_str()));
}
Expand All @@ -2227,8 +2225,8 @@ void RooLagrangianMorphFunc::printWeights() const

void RooLagrangianMorphFunc::printSampleWeights() const
{
auto *cache = this->getCache(this->_curNormSet);
for (const auto &sample : this->_sampleMap) {
auto *cache = this->getCache();
for (const auto &sample : _sampleMap) {
auto weightName = std::string("w_") + sample.first + "_" + this->GetName();
auto weight = static_cast<RooAbsReal *>(cache->_weights.find(weightName.c_str()));
if (!weight)
Expand Down Expand Up @@ -2261,7 +2259,7 @@ void RooLagrangianMorphFunc::randomizeParameters(double z)

bool RooLagrangianMorphFunc::updateCoefficients()
{
auto cache = this->getCache(_curNormSet);
auto cache = this->getCache();

std::string filename = this->_config.fileName;
TDirectory *file = openFile(filename.c_str());
Expand Down Expand Up @@ -2329,7 +2327,7 @@ bool RooLagrangianMorphFunc::useCoefficients(const char *filename)
cache = RooLagrangianMorphFunc::CacheElem::createCache(this, readMatrixFromFileT<Matrix>(filename));
if (!cache)
coutE(Caching) << "unable to create cache!" << std::endl;
this->_cacheMgr.setObj(0, 0, cache, 0);
_cacheMgr.setObj(nullptr, nullptr, cache, nullptr);
return true;
}

Expand All @@ -2338,7 +2336,7 @@ bool RooLagrangianMorphFunc::useCoefficients(const char *filename)

bool RooLagrangianMorphFunc::writeCoefficients(const char *filename)
{
auto cache = this->getCache(_curNormSet);
auto cache = this->getCache();
if (!cache)
return false;
writeMatrixToFileT(cache->_inverse, filename);
Expand All @@ -2348,15 +2346,15 @@ bool RooLagrangianMorphFunc::writeCoefficients(const char *filename)
////////////////////////////////////////////////////////////////////////////////
/// retrieve the cache object

typename RooLagrangianMorphFunc::CacheElem *RooLagrangianMorphFunc::getCache(const RooArgSet * /*nset*/) const
typename RooLagrangianMorphFunc::CacheElem *RooLagrangianMorphFunc::getCache() const
{
auto cache = static_cast<RooLagrangianMorphFunc::CacheElem *>(_cacheMgr.getObj(0, (RooArgSet *)0));
if (!cache) {
cxcoutP(Caching) << "creating cache from getCache function for " << this << std::endl;
cxcoutP(Caching) << "current storage has size " << this->_sampleMap.size() << std::endl;
cache = RooLagrangianMorphFunc::CacheElem::createCache(this);
if (cache)
this->_cacheMgr.setObj(0, 0, cache, 0);
_cacheMgr.setObj(nullptr, nullptr, cache, nullptr);
else
coutE(Caching) << "unable to create cache!" << std::endl;
}
Expand All @@ -2368,7 +2366,7 @@ typename RooLagrangianMorphFunc::CacheElem *RooLagrangianMorphFunc::getCache(con

bool RooLagrangianMorphFunc::hasCache() const
{
return (bool)(_cacheMgr.getObj(0, (RooArgSet *)0));
return (bool)(_cacheMgr.getObj(nullptr, static_cast<RooArgSet*>(nullptr)));
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2487,7 +2485,7 @@ double RooLagrangianMorphFunc::getParameterValue(const char *name) const
if (param) {
return param->getVal();
}
return 0;
return 0.0;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2690,7 +2688,7 @@ int RooLagrangianMorphFunc::nParameters() const
int RooLagrangianMorphFunc::nPolynomials() const
{
// return the number of samples in this morphing function
auto cache = getCache(_curNormSet);
auto cache = getCache();
return cache->_formulas.size();
}

Expand Down Expand Up @@ -2735,7 +2733,7 @@ const RooArgSet *RooLagrangianMorphFunc::getParameterSet() const

const RooArgList *RooLagrangianMorphFunc::getCouplingSet() const
{
auto cache = getCache(_curNormSet);
auto cache = getCache();
return &(cache->_couplings);
}

Expand Down Expand Up @@ -2777,7 +2775,7 @@ void RooLagrangianMorphFunc::setParameters(const ParamSet &params)

std::unique_ptr<RooWrapperPdf> RooLagrangianMorphFunc::createPdf() const
{
auto cache = getCache(_curNormSet);
auto cache = getCache();
auto func = std::make_unique<RooRealSumFunc>(*(cache->_sumFunc));

// create a wrapper on the roorealsumfunc
Expand All @@ -2789,7 +2787,7 @@ std::unique_ptr<RooWrapperPdf> RooLagrangianMorphFunc::createPdf() const

RooRealSumFunc *RooLagrangianMorphFunc::getFunc() const
{
auto cache = getCache(_curNormSet);
auto cache = getCache();
return cache->_sumFunc.get();
}

Expand Down Expand Up @@ -2835,7 +2833,7 @@ Double_t RooLagrangianMorphFunc::expectedEvents(const RooArgSet &nset) const
double RooLagrangianMorphFunc::expectedUncertainty() const
{
RooRealVar *observable = this->getObservable();
auto cache = this->getCache(_curNormSet);
auto cache = this->getCache();
double unc2 = 0;
for (const auto &sample : this->_sampleMap) {
RooAbsArg *phys = this->_physics.at(sample.second);
Expand Down Expand Up @@ -2923,23 +2921,12 @@ std::list<Double_t> *RooLagrangianMorphFunc::plotSamplingHint(RooAbsRealLValue &
////////////////////////////////////////////////////////////////////////////////
/// call getVal on the internal function

Double_t RooLagrangianMorphFunc::getValV(const RooArgSet *set) const
{
// cout << "XX RooLagrangianMorphFunc::getValV(" << this << ") set = " << set
// << std::endl ;
this->_curNormSet = set;
return RooAbsReal::getValV(set);
}

////////////////////////////////////////////////////////////////////////////////
/// call getVal on the internal function

Double_t RooLagrangianMorphFunc::evaluate() const
double RooLagrangianMorphFunc::evaluate() const
{
// call getVal on the internal function
RooRealSumFunc *pdf = this->getFunc();
if (pdf)
return this->_scale * pdf->getVal(_curNormSet);
return _scale * pdf->getVal(_lastNSet);
else
std::cerr << "unable to acquire in-built function!" << std::endl;
return 0.;
Expand Down Expand Up @@ -3015,7 +3002,7 @@ void RooLagrangianMorphFunc::setCacheAndTrackHints(RooArgSet &arg)

TMatrixD RooLagrangianMorphFunc::getMatrix() const
{
auto cache = getCache(_curNormSet);
auto cache = getCache();
if (!cache)
coutE(Caching) << "unable to retrieve cache!" << std::endl;
return makeRootMatrix(cache->_matrix);
Expand All @@ -3026,7 +3013,7 @@ TMatrixD RooLagrangianMorphFunc::getMatrix() const

TMatrixD RooLagrangianMorphFunc::getInvertedMatrix() const
{
auto cache = getCache(_curNormSet);
auto cache = getCache();
if (!cache)
coutE(Caching) << "unable to retrieve cache!" << std::endl;
return makeRootMatrix(cache->_inverse);
Expand All @@ -3039,7 +3026,7 @@ TMatrixD RooLagrangianMorphFunc::getInvertedMatrix() const

double RooLagrangianMorphFunc::getCondition() const
{
auto cache = getCache(_curNormSet);
auto cache = getCache();
if (!cache)
coutE(Caching) << "unable to retrieve cache!" << std::endl;
return cache->_condition;
Expand Down