Skip to content

Commit f106059

Browse files
committed
[RF] Don't randomize num. events when creating Asimov from Simultaneous
Closes JIRA ticket https://its.cern.ch/jira/browse/ROOT-7499 Implement also a unit test, inspired by the reproducer posted on JIRA.
1 parent d594834 commit f106059

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

roofit/roofitcore/inc/RooSimSplitGenContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class RooSimSplitGenContext : public RooAbsGenContext {
5454
std::vector<int> _gcIndex ; ///< Index value corresponding to component
5555
TString _idxCatName ; ///< Name of index category
5656
Int_t _numPdf ; ///< Number of generated PDFs
57+
bool _expectedData = false; ///< Asimov?
5758

5859
RooArgSet _allVarsPdf ; ///< All pdf variables
5960

roofit/roofitcore/src/RooSimSplitGenContext.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ RooDataSet* RooSimSplitGenContext::generate(double nEvents, bool skipInit, bool
191191
nExpectedTotal += nExpected.back();
192192
}
193193

194-
if (extendedMode ) {
194+
// We don't randomize events in two cases:
195+
// 1. When the generation is extended, each component pdf will already
196+
// randomize the expected number of events so we don't need to do it here.
197+
// 2. If we want to create an expected Asimov dataset.
198+
if (extendedMode || _expectedData) {
195199
nGen = nExpected;
196200
} else {
197201
// Determine from that total number of events to be generated for each component
@@ -237,6 +241,7 @@ RooDataSet* RooSimSplitGenContext::generate(double nEvents, bool skipInit, bool
237241

238242
void RooSimSplitGenContext::setExpectedData(bool flag)
239243
{
244+
_expectedData = flag;
240245
for(RooAbsGenContext *elem : _gcList) {
241246
elem->setExpectedData(flag) ;
242247
}

roofit/roofitcore/test/testRooSimultaneous.cxx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Tests for the RooSimultaneous
22
// Authors: Jonas Rembser, CERN 06/2021
33

4+
#include <Roo1DTable.h>
45
#include <RooAddition.h>
56
#include <RooCategory.h>
67
#include <RooConstVar.h>
@@ -541,3 +542,35 @@ TEST(RooSimultaneous, PlotProjWData)
541542
// sum of data entries in the center.
542543
EXPECT_DOUBLE_EQ(frame->getCurve()->interpolate(0.), combData.sumEntries());
543544
}
545+
546+
/// JIRA ticket https://its.cern.ch/jira/browse/ROOT-7499
547+
/// Check that we can also generate Asimov datasets with non-integer weights
548+
/// via RooSimultaneous.
549+
TEST(RooSimultaneous, ExpectedDataWithNonIntegerWeights)
550+
{
551+
552+
RooWorkspace ws{"ws"};
553+
ws.factory("dummy_obs_a[0,1]");
554+
ws.factory("dummy_obs_b[0,1]");
555+
ws.factory("Uniform::uniform_a(dummy_obs_a)");
556+
ws.factory("Uniform::uniform_b(dummy_obs_b)");
557+
ws.factory("SUM::model_a(coeff_a[3.5]*uniform_a)");
558+
ws.factory("SUM::model_b(coeff_b[6.5]*uniform_b)");
559+
560+
RooRealVar &dummy_obs_a = *ws.var("dummy_obs_a");
561+
RooRealVar &dummy_obs_b = *ws.var("dummy_obs_b");
562+
563+
ws.factory("dummy_cat[a]");
564+
ws.factory("SIMUL::sim_model(dummy_cat, a = model_a, b = model_b)");
565+
RooAbsCategory &dummy_cat = *ws.cat("dummy_cat");
566+
567+
// std::cout << "simultaneous expected = " << ws.pdf("sim_model")->expectedEvents(dummy_obs) << std::endl;
568+
RooDataSet *data = ws.pdf("sim_model")->generate({dummy_obs_a, dummy_obs_b, dummy_cat}, RooFit::ExpectedData());
569+
570+
std::unique_ptr<Roo1DTable> tab{data->table(dummy_cat)};
571+
572+
// Check that the sum of entries for each category is as expected, matching
573+
// the coefficients from the RooAddPdf.
574+
EXPECT_FLOAT_EQ(tab->get("a"), ws.var("coeff_a")->getVal());
575+
EXPECT_FLOAT_EQ(tab->get("b"), ws.var("coeff_b")->getVal());
576+
}

0 commit comments

Comments
 (0)