Skip to content

Commit

Permalink
Refs #4202. Better handling of theta widths in SofQW2.
Browse files Browse the repository at this point in the history
Needs verification and error handling + parallelization.
  • Loading branch information
martyngigg committed Jan 26, 2012
1 parent d893f42 commit a7c7232
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 379 deletions.
95 changes: 24 additions & 71 deletions Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/SofQW2.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/SofQW.h"
#include "MantidGeometry/Math/ConvexPolygon.h"
#include "MantidGeometry/Math/Quadrilateral.h"
#include "MantidGeometry/IDetector.h"
#include <list>

Expand Down Expand Up @@ -50,7 +50,7 @@ namespace Mantid
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
*/
class DLLExport SofQW2 : public SofQW
{
public:
Expand All @@ -64,91 +64,44 @@ namespace Mantid
virtual const std::string category() const { return "Inelastic";}

private:
/// A struct to store information about an intersection
struct BinWithWeight
{
/** Constructor
* @param i :: The index in the Y direction of the data bin
* @param j :: The index in the X direction of the data bin
* @param pointWeight :: The weight this point carries
*/
BinWithWeight(const size_t i, const size_t j, const double pointWeight)
: yIndex(i), xIndex(j), weight(pointWeight) {}
/// The index in the Y direction of the data bin
size_t yIndex;
/// The index in the X direction of the data bin
size_t xIndex;
/// The weight this point carries
double weight;
};

/// Sets documentation strings for this algorithm
virtual void initDocs();
/// Run the algorithm
void exec();
/// Calculate the Y and E values for the given possible overlap
std::pair<double,double> calculateYE(API::MatrixWorkspace_const_sptr inputWS,
const Geometry::ConvexPolygon & outputPoly) const;
/// Calculate the Y and E values from the given overlaps
std::pair<double,double> calculateYE(API::MatrixWorkspace_const_sptr inputWS,
const std::vector<BinWithWeight> & overlaps) const;
/// Calculate the Y and E values from the given overlaps for a distribution
std::pair<double,double> calculateDistYE(API::MatrixWorkspace_const_sptr inputWS,
const std::vector<BinWithWeight> & overlaps,
const double newBinWidth) const;
/// Find the overlap of the inputWS with the given polygon
std::vector<BinWithWeight> findIntersections(API::MatrixWorkspace_const_sptr inputWS,
const Geometry::ConvexPolygon & poly) const;
/// Rebin the inputQ
void rebinToOutput(const Geometry::Quadrilateral & inputQ, API::MatrixWorkspace_const_sptr inputWS,
const size_t i, const size_t j, API::MatrixWorkspace_sptr outputWS);
/// Get the efixed value for the given detector
double getEFixed(Geometry::IDetector_const_sptr det) const;
/// Calculate the Q value for a direct instrument
double calculateDirectQ(const double efixed, const double deltaE, const double twoTheta, const double psi) const;
/// Calculate the Q value for an indirect instrument
double calculateIndirectQ(const double efixed, const double deltaE, const double twoTheta, const double psi) const;
/// Find the intersect region on the output grid
bool getIntersectionRegion(API::MatrixWorkspace_const_sptr outputWS, const Geometry::Quadrilateral & inputQ,
size_t &qstart, size_t &qend, size_t &en_start, size_t &en_end) const;
/// Init variables cache base on the given workspace
void initCachedValues(API::MatrixWorkspace_const_sptr workspace);
/// Init the theta index
void initQCache(API::MatrixWorkspace_const_sptr workspace);
/// Q value struct
struct QValues
{
QValues() : lowerLeft(0.0), lowerRight(0.0),
upperRight(0.0), upperLeft(0.0) {}
QValues(const double lLeft, const double lRight,
const double uRight, const double uLeft)
: lowerLeft(lLeft), lowerRight(lRight),
upperRight(uRight), upperLeft(uLeft) {}

/// Q values
double lowerLeft, lowerRight, upperRight, upperLeft;
};
/// Calculate the corner Q values
QValues calculateQValues(Geometry::IDetector_const_sptr det,
const double dEMin, const double dEMax) const;
/// Calculate the Kf vectors
std::pair<Kernel::V3D, Kernel::V3D> calculateScatterDir(Geometry::IDetector_const_sptr det) const;
/// Calculate a single Q value
double calculateQ(const Kernel::V3D scatterDir, const double energy) const;
void initThetaCache(API::MatrixWorkspace_const_sptr workspace);

/// E Mode
int m_emode;
/// EFixed has been provided
bool m_efixedGiven;
/// EFixed
double m_efixed;
/// Beam direction
Kernel::V3D m_beamDir;
/// Sample position
Kernel::V3D m_samplePos;
/// Progress reporter
boost::shared_ptr<API::Progress> m_progress;
/// Small caching struct
struct QRangeCache
{
QRangeCache(const size_t index, const double wght)
: wsIndex(index), weight(wght), qValues(0) {}
/// workspace index origin
const size_t wsIndex;
/// Weight
const double weight;
/// QValues for each energy bin
std::vector<QValues> qValues;
};
/// The cache
std::list<QRangeCache> m_qcached;

//---------------------------------------------------------------------------------
/// Output Q axis
std::vector<double> m_Qout;
/// Input theta points
std::vector<double> m_thetaPts;
/// Theta width
double m_thetaWidth;
};


Expand Down

0 comments on commit a7c7232

Please sign in to comment.