/** handle the input parameters and build target workspace description as function of input parameters * @param spws shared pointer to target MD workspace (just created or already existing) * @param QModReq -- mode to convert momentum * @param dEModReq -- mode to convert energy * @param otherDimNames -- the vector of additional dimensions names (if any) * @param dimMin -- the vector of minimal values for all dimensions of the workspace; on input it is copied from the algorithm parameters, on output it is defined from MD workspace of matrix workspace depending on how well input parameters are defined * @param dimMax -- the vector of maximal values for all dimensions of the workspace; is set up similarly to dimMin * @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 targWSDescr -- the resulting class used to interpret all parameters together and used to describe selected transformation. */ bool ConvertToMD::buildTargetWSDescription(API::IMDEventWorkspace_sptr spws,const std::string &QModReq,const std::string &dEModReq,const std::vector<std::string> &otherDimNames, std::vector<double> &dimMin, std::vector<double> &dimMax, const std::string &QFrame,const std::string &convertTo_,MDEvents::MDWSDescription &targWSDescr) { // ------- Is there need to create new output workspace? bool createNewTargetWs =doWeNeedNewTargetWorkspace(spws); if (createNewTargetWs ) { targWSDescr.m_buildingNewWorkspace = true; // find min-max dimensions values -- either take them from input parameters or identify the defaults if input parameters are not defined this->findMinMax(m_InWS2D,QModReq,dEModReq,QFrame,convertTo_,otherDimNames,dimMin,dimMax); } else // get min/max from existing MD workspace ignoring input min/max values { targWSDescr.m_buildingNewWorkspace = false; size_t NDims = spws->getNumDims(); dimMin.resize(NDims); dimMax.resize(NDims); for(size_t i=0;i<NDims;i++) { const Geometry::IMDDimension *pDim = spws->getDimension(i).get(); dimMin[i] = pDim->getMinimum(); dimMax[i] = pDim->getMaximum(); } } // verify that the number min/max values is equivalent to the number of dimensions defined by properties and min is less max targWSDescr.setMinMax(dimMin,dimMax); targWSDescr.buildFromMatrixWS(m_InWS2D,QModReq,dEModReq,otherDimNames); bool LorentzCorrections = getProperty("LorentzCorrection"); targWSDescr.setLorentsCorr(LorentzCorrections); // instantiate class, responsible for defining Mslice-type projection MDEvents::MDWSTransform MsliceProj; //identify if u,v are present among input parameters and use defaults if not std::vector<double> ut = getProperty("UProj"); std::vector<double> vt = getProperty("VProj"); std::vector<double> wt = getProperty("WProj"); try { // otherwise input uv are ignored -> later it can be modified to set ub matrix if no given, but this may over-complicate things. MsliceProj.setUVvectors(ut,vt,wt); } catch(std::invalid_argument &) { g_log.error() << "The projections are coplanar. Will use defaults [1,0,0],[0,1,0] and [0,0,1]" << std::endl; } if(createNewTargetWs) { // check if we are working in powder mode // set up target coordinate system and identify/set the (multi) dimension's names to use targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr,QFrame,convertTo_); } else // user input is mainly ignored and everything is in old MD workspace { // dimensions are already build, so build MDWS description from existing workspace MDEvents::MDWSDescription oldWSDescr; oldWSDescr.buildFromMDWS(spws); // some conversion parameters can not be defined by the target workspace. They have to be retrieved from the input workspace // and derived from input parameters. oldWSDescr.setUpMissingParameters(targWSDescr); // set up target coordinate system and the dimension names/units oldWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(oldWSDescr,QFrame,convertTo_); // check inconsistencies, if the existing workspace can be used as target workspace. oldWSDescr.checkWSCorresponsMDWorkspace(targWSDescr); // reset new ws description name targWSDescr =oldWSDescr; } return createNewTargetWs; }
/** handle the input parameters and build target workspace description as function of input parameters * @param spws shared pointer to target MD workspace (just created or already existing) * @param QModReq -- mode to convert momentum * @param dEModReq -- mode to convert energy * @param otherDimNames -- the vector of additional dimensions names (if any) * @param dimMin -- the vector of minimal values for all dimensions of the workspace; on input it is copied from the algorithm parameters, on output it is defined from MD workspace of matrix workspace depending on how well input parameters are defined * @param dimMax -- the vector of maximal values for all dimensions of the workspace; is set up similarly to dimMin * @param QFrame -- in Q3D case this describes target coordinate system and is ignored in any other case * @param convertTo_ -- The parameter describing Q-scaling transformations * @param targWSDescr -- the resulting class used to interpret all parameters together and used to describe selected transformation. */ bool ConvertToMD::buildTargetWSDescription( API::IMDEventWorkspace_sptr spws, const std::string &QModReq, const std::string &dEModReq, const std::vector<std::string> &otherDimNames, std::vector<double> &dimMin, std::vector<double> &dimMax, const std::string &QFrame, const std::string &convertTo_, MDAlgorithms::MDWSDescription &targWSDescr) { // ------- Is there need to create new output workspace? bool createNewTargetWs = doWeNeedNewTargetWorkspace(spws); std::vector<int> split_into; if (createNewTargetWs) { targWSDescr.m_buildingNewWorkspace = true; // find min-max dimensions values -- either take them from input parameters // or identify the defaults if input parameters are not defined this->findMinMax(m_InWS2D, QModReq, dEModReq, QFrame, convertTo_, otherDimNames, dimMin, dimMax); // set number of bins each dimension split into. split_into = this->getProperty("SplitInto"); } else // get min/max from existing MD workspace ignoring input min/max values { targWSDescr.m_buildingNewWorkspace = false; size_t NDims = spws->getNumDims(); dimMin.resize(NDims); dimMax.resize(NDims); split_into.resize(NDims); for (size_t i = 0; i < NDims; i++) { const Geometry::IMDDimension *pDim = spws->getDimension(i).get(); dimMin[i] = pDim->getMinimum(); dimMax[i] = pDim->getMaximum(); // number of dimension split_into[i] = static_cast<int>(pDim->getNBins()); } } // verify that the number min/max values is equivalent to the number of // dimensions defined by properties and min is less max targWSDescr.setMinMax(dimMin, dimMax); targWSDescr.buildFromMatrixWS(m_InWS2D, QModReq, dEModReq, otherDimNames); targWSDescr.setNumBins(split_into); bool LorentzCorrections = getProperty("LorentzCorrection"); targWSDescr.setLorentsCorr(LorentzCorrections); double m_AbsMin = getProperty("AbsMinQ"); targWSDescr.setAbsMin(m_AbsMin); // Set optional projections for Q3D mode MDAlgorithms::MDWSTransform MsliceProj; if (QModReq == MDTransfQ3D().transfID()) { try { // otherwise input uv are ignored -> later it can be modified to set ub // matrix if no given, but this may over-complicate things. MsliceProj.setUVvectors(getProperty("UProj"), getProperty("VProj"), getProperty("WProj")); } catch (std::invalid_argument &) { g_log.warning() << "The projections are coplanar. Will use defaults " "[1,0,0],[0,1,0] and [0,0,1]\n"; } } else { auto warnIfSet = [this](const std::string &propName) { Property *prop = this->getProperty(propName); if (!prop->isDefault()) { g_log.warning(propName + " value ignored with QDimensions != " + MDTransfQ3D().transfID()); } }; for (const auto &name : {"UProj", "VProj", "WProj"}) { warnIfSet(name); } } if (createNewTargetWs) { // check if we are working in powder mode // set up target coordinate system and identify/set the (multi) dimension's // names to use targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr, QFrame, convertTo_); } else // user input is mainly ignored and everything is in old MD workspace { // dimensions are already build, so build MDWS description from existing // workspace MDAlgorithms::MDWSDescription oldWSDescr; oldWSDescr.buildFromMDWS(spws); // some conversion parameters can not be defined by the target workspace. // They have to be retrieved from the input workspace // and derived from input parameters. oldWSDescr.setUpMissingParameters(targWSDescr); // set up target coordinate system and the dimension names/units oldWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(oldWSDescr, QFrame, convertTo_); // check inconsistencies, if the existing workspace can be used as target // workspace. oldWSDescr.checkWSCorresponsMDWorkspace(targWSDescr); // reset new ws description name targWSDescr = oldWSDescr; } return createNewTargetWs; }