From 86faf3ffc225364253ba35431dda2e23eadbd1f2 Mon Sep 17 00:00:00 2001
From: Jonas Rembser <jonas.rembser@cern.ch>
Date: Mon, 12 Apr 2021 12:11:04 +0200
Subject: [PATCH] [RF] Make RooAbsTestStatistic error out if multiple ranges
 are passed

The RooFit test statistic classes give wrong results if they are
constructed from multiple comma-separated ranges. This can cause errors,
such as the one reported in Jira issue ROOT-10038.

This commit suggests to throw an exception if multiple comma-separated
ranges are detected.
---
 roofit/roofitcore/src/RooAbsTestStatistic.cxx | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/roofit/roofitcore/src/RooAbsTestStatistic.cxx b/roofit/roofitcore/src/RooAbsTestStatistic.cxx
index a55c09e83b9..88c57bd6ada 100644
--- a/roofit/roofitcore/src/RooAbsTestStatistic.cxx
+++ b/roofit/roofitcore/src/RooAbsTestStatistic.cxx
@@ -104,6 +104,16 @@ RooAbsTestStatistic::RooAbsTestStatistic(const char *name, const char *title, Ro
 {
   // Register all parameters as servers
   _paramSet.add(*std::unique_ptr<RooArgSet>{real.getParameters(&data)});
+
+  if (cfg.rangeName.find(',') != std::string::npos) {
+    auto errorMsg = std::string("Ranges ") + cfg.rangeName
+            + " were passed to the RooAbsTestStatistic with name \"" + name + "\", "
+            + "but it doesn't support multiple comma-separated fit ranges!\n" +
+            + "Instead, one should combine multiple RooAbsTestStatistic objects "
+            + "(see RooAbsPdf::createNLL for an example with RooNLLVar).";
+    coutE(InputArguments) <<  errorMsg << std::endl;
+    throw std::invalid_argument(errorMsg);
+  }
 }
 
 
-- 
GitLab