Skip to content

Commit 0c635d5

Browse files
committed
hs3: export polynomial defaults as numbers
1 parent 658a04c commit 0c635d5

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

roofit/hs3/src/JSONFactories_RooFitCore.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ class RooPolynomialFactory : public RooFit::JSONIO::Importer {
282282
// As long as the coefficients match the default coefficients in
283283
// RooFit, we don't have to instantiate RooFit objects but can
284284
// increase the lowestOrder flag.
285-
if (order == 0 && coef.val() == "1.0") {
285+
if (order == 0 && (coef.val() == "1.0" || coef.val() == "1")) {
286286
++lowestOrder;
287-
} else if (coefs.empty() && coef.val() == "0.0") {
287+
} else if (coefs.empty() && (coef.val() == "0.0" || coef.val() == "0")) {
288288
++lowestOrder;
289289
} else {
290290
coefs.add(*tool->request<RooAbsReal>(coef.val(), name));
@@ -817,7 +817,7 @@ void writePolynomialBody(const Pdf *pdf, JSONNode &elem)
817817
elem["x"] << pdf->x().GetName();
818818
auto &coefs = elem["coefficients"].set_seq();
819819
for (int i = 0; i < pdf->lowestOrder(); ++i) {
820-
coefs.append_child() << (i == 0 ? "1.0" : "0.0");
820+
coefs.append_child() << (i == 0 ? 1.0 : 0.0);
821821
}
822822
for (const auto &coef : pdf->coefList()) {
823823
coefs.append_child() << coef->GetName();

roofit/hs3/test/testRooFitHS3.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,12 @@ TEST(RooFitHS3, RooPolynomial)
701701
EXPECT_EQ(status, 0);
702702
status = validate({"Polynomial::poly1(x[0, 10], {a_2[0.003, -10, 10]}, 2)"});
703703
EXPECT_EQ(status, 0);
704+
705+
RooWorkspace ws;
706+
ws.factory("Polynomial::poly1(x[0, 10], {a_2[0.003, -10, 10]}, 2)");
707+
const std::string json = RooJSONFactoryWSTool{ws}.exportJSONtoString();
708+
EXPECT_NE(json.find("\"coefficients\":[1.0,0.0,\"a_2\"]"), std::string::npos) << json;
709+
EXPECT_EQ(json.find("\"coefficients\":[\"1.0\""), std::string::npos) << json;
704710
}
705711

706712
TEST(RooFitHS3, RooPowerSum)

0 commit comments

Comments
 (0)