-
Notifications
You must be signed in to change notification settings - Fork 434
Add codegen implementations of CMSHist classes (2) #1252
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -412,6 +412,24 @@ void CMSHistSum::updateCache() const { | |
| } | ||
| } | ||
|
|
||
| std::vector<double> CMSHistSum::getFuncValList(std::size_t fnIdx) { | ||
| staging_ = compcache_[fnIdx]; | ||
| if (vtype_[fnIdx] == CMSHistFunc::VerticalSetting::LogQuadLinear) { | ||
| staging_.Exp(); | ||
| staging_.Scale(storage_[process_fields_[fnIdx]].Integral() / staging_.Integral()); | ||
| } | ||
| staging_.CropUnderflows(); | ||
| std::vector<double> result = staging_.GetValues(); | ||
| for (unsigned j = 0; j < bintypes_.size(); ++j) { | ||
| if (bintypes_[j][0] == 1) { | ||
| double x = vbinpars_[j][0]->getVal(); | ||
| result[j] += binerrors_[fnIdx][j] * x; | ||
| } else if (bintypes_[j][0] == 2 || bintypes_[j][0] == 3) | ||
| result[j] += scaledbinmods_[fnIdx][j]; | ||
| } | ||
| return result; | ||
| } | ||
|
Comment on lines
+415
to
+431
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. Harden This method currently assumes valid Proposed fix std::vector<double> CMSHistSum::getFuncValList(std::size_t fnIdx) {
+ updateCache();
+ if (fnIdx >= compcache_.size() || fnIdx >= binerrors_.size() || fnIdx >= scaledbinmods_.size()) {
+ throw std::out_of_range("CMSHistSum::getFuncValList: fnIdx out of range");
+ }
+
staging_ = compcache_[fnIdx];
if (vtype_[fnIdx] == CMSHistFunc::VerticalSetting::LogQuadLinear) {
staging_.Exp();
- staging_.Scale(storage_[process_fields_[fnIdx]].Integral() / staging_.Integral());
+ const double denom = staging_.Integral();
+ if (denom > 0.) {
+ staging_.Scale(storage_[process_fields_[fnIdx]].Integral() / denom);
+ }
}
staging_.CropUnderflows();
std::vector<double> result = staging_.GetValues(); |
||
|
|
||
| void CMSHistSum::runBarlowBeeston() const { | ||
| updateCache(); | ||
| const unsigned n = bb_.use.size(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ | |
| #if ROOT_VERSION_CODE >= ROOT_VERSION(6, 36, 0) | ||
|
|
||
| #include "../interface/AsymPow.h" | ||
| #include "../interface/CMSHistErrorPropagator.h" | ||
| #include "../interface/CMSHistFunc.h" | ||
| #include "../interface/CMSHistSum.h" | ||
| #include "../interface/ProcessNormalization.h" | ||
| #include "../interface/VerticalInterpHistPdf.h" | ||
| #include "../interface/VerticalInterpPdf.h" | ||
|
|
@@ -312,4 +315,68 @@ std::string RooFit::Experimental::codegenIntegralImpl(RooParametricHist& arg, | |
| xMax); | ||
| } | ||
|
|
||
| void RooFit::Experimental::codegenImpl(CMSHistFunc& arg, CodegenContext& ctx) { | ||
| arg.evaluate(); // trigger cache() creation | ||
| std::vector<double> const& edges = arg.cache().GetBinEdges(); | ||
|
|
||
| // I don't know if these values are actually constant and we can take them | ||
| // here to hardcode into the generated code... | ||
| auto const& values = arg.cache().GetValues(); | ||
|
|
||
| ctx.addResult(&arg, | ||
| ctx.buildCall("RooFit::Detail::MathFuncs::cmsHistFunc", | ||
| arg.getXVar(), | ||
| edges.size() - 1, | ||
| edges, | ||
| values | ||
| )); | ||
| } | ||
|
|
||
| void RooFit::Experimental::codegenImpl(CMSHistErrorPropagator& arg, CodegenContext& ctx) { | ||
| ctx.addResult(&arg, | ||
| ctx.buildCall("RooFit::Detail::MathFuncs::cmsHistErrorPropagator", | ||
| arg.getXVar(), | ||
| arg.coefList().size(), | ||
| arg.coefList(), | ||
| arg.funcList())); | ||
| } | ||
|
|
||
| std::string RooFit::Experimental::codegenIntegralImpl(CMSHistErrorPropagator& arg, | ||
| int code, | ||
| const char* rangeName, | ||
| CodegenContext& ctx) { | ||
| return "2.0"; // TODO: dummy for now | ||
| } | ||
|
Comment on lines
+344
to
+349
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. Replace dummy integral constants with fail-fast behavior. Returning Proposed minimal safe fix std::string RooFit::Experimental::codegenIntegralImpl(CMSHistErrorPropagator& arg,
int code,
const char* rangeName,
CodegenContext& ctx) {
- return "2.0"; // TODO: dummy for now
+ throw std::runtime_error("codegenIntegralImpl(CMSHistErrorPropagator) not implemented");
}
@@
std::string RooFit::Experimental::codegenIntegralImpl(CMSHistSum& arg,
int code,
const char* rangeName,
CodegenContext& ctx) {
- return "3.0"; // TODO: dummy for now
+ throw std::runtime_error("codegenIntegralImpl(CMSHistSum) not implemented");
}Also applies to: 375-380 🤖 Prompt for AI Agents |
||
|
|
||
| void RooFit::Experimental::codegenImpl(CMSHistSum& arg, CodegenContext& ctx) { | ||
| arg.evaluate(); | ||
| std::vector<double> const& edges = arg.cache().GetBinEdges(); | ||
| std::size_t nBins = edges.size() - 1; | ||
| RooArgList const& coefs = arg.coefList(); | ||
| std::size_t nSamples = coefs.size(); | ||
| std::vector<double> values(nBins * nSamples); | ||
| for (std::size_t iSamples = 0; iSamples < nSamples; ++iSamples) { | ||
| std::vector<double> sampleValues = arg.getFuncValList(iSamples); | ||
| for (std::size_t iBin = 0; iBin < nBins; ++iBin) | ||
| values[iBin + iSamples * nBins] = sampleValues[iBin]; | ||
| } | ||
|
|
||
| ctx.addResult(&arg, | ||
| ctx.buildCall("RooFit::Detail::MathFuncs::cmsHistSum", | ||
| arg.getXVar(), | ||
| nBins, | ||
| nSamples, | ||
| coefs, | ||
| edges, | ||
| values | ||
| )); | ||
| } | ||
|
|
||
| std::string RooFit::Experimental::codegenIntegralImpl(CMSHistSum& arg, | ||
| int code, | ||
| const char* rangeName, | ||
| CodegenContext& ctx) { | ||
| return "3.0"; // TODO: dummy for now | ||
| } | ||
|
Comment on lines
+318
to
+380
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. Run clang-format on the new codegen overload block. CI is already failing formatting checks for this region ( 🤖 Prompt for AI Agents |
||
|
|
||
| #endif // ROOT_VERSION_CODE >= ROOT_VERSION(6,36,0) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,15 +73,15 @@ FastHisto::FastHisto(const FastHisto &other) : | |
| } | ||
|
|
||
| int FastHisto::FindBin(const T &x) const { | ||
| auto match = std::lower_bound(binEdges_.begin(), binEdges_.end(), x); | ||
| auto match = std::upper_bound(binEdges_.begin(), binEdges_.end(), x); | ||
|
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. Fix clang-format violations in this file before merge. CI is currently failing on formatting for this file; please run the project formatter on the touched ranges and re-push. Also applies to: 84-84, 143-143, 146-146, 189-189, 200-200, 250-250, 253-253, 256-256 🤖 Prompt for AI Agents |
||
| if (match == binEdges_.begin()) return -1; | ||
| if (match == binEdges_.end()) return values_.size(); | ||
| return match - binEdges_.begin() - 1; | ||
| } | ||
|
|
||
|
|
||
| FastHisto::T FastHisto::GetAt(const T &x) const { | ||
| auto match = std::lower_bound(binEdges_.begin(), binEdges_.end(), x); | ||
| auto match = std::upper_bound(binEdges_.begin(), binEdges_.end(), x); | ||
| if (match == binEdges_.begin() || match == binEdges_.end()) return T(0.0); | ||
| return values_[match - binEdges_.begin() - 1]; | ||
| } | ||
|
|
@@ -140,10 +140,10 @@ FastHisto2D::FastHisto2D(const FastHisto2D &other) : | |
| } | ||
|
|
||
| FastHisto2D::T FastHisto2D::GetAt(const T &x, const T &y) const { | ||
| auto matchx = std::lower_bound(binEdgesX_.begin(), binEdgesX_.end(), x); | ||
| auto matchx = std::upper_bound(binEdgesX_.begin(), binEdgesX_.end(), x); | ||
| if (matchx == binEdgesX_.begin() || matchx == binEdgesX_.end()) return T(0.0); | ||
| int ix = (matchx - binEdgesX_.begin() - 1); | ||
| auto matchy = std::lower_bound(binEdgesY_.begin(), binEdgesY_.end(), y); | ||
| auto matchy = std::upper_bound(binEdgesY_.begin(), binEdgesY_.end(), y); | ||
| if (matchy == binEdgesY_.begin() || matchy == binEdgesY_.end()) return T(0.0); | ||
| int iy = (matchy - binEdgesY_.begin() - 1); | ||
| return values_[ix * binY_ + iy]; | ||
|
|
@@ -186,7 +186,7 @@ FastHisto2D::T FastHisto2D::GetMaxOnXY() const { | |
|
|
||
|
|
||
| FastHisto2D::T FastHisto2D::GetMaxOnX(const T &y) const { | ||
| auto matchy = std::lower_bound(binEdgesY_.begin(), binEdgesY_.end(), y); | ||
| auto matchy = std::upper_bound(binEdgesY_.begin(), binEdgesY_.end(), y); | ||
| if (matchy == binEdgesY_.begin() || matchy == binEdgesY_.end()) return T(0.0); | ||
| int iy = (matchy - binEdgesY_.begin() - 1); | ||
| T ret = 0.0; | ||
|
|
@@ -197,7 +197,7 @@ FastHisto2D::T FastHisto2D::GetMaxOnX(const T &y) const { | |
| } | ||
|
|
||
| FastHisto2D::T FastHisto2D::GetMaxOnY(const T &x) const { | ||
| auto matchx = std::lower_bound(binEdgesX_.begin(), binEdgesX_.end(), x); | ||
| auto matchx = std::upper_bound(binEdgesX_.begin(), binEdgesX_.end(), x); | ||
| if (matchx == binEdgesX_.begin() || matchx == binEdgesX_.end()) return T(0.0); | ||
| int ix = (matchx - binEdgesX_.begin() - 1); | ||
| return *std::max( &values_[ix * binY_], &values_[(ix+1) * binY_] ); | ||
|
|
@@ -247,13 +247,13 @@ FastHisto3D::FastHisto3D(const FastHisto3D &other) : | |
| } | ||
|
|
||
| FastHisto3D::T FastHisto3D::GetAt(const T &x, const T &y, const T &z) const { | ||
| auto matchx = std::lower_bound(binEdgesX_.begin(), binEdgesX_.end(), x); | ||
| auto matchx = std::upper_bound(binEdgesX_.begin(), binEdgesX_.end(), x); | ||
| if (matchx == binEdgesX_.begin() || matchx == binEdgesX_.end()) return T(0.0); | ||
| int ix = (matchx - binEdgesX_.begin() - 1); | ||
| auto matchy = std::lower_bound(binEdgesY_.begin(), binEdgesY_.end(), y); | ||
| auto matchy = std::upper_bound(binEdgesY_.begin(), binEdgesY_.end(), y); | ||
| if (matchy == binEdgesY_.begin() || matchy == binEdgesY_.end()) return T(0.0); | ||
| int iy = (matchy - binEdgesY_.begin() - 1); | ||
| auto matchz = std::lower_bound(binEdgesZ_.begin(), binEdgesZ_.end(), z); | ||
| auto matchz = std::upper_bound(binEdgesZ_.begin(), binEdgesZ_.end(), z); | ||
| if (matchz == binEdgesZ_.begin() || matchz == binEdgesZ_.end()) return T(0.0); | ||
| int iz = (matchz - binEdgesZ_.begin() - 1); | ||
| return values_[ix * binY_ *binZ_ +binZ_*iy + iz]; | ||
|
|
||
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
🏁 Script executed:
Repository: cms-analysis/HiggsAnalysis-CombinedLimit
Length of output: 699
🏁 Script executed:
Repository: cms-analysis/HiggsAnalysis-CombinedLimit
Length of output: 503
🏁 Script executed:
Repository: cms-analysis/HiggsAnalysis-CombinedLimit
Length of output: 111
🏁 Script executed:
Repository: cms-analysis/HiggsAnalysis-CombinedLimit
Length of output: 168
🏁 Script executed:
Repository: cms-analysis/HiggsAnalysis-CombinedLimit
Length of output: 410
🏁 Script executed:
Repository: cms-analysis/HiggsAnalysis-CombinedLimit
Length of output: 1556
Define the
CMSHistFuncintegral overload implementation.The declaration at line 31 declares
codegenIntegralImpl(CMSHistFunc&, ...), but this overload has no matching definition insrc/CombineCodegenImpl.cxx. The other three overloads (CMSHistErrorPropagator,CMSHistSum,VerticalInterpPdf) are all properly defined. This missing definition will cause a linker error if the overload is dispatched to.🤖 Prompt for AI Agents