Skip to content

Commit

Permalink
Refs #4734 carry a TotalWeight field in MDBoxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Mar 28, 2012
1 parent eee6add commit 8aed22b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
22 changes: 22 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/IMDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ namespace MDEvents
return m_errorSquared;
}

//-----------------------------------------------------------------------------------------------
/** Returns the total weight of all events within. Typically this is
* equal to the number of events (weight of 1 per event)
*/
virtual signal_t getTotalWeight() const
{
return m_totalWeight;
}

//-----------------------------------------------------------------------------------------------
/** Sets the integrated signal from all points within (mostly used for testing)
* @param signal :: new Signal amount.
Expand All @@ -326,6 +335,15 @@ namespace MDEvents
m_errorSquared = ErrorSquared;
}

//-----------------------------------------------------------------------------------------------
/** Sets the total weight from all points within (mostly used for testing)
* @param total :: new weight amount.
*/
virtual void setTotalWeight(const signal_t total)
{
m_totalWeight = total;
}

//-----------------------------------------------------------------------------------------------
/** Returns the integrated signal from all points within, normalized for the cell volume
*/
Expand Down Expand Up @@ -414,6 +432,10 @@ namespace MDEvents
* Set when refreshCache() is called. */
mutable signal_t m_errorSquared;

/** Cached total weight of all events
* Set when refreshCache() is called. */
mutable signal_t m_totalWeight;

/// Inverse of the volume of the cell, to be used for normalized signal.
coord_t m_inverseVolume;

Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDEvents/src/IMDBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace MDEvents
*/
TMDE(
IMDBox)::IMDBox()
: m_signal(0.0), m_errorSquared(0.0),
: m_signal(0.0), m_errorSquared(0.0), m_totalWeight(0.0),
m_inverseVolume(1.0),
m_depth(0),
m_parent(NULL)
Expand All @@ -34,7 +34,7 @@ namespace MDEvents
*/
TMDE(
IMDBox)::IMDBox(const std::vector<Mantid::Geometry::MDDimensionExtents> & extentsVector)
: m_signal(0.0), m_errorSquared(0.0),
: m_signal(0.0), m_errorSquared(0.0), m_totalWeight(0.0),
m_inverseVolume(1.0),
m_depth(0),
m_parent(NULL)
Expand All @@ -59,7 +59,7 @@ namespace MDEvents
TMDE(
IMDBox)::IMDBox(const IMDBox<MDE,nd> & box)
: ISaveable(box),
m_signal(box.m_signal), m_errorSquared(box.m_errorSquared),
m_signal(box.m_signal), m_errorSquared(box.m_errorSquared), m_totalWeight(box.m_totalWeight),
m_inverseVolume(box.m_inverseVolume), m_depth(box.m_depth),
m_parent(box.m_parent)
{
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ namespace MDEvents
this->m_errorSquared += static_cast<signal_t>(event.getErrorSquared());
}
}
/// TODO #4734: sum the individual weights of each event?
this->m_totalWeight = static_cast<double>(this->getNPoints());
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDGridBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ namespace MDEvents
nPoints = 0;
this->m_signal = 0;
this->m_errorSquared = 0;
this->m_totalWeight = 0;

#ifdef MDBOX_TRACK_CENTROID
for (size_t d=0; d<nd; d++)
this->m_centroid[d] = 0;
Expand All @@ -390,6 +392,7 @@ namespace MDEvents
nPoints += ibox->getNPoints();
this->m_signal += ibox->getSignal();
this->m_errorSquared += ibox->getErrorSquared();
this->m_totalWeight += ibox->getTotalWeight();

#ifdef MDBOX_TRACK_CENTROID
// And track the centroid
Expand Down
8 changes: 8 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/IMDBoxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ class IMDBoxTest : public CxxTest::TestSuite
TS_ASSERT_DELTA( box.getError(), sqrt(456.0), 1e-4);
}

void test_getTotalWeight()
{
IMDBoxTester<MDLeanEvent<3>,3> box;
TS_ASSERT_EQUALS( box.getTotalWeight(), 0.0);
box.setTotalWeight(123.0);
TS_ASSERT_EQUALS( box.getTotalWeight(), 123.0);
}

void test_get_and_set_depth()
{
IMDBoxTester<MDLeanEvent<3>,3> b;
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDBoxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class MDBoxTest : public CxxTest::TestSuite
// Did it keep a running total of the signal and error?
TS_ASSERT_DELTA( b.getSignal(), 1.2*1, 1e-5);
TS_ASSERT_DELTA( b.getErrorSquared(), 3.4*1, 1e-5);
// Weight of 1.0 per event.
TS_ASSERT_EQUALS( b.getTotalWeight(), 1.0);

}
/** Adding events in unsafe way also works */
void test_addEventUnsafe()
Expand Down

0 comments on commit 8aed22b

Please sign in to comment.