|
2 | 2 | // Authors: Stephan Hageboeck, CERN 05/2019 |
3 | 3 | // Jonas Rembser, CERN 06/2022 |
4 | 4 |
|
5 | | -#include <RooRealVar.h> |
6 | | -#include <RooGenericPdf.h> |
7 | | -#include <RooProduct.h> |
8 | 5 | #include <RooArgList.h> |
9 | 6 | #include <RooBinning.h> |
10 | | -#include <RooUniformBinning.h> |
| 7 | +#include <RooFormulaVar.h> |
| 8 | +#include <RooGenericPdf.h> |
11 | 9 | #include <RooHelpers.h> |
| 10 | +#include <RooHistPdf.h> |
| 11 | +#include <RooProduct.h> |
| 12 | +#include <RooRealVar.h> |
| 13 | +#include <RooUniformBinning.h> |
12 | 14 | #include <RooWorkspace.h> |
13 | 15 |
|
14 | 16 | #include <gtest/gtest.h> |
@@ -340,3 +342,47 @@ TEST(GenericPdf, BinnedBoundariesSurviveRename) |
340 | 342 | EXPECT_NE(integratorName.find("RooBinIntegrator"), std::string::npos) << integratorName; |
341 | 343 | EXPECT_DOUBLE_EQ(value, piecewiseFlatIntegral); |
342 | 344 | } |
| 345 | + |
| 346 | +// Ensure the implementation of RooGenericPdf::binBoundaries() (and |
| 347 | +// RooFormulaVar::binBoundaries()) is consistent with equivalent RooHistPdf. |
| 348 | +TEST(GenericPdf, BinnedBoundariesConsistentWithHistPdf) |
| 349 | +{ |
| 350 | + int nBins = 5; |
| 351 | + |
| 352 | + RooRealVar x{"x", "x", 0, 0, 5}; |
| 353 | + x.setBins(nBins); |
| 354 | + |
| 355 | + RooDataHist dh{"dh", "", x}; |
| 356 | + |
| 357 | + RooHistPdf hpdf{"hpdf", "", x, dh}; |
| 358 | + RooGenericPdf gpdf{"gpdf", "x[0] - x[0] + 1", {x}}; // uniform dummy |
| 359 | + gpdf.setBinning(x, x.getBinning()); |
| 360 | + |
| 361 | + RooFormulaVar fvar{"fvar", "x[0] - x[0] + 1", {x}}; // uniform dummy |
| 362 | + fvar.setBinning(x, x.getBinning()); |
| 363 | + |
| 364 | + // intentionally beyond the bin boundaries |
| 365 | + double lo = -10; |
| 366 | + double hi = 10; |
| 367 | + |
| 368 | + std::unique_ptr<std::list<double>> boundsHistPdf{hpdf.binBoundaries(x, lo, hi)}; |
| 369 | + std::unique_ptr<std::list<double>> boundsGenericPdf{gpdf.binBoundaries(x, lo, hi)}; |
| 370 | + std::unique_ptr<std::list<double>> boundsFormulaVar{fvar.binBoundaries(x, lo, hi)}; |
| 371 | + |
| 372 | + EXPECT_EQ(boundsHistPdf->size(), nBins + 1); |
| 373 | + EXPECT_EQ(boundsGenericPdf->size(), nBins + 1); |
| 374 | + EXPECT_EQ(boundsFormulaVar->size(), nBins + 1); |
| 375 | + |
| 376 | + auto iterHistPdf = boundsHistPdf->begin(); |
| 377 | + auto iterGenericPdf = boundsGenericPdf->begin(); |
| 378 | + auto iterFormulaVar = boundsFormulaVar->begin(); |
| 379 | + |
| 380 | + for (int i = 0; i < nBins + 1; ++i) { |
| 381 | + EXPECT_EQ(*iterHistPdf, static_cast<double>(i)); |
| 382 | + EXPECT_EQ(*iterGenericPdf, static_cast<double>(i)); |
| 383 | + EXPECT_EQ(*iterFormulaVar, static_cast<double>(i)); |
| 384 | + iterHistPdf++; |
| 385 | + iterGenericPdf++; |
| 386 | + iterFormulaVar++; |
| 387 | + } |
| 388 | +} |
0 commit comments