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; }
/** 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]; } } }