Esempio n. 1
0
void EnggDiffFittingModel::convertFromDistribution(
    Mantid::API::MatrixWorkspace_sptr inputWS) {
  const auto name = inputWS->getName();
  auto convertFromDistAlg = Mantid::API::AlgorithmManager::Instance().create(
      "ConvertFromDistribution");
  convertFromDistAlg->initialize();
  convertFromDistAlg->setProperty("Workspace", inputWS);
  convertFromDistAlg->execute();
}
void IndirectFitAnalysisTab::plotSpectrum(
    Mantid::API::MatrixWorkspace_sptr workspace,
    const std::string &parameterToPlot) {
  const auto name = QString::fromStdString(workspace->getName());
  const auto labels = IndirectTab::extractAxisLabels(workspace, 1);
  for (const auto &parameter : m_fittingModel->getFitParameterNames()) {
    if (boost::contains(parameter, parameterToPlot)) {
      auto it = labels.find(parameter);
      if (it != labels.end())
        IndirectTab::plotSpectrum(name, static_cast<int>(it->second));
    }
  }
}
Esempio n. 3
0
    /** Method takes min-max values from algorithm parameters if they are present or calculates default min-max values if these values 
     *  were not supplied to the method or the supplied value is incorrect.
     *
    *@param inWS     -- the shared pointer to the source workspace
    *@param QMode    -- the string which defines algorithms Q-conversion mode
    *@param dEMode   -- the string describes the algorithms energy conversion mode
    *@param QFrame   -- in Q3D case this describes target coordinate system and is ignored in any other caste
    *@param ConvertTo -- The parameter describing Q-scaling transformations 
    *@param otherDim -- the vector of other dimension names (if any)
    *  Input-output values: 
    *@param minVal   -- the vector with min values for the algorithm
    *@param maxVal   -- the vector with max values for the algorithm
    *
    *
    */
    void ConvertToMD::findMinMax(const Mantid::API::MatrixWorkspace_sptr &inWS,const std::string &QMode, const std::string &dEMode,
      const std::string &QFrame,const std::string &ConvertTo,const std::vector<std::string> &otherDim,
      std::vector<double> &minVal,std::vector<double> &maxVal)
    {

      // get raw pointer to Q-transformation (do not delete this pointer, it hold by MDTransfFatctory!)
      MDTransfInterface* pQtransf =  MDTransfFactory::Instance().create(QMode).get();
      // get number of dimensions this Q transformation generates from the workspace. 
      auto iEmode = Kernel::DeltaEMode().fromString(dEMode);
      // get total number of dimensions the workspace would have.
      unsigned int nMatrixDim = pQtransf->getNMatrixDimensions(iEmode,inWS);
      // total number of dimensions
      size_t nDim =nMatrixDim+otherDim.size();

      // probably already have well defined min-max values, so no point of pre-calculating them
      bool wellDefined(true);
      if((nDim == minVal.size()) && (minVal.size()==maxVal.size()))
      {
        // are they indeed well defined?
        for(size_t i=0;i<minVal.size();i++)
        {
          if(minVal[i]>=maxVal[i]) // no it is ill defined
          {
            g_log.information()<<" Min Value: "<<minVal[i]<<" for dimension N: "<<i<<" equal or exceeds max value:"<<maxVal[i]<<std::endl;
            wellDefined = false;
            break;
          }
        }
        if (wellDefined)return;
      }

      // we need to identify min-max values by themselves

      Mantid::API::Algorithm_sptr childAlg = createChildAlgorithm("ConvertToMDMinMaxLocal");
      if(!childAlg)throw(std::runtime_error("Can not create child ChildAlgorithm to found min/max values"));

      childAlg->setPropertyValue("InputWorkspace", inWS->getName());
      childAlg->setPropertyValue("QDimensions",QMode);
      childAlg->setPropertyValue("dEAnalysisMode",dEMode);
      childAlg->setPropertyValue("Q3DFrames",QFrame);
      childAlg->setProperty("OtherDimensions",otherDim);
      childAlg->setProperty("QConversionScales",ConvertTo);
      childAlg->setProperty("PreprocDetectorsWS",std::string(getProperty("PreprocDetectorsWS")));
      childAlg->execute();
      if(!childAlg->isExecuted())throw(std::runtime_error("Can not properly execute child algorithm to find min/max workspace values"));

      minVal = childAlg->getProperty("MinValues");
      maxVal = childAlg->getProperty("MaxValues");

      // if some min-max values for dimensions produce ws with 0 width in this direction, change it to have some width;
      for(unsigned int i=0;i<nDim;i++)
      {
        if(minVal[i]>=maxVal[i])
        {
          g_log.debug()<<"identified min-max values for dimension N: "<<i<<" are equal. Modifying min-max value to produce dimension with 0.2*dimValue width\n";
          if(minVal[i]>0)
          {
            minVal[i]*=0.9;
            maxVal[i]*=1.1;
          }
          else if(minVal[i]==0)
          {
            minVal[i]=-0.1;
            maxVal[i]=0.1;
          }
          else
          {
            minVal[i]*=1.1;
            maxVal[i]*=0.9;

          }
        }
        else // expand min-max values a bit to avoid cutting data on the edges
        {
          if (std::fabs(minVal[i])>FLT_EPSILON)
            minVal[i]*=(1+2*FLT_EPSILON);
          else
            minVal[i]-=2*FLT_EPSILON;
          if (std::fabs(minVal[i])>FLT_EPSILON)
            maxVal[i]*=(1+2*FLT_EPSILON);
          else
            minVal[i]+=2*FLT_EPSILON;
        }
      }

      if(!wellDefined) return;

      // if only min or only max limits are defined and are well defined workspace, the algorithm will use these limits
      std::vector<double> minAlgValues = this->getProperty("MinValues");
      std::vector<double> maxAlgValues = this->getProperty("MaxValues");
      bool allMinDefined = (minAlgValues.size()==nDim);
      bool allMaxDefined = (maxAlgValues.size()==nDim);
      if(allMinDefined || allMaxDefined)
      {
        for(size_t i=0;i<nDim;i++)
        {
          if (allMinDefined)  minVal[i] = minAlgValues[i];
          if (allMaxDefined)  maxVal[i] = maxAlgValues[i];
        }

      }


    }
void IndirectFitAnalysisTab::plotSpectrum(
    Mantid::API::MatrixWorkspace_sptr workspace) {
  const auto name = QString::fromStdString(workspace->getName());
  for (auto i = 0u; i < workspace->getNumberHistograms(); ++i)
    IndirectTab::plotSpectrum(name, static_cast<int>(i));
}