BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DistributionItems.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/DistributionItems.h
6 //! @brief Defines class DistributionItem and several subclasses
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2022
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_DISTRIBUTIONITEMS_H
16 #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_DISTRIBUTIONITEMS_H
17 
20 #include <QVector>
21 #include <memory>
22 
23 class IDistribution1D;
24 class IRangedDistribution;
25 class Streamer;
26 
28 public:
29  virtual ~DistributionItem() = default;
31 
32  template <typename T>
33  bool is() const
34  {
35  return dynamic_cast<const T*>(this) != nullptr;
36  }
37 
38  virtual std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const = 0;
39 
40  virtual void initDistribution(double) {}
41 
42  virtual void setLimits(const RealLimits& limits);
43  RealLimits limits() const;
44 
45  //! Set the unit of the distributed value
46  virtual void setUnit(const variant<QString, Unit>& unit) = 0;
47 
48  UINT_PROPERTY(numberOfSamples, NumberOfSamples);
49  DOUBLE_PROPERTY(sigmaFactor, SigmaFactor);
50  bool hasSigmaFactor() const;
51 
52  //! Serialization of contents.
53  //!
54  //! Important: limits and a changed unit (with setUnit) will not be serialized here. They have
55  //! to be set again by the owner of DistributionItem after reading it
56  void serialize(Streamer& s);
57 
58  virtual DoubleDescriptors distributionValues(bool withMean = true) const = 0;
59 
60 protected:
61  void initSigmaFactor();
63 
64  RealLimits m_limits;
65 
66 private:
67  QVector<DoubleProperty*> m_serializationProperties; //! properties to be serialized
68 };
69 
71 public:
72  SymmetricResolutionItem(double mean, int decimals = 3, const QString& meanLabel = "Mean");
73  void setUnit(const variant<QString, Unit>& unit) override;
74  void setLimits(const RealLimits& limits) override;
75 
76  DOUBLE_PROPERTY(mean, Mean);
77  void setMeanDecimals(uint d);
78 
79  virtual std::unique_ptr<IRangedDistribution> createIRangedDistribution(double scale) const = 0;
80  virtual double deviation(double scale) const = 0;
81 };
82 
84 public:
86 
87  std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const override;
88  std::unique_ptr<IRangedDistribution> createIRangedDistribution(double scale) const override;
89  double deviation(double scale) const override;
90  void initDistribution(double value) override;
91 
92  DoubleDescriptors distributionValues(bool withMean = true) const override;
93 };
94 
96 public:
98 
99  void setUnit(const variant<QString, Unit>& unit) override;
100 
101  std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const override;
102  void initDistribution(double value) override;
103 
104  DOUBLE_PROPERTY(minimum, Minimum);
105  DOUBLE_PROPERTY(maximum, Maximum);
106  void setRange(double min, double max);
107 
108  DoubleDescriptors distributionValues(bool withMean = true) const override;
109 };
110 
112 public:
114  void setUnit(const variant<QString, Unit>& unit) override;
115 
116  std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const override;
117  std::unique_ptr<IRangedDistribution> createIRangedDistribution(double scale) const override;
118  double deviation(double scale) const override;
119 
120  DOUBLE_PROPERTY(hwhm, Hwhm);
121 
122  void initDistribution(double value) override;
123 
124  DoubleDescriptors distributionValues(bool withMean = true) const override;
125 };
126 
128 public:
130  void setUnit(const variant<QString, Unit>& unit) override;
131 
132  std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const override;
133  std::unique_ptr<IRangedDistribution> createIRangedDistribution(double scale) const override;
134  double deviation(double scale) const override;
135 
136  DOUBLE_PROPERTY(standardDeviation, StandardDeviation);
137 
138  void initDistribution(double value) override;
139 
140  DoubleDescriptors distributionValues(bool withMean = true) const override;
141 };
142 
144 public:
146  void setUnit(const variant<QString, Unit>& unit) override;
147 
148  std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const override;
149  void initDistribution(double value) override;
150 
151  DOUBLE_PROPERTY(median, Median);
152  DOUBLE_PROPERTY(scaleParameter, ScaleParameter);
153 
154  DoubleDescriptors distributionValues(bool withMean = true) const override;
155 };
156 
158 public:
160  void setUnit(const variant<QString, Unit>& unit) override;
161 
162  std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const override;
163  std::unique_ptr<IRangedDistribution> createIRangedDistribution(double scale) const override;
164  double deviation(double scale) const override;
165  void initDistribution(double value) override;
166 
167  DOUBLE_PROPERTY(sigma, Sigma);
168 
169  DoubleDescriptors distributionValues(bool withMean = true) const override;
170 };
171 
173 public:
175  void setUnit(const variant<QString, Unit>& unit) override;
176 
177  std::unique_ptr<IDistribution1D> createDistribution(double scale = 1.0) const override;
178  void initDistribution(double value) override;
179 
180  DOUBLE_PROPERTY(center, Center);
181  DOUBLE_PROPERTY(leftWidth, LeftWidth);
182  DOUBLE_PROPERTY(middleWidth, MiddleWidth);
183  DOUBLE_PROPERTY(rightWidth, RightWidth);
184 
185  DoubleDescriptors distributionValues(bool withMean = true) const override;
186 };
187 
188 #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_DISTRIBUTIONITEMS_H
QList< DoubleDescriptor > DoubleDescriptors
Defines class DoubleProperty.
Defines class UIntProperty.
DOUBLE_PROPERTY(sigma, Sigma)
void setUnit(const variant< QString, Unit > &unit) override
Set the unit of the distributed value.
double deviation(double scale) const override
std::unique_ptr< IRangedDistribution > createIRangedDistribution(double scale) const override
DoubleDescriptors distributionValues(bool withMean=true) const override
void initDistribution(double value) override
std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const override
DOUBLE_PROPERTY(minimum, Minimum)
DoubleDescriptors distributionValues(bool withMean=true) const override
void setRange(double min, double max)
std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const override
DOUBLE_PROPERTY(maximum, Maximum)
void setUnit(const variant< QString, Unit > &unit) override
Set the unit of the distributed value.
void initDistribution(double value) override
std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const override
void initDistribution(double value) override
DOUBLE_PROPERTY(standardDeviation, StandardDeviation)
double deviation(double scale) const override
std::unique_ptr< IRangedDistribution > createIRangedDistribution(double scale) const override
void setUnit(const variant< QString, Unit > &unit) override
Set the unit of the distributed value.
DoubleDescriptors distributionValues(bool withMean=true) const override
DOUBLE_PROPERTY(sigmaFactor, SigmaFactor)
UINT_PROPERTY(numberOfSamples, NumberOfSamples)
virtual std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const =0
void serialize(Streamer &s)
Serialization of contents.
RealLimits limits() const
virtual ~DistributionItem()=default
void addToSerialization(DoubleProperty *d)
bool hasSigmaFactor() const
virtual void setLimits(const RealLimits &limits)
virtual void initDistribution(double)
virtual void setUnit(const variant< QString, Unit > &unit)=0
Set the unit of the distributed value.
QVector< DoubleProperty * > m_serializationProperties
virtual DoubleDescriptors distributionValues(bool withMean=true) const =0
void initDistribution(double value) override
DOUBLE_PROPERTY(scaleParameter, ScaleParameter)
DoubleDescriptors distributionValues(bool withMean=true) const override
DOUBLE_PROPERTY(median, Median)
std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const override
void setUnit(const variant< QString, Unit > &unit) override
Set the unit of the distributed value.
DOUBLE_PROPERTY(hwhm, Hwhm)
void initDistribution(double value) override
double deviation(double scale) const override
DoubleDescriptors distributionValues(bool withMean=true) const override
std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const override
std::unique_ptr< IRangedDistribution > createIRangedDistribution(double scale) const override
void setUnit(const variant< QString, Unit > &unit) override
Set the unit of the distributed value.
std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const override
DoubleDescriptors distributionValues(bool withMean=true) const override
double deviation(double scale) const override
void initDistribution(double value) override
std::unique_ptr< IRangedDistribution > createIRangedDistribution(double scale) const override
DOUBLE_PROPERTY(middleWidth, MiddleWidth)
void setUnit(const variant< QString, Unit > &unit) override
Set the unit of the distributed value.
std::unique_ptr< IDistribution1D > createDistribution(double scale=1.0) const override
void initDistribution(double value) override
DOUBLE_PROPERTY(rightWidth, RightWidth)
DoubleDescriptors distributionValues(bool withMean=true) const override
DOUBLE_PROPERTY(leftWidth, LeftWidth)
DOUBLE_PROPERTY(center, Center)
Class for representing a double value, its attributes and its accessors.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
virtual double deviation(double scale) const =0
void setLimits(const RealLimits &limits) override
virtual std::unique_ptr< IRangedDistribution > createIRangedDistribution(double scale) const =0
void setUnit(const variant< QString, Unit > &unit) override
Set the unit of the distributed value.
SymmetricResolutionItem(double mean, int decimals=3, const QString &meanLabel="Mean")
DOUBLE_PROPERTY(mean, Mean)