Skip to content

Commit

Permalink
refs #5034 get box recursion statistics from MDEventWorkspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Mar 28, 2012
1 parent 8aed22b commit f3c045c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MDEventWorkspace.h"

namespace Mantid
{
Expand Down Expand Up @@ -53,6 +54,9 @@ namespace MDEvents
void init();
/// Run the algorithm
void exec();

template<typename MDE, size_t nd>
void getBoxData(typename Mantid::MDEvents::MDEventWorkspace<MDE, nd>::sptr ws);
};


Expand Down
85 changes: 84 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The table workspace can be used as a basis for plotting within MantidPlot.
#include "MantidAPI/TableRow.h"
#include "MantidKernel/EnabledWhenProperty.h"
#include "MantidKernel/BoundedValidator.h"
#include "../inc/MantidMDEvents/MDEventWorkspace.h"
#include "../inc/MantidMDEvents/MDEventFactory.h"

using namespace Mantid::Kernel;
using namespace Mantid::API;
Expand Down Expand Up @@ -66,8 +68,84 @@ namespace MDEvents

declareProperty(new PropertyWithValue<int>("MaximumRows", 100000, boost::make_shared<BoundedValidator<int>>(), Direction::Input), "The number of neighbours to utilise. Defaults to 100000.");
setPropertySettings("MaximumRows", new EnabledWhenProperty(this, "LimitRows", IS_DEFAULT));

declareProperty(new WorkspaceProperty<ITableWorkspace>("BoxDataTable","",Direction::Output, Mantid::API::PropertyMode::Optional),
"Optional output data table with MDEventWorkspace-specific box data.");

}

//----------------------------------------------------------------------------------------------
/** Make a table of box data
* @param ws :: MDEventWorkspace being added to
*/
template<typename MDE, size_t nd>
void QueryMDWorkspace::getBoxData(typename Mantid::MDEvents::MDEventWorkspace<MDE, nd>::sptr ws)
{
if (this->getPropertyValue("BoxDataTable").empty())
return;

ITableWorkspace_sptr output = WorkspaceFactory::Instance().createTable();
output->addColumn("int", "RecursionDepth");
output->addColumn("int", "NumBoxes");
output->addColumn("int", "NumWithEvents");
output->addColumn("double", "PctWithEvents");
output->addColumn("int", "TotalEvents");
output->addColumn("double", "AvgEventsPer");
output->addColumn("double", "TotalWeight");
output->addColumn("double", "TotalSignal");
output->addColumn("double", "TotalErrorSquared");
for (size_t d=0; d<nd; d++)
output->addColumn("double", "Dim" + Strings::toString(d));

size_t depth=ws->getBoxController()->getMaxDepth()+1;
std::vector<int> NumBoxes(depth, 0);
std::vector<int> NumWithEvents(depth, 0);
std::vector<int> TotalEvents(depth, 0);
std::vector<double> TotalWeight(depth, 0);
std::vector<double> TotalSignal(depth, 0);
std::vector<double> TotalErrorSquared(depth, 0);
std::vector<std::vector<double>> Dims(depth, std::vector<double>(nd,0.0) );

std::vector<IMDBox<MDE,nd> *> boxes;
ws->getBox()->getBoxes(boxes, depth, true);
for (size_t i=0; i<boxes.size(); i++)
{
IMDBox<MDE,nd> * box = boxes[i];
size_t d = box->getDepth();
NumBoxes[d] += 1;
if (box->getNPoints() > 0)
NumWithEvents[d] += 1;
TotalEvents[d] += static_cast<int>(box->getNPoints());
TotalWeight[d] += box->getTotalWeight();
TotalSignal[d] += box->getSignal();
TotalErrorSquared[d] += box->getErrorSquared();
for (size_t dim=0; dim<nd; dim++)
Dims[d][dim] = double(box->getExtents(dim).max - box->getExtents(dim).min);
}

int rowCounter = 0;
for (size_t d=0; d<depth; d++)
{
int col = 0;
output->appendRow();
output->cell<int>(rowCounter, col++) = int(d);
output->cell<int>(rowCounter, col++) = NumBoxes[d];
output->cell<int>(rowCounter, col++) = NumWithEvents[d];
output->cell<double>(rowCounter, col++) = 100.0 * double(NumWithEvents[d]) / double(NumBoxes[d]);
output->cell<int>(rowCounter, col++) = TotalEvents[d];
output->cell<double>(rowCounter, col++) = double(TotalEvents[d]) / double(NumBoxes[d]);
output->cell<double>(rowCounter, col++) = TotalWeight[d];
output->cell<double>(rowCounter, col++) = TotalSignal[d];
output->cell<double>(rowCounter, col++) = TotalErrorSquared[d];
for (size_t dim=0; dim<nd; dim++)
output->cell<double>(rowCounter, col++) = Dims[d][dim];
rowCounter++;
}

setProperty("BoxDataTable", output);
}

//----------------------------------------------------------------------------------------------
/// Run the algorithm
void QueryMDWorkspace::exec()
{
Expand Down Expand Up @@ -109,9 +187,14 @@ namespace MDEvents
}
setProperty("OutputWorkspace", output);
delete it;

//
IMDEventWorkspace_sptr mdew;
CALL_MDEVENT_FUNCTION(this->getBoxData, input);

}



} // namespace Mantid
} // namespace MDEvents
} // namespace MDEvents
14 changes: 13 additions & 1 deletion Code/Mantid/Framework/MDEvents/test/QueryMDWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ class QueryMDWorkspaceTest : public CxxTest::TestSuite
TSM_ASSERT("Did not execute", query.isExecuted());
}

void testExecution_BoxData()
{
MDEventWorkspace3Lean::sptr in_ws = MDEventsTestHelper::makeMDEW<3>(10, -10.0, 20.0, 3);
QueryMDWorkspace query;
query.initialize();
query.setProperty("InputWorkspace", in_ws);
query.setPropertyValue("OutputWorkspace", "QueryWS");
query.setPropertyValue("BoxDataTable", "QueryWS_box");
query.execute();
TSM_ASSERT("Did not execute", query.isExecuted());
}

void testTableGenerated()
{
MDEventWorkspace3Lean::sptr in_ws = MDEventsTestHelper::makeMDEW<3>(10, -10.0, 20.0, 3);
Expand Down Expand Up @@ -91,4 +103,4 @@ class QueryMDWorkspaceTest : public CxxTest::TestSuite
};


#endif /* MANTID_MDEVENTS_QUERYMDWORKSPACETEST_H_ */
#endif /* MANTID_MDEVENTS_QUERYMDWORKSPACETEST_H_ */

0 comments on commit f3c045c

Please sign in to comment.