Пример #1
0
    DataObjects::TableWorkspace_sptr  ConvertToMDParent::runPreprocessDetectorsToMDChildUpdatingMasks(Mantid::API::MatrixWorkspace_const_sptr InWS2D,
      const std::string &OutWSName,const std::string &dEModeRequested,Kernel::DeltaEMode::Type &Emode)
    {
      // prospective result
      DataObjects::TableWorkspace_sptr TargTableWS;

      // if input workspace does not exist in analysis data service, we have to add it there to work with the Child Algorithm 
      std::string InWSName = InWS2D->getName();
      if(!API::AnalysisDataService::Instance().doesExist(InWSName))
      {
        throw std::runtime_error("Can not retrieve input matrix workspace "+InWSName+" from the analysis data service");
      }

      Mantid::API::Algorithm_sptr childAlg = createChildAlgorithm("PreprocessDetectorsToMD",0.,1.);
      if(!childAlg)throw(std::runtime_error("Can not create child ChildAlgorithm to preprocess detectors"));
      childAlg->setProperty("InputWorkspace",InWSName);
      childAlg->setProperty("OutputWorkspace",OutWSName);
      childAlg->setProperty("GetMaskState",true);
      childAlg->setProperty("UpdateMasksInfo",true);
      childAlg->setProperty("OutputWorkspace",OutWSName);

      // check and get energy conversion mode to define additional ChildAlgorithm parameters
      Emode = Kernel::DeltaEMode().fromString(dEModeRequested);
      if(Emode == Kernel::DeltaEMode::Indirect) 
        childAlg->setProperty("GetEFixed",true); 


      childAlg->execute();
      if(!childAlg->isExecuted())throw(std::runtime_error("Can not properly execute child algorithm PreprocessDetectorsToMD"));

      TargTableWS = childAlg->getProperty("OutputWorkspace");
      if(!TargTableWS)throw(std::runtime_error("Can not retrieve results of child algorithm PreprocessDetectorsToMD"));

      return TargTableWS;
    }
DataObjects::TableWorkspace_sptr
ConvertToMDParent::runPreprocessDetectorsToMDChildUpdatingMasks(
    const Mantid::API::MatrixWorkspace_const_sptr &InWS2D,
    const std::string &OutWSName, const std::string &dEModeRequested,
    Kernel::DeltaEMode::Type &Emode) {
  // prospective result
  DataObjects::TableWorkspace_sptr TargTableWS;

  Mantid::API::Algorithm_sptr childAlg =
      createChildAlgorithm("PreprocessDetectorsToMD", 0., 1.);
  if (!childAlg)
    throw(std::runtime_error(
        "Can not create child ChildAlgorithm to preprocess detectors"));

  auto pTargWSProp = dynamic_cast<WorkspaceProperty<MatrixWorkspace> *>(
      childAlg->getPointerToProperty("InputWorkspace"));
  if (!pTargWSProp) {
    throw std::runtime_error("Bad program logic: an algorithm workspace "
                             "property is not castable to a matrix workspace");
  }

  // TODO: bad unnecessary const_cast but WorkspaceProperty is missing const
  // assignment operators and I am not sure if ADS guarantees workspaces
  // const-ness
  // so, const cast is localized here despite input workspace is and should be
  // const in this case.
  *pTargWSProp = boost::const_pointer_cast<MatrixWorkspace>(InWS2D);

  childAlg->setProperty("OutputWorkspace", OutWSName);
  childAlg->setProperty("GetMaskState", true);
  childAlg->setProperty("UpdateMasksInfo", true);
  childAlg->setProperty("OutputWorkspace", OutWSName);

  // check and get energy conversion mode to define additional ChildAlgorithm
  // parameters
  Emode = Kernel::DeltaEMode::fromString(dEModeRequested);
  if (Emode == Kernel::DeltaEMode::Indirect)
    childAlg->setProperty("GetEFixed", true);

  childAlg->execute();
  if (!childAlg->isExecuted())
    throw(std::runtime_error(
        "Can not properly execute child algorithm PreprocessDetectorsToMD"));

  TargTableWS = childAlg->getProperty("OutputWorkspace");
  if (!TargTableWS)
    throw(std::runtime_error(
        "Can not retrieve results of child algorithm PreprocessDetectorsToMD"));

  return TargTableWS;
}
Пример #3
0
  /**
   * @brief IntegrateEllipsoids::initTargetWSDescr Initialize the output 
   *        information for the MD conversion framework.
   *
   * @param wksp The workspace to get information from.
   */
  void IntegrateEllipsoids::initTargetWSDescr(EventWorkspace_sptr wksp)
  {
    m_targWSDescr.setMinMax( std::vector<double>(3, -2000.),
                             std::vector<double>(3, 2000.));
    m_targWSDescr.buildFromMatrixWS(wksp, Q3D, ELASTIC);
    m_targWSDescr.setLorentsCorr(false);

    // generate the detectors table
    Mantid::API::Algorithm_sptr childAlg = createChildAlgorithm("PreprocessDetectorsToMD",0.,.5);
    childAlg->setProperty("InputWorkspace",wksp);
    childAlg->executeAsChildAlg();

    DataObjects::TableWorkspace_sptr table = childAlg->getProperty("OutputWorkspace");
    if(!table)
      throw(std::runtime_error("Can not retrieve results of \"PreprocessDetectorsToMD\""));
    else
      m_targWSDescr.m_PreprDetTable = table;
  }
Пример #4
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];
        }

      }


    }
Пример #5
0
 void C2ETab::runAlgorithm(const Mantid::API::Algorithm_sptr algorithm)
 {
   algorithm->setRethrows(true);
   m_algRunner->startAlgorithm(algorithm);
 }
  /** Execute the algorithm.   */
  void ConvertToDiffractionMDWorkspace2::exec()
  {
         


    Mantid::API::Algorithm_sptr Convert = createChildAlgorithm("ConvertToMD",0.,1.);
    Convert->initialize();
   
    Convert->setRethrows(true);
    Convert->initialize();

    Convert->setProperty<MatrixWorkspace_sptr>("InputWorkspace",this->getProperty("InputWorkspace"));
    Convert->setProperty("OutputWorkspace",this->getPropertyValue("OutputWorkspace"));
    Convert->setProperty("OverwriteExisting",!this->getProperty("Append"));


     if(!MDEvents::MDTransfFactory::Instance().exists("Q3D"))
     {
         throw std::runtime_error(" ConvertToMD Q3D plugin used to transform into DiffractionWorkspaced has not been registered with the MDTransformation factory");
     }
     Convert->setPropertyValue("QDimensions","Q3D");

     std::vector<std::string> dE_modes = Kernel::DeltaEMode().availableTypes();
     Convert->setPropertyValue("dEAnalysisMode",dE_modes[Kernel::DeltaEMode::Elastic]);

     std::string TargetFrame,Scaling;
     this->convertFramePropertyNames(this->getPropertyValue("OutputDimensions"),TargetFrame,Scaling);
     Convert->setProperty("Q3DFrames",TargetFrame);
     Convert->setProperty("QConversionScales",Scaling);

     Convert->setProperty("OtherDimensions","");
     Convert->setProperty("PreprocDetectorsWS","-"); 

     bool lorCorr = this->getProperty("LorentzCorrection");
     Convert->setProperty("LorentzCorrection",lorCorr);

     bool ignoreZeros = !this->getProperty("OneEventPerBin");
     Convert->setProperty("IgnoreZeroSignals",ignoreZeros);
     //set extents
     std::vector<double> extents = this->getProperty("Extents");
     std::vector<double> minVal,maxVal;
     convertExtents(extents,minVal,maxVal);
     Convert->setProperty("MinValues",minVal);
     Convert->setProperty("MaxValues",maxVal);


   // Box controller properties. Has defaults
      Convert->setProperty("SplitInto",this->getPropertyValue("SplitInto"));
      Convert->setProperty("SplitThreshold",this->getPropertyValue("SplitThreshold"));
      Convert->setProperty("MaxRecursionDepth",this->getPropertyValue("MaxRecursionDepth"));
      std::string depth = this->getPropertyValue("MinRecursionDepth");
      if(depth == "0") depth = "1";  // ConvertToMD does not understand 0 depth
      Convert->setProperty("MinRecursionDepth",depth);

      Convert->executeAsChildAlg();

      IMDEventWorkspace_sptr iOut = Convert->getProperty("OutputWorkspace");
      this->setProperty("OutputWorkspace",iOut);

      
  }