ComPWA
Common Partial-Wave-Analysis Framework
FitParameter.hpp
Go to the documentation of this file.
1 // Copyright (c) 2013, 2017 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
9 
10 #ifndef _FITPARAMETER_HPP_
11 #define _FITPARAMETER_HPP_
12 
13 #include <cmath>
14 #include <complex>
15 #include <iostream>
16 #include <sstream>
17 #include <stdexcept>
18 #include <string>
19 
20 #include <boost/property_tree/ptree_fwd.hpp>
21 #include <boost/serialization/utility.hpp>
22 
23 #include "Core/Exceptions.hpp"
24 #include "Core/FitParameter.hpp"
26 #include "Core/Logging.hpp"
27 
28 namespace ComPWA {
29 
30 namespace FunctionTree {
31 
32 enum ErrorType { SYM = 1, ASYM = 2, LHSCAN = 3, NOTDEF = 0 };
33 
34 class FitParameter : public Parameter {
35 
36 public:
40  FitParameter(std::string inName = "");
41 
44  FitParameter(const boost::property_tree::ptree &pt);
45 
48  FitParameter(std::string inName, const double value);
49 
52  FitParameter(std::string inName, const double value, const double error);
53 
57  FitParameter(std::string inName, const double value, const double min,
58  const double max);
59 
63  FitParameter(std::string inName, const double value, const double min,
64  const double max, const double error);
65 
67 
68  virtual bool isParameter() const { return true; }
69 
70  operator double() const { return Value; };
71 
72  virtual bool hasBounds() const { return HasBounds; }
73 
74  virtual bool isFixed() const { return IsFixed; }
75 
76  virtual void fixParameter(const bool fixed) { IsFixed = fixed; }
77 
82  virtual void updateParameter(std::shared_ptr<FitParameter> newPar);
83 
84  //====== PARAMETER VALUE ========
86  virtual double value() const { return Value; }
87 
89  virtual void setValue(const double inVal);
90 
92  virtual std::pair<double, double> bounds() const;
93 
95  virtual void setBounds(const double min, const double max);
96 
98  virtual void setBounds(const std::pair<double, double> r);
99 
100  //====== PARAMETER ERROR ========
102  virtual bool hasError() const;
103 
104  virtual ErrorType errorType() const { return ErrType; }
105 
107  virtual std::pair<double, double> error() const;
108 
111  virtual double avgError() const { return 0.5 * (Error.first + Error.second); }
112 
114  virtual void setError(double errLow, double errHigh);
115 
117  virtual void setError(std::pair<double, double> err);
118 
121  virtual void setError(double err);
122 
123  bool operator==(const FitParameter otherPar) const;
124 
128  void load(const boost::property_tree::ptree &pt);
129 
133  boost::property_tree::ptree save() const;
134 
137  virtual std::string to_str() const;
138 
141  virtual std::string val_to_str() const;
142 
143 protected:
144  virtual std::string className() const { return "Double"; }
145 
147  bool HasBounds;
148 
150  bool IsFixed;
151 
153  double Value;
154 
156  std::pair<double, double> Bounds;
157 
160 
162  std::pair<double, double> Error;
163 
164  virtual void SetErrorType(ErrorType t) { ErrType = t; }
165 
167  bool check_bounds(const std::pair<double, double> bounds) const;
168 
169 private:
170  friend class boost::serialization::access;
171  template <class archive>
172  void serialize(archive &ar, const unsigned int version) {
173  using namespace boost::serialization;
174  // ar &boost::serialization::make_nvp(
175  // "Parameter", boost::serialization::base_object<Parameter>(*this));
176  ar &make_nvp("Name", Name);
177  ar &make_nvp("Bounds", Bounds);
178  ar &make_nvp("Fix", IsFixed);
179  ar &make_nvp("Value", Value);
180  ar &make_nvp("Bounds", Bounds);
181  try {
182  ar &make_nvp("ErrorType", ErrType);
183  ar &make_nvp("Error", Error);
184  } catch (...) {
185  Error = std::pair<double, double>(0, 0);
186  ErrType = ErrorType::SYM;
187  }
188  }
189 };
190 BOOST_SERIALIZATION_SHARED_PTR(ComPWA::FunctionTree::FitParameter)
191 
192 } // namespace FunctionTree
193 } // namespace ComPWA
194 
195 #endif
virtual void setValue(const double inVal)
Setter for value of parameter.
void serialize(archive &ar, const unsigned int version)
virtual ErrorType errorType() const
virtual std::pair< double, double > error() const
Parameter error.
boost::property_tree::ptree save() const
Save parameter to a ptree.
bool operator==(const FitParameter otherPar) const
Base class for internal parameter.
Definition: Parameter.hpp:79
virtual void SetErrorType(ErrorType t)
virtual void updateParameter(std::shared_ptr< FitParameter > newPar)
Update member variables from other FitParameter.
std::pair< double, double > Bounds
Parameter bounds.
virtual std::pair< double, double > bounds() const
Bounds of parameter.
ComPWA exceptions.
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.
Definition: Parameter.hpp:145
virtual std::string className() const
Getter for typename of object, to be defined by the actual implementation.
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 bool isParameter() const
virtual void fixParameter(const bool fixed)
virtual double value() const
Getter for value of parameter.
virtual double avgError() const
Average parameter error (in case of asymmetric errors) or simply parameter error. ...
virtual void setError(double errLow, double errHigh)
Set parameter error and assume that this parameter has asymmetric errors.
double Value
Parameter value.
virtual std::string to_str() const
String with detailed information about the parameter.
Parameter base class.
virtual void setBounds(const double min, const double max)
Bounds of parameter.
virtual bool hasError() const
Is an error set?
std::pair< double, double > Error
Lower parameter error.
bool check_bounds(const std::pair< double, double > bounds) const
Check if min and max are valid bounds.