Skip to content

Commit 45d8e74

Browse files
guitargeekanigamova
authored andcommitted
Cache pointers CMSHistSum and ErrorPropagator in CachingNLL
This will make it more efficient to look them up to run the analytical Barlow Beeston.
1 parent a77c0a0 commit 45d8e74

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

interface/CachingNLL.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "SimpleConstraintGroup.h"
2121

2222
class RooMultiPdf;
23+
class CMSHistSum;
24+
class CMSHistErrorPropagator;
2325

2426
// Part zero: ArgSet checker
2527
namespace cacheutils {
@@ -145,6 +147,8 @@ class CachingAddNLL : public RooAbsReal {
145147
mutable std::vector<std::unique_ptr<RooAbsReal>> prods_;
146148
mutable std::vector<RooAbsReal*> integrals_;
147149
mutable std::vector<std::pair<const RooMultiPdf*,CachingPdfBase*> > multiPdfs_;
150+
mutable std::vector<CMSHistSum const*> histSums_;
151+
mutable std::vector<CMSHistErrorPropagator const*> histErrorPropagators_;
148152
mutable std::vector<Double_t> partialSum_;
149153
mutable std::vector<Double_t> workingArea_;
150154
mutable bool isRooRealSum_, fastExit_;

src/CachingNLL.cc

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,16 @@ cacheutils::CachingAddNLL::setup_()
568568

569569
multiPdfs_.clear();
570570
for (auto &itp : pdfs_) {
571-
bool isMultiPdf = itp->pdf()->IsA()->InheritsFrom(RooMultiPdf::Class());
572-
if (isMultiPdf) {
573-
const RooMultiPdf *mpdf = dynamic_cast<const RooMultiPdf*>(itp->pdf());
574-
multiPdfs_.push_back(std::make_pair(mpdf, itp.get()));
575-
}
571+
if (auto* mpdf = dynamic_cast<const RooMultiPdf*>(itp->pdf())) {
572+
multiPdfs_.emplace_back(mpdf, itp.get());
573+
}
574+
if (auto* hist = dynamic_cast<const CMSHistSum*>(itp->pdf())) {
575+
histSums_.emplace_back(hist);
576+
}
577+
if (auto* hist = dynamic_cast<const CMSHistErrorPropagator*>(itp->pdf())) {
578+
histErrorPropagators_.emplace_back(hist);
579+
}
576580
}
577-
578581
}
579582

580583
void
@@ -789,27 +792,21 @@ cacheutils::CachingAddNLL::setData(const RooAbsData &data)
789792
}
790793

791794
void cacheutils::CachingAddNLL::propagateData() {
792-
for (auto const& funci : pdfs_) {
793-
if ( auto pdf = dynamic_cast<CMSHistErrorPropagator const*>(funci->pdf()); pdf != nullptr ) {
794-
pdf->setData(*data_);
795-
}
796-
else if ( auto pdf = dynamic_cast<CMSHistSum const*>(funci->pdf()); pdf != nullptr ) {
797-
pdf->setData(*data_);
798-
}
799-
}
795+
for (auto* hist : histErrorPropagators_) {
796+
hist->setData(*data_);
797+
}
798+
for (auto* hist : histSums_) {
799+
hist->setData(*data_);
800+
}
800801
}
801802

802-
803803
void cacheutils::CachingAddNLL::setAnalyticBarlowBeeston(bool flag) {
804-
for (auto const& funci : pdfs_) {
805-
if ( auto pdf = dynamic_cast<CMSHistErrorPropagator const*>(funci->pdf()); pdf != nullptr ) {
806-
pdf->setAnalyticBarlowBeeston(flag);
807-
}
808-
if ( auto pdf = dynamic_cast<CMSHistSum const*>(funci->pdf()); pdf != nullptr ) {
809-
pdf->setAnalyticBarlowBeeston(flag);
810-
}
811-
812-
}
804+
for (auto* hist : histErrorPropagators_) {
805+
hist->setAnalyticBarlowBeeston(flag);
806+
}
807+
for (auto* hist : histSums_) {
808+
hist->setAnalyticBarlowBeeston(flag);
809+
}
813810
}
814811

815812
cacheutils::CachingSimNLL::CachingSimNLL(RooSimultaneous *pdf, RooAbsData *data, const RooArgSet *nuis) :

0 commit comments

Comments
 (0)