diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h index 97921431d007f84e30bfee9069fef5ed4261c2b0..523902e710aa11b106ddebf042c8335822e31efd 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h @@ -50,6 +50,7 @@ namespace IDA boost::shared_ptr<Mantid::API::CompositeFunction> createFunction(bool tieCentres=false); double getInstrumentResolution(std::string workspaceName); QtProperty* createLorentzian(const QString &); + QtProperty* createDiffSphere(const QString &); void createTemperatureCorrection(Mantid::API::CompositeFunction_sptr product); void populateFunction(Mantid::API::IFunction_sptr func, Mantid::API::IFunction_sptr comp, QtProperty* group, const std::string & pref, bool tie); QString fitTypeString() const; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui index 903d3702eecec710d9fbab6301aa6e0146eca24f..d2f27472f1c6185200d5d8b795aa8772cba2322c 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui @@ -141,6 +141,11 @@ <string>Two Lorentzians</string> </property> </item> + <item> + <property name="text"> + <string>Diffusion Sphere</string> + </property> + </item> </widget> </item> </layout> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp index 56fbf8531693c779d2364677204574fa333949a8..247a7875af74840915ca8ec5cdb5e6ff520b4fdd 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp @@ -94,6 +94,7 @@ namespace IDA m_properties["Lorentzian1"] = createLorentzian("Lorentzian 1"); m_properties["Lorentzian2"] = createLorentzian("Lorentzian 2"); + m_properties["DiffSphere"] = createDiffSphere("Diffusion Sphere"); m_uiForm.leTempCorrection->setValidator(new QDoubleValidator(m_parentWidget)); @@ -425,7 +426,7 @@ namespace IDA int fitTypeIndex = m_uiForm.cbFitType->currentIndex(); // Add 1st Lorentzian - if(fitTypeIndex > 0) + if(fitTypeIndex == 1 || fitTypeIndex == 2) { //if temperature not included then product is lorentzian * 1 //create product function for temp * lorentzian @@ -464,6 +465,28 @@ namespace IDA populateFunction(func, model, m_properties["Lorentzian2"], prefix2, false); } + // ---------------------------------------------------- + // --- Composite / Convolution / Model / DiffSphere --- + // ---------------------------------------------------- + if ( fitTypeIndex == 3 ) + { + //if temperature not included then product is lorentzian * 1 + //create product function for temp * lorentzian + auto product = boost::dynamic_pointer_cast<CompositeFunction>(FunctionFactory::Instance().createFunction("ProductFunction")); + + if(useTempCorrection) + { + createTemperatureCorrection(product); + } + + func = FunctionFactory::Instance().createFunction("InelasticDiffSphere"); + subIndex = product->addFunction(func); + index = model->addFunction(product); + prefix2 = createParName(index, subIndex); + + populateFunction(func, model, m_properties["DiffSphere"], prefix2, false); + } + conv->addFunction(model); comp->addFunction(conv); @@ -547,20 +570,46 @@ namespace IDA QtProperty* ConvFit::createLorentzian(const QString & name) { QtProperty* lorentzGroup = m_grpManager->addProperty(name); + m_properties[name+".Amplitude"] = m_dblManager->addProperty("Amplitude"); // m_dblManager->setRange(m_properties[name+".Amplitude"], 0.0, 1.0); // 0 < Amplitude < 1 m_properties[name+".PeakCentre"] = m_dblManager->addProperty("PeakCentre"); m_properties[name+".FWHM"] = m_dblManager->addProperty("FWHM"); + m_dblManager->setDecimals(m_properties[name+".Amplitude"], NUM_DECIMALS); m_dblManager->setDecimals(m_properties[name+".PeakCentre"], NUM_DECIMALS); m_dblManager->setDecimals(m_properties[name+".FWHM"], NUM_DECIMALS); m_dblManager->setValue(m_properties[name+".FWHM"], 0.02); + lorentzGroup->addSubProperty(m_properties[name+".Amplitude"]); lorentzGroup->addSubProperty(m_properties[name+".PeakCentre"]); lorentzGroup->addSubProperty(m_properties[name+".FWHM"]); + return lorentzGroup; } + QtProperty* ConvFit::createDiffSphere(const QString & name) + { + QtProperty* diffSphereGroup = m_grpManager->addProperty(name); + + m_properties[name+".Intensity"] = m_dblManager->addProperty("Intensity"); + m_properties[name+".Radius"] = m_dblManager->addProperty("Radius"); + m_properties[name+".Diffusion"] = m_dblManager->addProperty("Diffusion"); + /* m_properties[name+".Shift"] = m_dblManager->addProperty("Shift"); */ + + m_dblManager->setDecimals(m_properties[name+".Intensity"], NUM_DECIMALS); + m_dblManager->setDecimals(m_properties[name+".Radius"], NUM_DECIMALS); + m_dblManager->setDecimals(m_properties[name+".Diffusion"], NUM_DECIMALS); + /* m_dblManager->setDecimals(m_properties[name+".Shift"], NUM_DECIMALS); */ + + diffSphereGroup->addSubProperty(m_properties[name+".Intensity"]); + diffSphereGroup->addSubProperty(m_properties[name+".Radius"]); + diffSphereGroup->addSubProperty(m_properties[name+".Diffusion"]); + /* diffSphereGroup->addSubProperty(m_properties[name+".Shift"]); */ + + return diffSphereGroup; + } + void ConvFit::populateFunction(IFunction_sptr func, IFunction_sptr comp, QtProperty* group, const std::string & pref, bool tie) { // Get subproperties of group and apply them as parameters on the function object @@ -610,6 +659,8 @@ namespace IDA fitType += "1L"; break; case 2: fitType += "2L"; break; + case 3: + fitType += "DS"; break; } return fitType; @@ -643,6 +694,7 @@ namespace IDA { m_cfTree->removeProperty(m_properties["Lorentzian1"]); m_cfTree->removeProperty(m_properties["Lorentzian2"]); + m_cfTree->removeProperty(m_properties["DiffSphere"]); auto hwhmRangeSelector = m_uiForm.ppPlot->getRangeSelector("ConvFitHWHM"); @@ -660,6 +712,10 @@ namespace IDA m_cfTree->addProperty(m_properties["Lorentzian2"]); hwhmRangeSelector->setVisible(true); break; + case 3: + m_cfTree->addProperty(m_properties["DiffSphere"]); + hwhmRangeSelector->setVisible(false); + break; } } @@ -853,7 +909,7 @@ namespace IDA m_dblManager->setValue(m_properties["BGA0"], parameters["f0.A0"]); m_dblManager->setValue(m_properties["BGA1"], parameters["f0.A1"]); - int noLorentz = m_uiForm.cbFitType->currentIndex(); + int fitTypeIndex = m_uiForm.cbFitType->currentIndex(); int funcIndex = 0; int subIndex = 0; @@ -866,7 +922,10 @@ namespace IDA } bool usingDeltaFunc = m_blnManager->value(m_properties["UseDeltaFunc"]); - bool usingCompositeFunc = ((usingDeltaFunc && noLorentz > 0) || noLorentz > 1); + + // If using a delta function with any fit type or using two Lorentzians + bool usingCompositeFunc = ((usingDeltaFunc && fitTypeIndex > 0) || fitTypeIndex == 2); + QString prefBase = "f1.f1."; if ( usingDeltaFunc ) @@ -883,7 +942,7 @@ namespace IDA funcIndex++; } - if ( noLorentz > 0 ) + if ( fitTypeIndex == 1 || fitTypeIndex == 2 ) { // One Lorentz QString pref = prefBase; @@ -903,7 +962,7 @@ namespace IDA funcIndex++; } - if ( noLorentz > 1 ) + if ( fitTypeIndex == 2 ) { // Two Lorentz QString pref = prefBase; @@ -914,6 +973,26 @@ namespace IDA m_dblManager->setValue(m_properties["Lorentzian 2.FWHM"], parameters[pref+"FWHM"]); } + if ( fitTypeIndex == 3 ) + { + // DiffSphere + QString pref = prefBase; + + if ( usingCompositeFunc ) + { + pref += "f" + QString::number(funcIndex) + ".f" + QString::number(subIndex) + "."; + } + else + { + pref += "f" + QString::number(subIndex) + "."; + } + + m_dblManager->setValue(m_properties["Diffusion Sphere.Intensity"], parameters[pref+"Intensity"]); + m_dblManager->setValue(m_properties["Diffusion Sphere.Radius"], parameters[pref+"Radius"]); + m_dblManager->setValue(m_properties["Diffusion Sphere.Diffusion"], parameters[pref+"Diffusion"]); + /* m_dblManager->setValue(m_properties["Diffusion Sphere.Shift"], parameters[pref+"Shift"]); */ + } + m_pythonExportWsName = ""; } diff --git a/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py b/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py index 54e34ca44457893d7b7090a436bc0127c658a5c8..00f8e10573b9fb1160b44e5d65061c8c30861af7 100644 --- a/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py +++ b/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py @@ -48,7 +48,6 @@ def calculateEISF(params_table): mtd[params_table].setCell(col_name, i, value) mtd[params_table].setCell(error_col_name, i, error) -############################################################################## def confitSeq(inputWS, func, startX, endX, ftype, bgd, temperature=None, specMin=0, specMax=None, convolve=True, Plot='None', Save=False): StartTime('ConvFit') @@ -112,13 +111,6 @@ def confitSeq(inputWS, func, startX, endX, ftype, bgd, temperature=None, specMin CopyLogs(InputWorkspace=wsname, OutputWorkspace=output_workspace + "_Workspaces") - temp_correction = temperature is not None - AddSampleLog(Workspace=wsname, LogName='temperature_correction', - LogType='String', LogText=str(temp_correction)) - if temp_correction: - AddSampleLog(Workspace=wsname, LogName='temperature_value', - LogType='String', LogText=str(temperature)) - RenameWorkspace(InputWorkspace=output_workspace, OutputWorkspace=output_workspace + "_Parameters") fit_workspaces = mtd[output_workspace + '_Workspaces'].getNames() @@ -140,6 +132,7 @@ def confitSeq(inputWS, func, startX, endX, ftype, bgd, temperature=None, specMin EndTime('ConvFit') + ############################################################################## # FuryFit ##############################################################################