From 2b1ecc6330e4d594edbcc50c462f3fa166744079 Mon Sep 17 00:00:00 2001 From: Carsten Burgard Date: Fri, 15 Dec 2023 16:25:58 +0100 Subject: [PATCH] [RF][HS3] Force exporting also empty ShapeSys In the current implementation, shapesys with no valid data (all constraints constant) are written out in an invalid way, making it impossible for the reader to then instantiate the correct number of parameters. This PR fixes this by forcing the write-out of data with all-zeros for such invalid shapesys. Alternatively, one could imagine dropping these shapesys completely, but that's maybe something of a policy decision that I don't want to make in a bugfix patch :) --- roofit/hs3/src/JSONFactories_HistFactory.cxx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/roofit/hs3/src/JSONFactories_HistFactory.cxx b/roofit/hs3/src/JSONFactories_HistFactory.cxx index 74949e2288890..09d56e33a7650 100644 --- a/roofit/hs3/src/JSONFactories_HistFactory.cxx +++ b/roofit/hs3/src/JSONFactories_HistFactory.cxx @@ -319,7 +319,7 @@ bool importHistSample(RooJSONFactoryWSTool &tool, RooDataHist &dh, RooArgSet con constraints.add(getConstraint(ws, parname)); } else if (modtype == "shapesys") { std::string funcName = channelName + "_" + sysname + "_ShapeSys"; - // funName should be "__ShapeSys" + // funcName should be "__ShapeSys" std::vector vals; for (const auto &v : mod["data"]["vals"].children()) { vals.push_back(v.val_double()); @@ -328,6 +328,9 @@ bool importHistSample(RooJSONFactoryWSTool &tool, RooDataHist &dh, RooArgSet con for (const auto &v : mod["parameters"].children()) { parnames.push_back(v.val()); } + if (vals.empty()) { + RooJSONFactoryWSTool::error("unable to instantiate shapesys '" + sysname + "' with 0 values!"); + } std::string constraint(mod["constraint"].val()); shapeElems.add(createPHF(funcName, sysname, parnames, vals, tool, constraints, varlist, constraint, defaultGammaMin, defaultShapeSysGammaMax, minShapeUncertainty)); @@ -925,6 +928,13 @@ bool tryExportHistFactory(RooJSONFactoryWSTool *tool, const std::string &pdfname auto &data = mod["data"].set_map(); auto &vals = data["vals"]; vals.fill_seq(sys.constraints); + } else { + auto &data = mod["data"].set_map(); + auto &vals = data["vals"]; + vals.set_seq(); + for (std::size_t i = 0; i < sys.parameters.size(); ++i) { + vals.append_child() << 0; + } } }