Skip to content

Commit

Permalink
refs #7529 Generally fixes the issue with different Units
Browse files Browse the repository at this point in the history
but more testing is necessary
refs #8794 Resolved conflicts while reverting ticket to master

Conflicts:
	Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/ConvertToMDHelper2.h
	Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
	Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDHelper2.cpp
  • Loading branch information
abuts committed Jan 30, 2014
1 parent ae6eab9 commit 6b3bf28
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 46 deletions.
27 changes: 18 additions & 9 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/Unit.h
Expand Up @@ -155,7 +155,12 @@ class MANTID_KERNEL_DLL Unit
/// @return true if the unit was initialized and so can use singleToTOF()
bool isInitialized() const
{ return initialized; }

/// some units can be converted into TOF only in some range of values;
/// This function returns minimal TOF value still convertable into reasonable unit
virtual double conversionTOFMin()const
{
return -DBL_MAX;
};
protected:
// Add a 'quick conversion' for a unit pair
void addConversion(std::string to, const double& factor, const double& power = 1.0) const;
Expand Down Expand Up @@ -280,6 +285,7 @@ class MANTID_KERNEL_DLL Wavelength : public Unit
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
Wavelength();
/// Destructor
Expand Down Expand Up @@ -307,6 +313,7 @@ class MANTID_KERNEL_DLL Energy : public Unit
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
Energy();
/// Destructor
Expand All @@ -330,7 +337,7 @@ class MANTID_KERNEL_DLL Energy_inWavenumber : public Unit
virtual double singleFromTOF(const double tof) const;
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
Energy_inWavenumber();
/// Destructor
Expand All @@ -354,7 +361,7 @@ class MANTID_KERNEL_DLL dSpacing : public Unit
virtual double singleFromTOF(const double tof) const;
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
dSpacing();
/// Destructor
Expand All @@ -378,7 +385,7 @@ class MANTID_KERNEL_DLL MomentumTransfer : public Unit
virtual double singleFromTOF(const double tof) const;
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
MomentumTransfer();
/// Destructor
Expand All @@ -402,7 +409,7 @@ class MANTID_KERNEL_DLL QSquared : public Unit
virtual double singleFromTOF(const double tof) const;
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
QSquared();
/// Destructor
Expand All @@ -427,6 +434,8 @@ class MANTID_KERNEL_DLL DeltaE : public Unit
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;

/// Constructor
DeltaE();
/// Destructor
Expand All @@ -451,7 +460,7 @@ class MANTID_KERNEL_DLL DeltaE_inWavenumber : public DeltaE

virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
DeltaE_inWavenumber();
/// Destructor
Expand Down Expand Up @@ -496,7 +505,7 @@ class MANTID_KERNEL_DLL Momentum : public Unit
virtual double singleFromTOF(const double tof) const;
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
Momentum();
/// Destructor
Expand All @@ -523,7 +532,7 @@ class MANTID_KERNEL_DLL SpinEchoLength : public Wavelength
virtual double singleFromTOF(const double tof) const;
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
SpinEchoLength();
/// Destructor
Expand All @@ -544,7 +553,7 @@ class MANTID_KERNEL_DLL SpinEchoTime : public Wavelength
virtual double singleFromTOF(const double tof) const;
virtual void init();
virtual Unit * clone() const;

virtual double conversionTOFMin()const;
/// Constructor
SpinEchoTime();
/// Destructor
Expand Down
65 changes: 65 additions & 0 deletions Code/Mantid/Framework/Kernel/src/Unit.cpp
Expand Up @@ -348,6 +348,13 @@ double Wavelength::singleToTOF(const double x) const
tof += sfpTo;
return tof;
}
double Wavelength::conversionTOFMin()const
{
double range(0);
if( emode == 1 || emode == 2 )
range=sfpTo;
return range;
}

double Wavelength::singleFromTOF(const double tof) const
{
Expand Down Expand Up @@ -405,6 +412,11 @@ double Energy::singleToTOF(const double x) const
return factorTo / sqrt(temp);
}

double Energy::conversionTOFMin()const
{
return 0.;
}

double Energy::singleFromTOF(const double tof) const
{
double temp = tof;
Expand Down Expand Up @@ -461,6 +473,11 @@ double Energy_inWavenumber::singleToTOF(const double x) const
return factorTo / sqrt(temp);
}

double Energy_inWavenumber::conversionTOFMin()const
{
return 0;
}

double Energy_inWavenumber::singleFromTOF(const double tof) const
{
double temp = tof;
Expand Down Expand Up @@ -509,6 +526,11 @@ double dSpacing::singleToTOF(const double x) const
return x*factorTo;
}

double dSpacing::conversionTOFMin()const
{
return 0;
}

double dSpacing::singleFromTOF(const double tof) const
{
return tof/factorFrom;
Expand Down Expand Up @@ -559,6 +581,10 @@ double MomentumTransfer::singleToTOF(const double x) const
if (temp == 0.0) temp = DBL_MIN; // Protect against divide by zero
return factorTo / temp;
}
double MomentumTransfer::conversionTOFMin()const
{
return 0;
}

double MomentumTransfer::singleFromTOF(const double tof) const
{
Expand Down Expand Up @@ -612,6 +638,12 @@ double QSquared::singleToTOF(const double x) const
return factorTo / sqrt(temp);
}

double QSquared::conversionTOFMin()const
{
return 0;
}


double QSquared::singleFromTOF(const double tof) const
{
double temp = tof;
Expand Down Expand Up @@ -736,6 +768,14 @@ double DeltaE::singleFromTOF(const double tof) const
return DBL_MAX;
}

double DeltaE::conversionTOFMin()const
{
double range(DBL_MAX); // impossible for elastic
if (emode == 1 || emode == 2)
range = t_otherFrom;
return range;
}

Unit * DeltaE::clone() const
{
return new DeltaE(*this);
Expand Down Expand Up @@ -771,6 +811,12 @@ DeltaE_inWavenumber::DeltaE_inWavenumber() : DeltaE()
addConversion("DeltaE",1/PhysicalConstants::meVtoWavenumber,1.);
}

double DeltaE_inWavenumber::conversionTOFMin()const
{
return DeltaE::conversionTOFMin();
}


// =====================================================================================================
/* Momentum in Angstrom^-1. It is 2*Pi/wavelength
* =====================================================================================================
Expand Down Expand Up @@ -866,6 +912,15 @@ double Momentum::singleToTOF(const double ki) const
tof += sfpTo;
return tof;
}
double Momentum::conversionTOFMin()const
{
double range(DBL_MAX);
range=0;
if (emode == 1 || emode == 2)
range = sfpTo;
return range;
}


double Momentum::singleFromTOF(const double tof) const
{
Expand Down Expand Up @@ -915,6 +970,12 @@ double SpinEchoLength::singleToTOF(const double x) const
return tof;
}

double SpinEchoLength::conversionTOFMin()const
{
return 0;
}


double SpinEchoLength::singleFromTOF(const double tof) const
{
double wavelength = Wavelength::singleFromTOF(tof);
Expand Down Expand Up @@ -957,6 +1018,10 @@ double SpinEchoTime::singleToTOF(const double x) const
double tof = Wavelength::singleToTOF(wavelength);
return tof;
}
double SpinEchoTime::conversionTOFMin()const
{
return 0;
}

double SpinEchoTime::singleFromTOF(const double tof) const
{
Expand Down
Expand Up @@ -90,6 +90,7 @@ namespace MDEvents

// workspace related helper functions, providing access to various workspace functions
API::MatrixWorkspace_const_sptr getInWS()const{return m_InWS;}
void setWS(API::MatrixWorkspace_sptr otherMatrixWS);
std::string getWSName()const{return m_InWS->name();}
bool isPowder()const{return !m_InWS->sample().hasOrientedLattice();}
bool hasLattice()const{return m_InWS->sample().hasOrientedLattice();}
Expand All @@ -107,7 +108,7 @@ namespace MDEvents
void setUpMissingParameters(const MDEvents::MDWSDescription &SourceMatrixWorkspace);

/// method builds MD Event ws description from a matrix workspace and the transformations, requested to be performed on the workspace
void buildFromMatrixWS(const API::MatrixWorkspace_const_sptr &pWS,const std::string &QMode,const std::string dEMode,
void buildFromMatrixWS(const API::MatrixWorkspace_sptr &pWS,const std::string &QMode,const std::string dEMode,
const std::vector<std::string> &dimProperyNames = std::vector<std::string>());

/// compare two descriptions and select the coplimentary result.
Expand Down Expand Up @@ -136,7 +137,7 @@ namespace MDEvents
/// Calculated from number of input properties and the operations, performed on input workspace;
unsigned int m_NDims;
// shared pointer to the source matrix workspace
API::MatrixWorkspace_const_sptr m_InWS;
API::MatrixWorkspace_sptr m_InWS;
/// energy transfer analysis mode
Kernel::DeltaEMode::Type m_Emode;
/// if one needs to calculate Lorentz corrections
Expand Down
Expand Up @@ -74,8 +74,11 @@ class DLLExport UnitsConversionHelper
public:
UnitsConversionHelper():m_pTwoThetas(NULL),m_pL2s(NULL){};
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);
double convertUnits(double val);
Kernel::Unit *const getTargetUnitPtr()const{return m_TargetUnit.get();}
Kernel::Unit *const getSourceUnitPtr()const{return m_TargetUnit.get();}
// copy constructor
UnitsConversionHelper(const UnitsConversionHelper &another);
protected: // for testing
Expand Down
8 changes: 5 additions & 3 deletions Code/Mantid/Framework/MDEvents/src/MDWSDescription.cpp
Expand Up @@ -46,7 +46,7 @@ void MDWSDescription::setDimUnit(unsigned int nDim,const std::string &Unit)
*@param dimPropertyNames -- the vector of names for additional ws properties, which will be used as dimensions.
*/
void MDWSDescription::buildFromMatrixWS(const API::MatrixWorkspace_const_sptr &pWS,const std::string &QMode,const std::string dEMode,
void MDWSDescription::buildFromMatrixWS(const API::MatrixWorkspace_sptr &pWS,const std::string &QMode,const std::string dEMode,
const std::vector<std::string> &dimPropertyNames)
{
m_InWS = pWS;
Expand Down Expand Up @@ -94,9 +94,11 @@ void MDWSDescription::buildFromMatrixWS(const API::MatrixWorkspace_const_sptr &p
}


}



void MDWSDescription::setWS(API::MatrixWorkspace_sptr otherMatrixWS)
{
m_InWS = otherMatrixWS;
}
/// Method checks if input workspace has defined goniometer
bool MDWSDescription::hasGoniometer()const
Expand Down

0 comments on commit 6b3bf28

Please sign in to comment.