Skip to content

Commit 8de53fa

Browse files
committed
Throw runtime error when parameter is set via command line in a range outside its value
1 parent e13625a commit 8de53fa

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/utils.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,15 @@ void utils::setModelParameters( const std::string & setPhysicsModelParameterExpr
765765
cout << "Set Default Value of Parameter " << target
766766
<< " To : " << PhysicsParameterValue << "\n";
767767
tmpParameter->setVal(PhysicsParameterValue);
768+
if (tmpParameter->getVal() != PhysicsParameterValue) {
769+
throw std::runtime_error(
770+
Form("Parameter %s value %g is outside its range [%g, %g]. "
771+
"Use --rMin/--rMax or --setParameterRanges to adjust the range.",
772+
target.c_str(),
773+
PhysicsParameterValue,
774+
tmpParameter->getMin(),
775+
tmpParameter->getMax()));
776+
}
768777
}
769778
} else {
770779
RooCategory *tmpCategory = dynamic_cast<RooCategory*>(tmp);
@@ -791,9 +800,18 @@ void utils::setModelParameters( const std::string & setPhysicsModelParameterExpr
791800
if (isrvar) {
792801
RooRealVar *tmpParameter = dynamic_cast<RooRealVar*>(tmp);
793802
double PhysicsParameterValue = atof(SetParameterExpression[1].c_str());
794-
cout << "Set Default Value of Parameter " << SetParameterExpression[0]
795-
<< " To : " << PhysicsParameterValue << "\n";
803+
cout << "Set Default Value of Parameter " << SetParameterExpression[0] << " To : " << PhysicsParameterValue
804+
<< "\n";
796805
tmpParameter->setVal(PhysicsParameterValue);
806+
if (tmpParameter->getVal() != PhysicsParameterValue) {
807+
throw std::runtime_error(
808+
Form("Parameter %s value %g is outside its range [%g, %g]. "
809+
"Use --rMin/--rMax or --setParameterRanges to adjust the range.",
810+
SetParameterExpression[0].c_str(),
811+
PhysicsParameterValue,
812+
tmpParameter->getMin(),
813+
tmpParameter->getMax()));
814+
}
797815
} else {
798816
RooCategory *tmpCategory = dynamic_cast<RooCategory*>(tmp);
799817
int PhysicsParameterValue = atoi(SetParameterExpression[1].c_str());

0 commit comments

Comments
 (0)