Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,16 @@
std::smatch match;
if (std::regex_match(target, match, rgx)) {
double PhysicsParameterValue = atof(SetParameterExpression[1].c_str());
if (PhysicsParameterValue < tmpParameter->getMin() ||
PhysicsParameterValue > tmpParameter->getMax()) {

Check warning on line 766 in src/utils.cc

View check run for this annotation

Codecov / codecov/patch

src/utils.cc#L766

Added line #L766 was not covered by tests
throw std::runtime_error(
Form("Parameter %s value %g is outside its range [%g, %g]. "
"Use --rMin/--rMax or --setParameterRanges to adjust the range.",
target.c_str(),
PhysicsParameterValue,
tmpParameter->getMin(),
tmpParameter->getMax()));
}
cout << "Set Default Value of Parameter " << target
<< " To : " << PhysicsParameterValue << "\n";
tmpParameter->setVal(PhysicsParameterValue);
Expand Down Expand Up @@ -791,8 +801,17 @@
if (isrvar) {
RooRealVar *tmpParameter = dynamic_cast<RooRealVar*>(tmp);
double PhysicsParameterValue = atof(SetParameterExpression[1].c_str());
cout << "Set Default Value of Parameter " << SetParameterExpression[0]
<< " To : " << PhysicsParameterValue << "\n";
if (PhysicsParameterValue < tmpParameter->getMin() || PhysicsParameterValue > tmpParameter->getMax()) {
throw std::runtime_error(
Form("Parameter %s value %g is outside its range [%g, %g]. "
"Use --rMin/--rMax or --setParameterRanges to adjust the range.",
SetParameterExpression[0].c_str(),
PhysicsParameterValue,
tmpParameter->getMin(),
tmpParameter->getMax()));
}
cout << "Set Default Value of Parameter " << SetParameterExpression[0] << " To : " << PhysicsParameterValue
<< "\n";
tmpParameter->setVal(PhysicsParameterValue);
} else {
RooCategory *tmpCategory = dynamic_cast<RooCategory*>(tmp);
Expand Down
16 changes: 16 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ COMBINE_ADD_TEST(simple-counting-experiment-text2workspace
# No output, so nothing to compare. We just check that it runs.
)

# Test that setting a parameter outside its range throws an error
COMBINE_ADD_TEST(setParameters-out-of-range
COMMAND combine -M MultiDimFit simple-counting-experiment.txt --setParameters r=-1.05
COPY_TO_BUILDDIR ${REPO}/data/tutorials/counting/simple-counting-experiment.txt
PASSRC 1
PASSREGEX "outside its range"
)

# Test that setting a parameter outside its range via regex throws an error
COMBINE_ADD_TEST(setParameters-out-of-range-regex
COMMAND combine -M MultiDimFit simple-counting-experiment.txt --setParameters "rgx{r}=-1.05"
COPY_TO_BUILDDIR ${REPO}/data/tutorials/counting/simple-counting-experiment.txt
PASSRC 1
PASSREGEX "outside its range"
)

COMBINE_ADD_TEST(simple-shapes-TH1-text2workspace
COMMAND text2workspace.py simple-shapes-TH1.txt
COPY_TO_BUILDDIR ${REPO}/data/tutorials/shapes/simple-shapes-TH1.txt
Expand Down
Loading