Skip to content

Commit

Permalink
refs #7228 enabled "Drop 0" option in convertToMD
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Sep 13, 2013
1 parent 585ae38 commit d7a381c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ namespace MDAlgorithms
this->setPropertySettings("ClearInputWorkspace", new DisabledProperty());

declareProperty(new PropertyWithValue<bool>("OneEventPerBin", false, Direction::Input),
"Algorithm v2 always uses OneMDEvent per histogram bin (including zero bins) when works with histogram workspace\n"
" and convers every event into MDEvent when works with event workspace");
"Use the histogram representation (event for event workspaces).\n"
"One MDEvent will be created for each histogram bin (even empty ones).\n"
"Warning! This can use signficantly more memory!");
// disable property on interface
this->setPropertySettings("OneEventPerBin", new DisabledProperty());
//this->setPropertySettings("OneEventPerBin", new DisabledProperty());



Expand Down Expand Up @@ -277,6 +278,9 @@ namespace MDAlgorithms

bool lorCorr = this->getProperty("LorentzCorrection");
Convert->setProperty("LorentzCorrection",lorCorr);

bool ignoreZeros = !this->getProperty("OneEventPerBin");
Convert->setProperty("IgnoreZeroSignals",ignoreZeros);
//set extents
std::vector<double> extents = this->getProperty("Extents");
std::vector<double> minVal,maxVal;
Expand Down
8 changes: 6 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ ConvertToMD::init()
"by the Lorentz multiplier:\n <math>sin(\\theta)^2/\\lambda^4</math>. Currently works in Q3D Elastic case only "
"and is ignored in any other case."
);

declareProperty(new PropertyWithValue<bool>("IgnoreZeroSignals", false, Direction::Input),
"Enabling this property forces algorithm to ignore bins with zero signal for input matxix workspace. Input events workspaces are not affected. "
"This violates the data normalization but may substantially accelerate calculations in situations when the normalization is not important. (e.g. peak finding)."
);
declareProperty(new ArrayProperty<double>("MinValues"),
"It has to be N comma separated values, where N is the number of dimensions of the target workspace. Values "
"smaller then specified here will not be added to workspace.\n Number N is defined by properties 4,6 and 7 and "
Expand Down Expand Up @@ -395,8 +398,9 @@ void ConvertToMD::exec()
ConvToMDSelector AlgoSelector;
m_Convertor = AlgoSelector.convSelector(m_InWS2D,m_Convertor);

bool ignoreZeros = getProperty("IgnoreZeroSignals");
// initate conversion and estimate amout of job to do
size_t n_steps = m_Convertor->initialize(targWSDescr,m_OutWSWrapper);
size_t n_steps = m_Convertor->initialize(targWSDescr,m_OutWSWrapper,ignoreZeros);
// progress reporter
m_Progress.reset(new API::Progress(this,0.0,1.0,n_steps));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace MDEvents
ConvToMDBase();

///method which initates all main class variables
virtual size_t initialize(const MDWSDescription &WSD, boost::shared_ptr<MDEventWSWrapper> inWSWrapper);
virtual size_t initialize(const MDWSDescription &WSD, boost::shared_ptr<MDEventWSWrapper> inWSWrapper, bool IgnoreZeros);
/// method which starts the conversion procedure
virtual void runConversion(API::Progress *)=0;
/// virtual destructor
Expand Down Expand Up @@ -94,6 +94,8 @@ namespace MDEvents
// On multiprocessor machine the algorithm should run and utilizes all cores (see Kernel::Threadpool),
// but this can be chenged setting this parameter to 0 (no multithreading) or positive number specifying the requested nymber of threads
int m_NumThreads;
// propery which indicates that data with 0 signal should be ignored
bool m_IgnoreZeros;
/// Any special coordinate system used.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;
private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace MDEvents
class ConvToMDEventsWS: public ConvToMDBase
{
public:
size_t initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper);
size_t initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper,bool ignoreZeros);
void runConversion(API::Progress *pProgress);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ConvToMDHistoWS: public ConvToMDBase
{

public:
size_t initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper);
size_t initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper, bool ignoreZeros);

void runConversion(API::Progress *pProgress);
private:
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ namespace Mantid
* unit conversion (if any)
* @param inWSWrapper -- shared pointer to target MD Event workspace to add converted events to.
*/
size_t ConvToMDBase::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper)
size_t ConvToMDBase::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper, bool ignoreZeros)
{

m_IgnoreZeros = ignoreZeros;
m_InWS2D = WSD.getInWS();
// preprocessed detectors information:
// check if detector information has been precalculated:
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/ConvToMDEventsWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ namespace Mantid
/** method sets up all internal variables necessary to convert from Event Workspace to MDEvent workspace
@param WSD -- the class describing the target MD workspace, sorurce Event workspace and the transformations, necessary to perform on these workspaces
@param inWSWrapper -- the class wrapping the target MD workspace
@param ignoreZeros -- if zero value signals should be rejected
*/
size_t ConvToMDEventsWS::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper)
size_t ConvToMDEventsWS::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper,bool ignoreZeros)
{
size_t numSpec=ConvToMDBase::initialize(WSD,inWSWrapper);
size_t numSpec=ConvToMDBase::initialize(WSD,inWSWrapper,ignoreZeros);


m_EventWS = boost::dynamic_pointer_cast<const DataObjects::EventWorkspace>(m_InWS2D);
Expand Down
9 changes: 7 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/ConvToMDHistoWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ namespace Mantid
/** method sets up all internal variables necessary to convert from Matrix2D workspace to MDEvent workspace
@param WSD -- the class describing the target MD workspace, sorurce matrtix workspace and the transformations, necessary to perform on these workspaces
@param inWSWrapper -- the class wrapping the target MD workspace
@param ignoreZeros -- if zero value signals should be rejected
*/
size_t ConvToMDHistoWS::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper)
size_t ConvToMDHistoWS::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper, bool ignoreZeros)
{

size_t numSpec=ConvToMDBase::initialize(WSD,inWSWrapper);
size_t numSpec=ConvToMDBase::initialize(WSD,inWSWrapper,ignoreZeros);

// check if we indeed have matrix workspace as input.
DataObjects::Workspace2D_const_sptr pWS2D = boost::dynamic_pointer_cast<const DataObjects::Workspace2D>(m_InWS2D);
Expand All @@ -39,6 +40,8 @@ namespace Mantid
size_t ConvToMDHistoWS::conversionChunk(size_t startSpectra)
{
size_t nAddedEvents(0),nBufEvents(0);
// cach global variable locally
bool ignoreZeros(m_IgnoreZeros);

const size_t specSize = this->m_InWS2D->blocksize();
// preprocessed detectors associate each spectra with a detector (position)
Expand Down Expand Up @@ -87,6 +90,8 @@ namespace Mantid
double signal = Signal[j];
// drop NaN events
if(isNaN(signal))continue;
// drop 0 -value signals if necessary.
if(ignoreZeros &&(signal==0.))continue;
double errorSq = Error[j]*Error[j];

if(!m_QConverter->calcMatrixCoordinates(XtargetUnits,i,j,locCoord,signal,errorSq))continue; // skip ND outside the range
Expand Down

0 comments on commit d7a381c

Please sign in to comment.