12 namespace FunctionTree {
16 Value(0), Bounds(
std::pair<double, double>(0, 0)),
22 Error(
std::pair<double, double>(0, 0)) {
38 const double min,
const double max)
46 const double min,
const double max,
68 if (newPar->hasBounds()) {
74 bool isFix = newPar->isFixed();
95 throw ParameterFixed(
"FunctionTree::FitParameter::setValue() | Parameter " +
96 name() +
" is fixed!");
104 "FitParameter::setValue() | Parameter " +
name() +
105 " not within bounds: val=" + std::to_string(inVal) +
" [" +
106 std::to_string(
bounds().first) +
";" + std::to_string(
bounds().second) +
117 throw BadParameter(
"FitParameter::setBounds() | Bounds not valid: [" +
118 std::to_string(min) +
", " + std::to_string(max) +
"]");
126 throw BadParameter(
"FitParameter::setBounds() | Bounds not valid: [" +
127 std::to_string(r.first) +
", " +
128 std::to_string(r.second) +
"]");
141 throw std::runtime_error(
"FitParameter::error() | " 143 Name +
" has no errors defined!");
148 Error.first = errLow;
149 Error.second = errHigh;
150 if (
Error.first == 0.0 &&
Error.second == 0.0)
158 if (
Error.first == 0.0 &&
Error.second == 0.0)
167 if (
Error.first == 0.0 &&
Error.second == 0.0)
174 if (this->
type() != otherPar.
type())
176 if (this->
name() != otherPar.
name())
185 throw std::runtime_error(
"FitParameter::operator==() | Parameters " 187 name() +
") and value (" +
188 std::to_string(
value()) +
190 "parameter bounds. We assume that there is a " 191 "mistake. Check your input files!");
194 throw std::runtime_error(
195 "FitParameter::operator==() | Parameters " 197 name() +
") and value (" + std::to_string(
value()) +
198 ") but one is fixed the other not. " 199 "We assume that there is a mistake. Check your input files!");
202 throw std::runtime_error(
"FitParameter::operator==() | Parameters " 204 name() +
") and value (" +
205 std::to_string(
value()) +
207 "parameter error. We assume that there is a " 208 "mistake. Check your input files!");
214 if ((bounds.second > bounds.first) && (bounds.second >=
Value) &&
215 (bounds.first <=
Value))
221 std::stringstream oss;
222 oss << std::setw(20) <<
Name;
223 oss <<
"\t Value = " << std::left <<
Value;
225 oss <<
" (+-" <<
Error.first <<
")";
227 oss <<
" (+" <<
Error.second <<
" -" <<
Error.first <<
")";
231 oss <<
" [" <<
Bounds.first <<
" ; " <<
Bounds.second <<
"]";
238 std::stringstream ovs;
247 auto c = pt.get_optional<std::string>(
"<xmlattr>.Class");
248 if (c && c.get() !=
"Double")
249 throw BadConfig(
"CoherentIntensity::Factory() | Property tree seems to " 250 "not containt a configuration for an CoherentIntensity!");
253 Name = pt.get<std::string>(
"<xmlattr>.Name");
254 Value = pt.get<
double>(
"Value");
257 if (pt.get_optional<
double>(
"Error")) {
258 this->
setError(pt.get<
double>(
"Error"));
260 if (pt.get_optional<
double>(
"ErrorLow")) {
261 if (pt.get_optional<
double>(
"ErrorHigh"))
262 this->
setError(std::pair<double, double>(pt.get<
double>(
"ErrorLow"),
263 pt.get<
double>(
"ErrorHigh")));
265 throw std::runtime_error(
"FitParameterFactory() | Parameter asymmetic " 266 "error not properly set!");
267 }
else if (pt.get_optional<
double>(
"ErrorHigh")) {
268 throw std::runtime_error(
"FitParameterFactory() | Parameter asymmetic " 269 "error not properly set!");
273 auto fix = pt.get_optional<
bool>(
"Fix");
279 auto min = pt.get_optional<
double>(
"Min");
280 auto max = pt.get_optional<
double>(
"Max");
283 }
else if (min || max) {
284 throw std::runtime_error(
285 "FitParameterFactory() | Parameter bounds not properly set!");
291 boost::property_tree::ptree pt;
294 pt.put(
"<xmlattr>.Class",
"Double");
295 pt.put(
"<xmlattr>.Name",
name());
296 pt.put(
"Value",
value());
299 pt.put(
"Min",
bounds().first);
300 pt.put(
"Max",
bounds().second);
303 pt.put(
"Error",
error().first);
305 pt.put(
"ErrorLow",
error().first);
306 pt.put(
"ErrorHigh",
error().second);
virtual void setValue(const double inVal)
Setter for value of parameter.
virtual std::pair< double, double > error() const
Parameter error.
boost::property_tree::ptree save() const
Save parameter to a ptree.
Implementations of Parameter for various data types.
bool operator==(const FitParameter otherPar) const
Base class for internal parameter.
virtual void SetErrorType(ErrorType t)
virtual void updateParameter(std::shared_ptr< FitParameter > newPar)
Update member variables from other FitParameter.
virtual bool hasBounds() const
std::pair< double, double > Bounds
Parameter bounds.
virtual std::pair< double, double > bounds() const
Bounds of parameter.
virtual std::string name() const
Getter for name of object.
bool HasBounds
Are valid bounds defined for this parameter?
void load(const boost::property_tree::ptree &pt)
Load parameters from a ptree.
std::string Name
Name of parameter.
virtual std::string val_to_str() const
String with detailed information about the parameter.
bool IsFixed
Do you want to keep parameter fixed?
ErrorType ErrType
No error / symmetric error / asymmetric error.
FitParameter(std::string inName="")
Standard constructor with no information provided.
virtual void fixParameter(const bool fixed)
virtual double value() const
Getter for value of parameter.
virtual ParType type() const
Getter for type of object.
Parameter cannot be changed.
virtual void setError(double errLow, double errHigh)
Set parameter error and assume that this parameter has asymmetric errors.
virtual bool isFixed() const
double Value
Parameter value.
virtual std::string to_str() const
String with detailed information about the parameter.
virtual void setBounds(const double min, const double max)
Bounds of parameter.
virtual bool hasError() const
Is an error set?
void notify()
Notify all observing TreeNodes that parameter changed.
std::pair< double, double > Error
Lower parameter error.
ParType
Enums for the type of the parameter, should be extended if an new parameter type is added...
bool check_bounds(const std::pair< double, double > bounds) const
Check if min and max are valid bounds.