16 #include "Base/Const/Units.h"
17 #include "Base/Pixel/RectangularPixel.h"
18 #include "Device/Beam/Beam.h"
19 #include "Device/Coord/CoordSystem1D.h"
20 #include "Device/Coord/CoordSystem2D.h"
21 #include "Device/Detector/RectangularDetector.h"
22 #include "Device/Detector/SphericalDetector.h"
39 #include "Sim/Simulation/DepthProbeSimulation.h"
40 #include "Sim/Simulation/OffspecSimulation.h"
41 #include "Sim/Simulation/ScatteringSimulation.h"
45 void setBeamDistribution(ParameterDistribution::WhichParameter which,
50 simulation.addParameterDistribution(*P_par_distr);
60 : m_withPolarizerAnalyzer(false)
62 m_id = QUuid::createUuid().toString();
63 m_analyzerEfficiency.init(
"Analyzer efficiency",
"Efficiency of the polarization analysis", 0.0,
65 m_analyzerTotalTransmission.init(
"Analyzer transmission",
66 "Total transmission of the polarization analysis", 1.0,
68 m_polarization.init(
"Polarization (Bloch vector)",
69 "Polarization of the beam, given as the Bloch vector",
Unit::unitless,
71 m_analyzerDirection.init(
"Analyzer direction",
"Direction of the polarization analysis",
144 template <
typename T>
176 return beam<SpecularBeamItem>();
188 throw Error(
"Error in SpecularInstrumentItem::updateToRealData: The type "
189 "of instrument is incompatible with passed data shape.");
198 if (native_units ==
"nbins") {
203 if (!
beamItem()->inclinationAngleItem()->pointwiseAlphaAxisSelected())
206 const auto* axisItem =
210 if (axisItem->getUnitsLabel() != native_units)
213 const auto* instrumentAxis = axisItem->axis();
221 return *instrumentAxis == native_axis;
229 if (!pointwise_axis->axis())
232 return new AngularReflectometryCoordinates(
beam->wavelength(), *pointwise_axis->axis(),
236 return new AngularReflectometryCoordinates(
beam->wavelength(), *axis_item->createAxis(1.0),
260 axisItem->setUpperBound(1.0);
261 axisItem->setBinCount(500);
263 m_zAxis.initNbins(
"Nbins",
"Number of points in scan across sample bulk");
264 m_zAxis.initMin(
"Min",
"Starting value below sample horizon", -100.0,
Unit::nanometer,
265 RealLimits::limitless());
266 m_zAxis.initMax(
"Max",
"Ending value above sample horizon", 100.0,
Unit::nanometer,
267 RealLimits::limitless());
273 Serialize::rwBaseClass<InstrumentItem>(s,
"InstrumentItem",
this);
274 m_zAxis.rwAxisProperty(s,
"zAxis");
279 return beam<SpecularBeamItem>();
284 return std::vector<int>();
289 throw std::runtime_error(
"DepthProbeInstrumentItem::updateToRealData()");
299 return "Depth probe";
304 auto* simulation =
new DepthProbeSimulation(sample);
307 auto axis = axis_item->
createAxis(Units::deg);
309 simulation->setBeamParameters(
beamItem()->wavelength(),
static_cast<int>(axis->size()),
310 axis->min(), axis->max());
312 simulation->setZSpan(m_zAxis.nbins(), m_zAxis.min(), m_zAxis.max());
314 setBeamDistribution(ParameterDistribution::BeamWavelength, *
beamItem()->wavelengthItem(),
317 setBeamDistribution(ParameterDistribution::BeamInclinationAngle,
318 *
beamItem()->inclinationAngleItem(), *simulation);
342 Serialize::rwBaseClass<InstrumentItem>(s,
"InstrumentItem",
this);
365 detector->setDetectorNormal(
beam->direction().zReflected());
367 return std::make_unique<Instrument>(*
beam, *detector);
373 beam->setPolarization(m_polarization);
375 detector->setAnalyzer(m_analyzerDirection, m_analyzerEfficiency, m_analyzerTotalTransmission);
376 detector->setDetectorNormal(
beam->direction().zReflected());
378 auto* result =
new ScatteringSimulation(*
beam, sample, *detector);
385 beam->setPolarization(m_polarization);
387 detector->setAnalyzer(m_analyzerDirection, m_analyzerEfficiency, m_analyzerTotalTransmission);
388 detector->setDetectorNormal(
beam->direction().zReflected());
390 auto* result =
new OffspecSimulation(*
beam, sample, *detector);
401 return {detector_item->xSize(), detector_item->ySize()};
409 const auto data_shape = item->
shape();
410 if (
shape().size() != data_shape.size())
411 throw Error(
"Error in GISASInstrumentItem::updateToRealData: The type of "
412 "instrument is incompatible with passed data shape.");
430 return instrument->detector().scatteringCoords(instrument->beam());
439 m_alphaAxis.initNbins(
"Nbins",
"Number of points in scan");
440 m_alphaAxis.initMin(
"Min",
"Starting value", 0.0,
Unit::degree, RealLimits::limited(-90, 90));
441 m_alphaAxis.initMax(
"Max",
"Ending value", 10.0,
Unit::degree, RealLimits::limited(-90, 90));
450 Serialize::rwBaseClass<Instrument2DItem>(s,
"Instrument2DItem",
this);
451 m_alphaAxis.rwAxisProperty(s,
"alphaAxis");
464 const auto data_shape = dataItem->
shape();
465 if (
shape().size() != data_shape.size())
466 throw Error(
"Error in OffspecInstrumentItem::updateToRealData: The type of "
467 "instrument is incompatible with passed data shape.");
469 m_alphaAxis.setNbins(data_shape[0]);
480 return "Off specular";
486 new FixedBinAxis(
"alpha", m_alphaAxis.nbins(), m_alphaAxis.min() * Units::deg,
487 m_alphaAxis.max() * Units::deg);
489 return instrument->detector().offspecCoords(alphaAxis, instrument->beam().direction());
Defines class BackgroundItemCatalog.
Defines BackgroundItem classes.
Defines GUI::Util namespace.
Defines class BeamWavelengthItem.
Defines namespace GUI::Util::CoordName.
Defines class DetectorItemCatalog.
Defines classes DetectorItems.
Defines class InstrumentItemCatalog.
Defines class InstrumentItem and all its children.
Defines class Instrument.
Defines pointwise axis item.
Defines class RealDataItem.
Defines class RectangularDetectorItem.
Defines class SphericalDetectorItem.
Defines functions from namespace GUI::Util::String.
void setLowerBound(double value)
virtual std::unique_ptr< IAxis > createAxis(double scale) const
The BeamDistributionItem handles wavelength, inclination and azimuthal parameter distribution for Bea...
std::unique_ptr< ParameterDistribution > getParameterDistributionForName(ParameterDistribution::WhichParameter which) const
std::unique_ptr< Beam > createBeam() const
QString instrumentType() const override
The type as how to show it on the UI. Do not use for type checking or similar!
DepthProbeSimulation * createSimulation(const MultiLayer &sample) const
DepthProbeInstrumentItem()
SpecularBeamItem * beamItem() const override
QString defaultName() const override
The default user visible name when creating an instrument.
ICoordSystem * createCoordSystem() const override
void serialize(Streamer &s) override
void updateToRealData(const RealDataItem *item) override
std::vector< int > shape() const override
void importMasks(const MaskContainerItem *maskContainer)
virtual void setYSize(size_t ny)=0
sets the size of y-axis of the detector
virtual int ySize() const =0
Returns the size of y-axis of the detector.
std::unique_ptr< IDetector > createDetector() const
virtual void setXSize(size_t nx)=0
sets the size of x-axis of the detector
void setInclinationAngleGetter(std::function< double()> getter)
Explicitly set a getter function for the inclination angle.
QString instrumentType() const override
The type as how to show it on the UI. Do not use for type checking or similar!
ICoordSystem * createCoordSystem() const override
std::vector< int > shape() const override
QString defaultName() const override
The default user visible name when creating an instrument.
void updateToRealData(const RealDataItem *item) override
void serialize(Streamer &s) override
SelectionDescriptor< DetectorItem * > detectorSelection() const
DetectorItem * detectorItem() const
ScatteringSimulation * createScatteringSimulation(const MultiLayer &sample) const
OffspecSimulation * createOffspecSimulation(const MultiLayer &sample) const
SelectionProperty< DetectorItem * > m_detectorItem
std::unique_ptr< Instrument > createInstrument() const
void importMasks(const MaskContainerItem *maskContainer) override
static Type type(const InstrumentItem *item)
Returns the enum type of the given item.
static InstrumentItem * create(Type type)
Creates the item of the given type.
Abstract base class for instrument-specific item classes.
InstrumentItem * createCopy() const
Creates an exact copy; also ID is the same!
QString instrumentName() const
bool withPolarizerAnalyzer() const
void setId(const QString &id)
virtual std::vector< int > shape() const =0
void setDescription(const QString &description)
virtual BeamItem * beamItem() const
std::unique_ptr< BeamItem > m_beamItem
void setWithPolarizerAnalyzer(bool with)
SelectionDescriptor< BackgroundItem * > backgroundSelection() const
void setInstrumentName(const QString &instrumentName)
virtual void serialize(Streamer &s)
SelectionProperty< BackgroundItem * > m_backgroundItem
virtual bool alignedWith(const RealDataItem *item) const
BackgroundItem * backgroundItem() const
bool m_withPolarizerAnalyzer
QString description() const
Container holding various masks as children.
void updateToRealData(const RealDataItem *item) override
QString instrumentType() const override
The type as how to show it on the UI. Do not use for type checking or similar!
QString defaultName() const override
The default user visible name when creating an instrument.
std::vector< int > shape() const override
void serialize(Streamer &s) override
ICoordSystem * createCoordSystem() const override
Item for non-uniform axis with specified coordinates.
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
QString nativeDataUnits() const
std::vector< int > shape() const
Returns the shape of underlying data item.
bool hasNativeData() const
const Datafield * nativeDatafield() const
Describes a selection (various possibilities and the current one).
T get() const
Direct access to the stored pointer.
void init(const QString &label, const QString &tooltip, const QString &persistentTag, ArgsForCreation... argsForCreation)
Initialize by means of a catalog class and optional creation arguments.
bool uniformAlphaAxisSelected() const
True if uniform axis is selected.
BasicAxisItem * alphaAxis() const
The currently selected axis.
BasicAxisItem * inclinationAxis() const
void updateToData(const IAxis &axis, QString units)
SpecularBeamInclinationItem * inclinationAngleItem() const override
ICoordSystem * createCoordSystem() const override
SpecularBeamItem * beamItem() const override
std::vector< int > shape() const override
QString defaultName() const override
The default user visible name when creating an instrument.
QString instrumentType() const override
The type as how to show it on the UI. Do not use for type checking or similar!
void updateToRealData(const RealDataItem *item) override
bool alignedWith(const RealDataItem *item) const override
Supports serialization to or deserialization from QXmlStream.
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Coords coordFromName(const QString &name)
Returns domain axes units type from their GUI name.
void copyContents(const T *source, T *dest)
void rwProperty(Streamer &s, DoubleProperty &d)
void rwValue(Streamer &s, const QString &tag, bool &val)
void rwClass(Streamer &s, const QString &tag, T &t)
Serializes an item from a class that provides the function void serialize(Streamer&).