Skip to content

Commit 436cedd

Browse files
Phmonskiguitargeek
authored andcommitted
[HS3] Fix RooFormulaVar key export
This PR handles some key changes to HS3 missed by #22735 Fix HS3 export type names for generic functions. `RooTFnBinding and generated transformation functions now export as `generic, while RooGenericPdf continues to use `generic_dist. Legacy `generic_function` files remain supported on import.
1 parent 0ca1dda commit 436cedd

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

roofit/hs3/src/JSONFactories_RooFitCore.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ bool importExponential(RooJSONFactoryWSTool *tool, const JSONNode &p)
581581
// },
582582
// {
583583
// "name": "c_exponential_inverted", // transformation function created on-the-fly on export
584-
// "type": "generic_function",
584+
// "type": "generic",
585585
// "expression": "-c"
586586
// }
587587
//
@@ -1270,7 +1270,7 @@ STATIC_EXECUTE([]() {
12701270
registerExporter<exportPolynomial<RooPolyVar>>(RooPolyVar::Class(), "polynomial", false);
12711271
registerExporter<exportRealSumFunc>(RooRealSumFunc::Class(), "weighted_sum", false);
12721272
registerExporter<exportRealSumPdf>(RooRealSumPdf::Class(), "weighted_sum_dist", false);
1273-
registerExporter<exportTFnBinding>(RooTFnBinding::Class(), "generic_function", false);
1273+
registerExporter<exportTFnBinding>(RooTFnBinding::Class(), "generic", false);
12741274
registerExporter<exportRealIntegral>(RooRealIntegral::Class(), "integral", false);
12751275
registerExporter<exportDerivative>(RooDerivative::Class(), "derivative", false);
12761276
registerExporter<exportFFTConvPdf>(RooFFTConvPdf::Class(), "fft_convolution_dist", false);

roofit/hs3/src/RooJSONFactoryWSTool.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ std::string RooJSONFactoryWSTool::exportTransformed(const RooAbsReal *original,
942942
{
943943
std::string newname = std::string(original->GetName()) + suffix;
944944
RooFit::Detail::JSONNode &trafo_node = appendNamedChild((*_rootnodeOutput)["functions"], newname);
945-
trafo_node["type"] << "generic_function";
945+
trafo_node["type"] << "generic";
946946
trafo_node["expression"] << TString::Format(formula.c_str(), original->GetName()).Data();
947947
this->setAttribute(newname, "roofit_skip"); // this function should not be imported back in
948948
return newname;

roofit/hs3/test/testRooFitHS3.cxx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <RooStats/HistFactory/ParamHistFunc.h>
3737
#include <RooStats/HistFactory/FlexibleInterpVar.h>
3838
#include <RooStats/HistFactory/PiecewiseInterpolation.h>
39+
#include <RooTFnBinding.h>
3940
#include <RooWorkspace.h>
4041

4142
#include <cmath>
@@ -44,6 +45,7 @@
4445
#include <string_view>
4546
#include <vector>
4647

48+
#include <TF3.h>
4749
#include <TROOT.h>
4850

4951
#include <gtest/gtest.h>
@@ -2300,3 +2302,29 @@ TEST(RooFitHS3, SimultaneousFit)
23002302

23012303
EXPECT_TRUE(res2->isIdentical(*res1));
23022304
}
2305+
2306+
TEST(RooFitHS3, GenericTypeNames)
2307+
{
2308+
RooRealVar x{"x", "x", 0.5, -1.0, 1.0};
2309+
RooRealVar y{"y", "y", 0.5, -1.0, 1.0};
2310+
RooRealVar z{"z", "z", 0.5, -1.0, 1.0};
2311+
RooRealVar c{"c", "c", -0.1};
2312+
RooFormulaVar formula{"formula", "x + y", RooArgList{x, y}};
2313+
RooGenericPdf genericPdf{"genericPdf", "x + 2.0", RooArgList{x}};
2314+
TF3 tf3{"tf3", "x + y + z", -1.0, 1.0, -1.0, 1.0, -1.0, 1.0};
2315+
RooTFnBinding binding{"binding", "binding", &tf3, RooArgList{x, y, z}};
2316+
RooExponential exponential{"exponential", "exponential", x, c};
2317+
2318+
RooWorkspace ws{"ws_generic_types"};
2319+
ws.import(formula, RooFit::Silence());
2320+
ws.import(genericPdf, RooFit::Silence(), RooFit::RecycleConflictNodes());
2321+
ws.import(binding, RooFit::Silence(), RooFit::RecycleConflictNodes());
2322+
ws.import(exponential, RooFit::Silence(), RooFit::RecycleConflictNodes());
2323+
2324+
const std::string json = RooJSONFactoryWSTool{ws}.exportJSONtoString();
2325+
EXPECT_NE(json.find("\"name\":\"formula\",\"type\":\"generic\""), std::string::npos) << json;
2326+
EXPECT_NE(json.find("\"name\":\"genericPdf\",\"type\":\"generic_dist\""), std::string::npos) << json;
2327+
EXPECT_NE(json.find("\"name\":\"binding\",\"type\":\"generic\""), std::string::npos) << json;
2328+
EXPECT_NE(json.find("\"name\":\"c_exponential_inverted\",\"type\":\"generic\""), std::string::npos) << json;
2329+
EXPECT_EQ(json.find("\"type\":\"generic_function\""), std::string::npos) << json;
2330+
}

0 commit comments

Comments
 (0)