Skip to content

Commit eb35ad1

Browse files
committed
[AD] Add translation methods for RooParametricHist
1 parent 1cc876a commit eb35ad1

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

interface/CombineCodegenImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FastVerticalInterpHistPdf2;
88
class FastVerticalInterpHistPdf2D2;
99
class ProcessNormalization;
1010
class VerticalInterpPdf;
11+
class RooParametricHist;
1112

1213
namespace RooFit::Experimental {
1314

@@ -18,8 +19,10 @@ namespace RooFit::Experimental {
1819
void codegenImpl(FastVerticalInterpHistPdf2D2& arg, CodegenContext& ctx);
1920
void codegenImpl(ProcessNormalization& arg, CodegenContext& ctx);
2021
void codegenImpl(VerticalInterpPdf& arg, CodegenContext& ctx);
22+
void codegenImpl(RooParametricHist& arg, CodegenContext& ctx);
2123

2224
std::string codegenIntegralImpl(VerticalInterpPdf& arg, int code, const char* rangeName, CodegenContext& ctx);
25+
std::string codegenIntegralImpl(RooParametricHist& arg, int code, const char* rangeName, CodegenContext& ctx);
2326

2427
} // namespace RooFit::Experimental
2528

src/CombineCodegenImpl.cxx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../interface/VerticalInterpHistPdf.h"
1010
#include "../interface/VerticalInterpPdf.h"
1111
#include "../interface/CombineMathFuncs.h"
12+
#include "../interface/RooParametricHist.h"
1213

1314
#include <RooUniformBinning.h>
1415

@@ -242,6 +243,33 @@ void RooFit::Experimental::codegenImpl(VerticalInterpPdf& arg, CodegenContext& c
242243
arg.quadraticAlgo()));
243244
}
244245

246+
void RooFit::Experimental::codegenImpl(RooParametricHist& arg, CodegenContext& ctx) {
247+
std::vector<double> diffs_flat;
248+
std::vector<double> sums_flat;
249+
if (arg.hasMorphs()) {
250+
arg.getFlattenedMorphs(diffs_flat, sums_flat);
251+
}
252+
253+
std::string xName = ctx.getResult(arg.observable());
254+
std::stringstream bin_i;
255+
bin_i << ctx.buildCall("RooFit::Detail::MathFuncs::parametricHistFindBin", arg.getNBins(), arg.getBins(), xName);
256+
std::stringstream code;
257+
code << ctx.buildCall("RooFit::Detail::MathFuncs::parametricHistEvaluate",
258+
bin_i.str(),
259+
arg.getPars(),
260+
arg.getBins(),
261+
arg.getNBins(),
262+
arg.getCoeffList(),
263+
static_cast<int>(arg.getCoeffList().size()),
264+
arg.hasMorphs() ? diffs_flat : std::vector<double>{},
265+
arg.hasMorphs() ? sums_flat : std::vector<double>{},
266+
arg.getWidths(),
267+
arg.getSmoothRegion()) +
268+
";\n";
269+
ctx.addToCodeBody(code.str());
270+
ctx.addResult(&arg, code.str());
271+
}
272+
245273
std::string RooFit::Experimental::codegenIntegralImpl(VerticalInterpPdf& arg,
246274
int code,
247275
const char* rangeName,
@@ -257,4 +285,31 @@ std::string RooFit::Experimental::codegenIntegralImpl(VerticalInterpPdf& arg,
257285
arg.quadraticAlgo());
258286
}
259287

288+
std::string RooFit::Experimental::codegenIntegralImpl(RooParametricHist& arg,
289+
int code,
290+
const char* rangeName,
291+
CodegenContext& ctx) {
292+
std::vector<double> diffs_flat;
293+
std::vector<double> sums_flat;
294+
if (arg.hasMorphs()) {
295+
arg.getFlattenedMorphs(diffs_flat, sums_flat);
296+
}
297+
double xMin = rangeName ? arg.getObs().getMin(rangeName) : -1;
298+
double xMax = rangeName ? arg.getObs().getMax(rangeName) : -1; // if rangeName is null, these values won't be used
299+
300+
return ctx.buildCall("RooFit::Detail::MathFuncs::parametricHistIntegral",
301+
arg.getPars(),
302+
arg.getBins(),
303+
arg.getNBins(),
304+
arg.getCoeffList(),
305+
static_cast<int>(arg.getCoeffList().size()),
306+
arg.hasMorphs() ? diffs_flat : std::vector<double>{},
307+
arg.hasMorphs() ? sums_flat : std::vector<double>{},
308+
arg.getWidths(),
309+
arg.getSmoothRegion(),
310+
rangeName ? std::string("\"") + rangeName + "\"" : std::string("nullptr"),
311+
xMin,
312+
xMax);
313+
}
314+
260315
#endif // ROOT_VERSION_CODE >= ROOT_VERSION(6,36,0)

0 commit comments

Comments
 (0)