Skip to content

Commit ad9e6ac

Browse files
committed
[HS3] Add interpolation export for HistFactory modifiers
1 parent 240db97 commit ad9e6ac

5 files changed

Lines changed: 672 additions & 55 deletions

File tree

roofit/histfactory/inc/RooStats/HistFactory/PiecewiseInterpolation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class PiecewiseInterpolation : public RooAbsReal {
3333
PiecewiseInterpolation() ;
3434
PiecewiseInterpolation(const char *name, const char *title, const RooAbsReal &nominal, const RooArgList &lowSet,
3535
const RooArgList &highSet, const RooArgList &paramSet);
36+
PiecewiseInterpolation(const char *name, const char *title, const RooAbsReal &nominal, const RooArgList &lowSet,
37+
const RooArgList &highSet, const RooArgList &paramSet,
38+
const std::vector<int> &interpolationCodes);
3639
~PiecewiseInterpolation() override ;
3740

3841
PiecewiseInterpolation(const PiecewiseInterpolation& other, const char *name = nullptr);

roofit/histfactory/src/PiecewiseInterpolation.cxx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,32 @@ PiecewiseInterpolation::PiecewiseInterpolation(const char *name, const char *tit
131131
TRACE_CREATE;
132132
}
133133

134-
134+
////////////////////////////////////////////////////////////////////////////////
135+
/// Construct a new interpolation and set the interpolation code for each
136+
/// parameter by position.
137+
/// \param name Name of the object.
138+
/// \param title Title (for e.g. plotting).
139+
/// \param nominal Nominal value of the function.
140+
/// \param lowSet Set of down variations.
141+
/// \param highSet Set of up variations.
142+
/// \param paramSet Parameters that control the interpolation.
143+
/// \param interpolationCodes Interpolation code for each parameter.
144+
PiecewiseInterpolation::PiecewiseInterpolation(const char *name, const char *title, const RooAbsReal &nominal,
145+
const RooArgList &lowSet, const RooArgList &highSet,
146+
const RooArgList &paramSet, const std::vector<int> &interpolationCodes)
147+
: PiecewiseInterpolation(name, title, nominal, lowSet, highSet, paramSet)
148+
{
149+
if (interpolationCodes.size() != _paramSet.size()) {
150+
coutE(InputArguments) << "PiecewiseInterpolation::ctor(" << GetName()
151+
<< ") ERROR: interpolation code vector should have the same length as the parameter list"
152+
<< std::endl;
153+
RooErrorHandler::softAbort();
154+
return;
155+
}
156+
for (std::size_t i = 0; i < interpolationCodes.size(); ++i) {
157+
setInterpCodeForParam(i, interpolationCodes[i]);
158+
}
159+
}
135160

136161
////////////////////////////////////////////////////////////////////////////////
137162
/// Copy constructor

roofit/histfactory/test/testPiecewiseInterpolation.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,22 @@ TEST(PiecewiseInterpolation, AdditiveOrMultiplicative)
101101
}
102102
}
103103
}
104+
105+
TEST(PiecewiseInterpolation, ConstructWithPerParameterCodes)
106+
{
107+
RooRealVar nominal{"nominal", "nominal", 1.0};
108+
RooRealVar parameter{"parameter", "parameter", 0.0, -2.0, 2.0};
109+
RooRealVar low1{"low1", "low1", 0.8};
110+
RooRealVar low2{"low2", "low2", 0.7};
111+
RooRealVar high1{"high1", "high1", 1.2};
112+
RooRealVar high2{"high2", "high2", 1.4};
113+
114+
// Repeating a parameter is supported by PiecewiseInterpolation, so codes
115+
// need to be assigned by position rather than by looking up the parameter.
116+
RooArgList parameters{parameter, parameter};
117+
RooArgList lows{low1, low2};
118+
RooArgList highs{high1, high2};
119+
PiecewiseInterpolation interpolation{"interpolation", "", nominal, lows, highs, parameters, {0, 2}};
120+
121+
EXPECT_EQ(interpolation.interpolationCodes(), (std::vector<int>{0, 2}));
122+
}

0 commit comments

Comments
 (0)