Ejemplo n.º 1
0
void ALCBaselineModellingModel::fit(IFunction_const_sptr function,
                                    const std::vector<Section> &sections) {
  // Create a copy of the data
  IAlgorithm_sptr clone = AlgorithmManager::Instance().create("CloneWorkspace");
  clone->setChild(true);
  clone->setProperty("InputWorkspace",
                     boost::const_pointer_cast<MatrixWorkspace>(m_data));
  clone->setProperty("OutputWorkspace", "__NotUsed__");
  clone->execute();

  Workspace_sptr cloned = clone->getProperty("OutputWorkspace");
  MatrixWorkspace_sptr dataToFit =
      boost::dynamic_pointer_cast<MatrixWorkspace>(cloned);
  assert(dataToFit); // CloneWorkspace should take care of that

  disableUnwantedPoints(dataToFit, sections);

  IFunction_sptr funcToFit =
      FunctionFactory::Instance().createInitialized(function->asString());

  IAlgorithm_sptr fit = AlgorithmManager::Instance().create("Fit");
  fit->setChild(true);
  fit->setProperty("Function", funcToFit);
  fit->setProperty("InputWorkspace", dataToFit);
  fit->setProperty("CreateOutput", true);

  // Run async so that progress can be shown
  Poco::ActiveResult<bool> result(fit->executeAsync());
  while (!result.available()) {
    QCoreApplication::processEvents();
  }
  if (!result.error().empty()) {
    throw std::runtime_error(result.error());
  }

  MatrixWorkspace_sptr fitOutput = fit->getProperty("OutputWorkspace");
  m_parameterTable = fit->getProperty("OutputParameters");

  enableDisabledPoints(fitOutput, m_data);
  setErrorsAfterFit(fitOutput);

  setCorrectedData(fitOutput);
  setFittedFunction(funcToFit);
  m_sections = sections;
}
Ejemplo n.º 2
0
  void ALCBaselineModellingModel::fit(IFunction_const_sptr function, const std::vector<Section>& sections)
  {
    // Create a copy of the data
    IAlgorithm_sptr clone = AlgorithmManager::Instance().create("CloneWorkspace");
    clone->setChild(true);
    clone->setProperty("InputWorkspace", boost::const_pointer_cast<MatrixWorkspace>(m_data));
    clone->setProperty("OutputWorkspace", "__NotUsed__");
    clone->execute();

    Workspace_sptr cloned = clone->getProperty("OutputWorkspace");
    MatrixWorkspace_sptr dataToFit = boost::dynamic_pointer_cast<MatrixWorkspace>(cloned);
    assert(dataToFit); // CloneWorkspace should take care of that

    disableUnwantedPoints(dataToFit, sections);

    IFunction_sptr funcToFit =
        FunctionFactory::Instance().createInitialized(function->asString());

    IAlgorithm_sptr fit = AlgorithmManager::Instance().create("Fit");
    fit->setChild(true);
    fit->setProperty("Function", funcToFit);
    fit->setProperty("InputWorkspace", dataToFit);
    fit->setProperty("CreateOutput", true);
    fit->execute();

    MatrixWorkspace_sptr fitOutput = fit->getProperty("OutputWorkspace");
    m_parameterTable = fit->getProperty("OutputParameters");

    enableDisabledPoints(fitOutput,m_data);
    setErrorsAfterFit(fitOutput);

    setCorrectedData(fitOutput);
    setFittedFunction(funcToFit);
    m_sections = sections;

  }