diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h b/Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h index 2ba5838baabb..e802451adcac 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h @@ -9,7 +9,6 @@ #include "MantidAPI/IBoxControllerIO.h" #include #include -#include #include diff --git a/Code/Mantid/Framework/API/src/IMDEventWorkspace.cpp b/Code/Mantid/Framework/API/src/IMDEventWorkspace.cpp index 6b4364e85a63..9e2bb2a7e3a3 100644 --- a/Code/Mantid/Framework/API/src/IMDEventWorkspace.cpp +++ b/Code/Mantid/Framework/API/src/IMDEventWorkspace.cpp @@ -22,7 +22,8 @@ namespace API /** Copy constructor */ IMDEventWorkspace::IMDEventWorkspace(const IMDEventWorkspace & other) : IMDWorkspace(other), - MultipleExperimentInfos(other) + MultipleExperimentInfos(other), + m_fileNeedsUpdating(other.m_fileNeedsUpdating) { } diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h index 20915ba10415..a4a0fa377784 100644 --- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h @@ -48,7 +48,7 @@ namespace Mantid { public: /// Default constructor - Divide() : BinaryOperation() {}; + Divide() : BinaryOperation(),m_warnOnZeroDivide(true){}; /// Destructor virtual ~Divide() {}; /// Algorithm's name for identification overriding a virtual method @@ -81,7 +81,7 @@ namespace Mantid void checkRequirements(); std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const; - + // usually you want to warn user if division by 0 occurs. set it to false to generate these warnings on debug level only bool m_warnOnZeroDivide; }; diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/CalculateGammaBackground.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/CalculateGammaBackground.h index 52e0affe6af1..6556da2145e5 100644 --- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/CalculateGammaBackground.h +++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/CalculateGammaBackground.h @@ -118,6 +118,8 @@ namespace Mantid /// Pointer to progress reporting API::Progress *m_progress; + // internal method called within the loop to avoid true-catch operations which broke Microsoft compiler compiling in parallel + bool calculateBackground(size_t inputIndex, size_t ouptutIndex); }; diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ConvertToYSpace.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ConvertToYSpace.h index b824b1c9164c..2086143a1e3e 100644 --- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ConvertToYSpace.h +++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ConvertToYSpace.h @@ -71,7 +71,7 @@ namespace CurveFitting void exec(); /// Perform the conversion to Y-space - void convert(const size_t i); + bool convert(const size_t i); /// Check and store appropriate input data void retrieveInputs(); /// Create the output workspace diff --git a/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp b/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp index 476351540920..746927c38295 100644 --- a/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp +++ b/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp @@ -50,7 +50,7 @@ namespace Mantid specid_t FORWARD_SCATTER_SPECMIN = 135; /// End of forward scattering spectrum numbers (inclusive) specid_t FORWARD_SCATTER_SPECMAX = 198; - } + } //-------------------------------------------------------------------------------------------------------- // Public members @@ -59,8 +59,8 @@ namespace Mantid /// Default constructor CalculateGammaBackground::CalculateGammaBackground() : Algorithm(), m_inputWS(), m_indices(), m_profileFunction(), m_npeaks(0), m_reversed(), - m_samplePos(), m_l1(0.0), m_foilRadius(0.0), m_foilUpMin(0.0),m_foilUpMax(0.0), m_foils0(), m_foils1(), - m_backgroundWS(), m_correctedWS(), m_progress(NULL) + m_samplePos(), m_l1(0.0), m_foilRadius(0.0), m_foilUpMin(0.0),m_foilUpMax(0.0), m_foils0(), m_foils1(), + m_backgroundWS(), m_correctedWS(), m_progress(NULL) { } @@ -95,6 +95,40 @@ namespace Mantid this->setOptionalMessage("Calculates the background due to gamma rays produced when neutrons are absorbed by shielding."); } + bool inline CalculateGammaBackground::calculateBackground(size_t inputIndex,size_t outputIndex) + { + m_backgroundWS->setX(outputIndex,m_inputWS->refX(inputIndex)); + m_correctedWS->setX(outputIndex,m_inputWS->refX(inputIndex)); + try + { + const auto * inSpec = m_inputWS->getSpectrum(inputIndex); + const specid_t spectrumNo(inSpec->getSpectrumNo()); + m_backgroundWS->getSpectrum(outputIndex)->copyInfoFrom(*inSpec); + m_correctedWS->getSpectrum(outputIndex)->copyInfoFrom(*inSpec); + + if(spectrumNo >= FORWARD_SCATTER_SPECMIN && spectrumNo <= FORWARD_SCATTER_SPECMAX ) + { + applyCorrection(inputIndex,outputIndex); + } + else + { + + g_log.information("Spectrum " + boost::lexical_cast(spectrumNo) + " not in forward scatter range. Skipping correction."); + // Leave background at 0 and just copy data to corrected + m_correctedWS->dataY(outputIndex) = m_inputWS->readY(inputIndex); + + } + return true; + } + catch(Exception::NotFoundError &) + { + return false; + } + + + + } + void CalculateGammaBackground::init() { @@ -102,12 +136,12 @@ namespace Mantid wsValidator->add("TOF"); wsValidator->add(false); // point data declareProperty(new WorkspaceProperty<>("InputWorkspace", "", Direction::Input, - wsValidator), - "An input workspace containing TOF data"); + wsValidator), + "An input workspace containing TOF data"); declareProperty(new API::FunctionProperty("ComptonFunction"), - "Function that is able to compute the mass spectrum for the input data" - "This will usually be the output from the Fitting"); + "Function that is able to compute the mass spectrum for the input data" + "This will usually be the output from the Fitting"); declareProperty(new ArrayProperty("WorkspaceIndexList"), "Indices of the spectra to include in the correction. If provided, the output only include these spectra\n" @@ -127,55 +161,35 @@ namespace Mantid m_progress = new Progress(this, 0.0, 1.0, nreports); PARALLEL_FOR3(m_inputWS, m_correctedWS, m_backgroundWS) - for(int64_t i = 0; i < nhist; ++i) - { - PARALLEL_START_INTERUPT_REGION - - const size_t outputIndex = i; - auto indexIter = m_indices.cbegin(); - std::advance(indexIter, i); - const size_t inputIndex = indexIter->second; - - m_backgroundWS->setX(outputIndex,m_inputWS->refX(inputIndex)); - m_correctedWS->setX(outputIndex,m_inputWS->refX(inputIndex)); - try + for(int64_t i = 0; i < nhist; ++i) { - const auto * inSpec = m_inputWS->getSpectrum(inputIndex); - const specid_t spectrumNo(inSpec->getSpectrumNo()); - m_backgroundWS->getSpectrum(outputIndex)->copyInfoFrom(*inSpec); - m_correctedWS->getSpectrum(outputIndex)->copyInfoFrom(*inSpec); + PARALLEL_START_INTERUPT_REGION + const size_t outputIndex = i; + auto indexIter = m_indices.cbegin(); + std::advance(indexIter, i); + const size_t inputIndex = indexIter->second; - if(spectrumNo >= FORWARD_SCATTER_SPECMIN && spectrumNo <= FORWARD_SCATTER_SPECMAX ) - { - applyCorrection(inputIndex,outputIndex); - } - else + + if (!calculateBackground(inputIndex,outputIndex)) { - g_log.information("Spectrum " + boost::lexical_cast(spectrumNo) + " not in forward scatter range. Skipping correction."); - // Leave background at 0 and just copy data to corrected - m_correctedWS->dataY(outputIndex) = m_inputWS->readY(inputIndex); + g_log.information("No detector defined for index=" + boost::lexical_cast(inputIndex) + ". Skipping correction."); } - } - catch(Exception::NotFoundError &) - { - g_log.information("No detector defined for index=" + boost::lexical_cast(inputIndex) + ". Skipping correction."); - } - PARALLEL_END_INTERUPT_REGION - } - PARALLEL_CHECK_INTERUPT_REGION + PARALLEL_END_INTERUPT_REGION + } + PARALLEL_CHECK_INTERUPT_REGION - setProperty("BackgroundWorkspace",m_backgroundWS); - setProperty("CorrectedWorkspace",m_correctedWS); + setProperty("BackgroundWorkspace",m_backgroundWS); + setProperty("CorrectedWorkspace",m_correctedWS); } /** - * Calculate & apply gamma correction for the given index of the - * input workspace - * @param inputIndex A workspace index that defines the input spectrum to correct - * @param outputIndex A workspace index that defines the output to hold the results - */ + * Calculate & apply gamma correction for the given index of the + * input workspace + * @param inputIndex A workspace index that defines the input spectrum to correct + * @param outputIndex A workspace index that defines the output to hold the results + */ void CalculateGammaBackground::applyCorrection(const size_t inputIndex, const size_t outputIndex) { m_progress->report("Computing TOF from detector"); @@ -210,18 +224,18 @@ namespace Mantid for(size_t j = 0; j < nbins; ++j) { - // m_backgroundWS already contains the foil values, careful not to overwrite them - double & foilValue = foilY[j]; // non-const reference - foilValue *= corrFactor; - detY[j] = (inY[j] - foilValue); + // m_backgroundWS already contains the foil values, careful not to overwrite them + double & foilValue = foilY[j]; // non-const reference + foilValue *= corrFactor; + detY[j] = (inY[j] - foilValue); } } /** - * Results are placed in the mapped index on the output corrected workspace - * @param inputIndex Workspace index that defines the input spectrum to correct - * @param outputIndex Workspace index that defines the spectrum to hold the results - */ + * Results are placed in the mapped index on the output corrected workspace + * @param inputIndex Workspace index that defines the input spectrum to correct + * @param outputIndex Workspace index that defines the spectrum to hold the results + */ void CalculateGammaBackground::calculateSpectrumFromDetector(const size_t inputIndex, const size_t outputIndex) { auto det = m_inputWS->getDetector(inputIndex); @@ -251,15 +265,15 @@ namespace Mantid //Correct for distance to the detector: 0.5/l2^2 const double detDistCorr = 0.5/detPar.l2/detPar.l2; std::transform(ctdet.begin(),ctdet.end(),ctdet.begin(), - std::bind2nd(std::multiplies(), detDistCorr)); + std::bind2nd(std::multiplies(), detDistCorr)); } /** - * Calculate & apply gamma correction for the given index of the - * input workspace - * @param inputIndex Workspace index that defines the input spectrum to correct - * @param outputIndex Workspace index that defines the spectrum to hold the results - */ + * Calculate & apply gamma correction for the given index of the + * input workspace + * @param inputIndex Workspace index that defines the input spectrum to correct + * @param outputIndex Workspace index that defines the spectrum to hold the results + */ void CalculateGammaBackground::calculateBackgroundFromFoils(const size_t inputIndex, const size_t outputIndex) { auto det = m_inputWS->getDetector(inputIndex); @@ -293,13 +307,13 @@ namespace Mantid calculateBackgroundSingleFoil(foilSpectrum, outputIndex,m_foils1[i], detPos, detPar, detRes); // sum spectrum values from first position std::transform(ctfoil.begin(), ctfoil.end(), foilSpectrum.begin(), ctfoil.begin(), - std::plus()); + std::plus()); foilSpectrum.assign(nxvalues,0.0); calculateBackgroundSingleFoil(foilSpectrum, outputIndex,m_foils0[i], detPos, detPar, detRes); // subtract spectrum values from zeroth position std::transform(ctfoil.begin(), ctfoil.end(), foilSpectrum.begin(), ctfoil.begin(), - std::minus()); + std::minus()); } bool reversed = (m_reversed.count(m_inputWS->getSpectrum(inputIndex)->getSpectrumNo()) != 0 ); // This is quicker than the if within the loop @@ -307,30 +321,30 @@ namespace Mantid { // The reversed ones should be (C0 - C1) std::transform(ctfoil.begin(), ctfoil.end(), ctfoil.begin(), - std::bind2nd(std::multiplies(),-1.0)); + std::bind2nd(std::multiplies(),-1.0)); } } /** - * Integrates over the foil area defined by the foil radius to accumulate an estimate of the counts - * resulting from this region - * @param ctfoil Output vector to hold results - * @param wsIndex Index on output background workspaces currently operating - * @param foilInfo Foil description object - * @param detPos The pre-calculated detector V3D - * @param detPar DetectorParams object that defines information on the detector associated with spectrum at wsIndex - * @param detRes ResolutionParams object that defines information on the resolution associated with spectrum at wsIndex - */ + * Integrates over the foil area defined by the foil radius to accumulate an estimate of the counts + * resulting from this region + * @param ctfoil Output vector to hold results + * @param wsIndex Index on output background workspaces currently operating + * @param foilInfo Foil description object + * @param detPos The pre-calculated detector V3D + * @param detPar DetectorParams object that defines information on the detector associated with spectrum at wsIndex + * @param detRes ResolutionParams object that defines information on the resolution associated with spectrum at wsIndex + */ void CalculateGammaBackground::calculateBackgroundSingleFoil(std::vector & ctfoil, const size_t wsIndex, - const FoilInfo & foilInfo, - const V3D & detPos, const DetectorParams & detPar, - const ResolutionParams & detRes) + const FoilInfo & foilInfo, + const V3D & detPos, const DetectorParams & detPar, + const ResolutionParams & detRes) { /** Integrates over the foils - * by dividing into 2cm^2 elements - * The integration is performed in cylindrical coordinates - */ + * by dividing into 2cm^2 elements + * The integration is performed in cylindrical coordinates + */ const double thetaStep = (foilInfo.thetaMax - foilInfo.thetaMin)/static_cast(NTHETA); const double thetaStepRad = thetaStep*DEG2RAD; @@ -379,16 +393,16 @@ namespace Mantid } /** - * Uses the compton profile functions to compute a particular mass spectrum - * @param result [Out] The value of the computed spectrum - * @param tmpWork [In] Pre-allocated working area that will be overwritten - * @param wsIndex Index on the output background workspace that gives the X values to use - * @param detpar Struct containing parameters about the detector - * @param respar Struct containing parameters about the resolution - */ + * Uses the compton profile functions to compute a particular mass spectrum + * @param result [Out] The value of the computed spectrum + * @param tmpWork [In] Pre-allocated working area that will be overwritten + * @param wsIndex Index on the output background workspace that gives the X values to use + * @param detpar Struct containing parameters about the detector + * @param respar Struct containing parameters about the resolution + */ void CalculateGammaBackground::calculateTofSpectrum(std::vector & result, std::vector &tmpWork, - const size_t wsIndex, - const DetectorParams & detpar, const ResolutionParams & respar) + const size_t wsIndex, + const DetectorParams & detpar, const ResolutionParams & respar) { assert(result.size() == tmpWork.size()); @@ -399,7 +413,7 @@ namespace Mantid // retrieveInputs ensures we will get a composite function and that each member is a ComptonProfile // we can't static_cast though due to the virtual inheritance with IFunction auto profileFunction = \ - boost::dynamic_pointer_cast(FunctionFactory::Instance().createInitialized(m_profileFunction)); + boost::dynamic_pointer_cast(FunctionFactory::Instance().createInitialized(m_profileFunction)); for(size_t i = 0; i < m_npeaks; ++i) { @@ -412,7 +426,7 @@ namespace Mantid profile->massProfile(tmpWork.data(), tmpWork.size()); // Add to final result std::transform(result.begin(), result.end(), tmpWork.begin(), result.begin(), - std::plus()); + std::plus()); m_progress->report(); } // Put X back microseconds @@ -420,8 +434,8 @@ namespace Mantid } /** - * Caches input details for the peak information - */ + * Caches input details for the peak information + */ void CalculateGammaBackground::retrieveInputs() { m_inputWS = getProperty("InputWorkspace"); @@ -447,7 +461,7 @@ namespace Mantid else { throw std::invalid_argument("Invalid function found. Expected ComptonFunction to contain a " - "composite of ComptonProfiles or a single ComptonProfile."); + "composite of ComptonProfiles or a single ComptonProfile."); } // Spectrum numbers whose calculation of background from foils is reversed @@ -455,8 +469,8 @@ namespace Mantid for(specid_t i = 143; i < 199; ++i) { if( (i >= 143 && i <= 150) || (i >= 159 && i <= 166) || - (i >= 175 && i <= 182) || (i >= 191 && i <= 198) ) - m_reversed.insert(i); + (i >= 175 && i <= 182) || (i >= 191 && i <= 198) ) + m_reversed.insert(i); } // Workspace indices mapping input->output @@ -482,8 +496,8 @@ namespace Mantid /** - * Create & cache output workspaces - */ + * Create & cache output workspaces + */ void CalculateGammaBackground::createOutputWorkspaces() { const size_t nhist = m_indices.size(); @@ -492,7 +506,7 @@ namespace Mantid } /** - */ + */ void CalculateGammaBackground::cacheInstrumentGeometry() { auto inst = m_inputWS->getInstrument(); @@ -508,7 +522,7 @@ namespace Mantid if(!changer) { throw std::invalid_argument("Input workspace has no component named foil-changer. " - "One is required to define integration area."); + "One is required to define integration area."); } // 'height' of box sets limits in beam direction @@ -561,10 +575,10 @@ namespace Mantid { std::ostringstream os; os << "Instrument geometry:\n" - << " l1 = " << m_l1 << "m\n" - << " foil radius = " << m_foilRadius << "\n" - << " foil integration min = " << m_foilUpMin << "\n" - << " foil integration max = " << m_foilUpMax << "\n"; + << " l1 = " << m_l1 << "m\n" + << " foil radius = " << m_foilRadius << "\n" + << " foil integration min = " << m_foilUpMin << "\n" + << " foil integration max = " << m_foilUpMax << "\n"; std::ostringstream secondos; for(size_t i = 0; i < nfoils; ++i) { @@ -577,14 +591,14 @@ namespace Mantid } } - /** - * @param foilComp A pointer to the foil component - * @param radius The radius that gives the distance to the centre of the bounding box - * @param horizDir An enumeration defining which direction is horizontal - * @return The min/max angle in theta(degrees) (horizontal direction if you assume mid-point theta = 0) - */ + /** + * @param foilComp A pointer to the foil component + * @param radius The radius that gives the distance to the centre of the bounding box + * @param horizDir An enumeration defining which direction is horizontal + * @return The min/max angle in theta(degrees) (horizontal direction if you assume mid-point theta = 0) + */ std::pair CalculateGammaBackground::calculateThetaRange(const Geometry::IComponent_const_sptr & foilComp, - const double radius, const unsigned int horizDir) const + const double radius, const unsigned int horizDir) const { auto shapedObject = boost::dynamic_pointer_cast(foilComp); if(!shapedObject) diff --git a/Code/Mantid/Framework/CurveFitting/src/ConvertToYSpace.cpp b/Code/Mantid/Framework/CurveFitting/src/ConvertToYSpace.cpp index ca07c6fd3206..28e7d5f5ba00 100644 --- a/Code/Mantid/Framework/CurveFitting/src/ConvertToYSpace.cpp +++ b/Code/Mantid/Framework/CurveFitting/src/ConvertToYSpace.cpp @@ -19,292 +19,297 @@ to a decreasing set of \displaystyle Y values. As a result the fina namespace Mantid { -namespace CurveFitting -{ + namespace CurveFitting + { - // Register the algorithm into the AlgorithmFactory - DECLARE_ALGORITHM(ConvertToYSpace); - - using namespace API; - using namespace Kernel; + // Register the algorithm into the AlgorithmFactory + DECLARE_ALGORITHM(ConvertToYSpace); - namespace - { - /// Conversion constant - const double MASS_TO_MEV = 0.5*PhysicalConstants::NeutronMass/PhysicalConstants::meV; - } - - //---------------------------------------------------------------------------------------------- - /** Constructor - */ - ConvertToYSpace::ConvertToYSpace() - : Algorithm(), m_inputWS(), m_mass(0.0), m_l1(0.0), m_samplePos(),m_outputWS() - { - } - - - //---------------------------------------------------------------------------------------------- - /// Algorithm's name for identification. @see Algorithm::name - const std::string ConvertToYSpace::name() const { return "ConvertToYSpace";}; - - /// Algorithm's version for identification. @see Algorithm::version - int ConvertToYSpace::version() const { return 1;}; - - /// Algorithm's category for identification. @see Algorithm::category - const std::string ConvertToYSpace::category() const { return "Transforms\\Units";} - - //---------------------------------------------------------------------------------------------- - /// Sets documentation strings for this algorithm - void ConvertToYSpace::initDocs() - { - this->setWikiSummary("Converts workspace in units of TOF to Y-space as defined in Compton scattering field"); - this->setOptionalMessage("Converts workspace in units of TOF to Y-space as defined in Compton scattering field"); - } - - //---------------------------------------------------------------------------------------------- - /** - * @param ws The workspace with attached instrument - * @param index Index of the spectrum - * @return DetectorParams structure containing the relevant parameters - */ - DetectorParams ConvertToYSpace::getDetectorParameters(const API::MatrixWorkspace_const_sptr & ws, - const size_t index) - { - auto inst = ws->getInstrument(); - auto sample = inst->getSample(); - auto source = inst->getSource(); - if(!sample || !source) + using namespace API; + using namespace Kernel; + + namespace { - throw std::invalid_argument("ConvertToYSpace - Workspace has no source/sample."); + /// Conversion constant + const double MASS_TO_MEV = 0.5*PhysicalConstants::NeutronMass/PhysicalConstants::meV; } - Geometry::IDetector_const_sptr det; - try + + //---------------------------------------------------------------------------------------------- + /** Constructor + */ + ConvertToYSpace::ConvertToYSpace() + : Algorithm(), m_inputWS(), m_mass(0.0), m_l1(0.0), m_samplePos(),m_outputWS() { - det = ws->getDetector(index); } - catch (Kernel::Exception::NotFoundError &) + + + //---------------------------------------------------------------------------------------------- + /// Algorithm's name for identification. @see Algorithm::name + const std::string ConvertToYSpace::name() const { return "ConvertToYSpace";}; + + /// Algorithm's version for identification. @see Algorithm::version + int ConvertToYSpace::version() const { return 1;}; + + /// Algorithm's category for identification. @see Algorithm::category + const std::string ConvertToYSpace::category() const { return "Transforms\\Units";} + + //---------------------------------------------------------------------------------------------- + /// Sets documentation strings for this algorithm + void ConvertToYSpace::initDocs() { - throw std::invalid_argument("ConvertToYSpace - Workspace has no detector attached to histogram at index " + \ - boost::lexical_cast(index)); + this->setWikiSummary("Converts workspace in units of TOF to Y-space as defined in Compton scattering field"); + this->setOptionalMessage("Converts workspace in units of TOF to Y-space as defined in Compton scattering field"); } - DetectorParams detpar; - const auto & pmap = ws->constInstrumentParameters(); - detpar.l1 = sample->getDistance(*source); - detpar.l2 = det->getDistance(*sample); - detpar.theta = ws->detectorTwoTheta(det); - detpar.t0 = ConvertToYSpace::getComponentParameter(det, pmap, "t0")*1e-6; // Convert to seconds - detpar.efixed = ConvertToYSpace::getComponentParameter(det, pmap, "efixed"); - return detpar; - } - - /** - * If a DetectorGroup is encountered then the parameters are averaged over the group - * @param comp A pointer to the component that should contain the parameter - * @param pmap A reference to the ParameterMap that stores the parameters - * @param name The name of the parameter - * @returns The value of the parameter if it exists - * @throws A std::invalid_argument error if the parameter does not exist - */ - double ConvertToYSpace::getComponentParameter(const Geometry::IComponent_const_sptr & comp, - const Geometry::ParameterMap &pmap, - const std::string &name) - { - if(!comp) throw std::invalid_argument("ComptonProfile - Cannot retrieve parameter from NULL component"); - - double result(0.0); - if(const auto group = boost::dynamic_pointer_cast(comp)) + //---------------------------------------------------------------------------------------------- + /** + * @param ws The workspace with attached instrument + * @param index Index of the spectrum + * @return DetectorParams structure containing the relevant parameters + */ + DetectorParams ConvertToYSpace::getDetectorParameters(const API::MatrixWorkspace_const_sptr & ws, + const size_t index) { - const auto dets = group->getDetectors(); - double avg(0.0); - for(auto it = dets.begin(); it!= dets.end(); ++it) + auto inst = ws->getInstrument(); + auto sample = inst->getSample(); + auto source = inst->getSource(); + if(!sample || !source) { - auto param = pmap.getRecursive((*it)->getComponentID(), name); - if(param) avg += param->value(); - else - throw std::invalid_argument("ComptonProfile - Unable to find DetectorGroup component parameter \"" + name + "\"."); + throw std::invalid_argument("ConvertToYSpace - Workspace has no source/sample."); + } + Geometry::IDetector_const_sptr det; + try + { + det = ws->getDetector(index); + } + catch (Kernel::Exception::NotFoundError &) + { + throw std::invalid_argument("ConvertToYSpace - Workspace has no detector attached to histogram at index " + \ + boost::lexical_cast(index)); } - result = avg/static_cast(group->nDets()); + + DetectorParams detpar; + const auto & pmap = ws->constInstrumentParameters(); + detpar.l1 = sample->getDistance(*source); + detpar.l2 = det->getDistance(*sample); + detpar.theta = ws->detectorTwoTheta(det); + detpar.t0 = ConvertToYSpace::getComponentParameter(det, pmap, "t0")*1e-6; // Convert to seconds + detpar.efixed = ConvertToYSpace::getComponentParameter(det, pmap, "efixed"); + return detpar; } - else + + /** + * If a DetectorGroup is encountered then the parameters are averaged over the group + * @param comp A pointer to the component that should contain the parameter + * @param pmap A reference to the ParameterMap that stores the parameters + * @param name The name of the parameter + * @returns The value of the parameter if it exists + * @throws A std::invalid_argument error if the parameter does not exist + */ + double ConvertToYSpace::getComponentParameter(const Geometry::IComponent_const_sptr & comp, + const Geometry::ParameterMap &pmap, + const std::string &name) { - auto param = pmap.getRecursive(comp->getComponentID(), name); - if(param) + if(!comp) throw std::invalid_argument("ComptonProfile - Cannot retrieve parameter from NULL component"); + + double result(0.0); + if(const auto group = boost::dynamic_pointer_cast(comp)) { - result = param->value(); + const auto dets = group->getDetectors(); + double avg(0.0); + for(auto it = dets.begin(); it!= dets.end(); ++it) + { + auto param = pmap.getRecursive((*it)->getComponentID(), name); + if(param) avg += param->value(); + else + throw std::invalid_argument("ComptonProfile - Unable to find DetectorGroup component parameter \"" + name + "\"."); + } + result = avg/static_cast(group->nDets()); } else { - throw std::invalid_argument("ComptonProfile - Unable to find component parameter \"" + name + "\"."); + auto param = pmap.getRecursive(comp->getComponentID(), name); + if(param) + { + result = param->value(); + } + else + { + throw std::invalid_argument("ComptonProfile - Unable to find component parameter \"" + name + "\"."); + } } + return result; } - return result; - } - - //---------------------------------------------------------------------------------------------- - - /** - * @param yspace Output yspace value - * @param qspace Output qspace value - * @param ei Output incident energy value - * @param mass Mass value for the transformation - * @param tsec Time-of-flight in seconds - * @param k1 Modulus of wavevector for final energy (sqrt(efixed/massToMeV)), avoids repeated calculation - * @param v1 Velocity of neutron for final energy (sqrt(efixed/massToMeV)), avoids repeated calculation - * @param detpar Struct defining Detector parameters @see ComptonProfile - */ - void ConvertToYSpace::calculateY(double & yspace, double & qspace, double &ei, - const double mass, const double tsec, - const double k1, const double v1, - const DetectorParams & detpar) - { - const double v0 = detpar.l1/(tsec - detpar.t0 - (detpar.l2/v1)); - ei = MASS_TO_MEV*v0*v0; - const double w = ei - detpar.efixed; - const double k0 = std::sqrt(ei/PhysicalConstants::E_mev_toNeutronWavenumberSq); - qspace = std::sqrt(k0*k0 + k1*k1 - 2.0*k0*k1*std::cos(detpar.theta)); - const double wreduced = PhysicalConstants::E_mev_toNeutronWavenumberSq*qspace*qspace/mass; - yspace = 0.2393*(mass/qspace)*(w - wreduced); - } - - //---------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------------------------- + + /** + * @param yspace Output yspace value + * @param qspace Output qspace value + * @param ei Output incident energy value + * @param mass Mass value for the transformation + * @param tsec Time-of-flight in seconds + * @param k1 Modulus of wavevector for final energy (sqrt(efixed/massToMeV)), avoids repeated calculation + * @param v1 Velocity of neutron for final energy (sqrt(efixed/massToMeV)), avoids repeated calculation + * @param detpar Struct defining Detector parameters @see ComptonProfile + */ + void ConvertToYSpace::calculateY(double & yspace, double & qspace, double &ei, + const double mass, const double tsec, + const double k1, const double v1, + const DetectorParams & detpar) + { + const double v0 = detpar.l1/(tsec - detpar.t0 - (detpar.l2/v1)); + ei = MASS_TO_MEV*v0*v0; + const double w = ei - detpar.efixed; + const double k0 = std::sqrt(ei/PhysicalConstants::E_mev_toNeutronWavenumberSq); + qspace = std::sqrt(k0*k0 + k1*k1 - 2.0*k0*k1*std::cos(detpar.theta)); + const double wreduced = PhysicalConstants::E_mev_toNeutronWavenumberSq*qspace*qspace/mass; + yspace = 0.2393*(mass/qspace)*(w - wreduced); + } - /** Initialize the algorithm's properties. - */ - void ConvertToYSpace::init() - { - auto wsValidator = boost::make_shared(); - wsValidator->add(false); // point data - wsValidator->add(); - wsValidator->add("TOF"); - declareProperty(new WorkspaceProperty<>("InputWorkspace","",Direction::Input,wsValidator), - "An input workspace."); + //---------------------------------------------------------------------------------------------- - auto mustBePositive = boost::make_shared >(); - mustBePositive->setLower(0.0); - mustBePositive->setLowerExclusive(true); //strictly greater than 0.0 - declareProperty("Mass",-1.0,mustBePositive,"The mass defining the recoil peak in AMU"); - declareProperty(new WorkspaceProperty<>("OutputWorkspace","",Direction::Output), "An output workspace."); + /** Initialize the algorithm's properties. + */ + void ConvertToYSpace::init() + { + auto wsValidator = boost::make_shared(); + wsValidator->add(false); // point data + wsValidator->add(); + wsValidator->add("TOF"); + declareProperty(new WorkspaceProperty<>("InputWorkspace","",Direction::Input,wsValidator), + "An input workspace."); - } + auto mustBePositive = boost::make_shared >(); + mustBePositive->setLower(0.0); + mustBePositive->setLowerExclusive(true); //strictly greater than 0.0 + declareProperty("Mass",-1.0,mustBePositive,"The mass defining the recoil peak in AMU"); + declareProperty(new WorkspaceProperty<>("OutputWorkspace","",Direction::Output), "An output workspace."); + } - //---------------------------------------------------------------------------------------------- - /** Execute the algorithm. - */ - void ConvertToYSpace::exec() - { - retrieveInputs(); - createOutputWorkspace(); - const int64_t nhist = static_cast(m_inputWS->getNumberHistograms()); - const int64_t nreports = nhist; - auto progress = boost::make_shared(this, 0.0, 1.0, nreports); - PARALLEL_FOR2(m_inputWS, m_outputWS) - for(int64_t i = 0; i < nhist; ++i) + //---------------------------------------------------------------------------------------------- + /** Execute the algorithm. + */ + void ConvertToYSpace::exec() { - PARALLEL_START_INTERUPT_REGION + retrieveInputs(); + createOutputWorkspace(); + + const int64_t nhist = static_cast(m_inputWS->getNumberHistograms()); + const int64_t nreports = nhist; + auto progress = boost::make_shared(this, 0.0, 1.0, nreports); + + PARALLEL_FOR2(m_inputWS, m_outputWS) + for(int64_t i = 0; i < nhist; ++i) + { + PARALLEL_START_INTERUPT_REGION + + if (!convert(i)) + { + + g_log.warning("No detector defined for index=" + boost::lexical_cast(i) + ". Zeroing spectrum."); + m_outputWS->maskWorkspaceIndex(i); + } + + PARALLEL_END_INTERUPT_REGION + } + PARALLEL_CHECK_INTERUPT_REGION + + setProperty("OutputWorkspace", m_outputWS); + } + /** + * Convert the spectrum at the given index on the input workspace + * and place the output in the pre-allocated output workspace + * @param index Index on the input & output workspaces giving the spectrum to convert + */ + bool ConvertToYSpace::convert(const size_t index) + { try { - convert(i); - } - catch(Exception::NotFoundError &) + + auto det = m_inputWS->getDetector(index); + const auto & pmap = m_inputWS->constInstrumentParameters(); + auto detPos = det->getPos(); + + // -- Setup detector & resolution parameters -- + DetectorParams detPar; + detPar.l1 = m_l1; + detPar.l2 = m_samplePos.distance(detPos); + detPar.theta = m_inputWS->detectorTwoTheta(det); //radians + detPar.t0 = getComponentParameter(det, pmap, "t0")*1e-06; // seconds + detPar.efixed = getComponentParameter(det, pmap,"efixed"); + const double v1 = std::sqrt(detPar.efixed/MASS_TO_MEV); + const double k1 = std::sqrt(detPar.efixed/PhysicalConstants::E_mev_toNeutronWavenumberSq); + + auto & outX = m_outputWS->dataX(index); + auto & outY = m_outputWS->dataY(index); + auto & outE = m_outputWS->dataE(index); + const auto & inX = m_inputWS->readX(index); + const auto & inY = m_inputWS->readY(index); + const auto & inE = m_inputWS->readE(index); + + // The t->y mapping flips the order of the axis so we need to reverse it to have a monotonically + // increasing axis + const size_t npts = inY.size(); + for(size_t j = 0; j < npts; ++j) + { + double ys(0.0),qs(0.0),ei(0.0); + calculateY(ys,qs,ei,m_mass,inX[j]*1e-06,k1,v1,detPar); + const size_t outIndex = (npts - j - 1); + outX[outIndex] = ys; + const double prefactor = qs/pow(ei,0.1); + outY[outIndex] = prefactor*inY[j]; + outE[outIndex] = prefactor*inE[j]; + } + return true; + }catch(Exception::NotFoundError &) { - g_log.warning("No detector defined for index=" + boost::lexical_cast(i) + ". Zeroing spectrum."); - m_outputWS->maskWorkspaceIndex(i); + return false; } - - PARALLEL_END_INTERUPT_REGION } - PARALLEL_CHECK_INTERUPT_REGION - setProperty("OutputWorkspace", m_outputWS); - } - /** - * Convert the spectrum at the given index on the input workspace - * and place the output in the pre-allocated output workspace - * @param index Index on the input & output workspaces giving the spectrum to convert - */ - void ConvertToYSpace::convert(const size_t index) - { - auto det = m_inputWS->getDetector(index); - const auto & pmap = m_inputWS->constInstrumentParameters(); - auto detPos = det->getPos(); - - // -- Setup detector & resolution parameters -- - DetectorParams detPar; - detPar.l1 = m_l1; - detPar.l2 = m_samplePos.distance(detPos); - detPar.theta = m_inputWS->detectorTwoTheta(det); //radians - detPar.t0 = getComponentParameter(det, pmap, "t0")*1e-06; // seconds - detPar.efixed = getComponentParameter(det, pmap,"efixed"); - const double v1 = std::sqrt(detPar.efixed/MASS_TO_MEV); - const double k1 = std::sqrt(detPar.efixed/PhysicalConstants::E_mev_toNeutronWavenumberSq); - - auto & outX = m_outputWS->dataX(index); - auto & outY = m_outputWS->dataY(index); - auto & outE = m_outputWS->dataE(index); - const auto & inX = m_inputWS->readX(index); - const auto & inY = m_inputWS->readY(index); - const auto & inE = m_inputWS->readE(index); - - // The t->y mapping flips the order of the axis so we need to reverse it to have a monotonically - // increasing axis - const size_t npts = inY.size(); - for(size_t j = 0; j < npts; ++j) + /** + * Caches input details for the peak information + */ + void ConvertToYSpace::retrieveInputs() { - double ys(0.0),qs(0.0),ei(0.0); - calculateY(ys,qs,ei,m_mass,inX[j]*1e-06,k1,v1,detPar); - const size_t outIndex = (npts - j - 1); - outX[outIndex] = ys; - const double prefactor = qs/pow(ei,0.1); - outY[outIndex] = prefactor*inY[j]; - outE[outIndex] = prefactor*inE[j]; + m_inputWS = getProperty("InputWorkspace"); + m_mass = getProperty("Mass"); + cacheInstrumentGeometry(); } - } - - /** - * Caches input details for the peak information - */ - void ConvertToYSpace::retrieveInputs() - { - m_inputWS = getProperty("InputWorkspace"); - m_mass = getProperty("Mass"); - cacheInstrumentGeometry(); - } + /** + * Create & cache output workspaces + */ + void ConvertToYSpace::createOutputWorkspace() + { + m_outputWS = WorkspaceFactory::Instance().create(m_inputWS); + // Units + auto xLabel = boost::make_shared("Momentum", "A^-1"); + m_outputWS->getAxis(0)->unit() = xLabel; + m_outputWS->setYUnit(""); + m_outputWS->setYUnitLabel(""); + } - /** - * Create & cache output workspaces - */ - void ConvertToYSpace::createOutputWorkspace() - { - m_outputWS = WorkspaceFactory::Instance().create(m_inputWS); - // Units - auto xLabel = boost::make_shared("Momentum", "A^-1"); - m_outputWS->getAxis(0)->unit() = xLabel; - m_outputWS->setYUnit(""); - m_outputWS->setYUnitLabel(""); - } - - /** - */ - void ConvertToYSpace::cacheInstrumentGeometry() - { - auto inst = m_inputWS->getInstrument(); - auto source = inst->getSource(); - auto sample = inst->getSample(); - m_l1 = sample->getDistance(*source); - m_samplePos = sample->getPos(); - } + /** + */ + void ConvertToYSpace::cacheInstrumentGeometry() + { + auto inst = m_inputWS->getInstrument(); + auto source = inst->getSource(); + auto sample = inst->getSample(); + m_l1 = sample->getDistance(*source); + m_samplePos = sample->getPos(); + } -} // namespace CurveFitting + } // namespace CurveFitting } // namespace Mantid diff --git a/Code/Mantid/Framework/MDAlgorithms/src/CompareMDWorkspaces.cpp b/Code/Mantid/Framework/MDAlgorithms/src/CompareMDWorkspaces.cpp index 851d03174363..6e55cb2c939e 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/CompareMDWorkspaces.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/CompareMDWorkspaces.cpp @@ -263,7 +263,7 @@ namespace Mantid // Are both MDGridBoxes ? MDGridBox* gridbox1 = dynamic_cast*>(box1); MDGridBox* gridbox2 = dynamic_cast*>(box2); - if (gridbox1) + if (gridbox1 && gridbox2) { for (size_t d=0; dcompareTol( gridbox1->getBoxSize(d), gridbox2->getBoxSize(d), "Box sizes do not match"); diff --git a/Code/Mantid/Framework/MDAlgorithms/src/ConvertToDiffractionMDWorkspace.cpp b/Code/Mantid/Framework/MDAlgorithms/src/ConvertToDiffractionMDWorkspace.cpp index e7de3ae9195c..c237157f0229 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/ConvertToDiffractionMDWorkspace.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/ConvertToDiffractionMDWorkspace.cpp @@ -104,7 +104,15 @@ namespace MDAlgorithms //---------------------------------------------------------------------------------------------- /** Constructor */ - ConvertToDiffractionMDWorkspace::ConvertToDiffractionMDWorkspace() + ConvertToDiffractionMDWorkspace::ConvertToDiffractionMDWorkspace(): + ClearInputWorkspace(false), // imput workspace should be left untouched + OneEventPerBin(false), // it is very expensive otherwise + Append(true), // append data to existing target MD workspace if one exist + LorentzCorrection(false), // not doing Lorents + l1(1.), + beamline_norm(1.), + failedDetectorLookupCount(0), + m_extentsMin(NULL),m_extentsMax(NULL) // will be allocated in exec using nDims { } diff --git a/Code/Mantid/Framework/MDAlgorithms/src/LoadMD.cpp b/Code/Mantid/Framework/MDAlgorithms/src/LoadMD.cpp index 3ba72a0b7407..a41c27afced0 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/LoadMD.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/LoadMD.cpp @@ -61,7 +61,9 @@ namespace Mantid //---------------------------------------------------------------------------------------------- /** Constructor */ - LoadMD::LoadMD() + LoadMD::LoadMD(): + m_numDims(0), // uninitialized incorrect value + m_BoxStructureAndMethadata(true) // this is faster but rarely needed. { } diff --git a/Code/Mantid/Framework/MDAlgorithms/src/SlicingAlgorithm.cpp b/Code/Mantid/Framework/MDAlgorithms/src/SlicingAlgorithm.cpp index 443750173eaf..dbc1f614c06b 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/SlicingAlgorithm.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/SlicingAlgorithm.cpp @@ -27,7 +27,9 @@ namespace MDAlgorithms SlicingAlgorithm::SlicingAlgorithm() : m_transform(), m_transformFromOriginal(), m_transformToOriginal(), - m_transformFromIntermediate(), m_transformToIntermediate() + m_transformFromIntermediate(), m_transformToIntermediate(), + m_axisAligned(true), + m_outD(0) // unititialized and should be invalid { } diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h index 1a8b70f4bec4..446653270038 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h @@ -290,7 +290,7 @@ void test_EventNoUnitsConv() pTargWS->createEmptyMDWS(WSD); ConvToMDSelector AlgoSelector; - pConvMethods = AlgoSelector.convSelector(inWsEv); + pConvMethods = AlgoSelector.convSelector(inWsEv,pConvMethods); TS_ASSERT_THROWS_NOTHING(pConvMethods->initialize(WSD,pTargWS,false)); pMockAlgorithm->resetProgress(numHist); @@ -326,7 +326,7 @@ void test_EventFromTOFConv() ConvToMDSelector AlgoSelector; - pConvMethods = AlgoSelector.convSelector(inWsEv); + pConvMethods = AlgoSelector.convSelector(inWsEv,pConvMethods); pConvMethods->initialize(WSD,pTargWS,false); pMockAlgorithm->resetProgress(numHist); @@ -364,7 +364,7 @@ void test_HistoFromTOFConv() pTargWS->createEmptyMDWS(WSD); ConvToMDSelector AlgoSelector; - pConvMethods = AlgoSelector.convSelector(inWs2D); + pConvMethods = AlgoSelector.convSelector(inWs2D,pConvMethods); pConvMethods->initialize(WSD,pTargWS,false); pMockAlgorithm->resetProgress(numHist); @@ -405,7 +405,7 @@ void test_HistoNoUnitsConv() pTargWS->createEmptyMDWS(WSD); ConvToMDSelector AlgoSelector; - pConvMethods = AlgoSelector.convSelector(inWs2D); + pConvMethods = AlgoSelector.convSelector(inWs2D,pConvMethods); pConvMethods->initialize(WSD,pTargWS,false); pMockAlgorithm->resetProgress(numHist); diff --git a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/ConvToMDSelector.h b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/ConvToMDSelector.h index 7ced9018e2d2..63d0d6bde75a 100644 --- a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/ConvToMDSelector.h +++ b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/ConvToMDSelector.h @@ -44,7 +44,7 @@ class DLLExport ConvToMDSelector public: /// function which selects the convertor depending on workspace type and (possibly, in a future) some workspace properties boost::shared_ptr convSelector(API::MatrixWorkspace_sptr inputWS, - boost::shared_ptr currentSptr = boost::shared_ptr())const; + boost::shared_ptr ¤tSptr)const; }; } // end MDAlgorithms Namespace } // end Mantid Namespace diff --git a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/CoordTransformAffine.h b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/CoordTransformAffine.h index 69725cbca68a..2fa7fe316f76 100644 --- a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/CoordTransformAffine.h +++ b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/CoordTransformAffine.h @@ -59,6 +59,8 @@ namespace MDEvents /// Raw pointer to the same underlying matrix as affineMatrix. coord_t ** rawMatrix; + /// raw pointer to the memory block, referred by the raw Matrix; + coord_t * rawMemory; void copyRawMatrix(); }; diff --git a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDTransfModQ.h b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDTransfModQ.h index 4f9d7a2b02ce..2915411a5d05 100644 --- a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDTransfModQ.h +++ b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDTransfModQ.h @@ -50,7 +50,7 @@ class DLLExport MDTransfModQ: public MDTransfInterface const std::string transfID()const; // {return "ModQ"; } /** energy conversion modes supported by this class; * The class supports three standard energy conversion modes */ - std::vector getEmodes()const{ return Kernel::DeltaEMode().availableTypes();} + std::vector getEmodes()const; bool calcGenericVariables(std::vector &Coord, size_t nd); bool calcYDepCoordinates(std::vector &Coord,size_t i); diff --git a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/UnitsConversionHelper.h b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/UnitsConversionHelper.h index 6099241a0e73..4fce0eb1db04 100644 --- a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/UnitsConversionHelper.h +++ b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/UnitsConversionHelper.h @@ -72,7 +72,7 @@ class DLLExport UnitsConversionHelper float *m_pEfixedArray; public: - UnitsConversionHelper():m_pTwoThetas(NULL),m_pL2s(NULL){}; + UnitsConversionHelper(); void initialize(const MDWSDescription &targetWSDescr,const std::string &units_to); void initialize(const std::string &unitsFrom,const std::string &unitsTo,const DataObjects::TableWorkspace_const_sptr &DetWS,int Emode); void updateConversion(size_t i); diff --git a/Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp b/Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp index 34a220dde40d..395d4a951b7d 100644 --- a/Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp +++ b/Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp @@ -89,7 +89,12 @@ namespace Mantid }; /** empty default constructor */ - ConvToMDBase::ConvToMDBase():m_NumThreads(-1), m_coordinateSystem(Mantid::API::None) + ConvToMDBase::ConvToMDBase():m_NDims(0), // wrong non-initialized + m_RunIndex(0), // defauld run index is 0 + m_NSpectra(0), // no valid spectra by default. + m_NumThreads(-1), // run with all cores availible + m_ignoreZeros(false), // 0-s added to workspace + m_coordinateSystem(Mantid::API::None) { } diff --git a/Code/Mantid/Framework/MDEvents/src/ConvToMDEventsWS.cpp b/Code/Mantid/Framework/MDEvents/src/ConvToMDEventsWS.cpp index 82c3d48831dc..6e2173bae08a 100644 --- a/Code/Mantid/Framework/MDEvents/src/ConvToMDEventsWS.cpp +++ b/Code/Mantid/Framework/MDEvents/src/ConvToMDEventsWS.cpp @@ -1,6 +1,7 @@ #include "MantidMDEvents/ConvToMDEventsWS.h" #include "MantidMDEvents/UnitsConversionHelper.h" -// + + namespace Mantid { @@ -122,15 +123,16 @@ namespace Mantid size_t nValidSpectra = m_NSpectra; //--->>> Thread control stuff - Kernel::ThreadScheduler * ts = new Kernel::ThreadSchedulerFIFO(); + Kernel::ThreadSchedulerFIFO * ts(NULL); + int nThreads(m_NumThreads); if(nThreads<0)nThreads= 0; // negative m_NumThreads correspond to all cores used, 0 no threads and positive number -- nThreads requested; bool runMultithreaded = false; if(m_NumThreads!=0) { runMultithreaded = true; - // Create the thread pool that will run all of these. - ts = new Kernel::ThreadSchedulerFIFO(); + // Create the thread pool that will run all of these. It will be deleted by the threadpool + ts = new Kernel::ThreadSchedulerFIFO(); // it will initiate thread pool with number threads or machine's cores (0 in tp constructor) pProgress->resetNumSteps(nValidSpectra,0,1); } @@ -189,6 +191,7 @@ namespace Mantid /// Set the special coordinate system flag on the output workspace. m_OutWSWrapper->pWorkspace()->setCoordinateSystem(m_coordinateSystem); + } diff --git a/Code/Mantid/Framework/MDEvents/src/ConvToMDHistoWS.cpp b/Code/Mantid/Framework/MDEvents/src/ConvToMDHistoWS.cpp index 1c63a0ec7a0e..4cc73ad2c03b 100644 --- a/Code/Mantid/Framework/MDEvents/src/ConvToMDHistoWS.cpp +++ b/Code/Mantid/Framework/MDEvents/src/ConvToMDHistoWS.cpp @@ -148,15 +148,15 @@ namespace Mantid //--->>> Thread control stuff - Kernel::ThreadScheduler * ts = new Kernel::ThreadSchedulerFIFO(); + Kernel::ThreadSchedulerFIFO * ts(NULL); int nThreads(m_NumThreads); if(nThreads<0)nThreads= 0; // negative m_NumThreads correspond to all cores used, 0 no threads and positive number -- nThreads requested; bool runMultithreaded = false; if(m_NumThreads!=0) { runMultithreaded = true; - // Create the thread pool that will run all of these. - ts = new Kernel::ThreadSchedulerFIFO(); + // Create the thread pool that will run all of these. It will be deleted by the threadpool + ts = new Kernel::ThreadSchedulerFIFO(); // it will initiate thread pool with number threads or machine's cores (0 in tp constructor) pProgress->resetNumSteps(nValidSpectra,0,1); } diff --git a/Code/Mantid/Framework/MDEvents/src/ConvToMDSelector.cpp b/Code/Mantid/Framework/MDEvents/src/ConvToMDSelector.cpp index 706bb7e34c47..13fc0adf4ddc 100644 --- a/Code/Mantid/Framework/MDEvents/src/ConvToMDSelector.cpp +++ b/Code/Mantid/Framework/MDEvents/src/ConvToMDSelector.cpp @@ -18,33 +18,38 @@ enum wsType *@returns shared pointer to new solver, which corresponds to the workspace */ boost::shared_ptr ConvToMDSelector::convSelector(API::MatrixWorkspace_sptr inputWS, - boost::shared_ptr currentSolver)const + boost::shared_ptr ¤tSolver)const { // identify what kind of workspace we expect to process - wsType inputWSType(Undefined); - if(boost::dynamic_pointer_cast(inputWS)) inputWSType = EventWS; - if(boost::dynamic_pointer_cast(inputWS)) inputWSType = Matrix2DWS; + wsType inputWSType = Undefined; + if(boost::dynamic_pointer_cast(inputWS)) + inputWSType = EventWS; + if(boost::dynamic_pointer_cast(inputWS)) + inputWSType = Matrix2DWS; if(inputWSType == Undefined) throw(std::invalid_argument("ConvToMDEventsSelector::got a workspace which is neither matrix nor event workspace; Can not deal with it")); // identify what converter (if any) is currently initialized; - wsType wsConvType(Undefined); + wsType existingWsConvType(Undefined); ConvToMDBase *pSolver = currentSolver.get(); if(pSolver) { - if(dynamic_cast(pSolver)) wsConvType = EventWS; - if(dynamic_cast(pSolver)) wsConvType = Matrix2DWS; + if(dynamic_cast(pSolver)) existingWsConvType = EventWS; + if(dynamic_cast(pSolver)) existingWsConvType = Matrix2DWS; } // select a converter, which corresponds to the workspace type - if((wsConvType==Undefined)||(wsConvType!=inputWSType)) + if((existingWsConvType==Undefined)||(existingWsConvType!=inputWSType)) { switch(inputWSType) { - case(EventWS): return boost::shared_ptr(new ConvToMDEventsWS()); - case(Matrix2DWS): return boost::shared_ptr(new ConvToMDHistoWS()); - default: throw(std::logic_error("ConvToMDEventsSelector: requested converter for unknown ws type")); + case(EventWS): + return boost::shared_ptr(new ConvToMDEventsWS()); + case(Matrix2DWS): + return boost::shared_ptr(new ConvToMDHistoWS()); + default: + throw(std::logic_error("ConvToMDEventsSelector: requested converter for unknown ws type")); } } diff --git a/Code/Mantid/Framework/MDEvents/src/CoordTransformAffine.cpp b/Code/Mantid/Framework/MDEvents/src/CoordTransformAffine.cpp index 8e16312cec5c..de862159a023 100644 --- a/Code/Mantid/Framework/MDEvents/src/CoordTransformAffine.cpp +++ b/Code/Mantid/Framework/MDEvents/src/CoordTransformAffine.cpp @@ -30,21 +30,35 @@ namespace MDEvents */ CoordTransformAffine::CoordTransformAffine(const size_t inD, const size_t outD) : CoordTransform(inD, outD), - affineMatrix(outD+1, inD+1), rawMatrix(NULL) + affineMatrix(outD+1, inD+1), rawMatrix(NULL),rawMemory(NULL) { affineMatrix.identityMatrix(); // Allocate the raw matrix size_t nx = affineMatrix.numRows(); size_t ny = affineMatrix.numCols(); - coord_t * tmpX = new coord_t[nx*ny]; + // vector of pointers rawMatrix = new coord_t*[nx]; + // memory itself + rawMemory = new coord_t[nx*ny]; for (size_t i=0;i entries; file->getEntries(entries); + std::list ExperimentBlockNum; std::map::iterator it = entries.begin(); - std::vector hasExperimentBlock; - uint16_t numExperimentInfo = 0; for (; it != entries.end(); ++it) { std::string name = it->first; @@ -402,11 +401,10 @@ namespace Mantid try { uint16_t num = boost::lexical_cast(name.substr(10, name.size()-10)); - if (num+1 > numExperimentInfo) + if (num::max()-1) { - numExperimentInfo = uint16_t(num+uint16_t(1)); - hasExperimentBlock.resize(numExperimentInfo, false); - hasExperimentBlock[num] = true; + // dublicated experiment info names are impossible due to the structure of the nexus file but missing -- can be found. + ExperimentBlockNum.push_back(num); } } catch (boost::bad_lexical_cast &) @@ -414,15 +412,31 @@ namespace Mantid } } - // Now go through in order, loading and adding - for (uint16_t i=0; i < numExperimentInfo; i++) + ExperimentBlockNum.sort(); + + // check if all subsequent experiment infos numbers are present + auto itr=ExperimentBlockNum.begin(); + size_t ic=0; + for (;itr!=ExperimentBlockNum.end();itr++) { - std::string groupName = "experiment" + Kernel::Strings::toString(i); - if (!numExperimentInfo) + if (*itr != ic) + { + for(size_t i=ic+1;i<*itr; i++) { - g_log.warning() << "NXS file is missing a ExperimentInfo block " << groupName << ". Workspace will be missing ExperimentInfo." << std::endl; - break; + std::string groupName = "experiment" + Kernel::Strings::toString(i); + g_log.warning() << "NXS file is missing a ExperimentInfo block " << groupName << ". Workspace will be missing ExperimentInfo." << std::endl; } + } + ic++; + } + + // Now go through in order, loading and adding + itr=ExperimentBlockNum.begin(); + for (;itr!=ExperimentBlockNum.end();itr++) + { + + std::string groupName = "experiment" + Kernel::Strings::toString(*itr); + file->openGroup(groupName, "NXgroup"); API::ExperimentInfo_sptr ei(new API::ExperimentInfo); std::string parameterStr; diff --git a/Code/Mantid/Framework/MDEvents/src/MDTransfModQ.cpp b/Code/Mantid/Framework/MDEvents/src/MDTransfModQ.cpp index 03400c8a9d81..f925c16ad5e1 100644 --- a/Code/Mantid/Framework/MDEvents/src/MDTransfModQ.cpp +++ b/Code/Mantid/Framework/MDEvents/src/MDTransfModQ.cpp @@ -361,8 +361,18 @@ namespace Mantid /// constructor; MDTransfModQ::MDTransfModQ(): - m_Det(NULL)//,m_NMatrixDim(-1) + m_ex(0),m_ey(0),m_ez(1), + m_Det(NULL), + m_NMatrixDim(0), //uninitialized + m_Emode(Kernel::DeltaEMode::Undefined), // uninitialized + m_Ki(1.),m_Ei(1.), + m_pEfixedArray(NULL), + m_pDetMasks(NULL) {} + std::vector MDTransfModQ::getEmodes()const + { + return Kernel::DeltaEMode().availableTypes(); + } } // End MDAlgorighms namespace } // End Mantid namespace diff --git a/Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp b/Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp index 559d13b12587..ce3f0ffa65a1 100644 --- a/Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp +++ b/Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp @@ -228,9 +228,11 @@ Kernel::DblMatrix MDWSTransform::buildQTrahsf(MDEvents::MDWSDescription &TargWSD case OrthogonalHKLScale://< each momentum component divided by appropriate lattice parameter; equivalent to hkl for orthogonal axis { if(spLatt) + { for(int i=0;i<3;i++){ Scale[i][i] = (2*M_PI)/spLatt->a(i);} Transf = spLatt->getU(); - break; + } + break; } case HKLScale: //< non-orthogonal system for non-orthogonal lattice { diff --git a/Code/Mantid/Framework/MDEvents/src/UnitsConversionHelper.cpp b/Code/Mantid/Framework/MDEvents/src/UnitsConversionHelper.cpp index 0b554c4a3002..4d290d5b414f 100644 --- a/Code/Mantid/Framework/MDEvents/src/UnitsConversionHelper.cpp +++ b/Code/Mantid/Framework/MDEvents/src/UnitsConversionHelper.cpp @@ -112,7 +112,7 @@ void UnitsConversionHelper::updateConversion(size_t i) case(CnvrtToMD::ConvertFast): return; case(CnvrtToMD::ConvertFromTOF): { - double delta; + double delta(std::numeric_limits::quiet_NaN()); m_TwoTheta = (*m_pTwoThetas)[i]; m_L2 = (*m_pL2s)[i]; double Efix = m_Efix; @@ -123,7 +123,7 @@ void UnitsConversionHelper::updateConversion(size_t i) } case(CnvrtToMD::ConvertByTOF): { - double delta; + double delta(std::numeric_limits::quiet_NaN()); m_TwoTheta = (*m_pTwoThetas)[i]; m_L2 = (*m_pL2s)[i]; double Efix = m_Efix; @@ -188,6 +188,14 @@ UnitsConversionHelper::UnitsConversionHelper(const UnitsConversionHelper &anothe if(another.m_TargetUnit) m_TargetUnit = Kernel::Unit_sptr(another.m_TargetUnit->clone()); } +UnitsConversionHelper::UnitsConversionHelper(): + m_UnitCnvrsn(CnvrtToMD::ConvertNo), + m_Factor(1),m_Power(1), + m_Emode(-1), // undefined + m_L1(1),m_Efix(1),m_TwoTheta(0),m_L2(1), + m_pTwoThetas(NULL),m_pL2s(NULL),m_pEfixedArray(NULL) +{}; + } // endNamespace MDEvents } // endNamespace Mantid diff --git a/Code/Mantid/Framework/TestHelpers/src/MDEventsTestHelper.cpp b/Code/Mantid/Framework/TestHelpers/src/MDEventsTestHelper.cpp index a5bd06924e35..e727af55d3a9 100644 --- a/Code/Mantid/Framework/TestHelpers/src/MDEventsTestHelper.cpp +++ b/Code/Mantid/Framework/TestHelpers/src/MDEventsTestHelper.cpp @@ -255,6 +255,10 @@ namespace MDEventsTestHelper MDHistoDimension_sptr(new MDHistoDimension("t","t","m", 0.0, max, numBins)) ); } + + if (!ws) + throw std::runtime_error(" invalid or unsupported number of dimensions given"); + Mantid::MDEvents::MDHistoWorkspace_sptr ws_sptr(ws); ws_sptr->setTo(signal, errorSquared, numEvents); ws_sptr->addExperimentInfo(ExperimentInfo_sptr(new ExperimentInfo()));