BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularBeamInclinationItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Device/SpecularBeamInclinationItem.cpp
6 //! @brief Implements class SpecularBeamInclinationItem
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Axis/IAxis.h"
17 #include "Base/Const/Units.h"
21 
22 namespace {
23 
24 void setAxisPresentationDefaults(BasicAxisItem* axisItem)
25 {
26  ASSERT(axisItem);
27 
28  axisItem->setTitle("alpha_i");
29  axisItem->binsItem()->setToolTip("Number of points in scan");
30  axisItem->minItem()->setToolTip("Starting value [deg]");
31  axisItem->maxItem()->setToolTip("Ending value [deg]");
32  axisItem->minItem()->setLimits(RealLimits::limited(0., 90.));
33  axisItem->maxItem()->setLimits(RealLimits::limited(0., 90.));
34 
35  if (!dynamic_cast<PointwiseAxisItem*>(axisItem)) {
36  axisItem->setLowerBound(0.0);
37  axisItem->setUpperBound(3.0);
38  axisItem->setBinCount(500);
39  }
40 }
41 
42 void initDistribution(DistributionItem* newDistribution,
43  const DistributionItem* currentDistribution)
44 {
45  newDistribution->setLimits(RealLimits::limited(-90.0, 90.0));
46  newDistribution->setUnit(Unit::degree);
47 
48  double meanVal = 0.0;
49  if (auto* cd = dynamic_cast<const SymmetricResolutionItem*>(currentDistribution))
50  meanVal = cd->mean();
51 
52  if (auto* nd = dynamic_cast<SymmetricResolutionItem*>(newDistribution)) {
53  nd->setMean(meanVal);
54  nd->setMeanDecimals(3);
55  }
56 
57  newDistribution->initDistribution(meanVal);
58 };
59 
60 
61 } // namespace
62 
65  , m_owningInstrument(owningInstrument)
66 {
68  "Distribution", "", "distribution", DistributionItemCatalog::symmetricTypes(),
69  initDistribution);
70 
71  m_uniformAlphaAxis.reset(new BasicAxisItem());
72  setAxisPresentationDefaults(m_uniformAlphaAxis.get());
74 }
75 
77 {
78  s.assertVersion(0);
79  Serialize::rwSelected<DistributionItemCatalog>(s, m_distribution);
80  Serialize::rwValue(s, "currentAxisIsUniformAxis", m_currentAxisIsUniformAxis);
81  Serialize::rwInitializable<BasicAxisItem>(s, "uniformAxis", m_uniformAlphaAxis,
82  setAxisPresentationDefaults);
83  Serialize::rwInitializable<PointwiseAxisItem>(s, "pointwiseAxis", m_pointwiseAlphaAxis,
84  setAxisPresentationDefaults);
85 
86  if (s.xmlReader()) {
87  m_distribution->setLimits(RealLimits::limited(-90.0, 90.0));
90  m_pointwiseAlphaAxis->setOwningInstrument(m_owningInstrument);
91  }
92 }
93 
95 {
96  return Units::deg;
97 }
98 
100 {
102 }
103 
105 {
106  return m_pointwiseAlphaAxis.get() != nullptr;
107 }
108 
110 {
112 }
113 
115 {
117 }
118 
120 {
122 }
123 
125 {
126  ASSERT(pointwiseAlphaAxisDefined());
128 }
129 
131 {
132  m_uniformAlphaAxis->setBinCount(static_cast<int>(axis.size()));
133 }
134 
135 void SpecularBeamInclinationItem::initPointwiseAxis(const IAxis& axis, QString units)
136 {
137  if (!m_pointwiseAlphaAxis) {
139  m_pointwiseAlphaAxis->setOwningInstrument(m_owningInstrument);
140  setAxisPresentationDefaults(m_pointwiseAlphaAxis.get());
141  }
142 
143  m_pointwiseAlphaAxis->init(axis, units);
144  m_pointwiseAlphaAxis->updateIndicators();
145 }
Defines class DistributionItemCatalog.
Defines pointwise axis item.
Defines class Streamer.
Declares the class SpecularBeamInclinationItem.
@ degree
SessionItem * maxItem() const
Definition: AxesItems.cpp:70
SessionItem * binsItem() const
Definition: AxesItems.cpp:36
SessionItem * minItem() const
Definition: AxesItems.cpp:53
void setBinCount(size_t value)
Definition: AxesItems.cpp:31
void setLowerBound(double value)
Definition: AxesItems.cpp:48
void setUpperBound(double value)
Definition: AxesItems.cpp:65
void setTitle(const QString &title)
Definition: AxesItems.cpp:85
The BeamDistributionItem handles wavelength, inclination and azimuthal parameter distribution for Bea...
SelectionProperty< DistributionItem * > m_distribution
static QVector< Type > symmetricTypes()
Types of symmetric distributions.
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.
Abstract base class for instrument-specific item classes.
Item for non-uniform axis with specified coordinates.
void initWithInitializer(const QString &label, const QString &tooltip, const QString &persistentTag, std::function< void(T newItem, const T oldItem)> initializer)
Initialize by means of a catalog class and an initializer function.
SessionItem & setToolTip(const QString &tooltip)
SessionItem & setLimits(const RealLimits &value)
const InstrumentItem * m_owningInstrument
bool uniformAlphaAxisSelected() const
True if uniform axis is selected.
BasicAxisItem * alphaAxis() const
The currently selected axis.
bool pointwiseAlphaAxisDefined() const
True if a pointwise axis was defined.
std::unique_ptr< BasicAxisItem > m_uniformAlphaAxis
bool pointwiseAlphaAxisSelected() const
True if pointwise axis is selected.
SpecularBeamInclinationItem(const InstrumentItem *owningInstrument)
void serialize(Streamer &s) override
std::unique_ptr< PointwiseAxisItem > m_pointwiseAlphaAxis
void initPointwiseAxis(const IAxis &axis, QString units)
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
Definition: Streamer.h:48
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26
void rwValue(Streamer &s, const QString &tag, bool &val)
Definition: Serialize.cpp:19