Skip to content

Commit

Permalink
Merge pull request mantidproject#37070 from robertapplin/36966-use-mu…
Browse files Browse the repository at this point in the history
…lti-classes-for-iqtfit

Use `MultiFunctionTemplate` classes for IqtFit
  • Loading branch information
SilkeSchomann authored Apr 8, 2024
2 parents 20f5575 + 2b31cc7 commit bbd1b8c
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 672 deletions.
4 changes: 0 additions & 4 deletions qt/scientific_interfaces/Inelastic/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ set(SRC_FILES
FunctionBrowser/FunctionTemplatePresenter.cpp
FunctionBrowser/FqFunctionModel.cpp
FunctionBrowser/IqtFunctionTemplateModel.cpp
FunctionBrowser/IqtFunctionTemplateView.cpp
FunctionBrowser/IqtTemplatePresenter.cpp
FunctionBrowser/MSDFunctionModel.cpp
FunctionBrowser/SingleFunctionTemplateModel.cpp
FunctionBrowser/SingleFunctionTemplateView.cpp
Expand Down Expand Up @@ -70,7 +68,6 @@ set(INC_FILES
FunctionBrowser/FqFunctionModel.h
FunctionBrowser/ITemplatePresenter.h
FunctionBrowser/IqtFunctionTemplateModel.h
FunctionBrowser/IqtTemplatePresenter.h
FunctionBrowser/MSDFunctionModel.h
FunctionBrowser/ParamID.h
FunctionBrowser/SingleFunctionTemplatePresenter.h
Expand Down Expand Up @@ -104,7 +101,6 @@ set(MOC_FILES
FitOutputOptionsView.h
FitPlotView.h
FunctionBrowser/FunctionTemplateView.h
FunctionBrowser/IqtFunctionTemplateView.h
FunctionBrowser/SingleFunctionTemplateView.h
FunctionBrowser/MultiFunctionTemplateView.h
InelasticFitPropertyBrowser.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "FunctionBrowser/ConvFunctionTemplateModel.h"
#include "FunctionBrowser/FqFunctionModel.h"
#include "FunctionBrowser/IqtFunctionTemplateModel.h"
#include "FunctionBrowser/IqtFunctionTemplateView.h"
#include "FunctionBrowser/IqtTemplatePresenter.h"
#include "FunctionBrowser/MSDFunctionModel.h"
#include "FunctionBrowser/MultiFunctionTemplatePresenter.h"
#include "FunctionBrowser/MultiFunctionTemplateView.h"
Expand Down Expand Up @@ -55,8 +53,9 @@ DataAnalysisTab *DataAnalysisTabFactory::makeMSDFitTab(int const index) const {
DataAnalysisTab *DataAnalysisTabFactory::makeIqtFitTab(int const index) const {
auto tab = new DataAnalysisTab(IqtFit::TAB_NAME, IqtFit::HAS_RESOLUTION, m_tabWidget->widget(index));
tab->setupFittingModel<IqtFitModel>();
tab->setupFitPropertyBrowser<IqtFunctionTemplateView, IqtTemplatePresenter, IqtFunctionTemplateModel>(
IqtFit::HIDDEN_PROPS);
auto browserCustomizations = packBrowserCustomizations(IqtFit::templateSubTypes());
tab->setupFitPropertyBrowser<MultiFunctionTemplateView, MultiFunctionTemplatePresenter, IqtFunctionTemplateModel>(
IqtFit::HIDDEN_PROPS, false, std::move(browserCustomizations));
tab->setupFitDataView<FitDataView>();
tab->setupOutputOptionsPresenter(true);
tab->setUpFitDataPresenter<FitDataPresenter>();
Expand Down
7 changes: 7 additions & 0 deletions qt/scientific_interfaces/Inelastic/Analysis/FitTabConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ static const auto HAS_RESOLUTION = false;
static const auto HIDDEN_PROPS =
std::vector<std::string>({"CreateOutput", "LogValue", "PassWSIndexToFunction", "ConvolveMembers",
"OutputCompositeMembers", "OutputWorkspace", "Output", "PeakRadius", "PlotParameter"});

inline auto templateSubTypes() {
return packTemplateSubTypes(
std::make_unique<IqtTypes::ExponentialSubType>(), std::make_unique<IqtTypes::StretchExpSubType>(),
std::make_unique<IqtTypes::BackgroundSubType>(), std::make_unique<IqtTypes::TieIntensitiesSubType>());
}

} // namespace IqtFit

namespace ConvFit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ std::optional<std::string> ConvFunctionTemplateModel::getPrefix(ParamID name) co
auto const prefixes = model()->peakPrefixes();
if (!prefixes)
return std::optional<std::string>();
auto const index = name > ParamID::LOR2_FWHM_1 && name <= ParamID::LOR2_FWHM_2 ? 1 : 0;
auto const index = name > ParamID::LOR1_FWHM && name <= ParamID::LOR2_FWHM ? 1 : 0;
return prefixes->at(index).toStdString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class MANTIDQT_INELASTIC_DLL ConvFunctionTemplateModel : public MultiFunctionTem
void checkConvolution(const IFunction_sptr &fun);
void checkSingleFunction(const IFunction_sptr &fun, bool &isLorentzianTypeSet, bool &isFiTypeSet);

FitType m_fitType = FitType::None;
LorentzianType m_lorentzianType = LorentzianType::None;
DeltaType m_deltaType = DeltaType::None;
TempCorrectionType m_tempCorrectionType = TempCorrectionType::None;
BackgroundType m_backgroundType = BackgroundType::None;
ConvTypes::FitType m_fitType = ConvTypes::FitType::None;
ConvTypes::LorentzianType m_lorentzianType = ConvTypes::LorentzianType::None;
ConvTypes::DeltaType m_deltaType = ConvTypes::DeltaType::None;
ConvTypes::TempCorrectionType m_tempCorrectionType = ConvTypes::TempCorrectionType::None;
ConvTypes::BackgroundType m_backgroundType = ConvTypes::BackgroundType::None;

BackgroundSubType m_backgroundSubtype;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@

namespace MantidQt::CustomInterfaces::IDA {

template <>
std::map<IqtTypes::ExponentialType, TemplateSubTypeDescriptor>
TemplateSubTypeImpl<IqtTypes::ExponentialType>::g_typeMap{
{IqtTypes::ExponentialType::None, {"None", "", {ParamID::NONE, ParamID::NONE}}},
{IqtTypes::ExponentialType::OneExponential,
{"One Exponential", "ExpDecay", {ParamID::EXP1_HEIGHT, ParamID::EXP1_LIFETIME}}},
{IqtTypes::ExponentialType::TwoExponentials,
{"Two Exponentials", "ExpDecay", {ParamID::EXP1_HEIGHT, ParamID::EXP2_LIFETIME}}},
};

template <>
std::map<IqtTypes::StretchExpType, TemplateSubTypeDescriptor> TemplateSubTypeImpl<IqtTypes::StretchExpType>::g_typeMap{
{IqtTypes::StretchExpType::None, {"None", "", {ParamID::NONE, ParamID::NONE}}},
{IqtTypes::StretchExpType::StretchExponential,
{"Stretch Exponential", "StretchExp", {ParamID::STRETCH_HEIGHT, ParamID::STRETCH_STRETCHING}}},
};

template <>
std::map<IqtTypes::BackgroundType, TemplateSubTypeDescriptor> TemplateSubTypeImpl<IqtTypes::BackgroundType>::g_typeMap{
{IqtTypes::BackgroundType::None, {"None", "", {ParamID::NONE, ParamID::NONE}}},
{IqtTypes::BackgroundType::Flat, {"FlatBackground", "FlatBackground", {ParamID::FLAT_BG_A0, ParamID::FLAT_BG_A0}}},
};

template <>
std::map<IqtTypes::TieIntensitiesType, TemplateSubTypeDescriptor>
TemplateSubTypeImpl<IqtTypes::TieIntensitiesType>::g_typeMap{
{IqtTypes::TieIntensitiesType::False, {"None", "", {ParamID::NONE, ParamID::NONE}}},
{IqtTypes::TieIntensitiesType::True, {"Tie Intensities", "", {ParamID::NONE, ParamID::NONE}}},
};

namespace ConvTypes {

std::map<FitType, bool> FitTypeQDepends = std::map<FitType, bool>({{FitType::None, false},
Expand Down Expand Up @@ -84,7 +114,7 @@ std::map<ConvTypes::LorentzianType, TemplateSubTypeDescriptor>
{ConvTypes::LorentzianType::OneLorentzian,
{"One Lorentzian", "Lorentzian", {ParamID::LOR1_AMPLITUDE, ParamID::LOR1_FWHM}}},
{ConvTypes::LorentzianType::TwoLorentzians,
{"Two Lorentzians", "Lorentzian", {ParamID::LOR2_AMPLITUDE_1, ParamID::LOR2_FWHM_1, ParamID::LOR2_FWHM_2}}},
{"Two Lorentzians", "Lorentzian", {ParamID::LOR1_AMPLITUDE, ParamID::LOR2_FWHM}}},
};

template <>
Expand All @@ -106,7 +136,7 @@ std::map<ConvTypes::DeltaType, TemplateSubTypeDescriptor> TemplateSubTypeImpl<Co
template <>
std::map<ConvTypes::TempCorrectionType, TemplateSubTypeDescriptor>
TemplateSubTypeImpl<ConvTypes::TempCorrectionType>::g_typeMap{
{ConvTypes::TempCorrectionType::None, {"None", "", {ParamID::NONE}}},
{ConvTypes::TempCorrectionType::None, {"None", "", {ParamID::NONE, ParamID::NONE}}},
{ConvTypes::TempCorrectionType::Exponential,
{"Temp Correction", "ConvTempCorrection", {ParamID::TEMPERATURE, ParamID::TEMPERATURE}}},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,48 @@
namespace MantidQt {
namespace CustomInterfaces {
namespace IDA {
namespace IqtTypes {

enum class ExponentialType {
None,
OneExponential,
TwoExponentials,
};

enum class StretchExpType { None, StretchExponential };

enum class BackgroundType { None, Flat };

enum class TieIntensitiesType { False, True };

enum SubTypeIndex {
Exponential = 0,
StretchExponential = 1,
Background = 2,
TieIntensities = 3,
};

struct ExponentialSubType : public TemplateSubTypeImpl<ExponentialType> {
std::string name() const override { return "Exponentials"; }
bool isType(const std::type_info &type) const override { return type == typeid(int); }
};

struct StretchExpSubType : public TemplateSubTypeImpl<StretchExpType> {
std::string name() const override { return "Stretch Exponential"; }
bool isType(const std::type_info &type) const override { return type == typeid(bool); }
};

struct BackgroundSubType : public TemplateSubTypeImpl<BackgroundType> {
std::string name() const override { return "Background"; }
};

struct TieIntensitiesSubType : public TemplateSubTypeImpl<TieIntensitiesType> {
std::string name() const override { return "Tie Intensities"; }
bool isType(const std::type_info &type) const override { return type == typeid(bool); }
};

} // namespace IqtTypes

namespace ConvTypes {

enum class LorentzianType {
Expand Down
Loading

0 comments on commit bbd1b8c

Please sign in to comment.