-
Notifications
You must be signed in to change notification settings - Fork 429
Do analytical Barlow Beeston before likelihood evaluation #1137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -568,13 +568,16 @@ | |
|
|
||
| multiPdfs_.clear(); | ||
| for (auto &itp : pdfs_) { | ||
| bool isMultiPdf = itp->pdf()->IsA()->InheritsFrom(RooMultiPdf::Class()); | ||
| if (isMultiPdf) { | ||
| const RooMultiPdf *mpdf = dynamic_cast<const RooMultiPdf*>(itp->pdf()); | ||
| multiPdfs_.push_back(std::make_pair(mpdf, itp.get())); | ||
| } | ||
| if (auto* mpdf = dynamic_cast<const RooMultiPdf*>(itp->pdf())) { | ||
| multiPdfs_.emplace_back(mpdf, itp.get()); | ||
| } | ||
| if (auto* hist = dynamic_cast<const CMSHistSum*>(itp->pdf())) { | ||
| histSums_.emplace_back(hist); | ||
| } | ||
| if (auto* hist = dynamic_cast<const CMSHistErrorPropagator*>(itp->pdf())) { | ||
| histErrorPropagators_.emplace_back(hist); | ||
| } | ||
| } | ||
|
Comment on lines
+571
to
580
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear vectors before populating to prevent stale/duplicate pointers. When Apply this diff: for (int i = 0, n = integrals_.size(); i < n; ++i) delete integrals_[i];
integrals_.clear(); pdfs_.clear(); coeffs_.clear(); prods_.clear();
+histSums_.clear(); histErrorPropagators_.clear();
🤖 Prompt for AI Agents |
||
|
|
||
| } | ||
|
|
||
| void | ||
|
|
@@ -592,6 +595,9 @@ | |
| #ifdef DEBUG_CACHE | ||
| PerfCounter::add("CachingAddNLL::evaluate called"); | ||
| #endif | ||
| // The very first thing we do before any evaluation: run the analytical | ||
| // minimization of Barlow-Beeston nuisance parameters. | ||
| const_cast<CachingAddNLL&>(*this).runAnalyticBarlowBeeston(); | ||
|
|
||
| std::fill( partialSum_.begin(), partialSum_.end(), 0.0 ); | ||
|
|
||
|
|
@@ -789,27 +795,30 @@ | |
| } | ||
|
|
||
| void cacheutils::CachingAddNLL::propagateData() { | ||
| for (auto const& funci : pdfs_) { | ||
| if ( auto pdf = dynamic_cast<CMSHistErrorPropagator const*>(funci->pdf()); pdf != nullptr ) { | ||
| pdf->setData(*data_); | ||
| } | ||
| else if ( auto pdf = dynamic_cast<CMSHistSum const*>(funci->pdf()); pdf != nullptr ) { | ||
| pdf->setData(*data_); | ||
| } | ||
| } | ||
| for (auto* hist : histErrorPropagators_) { | ||
| hist->setData(*data_); | ||
| } | ||
| for (auto* hist : histSums_) { | ||
| hist->setData(*data_); | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| void cacheutils::CachingAddNLL::setAnalyticBarlowBeeston(bool flag) { | ||
| for (auto const& funci : pdfs_) { | ||
| if ( auto pdf = dynamic_cast<CMSHistErrorPropagator const*>(funci->pdf()); pdf != nullptr ) { | ||
| pdf->setAnalyticBarlowBeeston(flag); | ||
| } | ||
| if ( auto pdf = dynamic_cast<CMSHistSum const*>(funci->pdf()); pdf != nullptr ) { | ||
| pdf->setAnalyticBarlowBeeston(flag); | ||
| } | ||
| for (auto* hist : histErrorPropagators_) { | ||
| hist->setAnalyticBarlowBeeston(flag); | ||
| } | ||
| for (auto* hist : histSums_) { | ||
| hist->setAnalyticBarlowBeeston(flag); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| void cacheutils::CachingAddNLL::runAnalyticBarlowBeeston() { | ||
| for (auto* hist : histErrorPropagators_) { | ||
| hist->runBarlowBeeston(); | ||
| } | ||
| for (auto* hist : histSums_) { | ||
| hist->runBarlowBeeston(); | ||
| } | ||
| } | ||
|
|
||
| cacheutils::CachingSimNLL::CachingSimNLL(RooSimultaneous *pdf, RooAbsData *data, const RooArgSet *nuis) : | ||
|
|
@@ -1010,6 +1019,17 @@ | |
| #ifdef DEBUG_CACHE | ||
| PerfCounter::add("CachingSimNLL::evaluate called"); | ||
| #endif | ||
|
|
||
| // The very first thing we do before any evaluation: run the analytical | ||
| // minimization of Barlow-Beeston nuisance parameters. | ||
| for (size_t i = 0; i < pdfs_.size(); ++i) { | ||
| if (!pdfs_[i]) | ||
| continue; | ||
| if (!channelMasks_.empty() && channelMasks_[i]->getVal() != 0.) | ||
| continue; | ||
| pdfs_[i]->runAnalyticBarlowBeeston(); | ||
| } | ||
|
|
||
| static bool gentleNegativePenalty_ = runtimedef::get("GENTLE_LEE"); | ||
| DefaultAccumulator<double> ret = 0; | ||
| for (std::size_t idx = 0; idx < pdfs_.size(); ++idx) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Non‑owning raw pointers: verify population and clearing.
Ensure these are:
Run:
🏁 Script executed:
Length of output: 2296
🏁 Script executed:
Length of output: 241
🏁 Script executed:
Length of output: 1293
🏁 Script executed:
Length of output: 1871
Confirm: Non-owning raw pointers must be cleared on reset.
The vectors
histSums_andhistErrorPropagators_are populated during PDF setup (src/CachingNLL.cc:588, 591) but are never cleared. This is inconsistent with other mutable cache vectors (integrals_,pdfs_,coeffs_,multiPdfs_) which are explicitly cleared insetup_()(line 525) and the destructor (line 413). Without clearing, these vectors retain stale pointers when PDFs or data are reset, creating a use-after-free risk in methods likepropagateData(),setAnalyticBarlowBeeston(), andrunAnalyticBarlowBeeston().histSums_.clear()andhistErrorPropagators_.clear()insetup_()after line 525 and in the destructor after line 413.🤖 Prompt for AI Agents